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