]>
Commit | Line | Data |
---|---|---|
d0ce9946 CL |
1 | /* |
2 | * C-Media CMI8788 driver - mixer code | |
3 | * | |
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | |
5 | * | |
6 | * | |
7 | * This driver is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License, version 2. | |
9 | * | |
10 | * This driver is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this driver; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | ||
d0ce9946 CL |
20 | #include <linux/mutex.h> |
21 | #include <sound/ac97_codec.h> | |
22 | #include <sound/asoundef.h> | |
23 | #include <sound/control.h> | |
24 | #include <sound/tlv.h> | |
25 | #include "oxygen.h" | |
26 | ||
27 | static int dac_volume_info(struct snd_kcontrol *ctl, | |
28 | struct snd_ctl_elem_info *info) | |
29 | { | |
d0ce9946 CL |
30 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
31 | info->count = 8; | |
ccc80fb4 | 32 | info->value.integer.min = 0; |
d0ce9946 CL |
33 | info->value.integer.max = 0xff; |
34 | return 0; | |
35 | } | |
36 | ||
37 | static int dac_volume_get(struct snd_kcontrol *ctl, | |
38 | struct snd_ctl_elem_value *value) | |
39 | { | |
40 | struct oxygen *chip = ctl->private_data; | |
41 | unsigned int i; | |
42 | ||
43 | mutex_lock(&chip->mutex); | |
44 | for (i = 0; i < 8; ++i) | |
45 | value->value.integer.value[i] = chip->dac_volume[i]; | |
46 | mutex_unlock(&chip->mutex); | |
47 | return 0; | |
48 | } | |
49 | ||
50 | static int dac_volume_put(struct snd_kcontrol *ctl, | |
51 | struct snd_ctl_elem_value *value) | |
52 | { | |
53 | struct oxygen *chip = ctl->private_data; | |
54 | unsigned int i; | |
55 | int changed; | |
56 | ||
57 | changed = 0; | |
58 | mutex_lock(&chip->mutex); | |
59 | for (i = 0; i < 8; ++i) | |
60 | if (value->value.integer.value[i] != chip->dac_volume[i]) { | |
61 | chip->dac_volume[i] = value->value.integer.value[i]; | |
62 | changed = 1; | |
63 | } | |
64 | if (changed) | |
65 | chip->model->update_dac_volume(chip); | |
66 | mutex_unlock(&chip->mutex); | |
67 | return changed; | |
68 | } | |
69 | ||
70 | static int dac_mute_get(struct snd_kcontrol *ctl, | |
71 | struct snd_ctl_elem_value *value) | |
72 | { | |
73 | struct oxygen *chip = ctl->private_data; | |
74 | ||
75 | mutex_lock(&chip->mutex); | |
76 | value->value.integer.value[0] = !chip->dac_mute; | |
77 | mutex_unlock(&chip->mutex); | |
78 | return 0; | |
79 | } | |
80 | ||
81 | static int dac_mute_put(struct snd_kcontrol *ctl, | |
82 | struct snd_ctl_elem_value *value) | |
83 | { | |
84 | struct oxygen *chip = ctl->private_data; | |
85 | int changed; | |
86 | ||
87 | mutex_lock(&chip->mutex); | |
88 | changed = !value->value.integer.value[0] != chip->dac_mute; | |
89 | if (changed) { | |
90 | chip->dac_mute = !value->value.integer.value[0]; | |
91 | chip->model->update_dac_mute(chip); | |
92 | } | |
93 | mutex_unlock(&chip->mutex); | |
94 | return changed; | |
95 | } | |
96 | ||
97 | static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | |
98 | { | |
99 | static const char *const names[3] = { | |
7113e958 | 100 | "Front", "Front+Surround", "Front+Surround+Back" |
d0ce9946 CL |
101 | }; |
102 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
103 | info->count = 1; | |
104 | info->value.enumerated.items = 3; | |
105 | if (info->value.enumerated.item > 2) | |
106 | info->value.enumerated.item = 2; | |
107 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | |
108 | return 0; | |
109 | } | |
110 | ||
111 | static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | |
112 | { | |
113 | struct oxygen *chip = ctl->private_data; | |
114 | ||
115 | mutex_lock(&chip->mutex); | |
116 | value->value.enumerated.item[0] = chip->dac_routing; | |
117 | mutex_unlock(&chip->mutex); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | void oxygen_update_dac_routing(struct oxygen *chip) | |
122 | { | |
d0ce9946 | 123 | static const unsigned int reg_values[3] = { |
e0059549 | 124 | 0xe400, /* front <- 0, surround <- 1, center <- 2, back <- 3 */ |
7113e958 CL |
125 | 0xe000, /* front <- 0, surround <- 0, center <- 2, back <- 3 */ |
126 | 0x2000 /* front <- 0, surround <- 0, center <- 2, back <- 0 */ | |
d0ce9946 | 127 | }; |
7113e958 | 128 | u8 channels; |
d0ce9946 CL |
129 | unsigned int reg_value; |
130 | ||
7113e958 CL |
131 | channels = oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) & |
132 | OXYGEN_PLAY_CHANNELS_MASK; | |
133 | if (channels == OXYGEN_PLAY_CHANNELS_2) | |
d0ce9946 | 134 | reg_value = reg_values[chip->dac_routing]; |
7113e958 CL |
135 | else if (channels == OXYGEN_PLAY_CHANNELS_8) |
136 | reg_value = 0x6c00; /* surround <- 3, back <- 1 */ | |
d0ce9946 | 137 | else |
e0059549 | 138 | reg_value = 0xe400; |
d0ce9946 CL |
139 | oxygen_write16_masked(chip, OXYGEN_PLAY_ROUTING, reg_value, 0xff00); |
140 | } | |
141 | ||
142 | static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | |
143 | { | |
144 | struct oxygen *chip = ctl->private_data; | |
145 | int changed; | |
146 | ||
147 | mutex_lock(&chip->mutex); | |
148 | changed = value->value.enumerated.item[0] != chip->dac_routing; | |
149 | if (changed) { | |
150 | chip->dac_routing = min(value->value.enumerated.item[0], 2u); | |
151 | spin_lock_irq(&chip->reg_lock); | |
152 | oxygen_update_dac_routing(chip); | |
153 | spin_unlock_irq(&chip->reg_lock); | |
154 | } | |
155 | mutex_unlock(&chip->mutex); | |
156 | return changed; | |
157 | } | |
158 | ||
159 | static int spdif_switch_get(struct snd_kcontrol *ctl, | |
160 | struct snd_ctl_elem_value *value) | |
161 | { | |
162 | struct oxygen *chip = ctl->private_data; | |
163 | ||
164 | mutex_lock(&chip->mutex); | |
165 | value->value.integer.value[0] = chip->spdif_playback_enable; | |
166 | mutex_unlock(&chip->mutex); | |
167 | return 0; | |
168 | } | |
169 | ||
170 | static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate) | |
171 | { | |
172 | switch (oxygen_rate) { | |
173 | case OXYGEN_RATE_32000: | |
174 | return IEC958_AES3_CON_FS_32000 << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
175 | case OXYGEN_RATE_44100: | |
176 | return IEC958_AES3_CON_FS_44100 << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
177 | default: /* OXYGEN_RATE_48000 */ | |
178 | return IEC958_AES3_CON_FS_48000 << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
179 | case OXYGEN_RATE_64000: | |
180 | return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
181 | case OXYGEN_RATE_88200: | |
182 | return 0x8 << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
183 | case OXYGEN_RATE_96000: | |
184 | return 0xa << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
185 | case OXYGEN_RATE_176400: | |
186 | return 0xc << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
187 | case OXYGEN_RATE_192000: | |
188 | return 0xe << OXYGEN_SPDIF_CS_RATE_SHIFT; | |
189 | } | |
190 | } | |
191 | ||
192 | void oxygen_update_spdif_source(struct oxygen *chip) | |
193 | { | |
194 | u32 old_control, new_control; | |
195 | u16 old_routing, new_routing; | |
196 | unsigned int oxygen_rate; | |
197 | ||
198 | old_control = oxygen_read32(chip, OXYGEN_SPDIF_CONTROL); | |
199 | old_routing = oxygen_read16(chip, OXYGEN_PLAY_ROUTING); | |
200 | if (chip->pcm_active & (1 << PCM_SPDIF)) { | |
201 | new_control = old_control | OXYGEN_SPDIF_OUT_ENABLE; | |
202 | new_routing = (old_routing & ~0x00e0) | 0x0000; | |
203 | oxygen_rate = (old_control >> OXYGEN_SPDIF_OUT_RATE_SHIFT) | |
204 | & OXYGEN_I2S_RATE_MASK; | |
205 | /* S/PDIF rate was already set by the caller */ | |
206 | } else if ((chip->pcm_active & (1 << PCM_MULTICH)) && | |
207 | chip->spdif_playback_enable) { | |
208 | new_routing = (old_routing & ~0x00e0) | 0x0020; | |
209 | oxygen_rate = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT) | |
210 | & OXYGEN_I2S_RATE_MASK; | |
211 | new_control = (old_control & ~OXYGEN_SPDIF_OUT_RATE_MASK) | | |
212 | (oxygen_rate << OXYGEN_SPDIF_OUT_RATE_SHIFT) | | |
213 | OXYGEN_SPDIF_OUT_ENABLE; | |
214 | } else { | |
215 | new_control = old_control & ~OXYGEN_SPDIF_OUT_ENABLE; | |
216 | new_routing = old_routing; | |
217 | oxygen_rate = OXYGEN_RATE_44100; | |
218 | } | |
219 | if (old_routing != new_routing) { | |
220 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, | |
221 | new_control & ~OXYGEN_SPDIF_OUT_ENABLE); | |
222 | oxygen_write16(chip, OXYGEN_PLAY_ROUTING, new_routing); | |
223 | } | |
224 | if (new_control & OXYGEN_SPDIF_OUT_ENABLE) | |
225 | oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, | |
226 | oxygen_spdif_rate(oxygen_rate) | | |
227 | ((chip->pcm_active & (1 << PCM_SPDIF)) ? | |
228 | chip->spdif_pcm_bits : chip->spdif_bits)); | |
229 | oxygen_write32(chip, OXYGEN_SPDIF_CONTROL, new_control); | |
230 | } | |
231 | ||
232 | static int spdif_switch_put(struct snd_kcontrol *ctl, | |
233 | struct snd_ctl_elem_value *value) | |
234 | { | |
235 | struct oxygen *chip = ctl->private_data; | |
236 | int changed; | |
237 | ||
238 | mutex_lock(&chip->mutex); | |
239 | changed = value->value.integer.value[0] != chip->spdif_playback_enable; | |
240 | if (changed) { | |
241 | chip->spdif_playback_enable = !!value->value.integer.value[0]; | |
242 | spin_lock_irq(&chip->reg_lock); | |
243 | oxygen_update_spdif_source(chip); | |
244 | spin_unlock_irq(&chip->reg_lock); | |
245 | } | |
246 | mutex_unlock(&chip->mutex); | |
247 | return changed; | |
248 | } | |
249 | ||
250 | static int spdif_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | |
251 | { | |
252 | info->type = SNDRV_CTL_ELEM_TYPE_IEC958; | |
253 | info->count = 1; | |
254 | return 0; | |
255 | } | |
256 | ||
257 | static void oxygen_to_iec958(u32 bits, struct snd_ctl_elem_value *value) | |
258 | { | |
259 | value->value.iec958.status[0] = | |
260 | bits & (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | | |
261 | OXYGEN_SPDIF_PREEMPHASIS); | |
262 | value->value.iec958.status[1] = /* category and original */ | |
263 | bits >> OXYGEN_SPDIF_CATEGORY_SHIFT; | |
264 | } | |
265 | ||
266 | static u32 iec958_to_oxygen(struct snd_ctl_elem_value *value) | |
267 | { | |
268 | u32 bits; | |
269 | ||
270 | bits = value->value.iec958.status[0] & | |
271 | (OXYGEN_SPDIF_NONAUDIO | OXYGEN_SPDIF_C | | |
272 | OXYGEN_SPDIF_PREEMPHASIS); | |
273 | bits |= value->value.iec958.status[1] << OXYGEN_SPDIF_CATEGORY_SHIFT; | |
274 | if (bits & OXYGEN_SPDIF_NONAUDIO) | |
275 | bits |= OXYGEN_SPDIF_V; | |
276 | return bits; | |
277 | } | |
278 | ||
279 | static inline void write_spdif_bits(struct oxygen *chip, u32 bits) | |
280 | { | |
281 | oxygen_write32_masked(chip, OXYGEN_SPDIF_OUTPUT_BITS, bits, | |
282 | OXYGEN_SPDIF_NONAUDIO | | |
283 | OXYGEN_SPDIF_C | | |
284 | OXYGEN_SPDIF_PREEMPHASIS | | |
285 | OXYGEN_SPDIF_CATEGORY_MASK | | |
286 | OXYGEN_SPDIF_ORIGINAL | | |
287 | OXYGEN_SPDIF_V); | |
288 | } | |
289 | ||
290 | static int spdif_default_get(struct snd_kcontrol *ctl, | |
291 | struct snd_ctl_elem_value *value) | |
292 | { | |
293 | struct oxygen *chip = ctl->private_data; | |
294 | ||
295 | mutex_lock(&chip->mutex); | |
296 | oxygen_to_iec958(chip->spdif_bits, value); | |
297 | mutex_unlock(&chip->mutex); | |
298 | return 0; | |
299 | } | |
300 | ||
301 | static int spdif_default_put(struct snd_kcontrol *ctl, | |
302 | struct snd_ctl_elem_value *value) | |
303 | { | |
304 | struct oxygen *chip = ctl->private_data; | |
305 | u32 new_bits; | |
306 | int changed; | |
307 | ||
308 | new_bits = iec958_to_oxygen(value); | |
309 | mutex_lock(&chip->mutex); | |
310 | changed = new_bits != chip->spdif_bits; | |
311 | if (changed) { | |
312 | chip->spdif_bits = new_bits; | |
313 | if (!(chip->pcm_active & (1 << PCM_SPDIF))) | |
314 | write_spdif_bits(chip, new_bits); | |
315 | } | |
316 | mutex_unlock(&chip->mutex); | |
317 | return changed; | |
318 | } | |
319 | ||
320 | static int spdif_mask_get(struct snd_kcontrol *ctl, | |
321 | struct snd_ctl_elem_value *value) | |
322 | { | |
323 | value->value.iec958.status[0] = IEC958_AES0_NONAUDIO | | |
324 | IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS; | |
325 | value->value.iec958.status[1] = | |
326 | IEC958_AES1_CON_CATEGORY | IEC958_AES1_CON_ORIGINAL; | |
327 | return 0; | |
328 | } | |
329 | ||
330 | static int spdif_pcm_get(struct snd_kcontrol *ctl, | |
331 | struct snd_ctl_elem_value *value) | |
332 | { | |
333 | struct oxygen *chip = ctl->private_data; | |
334 | ||
335 | mutex_lock(&chip->mutex); | |
336 | oxygen_to_iec958(chip->spdif_pcm_bits, value); | |
337 | mutex_unlock(&chip->mutex); | |
338 | return 0; | |
339 | } | |
340 | ||
341 | static int spdif_pcm_put(struct snd_kcontrol *ctl, | |
342 | struct snd_ctl_elem_value *value) | |
343 | { | |
344 | struct oxygen *chip = ctl->private_data; | |
345 | u32 new_bits; | |
346 | int changed; | |
347 | ||
348 | new_bits = iec958_to_oxygen(value); | |
349 | mutex_lock(&chip->mutex); | |
350 | changed = new_bits != chip->spdif_pcm_bits; | |
351 | if (changed) { | |
352 | chip->spdif_pcm_bits = new_bits; | |
353 | if (chip->pcm_active & (1 << PCM_SPDIF)) | |
354 | write_spdif_bits(chip, new_bits); | |
355 | } | |
356 | mutex_unlock(&chip->mutex); | |
357 | return changed; | |
358 | } | |
359 | ||
360 | static int spdif_input_mask_get(struct snd_kcontrol *ctl, | |
361 | struct snd_ctl_elem_value *value) | |
362 | { | |
363 | value->value.iec958.status[0] = 0xff; | |
364 | value->value.iec958.status[1] = 0xff; | |
365 | value->value.iec958.status[2] = 0xff; | |
366 | value->value.iec958.status[3] = 0xff; | |
367 | return 0; | |
368 | } | |
369 | ||
370 | static int spdif_input_default_get(struct snd_kcontrol *ctl, | |
371 | struct snd_ctl_elem_value *value) | |
372 | { | |
373 | struct oxygen *chip = ctl->private_data; | |
374 | u32 bits; | |
375 | ||
376 | bits = oxygen_read32(chip, OXYGEN_SPDIF_INPUT_BITS); | |
377 | value->value.iec958.status[0] = bits; | |
378 | value->value.iec958.status[1] = bits >> 8; | |
379 | value->value.iec958.status[2] = bits >> 16; | |
380 | value->value.iec958.status[3] = bits >> 24; | |
381 | return 0; | |
382 | } | |
383 | ||
384 | static int ac97_switch_get(struct snd_kcontrol *ctl, | |
385 | struct snd_ctl_elem_value *value) | |
386 | { | |
387 | struct oxygen *chip = ctl->private_data; | |
388 | unsigned int index = ctl->private_value & 0xff; | |
389 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; | |
390 | int invert = ctl->private_value & (1 << 16); | |
391 | u16 reg; | |
392 | ||
393 | mutex_lock(&chip->mutex); | |
394 | reg = oxygen_read_ac97(chip, 0, index); | |
395 | mutex_unlock(&chip->mutex); | |
396 | if (!(reg & (1 << bitnr)) ^ !invert) | |
397 | value->value.integer.value[0] = 1; | |
398 | else | |
399 | value->value.integer.value[0] = 0; | |
400 | return 0; | |
401 | } | |
402 | ||
893e44ba CL |
403 | static void ac97_mute_ctl(struct oxygen *chip, unsigned int control) |
404 | { | |
405 | unsigned int index = chip->controls[control]->private_value & 0xff; | |
406 | u16 value; | |
407 | ||
408 | value = oxygen_read_ac97(chip, 0, index); | |
409 | if (!(value & 0x8000)) { | |
410 | oxygen_write_ac97(chip, 0, index, value | 0x8000); | |
411 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
412 | &chip->controls[control]->id); | |
413 | } | |
414 | } | |
415 | ||
d0ce9946 CL |
416 | static int ac97_switch_put(struct snd_kcontrol *ctl, |
417 | struct snd_ctl_elem_value *value) | |
418 | { | |
419 | struct oxygen *chip = ctl->private_data; | |
420 | unsigned int index = ctl->private_value & 0xff; | |
421 | unsigned int bitnr = (ctl->private_value >> 8) & 0xff; | |
422 | int invert = ctl->private_value & (1 << 16); | |
423 | u16 oldreg, newreg; | |
424 | int change; | |
425 | ||
426 | mutex_lock(&chip->mutex); | |
427 | oldreg = oxygen_read_ac97(chip, 0, index); | |
428 | newreg = oldreg; | |
429 | if (!value->value.integer.value[0] ^ !invert) | |
430 | newreg |= 1 << bitnr; | |
431 | else | |
432 | newreg &= ~(1 << bitnr); | |
433 | change = newreg != oldreg; | |
434 | if (change) { | |
435 | oxygen_write_ac97(chip, 0, index, newreg); | |
893e44ba | 436 | if (index == AC97_LINE) { |
d0ce9946 CL |
437 | oxygen_write_ac97_masked(chip, 0, 0x72, |
438 | !!(newreg & 0x8000), 0x0001); | |
893e44ba CL |
439 | if (!(newreg & 0x8000)) { |
440 | ac97_mute_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH); | |
441 | ac97_mute_ctl(chip, CONTROL_CD_CAPTURE_SWITCH); | |
442 | ac97_mute_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH); | |
443 | } | |
444 | } else if ((index == AC97_MIC || index == AC97_CD || | |
445 | index == AC97_VIDEO || index == AC97_AUX) && | |
446 | bitnr == 15 && !(newreg & 0x8000)) { | |
447 | ac97_mute_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH); | |
448 | oxygen_write_ac97_masked(chip, 0, 0x72, 0x0001, 0x0001); | |
449 | } | |
d0ce9946 CL |
450 | } |
451 | mutex_unlock(&chip->mutex); | |
452 | return change; | |
453 | } | |
454 | ||
455 | static int ac97_volume_info(struct snd_kcontrol *ctl, | |
456 | struct snd_ctl_elem_info *info) | |
457 | { | |
458 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
459 | info->count = 2; | |
460 | info->value.integer.min = 0; | |
461 | info->value.integer.max = 0x1f; | |
462 | return 0; | |
463 | } | |
464 | ||
465 | static int ac97_volume_get(struct snd_kcontrol *ctl, | |
466 | struct snd_ctl_elem_value *value) | |
467 | { | |
468 | struct oxygen *chip = ctl->private_data; | |
469 | unsigned int index = ctl->private_value; | |
470 | u16 reg; | |
471 | ||
472 | mutex_lock(&chip->mutex); | |
473 | reg = oxygen_read_ac97(chip, 0, index); | |
474 | mutex_unlock(&chip->mutex); | |
475 | value->value.integer.value[0] = 31 - (reg & 0x1f); | |
476 | value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); | |
477 | return 0; | |
478 | } | |
479 | ||
480 | static int ac97_volume_put(struct snd_kcontrol *ctl, | |
481 | struct snd_ctl_elem_value *value) | |
482 | { | |
483 | struct oxygen *chip = ctl->private_data; | |
484 | unsigned int index = ctl->private_value; | |
485 | u16 oldreg, newreg; | |
486 | int change; | |
487 | ||
488 | mutex_lock(&chip->mutex); | |
489 | oldreg = oxygen_read_ac97(chip, 0, index); | |
490 | newreg = oldreg; | |
491 | newreg = (newreg & ~0x1f) | | |
492 | (31 - (value->value.integer.value[0] & 0x1f)); | |
493 | newreg = (newreg & ~0x1f00) | | |
494 | ((31 - (value->value.integer.value[0] & 0x1f)) << 8); | |
495 | change = newreg != oldreg; | |
496 | if (change) | |
497 | oxygen_write_ac97(chip, 0, index, newreg); | |
498 | mutex_unlock(&chip->mutex); | |
499 | return change; | |
500 | } | |
501 | ||
502 | #define AC97_SWITCH(xname, index, bitnr, invert) { \ | |
503 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
504 | .name = xname, \ | |
505 | .info = snd_ctl_boolean_mono_info, \ | |
506 | .get = ac97_switch_get, \ | |
507 | .put = ac97_switch_put, \ | |
508 | .private_value = ((invert) << 16) | ((bitnr) << 8) | (index), \ | |
509 | } | |
510 | #define AC97_VOLUME(xname, index) { \ | |
511 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
512 | .name = xname, \ | |
513 | .info = ac97_volume_info, \ | |
514 | .get = ac97_volume_get, \ | |
515 | .put = ac97_volume_put, \ | |
516 | .tlv = { .p = ac97_db_scale, }, \ | |
517 | .private_value = (index), \ | |
518 | } | |
519 | ||
520 | static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); | |
521 | ||
522 | static const struct snd_kcontrol_new controls[] = { | |
523 | { | |
524 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
fb920b7d | 525 | .name = "Master Playback Volume", |
ccc80fb4 | 526 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
d0ce9946 CL |
527 | .info = dac_volume_info, |
528 | .get = dac_volume_get, | |
529 | .put = dac_volume_put, | |
d0ce9946 CL |
530 | }, |
531 | { | |
532 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
fb920b7d | 533 | .name = "Master Playback Switch", |
d0ce9946 CL |
534 | .info = snd_ctl_boolean_mono_info, |
535 | .get = dac_mute_get, | |
536 | .put = dac_mute_put, | |
537 | }, | |
538 | { | |
539 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
540 | .name = "Stereo Upmixing", | |
541 | .info = upmix_info, | |
542 | .get = upmix_get, | |
543 | .put = upmix_put, | |
544 | }, | |
545 | { | |
546 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
547 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), | |
548 | .info = snd_ctl_boolean_mono_info, | |
549 | .get = spdif_switch_get, | |
550 | .put = spdif_switch_put, | |
551 | }, | |
552 | { | |
553 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
554 | .device = 1, | |
555 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), | |
556 | .info = spdif_info, | |
557 | .get = spdif_default_get, | |
558 | .put = spdif_default_put, | |
559 | }, | |
560 | { | |
561 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
562 | .device = 1, | |
563 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), | |
564 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
565 | .info = spdif_info, | |
566 | .get = spdif_mask_get, | |
567 | }, | |
568 | { | |
569 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
570 | .device = 1, | |
571 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), | |
572 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | |
573 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, | |
574 | .info = spdif_info, | |
575 | .get = spdif_pcm_get, | |
576 | .put = spdif_pcm_put, | |
577 | }, | |
578 | { | |
579 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
580 | .device = 1, | |
581 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK), | |
582 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
583 | .info = spdif_info, | |
584 | .get = spdif_input_mask_get, | |
585 | }, | |
586 | { | |
587 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, | |
588 | .device = 1, | |
589 | .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), | |
590 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
591 | .info = spdif_info, | |
592 | .get = spdif_input_default_get, | |
593 | }, | |
31c77643 CL |
594 | }; |
595 | ||
596 | static const struct snd_kcontrol_new ac97_controls[] = { | |
d0ce9946 CL |
597 | AC97_VOLUME("Mic Capture Volume", AC97_MIC), |
598 | AC97_SWITCH("Mic Capture Switch", AC97_MIC, 15, 1), | |
599 | AC97_SWITCH("Mic Boost (+20dB)", AC97_MIC, 6, 0), | |
600 | AC97_SWITCH("Line Capture Switch", AC97_LINE, 15, 1), | |
601 | AC97_VOLUME("CD Capture Volume", AC97_CD), | |
602 | AC97_SWITCH("CD Capture Switch", AC97_CD, 15, 1), | |
603 | AC97_VOLUME("Aux Capture Volume", AC97_AUX), | |
604 | AC97_SWITCH("Aux Capture Switch", AC97_AUX, 15, 1), | |
605 | }; | |
606 | ||
607 | static void oxygen_any_ctl_free(struct snd_kcontrol *ctl) | |
608 | { | |
609 | struct oxygen *chip = ctl->private_data; | |
01a3affb | 610 | unsigned int i; |
d0ce9946 CL |
611 | |
612 | /* I'm too lazy to write a function for each control :-) */ | |
01a3affb CL |
613 | for (i = 0; i < ARRAY_SIZE(chip->controls); ++i) |
614 | chip->controls[i] = NULL; | |
d0ce9946 CL |
615 | } |
616 | ||
31c77643 CL |
617 | static int add_controls(struct oxygen *chip, |
618 | const struct snd_kcontrol_new controls[], | |
619 | unsigned int count) | |
d0ce9946 | 620 | { |
01a3affb CL |
621 | static const char *const known_ctl_names[CONTROL_COUNT] = { |
622 | [CONTROL_SPDIF_PCM] = | |
623 | SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), | |
624 | [CONTROL_SPDIF_INPUT_BITS] = | |
625 | SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), | |
893e44ba CL |
626 | [CONTROL_MIC_CAPTURE_SWITCH] = "Mic Capture Switch", |
627 | [CONTROL_LINE_CAPTURE_SWITCH] = "Line Capture Switch", | |
628 | [CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch", | |
629 | [CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch", | |
01a3affb CL |
630 | }; |
631 | unsigned int i, j; | |
ccc80fb4 | 632 | struct snd_kcontrol_new template; |
d0ce9946 CL |
633 | struct snd_kcontrol *ctl; |
634 | int err; | |
635 | ||
31c77643 | 636 | for (i = 0; i < count; ++i) { |
ccc80fb4 CL |
637 | template = controls[i]; |
638 | err = chip->model->control_filter(&template); | |
639 | if (err < 0) | |
640 | return err; | |
d0ce9946 CL |
641 | ctl = snd_ctl_new1(&controls[i], chip); |
642 | if (!ctl) | |
643 | return -ENOMEM; | |
d0ce9946 CL |
644 | err = snd_ctl_add(chip->card, ctl); |
645 | if (err < 0) | |
646 | return err; | |
01a3affb CL |
647 | for (j = 0; j < CONTROL_COUNT; ++j) |
648 | if (!strcmp(ctl->id.name, known_ctl_names[j])) { | |
649 | chip->controls[j] = ctl; | |
650 | ctl->private_free = oxygen_any_ctl_free; | |
651 | } | |
d0ce9946 | 652 | } |
31c77643 CL |
653 | return 0; |
654 | } | |
655 | ||
656 | int oxygen_mixer_init(struct oxygen *chip) | |
657 | { | |
658 | int err; | |
659 | ||
660 | err = add_controls(chip, controls, ARRAY_SIZE(controls)); | |
661 | if (err < 0) | |
662 | return err; | |
663 | if (chip->has_ac97_0) { | |
664 | err = add_controls(chip, ac97_controls, | |
665 | ARRAY_SIZE(ac97_controls)); | |
666 | if (err < 0) | |
667 | return err; | |
668 | } | |
d0ce9946 CL |
669 | return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0; |
670 | } |