Blame view

sound/pci/ak4531_codec.c 17.2 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
2
   *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   *  Universal routines for AK4531 codec
   *
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   *
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
23
  #include <linux/delay.h>
  #include <linux/init.h>
  #include <linux/slab.h>
62932df8f   Ingo Molnar   [ALSA] semaphore ...
24
  #include <linux/mutex.h>
da155d5b4   Paul Gortmaker   sound: Add module...
25
  #include <linux/module.h>
62932df8f   Ingo Molnar   [ALSA] semaphore ...
26

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
  #include <sound/core.h>
  #include <sound/ak4531_codec.h>
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
29
  #include <sound/tlv.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30

6719292af   Jaroslav Kysela   ALSA: Remove dupl...
31
  /*
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
32
  MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
  MODULE_DESCRIPTION("Universal routines for AK4531 codec");
  MODULE_LICENSE("GPL");
6719292af   Jaroslav Kysela   ALSA: Remove dupl...
35
  */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36

adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
37
  #ifdef CONFIG_PROC_FS
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
38
  static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531);
adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
39
40
41
  #else
  #define snd_ak4531_proc_init(card,ak)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
47
  
  /*
   *
   */
   
  #if 0
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
48
  static void snd_ak4531_dump(struct snd_ak4531 *ak4531)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
  {
  	int idx;
  	
  	for (idx = 0; idx < 0x19; idx++)
ee419653a   Takashi Iwai   ALSA: Fix missing...
53
54
55
  		printk(KERN_DEBUG "ak4531 0x%x: 0x%x
  ",
  		       idx, ak4531->regs[idx]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
58
59
60
61
62
63
64
65
66
67
68
  }
  
  #endif
  
  /*
   *
   */
  
  #define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    .info = snd_ak4531_info_single, \
    .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
    .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) }
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
69
70
71
72
73
74
75
76
  #define AK4531_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv)    \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
    .name = xname, .index = xindex, \
    .info = snd_ak4531_info_single, \
    .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
    .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22), \
    .tlv = { .p = (xtlv) } }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77

9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
78
  static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
80
81
82
83
84
85
86
87
88
  {
  	int mask = (kcontrol->private_value >> 24) & 0xff;
  
  	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 1;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = mask;
  	return 0;
  }
   
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
89
  static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
91
  	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
95
96
  	int reg = kcontrol->private_value & 0xff;
  	int shift = (kcontrol->private_value >> 16) & 0x07;
  	int mask = (kcontrol->private_value >> 24) & 0xff;
  	int invert = (kcontrol->private_value >> 22) & 1;
  	int val;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
97
  	mutex_lock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  	val = (ak4531->regs[reg] >> shift) & mask;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
99
  	mutex_unlock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
103
104
105
  	if (invert) {
  		val = mask - val;
  	}
  	ucontrol->value.integer.value[0] = val;
  	return 0;
  }
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
106
  static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
108
  	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
113
114
115
116
117
118
119
120
  	int reg = kcontrol->private_value & 0xff;
  	int shift = (kcontrol->private_value >> 16) & 0x07;
  	int mask = (kcontrol->private_value >> 24) & 0xff;
  	int invert = (kcontrol->private_value >> 22) & 1;
  	int change;
  	int val;
  
  	val = ucontrol->value.integer.value[0] & mask;
  	if (invert) {
  		val = mask - val;
  	}
  	val <<= shift;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
121
  	mutex_lock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
123
124
  	val = (ak4531->regs[reg] & ~(mask << shift)) | val;
  	change = val != ak4531->regs[reg];
  	ak4531->write(ak4531, reg, ak4531->regs[reg] = val);
62932df8f   Ingo Molnar   [ALSA] semaphore ...
125
  	mutex_unlock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
127
128
129
130
131
132
133
  	return change;
  }
  
  #define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    .info = snd_ak4531_info_double, \
    .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
    .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
134
135
136
137
138
139
140
141
  #define AK4531_DOUBLE_TLV(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert, xtlv) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
    .name = xname, .index = xindex, \
    .info = snd_ak4531_info_double, \
    .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
    .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22), \
    .tlv = { .p = (xtlv) } }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142

9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
143
  static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144
145
146
147
148
149
150
151
152
153
  {
  	int mask = (kcontrol->private_value >> 24) & 0xff;
  
  	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 2;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = mask;
  	return 0;
  }
   
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
154
  static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
