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