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 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 5 | * Copyright (c) 2000-2004 Jaroslav Kysela <perex@perex.cz>, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 22 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/init.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 28 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <sound/core.h> |
| 30 | #include <sound/control.h> |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 31 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <sound/ak4xxx-adda.h> |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 33 | #include <sound/info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 35 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 39 | /* write the given register and save the data to the cache */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 40 | void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg, |
| 41 | unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
| 43 | ak->ops.lock(ak, chip); |
| 44 | ak->ops.write(ak, chip, reg, val); |
| 45 | |
| 46 | /* save the data */ |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 47 | snd_akm4xxx_set(ak, chip, reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | ak->ops.unlock(ak, chip); |
| 49 | } |
| 50 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 51 | EXPORT_SYMBOL(snd_akm4xxx_write); |
| 52 | |
| 53 | /* reset procedure for AK4524 and AK4528 */ |
| 54 | static void ak4524_reset(struct snd_akm4xxx *ak, int state) |
| 55 | { |
| 56 | unsigned int chip; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 57 | unsigned char reg; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 58 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 59 | for (chip = 0; chip < ak->num_dacs/2; chip++) { |
| 60 | snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03); |
| 61 | if (state) |
| 62 | continue; |
| 63 | /* DAC volumes */ |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 64 | for (reg = 0x04; reg < ak->total_regs; reg++) |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 65 | snd_akm4xxx_write(ak, chip, reg, |
| 66 | snd_akm4xxx_get(ak, chip, reg)); |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | /* reset procedure for AK4355 and AK4358 */ |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 71 | static void ak435X_reset(struct snd_akm4xxx *ak, int state) |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 72 | { |
| 73 | unsigned char reg; |
| 74 | |
| 75 | if (state) { |
| 76 | snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ |
| 77 | return; |
| 78 | } |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 79 | for (reg = 0x00; reg < ak->total_regs; reg++) |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 80 | if (reg != 0x01) |
| 81 | snd_akm4xxx_write(ak, 0, reg, |
| 82 | snd_akm4xxx_get(ak, 0, reg)); |
| 83 | snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */ |
| 84 | } |
| 85 | |
| 86 | /* reset procedure for AK4381 */ |
| 87 | static void ak4381_reset(struct snd_akm4xxx *ak, int state) |
| 88 | { |
| 89 | unsigned int chip; |
| 90 | unsigned char reg; |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 91 | for (chip = 0; chip < ak->num_dacs/2; chip++) { |
| 92 | snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f); |
| 93 | if (state) |
| 94 | continue; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 95 | for (reg = 0x01; reg < ak->total_regs; reg++) |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 96 | snd_akm4xxx_write(ak, chip, reg, |
| 97 | snd_akm4xxx_get(ak, chip, reg)); |
| 98 | } |
| 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* |
| 102 | * reset the AKM codecs |
| 103 | * @state: 1 = reset codec, 0 = restore the registers |
| 104 | * |
| 105 | * assert the reset operation and restores the register values to the chips. |
| 106 | */ |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 107 | void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | switch (ak->type) { |
| 110 | case SND_AK4524: |
| 111 | case SND_AK4528: |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 112 | case SND_AK4620: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 113 | ak4524_reset(ak, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | break; |
| 115 | case SND_AK4529: |
| 116 | /* FIXME: needed for ak4529? */ |
| 117 | break; |
| 118 | case SND_AK4355: |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 119 | ak435X_reset(ak, state); |
Pavel Hofman | 841b23d | 2008-03-17 08:45:33 +0100 | [diff] [blame] | 120 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | case SND_AK4358: |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 122 | ak435X_reset(ak, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | break; |
| 124 | case SND_AK4381: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 125 | ak4381_reset(ak, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | break; |
Takashi Iwai | cf93907 | 2006-08-09 14:33:27 +0200 | [diff] [blame] | 127 | default: |
| 128 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 132 | EXPORT_SYMBOL(snd_akm4xxx_reset); |
| 133 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Volume conversion table for non-linear volumes |
| 137 | * from -63.5dB (mute) to 0dB step 0.5dB |
| 138 | * |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 139 | * Used for AK4524/AK4620 input/ouput attenuation, AK4528, and |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 140 | * AK5365 input attenuation |
| 141 | */ |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 142 | static const unsigned char vol_cvt_datt[128] = { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 143 | 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, |
| 144 | 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, |
| 145 | 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x09, 0x0a, |
| 146 | 0x0a, 0x0b, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x0f, |
| 147 | 0x10, 0x10, 0x11, 0x12, 0x12, 0x13, 0x13, 0x14, |
| 148 | 0x15, 0x16, 0x17, 0x17, 0x18, 0x19, 0x1a, 0x1c, |
| 149 | 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x23, |
| 150 | 0x24, 0x25, 0x26, 0x28, 0x29, 0x2a, 0x2b, 0x2d, |
| 151 | 0x2e, 0x30, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, |
| 152 | 0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3e, 0x3f, 0x40, |
| 153 | 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x48, 0x4a, |
| 154 | 0x4b, 0x4d, 0x4e, 0x50, 0x51, 0x52, 0x53, 0x54, |
| 155 | 0x55, 0x56, 0x58, 0x59, 0x5b, 0x5c, 0x5e, 0x5f, |
| 156 | 0x60, 0x61, 0x62, 0x64, 0x65, 0x66, 0x67, 0x69, |
| 157 | 0x6a, 0x6c, 0x6d, 0x6f, 0x70, 0x71, 0x72, 0x73, |
| 158 | 0x75, 0x76, 0x77, 0x79, 0x7a, 0x7c, 0x7d, 0x7f, |
| 159 | }; |
| 160 | |
| 161 | /* |
| 162 | * dB tables |
| 163 | */ |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 164 | static const DECLARE_TLV_DB_SCALE(db_scale_vol_datt, -6350, 50, 1); |
| 165 | static const DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750, 50, 1); |
| 166 | static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350, 50, 1); |
| 167 | static const DECLARE_TLV_DB_LINEAR(db_scale_linear, TLV_DB_GAIN_MUTE, 0); |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* |
| 170 | * initialize all the ak4xxx chips |
| 171 | */ |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 172 | void snd_akm4xxx_init(struct snd_akm4xxx *ak) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 174 | static const unsigned char inits_ak4524[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | 0x00, 0x07, /* 0: all power up */ |
| 176 | 0x01, 0x00, /* 1: ADC/DAC reset */ |
| 177 | 0x02, 0x60, /* 2: 24bit I2S */ |
| 178 | 0x03, 0x19, /* 3: deemphasis off */ |
| 179 | 0x01, 0x03, /* 1: ADC/DAC enable */ |
| 180 | 0x04, 0x00, /* 4: ADC left muted */ |
| 181 | 0x05, 0x00, /* 5: ADC right muted */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | 0x06, 0x00, /* 6: DAC left muted */ |
| 183 | 0x07, 0x00, /* 7: DAC right muted */ |
| 184 | 0xff, 0xff |
| 185 | }; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 186 | static const unsigned char inits_ak4528[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | 0x00, 0x07, /* 0: all power up */ |
| 188 | 0x01, 0x00, /* 1: ADC/DAC reset */ |
| 189 | 0x02, 0x60, /* 2: 24bit I2S */ |
| 190 | 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */ |
| 191 | 0x01, 0x03, /* 1: ADC/DAC enable */ |
| 192 | 0x04, 0x00, /* 4: ADC left muted */ |
| 193 | 0x05, 0x00, /* 5: ADC right muted */ |
| 194 | 0xff, 0xff |
| 195 | }; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 196 | static const unsigned char inits_ak4529[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | 0x09, 0x01, /* 9: ATS=0, RSTN=1 */ |
| 198 | 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */ |
| 199 | 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */ |
| 200 | 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */ |
| 201 | 0x02, 0xff, /* 2: LOUT1 muted */ |
| 202 | 0x03, 0xff, /* 3: ROUT1 muted */ |
| 203 | 0x04, 0xff, /* 4: LOUT2 muted */ |
| 204 | 0x05, 0xff, /* 5: ROUT2 muted */ |
| 205 | 0x06, 0xff, /* 6: LOUT3 muted */ |
| 206 | 0x07, 0xff, /* 7: ROUT3 muted */ |
| 207 | 0x0b, 0xff, /* B: LOUT4 muted */ |
| 208 | 0x0c, 0xff, /* C: ROUT4 muted */ |
| 209 | 0x08, 0x55, /* 8: deemphasis all off */ |
| 210 | 0xff, 0xff |
| 211 | }; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 212 | static const unsigned char inits_ak4355[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | 0x01, 0x02, /* 1: reset and soft-mute */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 214 | 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, |
| 215 | * disable DZF, sharp roll-off, RSTN#=0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */ |
| 217 | // 0x02, 0x2e, /* quad speed */ |
| 218 | 0x03, 0x01, /* 3: de-emphasis off */ |
| 219 | 0x04, 0x00, /* 4: LOUT1 volume muted */ |
| 220 | 0x05, 0x00, /* 5: ROUT1 volume muted */ |
| 221 | 0x06, 0x00, /* 6: LOUT2 volume muted */ |
| 222 | 0x07, 0x00, /* 7: ROUT2 volume muted */ |
| 223 | 0x08, 0x00, /* 8: LOUT3 volume muted */ |
| 224 | 0x09, 0x00, /* 9: ROUT3 volume muted */ |
| 225 | 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */ |
| 226 | 0x01, 0x01, /* 1: un-reset, unmute */ |
| 227 | 0xff, 0xff |
| 228 | }; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 229 | static const unsigned char inits_ak4358[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | 0x01, 0x02, /* 1: reset and soft-mute */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 231 | 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, |
| 232 | * disable DZF, sharp roll-off, RSTN#=0 */ |
Alexander Beregalov | 46480b3 | 2008-08-21 08:28:42 +0400 | [diff] [blame] | 233 | 0x02, 0x4e, /* 2: DA's power up, normal speed, RSTN#=0 */ |
| 234 | /* 0x02, 0x6e,*/ /* quad speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | 0x03, 0x01, /* 3: de-emphasis off */ |
| 236 | 0x04, 0x00, /* 4: LOUT1 volume muted */ |
| 237 | 0x05, 0x00, /* 5: ROUT1 volume muted */ |
| 238 | 0x06, 0x00, /* 6: LOUT2 volume muted */ |
| 239 | 0x07, 0x00, /* 7: ROUT2 volume muted */ |
| 240 | 0x08, 0x00, /* 8: LOUT3 volume muted */ |
| 241 | 0x09, 0x00, /* 9: ROUT3 volume muted */ |
| 242 | 0x0b, 0x00, /* b: LOUT4 volume muted */ |
| 243 | 0x0c, 0x00, /* c: ROUT4 volume muted */ |
| 244 | 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */ |
| 245 | 0x01, 0x01, /* 1: un-reset, unmute */ |
| 246 | 0xff, 0xff |
| 247 | }; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 248 | static const unsigned char inits_ak4381[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */ |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 250 | 0x01, 0x02, /* 1: de-emphasis off, normal speed, |
| 251 | * sharp roll-off, DZF off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | // 0x01, 0x12, /* quad speed */ |
| 253 | 0x02, 0x00, /* 2: DZF disabled */ |
| 254 | 0x03, 0x00, /* 3: LATT 0 */ |
| 255 | 0x04, 0x00, /* 4: RATT 0 */ |
| 256 | 0x00, 0x0f, /* 0: power-up, un-reset */ |
| 257 | 0xff, 0xff |
| 258 | }; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 259 | static const unsigned char inits_ak4620[] = { |
| 260 | 0x00, 0x07, /* 0: normal */ |
| 261 | 0x01, 0x00, /* 0: reset */ |
| 262 | 0x01, 0x02, /* 1: RSTAD */ |
| 263 | 0x01, 0x03, /* 1: RSTDA */ |
| 264 | 0x01, 0x0f, /* 1: normal */ |
| 265 | 0x02, 0x60, /* 2: 24bit I2S */ |
| 266 | 0x03, 0x01, /* 3: deemphasis off */ |
| 267 | 0x04, 0x00, /* 4: LIN muted */ |
| 268 | 0x05, 0x00, /* 5: RIN muted */ |
| 269 | 0x06, 0x00, /* 6: LOUT muted */ |
| 270 | 0x07, 0x00, /* 7: ROUT muted */ |
| 271 | 0xff, 0xff |
| 272 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 274 | int chip; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 275 | const unsigned char *ptr, *inits; |
| 276 | unsigned char reg, data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 278 | memset(ak->images, 0, sizeof(ak->images)); |
| 279 | memset(ak->volumes, 0, sizeof(ak->volumes)); |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | switch (ak->type) { |
| 282 | case SND_AK4524: |
| 283 | inits = inits_ak4524; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 284 | ak->num_chips = ak->num_dacs / 2; |
| 285 | ak->name = "ak4524"; |
| 286 | ak->total_regs = 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | break; |
| 288 | case SND_AK4528: |
| 289 | inits = inits_ak4528; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 290 | ak->num_chips = ak->num_dacs / 2; |
| 291 | ak->name = "ak4528"; |
| 292 | ak->total_regs = 0x06; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | break; |
| 294 | case SND_AK4529: |
| 295 | inits = inits_ak4529; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 296 | ak->num_chips = 1; |
| 297 | ak->name = "ak4529"; |
| 298 | ak->total_regs = 0x0d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | break; |
| 300 | case SND_AK4355: |
| 301 | inits = inits_ak4355; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 302 | ak->num_chips = 1; |
| 303 | ak->name = "ak4355"; |
| 304 | ak->total_regs = 0x0b; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | break; |
| 306 | case SND_AK4358: |
| 307 | inits = inits_ak4358; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 308 | ak->num_chips = 1; |
| 309 | ak->name = "ak4358"; |
| 310 | ak->total_regs = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | break; |
| 312 | case SND_AK4381: |
| 313 | inits = inits_ak4381; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 314 | ak->num_chips = ak->num_dacs / 2; |
| 315 | ak->name = "ak4381"; |
| 316 | ak->total_regs = 0x05; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | break; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 318 | case SND_AK5365: |
| 319 | /* FIXME: any init sequence? */ |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 320 | ak->num_chips = 1; |
| 321 | ak->name = "ak5365"; |
| 322 | ak->total_regs = 0x08; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 323 | return; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 324 | case SND_AK4620: |
| 325 | inits = inits_ak4620; |
| 326 | ak->num_chips = ak->num_dacs / 2; |
| 327 | ak->name = "ak4620"; |
| 328 | ak->total_regs = 0x08; |
| 329 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | default: |
| 331 | snd_BUG(); |
| 332 | return; |
| 333 | } |
| 334 | |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 335 | for (chip = 0; chip < ak->num_chips; chip++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | ptr = inits; |
| 337 | while (*ptr != 0xff) { |
| 338 | reg = *ptr++; |
| 339 | data = *ptr++; |
| 340 | snd_akm4xxx_write(ak, chip, reg, data); |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 341 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 346 | EXPORT_SYMBOL(snd_akm4xxx_init); |
| 347 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 348 | /* |
| 349 | * Mixer callbacks |
| 350 | */ |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 351 | #define AK_IPGA (1<<20) /* including IPGA */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 352 | #define AK_VOL_CVT (1<<21) /* need dB conversion */ |
| 353 | #define AK_NEEDSMSB (1<<22) /* need MSB update bit */ |
| 354 | #define AK_INVERT (1<<23) /* data is inverted */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | #define AK_GET_CHIP(val) (((val) >> 8) & 0xff) |
| 356 | #define AK_GET_ADDR(val) ((val) & 0xff) |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 357 | #define AK_GET_SHIFT(val) (((val) >> 16) & 0x0f) |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 358 | #define AK_GET_VOL_CVT(val) (((val) >> 21) & 1) |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 359 | #define AK_GET_IPGA(val) (((val) >> 20) & 1) |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame] | 360 | #define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | #define AK_GET_INVERT(val) (((val) >> 23) & 1) |
| 362 | #define AK_GET_MASK(val) (((val) >> 24) & 0xff) |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 363 | #define AK_COMPOSE(chip,addr,shift,mask) \ |
| 364 | (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 366 | static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol, |
| 367 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
| 369 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 370 | |
| 371 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 372 | uinfo->count = 1; |
| 373 | uinfo->value.integer.min = 0; |
| 374 | uinfo->value.integer.max = mask; |
| 375 | return 0; |
| 376 | } |
| 377 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 378 | static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol, |
| 379 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 381 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 383 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame] | 384 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 385 | ucontrol->value.integer.value[0] = snd_akm4xxx_get_vol(ak, chip, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | return 0; |
| 387 | } |
| 388 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 389 | static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr, |
| 390 | unsigned char nval) |
| 391 | { |
| 392 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 393 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 394 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 395 | |
| 396 | if (snd_akm4xxx_get_vol(ak, chip, addr) == nval) |
| 397 | return 0; |
| 398 | |
| 399 | snd_akm4xxx_set_vol(ak, chip, addr, nval); |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 400 | if (AK_GET_VOL_CVT(kcontrol->private_value) && nval < 128) |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 401 | nval = vol_cvt_datt[nval]; |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 402 | if (AK_GET_IPGA(kcontrol->private_value) && nval >= 128) |
| 403 | nval++; /* need to correct + 1 since both 127 and 128 are 0dB */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 404 | if (AK_GET_INVERT(kcontrol->private_value)) |
| 405 | nval = mask - nval; |
| 406 | if (AK_GET_NEEDSMSB(kcontrol->private_value)) |
| 407 | nval |= 0x80; |
Pavel Hofman | 841b23d | 2008-03-17 08:45:33 +0100 | [diff] [blame] | 408 | /* printk(KERN_DEBUG "DEBUG - AK writing reg: chip %x addr %x, |
| 409 | nval %x\n", chip, addr, nval); */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 410 | snd_akm4xxx_write(ak, chip, addr, nval); |
| 411 | return 1; |
| 412 | } |
| 413 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 414 | static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol, |
| 415 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 417 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 418 | unsigned int val = ucontrol->value.integer.value[0]; |
| 419 | if (val > mask) |
| 420 | return -EINVAL; |
| 421 | return put_ak_reg(kcontrol, AK_GET_ADDR(kcontrol->private_value), val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 424 | static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol, |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 425 | struct snd_ctl_elem_info *uinfo) |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 426 | { |
| 427 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 428 | |
| 429 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 430 | uinfo->count = 2; |
| 431 | uinfo->value.integer.min = 0; |
| 432 | uinfo->value.integer.max = mask; |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol, |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 437 | struct snd_ctl_elem_value *ucontrol) |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 438 | { |
| 439 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 440 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 441 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame] | 442 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 443 | ucontrol->value.integer.value[0] = snd_akm4xxx_get_vol(ak, chip, addr); |
| 444 | ucontrol->value.integer.value[1] = snd_akm4xxx_get_vol(ak, chip, addr+1); |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol, |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 449 | struct snd_ctl_elem_value *ucontrol) |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 450 | { |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 451 | int addr = AK_GET_ADDR(kcontrol->private_value); |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 452 | unsigned int mask = AK_GET_MASK(kcontrol->private_value); |
| 453 | unsigned int val[2]; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 454 | int change; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 455 | |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 456 | val[0] = ucontrol->value.integer.value[0]; |
| 457 | val[1] = ucontrol->value.integer.value[1]; |
| 458 | if (val[0] > mask || val[1] > mask) |
| 459 | return -EINVAL; |
| 460 | change = put_ak_reg(kcontrol, addr, val[0]); |
| 461 | change |= put_ak_reg(kcontrol, addr + 1, val[1]); |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 462 | return change; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 465 | static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol, |
| 466 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Takashi Iwai | 609e478 | 2014-10-20 18:13:01 +0200 | [diff] [blame] | 468 | static const char * const texts[4] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | "44.1kHz", "Off", "48kHz", "32kHz", |
| 470 | }; |
Takashi Iwai | 609e478 | 2014-10-20 18:13:01 +0200 | [diff] [blame] | 471 | return snd_ctl_enum_info(uinfo, 1, 4, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 474 | static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol, |
| 475 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 477 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 479 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 480 | int shift = AK_GET_SHIFT(kcontrol->private_value); |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 481 | ucontrol->value.enumerated.item[0] = |
| 482 | (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 486 | static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol, |
| 487 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 489 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 491 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 492 | int shift = AK_GET_SHIFT(kcontrol->private_value); |
| 493 | unsigned char nval = ucontrol->value.enumerated.item[0] & 3; |
| 494 | int change; |
| 495 | |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 496 | nval = (nval << shift) | |
| 497 | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | change = snd_akm4xxx_get(ak, chip, addr) != nval; |
| 499 | if (change) |
| 500 | snd_akm4xxx_write(ak, chip, addr, nval); |
| 501 | return change; |
| 502 | } |
| 503 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 504 | #define ak4xxx_switch_info snd_ctl_boolean_mono_info |
Jochen Voss | 30ba6e2 | 2006-08-09 14:26:26 +0200 | [diff] [blame] | 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); |
Pavel Hofman | ea7cfcd | 2007-05-19 17:21:04 +0200 | [diff] [blame] | 514 | /* we observe the (1<<shift) bit only */ |
| 515 | unsigned char val = snd_akm4xxx_get(ak, chip, addr) & (1<<shift); |
Jochen Voss | 30ba6e2 | 2006-08-09 14:26:26 +0200 | [diff] [blame] | 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 | |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 547 | #define AK5365_NUM_INPUTS 5 |
| 548 | |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 549 | static int ak4xxx_capture_num_inputs(struct snd_akm4xxx *ak, int mixer_ch) |
| 550 | { |
| 551 | int num_names; |
| 552 | const char **input_names; |
| 553 | |
| 554 | input_names = ak->adc_info[mixer_ch].input_names; |
| 555 | num_names = 0; |
| 556 | while (num_names < AK5365_NUM_INPUTS && input_names[num_names]) |
| 557 | ++num_names; |
| 558 | return num_names; |
| 559 | } |
| 560 | |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 561 | static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol, |
| 562 | struct snd_ctl_elem_info *uinfo) |
| 563 | { |
| 564 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 565 | int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); |
Takashi Iwai | 609e478 | 2014-10-20 18:13:01 +0200 | [diff] [blame] | 566 | unsigned int num_names; |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 567 | |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 568 | num_names = ak4xxx_capture_num_inputs(ak, mixer_ch); |
| 569 | if (!num_names) |
| 570 | return -EINVAL; |
Takashi Iwai | 609e478 | 2014-10-20 18:13:01 +0200 | [diff] [blame] | 571 | return snd_ctl_enum_info(uinfo, 1, num_names, |
| 572 | ak->adc_info[mixer_ch].input_names); |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static int ak4xxx_capture_source_get(struct snd_kcontrol *kcontrol, |
| 576 | struct snd_ctl_elem_value *ucontrol) |
| 577 | { |
| 578 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
| 579 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 580 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 581 | int mask = AK_GET_MASK(kcontrol->private_value); |
| 582 | unsigned char val; |
| 583 | |
| 584 | val = snd_akm4xxx_get(ak, chip, addr) & mask; |
| 585 | ucontrol->value.enumerated.item[0] = val; |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static int ak4xxx_capture_source_put(struct snd_kcontrol *kcontrol, |
| 590 | struct snd_ctl_elem_value *ucontrol) |
| 591 | { |
| 592 | struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 593 | int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 594 | int chip = AK_GET_CHIP(kcontrol->private_value); |
| 595 | int addr = AK_GET_ADDR(kcontrol->private_value); |
| 596 | int mask = AK_GET_MASK(kcontrol->private_value); |
| 597 | unsigned char oval, val; |
Takashi Iwai | 02ff132 | 2007-11-15 16:15:29 +0100 | [diff] [blame] | 598 | int num_names = ak4xxx_capture_num_inputs(ak, mixer_ch); |
| 599 | |
| 600 | if (ucontrol->value.enumerated.item[0] >= num_names) |
| 601 | return -EINVAL; |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 602 | |
| 603 | oval = snd_akm4xxx_get(ak, chip, addr); |
| 604 | val = oval & ~mask; |
| 605 | val |= ucontrol->value.enumerated.item[0] & mask; |
| 606 | if (val != oval) { |
| 607 | snd_akm4xxx_write(ak, chip, addr, val); |
| 608 | return 1; |
| 609 | } |
| 610 | return 0; |
| 611 | } |
| 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* |
| 614 | * build AK4xxx controls |
| 615 | */ |
| 616 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 617 | static int build_dac_controls(struct snd_akm4xxx *ak) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 619 | int idx, err, mixer_ch, num_stereo; |
| 620 | struct snd_kcontrol_new knew; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 622 | mixer_ch = 0; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 623 | for (idx = 0; idx < ak->num_dacs; ) { |
Pavel Hofman | ea7cfcd | 2007-05-19 17:21:04 +0200 | [diff] [blame] | 624 | /* mute control for Revolution 7.1 - AK4381 */ |
| 625 | if (ak->type == SND_AK4381 |
| 626 | && ak->dac_info[mixer_ch].switch_name) { |
| 627 | memset(&knew, 0, sizeof(knew)); |
| 628 | knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 629 | knew.count = 1; |
| 630 | knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 631 | knew.name = ak->dac_info[mixer_ch].switch_name; |
| 632 | knew.info = ak4xxx_switch_info; |
| 633 | knew.get = ak4xxx_switch_get; |
| 634 | knew.put = ak4xxx_switch_put; |
| 635 | knew.access = 0; |
| 636 | /* register 1, bit 0 (SMUTE): 0 = normal operation, |
| 637 | 1 = mute */ |
| 638 | knew.private_value = |
| 639 | AK_COMPOSE(idx/2, 1, 0, 0) | AK_INVERT; |
| 640 | err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); |
| 641 | if (err < 0) |
| 642 | return err; |
| 643 | } |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 644 | memset(&knew, 0, sizeof(knew)); |
| 645 | if (! ak->dac_info || ! ak->dac_info[mixer_ch].name) { |
| 646 | knew.name = "DAC Volume"; |
| 647 | knew.index = mixer_ch + ak->idx_offset * 2; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 648 | num_stereo = 1; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 649 | } else { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 650 | knew.name = ak->dac_info[mixer_ch].name; |
| 651 | num_stereo = ak->dac_info[mixer_ch].num_channels; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 652 | } |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 653 | knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 654 | knew.count = 1; |
| 655 | knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 656 | SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 657 | if (num_stereo == 2) { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 658 | knew.info = snd_akm4xxx_stereo_volume_info; |
| 659 | knew.get = snd_akm4xxx_stereo_volume_get; |
| 660 | knew.put = snd_akm4xxx_stereo_volume_put; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 661 | } else { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 662 | knew.info = snd_akm4xxx_volume_info; |
| 663 | knew.get = snd_akm4xxx_volume_get; |
| 664 | knew.put = snd_akm4xxx_volume_put; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | switch (ak->type) { |
| 667 | case SND_AK4524: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 668 | /* register 6 & 7 */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 669 | knew.private_value = |
| 670 | AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127) | |
| 671 | AK_VOL_CVT; |
| 672 | knew.tlv.p = db_scale_vol_datt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | break; |
| 674 | case SND_AK4528: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 675 | /* register 4 & 5 */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 676 | knew.private_value = |
| 677 | AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127) | |
| 678 | AK_VOL_CVT; |
| 679 | knew.tlv.p = db_scale_vol_datt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | break; |
| 681 | case SND_AK4529: { |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 682 | /* registers 2-7 and b,c */ |
| 683 | int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 684 | knew.private_value = |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 685 | AK_COMPOSE(0, val, 0, 255) | AK_INVERT; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 686 | knew.tlv.p = db_scale_8bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | break; |
| 688 | } |
| 689 | case SND_AK4355: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 690 | /* register 4-9, chip #0 only */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 691 | knew.private_value = AK_COMPOSE(0, idx + 4, 0, 255); |
| 692 | knew.tlv.p = db_scale_8bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | break; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame] | 694 | case SND_AK4358: { |
| 695 | /* register 4-9 and 11-12, chip #0 only */ |
| 696 | int addr = idx < 6 ? idx + 4 : idx + 5; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 697 | knew.private_value = |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame] | 698 | AK_COMPOSE(0, addr, 0, 127) | AK_NEEDSMSB; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 699 | knew.tlv.p = db_scale_7bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | break; |
Jochen Voss | 3479307 | 2006-08-23 18:35:35 +0200 | [diff] [blame] | 701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | case SND_AK4381: |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 703 | /* register 3 & 4 */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 704 | knew.private_value = |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 705 | AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 706 | knew.tlv.p = db_scale_linear; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | break; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 708 | case SND_AK4620: |
| 709 | /* register 6 & 7 */ |
| 710 | knew.private_value = |
| 711 | AK_COMPOSE(idx/2, (idx%2) + 6, 0, 255); |
| 712 | knew.tlv.p = db_scale_linear; |
| 713 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | default: |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 715 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 717 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 718 | err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 719 | if (err < 0) |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 720 | return err; |
Jani Alinikula | c83c0c4 | 2006-06-27 15:00:55 +0200 | [diff] [blame] | 721 | |
| 722 | idx += num_stereo; |
| 723 | mixer_ch++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 725 | return 0; |
| 726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 728 | static int build_adc_controls(struct snd_akm4xxx *ak) |
| 729 | { |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 730 | int idx, err, mixer_ch, num_stereo, max_steps; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 731 | struct snd_kcontrol_new knew; |
| 732 | |
| 733 | mixer_ch = 0; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 734 | if (ak->type == SND_AK4528) |
| 735 | return 0; /* no controls */ |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 736 | for (idx = 0; idx < ak->num_adcs;) { |
| 737 | memset(&knew, 0, sizeof(knew)); |
| 738 | if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) { |
| 739 | knew.name = "ADC Volume"; |
| 740 | knew.index = mixer_ch + ak->idx_offset * 2; |
| 741 | num_stereo = 1; |
| 742 | } else { |
| 743 | knew.name = ak->adc_info[mixer_ch].name; |
| 744 | num_stereo = ak->adc_info[mixer_ch].num_channels; |
| 745 | } |
| 746 | knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 747 | knew.count = 1; |
| 748 | knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 749 | SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
| 750 | if (num_stereo == 2) { |
| 751 | knew.info = snd_akm4xxx_stereo_volume_info; |
| 752 | knew.get = snd_akm4xxx_stereo_volume_get; |
| 753 | knew.put = snd_akm4xxx_stereo_volume_put; |
| 754 | } else { |
| 755 | knew.info = snd_akm4xxx_volume_info; |
| 756 | knew.get = snd_akm4xxx_volume_get; |
| 757 | knew.put = snd_akm4xxx_volume_put; |
| 758 | } |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 759 | /* register 4 & 5 */ |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 760 | if (ak->type == SND_AK5365) |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 761 | max_steps = 152; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 762 | else |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 763 | max_steps = 164; |
| 764 | knew.private_value = |
| 765 | AK_COMPOSE(idx/2, (idx%2) + 4, 0, max_steps) | |
| 766 | AK_VOL_CVT | AK_IPGA; |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 767 | knew.tlv.p = db_scale_vol_datt; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 768 | err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); |
| 769 | if (err < 0) |
| 770 | return err; |
| 771 | |
| 772 | if (ak->type == SND_AK5365 && (idx % 2) == 0) { |
| 773 | if (! ak->adc_info || |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 774 | ! ak->adc_info[mixer_ch].switch_name) { |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 775 | knew.name = "Capture Switch"; |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 776 | knew.index = mixer_ch + ak->idx_offset * 2; |
| 777 | } else |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 778 | knew.name = ak->adc_info[mixer_ch].switch_name; |
| 779 | knew.info = ak4xxx_switch_info; |
| 780 | knew.get = ak4xxx_switch_get; |
| 781 | knew.put = ak4xxx_switch_put; |
| 782 | knew.access = 0; |
| 783 | /* register 2, bit 0 (SMUTE): 0 = normal operation, |
| 784 | 1 = mute */ |
| 785 | knew.private_value = |
| 786 | AK_COMPOSE(idx/2, 2, 0, 0) | AK_INVERT; |
| 787 | err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); |
| 788 | if (err < 0) |
| 789 | return err; |
Jochen Voss | a58e7cb | 2006-10-04 18:04:10 +0200 | [diff] [blame] | 790 | |
| 791 | memset(&knew, 0, sizeof(knew)); |
| 792 | knew.name = ak->adc_info[mixer_ch].selector_name; |
| 793 | if (!knew.name) { |
| 794 | knew.name = "Capture Channel"; |
| 795 | knew.index = mixer_ch + ak->idx_offset * 2; |
| 796 | } |
| 797 | |
| 798 | knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 799 | knew.info = ak4xxx_capture_source_info; |
| 800 | knew.get = ak4xxx_capture_source_get; |
| 801 | knew.put = ak4xxx_capture_source_put; |
| 802 | knew.access = 0; |
| 803 | /* input selector control: reg. 1, bits 0-2. |
| 804 | * mis-use 'shift' to pass mixer_ch */ |
| 805 | knew.private_value |
| 806 | = AK_COMPOSE(idx/2, 1, mixer_ch, 0x07); |
| 807 | err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); |
| 808 | if (err < 0) |
| 809 | return err; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | idx += num_stereo; |
| 813 | mixer_ch++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 815 | return 0; |
| 816 | } |
Jochen Voss | 683fe15 | 2006-08-08 21:12:44 +0200 | [diff] [blame] | 817 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 818 | static int build_deemphasis(struct snd_akm4xxx *ak, int num_emphs) |
| 819 | { |
| 820 | int idx, err; |
| 821 | struct snd_kcontrol_new knew; |
Jochen Voss | 30ba6e2 | 2006-08-09 14:26:26 +0200 | [diff] [blame] | 822 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 823 | for (idx = 0; idx < num_emphs; idx++) { |
| 824 | memset(&knew, 0, sizeof(knew)); |
| 825 | knew.name = "Deemphasis"; |
| 826 | knew.index = idx + ak->idx_offset; |
| 827 | knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 828 | knew.count = 1; |
| 829 | knew.info = snd_akm4xxx_deemphasis_info; |
| 830 | knew.get = snd_akm4xxx_deemphasis_get; |
| 831 | knew.put = snd_akm4xxx_deemphasis_put; |
| 832 | switch (ak->type) { |
| 833 | case SND_AK4524: |
| 834 | case SND_AK4528: |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 835 | case SND_AK4620: |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 836 | /* register 3 */ |
| 837 | knew.private_value = AK_COMPOSE(idx, 3, 0, 0); |
| 838 | break; |
| 839 | case SND_AK4529: { |
| 840 | int shift = idx == 3 ? 6 : (2 - idx) * 2; |
| 841 | /* register 8 with shift */ |
| 842 | knew.private_value = AK_COMPOSE(0, 8, shift, 0); |
| 843 | break; |
| 844 | } |
| 845 | case SND_AK4355: |
| 846 | case SND_AK4358: |
| 847 | knew.private_value = AK_COMPOSE(idx, 3, 0, 0); |
| 848 | break; |
| 849 | case SND_AK4381: |
| 850 | knew.private_value = AK_COMPOSE(idx, 1, 1, 0); |
| 851 | break; |
| 852 | default: |
| 853 | return -EINVAL; |
| 854 | } |
| 855 | err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); |
Jochen Voss | 30ba6e2 | 2006-08-09 14:26:26 +0200 | [diff] [blame] | 856 | if (err < 0) |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 857 | return err; |
| 858 | } |
| 859 | return 0; |
| 860 | } |
| 861 | |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 862 | static void proc_regs_read(struct snd_info_entry *entry, |
| 863 | struct snd_info_buffer *buffer) |
| 864 | { |
Joe Perches | 9fe856e | 2010-09-04 18:52:54 -0700 | [diff] [blame] | 865 | struct snd_akm4xxx *ak = entry->private_data; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 866 | int reg, val, chip; |
| 867 | for (chip = 0; chip < ak->num_chips; chip++) { |
| 868 | for (reg = 0; reg < ak->total_regs; reg++) { |
| 869 | val = snd_akm4xxx_get(ak, chip, reg); |
| 870 | snd_iprintf(buffer, "chip %d: 0x%02x = 0x%02x\n", chip, |
| 871 | reg, val); |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | static int proc_init(struct snd_akm4xxx *ak) |
| 877 | { |
| 878 | struct snd_info_entry *entry; |
| 879 | int err; |
| 880 | err = snd_card_proc_new(ak->card, ak->name, &entry); |
| 881 | if (err < 0) |
| 882 | return err; |
| 883 | snd_info_set_text_ops(entry, ak, proc_regs_read); |
| 884 | return 0; |
| 885 | } |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 886 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 887 | int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak) |
| 888 | { |
| 889 | int err, num_emphs; |
| 890 | |
| 891 | err = build_dac_controls(ak); |
| 892 | if (err < 0) |
| 893 | return err; |
| 894 | |
Takashi Iwai | 854b66e | 2006-09-08 12:27:38 +0200 | [diff] [blame] | 895 | err = build_adc_controls(ak); |
| 896 | if (err < 0) |
| 897 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | if (ak->type == SND_AK4355 || ak->type == SND_AK4358) |
| 899 | num_emphs = 1; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 900 | else if (ak->type == SND_AK4620) |
| 901 | num_emphs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | else |
| 903 | num_emphs = ak->num_dacs / 2; |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 904 | err = build_deemphasis(ak, num_emphs); |
| 905 | if (err < 0) |
| 906 | return err; |
Pavel Hofman | 8f34692 | 2009-09-16 22:25:36 +0200 | [diff] [blame] | 907 | err = proc_init(ak); |
| 908 | if (err < 0) |
| 909 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Takashi Iwai | 723b2b0 | 2006-08-30 16:49:54 +0200 | [diff] [blame] | 911 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
Takashi Iwai | cb9d24e | 2006-06-27 17:49:12 +0200 | [diff] [blame] | 913 | EXPORT_SYMBOL(snd_akm4xxx_build_controls); |
| 914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | static int __init alsa_akm4xxx_module_init(void) |
| 916 | { |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static void __exit alsa_akm4xxx_module_exit(void) |
| 921 | { |
| 922 | } |
| 923 | |
| 924 | module_init(alsa_akm4xxx_module_init) |
| 925 | module_exit(alsa_akm4xxx_module_exit) |