156
  	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
158
159
160
161
162
163
  	int left_reg = kcontrol->private_value & 0xff;
  	int right_reg = (kcontrol->private_value >> 8) & 0xff;
  	int left_shift = (kcontrol->private_value >> 16) & 0x07;
  	int right_shift = (kcontrol->private_value >> 19) & 0x07;
  	int mask = (kcontrol->private_value >> 24) & 0xff;
  	int invert = (kcontrol->private_value >> 22) & 1;
  	int left, right;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
164
  	mutex_lock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
166
  	left = (ak4531->regs[left_reg] >> left_shift) & mask;
  	right = (ak4531->regs[right_reg] >> right_shift) & mask;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
167
  	mutex_unlock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
169
170
171
172
173
174
175
  	if (invert) {
  		left = mask - left;
  		right = mask - right;
  	}
  	ucontrol->value.integer.value[0] = left;
  	ucontrol->value.integer.value[1] = right;
  	return 0;
  }
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
176
  static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
178
  	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  	int left_reg = kcontrol->private_value & 0xff;
  	int right_reg = (kcontrol->private_value >> 8) & 0xff;
  	int left_shift = (kcontrol->private_value >> 16) & 0x07;
  	int right_shift = (kcontrol->private_value >> 19) & 0x07;
  	int mask = (kcontrol->private_value >> 24) & 0xff;
  	int invert = (kcontrol->private_value >> 22) & 1;
  	int change;
  	int left, right;
  
  	left = ucontrol->value.integer.value[0] & mask;
  	right = ucontrol->value.integer.value[1] & mask;
  	if (invert) {
  		left = mask - left;
  		right = mask - right;
  	}
  	left <<= left_shift;
  	right <<= right_shift;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
196
  	mutex_lock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
198
199
200
201
202
203
204
205
206
207
  	if (left_reg == right_reg) {
  		left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right;
  		change = left != ak4531->regs[left_reg];
  		ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
  	} else {
  		left = (ak4531->regs[left_reg] & ~(mask << left_shift)) | left;
  		right = (ak4531->regs[right_reg] & ~(mask << right_shift)) | right;
  		change = left != ak4531->regs[left_reg] || right != ak4531->regs[right_reg];
  		ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
  		ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right);
  	}
62932df8f   Ingo Molnar   [ALSA] semaphore ...
208
  	mutex_unlock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
211
212
213
214
215
216
  	return change;
  }
  
  #define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
    .info = snd_ak4531_info_input_sw, \
    .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \
    .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
217
  static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218
219
220
221
222
223
224
225
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  	uinfo->count = 4;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = 1;
  	return 0;
  }
   
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
226
  static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
228
  	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229
230
231
232
  	int reg1 = kcontrol->private_value & 0xff;
  	int reg2 = (kcontrol->private_value >> 8) & 0xff;
  	int left_shift = (kcontrol->private_value >> 16) & 0x0f;
  	int right_shift = (kcontrol->private_value >> 24) & 0x0f;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
233
  	mutex_lock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
  	ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1;
  	ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1;
  	ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1;
  	ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
238
  	mutex_unlock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
  	return 0;
  }
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
241
  static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
243
  	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
246
247
248
249
  	int reg1 = kcontrol->private_value & 0xff;
  	int reg2 = (kcontrol->private_value >> 8) & 0xff;
  	int left_shift = (kcontrol->private_value >> 16) & 0x0f;
  	int right_shift = (kcontrol->private_value >> 24) & 0x0f;
  	int change;
  	int val1, val2;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
250
  	mutex_lock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251
252
253
254
255
256
257
258
259
  	val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift));
  	val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift));
  	val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;
  	val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift;
  	val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift;
  	val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift;
  	change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2];
  	ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1);
  	ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2);
62932df8f   Ingo Molnar   [ALSA] semaphore ...
260
  	mutex_unlock(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
262
  	return change;
  }
0cb29ea0d   Takashi Iwai   [ALSA] Add even m...
263
264
265
  static const DECLARE_TLV_DB_SCALE(db_scale_master, -6200, 200, 0);
  static const DECLARE_TLV_DB_SCALE(db_scale_mono, -2800, 400, 0);
  static const DECLARE_TLV_DB_SCALE(db_scale_input, -5000, 200, 0);
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
266

