tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / sound / cmd_sound.c
1 /*
2  * Copyright 2000-2009
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <command.h>
26 #include <errno.h>
27 #include <ubi_uboot.h>
28 #include <asm/io.h>
29
30 #include "sound_common.h"
31
32 #define pr_fmt(fmt) "[sound: cmd ]" fmt
33 #ifdef  CMD_SND_DEBUG
34 #define snd_dbg(fmt,args...)    pr_info(fmt ,##args)
35 #else
36 #define snd_dbg(fmt,args...)
37 #endif
38
39 #define SND_REG_MASK (0xFFFFFFFF)
40
41 static inline int snd_reg_lock(int reg)
42 {
43         snd_dbg("register lock 0x%08x\n", reg);
44         return 0;
45 }
46
47 static inline int snd_reg_unlock(int reg)
48 {
49         snd_dbg("register unlock 0x%08x\n", reg);
50         return 0;
51 }
52
53 static inline int snd_reg_is_adie_addr(int reg)
54 {
55         return (reg >= ANA_REG_ADDR_START) && (reg <= ANA_REG_ADDR_END);
56 }
57
58 int snd_reg_read(int reg)
59 {
60         if (snd_reg_is_adie_addr(reg)) {
61                 return sci_adi_read(reg);
62         }
63         return __raw_readl(reg);
64 }
65
66 EXPORT_SYMBOL(snd_reg_read);
67
68 int snd_reg_write(int reg, int value, int mask)
69 {
70         int ret = 0;
71         if (snd_reg_is_adie_addr(reg)) {
72                 ret = sci_adi_write(reg, value, mask);
73         } else {
74                 int val;
75                 snd_reg_lock(reg);
76                 val = __raw_readl(reg) & ~mask;
77                 __raw_writel(val | (value & mask), reg);
78                 snd_reg_unlock(reg);
79         }
80         return ret;
81 }
82
83 EXPORT_SYMBOL(snd_reg_write);
84
85 int snd_reg_wirte_f(int reg, int value)
86 {
87         return snd_reg_write(reg, value, SND_REG_MASK);
88 }
89
90 EXPORT_SYMBOL(snd_reg_wirte_f);
91
92 int sound_init(void)
93 {
94         sprd_codec_init();
95         vbc_init();
96         return 0;
97 }
98
99 EXPORT_SYMBOL(sound_init);
100
101 int do_reg_write(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
102 {
103         int ret;
104         int addr, value, mask = SND_REG_MASK;
105
106         if (argc < 3)
107                 return cmd_usage(cmdtp);
108
109         addr = simple_strtoul(argv[1], NULL, 16);
110         value = simple_strtoul(argv[2], NULL, 16);
111         if (argc > 3)
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));
115         return ret;
116 }
117
118 int do_reg_read(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
119 {
120         int addr, lenght;
121
122         if (argc < 2)
123                 return cmd_usage(cmdtp);
124
125         addr = simple_strtoul(argv[1], NULL, 16);
126         if (argc > 2) {
127                 int address;
128                 lenght = simple_strtoul(argv[2], NULL, 16);
129                 for (address = addr & ~0xF; address < (addr + lenght);
130                      address += 0x4) {
131                         if (!(address & 0xF)) {
132                                 printf("\n0x%08x | ", address);
133                         }
134                         if (address >= addr) {
135                                 printf("0x%08x ", snd_reg_read(address));
136                         } else {
137                                 printf("           ");
138                         }
139                 }
140                 printf("\n");
141         } else {
142                 printf("0x%08x | 0x%08x\n", addr, snd_reg_read(addr));
143         }
144         return 0;
145 }
146
147 /* command define */
148
149 U_BOOT_CMD(regr, 3, 1, do_reg_read,
150            "get chip register value",
151            "\n"
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");
156
157 U_BOOT_CMD(regw, 4, 1, do_reg_write,
158            "set chip register value",
159            "\n"
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");