blob: f68bd740e1a19eb4354275fa9bb4913d41338203 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381
3 * AD and DA converters
4 *
5 * Copyright (c) 2000-2004 Jaroslav Kysela <perex@suse.cz>,
6 * Takashi Iwai <tiwai@suse.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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, MA 02111-1307 USA
21 *
22 */
23
24#include <sound/driver.h>
25#include <asm/io.h>
26#include <linux/delay.h>
27#include <linux/interrupt.h>
28#include <linux/init.h>
29#include <sound/core.h>
30#include <sound/control.h>
31#include <sound/ak4xxx-adda.h>
32
33MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>");
34MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters");
35MODULE_LICENSE("GPL");
36
Takashi Iwai97f02e02005-11-17 14:17:19 +010037void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg, unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 ak->ops.lock(ak, chip);
40 ak->ops.write(ak, chip, reg, val);
41
42 /* save the data */
43 if (ak->type == SND_AK4524 || ak->type == SND_AK4528) {
44 if ((reg != 0x04 && reg != 0x05) || (val & 0x80) == 0)
45 snd_akm4xxx_set(ak, chip, reg, val);
46 else
47 snd_akm4xxx_set_ipga(ak, chip, reg, val);
48 } else {
49 /* AK4529, or else */
50 snd_akm4xxx_set(ak, chip, reg, val);
51 }
52 ak->ops.unlock(ak, chip);
53}
54
55/*
56 * reset the AKM codecs
57 * @state: 1 = reset codec, 0 = restore the registers
58 *
59 * assert the reset operation and restores the register values to the chips.
60 */
Takashi Iwai97f02e02005-11-17 14:17:19 +010061void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 unsigned int chip;
64 unsigned char reg;
65
66 switch (ak->type) {
67 case SND_AK4524:
68 case SND_AK4528:
69 for (chip = 0; chip < ak->num_dacs/2; chip++) {
70 snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
71 if (state)
72 continue;
73 /* DAC volumes */
74 for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
75 snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
76 if (ak->type == SND_AK4528)
77 continue;
78 /* IPGA */
79 for (reg = 0x04; reg < 0x06; reg++)
80 snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get_ipga(ak, chip, reg));
81 }
82 break;
83 case SND_AK4529:
84 /* FIXME: needed for ak4529? */
85 break;
86 case SND_AK4355:
87 case SND_AK4358:
88 if (state) {
89 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
90 return;
91 }
92 for (reg = 0x00; reg < 0x0b; reg++)
93 if (reg != 0x01)
94 snd_akm4xxx_write(ak, 0, reg, snd_akm4xxx_get(ak, 0, reg));
95 snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
96 break;
97 case SND_AK4381:
98 for (chip = 0; chip < ak->num_dacs/2; chip++) {
99 snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
100 if (state)
101 continue;
102 for (reg = 0x01; reg < 0x05; reg++)
103 snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
104 }
105 break;
106 }
107}
108
109/*
110 * initialize all the ak4xxx chips
111 */
Takashi Iwai97f02e02005-11-17 14:17:19 +0100112void snd_akm4xxx_init(struct snd_akm4xxx *ak)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 static unsigned char inits_ak4524[] = {
115 0x00, 0x07, /* 0: all power up */
116 0x01, 0x00, /* 1: ADC/DAC reset */
117 0x02, 0x60, /* 2: 24bit I2S */
118 0x03, 0x19, /* 3: deemphasis off */
119 0x01, 0x03, /* 1: ADC/DAC enable */
120 0x04, 0x00, /* 4: ADC left muted */
121 0x05, 0x00, /* 5: ADC right muted */
122 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
123 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
124 0x06, 0x00, /* 6: DAC left muted */
125 0x07, 0x00, /* 7: DAC right muted */
126 0xff, 0xff
127 };
128 static unsigned char inits_ak4528[] = {
129 0x00, 0x07, /* 0: all power up */
130 0x01, 0x00, /* 1: ADC/DAC reset */
131 0x02, 0x60, /* 2: 24bit I2S */
132 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
133 0x01, 0x03, /* 1: ADC/DAC enable */
134 0x04, 0x00, /* 4: ADC left muted */
135 0x05, 0x00, /* 5: ADC right muted */
136 0xff, 0xff
137 };
138 static unsigned char inits_ak4529[] = {
139 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
140 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
141 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
142 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
143 0x02, 0xff, /* 2: LOUT1 muted */
144 0x03, 0xff, /* 3: ROUT1 muted */
145 0x04, 0xff, /* 4: LOUT2 muted */
146 0x05, 0xff, /* 5: ROUT2 muted */
147 0x06, 0xff, /* 6: LOUT3 muted */
148 0x07, 0xff, /* 7: ROUT3 muted */
149 0x0b, 0xff, /* B: LOUT4 muted */
150 0x0c, 0xff, /* C: ROUT4 muted */
151 0x08, 0x55, /* 8: deemphasis all off */
152 0xff, 0xff
153 };
154 static unsigned char inits_ak4355[] = {
155 0x01, 0x02, /* 1: reset and soft-mute */
156 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
157 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
158 // 0x02, 0x2e, /* quad speed */
159 0x03, 0x01, /* 3: de-emphasis off */
160 0x04, 0x00, /* 4: LOUT1 volume muted */
161 0x05, 0x00, /* 5: ROUT1 volume muted */
162 0x06, 0x00, /* 6: LOUT2 volume muted */
163 0x07, 0x00, /* 7: ROUT2 volume muted */
164 0x08, 0x00, /* 8: LOUT3 volume muted */
165 0x09, 0x00, /* 9: ROUT3 volume muted */
166 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
167 0x01, 0x01, /* 1: un-reset, unmute */
168 0xff, 0xff
169 };
170 static unsigned char inits_ak4358[] = {
171 0x01, 0x02, /* 1: reset and soft-mute */
172 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
173 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
174 // 0x02, 0x2e, /* quad speed */
175 0x03, 0x01, /* 3: de-emphasis off */
176 0x04, 0x00, /* 4: LOUT1 volume muted */
177 0x05, 0x00, /* 5: ROUT1 volume muted */
178 0x06, 0x00, /* 6: LOUT2 volume muted */
179 0x07, 0x00, /* 7: ROUT2 volume muted */
180 0x08, 0x00, /* 8: LOUT3 volume muted */
181 0x09, 0x00, /* 9: ROUT3 volume muted */
182 0x0b, 0x00, /* b: LOUT4 volume muted */
183 0x0c, 0x00, /* c: ROUT4 volume muted */
184 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
185 0x01, 0x01, /* 1: un-reset, unmute */
186 0xff, 0xff
187 };
188 static unsigned char inits_ak4381[] = {
189 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
190 0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */
191 // 0x01, 0x12, /* quad speed */
192 0x02, 0x00, /* 2: DZF disabled */
193 0x03, 0x00, /* 3: LATT 0 */
194 0x04, 0x00, /* 4: RATT 0 */
195 0x00, 0x0f, /* 0: power-up, un-reset */
196 0xff, 0xff
197 };
198
199 int chip, num_chips;
200 unsigned char *ptr, reg, data, *inits;
201
202 switch (ak->type) {
203 case SND_AK4524:
204 inits = inits_ak4524;
205 num_chips = ak->num_dacs / 2;
206 break;
207 case SND_AK4528:
208 inits = inits_ak4528;
209 num_chips = ak->num_dacs / 2;
210 break;
211 case SND_AK4529:
212 inits = inits_ak4529;
213 num_chips = 1;
214 break;
215 case SND_AK4355:
216 inits = inits_ak4355;
217 num_chips = 1;
218 break;
219 case SND_AK4358:
220 inits = inits_ak4358;
221 num_chips = 1;
222 break;
223 case SND_AK4381:
224 inits = inits_ak4381;
225 num_chips = ak->num_dacs / 2;
226 break;
227 default:
228 snd_BUG();
229 return;
230 }
231
232 for (chip = 0; chip < num_chips; chip++) {
233 ptr = inits;
234 while (*ptr != 0xff) {
235 reg = *ptr++;
236 data = *ptr++;
237 snd_akm4xxx_write(ak, chip, reg, data);
238 }
239 }
240}
241
242#define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
243#define AK_GET_ADDR(val) ((val) & 0xff)
244#define AK_GET_SHIFT(val) (((val) >> 16) & 0x7f)
245#define AK_GET_INVERT(val) (((val) >> 23) & 1)
246#define AK_GET_MASK(val) (((val) >> 24) & 0xff)
247#define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
248#define AK_INVERT (1<<23)
249
Takashi Iwai97f02e02005-11-17 14:17:19 +0100250static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol,
251 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
254
255 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
256 uinfo->count = 1;
257 uinfo->value.integer.min = 0;
258 uinfo->value.integer.max = mask;
259 return 0;
260}
261
Takashi Iwai97f02e02005-11-17 14:17:19 +0100262static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Takashi Iwai97f02e02005-11-17 14:17:19 +0100265 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 int chip = AK_GET_CHIP(kcontrol->private_value);
267 int addr = AK_GET_ADDR(kcontrol->private_value);
268 int invert = AK_GET_INVERT(kcontrol->private_value);
269 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
270 unsigned char val = snd_akm4xxx_get(ak, chip, addr);
271
272 ucontrol->value.integer.value[0] = invert ? mask - val : val;
273 return 0;
274}
275
Takashi Iwai97f02e02005-11-17 14:17:19 +0100276static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol,
277 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Takashi Iwai97f02e02005-11-17 14:17:19 +0100279 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 int chip = AK_GET_CHIP(kcontrol->private_value);
281 int addr = AK_GET_ADDR(kcontrol->private_value);
282 int invert = AK_GET_INVERT(kcontrol->private_value);
283 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
284 unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
285 int change;
286
287 if (invert)
288 nval = mask - nval;
289 change = snd_akm4xxx_get(ak, chip, addr) != nval;
290 if (change)
291 snd_akm4xxx_write(ak, chip, addr, nval);
292 return change;
293}
294
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200295static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_info *uinfo)
297{
298 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
299
300 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
301 uinfo->count = 2;
302 uinfo->value.integer.min = 0;
303 uinfo->value.integer.max = mask;
304 return 0;
305}
306
307static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol,
308 struct snd_ctl_elem_value *ucontrol)
309{
310 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
311 int chip = AK_GET_CHIP(kcontrol->private_value);
312 int addr = AK_GET_ADDR(kcontrol->private_value);
313 int invert = AK_GET_INVERT(kcontrol->private_value);
314 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
315 unsigned char val = snd_akm4xxx_get(ak, chip, addr);
316
317 ucontrol->value.integer.value[0] = invert ? mask - val : val;
318
319 val = snd_akm4xxx_get(ak, chip, addr+1);
320 ucontrol->value.integer.value[1] = invert ? mask - val : val;
321
322 return 0;
323}
324
325static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
327{
328 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
329 int chip = AK_GET_CHIP(kcontrol->private_value);
330 int addr = AK_GET_ADDR(kcontrol->private_value);
331 int invert = AK_GET_INVERT(kcontrol->private_value);
332 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
333 unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
334 int change0, change1;
335
336 if (invert)
337 nval = mask - nval;
338 change0 = snd_akm4xxx_get(ak, chip, addr) != nval;
339 if (change0)
340 snd_akm4xxx_write(ak, chip, addr, nval);
341
342 nval = ucontrol->value.integer.value[1] % (mask+1);
343 if (invert)
344 nval = mask - nval;
345 change1 = snd_akm4xxx_get(ak, chip, addr+1) != nval;
346 if (change1)
347 snd_akm4xxx_write(ak, chip, addr+1, nval);
348
349
350 return change0 || change1;
351}
352
Takashi Iwai97f02e02005-11-17 14:17:19 +0100353static int snd_akm4xxx_ipga_gain_info(struct snd_kcontrol *kcontrol,
354 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
357 uinfo->count = 1;
358 uinfo->value.integer.min = 0;
359 uinfo->value.integer.max = 36;
360 return 0;
361}
362
Takashi Iwai97f02e02005-11-17 14:17:19 +0100363static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Takashi Iwai97f02e02005-11-17 14:17:19 +0100366 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 int chip = AK_GET_CHIP(kcontrol->private_value);
368 int addr = AK_GET_ADDR(kcontrol->private_value);
369 ucontrol->value.integer.value[0] = snd_akm4xxx_get_ipga(ak, chip, addr) & 0x7f;
370 return 0;
371}
372
Takashi Iwai97f02e02005-11-17 14:17:19 +0100373static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Takashi Iwai97f02e02005-11-17 14:17:19 +0100376 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 int chip = AK_GET_CHIP(kcontrol->private_value);
378 int addr = AK_GET_ADDR(kcontrol->private_value);
379 unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
380 int change = snd_akm4xxx_get_ipga(ak, chip, addr) != nval;
381 if (change)
382 snd_akm4xxx_write(ak, chip, addr, nval);
383 return change;
384}
385
Takashi Iwai97f02e02005-11-17 14:17:19 +0100386static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
387 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
389 static char *texts[4] = {
390 "44.1kHz", "Off", "48kHz", "32kHz",
391 };
392 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
393 uinfo->count = 1;
394 uinfo->value.enumerated.items = 4;
395 if (uinfo->value.enumerated.item >= 4)
396 uinfo->value.enumerated.item = 3;
397 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
398 return 0;
399}
400
Takashi Iwai97f02e02005-11-17 14:17:19 +0100401static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol,
402 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Takashi Iwai97f02e02005-11-17 14:17:19 +0100404 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int chip = AK_GET_CHIP(kcontrol->private_value);
406 int addr = AK_GET_ADDR(kcontrol->private_value);
407 int shift = AK_GET_SHIFT(kcontrol->private_value);
408 ucontrol->value.enumerated.item[0] = (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3;
409 return 0;
410}
411
Takashi Iwai97f02e02005-11-17 14:17:19 +0100412static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol,
413 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Takashi Iwai97f02e02005-11-17 14:17:19 +0100415 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 int chip = AK_GET_CHIP(kcontrol->private_value);
417 int addr = AK_GET_ADDR(kcontrol->private_value);
418 int shift = AK_GET_SHIFT(kcontrol->private_value);
419 unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
420 int change;
421
422 nval = (nval << shift) | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift));
423 change = snd_akm4xxx_get(ak, chip, addr) != nval;
424 if (change)
425 snd_akm4xxx_write(ak, chip, addr, nval);
426 return change;
427}
428
429/*
430 * build AK4xxx controls
431 */
432
Takashi Iwai97f02e02005-11-17 14:17:19 +0100433int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
435 unsigned int idx, num_emphs;
Takashi Iwai97f02e02005-11-17 14:17:19 +0100436 struct snd_kcontrol *ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 int err;
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200438 int mixer_ch = 0;
439 int num_stereo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 ctl = kmalloc(sizeof(*ctl), GFP_KERNEL);
442 if (! ctl)
443 return -ENOMEM;
444
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200445 for (idx = 0; idx < ak->num_dacs; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 memset(ctl, 0, sizeof(*ctl));
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200447 if (ak->channel_names == NULL) {
448 strcpy(ctl->id.name, "DAC Volume");
449 num_stereo = 1;
450 ctl->id.index = mixer_ch + ak->idx_offset * 2;
451 } else {
452 strcpy(ctl->id.name, ak->channel_names[mixer_ch]);
453 num_stereo = ak->num_stereo[mixer_ch];
454 ctl->id.index = 0; //mixer_ch + ak->idx_offset * 2;
455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
457 ctl->count = 1;
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200458 if (num_stereo == 2) {
459 ctl->info = snd_akm4xxx_stereo_volume_info;
460 ctl->get = snd_akm4xxx_stereo_volume_get;
461 ctl->put = snd_akm4xxx_stereo_volume_put;
462 } else {
463 ctl->info = snd_akm4xxx_volume_info;
464 ctl->get = snd_akm4xxx_volume_get;
465 ctl->put = snd_akm4xxx_volume_put;
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 switch (ak->type) {
468 case SND_AK4524:
469 ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */
470 break;
471 case SND_AK4528:
472 ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
473 break;
474 case SND_AK4529: {
475 int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
476 ctl->private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
477 break;
478 }
479 case SND_AK4355:
480 ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
481 break;
482 case SND_AK4358:
483 if (idx >= 6)
484 ctl->private_value = AK_COMPOSE(0, idx + 5, 0, 255); /* register 4-9, chip #0 only */
485 else
486 ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
487 break;
488 case SND_AK4381:
489 ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */
490 break;
491 default:
492 err = -EINVAL;
493 goto __error;
494 }
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 ctl->private_data = ak;
497 if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
498 goto __error;
Jani Alinikulac83c0c42006-06-27 15:00:55 +0200499
500 idx += num_stereo;
501 mixer_ch++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
504 memset(ctl, 0, sizeof(*ctl));
505 strcpy(ctl->id.name, "ADC Volume");
506 ctl->id.index = idx + ak->idx_offset * 2;
507 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
508 ctl->count = 1;
509 ctl->info = snd_akm4xxx_volume_info;
510 ctl->get = snd_akm4xxx_volume_get;
511 ctl->put = snd_akm4xxx_volume_put;
512 ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
513 ctl->private_data = ak;
514 if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
515 goto __error;
516
517 memset(ctl, 0, sizeof(*ctl));
518 strcpy(ctl->id.name, "IPGA Analog Capture Volume");
519 ctl->id.index = idx + ak->idx_offset * 2;
520 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
521 ctl->count = 1;
522 ctl->info = snd_akm4xxx_ipga_gain_info;
523 ctl->get = snd_akm4xxx_ipga_gain_get;
524 ctl->put = snd_akm4xxx_ipga_gain_put;
525 ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */
526 ctl->private_data = ak;
527 if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
528 goto __error;
529 }
530 if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
531 num_emphs = 1;
532 else
533 num_emphs = ak->num_dacs / 2;
534 for (idx = 0; idx < num_emphs; idx++) {
535 memset(ctl, 0, sizeof(*ctl));
536 strcpy(ctl->id.name, "Deemphasis");
537 ctl->id.index = idx + ak->idx_offset;
538 ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
539 ctl->count = 1;
540 ctl->info = snd_akm4xxx_deemphasis_info;
541 ctl->get = snd_akm4xxx_deemphasis_get;
542 ctl->put = snd_akm4xxx_deemphasis_put;
543 switch (ak->type) {
544 case SND_AK4524:
545 case SND_AK4528:
546 ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */
547 break;
548 case SND_AK4529: {
549 int shift = idx == 3 ? 6 : (2 - idx) * 2;
550 ctl->private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */
551 break;
552 }
553 case SND_AK4355:
554 case SND_AK4358:
555 ctl->private_value = AK_COMPOSE(idx, 3, 0, 0);
556 break;
557 case SND_AK4381:
558 ctl->private_value = AK_COMPOSE(idx, 1, 1, 0);
559 break;
560 }
561 ctl->private_data = ak;
562 if ((err = snd_ctl_add(ak->card, snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
563 goto __error;
564 }
565 err = 0;
566
567 __error:
568 kfree(ctl);
569 return err;
570}
571
572static int __init alsa_akm4xxx_module_init(void)
573{
574 return 0;
575}
576
577static void __exit alsa_akm4xxx_module_exit(void)
578{
579}
580
581module_init(alsa_akm4xxx_module_init)
582module_exit(alsa_akm4xxx_module_exit)
583
584EXPORT_SYMBOL(snd_akm4xxx_write);
585EXPORT_SYMBOL(snd_akm4xxx_reset);
586EXPORT_SYMBOL(snd_akm4xxx_init);
587EXPORT_SYMBOL(snd_akm4xxx_build_controls);