3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <ubi_uboot.h>
30 #include "sound_common.h"
32 #define pr_fmt(fmt) "[sound: cmd ]" fmt
34 #define snd_dbg(fmt,args...) pr_info(fmt ,##args)
36 #define snd_dbg(fmt,args...)
39 #define SND_REG_MASK (0xFFFFFFFF)
41 static inline int snd_reg_lock(int reg)
43 snd_dbg("register lock 0x%08x\n", reg);
47 static inline int snd_reg_unlock(int reg)
49 snd_dbg("register unlock 0x%08x\n", reg);
53 static inline int snd_reg_is_adie_addr(int reg)
55 return (reg >= ANA_REG_ADDR_START) && (reg <= ANA_REG_ADDR_END);
58 int snd_reg_read(int reg)
60 if (snd_reg_is_adie_addr(reg)) {
61 return sci_adi_read(reg);
63 return __raw_readl(reg);
66 EXPORT_SYMBOL(snd_reg_read);
68 int snd_reg_write(int reg, int value, int mask)
71 if (snd_reg_is_adie_addr(reg)) {
72 ret = sci_adi_write(reg, value, mask);
76 val = __raw_readl(reg) & ~mask;
77 __raw_writel(val | (value & mask), reg);
83 EXPORT_SYMBOL(snd_reg_write);
85 int snd_reg_wirte_f(int reg, int value)
87 return snd_reg_write(reg, value, SND_REG_MASK);
90 EXPORT_SYMBOL(snd_reg_wirte_f);
99 EXPORT_SYMBOL(sound_init);
101 int do_reg_write(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
104 int addr, value, mask = SND_REG_MASK;
107 return cmd_usage(cmdtp);
109 addr = simple_strtoul(argv[1], NULL, 16);
110 value = simple_strtoul(argv[2], NULL, 16);
112 mask = simple_strtoul(argv[3], NULL, 16);
113 ret = snd_reg_write(addr, value, mask);
114 printf("0x%08x | 0x%08x\n", addr, snd_reg_read(addr));
118 int do_reg_read(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
123 return cmd_usage(cmdtp);
125 addr = simple_strtoul(argv[1], NULL, 16);
128 lenght = simple_strtoul(argv[2], NULL, 16);
129 for (address = addr & ~0xF; address < (addr + lenght);
131 if (!(address & 0xF)) {
132 printf("\n0x%08x | ", address);
134 if (address >= addr) {
135 printf("0x%08x ", snd_reg_read(address));
142 printf("0x%08x | 0x%08x\n", addr, snd_reg_read(addr));
149 U_BOOT_CMD(regr, 3, 1, do_reg_read,
150 "get chip register value",
152 " - get chip register value, include adie register\n"
153 "regr reg_addr [range]\n"
154 " reg_addr - which register you want get\n"
155 " range - what range you want get\n");
157 U_BOOT_CMD(regw, 4, 1, do_reg_write,
158 "set chip register value",
160 " - set chip register value, include adie register\n"
161 "regw reg_addr value [mask]\n"
162 " reg_addr - which register you want set\n"
163 " value - what value you want set\n"
164 " mask - which bit mask you just want set\n");