2 * ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381
5 * Copyright (c) 2000-2004 Jaroslav Kysela <perex@suse.cz>,
6 * Takashi Iwai <tiwai@suse.de>
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.
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, MA 02111-1307 USA
24 #include <sound/driver.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/tlv.h>
32 #include <sound/ak4xxx-adda.h>
34 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>");
35 MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters");
36 MODULE_LICENSE("GPL");
38 /* write the given register and save the data to the cache */
39 void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg,
42 ak->ops.lock(ak, chip);
43 ak->ops.write(ak, chip, reg, val);
46 /* don't overwrite with IPGA data */
47 if ((ak->type != SND_AK4524 && ak->type != SND_AK5365) ||
48 (reg != 0x04 && reg != 0x05) || (val & 0x80) == 0)
49 snd_akm4xxx_set(ak, chip, reg, val);
50 ak->ops.unlock(ak, chip);
53 EXPORT_SYMBOL(snd_akm4xxx_write);
55 /* reset procedure for AK4524 and AK4528 */
56 static void ak4524_reset(struct snd_akm4xxx *ak, int state)
59 unsigned char reg, maxreg;
61 if (ak->type == SND_AK4528)
65 for (chip = 0; chip < ak->num_dacs/2; chip++) {
66 snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
70 for (reg = 0x04; reg < maxreg; reg++)
71 snd_akm4xxx_write(ak, chip, reg,
72 snd_akm4xxx_get(ak, chip, reg));
73 if (ak->type == SND_AK4528)
76 for (reg = 0x04; reg < 0x06; reg++)
77 snd_akm4xxx_write(ak, chip, reg,
78 snd_akm4xxx_get_ipga(ak, chip, reg) | 0x80);
82 /* reset procedure for AK4355 and AK4358 */
83 static void ak4355_reset(struct snd_akm4xxx *ak, int state)
88 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
91 for (reg = 0x00; reg < 0x0b; reg++)
93 snd_akm4xxx_write(ak, 0, reg,
94 snd_akm4xxx_get(ak, 0, reg));
95 snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
98 /* reset procedure for AK4381 */
99 static void ak4381_reset(struct snd_akm4xxx *ak, int state)
104 for (chip = 0; chip < ak->num_dacs/2; chip++) {
105 snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
108 for (reg = 0x01; reg < 0x05; reg++)
109 snd_akm4xxx_write(ak, chip, reg,
110 snd_akm4xxx_get(ak, chip, reg));
115 * reset the AKM codecs
116 * @state: 1 = reset codec, 0 = restore the registers
118 * assert the reset operation and restores the register values to the chips.
120 void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
125 ak4524_reset(ak, state);
128 /* FIXME: needed for ak4529? */
132 ak4355_reset(ak, state);
135 ak4381_reset(ak, state);
142 EXPORT_SYMBOL(snd_akm4xxx_reset);
146 * Volume conversion table for non-linear volumes
147 * from -63.5dB (mute) to 0dB step 0.5dB
149 * Used for AK4524 input/ouput attenuation, AK4528, and
150 * AK5365 input attenuation
152 static unsigned char vol_cvt_datt[128] = {
153 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04,
154 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06,
155 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x09, 0x0a,
156 0x0a, 0x0b, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x0f,
157 0x10, 0x10, 0x11, 0x12, 0x12, 0x13, 0x13, 0x14,
158 0x15, 0x16, 0x17, 0x17, 0x18, 0x19, 0x1a, 0x1c,
159 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x23,
160 0x24, 0x25, 0x26, 0x28, 0x29, 0x2a, 0x2b, 0x2d,
161 0x2e, 0x30, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
162 0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3e, 0x3f, 0x40,
163 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x48, 0x4a,
164 0x4b, 0x4d, 0x4e, 0x50, 0x51, 0x52, 0x53, 0x54,
165 0x55, 0x56, 0x58, 0x59, 0x5b, 0x5c, 0x5e, 0x5f,
166 0x60, 0x61, 0x62, 0x64, 0x65, 0x66, 0x67, 0x69,
167 0x6a, 0x6c, 0x6d, 0x6f, 0x70, 0x71, 0x72, 0x73,
168 0x75, 0x76, 0x77, 0x79, 0x7a, 0x7c, 0x7d, 0x7f,
174 static DECLARE_TLV_DB_SCALE(db_scale_vol_datt, -6350, 50, 1);
175 static DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750, 50, 1);
176 static DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350, 50, 1);
177 static DECLARE_TLV_DB_LINEAR(db_scale_linear, TLV_DB_GAIN_MUTE, 0);
178 static DECLARE_TLV_DB_SCALE(db_scale_ipga, 0, 50, 0);
181 * initialize all the ak4xxx chips
183 void snd_akm4xxx_init(struct snd_akm4xxx *ak)
185 static unsigned char inits_ak4524[] = {
186 0x00, 0x07, /* 0: all power up */
187 0x01, 0x00, /* 1: ADC/DAC reset */
188 0x02, 0x60, /* 2: 24bit I2S */
189 0x03, 0x19, /* 3: deemphasis off */
190 0x01, 0x03, /* 1: ADC/DAC enable */
191 0x04, 0x00, /* 4: ADC left muted */
192 0x05, 0x00, /* 5: ADC right muted */
193 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
194 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
195 0x06, 0x00, /* 6: DAC left muted */
196 0x07, 0x00, /* 7: DAC right muted */
199 static unsigned char inits_ak4528[] = {
200 0x00, 0x07, /* 0: all power up */
201 0x01, 0x00, /* 1: ADC/DAC reset */
202 0x02, 0x60, /* 2: 24bit I2S */
203 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
204 0x01, 0x03, /* 1: ADC/DAC enable */
205 0x04, 0x00, /* 4: ADC left muted */
206 0x05, 0x00, /* 5: ADC right muted */
209 static unsigned char inits_ak4529[] = {
210 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
211 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
212 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
213 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
214 0x02, 0xff, /* 2: LOUT1 muted */
215 0x03, 0xff, /* 3: ROUT1 muted */
216 0x04, 0xff, /* 4: LOUT2 muted */
217 0x05, 0xff, /* 5: ROUT2 muted */
218 0x06, 0xff, /* 6: LOUT3 muted */
219 0x07, 0xff, /* 7: ROUT3 muted */
220 0x0b, 0xff, /* B: LOUT4 muted */
221 0x0c, 0xff, /* C: ROUT4 muted */
222 0x08, 0x55, /* 8: deemphasis all off */
225 static unsigned char inits_ak4355[] = {
226 0x01, 0x02, /* 1: reset and soft-mute */
227 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect,
228 * disable DZF, sharp roll-off, RSTN#=0 */
229 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
230 // 0x02, 0x2e, /* quad speed */
231 0x03, 0x01, /* 3: de-emphasis off */
232 0x04, 0x00, /* 4: LOUT1 volume muted */
233 0x05, 0x00, /* 5: ROUT1 volume muted */
234 0x06, 0x00, /* 6: LOUT2 volume muted */
235 0x07, 0x00, /* 7: ROUT2 volume muted */
236 0x08, 0x00, /* 8: LOUT3 volume muted */
237 0x09, 0x00, /* 9: ROUT3 volume muted */
238 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
239 0x01, 0x01, /* 1: un-reset, unmute */
242 static unsigned char inits_ak4358[] = {
243 0x01, 0x02, /* 1: reset and soft-mute */
244 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect,
245 * disable DZF, sharp roll-off, RSTN#=0 */
246 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
247 // 0x02, 0x2e, /* quad speed */
248 0x03, 0x01, /* 3: de-emphasis off */
249 0x04, 0x00, /* 4: LOUT1 volume muted */
250 0x05, 0x00, /* 5: ROUT1 volume muted */
251 0x06, 0x00, /* 6: LOUT2 volume muted */
252 0x07, 0x00, /* 7: ROUT2 volume muted */
253 0x08, 0x00, /* 8: LOUT3 volume muted */
254 0x09, 0x00, /* 9: ROUT3 volume muted */
255 0x0b, 0x00, /* b: LOUT4 volume muted */
256 0x0c, 0x00, /* c: ROUT4 volume muted */
257 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
258 0x01, 0x01, /* 1: un-reset, unmute */
261 static unsigned char inits_ak4381[] = {
262 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
263 0x01, 0x02, /* 1: de-emphasis off, normal speed,
264 * sharp roll-off, DZF off */
265 // 0x01, 0x12, /* quad speed */
266 0x02, 0x00, /* 2: DZF disabled */
267 0x03, 0x00, /* 3: LATT 0 */
268 0x04, 0x00, /* 4: RATT 0 */
269 0x00, 0x0f, /* 0: power-up, un-reset */
274 unsigned char *ptr, reg, data, *inits;
276 memset(ak->images, 0, sizeof(ak->images));
277 memset(ak->volumes, 0, sizeof(ak->volumes));
281 inits = inits_ak4524;
282 num_chips = ak->num_dacs / 2;
285 inits = inits_ak4528;
286 num_chips = ak->num_dacs / 2;
289 inits = inits_ak4529;
293 inits = inits_ak4355;
297 inits = inits_ak4358;
301 inits = inits_ak4381;
302 num_chips = ak->num_dacs / 2;
305 /* FIXME: any init sequence? */
312 for (chip = 0; chip < num_chips; chip++) {
314 while (*ptr != 0xff) {
317 snd_akm4xxx_write(ak, chip, reg, data);
322 EXPORT_SYMBOL(snd_akm4xxx_init);
327 #define AK_VOL_CVT (1<<21) /* need dB conversion */
328 #define AK_NEEDSMSB (1<<22) /* need MSB update bit */
329 #define AK_INVERT (1<<23) /* data is inverted */
330 #define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
331 #define AK_GET_ADDR(val) ((val) & 0xff)
332 #define AK_GET_SHIFT(val) (((val) >> 16) & 0x1f)
333 #define AK_GET_VOL_CVT(val) (((val) >> 21) & 1)
334 #define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1)
335 #define AK_GET_INVERT(val) (((val) >> 23) & 1)
336 #define AK_GET_MASK(val) (((val) >> 24) & 0xff)
337 #define AK_COMPOSE(chip,addr,shift,mask) \
338 (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
340 static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_info *uinfo)
343 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
345 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
347 uinfo->value.integer.min = 0;
348 uinfo->value.integer.max = mask;
352 static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_value *ucontrol)
355 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
356 int chip = AK_GET_CHIP(kcontrol->private_value);
357 int addr = AK_GET_ADDR(kcontrol->private_value);
359 ucontrol->value.integer.value[0] = snd_akm4xxx_get_vol(ak, chip, addr);
363 static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr,
366 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
367 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
368 int chip = AK_GET_CHIP(kcontrol->private_value);
370 if (snd_akm4xxx_get_vol(ak, chip, addr) == nval)
373 snd_akm4xxx_set_vol(ak, chip, addr, nval);
374 if (AK_GET_VOL_CVT(kcontrol->private_value))
375 nval = vol_cvt_datt[nval];
376 if (AK_GET_INVERT(kcontrol->private_value))
378 if (AK_GET_NEEDSMSB(kcontrol->private_value))
380 snd_akm4xxx_write(ak, chip, addr, nval);
384 static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol)
387 return put_ak_reg(kcontrol, AK_GET_ADDR(kcontrol->private_value),
388 ucontrol->value.integer.value[0]);
391 static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol,
392 struct snd_ctl_elem_info *uinfo)
394 unsigned int mask = AK_GET_MASK(kcontrol->private_value);
396 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
398 uinfo->value.integer.min = 0;
399 uinfo->value.integer.max = mask;
403 static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_value *ucontrol)
406 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
407 int chip = AK_GET_CHIP(kcontrol->private_value);
408 int addr = AK_GET_ADDR(kcontrol->private_value);
410 ucontrol->value.integer.value[0] = snd_akm4xxx_get_vol(ak, chip, addr);
411 ucontrol->value.integer.value[1] = snd_akm4xxx_get_vol(ak, chip, addr+1);
415 static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
416 struct snd_ctl_elem_value *ucontrol)
418 int addr = AK_GET_ADDR(kcontrol->private_value);
421 change = put_ak_reg(kcontrol, addr, ucontrol->value.integer.value[0]);
422 change |= put_ak_reg(kcontrol, addr + 1,
423 ucontrol->value.integer.value[1]);
427 #define snd_akm4xxx_ipga_gain_info snd_akm4xxx_volume_info
429 static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol,
430 struct snd_ctl_elem_value *ucontrol)
432 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
433 int chip = AK_GET_CHIP(kcontrol->private_value);
434 int addr = AK_GET_ADDR(kcontrol->private_value);
436 ucontrol->value.integer.value[0] =
437 snd_akm4xxx_get_ipga(ak, chip, addr);
441 static int put_ak_ipga(struct snd_kcontrol *kcontrol, int addr,
444 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
445 int chip = AK_GET_CHIP(kcontrol->private_value);
447 if (snd_akm4xxx_get_ipga(ak, chip, addr) == nval)
449 snd_akm4xxx_set_ipga(ak, chip, addr, nval);
450 snd_akm4xxx_write(ak, chip, addr, nval | 0x80); /* need MSB */
454 static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol,
455 struct snd_ctl_elem_value *ucontrol)
457 return put_ak_ipga(kcontrol, AK_GET_ADDR(kcontrol->private_value),
458 ucontrol->value.integer.value[0]);
461 #define snd_akm4xxx_stereo_gain_info snd_akm4xxx_stereo_volume_info
463 static int snd_akm4xxx_stereo_gain_get(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_value *ucontrol)
466 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
467 int chip = AK_GET_CHIP(kcontrol->private_value);
468 int addr = AK_GET_ADDR(kcontrol->private_value);
470 ucontrol->value.integer.value[0] =
471 snd_akm4xxx_get_ipga(ak, chip, addr);
472 ucontrol->value.integer.value[1] =
473 snd_akm4xxx_get_ipga(ak, chip, addr + 1);
477 static int snd_akm4xxx_stereo_gain_put(struct snd_kcontrol *kcontrol,
478 struct snd_ctl_elem_value *ucontrol)
480 int addr = AK_GET_ADDR(kcontrol->private_value);
483 change = put_ak_ipga(kcontrol, addr, ucontrol->value.integer.value[0]);
484 change |= put_ak_ipga(kcontrol, addr + 1,
485 ucontrol->value.integer.value[1]);
489 static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
490 struct snd_ctl_elem_info *uinfo)
492 static char *texts[4] = {
493 "44.1kHz", "Off", "48kHz", "32kHz",
495 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
497 uinfo->value.enumerated.items = 4;
498 if (uinfo->value.enumerated.item >= 4)
499 uinfo->value.enumerated.item = 3;
500 strcpy(uinfo->value.enumerated.name,
501 texts[uinfo->value.enumerated.item]);
505 static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol,
506 struct snd_ctl_elem_value *ucontrol)
508 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
509 int chip = AK_GET_CHIP(kcontrol->private_value);
510 int addr = AK_GET_ADDR(kcontrol->private_value);
511 int shift = AK_GET_SHIFT(kcontrol->private_value);
512 ucontrol->value.enumerated.item[0] =
513 (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3;
517 static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol,
518 struct snd_ctl_elem_value *ucontrol)
520 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
521 int chip = AK_GET_CHIP(kcontrol->private_value);
522 int addr = AK_GET_ADDR(kcontrol->private_value);
523 int shift = AK_GET_SHIFT(kcontrol->private_value);
524 unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
527 nval = (nval << shift) |
528 (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift));
529 change = snd_akm4xxx_get(ak, chip, addr) != nval;
531 snd_akm4xxx_write(ak, chip, addr, nval);
535 static int ak4xxx_switch_info(struct snd_kcontrol *kcontrol,
536 struct snd_ctl_elem_info *uinfo)
538 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
540 uinfo->value.integer.min = 0;
541 uinfo->value.integer.max = 1;
545 static int ak4xxx_switch_get(struct snd_kcontrol *kcontrol,
546 struct snd_ctl_elem_value *ucontrol)
548 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
549 int chip = AK_GET_CHIP(kcontrol->private_value);
550 int addr = AK_GET_ADDR(kcontrol->private_value);
551 int shift = AK_GET_SHIFT(kcontrol->private_value);
552 int invert = AK_GET_INVERT(kcontrol->private_value);
553 unsigned char val = snd_akm4xxx_get(ak, chip, addr);
557 ucontrol->value.integer.value[0] = (val & (1<<shift)) != 0;
561 static int ak4xxx_switch_put(struct snd_kcontrol *kcontrol,
562 struct snd_ctl_elem_value *ucontrol)
564 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
565 int chip = AK_GET_CHIP(kcontrol->private_value);
566 int addr = AK_GET_ADDR(kcontrol->private_value);
567 int shift = AK_GET_SHIFT(kcontrol->private_value);
568 int invert = AK_GET_INVERT(kcontrol->private_value);
569 long flag = ucontrol->value.integer.value[0];
570 unsigned char val, oval;
575 oval = snd_akm4xxx_get(ak, chip, addr);
577 val = oval | (1<<shift);
579 val = oval & ~(1<<shift);
580 change = (oval != val);
582 snd_akm4xxx_write(ak, chip, addr, val);
587 * build AK4xxx controls
590 static int build_dac_controls(struct snd_akm4xxx *ak)
592 int idx, err, mixer_ch, num_stereo;
593 struct snd_kcontrol_new knew;
596 for (idx = 0; idx < ak->num_dacs; ) {
597 memset(&knew, 0, sizeof(knew));
598 if (! ak->dac_info || ! ak->dac_info[mixer_ch].name) {
599 knew.name = "DAC Volume";
600 knew.index = mixer_ch + ak->idx_offset * 2;
603 knew.name = ak->dac_info[mixer_ch].name;
604 num_stereo = ak->dac_info[mixer_ch].num_channels;
606 knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
608 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
609 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
610 if (num_stereo == 2) {
611 knew.info = snd_akm4xxx_stereo_volume_info;
612 knew.get = snd_akm4xxx_stereo_volume_get;
613 knew.put = snd_akm4xxx_stereo_volume_put;
615 knew.info = snd_akm4xxx_volume_info;
616 knew.get = snd_akm4xxx_volume_get;
617 knew.put = snd_akm4xxx_volume_put;
623 AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127) |
625 knew.tlv.p = db_scale_vol_datt;
630 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127) |
632 knew.tlv.p = db_scale_vol_datt;
635 /* registers 2-7 and b,c */
636 int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb;
638 AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
639 knew.tlv.p = db_scale_8bit;
643 /* register 4-9, chip #0 only */
644 knew.private_value = AK_COMPOSE(0, idx + 4, 0, 255);
645 knew.tlv.p = db_scale_8bit;
648 /* register 4-9 and 11-12, chip #0 only */
649 int addr = idx < 6 ? idx + 4 : idx + 5;
651 AK_COMPOSE(0, addr, 0, 127) | AK_NEEDSMSB;
652 knew.tlv.p = db_scale_7bit;
658 AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255);
659 knew.tlv.p = db_scale_linear;
665 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
675 static int build_adc_controls(struct snd_akm4xxx *ak)
677 int idx, err, mixer_ch, num_stereo;
678 struct snd_kcontrol_new knew;
681 for (idx = 0; idx < ak->num_adcs;) {
682 memset(&knew, 0, sizeof(knew));
683 if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) {
684 knew.name = "ADC Volume";
685 knew.index = mixer_ch + ak->idx_offset * 2;
688 knew.name = ak->adc_info[mixer_ch].name;
689 num_stereo = ak->adc_info[mixer_ch].num_channels;
691 knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
693 knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
694 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
695 if (num_stereo == 2) {
696 knew.info = snd_akm4xxx_stereo_volume_info;
697 knew.get = snd_akm4xxx_stereo_volume_get;
698 knew.put = snd_akm4xxx_stereo_volume_put;
700 knew.info = snd_akm4xxx_volume_info;
701 knew.get = snd_akm4xxx_volume_get;
702 knew.put = snd_akm4xxx_volume_put;
706 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127) |
708 knew.tlv.p = db_scale_vol_datt;
709 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
713 if (! ak->adc_info || ! ak->adc_info[mixer_ch].gain_name)
714 knew.name = "IPGA Analog Capture Volume";
716 knew.name = ak->adc_info[mixer_ch].gain_name;
717 if (num_stereo == 2) {
718 knew.info = snd_akm4xxx_stereo_gain_info;
719 knew.get = snd_akm4xxx_stereo_gain_get;
720 knew.put = snd_akm4xxx_stereo_gain_put;
722 knew.info = snd_akm4xxx_ipga_gain_info;
723 knew.get = snd_akm4xxx_ipga_gain_get;
724 knew.put = snd_akm4xxx_ipga_gain_put;
727 if (ak->type == SND_AK4524)
728 knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0,
731 knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0,
733 knew.tlv.p = db_scale_ipga;
734 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
738 if (ak->type == SND_AK5365 && (idx % 2) == 0) {
739 if (! ak->adc_info ||
740 ! ak->adc_info[mixer_ch].switch_name)
741 knew.name = "Capture Switch";
743 knew.name = ak->adc_info[mixer_ch].switch_name;
744 knew.info = ak4xxx_switch_info;
745 knew.get = ak4xxx_switch_get;
746 knew.put = ak4xxx_switch_put;
748 /* register 2, bit 0 (SMUTE): 0 = normal operation,
751 AK_COMPOSE(idx/2, 2, 0, 0) | AK_INVERT;
752 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
763 static int build_deemphasis(struct snd_akm4xxx *ak, int num_emphs)
766 struct snd_kcontrol_new knew;
768 for (idx = 0; idx < num_emphs; idx++) {
769 memset(&knew, 0, sizeof(knew));
770 knew.name = "Deemphasis";
771 knew.index = idx + ak->idx_offset;
772 knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
774 knew.info = snd_akm4xxx_deemphasis_info;
775 knew.get = snd_akm4xxx_deemphasis_get;
776 knew.put = snd_akm4xxx_deemphasis_put;
781 knew.private_value = AK_COMPOSE(idx, 3, 0, 0);
784 int shift = idx == 3 ? 6 : (2 - idx) * 2;
785 /* register 8 with shift */
786 knew.private_value = AK_COMPOSE(0, 8, shift, 0);
791 knew.private_value = AK_COMPOSE(idx, 3, 0, 0);
794 knew.private_value = AK_COMPOSE(idx, 1, 1, 0);
799 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
806 int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
810 err = build_dac_controls(ak);
814 if (ak->type == SND_AK4524 || ak->type == SND_AK5365) {
815 err = build_adc_controls(ak);
820 if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
823 num_emphs = ak->num_dacs / 2;
824 err = build_deemphasis(ak, num_emphs);
831 EXPORT_SYMBOL(snd_akm4xxx_build_controls);
833 static int __init alsa_akm4xxx_module_init(void)
838 static void __exit alsa_akm4xxx_module_exit(void)
842 module_init(alsa_akm4xxx_module_init)
843 module_exit(alsa_akm4xxx_module_exit)