[ALSA] Remove sound/driver.h
[linux-2.6.git] / sound / pci / oxygen / oxygen_mixer.c
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
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 {
30         struct oxygen *chip = ctl->private_data;
31
32         info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
33         info->count = 8;
34         info->value.integer.min = chip->model->dac_minimum_volume;
35         info->value.integer.max = 0xff;
36         return 0;
37 }
38
39 static int dac_volume_get(struct snd_kcontrol *ctl,
40                           struct snd_ctl_elem_value *value)
41 {
42         struct oxygen *chip = ctl->private_data;
43         unsigned int i;
44
45         mutex_lock(&chip->mutex);
46         for (i = 0; i < 8; ++i)
47                 value->value.integer.value[i] = chip->dac_volume[i];
48         mutex_unlock(&chip->mutex);
49         return 0;
50 }
51
52 static int dac_volume_put(struct snd_kcontrol *ctl,
53                           struct snd_ctl_elem_value *value)
54 {
55         struct oxygen *chip = ctl->private_data;
56         unsigned int i;
57         int changed;
58
59         changed = 0;
60         mutex_lock(&chip->mutex);
61         for (i = 0; i < 8; ++i)
62                 if (value->value.integer.value[i] != chip->dac_volume[i]) {
63                         chip->dac_volume[i] = value->value.integer.value[i];
64                         changed = 1;
65                 }
66         if (changed)
67                 chip->model->update_dac_volume(chip);
68         mutex_unlock(&chip->mutex);
69         return changed;
70 }
71
72 static int dac_mute_get(struct snd_kcontrol *ctl,
73                         struct snd_ctl_elem_value *value)
74 {
75         struct oxygen *chip = ctl->private_data;
76
77         mutex_lock(&chip->mutex);
78         value->value.integer.value[0] = !chip->dac_mute;
79         mutex_unlock(&chip->mutex);
80         return 0;
81 }
82
83 static int dac_mute_put(struct snd_kcontrol *ctl,
84                           struct snd_ctl_elem_value *value)
85 {
86         struct oxygen *chip = ctl->private_data;
87         int changed;
88
89         mutex_lock(&chip->mutex);
90         changed = !value->value.integer.value[0] != chip->dac_mute;
91         if (changed) {
92                 chip->dac_mute = !value->value.integer.value[0];
93                 chip->model->update_dac_mute(chip);
94         }
95         mutex_unlock(&chip->mutex);
96         return changed;
97 }
98
99 static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
100 {
101         static const char *const names[3] = {
102                 "Front", "Front+Rear", "Front+Rear+Side"
103         };
104         info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
105         info->count = 1;
106         info->value.enumerated.items = 3;
107         if (info->value.enumerated.item > 2)
108                 info->value.enumerated.item = 2;
109         strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
110         return 0;
111 }
112
113 static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
114 {
115         struct oxygen *chip = ctl->private_data;
116
117         mutex_lock(&chip->mutex);
118         value->value.enumerated.item[0] = chip->dac_routing;
119         mutex_unlock(&chip->mutex);
120         return 0;
121 }
122
123 void oxygen_update_dac_routing(struct oxygen *chip)
124 {
125         /*
126          * hardware channel order: front, side, center/lfe, rear
127          * ALSA channel order:     front, rear, center/lfe, side
128          */
129         static const unsigned int reg_values[3] = {
130                 0x6c00, 0x2c00, 0x2000
131         };
132         unsigned int reg_value;
133
134         if ((oxygen_read8(chip, OXYGEN_PLAY_CHANNELS) &
135              OXYGEN_PLAY_CHANNELS_MASK) == OXYGEN_PLAY_CHANNELS_2)
136                 reg_value = reg_values[chip->dac_routing];
137         else
138                 reg_value = 0x6c00;
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
403 static int ac97_switch_put(struct snd_kcontrol *ctl,
404                            struct snd_ctl_elem_value *value)
405 {
406         struct oxygen *chip = ctl->private_data;
407         unsigned int index = ctl->private_value & 0xff;
408         unsigned int bitnr = (ctl->private_value >> 8) & 0xff;
409         int invert = ctl->private_value & (1 << 16);
410         u16 oldreg, newreg;
411         int change;
412
413         mutex_lock(&chip->mutex);
414         oldreg = oxygen_read_ac97(chip, 0, index);
415         newreg = oldreg;
416         if (!value->value.integer.value[0] ^ !invert)
417                 newreg |= 1 << bitnr;
418         else
419                 newreg &= ~(1 << bitnr);
420         change = newreg != oldreg;
421         if (change) {
422                 oxygen_write_ac97(chip, 0, index, newreg);
423                 if (index == AC97_LINE)
424                         oxygen_write_ac97_masked(chip, 0, 0x72,
425                                                  !!(newreg & 0x8000), 0x0001);
426         }
427         mutex_unlock(&chip->mutex);
428         return change;
429 }
430
431 static int ac97_volume_info(struct snd_kcontrol *ctl,
432                             struct snd_ctl_elem_info *info)
433 {
434         info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
435         info->count = 2;
436         info->value.integer.min = 0;
437         info->value.integer.max = 0x1f;
438         return 0;
439 }
440
441 static int ac97_volume_get(struct snd_kcontrol *ctl,
442                            struct snd_ctl_elem_value *value)
443 {
444         struct oxygen *chip = ctl->private_data;
445         unsigned int index = ctl->private_value;
446         u16 reg;
447
448         mutex_lock(&chip->mutex);
449         reg = oxygen_read_ac97(chip, 0, index);
450         mutex_unlock(&chip->mutex);
451         value->value.integer.value[0] = 31 - (reg & 0x1f);
452         value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f);
453         return 0;
454 }
455
456 static int ac97_volume_put(struct snd_kcontrol *ctl,
457                            struct snd_ctl_elem_value *value)
458 {
459         struct oxygen *chip = ctl->private_data;
460         unsigned int index = ctl->private_value;
461         u16 oldreg, newreg;
462         int change;
463
464         mutex_lock(&chip->mutex);
465         oldreg = oxygen_read_ac97(chip, 0, index);
466         newreg = oldreg;
467         newreg = (newreg & ~0x1f) |
468                 (31 - (value->value.integer.value[0] & 0x1f));
469         newreg = (newreg & ~0x1f00) |
470                 ((31 - (value->value.integer.value[0] & 0x1f)) << 8);
471         change = newreg != oldreg;
472         if (change)
473                 oxygen_write_ac97(chip, 0, index, newreg);
474         mutex_unlock(&chip->mutex);
475         return change;
476 }
477
478 #define AC97_SWITCH(xname, index, bitnr, invert) { \
479                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
480                 .name = xname, \
481                 .info = snd_ctl_boolean_mono_info, \
482                 .get = ac97_switch_get, \
483                 .put = ac97_switch_put, \
484                 .private_value = ((invert) << 16) | ((bitnr) << 8) | (index), \
485         }
486 #define AC97_VOLUME(xname, index) { \
487                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
488                 .name = xname, \
489                 .info = ac97_volume_info, \
490                 .get = ac97_volume_get, \
491                 .put = ac97_volume_put, \
492                 .tlv = { .p = ac97_db_scale, }, \
493                 .private_value = (index), \
494         }
495
496 static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
497
498 static const struct snd_kcontrol_new controls[] = {
499         {
500                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
501                 .name = "PCM Playback Volume",
502                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
503                           SNDRV_CTL_ELEM_ACCESS_TLV_READ,
504                 .info = dac_volume_info,
505                 .get = dac_volume_get,
506                 .put = dac_volume_put,
507                 .tlv = {
508                         .p = NULL, /* set later */
509                 },
510         },
511         {
512                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
513                 .name = "PCM Playback Switch",
514                 .info = snd_ctl_boolean_mono_info,
515                 .get = dac_mute_get,
516                 .put = dac_mute_put,
517         },
518         {
519                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
520                 .name = "Stereo Upmixing",
521                 .info = upmix_info,
522                 .get = upmix_get,
523                 .put = upmix_put,
524         },
525         {
526                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527                 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
528                 .info = snd_ctl_boolean_mono_info,
529                 .get = spdif_switch_get,
530                 .put = spdif_switch_put,
531         },
532         {
533                 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
534                 .device = 1,
535                 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
536                 .info = spdif_info,
537                 .get = spdif_default_get,
538                 .put = spdif_default_put,
539         },
540         {
541                 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
542                 .device = 1,
543                 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
544                 .access = SNDRV_CTL_ELEM_ACCESS_READ,
545                 .info = spdif_info,
546                 .get = spdif_mask_get,
547         },
548         {
549                 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
550                 .device = 1,
551                 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
552                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
553                           SNDRV_CTL_ELEM_ACCESS_INACTIVE,
554                 .info = spdif_info,
555                 .get = spdif_pcm_get,
556                 .put = spdif_pcm_put,
557         },
558         {
559                 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
560                 .device = 1,
561                 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
562                 .access = SNDRV_CTL_ELEM_ACCESS_READ,
563                 .info = spdif_info,
564                 .get = spdif_input_mask_get,
565         },
566         {
567                 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
568                 .device = 1,
569                 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
570                 .access = SNDRV_CTL_ELEM_ACCESS_READ,
571                 .info = spdif_info,
572                 .get = spdif_input_default_get,
573         },
574         AC97_VOLUME("Mic Capture Volume", AC97_MIC),
575         AC97_SWITCH("Mic Capture Switch", AC97_MIC, 15, 1),
576         AC97_SWITCH("Mic Boost (+20dB)", AC97_MIC, 6, 0),
577         AC97_SWITCH("Line Capture Switch", AC97_LINE, 15, 1),
578         AC97_VOLUME("CD Capture Volume", AC97_CD),
579         AC97_SWITCH("CD Capture Switch", AC97_CD, 15, 1),
580         AC97_VOLUME("Aux Capture Volume", AC97_AUX),
581         AC97_SWITCH("Aux Capture Switch", AC97_AUX, 15, 1),
582 };
583
584 static void oxygen_any_ctl_free(struct snd_kcontrol *ctl)
585 {
586         struct oxygen *chip = ctl->private_data;
587
588         /* I'm too lazy to write a function for each control :-) */
589         chip->spdif_pcm_ctl = NULL;
590         chip->spdif_input_bits_ctl = NULL;
591 }
592
593 int oxygen_mixer_init(struct oxygen *chip)
594 {
595         unsigned int i;
596         struct snd_kcontrol *ctl;
597         int err;
598
599         for (i = 0; i < ARRAY_SIZE(controls); ++i) {
600                 ctl = snd_ctl_new1(&controls[i], chip);
601                 if (!ctl)
602                         return -ENOMEM;
603                 if (!strcmp(ctl->id.name, "PCM Playback Volume"))
604                         ctl->tlv.p = chip->model->dac_tlv;
605                 else if (chip->model->cd_in_from_video_in &&
606                          !strncmp(ctl->id.name, "CD Capture ", 11))
607                         ctl->private_value ^= AC97_CD ^ AC97_VIDEO;
608                 err = snd_ctl_add(chip->card, ctl);
609                 if (err < 0)
610                         return err;
611                 if (!strcmp(ctl->id.name,
612                             SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM))) {
613                         chip->spdif_pcm_ctl = ctl;
614                         ctl->private_free = oxygen_any_ctl_free;
615                 } else if (!strcmp(ctl->id.name,
616                                  SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
617                         chip->spdif_input_bits_ctl = ctl;
618                         ctl->private_free = oxygen_any_ctl_free;
619                 }
620         }
621         return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0;
622 }