23ce15476   Takashi Iwai   [ALSA] Make ak453...
267
  static struct snd_kcontrol_new snd_ak4531_controls[] __devinitdata = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268

9107226d2   Takashi Iwai   [ALSA] Add dB sca...
269
270
271
  AK4531_DOUBLE_TLV("Master Playback Switch", 0,
  		  AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1,
  		  db_scale_master),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
  AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
273
274
  AK4531_SINGLE_TLV("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1,
  		  db_scale_mono),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
275
276
277
  AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1),
  
  AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
278
279
  AK4531_DOUBLE_TLV("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1,
  		  db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
280
281
282
283
  AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0),
  AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0),
  
  AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
284
285
  AK4531_DOUBLE_TLV("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1,
  		  db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
287
288
289
  AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0),
  AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5),
  
  AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
290
291
  AK4531_DOUBLE_TLV("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1,
  		  db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
293
294
295
  AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0),
  AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1),
  
  AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
296
297
  AK4531_DOUBLE_TLV("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1,
  		  db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
301
  AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0),
  AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3),
  
  AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
302
303
  AK4531_DOUBLE_TLV("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1,
  		  db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
306
307
  AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0),
  AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),
  
  AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
308
  AK4531_SINGLE_TLV("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1, db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
309
310
311
312
  AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0),
  AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0),
  
  AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
313
  AK4531_SINGLE_TLV("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1, db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
314
315
  AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0),
  AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0),
9107226d2   Takashi Iwai   [ALSA] Add dB sca...
316
  AK4531_SINGLE_TLV("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1, db_scale_input),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
319
320
321
322
323
324
325
326
327
  AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1),
  AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0),
  AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0),
  
  AK4531_DOUBLE("Mic Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 7, 7, 1, 0),
  AK4531_DOUBLE("Mono1 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 6, 6, 1, 0),
  AK4531_DOUBLE("Mono2 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 5, 5, 1, 0),
  
  AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0),
  AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0)
  };
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
328
  static int snd_ak4531_free(struct snd_ak4531 *ak4531)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
330
331
332
333
334
335
336
  {
  	if (ak4531) {
  		if (ak4531->private_free)
  			ak4531->private_free(ak4531);
  		kfree(ak4531);
  	}
  	return 0;
  }
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
337
  static int snd_ak4531_dev_free(struct snd_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
339
  	struct snd_ak4531 *ak4531 = device->device_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
  	return snd_ak4531_free(ak4531);
  }
  
  static u8 snd_ak4531_initial_map[0x19 + 1] = {
  	0x9f,		/* 00: Master Volume Lch */
  	0x9f,		/* 01: Master Volume Rch */
  	0x9f,		/* 02: Voice Volume Lch */
  	0x9f,		/* 03: Voice Volume Rch */
  	0x9f,		/* 04: FM Volume Lch */
  	0x9f,		/* 05: FM Volume Rch */
  	0x9f,		/* 06: CD Audio Volume Lch */
  	0x9f,		/* 07: CD Audio Volume Rch */
  	0x9f,		/* 08: Line Volume Lch */
  	0x9f,		/* 09: Line Volume Rch */
  	0x9f,		/* 0a: Aux Volume Lch */
  	0x9f,		/* 0b: Aux Volume Rch */
  	0x9f,		/* 0c: Mono1 Volume */
  	0x9f,		/* 0d: Mono2 Volume */
  	0x9f,		/* 0e: Mic Volume */
  	0x87,		/* 0f: Mono-out Volume */
  	0x00,		/* 10: Output Mixer SW1 */
  	0x00,		/* 11: Output Mixer SW2 */
  	0x00,		/* 12: Lch Input Mixer SW1 */
  	0x00,		/* 13: Rch Input Mixer SW1 */
  	0x00,		/* 14: Lch Input Mixer SW2 */
  	0x00,		/* 15: Rch Input Mixer SW2 */
  	0x00,		/* 16: Reset & Power Down */
  	0x00,		/* 17: Clock Select */
  	0x00,		/* 18: AD Input Select */
  	0x01		/* 19: Mic Amp Setup */
  };
23ce15476   Takashi Iwai   [ALSA] Make ak453...
371
372
373
  int __devinit snd_ak4531_mixer(struct snd_card *card,
  			       struct snd_ak4531 *_ak4531,
  			       struct snd_ak4531 **rak4531)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
