Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 33 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>"); |
| 34 | MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 37 | void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg, |
| 38 | unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | ak->ops.lock(ak, chip); |
| 41 | ak->ops.write(ak, chip, reg, val); |
| 42 | |
| 43 | /* save the data */ |
| 44 | if (ak->type == SND_AK4524 || ak->type == SND_AK4528) { |
| 45 | if ((reg != 0x04 && reg != 0x05) || (val & 0x80) == 0) |
| 46 | snd_akm4xxx_set(ak, chip, reg, val); |
| 47 | else |
| 48 | snd_akm4xxx_set_ipga(ak, chip, reg, val); |
| 49 | } else { |
| 50 | /* AK4529, or else */ |
| 51 | snd_akm4xxx_set(ak, chip, reg, val); |
| 52 | } |
| 53 | ak->ops.unlock(ak, chip); |
| 54 | } |
| 55 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 56 | EXPORT_SYMBOL(snd_akm4xxx_write); |
| 57 | |
| 58 | /* reset procedure for AK4524 and AK4528 */ |
| 59 | static void ak4524_reset(struct snd_akm4xxx *ak, int state) |
| 60 | { |
| 61 | unsigned int chip; |
| 62 | unsigned char reg, maxreg; |
| 63 | |
| 64 | if (ak->type == SND_AK4528) |
| 65 | maxreg = 0x06; |
| 66 | else |
| 67 | maxreg = 0x08; |
| 68 | for (chip = 0; chip < ak->num_dacs/2; chip++) { |
| 69 | snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03); |
| 70 | if (state) |
| 71 | continue; |
| 72 | /* DAC volumes */ |
| 73 | for (reg = 0x04; reg < maxreg; reg++) |
| 74 | snd_akm4xxx_write(ak, chip, reg, |
| 75 | 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, |
| 81 | snd_akm4xxx_get_ipga(ak, chip, reg)); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /* reset procedure for AK4355 and AK4358 */ |
| 86 | static void ak4355_reset(struct snd_akm4xxx *ak, int state) |
| 87 | { |
| 88 | unsigned char reg; |
| 89 | |
| 90 | if (state) { |
| 91 | snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ |
| 92 | return; |
| 93 | } |
| 94 | for (reg = 0x00; reg < 0x0b; reg++) |
| 95 | if (reg != 0x01) |
| 96 | snd_akm4xxx_write(ak, 0, reg, |
| 97 | snd_akm4xxx_get(ak, 0, reg)); |
| 98 | snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */ |
| 99 | } |
| 100 | |
| 101 | /* reset procedure for AK4381 */ |
| 102 | static void ak4381_reset(struct snd_akm4xxx *ak, int state) |
| 103 | { |
| 104 | unsigned int chip; |
| 105 | unsigned char reg; |
| 106 | |
| 107 | for (chip = 0; chip < ak->num_dacs/2; chip++) { |
| 108 | snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f); |
| 109 | if (state) |
| 110 | continue; |
| 111 | for (reg = 0x01; reg < 0x05; reg++) |
| 112 | snd_akm4xxx_write(ak, chip, reg, |
| 113 | snd_akm4xxx_get(ak, chip, reg)); |
| 114 | } |
| 115 | } |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* |
| 118 | * reset the AKM codecs |
| 119 | * @state: 1 = reset codec, 0 = restore the registers |
| 120 | * |
| 121 | * assert the reset operation and restores the register values to the chips. |
| 122 | */ |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 123 | void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | switch (ak->type) { |
| 126 | case SND_AK4524: |
| 127 | case SND_AK4528: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 128 | ak4524_reset(ak, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | break; |
| 130 | case SND_AK4529: |
| 131 | /* FIXME: needed for ak4529? */ |
| 132 | break; |
| 133 | case SND_AK4355: |
| 134 | case SND_AK4358: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 135 | ak4355_reset(ak, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | break; |
| 137 | case SND_AK4381: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 138 | ak4381_reset(ak, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | break; |
Takashi Iwai | cf93907 | 2006-08-09 14:33:27 +0200 | [diff] [blame] | 140 | default: |
| 141 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 145 | EXPORT_SYMBOL(snd_akm4xxx_reset); |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* |
| 148 | * initialize all the ak4xxx chips |
| 149 | */ |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 150 | void snd_akm4xxx_init(struct snd_akm4xxx *ak) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
| 152 | static unsigned char inits_ak4524[] = { |
| 153 | 0x00, 0x07, /* 0: all power up */ |
| 154 | 0x01, 0x00, /* 1: ADC/DAC reset */ |
| 155 | 0x02, 0x60, /* 2: 24bit I2S */ |
| 156 | 0x03, 0x19, /* 3: deemphasis off */ |
| 157 | 0x01, 0x03, /* 1: ADC/DAC enable */ |
| 158 | 0x04, 0x00, /* 4: ADC left muted */ |
| 159 | 0x05, 0x00, /* 5: ADC right muted */ |
| 160 | 0x04, 0x80, /* 4: ADC IPGA gain 0dB */ |
| 161 | 0x05, 0x80, /* 5: ADC IPGA gain 0dB */ |
| 162 | 0x06, 0x00, /* 6: DAC left muted */ |
| 163 | 0x07, 0x00, /* 7: DAC right muted */ |
| 164 | 0xff, 0xff |
| 165 | }; |
| 166 | static unsigned char inits_ak4528[] = { |
| 167 | 0x00, 0x07, /* 0: all power up */ |
| 168 | 0x01, 0x00, /* 1: ADC/DAC reset */ |
| 169 | 0x02, 0x60, /* 2: 24bit I2S */ |
| 170 | 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */ |
| 171 | 0x01, 0x03, /* 1: ADC/DAC enable */ |
| 172 | 0x04, 0x00, /* 4: ADC left muted */ |
| 173 | 0x05, 0x00, /* 5: ADC right muted */ |
| 174 | 0xff, 0xff |
| 175 | }; |
| 176 | static unsigned char inits_ak4529[] = { |
| 177 | 0x09, 0x01, /* 9: ATS=0, RSTN=1 */ |
| 178 | 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */ |
| 179 | 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */ |
| 180 | 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */ |
| 181 | 0x02, 0xff, /* 2: LOUT1 muted */ |
| 182 | 0x03, 0xff, /* 3: ROUT1 muted */ |
| 183 | 0x04, 0xff, /* 4: LOUT2 muted */ |
| 184 | 0x05, 0xff, /* 5: ROUT2 muted */ |
| 185 | 0x06, 0xff, /* 6: LOUT3 muted */ |
| 186 | 0x07, 0xff, /* 7: ROUT3 muted */ |
| 187 | 0x0b, 0xff, /* B: LOUT4 muted */ |
| 188 | 0x0c, 0xff, /* C: ROUT4 muted */ |
| 189 | 0x08, 0x55, /* 8: deemphasis all off */ |
| 190 | 0xff, 0xff |
| 191 | }; |
| 192 | static unsigned char inits_ak4355[] = { |
| 193 | 0x01, 0x02, /* 1: reset and soft-mute */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 194 | 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, |
| 195 | * disable DZF, sharp roll-off, RSTN#=0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */ |
| 197 | // 0x02, 0x2e, /* quad speed */ |
| 198 | 0x03, 0x01, /* 3: de-emphasis off */ |
| 199 | 0x04, 0x00, /* 4: LOUT1 volume muted */ |
| 200 | 0x05, 0x00, /* 5: ROUT1 volume muted */ |
| 201 | 0x06, 0x00, /* 6: LOUT2 volume muted */ |
| 202 | 0x07, 0x00, /* 7: ROUT2 volume muted */ |
| 203 | 0x08, 0x00, /* 8: LOUT3 volume muted */ |
| 204 | 0x09, 0x00, /* 9: ROUT3 volume muted */ |
| 205 | 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */ |
| 206 | 0x01, 0x01, /* 1: un-reset, unmute */ |
| 207 | 0xff, 0xff |
| 208 | }; |
| 209 | static unsigned char inits_ak4358[] = { |
| 210 | 0x01, 0x02, /* 1: reset and soft-mute */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 211 | 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, |
| 212 | * disable DZF, sharp roll-off, RSTN#=0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */ |
| 214 | // 0x02, 0x2e, /* quad speed */ |
| 215 | 0x03, 0x01, /* 3: de-emphasis off */ |
| 216 | 0x04, 0x00, /* 4: LOUT1 volume muted */ |
| 217 | 0x05, 0x00, /* 5: ROUT1 volume muted */ |
| 218 | 0x06, 0x00, /* 6: LOUT2 volume muted */ |
| 219 | 0x07, 0x00, /* 7: ROUT2 volume muted */ |
| 220 | 0x08, 0x00, /* 8: LOUT3 volume muted */ |
| 221 | 0x09, 0x00, /* 9: ROUT3 volume muted */ |
| 222 | 0x0b, 0x00, /* b: LOUT4 volume muted */ |
| 223 | 0x0c, 0x00, /* c: ROUT4 volume muted */ |
| 224 | 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */ |
| 225 | 0x01, 0x01, /* 1: un-reset, unmute */ |
| 226 | 0xff, 0xff |
| 227 | }; |
| 228 | static unsigned char inits_ak4381[] = { |
| 229 | 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 230 | 0x01, 0x02, /* 1: de-emphasis off, normal speed, |
| 231 | * sharp roll-off, DZF off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | // 0x01, 0x12, /* quad speed */ |
| 233 | 0x02, 0x00, /* 2: DZF disabled */ |
| 234 | 0x03, 0x00, /* 3: LATT 0 */ |
| 235 | 0x04, 0x00, /* 4: RATT 0 */ |
| 236 | 0x00, 0x0f, /* 0: power-up, un-reset */ |
| 237 | 0xff, 0xff |
| 238 | }; |
| 239 | |
| 240 | int chip, num_chips; |
| 241 | unsigned char *ptr, reg, data, *inits; |
| 242 | |
| 243 | switch (ak->type) { |
| 244 | case SND_AK4524: |
| 245 | inits = inits_ak4524; |
| 246 | num_chips = ak->num_dacs / 2; |
| 247 | break; |
| 248 | case SND_AK4528: |
| 249 | inits = inits_ak4528; |
| 250 | num_chips = ak->num_dacs / 2; |
| 251 | break; |
| 252 | case SND_AK4529: |
| 253 | inits = inits_ak4529; |
| 254 | num_chips = 1; |
| 255 | break; |
| 256 | case SND_AK4355: |
| 257 | inits = inits_ak4355; |
| 258 | num_chips = 1; |
| 259 | break; |
| 260 | case SND_AK4358: |
| 261 | inits = inits_ak4358; |
| 262 | num_chips = 1; |
| 263 | break; |
| 264 | case SND_AK4381: |
| 265 | inits = inits_ak4381; |
| 266 | num_chips = ak->num_dacs / 2; |
| 267 | break; |
| 268 | default: |
| 269 | snd_BUG(); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | for (chip = 0; chip < num_chips; chip++) { |
| 274 | ptr = inits; |
| 275 | while (*ptr != 0xff) { |
| 276 | reg = *ptr++; |
| 277 | data = *ptr++; |
| 278 | snd_akm4xxx_write(ak, chip, reg, data); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 283 | EXPORT_SYMBOL(snd_akm4xxx_init); |
| 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | #define AK_GET_CHIP(val) (((val) >> 8) & 0xff) |
| 286 | #define AK_GET_ADDR(val) ((val) & 0xff) |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 287 | #define AK_GET_SHIFT(val) (((val) >> 16) & 0x3f) |
| 288 | #define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | #define AK_GET_INVERT(val) (((val) >> 23) & 1) |
| 290 | #define AK_GET_MASK(val) (((val) >> 24) & 0xff) |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 291 | #define AK_COMPOSE(chip,addr,shift,mask) \ |
| 292 | (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24)) |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 293 | #define AK_NEEDSMSB (1<<22) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | #define AK_INVERT (1<<23) |
| 295 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 296 | static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol, |
| 297 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
| 299 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 300 | |
| 301 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 302 | uinfo->count = 1; |
| 303 | uinfo->value.integer.min = 0; |
| 304 | uinfo->value.integer.max = mask; |
| 305 | return 0; |
| 306 | } |
| 307 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 308 | static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol, |
| 309 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 311 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 313 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 314 | int needsmsb = AK_GET_NEEDSMSB(kcontrol->private_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | int invert = AK_GET_INVERT(kcontrol->private_value); |
| 316 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 317 | unsigned char val = snd_akm4xxx_get(ak, chip, addr); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 318 | |
| 319 | if (needsmsb) |
| 320 | val &= 0x7f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | ucontrol->value.integer.value[0] = invert ? mask - val : val; |
| 322 | return 0; |
| 323 | } |
| 324 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 325 | static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol, |
| 326 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 328 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 330 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 331 | int needsmsb = AK_GET_NEEDSMSB(kcontrol->private_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | int invert = AK_GET_INVERT(kcontrol->private_value); |
| 333 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 334 | unsigned char nval = ucontrol->value.integer.value[0] % (mask+1); |
| 335 | int change; |
| 336 | |
| 337 | if (invert) |
| 338 | nval = mask - nval; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 339 | if (needsmsb) |
| 340 | nval |= 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | change = snd_akm4xxx_get(ak, chip, addr) != nval; |
| 342 | if (change) |
| 343 | snd_akm4xxx_write(ak, chip, addr, nval); |
| 344 | return change; |
| 345 | } |
| 346 | |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 347 | static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol, |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 348 | struct snd_ctl_elem_info *uinfo) |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 349 | { |
| 350 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 351 | |
| 352 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 353 | uinfo->count = 2; |
| 354 | uinfo->value.integer.min = 0; |
| 355 | uinfo->value.integer.max = mask; |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol, |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 360 | struct snd_ctl_elem_value *ucontrol) |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 361 | { |
| 362 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 363 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 364 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 365 | int needsmsb = AK_GET_NEEDSMSB(kcontrol->private_value); |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 366 | int invert = AK_GET_INVERT(kcontrol->private_value); |
| 367 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 368 | unsigned char val; |
| 369 | |
| 370 | val = snd_akm4xxx_get(ak, chip, addr); |
| 371 | if (needsmsb) |
| 372 | val &= 0x7f; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 373 | ucontrol->value.integer.value[0] = invert ? mask - val : val; |
| 374 | |
| 375 | val = snd_akm4xxx_get(ak, chip, addr+1); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 376 | if (needsmsb) |
| 377 | val &= 0x7f; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 378 | ucontrol->value.integer.value[1] = invert ? mask - val : val; |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol, |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 384 | struct snd_ctl_elem_value *ucontrol) |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 385 | { |
| 386 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 387 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 388 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 389 | int needsmsb = AK_GET_NEEDSMSB(kcontrol->private_value); |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 390 | int invert = AK_GET_INVERT(kcontrol->private_value); |
| 391 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 392 | unsigned char nval = ucontrol->value.integer.value[0] % (mask+1); |
| 393 | int change0, change1; |
| 394 | |
| 395 | if (invert) |
| 396 | nval = mask - nval; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 397 | if (needsmsb) |
| 398 | nval |= 0x80; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 399 | change0 = snd_akm4xxx_get(ak, chip, addr) != nval; |
| 400 | if (change0) |
| 401 | snd_akm4xxx_write(ak, chip, addr, nval); |
| 402 | |
| 403 | nval = ucontrol->value.integer.value[1] % (mask+1); |
| 404 | if (invert) |
| 405 | nval = mask - nval; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 406 | if (needsmsb) |
| 407 | nval |= 0x80; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 408 | change1 = snd_akm4xxx_get(ak, chip, addr+1) != nval; |
| 409 | if (change1) |
| 410 | snd_akm4xxx_write(ak, chip, addr+1, nval); |
| 411 | |
| 412 | |
| 413 | return change0 || change1; |
| 414 | } |
| 415 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 416 | static int snd_akm4xxx_ipga_gain_info(struct snd_kcontrol *kcontrol, |
| 417 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
| 419 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 420 | uinfo->count = 1; |
| 421 | uinfo->value.integer.min = 0; |
| 422 | uinfo->value.integer.max = 36; |
| 423 | return 0; |
| 424 | } |
| 425 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 426 | static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol, |
| 427 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 429 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 431 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 432 | ucontrol->value.integer.value[0] = |
| 433 | snd_akm4xxx_get_ipga(ak, chip, addr) & 0x7f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 437 | static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol, |
| 438 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 440 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 442 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 443 | unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80; |
| 444 | int change = snd_akm4xxx_get_ipga(ak, chip, addr) != nval; |
| 445 | if (change) |
| 446 | snd_akm4xxx_write(ak, chip, addr, nval); |
| 447 | return change; |
| 448 | } |
| 449 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 450 | static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol, |
| 451 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
| 453 | static char *texts[4] = { |
| 454 | "44.1kHz", "Off", "48kHz", "32kHz", |
| 455 | }; |
| 456 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 457 | uinfo->count = 1; |
| 458 | uinfo->value.enumerated.items = 4; |
| 459 | if (uinfo->value.enumerated.item >= 4) |
| 460 | uinfo->value.enumerated.item = 3; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 461 | strcpy(uinfo->value.enumerated.name, |
| 462 | texts[uinfo->value.enumerated.item]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 466 | static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol, |
| 467 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 469 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 471 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 472 | int shift = AK_GET_SHIFT(kcontrol->private_value); |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 473 | ucontrol->value.enumerated.item[0] = |
| 474 | (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 478 | static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol, |
| 479 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 481 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 483 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 484 | int shift = AK_GET_SHIFT(kcontrol->private_value); |
| 485 | unsigned char nval = ucontrol->value.enumerated.item[0] & 3; |
| 486 | int change; |
| 487 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 488 | nval = (nval << shift) | |
| 489 | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | change = snd_akm4xxx_get(ak, chip, addr) != nval; |
| 491 | if (change) |
| 492 | snd_akm4xxx_write(ak, chip, addr, nval); |
| 493 | return change; |
| 494 | } |
| 495 | |
Jochen Voss | 30ba6e2 | 2006-08-09 14:26:26 +0200 | [diff] [blame] | 496 | static int ak4xxx_switch_info(struct snd_kcontrol *kcontrol, |
| 497 | struct snd_ctl_elem_info *uinfo) |
| 498 | { |
| 499 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 500 | uinfo->count = 1; |
| 501 | uinfo->value.integer.min = 0; |
| 502 | uinfo->value.integer.max = 1; |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static int ak4xxx_switch_get(struct snd_kcontrol *kcontrol, |
| 507 | struct snd_ctl_elem_value *ucontrol) |
| 508 | { |
| 509 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 510 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 511 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 512 | int shift = AK_GET_SHIFT(kcontrol->private_value); |
| 513 | int invert = AK_GET_INVERT(kcontrol->private_value); |
| 514 | unsigned char val = snd_akm4xxx_get(ak, chip, addr); |
| 515 | |
| 516 | if (invert) |
| 517 | val = ! val; |
| 518 | ucontrol->value.integer.value[0] = (val & (1<<shift)) != 0; |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static int ak4xxx_switch_put(struct snd_kcontrol *kcontrol, |
| 523 | struct snd_ctl_elem_value *ucontrol) |
| 524 | { |
| 525 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 526 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 527 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 528 | int shift = AK_GET_SHIFT(kcontrol->private_value); |
| 529 | int invert = AK_GET_INVERT(kcontrol->private_value); |
| 530 | long flag = ucontrol->value.integer.value[0]; |
| 531 | unsigned char val, oval; |
| 532 | int change; |
| 533 | |
| 534 | if (invert) |
| 535 | flag = ! flag; |
| 536 | oval = snd_akm4xxx_get(ak, chip, addr); |
| 537 | if (flag) |
| 538 | val = oval | (1<<shift); |
| 539 | else |
| 540 | val = oval & ~(1<<shift); |
| 541 | change = (oval != val); |
| 542 | if (change) |
| 543 | snd_akm4xxx_write(ak, chip, addr, val); |
| 544 | return change; |
| 545 | } |
| 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | /* |
| 548 | * build AK4xxx controls |
| 549 | */ |
| 550 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 551 | int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | { |
| 553 | unsigned int idx, num_emphs; |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 554 | struct snd_kcontrol *ctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | int err; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 556 | int mixer_ch = 0; |
| 557 | int num_stereo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
| 559 | ctl = kmalloc(sizeof(*ctl), GFP_KERNEL); |
| 560 | if (! ctl) |
| 561 | return -ENOMEM; |
| 562 | |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 563 | for (idx = 0; idx < ak->num_dacs; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | memset(ctl, 0, sizeof(*ctl)); |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 565 | if (ak->channel_names == NULL) { |
| 566 | strcpy(ctl->id.name, "DAC Volume"); |
| 567 | num_stereo = 1; |
| 568 | ctl->id.index = mixer_ch + ak->idx_offset * 2; |
| 569 | } else { |
| 570 | strcpy(ctl->id.name, ak->channel_names[mixer_ch]); |
| 571 | num_stereo = ak->num_stereo[mixer_ch]; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 572 | ctl->id.index = 0; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 575 | ctl->count = 1; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 576 | if (num_stereo == 2) { |
| 577 | ctl->info = snd_akm4xxx_stereo_volume_info; |
| 578 | ctl->get = snd_akm4xxx_stereo_volume_get; |
| 579 | ctl->put = snd_akm4xxx_stereo_volume_put; |
| 580 | } else { |
| 581 | ctl->info = snd_akm4xxx_volume_info; |
| 582 | ctl->get = snd_akm4xxx_volume_get; |
| 583 | ctl->put = snd_akm4xxx_volume_put; |
| 584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | switch (ak->type) { |
| 586 | case SND_AK4524: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 587 | /* register 6 & 7 */ |
| 588 | ctl->private_value = |
| 589 | AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | break; |
| 591 | case SND_AK4528: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 592 | /* register 4 & 5 */ |
| 593 | ctl->private_value = |
| 594 | AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | break; |
| 596 | case SND_AK4529: { |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 597 | /* registers 2-7 and b,c */ |
| 598 | int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; |
| 599 | ctl->private_value = |
| 600 | AK_COMPOSE(0, val, 0, 255) | AK_INVERT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | break; |
| 602 | } |
| 603 | case SND_AK4355: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 604 | /* register 4-9, chip #0 only */ |
| 605 | ctl->private_value = AK_COMPOSE(0, idx + 4, 0, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | break; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 607 | case SND_AK4358: { |
| 608 | /* register 4-9 and 11-12, chip #0 only */ |
| 609 | int addr = idx < 6 ? idx + 4 : idx + 5; |
| 610 | ctl->private_value = |
| 611 | AK_COMPOSE(0, addr, 0, 127) | AK_NEEDSMSB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | break; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame^] | 613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | case SND_AK4381: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 615 | /* register 3 & 4 */ |
| 616 | ctl->private_value = |
| 617 | AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | break; |
| 619 | default: |
| 620 | err = -EINVAL; |
| 621 | goto __error; |
| 622 | } |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | ctl->private_data = ak; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 625 | err = snd_ctl_add(ak->card, |
| 626 | snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ| |
| 627 | SNDRV_CTL_ELEM_ACCESS_WRITE)); |
| 628 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | goto __error; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 630 | |
| 631 | idx += num_stereo; |
| 632 | mixer_ch++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) { |
| 635 | memset(ctl, 0, sizeof(*ctl)); |
| 636 | strcpy(ctl->id.name, "ADC Volume"); |
| 637 | ctl->id.index = idx + ak->idx_offset * 2; |
| 638 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 639 | ctl->count = 1; |
| 640 | ctl->info = snd_akm4xxx_volume_info; |
| 641 | ctl->get = snd_akm4xxx_volume_get; |
| 642 | ctl->put = snd_akm4xxx_volume_put; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 643 | /* register 4 & 5 */ |
| 644 | ctl->private_value = |
| 645 | AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | ctl->private_data = ak; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 647 | err = snd_ctl_add(ak->card, |
| 648 | snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ| |
| 649 | SNDRV_CTL_ELEM_ACCESS_WRITE)); |
| 650 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | goto __error; |
| 652 | |
| 653 | memset(ctl, 0, sizeof(*ctl)); |
| 654 | strcpy(ctl->id.name, "IPGA Analog Capture Volume"); |
| 655 | ctl->id.index = idx + ak->idx_offset * 2; |
| 656 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 657 | ctl->count = 1; |
| 658 | ctl->info = snd_akm4xxx_ipga_gain_info; |
| 659 | ctl->get = snd_akm4xxx_ipga_gain_get; |
| 660 | ctl->put = snd_akm4xxx_ipga_gain_put; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 661 | /* register 4 & 5 */ |
| 662 | ctl->private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | ctl->private_data = ak; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 664 | err = snd_ctl_add(ak->card, |
| 665 | snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ| |
| 666 | SNDRV_CTL_ELEM_ACCESS_WRITE)); |
| 667 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | goto __error; |
| 669 | } |
Jochen Voss | 683fe15 | 2006-08-08 21:12:44 +0200 | [diff] [blame] | 670 | |
| 671 | if (ak->type == SND_AK5365) { |
| 672 | memset(ctl, 0, sizeof(*ctl)); |
| 673 | if (ak->channel_names == NULL) |
| 674 | strcpy(ctl->id.name, "Capture Volume"); |
| 675 | else |
| 676 | strcpy(ctl->id.name, ak->channel_names[0]); |
| 677 | ctl->id.index = ak->idx_offset * 2; |
| 678 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 679 | ctl->count = 1; |
| 680 | ctl->info = snd_akm4xxx_stereo_volume_info; |
| 681 | ctl->get = snd_akm4xxx_stereo_volume_get; |
| 682 | ctl->put = snd_akm4xxx_stereo_volume_put; |
| 683 | /* Registers 4 & 5 (see AK5365 data sheet, pages 34 and 35): |
| 684 | * valid values are from 0x00 (mute) to 0x98 (+12dB). */ |
| 685 | ctl->private_value = |
| 686 | AK_COMPOSE(0, 4, 0, 0x98); |
| 687 | ctl->private_data = ak; |
| 688 | err = snd_ctl_add(ak->card, |
| 689 | snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ| |
| 690 | SNDRV_CTL_ELEM_ACCESS_WRITE)); |
| 691 | if (err < 0) |
| 692 | goto __error; |
Jochen Voss | 30ba6e2 | 2006-08-09 14:26:26 +0200 | [diff] [blame] | 693 | |
| 694 | memset(ctl, 0, sizeof(*ctl)); |
| 695 | if (ak->channel_names == NULL) |
| 696 | strcpy(ctl->id.name, "Capture Switch"); |
| 697 | else |
| 698 | strcpy(ctl->id.name, ak->channel_names[1]); |
| 699 | ctl->id.index = ak->idx_offset * 2; |
| 700 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 701 | ctl->count = 1; |
| 702 | ctl->info = ak4xxx_switch_info; |
| 703 | ctl->get = ak4xxx_switch_get; |
| 704 | ctl->put = ak4xxx_switch_put; |
| 705 | /* register 2, bit 0 (SMUTE): 0 = normal operation, 1 = mute */ |
| 706 | ctl->private_value = |
| 707 | AK_COMPOSE(0, 2, 0, 0) | AK_INVERT; |
| 708 | ctl->private_data = ak; |
| 709 | err = snd_ctl_add(ak->card, |
| 710 | snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ| |
| 711 | SNDRV_CTL_ELEM_ACCESS_WRITE)); |
| 712 | if (err < 0) |
| 713 | goto __error; |
Jochen Voss | 683fe15 | 2006-08-08 21:12:44 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | if (ak->type == SND_AK4355 || ak->type == SND_AK4358) |
| 717 | num_emphs = 1; |
| 718 | else |
| 719 | num_emphs = ak->num_dacs / 2; |
| 720 | for (idx = 0; idx < num_emphs; idx++) { |
| 721 | memset(ctl, 0, sizeof(*ctl)); |
| 722 | strcpy(ctl->id.name, "Deemphasis"); |
| 723 | ctl->id.index = idx + ak->idx_offset; |
| 724 | ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 725 | ctl->count = 1; |
| 726 | ctl->info = snd_akm4xxx_deemphasis_info; |
| 727 | ctl->get = snd_akm4xxx_deemphasis_get; |
| 728 | ctl->put = snd_akm4xxx_deemphasis_put; |
| 729 | switch (ak->type) { |
| 730 | case SND_AK4524: |
| 731 | case SND_AK4528: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 732 | /* register 3 */ |
| 733 | ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | break; |
| 735 | case SND_AK4529: { |
| 736 | int shift = idx == 3 ? 6 : (2 - idx) * 2; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 737 | /* register 8 with shift */ |
| 738 | ctl->private_value = AK_COMPOSE(0, 8, shift, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | break; |
| 740 | } |
| 741 | case SND_AK4355: |
| 742 | case SND_AK4358: |
| 743 | ctl->private_value = AK_COMPOSE(idx, 3, 0, 0); |
| 744 | break; |
| 745 | case SND_AK4381: |
| 746 | ctl->private_value = AK_COMPOSE(idx, 1, 1, 0); |
| 747 | break; |
Takashi Iwai | cf93907 | 2006-08-09 14:33:27 +0200 | [diff] [blame] | 748 | default: |
| 749 | err = -EINVAL; |
| 750 | goto __error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | ctl->private_data = ak; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 753 | err = snd_ctl_add(ak->card, |
| 754 | snd_ctl_new(ctl, SNDRV_CTL_ELEM_ACCESS_READ| |
| 755 | SNDRV_CTL_ELEM_ACCESS_WRITE)); |
| 756 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | goto __error; |
| 758 | } |
| 759 | err = 0; |
| 760 | |
| 761 | __error: |
| 762 | kfree(ctl); |
| 763 | return err; |
| 764 | } |
| 765 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 766 | EXPORT_SYMBOL(snd_akm4xxx_build_controls); |
| 767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | static int __init alsa_akm4xxx_module_init(void) |
| 769 | { |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static void __exit alsa_akm4xxx_module_exit(void) |
| 774 | { |
| 775 | } |
| 776 | |
| 777 | module_init(alsa_akm4xxx_module_init) |
| 778 | module_exit(alsa_akm4xxx_module_exit) |