2 * C-Media CMI8788 driver - mixer code
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
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.
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.
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
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>
28 static int dac_volume_info(struct snd_kcontrol
*ctl
,
29 struct snd_ctl_elem_info
*info
)
31 struct oxygen
*chip
= ctl
->private_data
;
33 info
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
34 info
->count
= chip
->model
.dac_channels
;
35 info
->value
.integer
.min
= chip
->model
.dac_volume_min
;
36 info
->value
.integer
.max
= chip
->model
.dac_volume_max
;
40 static int dac_volume_get(struct snd_kcontrol
*ctl
,
41 struct snd_ctl_elem_value
*value
)
43 struct oxygen
*chip
= ctl
->private_data
;
46 mutex_lock(&chip
->mutex
);
47 for (i
= 0; i
< chip
->model
.dac_channels
; ++i
)
48 value
->value
.integer
.value
[i
] = chip
->dac_volume
[i
];
49 mutex_unlock(&chip
->mutex
);
53 static int dac_volume_put(struct snd_kcontrol
*ctl
,
54 struct snd_ctl_elem_value
*value
)
56 struct oxygen
*chip
= ctl
->private_data
;
61 mutex_lock(&chip
->mutex
);
62 for (i
= 0; i
< chip
->model
.dac_channels
; ++i
)
63 if (value
->value
.integer
.value
[i
] != chip
->dac_volume
[i
]) {
64 chip
->dac_volume
[i
] = value
->value
.integer
.value
[i
];
68 chip
->model
.update_dac_volume(chip
);
69 mutex_unlock(&chip
->mutex
);
73 static int dac_mute_get(struct snd_kcontrol
*ctl
,
74 struct snd_ctl_elem_value
*value
)
76 struct oxygen
*chip
= ctl
->private_data
;
78 mutex_lock(&chip
->mutex
);
79 value
->value
.integer
.value
[0] = !chip
->dac_mute
;
80 mutex_unlock(&chip
->mutex
);
84 static int dac_mute_put(struct snd_kcontrol
*ctl
,
85 struct snd_ctl_elem_value
*value
)
87 struct oxygen
*chip
= ctl
->private_data
;
90 mutex_lock(&chip
->mutex
);
91 changed
= !value
->value
.integer
.value
[0] != chip
->dac_mute
;
93 chip
->dac_mute
= !value
->value
.integer
.value
[0];
94 chip
->model
.update_dac_mute(chip
);
96 mutex_unlock(&chip
->mutex
);
100 static int upmix_info(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_info
*info
)
102 static const char *const names
[5] = {
105 "Front+Surround+Back",
106 "Front+Surround+Center/LFE",
107 "Front+Surround+Center/LFE+Back",
109 struct oxygen
*chip
= ctl
->private_data
;
110 unsigned int count
= chip
->model
.update_center_lfe_mix
? 5 : 3;
112 info
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
114 info
->value
.enumerated
.items
= count
;
115 if (info
->value
.enumerated
.item
>= count
)
116 info
->value
.enumerated
.item
= count
- 1;
117 strcpy(info
->value
.enumerated
.name
, names
[info
->value
.enumerated
.item
]);
121 static int upmix_get(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_value
*value
)
123 struct oxygen
*chip
= ctl
->private_data
;
125 mutex_lock(&chip
->mutex
);
126 value
->value
.enumerated
.item
[0] = chip
->dac_routing
;
127 mutex_unlock(&chip
->mutex
);
131 void oxygen_update_dac_routing(struct oxygen
*chip
)
133 /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */
134 static const unsigned int reg_values
[5] = {
135 /* stereo -> front */
136 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
137 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
138 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
139 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
),
140 /* stereo -> front+surround */
141 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
142 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
143 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
144 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
),
145 /* stereo -> front+surround+back */
146 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
147 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
148 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
149 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
),
150 /* stereo -> front+surround+center/LFE */
151 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
152 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
153 (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
154 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
),
155 /* stereo -> front+surround+center/LFE+back */
156 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
157 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
158 (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
159 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
),
162 unsigned int reg_value
;
164 channels
= oxygen_read8(chip
, OXYGEN_PLAY_CHANNELS
) &
165 OXYGEN_PLAY_CHANNELS_MASK
;
166 if (channels
== OXYGEN_PLAY_CHANNELS_2
)
167 reg_value
= reg_values
[chip
->dac_routing
];
168 else if (channels
== OXYGEN_PLAY_CHANNELS_8
)
169 /* in 7.1 mode, "rear" channels go to the "back" jack */
170 reg_value
= (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
171 (3 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
172 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
173 (1 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
);
175 reg_value
= (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT
) |
176 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT
) |
177 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT
) |
178 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT
);
179 oxygen_write16_masked(chip
, OXYGEN_PLAY_ROUTING
, reg_value
,
180 OXYGEN_PLAY_DAC0_SOURCE_MASK
|
181 OXYGEN_PLAY_DAC1_SOURCE_MASK
|
182 OXYGEN_PLAY_DAC2_SOURCE_MASK
|
183 OXYGEN_PLAY_DAC3_SOURCE_MASK
);
184 if (chip
->model
.update_center_lfe_mix
)
185 chip
->model
.update_center_lfe_mix(chip
, chip
->dac_routing
> 2);
188 static int upmix_put(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_value
*value
)
190 struct oxygen
*chip
= ctl
->private_data
;
191 unsigned int count
= chip
->model
.update_center_lfe_mix
? 5 : 3;
194 if (value
->value
.enumerated
.item
[0] >= count
)
196 mutex_lock(&chip
->mutex
);
197 changed
= value
->value
.enumerated
.item
[0] != chip
->dac_routing
;
199 chip
->dac_routing
= value
->value
.enumerated
.item
[0];
200 oxygen_update_dac_routing(chip
);
202 mutex_unlock(&chip
->mutex
);
206 static int spdif_switch_get(struct snd_kcontrol
*ctl
,
207 struct snd_ctl_elem_value
*value
)
209 struct oxygen
*chip
= ctl
->private_data
;
211 mutex_lock(&chip
->mutex
);
212 value
->value
.integer
.value
[0] = chip
->spdif_playback_enable
;
213 mutex_unlock(&chip
->mutex
);
217 static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate
)
219 switch (oxygen_rate
) {
220 case OXYGEN_RATE_32000
:
221 return IEC958_AES3_CON_FS_32000
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
222 case OXYGEN_RATE_44100
:
223 return IEC958_AES3_CON_FS_44100
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
224 default: /* OXYGEN_RATE_48000 */
225 return IEC958_AES3_CON_FS_48000
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
226 case OXYGEN_RATE_64000
:
227 return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT
;
228 case OXYGEN_RATE_88200
:
229 return IEC958_AES3_CON_FS_88200
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
230 case OXYGEN_RATE_96000
:
231 return IEC958_AES3_CON_FS_96000
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
232 case OXYGEN_RATE_176400
:
233 return IEC958_AES3_CON_FS_176400
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
234 case OXYGEN_RATE_192000
:
235 return IEC958_AES3_CON_FS_192000
<< OXYGEN_SPDIF_CS_RATE_SHIFT
;
239 void oxygen_update_spdif_source(struct oxygen
*chip
)
241 u32 old_control
, new_control
;
242 u16 old_routing
, new_routing
;
243 unsigned int oxygen_rate
;
245 old_control
= oxygen_read32(chip
, OXYGEN_SPDIF_CONTROL
);
246 old_routing
= oxygen_read16(chip
, OXYGEN_PLAY_ROUTING
);
247 if (chip
->pcm_active
& (1 << PCM_SPDIF
)) {
248 new_control
= old_control
| OXYGEN_SPDIF_OUT_ENABLE
;
249 new_routing
= (old_routing
& ~OXYGEN_PLAY_SPDIF_MASK
)
250 | OXYGEN_PLAY_SPDIF_SPDIF
;
251 oxygen_rate
= (old_control
>> OXYGEN_SPDIF_OUT_RATE_SHIFT
)
252 & OXYGEN_I2S_RATE_MASK
;
253 /* S/PDIF rate was already set by the caller */
254 } else if ((chip
->pcm_active
& (1 << PCM_MULTICH
)) &&
255 chip
->spdif_playback_enable
) {
256 new_routing
= (old_routing
& ~OXYGEN_PLAY_SPDIF_MASK
)
257 | OXYGEN_PLAY_SPDIF_MULTICH_01
;
258 oxygen_rate
= oxygen_read16(chip
, OXYGEN_I2S_MULTICH_FORMAT
)
259 & OXYGEN_I2S_RATE_MASK
;
260 new_control
= (old_control
& ~OXYGEN_SPDIF_OUT_RATE_MASK
) |
261 (oxygen_rate
<< OXYGEN_SPDIF_OUT_RATE_SHIFT
) |
262 OXYGEN_SPDIF_OUT_ENABLE
;
264 new_control
= old_control
& ~OXYGEN_SPDIF_OUT_ENABLE
;
265 new_routing
= old_routing
;
266 oxygen_rate
= OXYGEN_RATE_44100
;
268 if (old_routing
!= new_routing
) {
269 oxygen_write32(chip
, OXYGEN_SPDIF_CONTROL
,
270 new_control
& ~OXYGEN_SPDIF_OUT_ENABLE
);
271 oxygen_write16(chip
, OXYGEN_PLAY_ROUTING
, new_routing
);
273 if (new_control
& OXYGEN_SPDIF_OUT_ENABLE
)
274 oxygen_write32(chip
, OXYGEN_SPDIF_OUTPUT_BITS
,
275 oxygen_spdif_rate(oxygen_rate
) |
276 ((chip
->pcm_active
& (1 << PCM_SPDIF
)) ?
277 chip
->spdif_pcm_bits
: chip
->spdif_bits
));
278 oxygen_write32(chip
, OXYGEN_SPDIF_CONTROL
, new_control
);
281 static int spdif_switch_put(struct snd_kcontrol
*ctl
,
282 struct snd_ctl_elem_value
*value
)
284 struct oxygen
*chip
= ctl
->private_data
;
287 mutex_lock(&chip
->mutex
);
288 changed
= value
->value
.integer
.value
[0] != chip
->spdif_playback_enable
;
290 chip
->spdif_playback_enable
= !!value
->value
.integer
.value
[0];
291 spin_lock_irq(&chip
->reg_lock
);
292 oxygen_update_spdif_source(chip
);
293 spin_unlock_irq(&chip
->reg_lock
);
295 mutex_unlock(&chip
->mutex
);
299 static int spdif_info(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_info
*info
)
301 info
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
306 static void oxygen_to_iec958(u32 bits
, struct snd_ctl_elem_value
*value
)
308 value
->value
.iec958
.status
[0] =
309 bits
& (OXYGEN_SPDIF_NONAUDIO
| OXYGEN_SPDIF_C
|
310 OXYGEN_SPDIF_PREEMPHASIS
);
311 value
->value
.iec958
.status
[1] = /* category and original */
312 bits
>> OXYGEN_SPDIF_CATEGORY_SHIFT
;
315 static u32
iec958_to_oxygen(struct snd_ctl_elem_value
*value
)
319 bits
= value
->value
.iec958
.status
[0] &
320 (OXYGEN_SPDIF_NONAUDIO
| OXYGEN_SPDIF_C
|
321 OXYGEN_SPDIF_PREEMPHASIS
);
322 bits
|= value
->value
.iec958
.status
[1] << OXYGEN_SPDIF_CATEGORY_SHIFT
;
323 if (bits
& OXYGEN_SPDIF_NONAUDIO
)
324 bits
|= OXYGEN_SPDIF_V
;
328 static inline void write_spdif_bits(struct oxygen
*chip
, u32 bits
)
330 oxygen_write32_masked(chip
, OXYGEN_SPDIF_OUTPUT_BITS
, bits
,
331 OXYGEN_SPDIF_NONAUDIO
|
333 OXYGEN_SPDIF_PREEMPHASIS
|
334 OXYGEN_SPDIF_CATEGORY_MASK
|
335 OXYGEN_SPDIF_ORIGINAL
|
339 static int spdif_default_get(struct snd_kcontrol
*ctl
,
340 struct snd_ctl_elem_value
*value
)
342 struct oxygen
*chip
= ctl
->private_data
;
344 mutex_lock(&chip
->mutex
);
345 oxygen_to_iec958(chip
->spdif_bits
, value
);
346 mutex_unlock(&chip
->mutex
);
350 static int spdif_default_put(struct snd_kcontrol
*ctl
,
351 struct snd_ctl_elem_value
*value
)
353 struct oxygen
*chip
= ctl
->private_data
;
357 new_bits
= iec958_to_oxygen(value
);
358 mutex_lock(&chip
->mutex
);
359 changed
= new_bits
!= chip
->spdif_bits
;
361 chip
->spdif_bits
= new_bits
;
362 if (!(chip
->pcm_active
& (1 << PCM_SPDIF
)))
363 write_spdif_bits(chip
, new_bits
);
365 mutex_unlock(&chip
->mutex
);
369 static int spdif_mask_get(struct snd_kcontrol
*ctl
,
370 struct snd_ctl_elem_value
*value
)
372 value
->value
.iec958
.status
[0] = IEC958_AES0_NONAUDIO
|
373 IEC958_AES0_CON_NOT_COPYRIGHT
| IEC958_AES0_CON_EMPHASIS
;
374 value
->value
.iec958
.status
[1] =
375 IEC958_AES1_CON_CATEGORY
| IEC958_AES1_CON_ORIGINAL
;
379 static int spdif_pcm_get(struct snd_kcontrol
*ctl
,
380 struct snd_ctl_elem_value
*value
)
382 struct oxygen
*chip
= ctl
->private_data
;
384 mutex_lock(&chip
->mutex
);
385 oxygen_to_iec958(chip
->spdif_pcm_bits
, value
);
386 mutex_unlock(&chip
->mutex
);
390 static int spdif_pcm_put(struct snd_kcontrol
*ctl
,
391 struct snd_ctl_elem_value
*value
)
393 struct oxygen
*chip
= ctl
->private_data
;
397 new_bits
= iec958_to_oxygen(value
);
398 mutex_lock(&chip
->mutex
);
399 changed
= new_bits
!= chip
->spdif_pcm_bits
;
401 chip
->spdif_pcm_bits
= new_bits
;
402 if (chip
->pcm_active
& (1 << PCM_SPDIF
))
403 write_spdif_bits(chip
, new_bits
);
405 mutex_unlock(&chip
->mutex
);
409 static int spdif_input_mask_get(struct snd_kcontrol
*ctl
,
410 struct snd_ctl_elem_value
*value
)
412 value
->value
.iec958
.status
[0] = 0xff;
413 value
->value
.iec958
.status
[1] = 0xff;
414 value
->value
.iec958
.status
[2] = 0xff;
415 value
->value
.iec958
.status
[3] = 0xff;
419 static int spdif_input_default_get(struct snd_kcontrol
*ctl
,
420 struct snd_ctl_elem_value
*value
)
422 struct oxygen
*chip
= ctl
->private_data
;
425 bits
= oxygen_read32(chip
, OXYGEN_SPDIF_INPUT_BITS
);
426 value
->value
.iec958
.status
[0] = bits
;
427 value
->value
.iec958
.status
[1] = bits
>> 8;
428 value
->value
.iec958
.status
[2] = bits
>> 16;
429 value
->value
.iec958
.status
[3] = bits
>> 24;
433 static int spdif_loopback_get(struct snd_kcontrol
*ctl
,
434 struct snd_ctl_elem_value
*value
)
436 struct oxygen
*chip
= ctl
->private_data
;
438 value
->value
.integer
.value
[0] =
439 !!(oxygen_read32(chip
, OXYGEN_SPDIF_CONTROL
)
440 & OXYGEN_SPDIF_LOOPBACK
);
444 static int spdif_loopback_put(struct snd_kcontrol
*ctl
,
445 struct snd_ctl_elem_value
*value
)
447 struct oxygen
*chip
= ctl
->private_data
;
451 spin_lock_irq(&chip
->reg_lock
);
452 oldreg
= oxygen_read32(chip
, OXYGEN_SPDIF_CONTROL
);
453 if (value
->value
.integer
.value
[0])
454 newreg
= oldreg
| OXYGEN_SPDIF_LOOPBACK
;
456 newreg
= oldreg
& ~OXYGEN_SPDIF_LOOPBACK
;
457 changed
= newreg
!= oldreg
;
459 oxygen_write32(chip
, OXYGEN_SPDIF_CONTROL
, newreg
);
460 spin_unlock_irq(&chip
->reg_lock
);
464 static int monitor_volume_info(struct snd_kcontrol
*ctl
,
465 struct snd_ctl_elem_info
*info
)
467 info
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
469 info
->value
.integer
.min
= 0;
470 info
->value
.integer
.max
= 1;
474 static int monitor_get(struct snd_kcontrol
*ctl
,
475 struct snd_ctl_elem_value
*value
)
477 struct oxygen
*chip
= ctl
->private_data
;
478 u8 bit
= ctl
->private_value
;
479 int invert
= ctl
->private_value
& (1 << 8);
481 value
->value
.integer
.value
[0] =
482 !!invert
^ !!(oxygen_read8(chip
, OXYGEN_ADC_MONITOR
) & bit
);
486 static int monitor_put(struct snd_kcontrol
*ctl
,
487 struct snd_ctl_elem_value
*value
)
489 struct oxygen
*chip
= ctl
->private_data
;
490 u8 bit
= ctl
->private_value
;
491 int invert
= ctl
->private_value
& (1 << 8);
495 spin_lock_irq(&chip
->reg_lock
);
496 oldreg
= oxygen_read8(chip
, OXYGEN_ADC_MONITOR
);
497 if ((!!value
->value
.integer
.value
[0] ^ !!invert
) != 0)
498 newreg
= oldreg
| bit
;
500 newreg
= oldreg
& ~bit
;
501 changed
= newreg
!= oldreg
;
503 oxygen_write8(chip
, OXYGEN_ADC_MONITOR
, newreg
);
504 spin_unlock_irq(&chip
->reg_lock
);
508 static int ac97_switch_get(struct snd_kcontrol
*ctl
,
509 struct snd_ctl_elem_value
*value
)
511 struct oxygen
*chip
= ctl
->private_data
;
512 unsigned int codec
= (ctl
->private_value
>> 24) & 1;
513 unsigned int index
= ctl
->private_value
& 0xff;
514 unsigned int bitnr
= (ctl
->private_value
>> 8) & 0xff;
515 int invert
= ctl
->private_value
& (1 << 16);
518 mutex_lock(&chip
->mutex
);
519 reg
= oxygen_read_ac97(chip
, codec
, index
);
520 mutex_unlock(&chip
->mutex
);
521 if (!(reg
& (1 << bitnr
)) ^ !invert
)
522 value
->value
.integer
.value
[0] = 1;
524 value
->value
.integer
.value
[0] = 0;
528 static void mute_ac97_ctl(struct oxygen
*chip
, unsigned int control
)
530 unsigned int priv_idx
;
533 if (!chip
->controls
[control
])
535 priv_idx
= chip
->controls
[control
]->private_value
& 0xff;
536 value
= oxygen_read_ac97(chip
, 0, priv_idx
);
537 if (!(value
& 0x8000)) {
538 oxygen_write_ac97(chip
, 0, priv_idx
, value
| 0x8000);
539 if (chip
->model
.ac97_switch
)
540 chip
->model
.ac97_switch(chip
, priv_idx
, 0x8000);
541 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
542 &chip
->controls
[control
]->id
);
546 static int ac97_switch_put(struct snd_kcontrol
*ctl
,
547 struct snd_ctl_elem_value
*value
)
549 struct oxygen
*chip
= ctl
->private_data
;
550 unsigned int codec
= (ctl
->private_value
>> 24) & 1;
551 unsigned int index
= ctl
->private_value
& 0xff;
552 unsigned int bitnr
= (ctl
->private_value
>> 8) & 0xff;
553 int invert
= ctl
->private_value
& (1 << 16);
557 mutex_lock(&chip
->mutex
);
558 oldreg
= oxygen_read_ac97(chip
, codec
, index
);
560 if (!value
->value
.integer
.value
[0] ^ !invert
)
561 newreg
|= 1 << bitnr
;
563 newreg
&= ~(1 << bitnr
);
564 change
= newreg
!= oldreg
;
566 oxygen_write_ac97(chip
, codec
, index
, newreg
);
567 if (codec
== 0 && chip
->model
.ac97_switch
)
568 chip
->model
.ac97_switch(chip
, index
, newreg
& 0x8000);
569 if (index
== AC97_LINE
) {
570 oxygen_write_ac97_masked(chip
, 0, CM9780_GPIO_STATUS
,
572 CM9780_GPO0
: 0, CM9780_GPO0
);
573 if (!(newreg
& 0x8000)) {
574 mute_ac97_ctl(chip
, CONTROL_MIC_CAPTURE_SWITCH
);
575 mute_ac97_ctl(chip
, CONTROL_CD_CAPTURE_SWITCH
);
576 mute_ac97_ctl(chip
, CONTROL_AUX_CAPTURE_SWITCH
);
578 } else if ((index
== AC97_MIC
|| index
== AC97_CD
||
579 index
== AC97_VIDEO
|| index
== AC97_AUX
) &&
580 bitnr
== 15 && !(newreg
& 0x8000)) {
581 mute_ac97_ctl(chip
, CONTROL_LINE_CAPTURE_SWITCH
);
582 oxygen_write_ac97_masked(chip
, 0, CM9780_GPIO_STATUS
,
583 CM9780_GPO0
, CM9780_GPO0
);
586 mutex_unlock(&chip
->mutex
);
590 static int ac97_volume_info(struct snd_kcontrol
*ctl
,
591 struct snd_ctl_elem_info
*info
)
593 int stereo
= (ctl
->private_value
>> 16) & 1;
595 info
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
596 info
->count
= stereo
? 2 : 1;
597 info
->value
.integer
.min
= 0;
598 info
->value
.integer
.max
= 0x1f;
602 static int ac97_volume_get(struct snd_kcontrol
*ctl
,
603 struct snd_ctl_elem_value
*value
)
605 struct oxygen
*chip
= ctl
->private_data
;
606 unsigned int codec
= (ctl
->private_value
>> 24) & 1;
607 int stereo
= (ctl
->private_value
>> 16) & 1;
608 unsigned int index
= ctl
->private_value
& 0xff;
611 mutex_lock(&chip
->mutex
);
612 reg
= oxygen_read_ac97(chip
, codec
, index
);
613 mutex_unlock(&chip
->mutex
);
614 value
->value
.integer
.value
[0] = 31 - (reg
& 0x1f);
616 value
->value
.integer
.value
[1] = 31 - ((reg
>> 8) & 0x1f);
620 static int ac97_volume_put(struct snd_kcontrol
*ctl
,
621 struct snd_ctl_elem_value
*value
)
623 struct oxygen
*chip
= ctl
->private_data
;
624 unsigned int codec
= (ctl
->private_value
>> 24) & 1;
625 int stereo
= (ctl
->private_value
>> 16) & 1;
626 unsigned int index
= ctl
->private_value
& 0xff;
630 mutex_lock(&chip
->mutex
);
631 oldreg
= oxygen_read_ac97(chip
, codec
, index
);
633 newreg
= (newreg
& ~0x1f) |
634 (31 - (value
->value
.integer
.value
[0] & 0x1f));
636 newreg
= (newreg
& ~0x1f00) |
637 ((31 - (value
->value
.integer
.value
[1] & 0x1f)) << 8);
639 newreg
= (newreg
& ~0x1f00) | ((newreg
& 0x1f) << 8);
640 change
= newreg
!= oldreg
;
642 oxygen_write_ac97(chip
, codec
, index
, newreg
);
643 mutex_unlock(&chip
->mutex
);
647 static int ac97_fp_rec_volume_info(struct snd_kcontrol
*ctl
,
648 struct snd_ctl_elem_info
*info
)
650 info
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
652 info
->value
.integer
.min
= 0;
653 info
->value
.integer
.max
= 7;
657 static int ac97_fp_rec_volume_get(struct snd_kcontrol
*ctl
,
658 struct snd_ctl_elem_value
*value
)
660 struct oxygen
*chip
= ctl
->private_data
;
663 mutex_lock(&chip
->mutex
);
664 reg
= oxygen_read_ac97(chip
, 1, AC97_REC_GAIN
);
665 mutex_unlock(&chip
->mutex
);
666 value
->value
.integer
.value
[0] = reg
& 7;
667 value
->value
.integer
.value
[1] = (reg
>> 8) & 7;
671 static int ac97_fp_rec_volume_put(struct snd_kcontrol
*ctl
,
672 struct snd_ctl_elem_value
*value
)
674 struct oxygen
*chip
= ctl
->private_data
;
678 mutex_lock(&chip
->mutex
);
679 oldreg
= oxygen_read_ac97(chip
, 1, AC97_REC_GAIN
);
680 newreg
= oldreg
& ~0x0707;
681 newreg
= newreg
| (value
->value
.integer
.value
[0] & 7);
682 newreg
= newreg
| ((value
->value
.integer
.value
[0] & 7) << 8);
683 change
= newreg
!= oldreg
;
685 oxygen_write_ac97(chip
, 1, AC97_REC_GAIN
, newreg
);
686 mutex_unlock(&chip
->mutex
);
690 #define AC97_SWITCH(xname, codec, index, bitnr, invert) { \
691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
693 .info = snd_ctl_boolean_mono_info, \
694 .get = ac97_switch_get, \
695 .put = ac97_switch_put, \
696 .private_value = ((codec) << 24) | ((invert) << 16) | \
697 ((bitnr) << 8) | (index), \
699 #define AC97_VOLUME(xname, codec, index, stereo) { \
700 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
702 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
703 SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
704 .info = ac97_volume_info, \
705 .get = ac97_volume_get, \
706 .put = ac97_volume_put, \
707 .tlv = { .p = ac97_db_scale, }, \
708 .private_value = ((codec) << 24) | ((stereo) << 16) | (index), \
711 static DECLARE_TLV_DB_SCALE(monitor_db_scale
, -1000, 1000, 0);
712 static DECLARE_TLV_DB_SCALE(ac97_db_scale
, -3450, 150, 0);
713 static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale
, 0, 150, 0);
715 static const struct snd_kcontrol_new controls
[] = {
717 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
718 .name
= "Master Playback Volume",
719 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
720 .info
= dac_volume_info
,
721 .get
= dac_volume_get
,
722 .put
= dac_volume_put
,
725 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
726 .name
= "Master Playback Switch",
727 .info
= snd_ctl_boolean_mono_info
,
732 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
733 .name
= "Stereo Upmixing",
739 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
740 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, SWITCH
),
741 .info
= snd_ctl_boolean_mono_info
,
742 .get
= spdif_switch_get
,
743 .put
= spdif_switch_put
,
746 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
748 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, DEFAULT
),
750 .get
= spdif_default_get
,
751 .put
= spdif_default_put
,
754 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
756 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, CON_MASK
),
757 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
759 .get
= spdif_mask_get
,
762 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
764 .name
= SNDRV_CTL_NAME_IEC958("", PLAYBACK
, PCM_STREAM
),
765 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
766 SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
768 .get
= spdif_pcm_get
,
769 .put
= spdif_pcm_put
,
773 static const struct snd_kcontrol_new spdif_input_controls
[] = {
775 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
777 .name
= SNDRV_CTL_NAME_IEC958("", CAPTURE
, MASK
),
778 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
780 .get
= spdif_input_mask_get
,
783 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
785 .name
= SNDRV_CTL_NAME_IEC958("", CAPTURE
, DEFAULT
),
786 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
788 .get
= spdif_input_default_get
,
791 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
792 .name
= SNDRV_CTL_NAME_IEC958("Loopback ", NONE
, SWITCH
),
793 .info
= snd_ctl_boolean_mono_info
,
794 .get
= spdif_loopback_get
,
795 .put
= spdif_loopback_put
,
799 static const struct {
800 unsigned int pcm_dev
;
801 struct snd_kcontrol_new controls
[2];
802 } monitor_controls
[] = {
804 .pcm_dev
= CAPTURE_0_FROM_I2S_1
,
807 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
808 .name
= "Analog Input Monitor Playback Switch",
809 .info
= snd_ctl_boolean_mono_info
,
812 .private_value
= OXYGEN_ADC_MONITOR_A
,
815 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
816 .name
= "Analog Input Monitor Playback Volume",
817 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
818 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
819 .info
= monitor_volume_info
,
822 .private_value
= OXYGEN_ADC_MONITOR_A_HALF_VOL
824 .tlv
= { .p
= monitor_db_scale
, },
829 .pcm_dev
= CAPTURE_0_FROM_I2S_2
,
832 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
833 .name
= "Analog Input Monitor Playback Switch",
834 .info
= snd_ctl_boolean_mono_info
,
837 .private_value
= OXYGEN_ADC_MONITOR_B
,
840 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
841 .name
= "Analog Input Monitor Playback Volume",
842 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
843 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
844 .info
= monitor_volume_info
,
847 .private_value
= OXYGEN_ADC_MONITOR_B_HALF_VOL
849 .tlv
= { .p
= monitor_db_scale
, },
854 .pcm_dev
= CAPTURE_2_FROM_I2S_2
,
857 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
858 .name
= "Analog Input Monitor Playback Switch",
860 .info
= snd_ctl_boolean_mono_info
,
863 .private_value
= OXYGEN_ADC_MONITOR_B
,
866 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
867 .name
= "Analog Input Monitor Playback Volume",
869 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
870 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
871 .info
= monitor_volume_info
,
874 .private_value
= OXYGEN_ADC_MONITOR_B_HALF_VOL
876 .tlv
= { .p
= monitor_db_scale
, },
881 .pcm_dev
= CAPTURE_1_FROM_SPDIF
,
884 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
885 .name
= "Digital Input Monitor Playback Switch",
886 .info
= snd_ctl_boolean_mono_info
,
889 .private_value
= OXYGEN_ADC_MONITOR_C
,
892 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
893 .name
= "Digital Input Monitor Playback Volume",
894 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
895 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
896 .info
= monitor_volume_info
,
899 .private_value
= OXYGEN_ADC_MONITOR_C_HALF_VOL
901 .tlv
= { .p
= monitor_db_scale
, },
907 static const struct snd_kcontrol_new ac97_controls
[] = {
908 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC
, 0),
909 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC
, 15, 1),
910 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC
, 6, 0),
911 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE
, 15, 1),
912 AC97_VOLUME("CD Capture Volume", 0, AC97_CD
, 1),
913 AC97_SWITCH("CD Capture Switch", 0, AC97_CD
, 15, 1),
914 AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX
, 1),
915 AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX
, 15, 1),
918 static const struct snd_kcontrol_new ac97_fp_controls
[] = {
919 AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE
, 1),
920 AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE
, 15, 1),
922 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
923 .name
= "Front Panel Capture Volume",
924 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
925 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
926 .info
= ac97_fp_rec_volume_info
,
927 .get
= ac97_fp_rec_volume_get
,
928 .put
= ac97_fp_rec_volume_put
,
929 .tlv
= { .p
= ac97_rec_db_scale
, },
931 AC97_SWITCH("Front Panel Capture Switch", 1, AC97_REC_GAIN
, 15, 1),
934 static void oxygen_any_ctl_free(struct snd_kcontrol
*ctl
)
936 struct oxygen
*chip
= ctl
->private_data
;
939 /* I'm too lazy to write a function for each control :-) */
940 for (i
= 0; i
< ARRAY_SIZE(chip
->controls
); ++i
)
941 chip
->controls
[i
] = NULL
;
944 static int add_controls(struct oxygen
*chip
,
945 const struct snd_kcontrol_new controls
[],
948 static const char *const known_ctl_names
[CONTROL_COUNT
] = {
949 [CONTROL_SPDIF_PCM
] =
950 SNDRV_CTL_NAME_IEC958("", PLAYBACK
, PCM_STREAM
),
951 [CONTROL_SPDIF_INPUT_BITS
] =
952 SNDRV_CTL_NAME_IEC958("", CAPTURE
, DEFAULT
),
953 [CONTROL_MIC_CAPTURE_SWITCH
] = "Mic Capture Switch",
954 [CONTROL_LINE_CAPTURE_SWITCH
] = "Line Capture Switch",
955 [CONTROL_CD_CAPTURE_SWITCH
] = "CD Capture Switch",
956 [CONTROL_AUX_CAPTURE_SWITCH
] = "Aux Capture Switch",
959 struct snd_kcontrol_new
template;
960 struct snd_kcontrol
*ctl
;
963 for (i
= 0; i
< count
; ++i
) {
964 template = controls
[i
];
965 if (chip
->model
.control_filter
) {
966 err
= chip
->model
.control_filter(&template);
972 if (!strcmp(template.name
, "Stereo Upmixing") &&
973 chip
->model
.dac_channels
== 2)
975 if (!strcmp(template.name
, "Master Playback Volume") &&
976 chip
->model
.dac_tlv
) {
977 template.tlv
.p
= chip
->model
.dac_tlv
;
978 template.access
|= SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
980 ctl
= snd_ctl_new1(&template, chip
);
983 err
= snd_ctl_add(chip
->card
, ctl
);
986 for (j
= 0; j
< CONTROL_COUNT
; ++j
)
987 if (!strcmp(ctl
->id
.name
, known_ctl_names
[j
])) {
988 chip
->controls
[j
] = ctl
;
989 ctl
->private_free
= oxygen_any_ctl_free
;
995 int oxygen_mixer_init(struct oxygen
*chip
)
1000 err
= add_controls(chip
, controls
, ARRAY_SIZE(controls
));
1003 if (chip
->model
.device_config
& CAPTURE_1_FROM_SPDIF
) {
1004 err
= add_controls(chip
, spdif_input_controls
,
1005 ARRAY_SIZE(spdif_input_controls
));
1009 for (i
= 0; i
< ARRAY_SIZE(monitor_controls
); ++i
) {
1010 if (!(chip
->model
.device_config
& monitor_controls
[i
].pcm_dev
))
1012 err
= add_controls(chip
, monitor_controls
[i
].controls
,
1013 ARRAY_SIZE(monitor_controls
[i
].controls
));
1017 if (chip
->has_ac97_0
) {
1018 err
= add_controls(chip
, ac97_controls
,
1019 ARRAY_SIZE(ac97_controls
));
1023 if (chip
->has_ac97_1
) {
1024 err
= add_controls(chip
, ac97_fp_controls
,
1025 ARRAY_SIZE(ac97_fp_controls
));
1029 return chip
->model
.mixer_init
? chip
->model
.mixer_init(chip
) : 0;