375
376
  {
  	unsigned int idx;
  	int err;
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
377
378
  	struct snd_ak4531 *ak4531;
  	static struct snd_device_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
379
380
  		.dev_free =	snd_ak4531_dev_free,
  	};
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
381
382
383
384
  	if (snd_BUG_ON(!card || !_ak4531))
  		return -EINVAL;
  	if (rak4531)
  		*rak4531 = NULL;
e560d8d83   Takashi Iwai   [ALSA] Replace wi...
385
  	ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
  	if (ak4531 == NULL)
  		return -ENOMEM;
  	*ak4531 = *_ak4531;
62932df8f   Ingo Molnar   [ALSA] semaphore ...
389
  	mutex_init(&ak4531->reg_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
391
392
393
394
395
396
397
  	if ((err = snd_component_add(card, "AK4531")) < 0) {
  		snd_ak4531_free(ak4531);
  		return err;
  	}
  	strcpy(card->mixername, "Asahi Kasei AK4531");
  	ak4531->write(ak4531, AK4531_RESET, 0x03);	/* no RST, PD */
  	udelay(100);
  	ak4531->write(ak4531, AK4531_CLOCK, 0x00);	/* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */
11d3824ad   Takashi Iwai   [ALSA] ak4531 - A...
398
  	for (idx = 0; idx <= 0x19; idx++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
  		if (idx == AK4531_RESET || idx == AK4531_CLOCK)
  			continue;
  		ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]);	/* recording source is mixer */
  	}
  	for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) {
  		if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) {
  			snd_ak4531_free(ak4531);
  			return err;
  		}
  	}
  	snd_ak4531_proc_init(card, ak4531);
  	if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) {
  		snd_ak4531_free(ak4531);
  		return err;
  	}
  
  #if 0
  	snd_ak4531_dump(ak4531);
  #endif
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
418
419
  	if (rak4531)
  		*rak4531 = ak4531;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
420
421
422
423
  	return 0;
  }
  
  /*
11d3824ad   Takashi Iwai   [ALSA] ak4531 - A...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
   * power management
   */
  #ifdef CONFIG_PM
  void snd_ak4531_suspend(struct snd_ak4531 *ak4531)
  {
  	/* mute */
  	ak4531->write(ak4531, AK4531_LMASTER, 0x9f);
  	ak4531->write(ak4531, AK4531_RMASTER, 0x9f);
  	/* powerdown */
  	ak4531->write(ak4531, AK4531_RESET, 0x01);
  }
  
  void snd_ak4531_resume(struct snd_ak4531 *ak4531)
  {
  	int idx;
  
  	/* initialize */
  	ak4531->write(ak4531, AK4531_RESET, 0x03);
  	udelay(100);
  	ak4531->write(ak4531, AK4531_CLOCK, 0x00);
  	/* restore mixer registers */
  	for (idx = 0; idx <= 0x19; idx++) {
  		if (idx == AK4531_RESET || idx == AK4531_CLOCK)
  			continue;
  		ak4531->write(ak4531, idx, ak4531->regs[idx]);
  	}
  }
  #endif
adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
452
  #ifdef CONFIG_PROC_FS
11d3824ad   Takashi Iwai   [ALSA] ak4531 - A...
453
  /*
adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
454
   * /proc interface
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
   */
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
456
457
  static void snd_ak4531_proc_read(struct snd_info_entry *entry, 
  				 struct snd_info_buffer *buffer)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
458
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
459
  	struct snd_ak4531 *ak4531 = entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
460
461
462
463
464
465
466
467
468
469
470
  
  	snd_iprintf(buffer, "Asahi Kasei AK4531
  
  ");
  	snd_iprintf(buffer, "Recording source   : %s
  "
  		    "MIC gain           : %s
  ",
  		    ak4531->regs[AK4531_AD_IN] & 1 ? "external" : "mixer",
  		    ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB");
  }
23ce15476   Takashi Iwai   [ALSA] Make ak453...
471
472
  static void __devinit
  snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
  {
9f38945fa   Takashi Iwai   [ALSA] Remove xxx...
474
  	struct snd_info_entry *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
476
  
  	if (! snd_card_proc_new(card, "ak4531", &entry))
bf850204a   Takashi Iwai   [ALSA] Remove unn...
477
  		snd_info_set_text_ops(entry, ak4531, snd_ak4531_proc_read);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
478
  }
adf1b3d25   Takashi Iwai   [ALSA] Optimize f...
479
  #endif