Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
c1017a4c | 2 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
1da177e4 LT |
3 | * Universal routines for AK4531 codec |
4 | * | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
1da177e4 LT |
22 | #include <linux/delay.h> |
23 | #include <linux/init.h> | |
24 | #include <linux/slab.h> | |
62932df8 IM |
25 | #include <linux/mutex.h> |
26 | ||
1da177e4 LT |
27 | #include <sound/core.h> |
28 | #include <sound/ak4531_codec.h> | |
9107226d | 29 | #include <sound/tlv.h> |
1da177e4 | 30 | |
6719292a | 31 | /* |
c1017a4c | 32 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
1da177e4 LT |
33 | MODULE_DESCRIPTION("Universal routines for AK4531 codec"); |
34 | MODULE_LICENSE("GPL"); | |
6719292a | 35 | */ |
1da177e4 | 36 | |
adf1b3d2 | 37 | #ifdef CONFIG_PROC_FS |
9f38945f | 38 | static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531); |
adf1b3d2 TI |
39 | #else |
40 | #define snd_ak4531_proc_init(card,ak) | |
41 | #endif | |
1da177e4 LT |
42 | |
43 | /* | |
44 | * | |
45 | */ | |
46 | ||
47 | #if 0 | |
48 | ||
9f38945f | 49 | static void snd_ak4531_dump(struct snd_ak4531 *ak4531) |
1da177e4 LT |
50 | { |
51 | int idx; | |
52 | ||
53 | for (idx = 0; idx < 0x19; idx++) | |
54 | printk("ak4531 0x%x: 0x%x\n", idx, ak4531->regs[idx]); | |
55 | } | |
56 | ||
57 | #endif | |
58 | ||
59 | /* | |
60 | * | |
61 | */ | |
62 | ||
63 | #define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \ | |
64 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | |
65 | .info = snd_ak4531_info_single, \ | |
66 | .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \ | |
67 | .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) } | |
9107226d TI |
68 | #define AK4531_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \ |
69 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
70 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ | |
71 | .name = xname, .index = xindex, \ | |
72 | .info = snd_ak4531_info_single, \ | |
73 | .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \ | |
74 | .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22), \ | |
75 | .tlv = { .p = (xtlv) } } | |
1da177e4 | 76 | |
9f38945f | 77 | static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
1da177e4 LT |
78 | { |
79 | int mask = (kcontrol->private_value >> 24) & 0xff; | |
80 | ||
81 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; | |
82 | uinfo->count = 1; | |
83 | uinfo->value.integer.min = 0; | |
84 | uinfo->value.integer.max = mask; | |
85 | return 0; | |
86 | } | |
87 | ||
9f38945f | 88 | static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 89 | { |
9f38945f | 90 | struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
91 | int reg = kcontrol->private_value & 0xff; |
92 | int shift = (kcontrol->private_value >> 16) & 0x07; | |
93 | int mask = (kcontrol->private_value >> 24) & 0xff; | |
94 | int invert = (kcontrol->private_value >> 22) & 1; | |
95 | int val; | |
96 | ||
62932df8 | 97 | mutex_lock(&ak4531->reg_mutex); |
1da177e4 | 98 | val = (ak4531->regs[reg] >> shift) & mask; |
62932df8 | 99 | mutex_unlock(&ak4531->reg_mutex); |
1da177e4 LT |
100 | if (invert) { |
101 | val = mask - val; | |
102 | } | |
103 | ucontrol->value.integer.value[0] = val; | |
104 | return 0; | |
105 | } | |
106 | ||
9f38945f | 107 | static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 108 | { |
9f38945f | 109 | struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
110 | int reg = kcontrol->private_value & 0xff; |
111 | int shift = (kcontrol->private_value >> 16) & 0x07; | |
112 | int mask = (kcontrol->private_value >> 24) & 0xff; | |
113 | int invert = (kcontrol->private_value >> 22) & 1; | |
114 | int change; | |
115 | int val; | |
116 | ||
117 | val = ucontrol->value.integer.value[0] & mask; | |
118 | if (invert) { | |
119 | val = mask - val; | |
120 | } | |
121 | val <<= shift; | |
62932df8 | 122 | mutex_lock(&ak4531->reg_mutex); |
1da177e4 LT |
123 | val = (ak4531->regs[reg] & ~(mask << shift)) | val; |
124 | change = val != ak4531->regs[reg]; | |
125 | ak4531->write(ak4531, reg, ak4531->regs[reg] = val); | |
62932df8 | 126 | mutex_unlock(&ak4531->reg_mutex); |
1da177e4 LT |
127 | return change; |
128 | } | |
129 | ||
130 | #define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \ | |
131 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | |
132 | .info = snd_ak4531_info_double, \ | |
133 | .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \ | |
134 | .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) } | |
9107226d TI |
135 | #define AK4531_DOUBLE_TLV(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert, xtlv) \ |
136 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
137 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ | |
138 | .name = xname, .index = xindex, \ | |
139 | .info = snd_ak4531_info_double, \ | |
140 | .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \ | |
141 | .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22), \ | |
142 | .tlv = { .p = (xtlv) } } | |
1da177e4 | 143 | |
9f38945f | 144 | static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
1da177e4 LT |
145 | { |
146 | int mask = (kcontrol->private_value >> 24) & 0xff; | |
147 | ||
148 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; | |
149 | uinfo->count = 2; | |
150 | uinfo->value.integer.min = 0; | |
151 | uinfo->value.integer.max = mask; | |
152 | return 0; | |
153 | } | |
154 | ||
9f38945f | 155 | static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 156 | { |
9f38945f | 157 | struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
158 | int left_reg = kcontrol->private_value & 0xff; |
159 | int right_reg = (kcontrol->private_value >> 8) & 0xff; | |
160 | int left_shift = (kcontrol->private_value >> 16) & 0x07; | |
161 | int right_shift = (kcontrol->private_value >> 19) & 0x07; | |
162 | int mask = (kcontrol->private_value >> 24) & 0xff; | |
163 | int invert = (kcontrol->private_value >> 22) & 1; | |
164 | int left, right; | |
165 | ||
62932df8 | 166 | mutex_lock(&ak4531->reg_mutex); |
1da177e4 LT |
167 | left = (ak4531->regs[left_reg] >> left_shift) & mask; |
168 | right = (ak4531->regs[right_reg] >> right_shift) & mask; | |
62932df8 | 169 | mutex_unlock(&ak4531->reg_mutex); |
1da177e4 LT |
170 | if (invert) { |
171 | left = mask - left; | |
172 | right = mask - right; | |
173 | } | |
174 | ucontrol->value.integer.value[0] = left; | |
175 | ucontrol->value.integer.value[1] = right; | |
176 | return 0; | |
177 | } | |
178 | ||
9f38945f | 179 | static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 180 | { |
9f38945f | 181 | struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
182 | int left_reg = kcontrol->private_value & 0xff; |
183 | int right_reg = (kcontrol->private_value >> 8) & 0xff; | |
184 | int left_shift = (kcontrol->private_value >> 16) & 0x07; | |
185 | int right_shift = (kcontrol->private_value >> 19) & 0x07; | |
186 | int mask = (kcontrol->private_value >> 24) & 0xff; | |
187 | int invert = (kcontrol->private_value >> 22) & 1; | |
188 | int change; | |
189 | int left, right; | |
190 | ||
191 | left = ucontrol->value.integer.value[0] & mask; | |
192 | right = ucontrol->value.integer.value[1] & mask; | |
193 | if (invert) { | |
194 | left = mask - left; | |
195 | right = mask - right; | |
196 | } | |
197 | left <<= left_shift; | |
198 | right <<= right_shift; | |
62932df8 | 199 | mutex_lock(&ak4531->reg_mutex); |
1da177e4 LT |
200 | if (left_reg == right_reg) { |
201 | left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right; | |
202 | change = left != ak4531->regs[left_reg]; | |
203 | ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left); | |
204 | } else { | |
205 | left = (ak4531->regs[left_reg] & ~(mask << left_shift)) | left; | |
206 | right = (ak4531->regs[right_reg] & ~(mask << right_shift)) | right; | |
207 | change = left != ak4531->regs[left_reg] || right != ak4531->regs[right_reg]; | |
208 | ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left); | |
209 | ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right); | |
210 | } | |
62932df8 | 211 | mutex_unlock(&ak4531->reg_mutex); |
1da177e4 LT |
212 | return change; |
213 | } | |
214 | ||
215 | #define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \ | |
216 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | |
217 | .info = snd_ak4531_info_input_sw, \ | |
218 | .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \ | |
219 | .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) } | |
220 | ||
9f38945f | 221 | static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
1da177e4 LT |
222 | { |
223 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
224 | uinfo->count = 4; | |
225 | uinfo->value.integer.min = 0; | |
226 | uinfo->value.integer.max = 1; | |
227 | return 0; | |
228 | } | |
229 | ||
9f38945f | 230 | static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 231 | { |
9f38945f | 232 | struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
233 | int reg1 = kcontrol->private_value & 0xff; |
234 | int reg2 = (kcontrol->private_value >> 8) & 0xff; | |
235 | int left_shift = (kcontrol->private_value >> 16) & 0x0f; | |
236 | int right_shift = (kcontrol->private_value >> 24) & 0x0f; | |
237 | ||
62932df8 | 238 | mutex_lock(&ak4531->reg_mutex); |
1da177e4 LT |
239 | ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1; |
240 | ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1; | |
241 | ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1; | |
242 | ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1; | |
62932df8 | 243 | mutex_unlock(&ak4531->reg_mutex); |
1da177e4 LT |
244 | return 0; |
245 | } | |
246 | ||
9f38945f | 247 | static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 248 | { |
9f38945f | 249 | struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
250 | int reg1 = kcontrol->private_value & 0xff; |
251 | int reg2 = (kcontrol->private_value >> 8) & 0xff; | |
252 | int left_shift = (kcontrol->private_value >> 16) & 0x0f; | |
253 | int right_shift = (kcontrol->private_value >> 24) & 0x0f; | |
254 | int change; | |
255 | int val1, val2; | |
256 | ||
62932df8 | 257 | mutex_lock(&ak4531->reg_mutex); |
1da177e4 LT |
258 | val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift)); |
259 | val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift)); | |
260 | val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift; | |
261 | val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift; | |
262 | val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift; | |
263 | val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift; | |
264 | change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2]; | |
265 | ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1); | |
266 | ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2); | |
62932df8 | 267 | mutex_unlock(&ak4531->reg_mutex); |
1da177e4 LT |
268 | return change; |
269 | } | |
270 | ||
0cb29ea0 TI |
271 | static const DECLARE_TLV_DB_SCALE(db_scale_master, -6200, 200, 0); |
272 | static const DECLARE_TLV_DB_SCALE(db_scale_mono, -2800, 400, 0); | |
273 | static const DECLARE_TLV_DB_SCALE(db_scale_input, -5000, 200, 0); | |
9107226d | 274 | |
23ce1547 | 275 | static struct snd_kcontrol_new snd_ak4531_controls[] __devinitdata = { |
1da177e4 | 276 | |
9107226d TI |
277 | AK4531_DOUBLE_TLV("Master Playback Switch", 0, |
278 | AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1, | |
279 | db_scale_master), | |
1da177e4 LT |
280 | AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1), |
281 | ||
9107226d TI |
282 | AK4531_SINGLE_TLV("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1, |
283 | db_scale_mono), | |
1da177e4 LT |
284 | AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1), |
285 | ||
286 | AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1), | |
9107226d TI |
287 | AK4531_DOUBLE_TLV("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1, |
288 | db_scale_input), | |
1da177e4 LT |
289 | AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0), |
290 | AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0), | |
291 | ||
292 | AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1), | |
9107226d TI |
293 | AK4531_DOUBLE_TLV("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1, |
294 | db_scale_input), | |
1da177e4 LT |
295 | AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0), |
296 | AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5), | |
297 | ||
298 | AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1), | |
9107226d TI |
299 | AK4531_DOUBLE_TLV("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1, |
300 | db_scale_input), | |
1da177e4 LT |
301 | AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0), |
302 | AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1), | |
303 | ||
304 | AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1), | |
9107226d TI |
305 | AK4531_DOUBLE_TLV("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1, |
306 | db_scale_input), | |
1da177e4 LT |
307 | AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0), |
308 | AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3), | |
309 | ||
310 | AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1), | |
9107226d TI |
311 | AK4531_DOUBLE_TLV("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1, |
312 | db_scale_input), | |
1da177e4 LT |
313 | AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0), |
314 | AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3), | |
315 | ||
316 | AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1), | |
9107226d | 317 | AK4531_SINGLE_TLV("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1, db_scale_input), |
1da177e4 LT |
318 | AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0), |
319 | AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0), | |
320 | ||
321 | AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1), | |
9107226d | 322 | AK4531_SINGLE_TLV("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1, db_scale_input), |
1da177e4 LT |
323 | AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0), |
324 | AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0), | |
325 | ||
9107226d | 326 | AK4531_SINGLE_TLV("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1, db_scale_input), |
1da177e4 LT |
327 | AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1), |
328 | AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0), | |
329 | AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0), | |
330 | ||
331 | AK4531_DOUBLE("Mic Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 7, 7, 1, 0), | |
332 | AK4531_DOUBLE("Mono1 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 6, 6, 1, 0), | |
333 | AK4531_DOUBLE("Mono2 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 5, 5, 1, 0), | |
334 | ||
335 | AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0), | |
336 | AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0) | |
337 | }; | |
338 | ||
9f38945f | 339 | static int snd_ak4531_free(struct snd_ak4531 *ak4531) |
1da177e4 LT |
340 | { |
341 | if (ak4531) { | |
342 | if (ak4531->private_free) | |
343 | ak4531->private_free(ak4531); | |
344 | kfree(ak4531); | |
345 | } | |
346 | return 0; | |
347 | } | |
348 | ||
9f38945f | 349 | static int snd_ak4531_dev_free(struct snd_device *device) |
1da177e4 | 350 | { |
9f38945f | 351 | struct snd_ak4531 *ak4531 = device->device_data; |
1da177e4 LT |
352 | return snd_ak4531_free(ak4531); |
353 | } | |
354 | ||
355 | static u8 snd_ak4531_initial_map[0x19 + 1] = { | |
356 | 0x9f, /* 00: Master Volume Lch */ | |
357 | 0x9f, /* 01: Master Volume Rch */ | |
358 | 0x9f, /* 02: Voice Volume Lch */ | |
359 | 0x9f, /* 03: Voice Volume Rch */ | |
360 | 0x9f, /* 04: FM Volume Lch */ | |
361 | 0x9f, /* 05: FM Volume Rch */ | |
362 | 0x9f, /* 06: CD Audio Volume Lch */ | |
363 | 0x9f, /* 07: CD Audio Volume Rch */ | |
364 | 0x9f, /* 08: Line Volume Lch */ | |
365 | 0x9f, /* 09: Line Volume Rch */ | |
366 | 0x9f, /* 0a: Aux Volume Lch */ | |
367 | 0x9f, /* 0b: Aux Volume Rch */ | |
368 | 0x9f, /* 0c: Mono1 Volume */ | |
369 | 0x9f, /* 0d: Mono2 Volume */ | |
370 | 0x9f, /* 0e: Mic Volume */ | |
371 | 0x87, /* 0f: Mono-out Volume */ | |
372 | 0x00, /* 10: Output Mixer SW1 */ | |
373 | 0x00, /* 11: Output Mixer SW2 */ | |
374 | 0x00, /* 12: Lch Input Mixer SW1 */ | |
375 | 0x00, /* 13: Rch Input Mixer SW1 */ | |
376 | 0x00, /* 14: Lch Input Mixer SW2 */ | |
377 | 0x00, /* 15: Rch Input Mixer SW2 */ | |
378 | 0x00, /* 16: Reset & Power Down */ | |
379 | 0x00, /* 17: Clock Select */ | |
380 | 0x00, /* 18: AD Input Select */ | |
381 | 0x01 /* 19: Mic Amp Setup */ | |
382 | }; | |
383 | ||
23ce1547 TI |
384 | int __devinit snd_ak4531_mixer(struct snd_card *card, |
385 | struct snd_ak4531 *_ak4531, | |
386 | struct snd_ak4531 **rak4531) | |
1da177e4 LT |
387 | { |
388 | unsigned int idx; | |
389 | int err; | |
9f38945f TI |
390 | struct snd_ak4531 *ak4531; |
391 | static struct snd_device_ops ops = { | |
1da177e4 LT |
392 | .dev_free = snd_ak4531_dev_free, |
393 | }; | |
394 | ||
da3cec35 TI |
395 | if (snd_BUG_ON(!card || !_ak4531)) |
396 | return -EINVAL; | |
397 | if (rak4531) | |
398 | *rak4531 = NULL; | |
e560d8d8 | 399 | ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL); |
1da177e4 LT |
400 | if (ak4531 == NULL) |
401 | return -ENOMEM; | |
402 | *ak4531 = *_ak4531; | |
62932df8 | 403 | mutex_init(&ak4531->reg_mutex); |
1da177e4 LT |
404 | if ((err = snd_component_add(card, "AK4531")) < 0) { |
405 | snd_ak4531_free(ak4531); | |
406 | return err; | |
407 | } | |
408 | strcpy(card->mixername, "Asahi Kasei AK4531"); | |
409 | ak4531->write(ak4531, AK4531_RESET, 0x03); /* no RST, PD */ | |
410 | udelay(100); | |
411 | ak4531->write(ak4531, AK4531_CLOCK, 0x00); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */ | |
11d3824a | 412 | for (idx = 0; idx <= 0x19; idx++) { |
1da177e4 LT |
413 | if (idx == AK4531_RESET || idx == AK4531_CLOCK) |
414 | continue; | |
415 | ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]); /* recording source is mixer */ | |
416 | } | |
417 | for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) { | |
418 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) { | |
419 | snd_ak4531_free(ak4531); | |
420 | return err; | |
421 | } | |
422 | } | |
423 | snd_ak4531_proc_init(card, ak4531); | |
424 | if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) { | |
425 | snd_ak4531_free(ak4531); | |
426 | return err; | |
427 | } | |
428 | ||
429 | #if 0 | |
430 | snd_ak4531_dump(ak4531); | |
431 | #endif | |
da3cec35 TI |
432 | if (rak4531) |
433 | *rak4531 = ak4531; | |
1da177e4 LT |
434 | return 0; |
435 | } | |
436 | ||
11d3824a TI |
437 | /* |
438 | * power management | |
439 | */ | |
440 | #ifdef CONFIG_PM | |
441 | void snd_ak4531_suspend(struct snd_ak4531 *ak4531) | |
442 | { | |
443 | /* mute */ | |
444 | ak4531->write(ak4531, AK4531_LMASTER, 0x9f); | |
445 | ak4531->write(ak4531, AK4531_RMASTER, 0x9f); | |
446 | /* powerdown */ | |
447 | ak4531->write(ak4531, AK4531_RESET, 0x01); | |
448 | } | |
449 | ||
450 | void snd_ak4531_resume(struct snd_ak4531 *ak4531) | |
451 | { | |
452 | int idx; | |
453 | ||
454 | /* initialize */ | |
455 | ak4531->write(ak4531, AK4531_RESET, 0x03); | |
456 | udelay(100); | |
457 | ak4531->write(ak4531, AK4531_CLOCK, 0x00); | |
458 | /* restore mixer registers */ | |
459 | for (idx = 0; idx <= 0x19; idx++) { | |
460 | if (idx == AK4531_RESET || idx == AK4531_CLOCK) | |
461 | continue; | |
462 | ak4531->write(ak4531, idx, ak4531->regs[idx]); | |
463 | } | |
464 | } | |
465 | #endif | |
466 | ||
adf1b3d2 | 467 | #ifdef CONFIG_PROC_FS |
1da177e4 | 468 | /* |
adf1b3d2 | 469 | * /proc interface |
1da177e4 LT |
470 | */ |
471 | ||
9f38945f TI |
472 | static void snd_ak4531_proc_read(struct snd_info_entry *entry, |
473 | struct snd_info_buffer *buffer) | |
1da177e4 | 474 | { |
9f38945f | 475 | struct snd_ak4531 *ak4531 = entry->private_data; |
1da177e4 LT |
476 | |
477 | snd_iprintf(buffer, "Asahi Kasei AK4531\n\n"); | |
478 | snd_iprintf(buffer, "Recording source : %s\n" | |
479 | "MIC gain : %s\n", | |
480 | ak4531->regs[AK4531_AD_IN] & 1 ? "external" : "mixer", | |
481 | ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB"); | |
482 | } | |
483 | ||
23ce1547 TI |
484 | static void __devinit |
485 | snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531) | |
1da177e4 | 486 | { |
9f38945f | 487 | struct snd_info_entry *entry; |
1da177e4 LT |
488 | |
489 | if (! snd_card_proc_new(card, "ak4531", &entry)) | |
bf850204 | 490 | snd_info_set_text_ops(entry, ak4531, snd_ak4531_proc_read); |
1da177e4 | 491 | } |
adf1b3d2 | 492 | #endif |