]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - sound/isa/cs423x/cs4236_lib.c
Merge http://oss.oracle.com/git/ocfs2
[linux-2.6.git] / sound / isa / cs423x / cs4236_lib.c
1 /*
2  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3  *  Routines for control of CS4235/4236B/4237B/4238B/4239 chips
4  *
5  *  Note:
6  *     -----
7  *
8  *  Bugs:
9  *     -----
10  *
11  *   This program is free software; you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation; either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program; if not, write to the Free Software
23  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  *
25  */
26
27 /*
28  *  Indirect control registers (CS4236B+)
29  * 
30  *  C0
31  *     D8: WSS reset (all chips)
32  *
33  *  C1 (all chips except CS4236)
34  *     D7-D5: version 
35  *     D4-D0: chip id
36  *             11101 - CS4235
37  *             01011 - CS4236B
38  *             01000 - CS4237B
39  *             01001 - CS4238B
40  *             11110 - CS4239
41  *
42  *  C2
43  *     D7-D4: 3D Space (CS4235,CS4237B,CS4238B,CS4239)
44  *     D3-D0: 3D Center (CS4237B); 3D Volume (CS4238B)
45  * 
46  *  C3
47  *     D7: 3D Enable (CS4237B)
48  *     D6: 3D Mono Enable (CS4237B)
49  *     D5: 3D Serial Output (CS4237B,CS4238B)
50  *     D4: 3D Enable (CS4235,CS4238B,CS4239)
51  *
52  *  C4
53  *     D7: consumer serial port enable (CS4237B,CS4238B)
54  *     D6: channels status block reset (CS4237B,CS4238B)
55  *     D5: user bit in sub-frame of digital audio data (CS4237B,CS4238B)
56  *     D4: validity bit bit in sub-frame of digital audio data (CS4237B,CS4238B)
57  * 
58  *  C5  lower channel status (digital serial data description) (CS4237B,CS4238B)
59  *     D7-D6: first two bits of category code
60  *     D5: lock
61  *     D4-D3: pre-emphasis (0 = none, 1 = 50/15us)
62  *     D2: copy/copyright (0 = copy inhibited)
63  *     D1: 0 = digital audio / 1 = non-digital audio
64  *     
65  *  C6  upper channel status (digital serial data description) (CS4237B,CS4238B)
66  *     D7-D6: sample frequency (0 = 44.1kHz)
67  *     D5: generation status (0 = no indication, 1 = original/commercially precaptureed data)
68  *     D4-D0: category code (upper bits)
69  *
70  *  C7  reserved (must write 0)
71  *
72  *  C8  wavetable control
73  *     D7: volume control interrupt enable (CS4235,CS4239)
74  *     D6: hardware volume control format (CS4235,CS4239)
75  *     D3: wavetable serial port enable (all chips)
76  *     D2: DSP serial port switch (all chips)
77  *     D1: disable MCLK (all chips)
78  *     D0: force BRESET low (all chips)
79  *
80  */
81
82 #include <sound/driver.h>
83 #include <asm/io.h>
84 #include <linux/delay.h>
85 #include <linux/init.h>
86 #include <linux/time.h>
87 #include <linux/wait.h>
88 #include <sound/core.h>
89 #include <sound/cs4231.h>
90 #include <sound/asoundef.h>
91
92 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
93 MODULE_DESCRIPTION("Routines for control of CS4235/4236B/4237B/4238B/4239 chips");
94 MODULE_LICENSE("GPL");
95
96 /*
97  *
98  */
99
100 static unsigned char snd_cs4236_ext_map[18] = {
101         /* CS4236_LEFT_LINE */          0xff,
102         /* CS4236_RIGHT_LINE */         0xff,
103         /* CS4236_LEFT_MIC */           0xdf,
104         /* CS4236_RIGHT_MIC */          0xdf,
105         /* CS4236_LEFT_MIX_CTRL */      0xe0 | 0x18,
106         /* CS4236_RIGHT_MIX_CTRL */     0xe0,
107         /* CS4236_LEFT_FM */            0xbf,
108         /* CS4236_RIGHT_FM */           0xbf,
109         /* CS4236_LEFT_DSP */           0xbf,
110         /* CS4236_RIGHT_DSP */          0xbf,
111         /* CS4236_RIGHT_LOOPBACK */     0xbf,
112         /* CS4236_DAC_MUTE */           0xe0,
113         /* CS4236_ADC_RATE */           0x01,   /* 48kHz */
114         /* CS4236_DAC_RATE */           0x01,   /* 48kHz */
115         /* CS4236_LEFT_MASTER */        0xbf,
116         /* CS4236_RIGHT_MASTER */       0xbf,
117         /* CS4236_LEFT_WAVE */          0xbf,
118         /* CS4236_RIGHT_WAVE */         0xbf
119 };
120
121 /*
122  *
123  */
124
125 static void snd_cs4236_ctrl_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char val)
126 {
127         outb(reg, chip->cport + 3);
128         outb(chip->cimage[reg] = val, chip->cport + 4);
129 }
130
131 static unsigned char snd_cs4236_ctrl_in(struct snd_cs4231 *chip, unsigned char reg)
132 {
133         outb(reg, chip->cport + 3);
134         return inb(chip->cport + 4);
135 }
136
137 /*
138  *  PCM
139  */
140
141 #define CLOCKS 8
142
143 static struct snd_ratnum clocks[CLOCKS] = {
144         { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 },
145         { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 },
146         { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 },
147         { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 },
148         { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 },
149         { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 },
150         { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 },
151         { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 }
152 };
153
154 static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = {
155         .nrats = CLOCKS,
156         .rats = clocks,
157 };
158
159 static int snd_cs4236_xrate(struct snd_pcm_runtime *runtime)
160 {
161         return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
162                                              &hw_constraints_clocks);
163 }
164
165 static unsigned char divisor_to_rate_register(unsigned int divisor)
166 {
167         switch (divisor) {
168         case 353:       return 1;
169         case 529:       return 2;
170         case 617:       return 3;
171         case 1058:      return 4;
172         case 1764:      return 5;
173         case 2117:      return 6;
174         case 2558:      return 7;
175         default:
176                 if (divisor < 21 || divisor > 192) {
177                         snd_BUG();
178                         return 192;
179                 }
180                 return divisor;
181         }
182 }
183
184 static void snd_cs4236_playback_format(struct snd_cs4231 *chip, struct snd_pcm_hw_params *params, unsigned char pdfr)
185 {
186         unsigned long flags;
187         unsigned char rate = divisor_to_rate_register(params->rate_den);
188         
189         spin_lock_irqsave(&chip->reg_lock, flags);
190         /* set fast playback format change and clean playback FIFO */
191         snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
192         snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0);
193         snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x10);
194         snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate);
195         spin_unlock_irqrestore(&chip->reg_lock, flags);
196 }
197
198 static void snd_cs4236_capture_format(struct snd_cs4231 *chip, struct snd_pcm_hw_params *params, unsigned char cdfr)
199 {
200         unsigned long flags;
201         unsigned char rate = divisor_to_rate_register(params->rate_den);
202         
203         spin_lock_irqsave(&chip->reg_lock, flags);
204         /* set fast capture format change and clean capture FIFO */
205         snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
206         snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0);
207         snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x20);
208         snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate);
209         spin_unlock_irqrestore(&chip->reg_lock, flags);
210 }
211
212 #ifdef CONFIG_PM
213
214 static void snd_cs4236_suspend(struct snd_cs4231 *chip)
215 {
216         int reg;
217         unsigned long flags;
218         
219         spin_lock_irqsave(&chip->reg_lock, flags);
220         for (reg = 0; reg < 32; reg++)
221                 chip->image[reg] = snd_cs4231_in(chip, reg);
222         for (reg = 0; reg < 18; reg++)
223                 chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg));
224         for (reg = 2; reg < 9; reg++)
225                 chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg);
226         spin_unlock_irqrestore(&chip->reg_lock, flags);
227 }
228
229 static void snd_cs4236_resume(struct snd_cs4231 *chip)
230 {
231         int reg;
232         unsigned long flags;
233         
234         snd_cs4231_mce_up(chip);
235         spin_lock_irqsave(&chip->reg_lock, flags);
236         for (reg = 0; reg < 32; reg++) {
237                 switch (reg) {
238                 case CS4236_EXT_REG:
239                 case CS4231_VERSION:
240                 case 27:        /* why? CS4235 - master left */
241                 case 29:        /* why? CS4235 - master right */
242                         break;
243                 default:
244                         snd_cs4231_out(chip, reg, chip->image[reg]);
245                         break;
246                 }
247         }
248         for (reg = 0; reg < 18; reg++)
249                 snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]);
250         for (reg = 2; reg < 9; reg++) {
251                 switch (reg) {
252                 case 7:
253                         break;
254                 default:
255                         snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]);
256                 }
257         }
258         spin_unlock_irqrestore(&chip->reg_lock, flags);
259         snd_cs4231_mce_down(chip);
260 }
261
262 #endif /* CONFIG_PM */
263
264 int snd_cs4236_create(struct snd_card *card,
265                       unsigned long port,
266                       unsigned long cport,
267                       int irq, int dma1, int dma2,
268                       unsigned short hardware,
269                       unsigned short hwshare,
270                       struct snd_cs4231 ** rchip)
271 {
272         struct snd_cs4231 *chip;
273         unsigned char ver1, ver2;
274         unsigned int reg;
275         int err;
276
277         *rchip = NULL;
278         if (hardware == CS4231_HW_DETECT)
279                 hardware = CS4231_HW_DETECT3;
280         if (cport < 0x100) {
281                 snd_printk("please, specify control port for CS4236+ chips\n");
282                 return -ENODEV;
283         }
284         if ((err = snd_cs4231_create(card, port, cport, irq, dma1, dma2, hardware, hwshare, &chip)) < 0)
285                 return err;
286
287         if (!(chip->hardware & CS4231_HW_CS4236B_MASK)) {
288                 snd_printk("CS4236+: MODE3 and extended registers not available, hardware=0x%x\n",chip->hardware);
289                 snd_device_free(card, chip);
290                 return -ENODEV;
291         }
292 #if 0
293         {
294                 int idx;
295                 for (idx = 0; idx < 8; idx++)
296                         snd_printk("CD%i = 0x%x\n", idx, inb(chip->cport + idx));
297                 for (idx = 0; idx < 9; idx++)
298                         snd_printk("C%i = 0x%x\n", idx, snd_cs4236_ctrl_in(chip, idx));
299         }
300 #endif
301         ver1 = snd_cs4236_ctrl_in(chip, 1);
302         ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
303         snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2);
304         if (ver1 != ver2) {
305                 snd_printk("CS4236+ chip detected, but control port 0x%lx is not valid\n", cport);
306                 snd_device_free(card, chip);
307                 return -ENODEV;
308         }
309         snd_cs4236_ctrl_out(chip, 0, 0x00);
310         snd_cs4236_ctrl_out(chip, 2, 0xff);
311         snd_cs4236_ctrl_out(chip, 3, 0x00);
312         snd_cs4236_ctrl_out(chip, 4, 0x80);
313         snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE);
314         snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2);
315         snd_cs4236_ctrl_out(chip, 7, 0x00);
316         /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */
317         /* is working with this setup, other hardware should have */
318         /* different signal paths and this value should be selectable */
319         /* in the future */
320         snd_cs4236_ctrl_out(chip, 8, 0x8c);
321         chip->rate_constraint = snd_cs4236_xrate;
322         chip->set_playback_format = snd_cs4236_playback_format;
323         chip->set_capture_format = snd_cs4236_capture_format;
324 #ifdef CONFIG_PM
325         chip->suspend = snd_cs4236_suspend;
326         chip->resume = snd_cs4236_resume;
327 #endif
328
329         /* initialize extended registers */
330         for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++)
331                 snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]);
332
333         /* initialize compatible but more featured registers */
334         snd_cs4231_out(chip, CS4231_LEFT_INPUT, 0x40);
335         snd_cs4231_out(chip, CS4231_RIGHT_INPUT, 0x40);
336         snd_cs4231_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff);
337         snd_cs4231_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff);
338         snd_cs4231_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf);
339         snd_cs4231_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf);
340         snd_cs4231_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
341         snd_cs4231_out(chip, CS4231_LEFT_LINE_IN, 0xff);
342         snd_cs4231_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
343         switch (chip->hardware) {
344         case CS4231_HW_CS4235:
345         case CS4231_HW_CS4239:
346                 snd_cs4231_out(chip, CS4235_LEFT_MASTER, 0xff);
347                 snd_cs4231_out(chip, CS4235_RIGHT_MASTER, 0xff);
348                 break;
349         }
350
351         *rchip = chip;
352         return 0;
353 }
354
355 int snd_cs4236_pcm(struct snd_cs4231 *chip, int device, struct snd_pcm **rpcm)
356 {
357         struct snd_pcm *pcm;
358         int err;
359         
360         if ((err = snd_cs4231_pcm(chip, device, &pcm)) < 0)
361                 return err;
362         pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX;
363         if (rpcm)
364                 *rpcm = pcm;
365         return 0;
366 }
367
368 /*
369  *  MIXER
370  */
371
372 #define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \
373 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
374   .info = snd_cs4236_info_single, \
375   .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
376   .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
377
378 static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
379 {
380         int mask = (kcontrol->private_value >> 16) & 0xff;
381
382         uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
383         uinfo->count = 1;
384         uinfo->value.integer.min = 0;
385         uinfo->value.integer.max = mask;
386         return 0;
387 }
388
389 static int snd_cs4236_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
390 {
391         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
392         unsigned long flags;
393         int reg = kcontrol->private_value & 0xff;
394         int shift = (kcontrol->private_value >> 8) & 0xff;
395         int mask = (kcontrol->private_value >> 16) & 0xff;
396         int invert = (kcontrol->private_value >> 24) & 0xff;
397         
398         spin_lock_irqsave(&chip->reg_lock, flags);
399         ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask;
400         spin_unlock_irqrestore(&chip->reg_lock, flags);
401         if (invert)
402                 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
403         return 0;
404 }
405
406 static int snd_cs4236_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
407 {
408         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
409         unsigned long flags;
410         int reg = kcontrol->private_value & 0xff;
411         int shift = (kcontrol->private_value >> 8) & 0xff;
412         int mask = (kcontrol->private_value >> 16) & 0xff;
413         int invert = (kcontrol->private_value >> 24) & 0xff;
414         int change;
415         unsigned short val;
416         
417         val = (ucontrol->value.integer.value[0] & mask);
418         if (invert)
419                 val = mask - val;
420         val <<= shift;
421         spin_lock_irqsave(&chip->reg_lock, flags);
422         val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val;
423         change = val != chip->eimage[CS4236_REG(reg)];
424         snd_cs4236_ext_out(chip, reg, val);
425         spin_unlock_irqrestore(&chip->reg_lock, flags);
426         return change;
427 }
428
429 #define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \
430 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
431   .info = snd_cs4236_info_single, \
432   .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \
433   .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
434
435 static int snd_cs4236_get_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
436 {
437         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
438         unsigned long flags;
439         int reg = kcontrol->private_value & 0xff;
440         int shift = (kcontrol->private_value >> 8) & 0xff;
441         int mask = (kcontrol->private_value >> 16) & 0xff;
442         int invert = (kcontrol->private_value >> 24) & 0xff;
443         
444         spin_lock_irqsave(&chip->reg_lock, flags);
445         ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask;
446         spin_unlock_irqrestore(&chip->reg_lock, flags);
447         if (invert)
448                 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
449         return 0;
450 }
451
452 static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
453 {
454         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
455         unsigned long flags;
456         int reg = kcontrol->private_value & 0xff;
457         int shift = (kcontrol->private_value >> 8) & 0xff;
458         int mask = (kcontrol->private_value >> 16) & 0xff;
459         int invert = (kcontrol->private_value >> 24) & 0xff;
460         int change;
461         unsigned short val;
462         
463         val = (ucontrol->value.integer.value[0] & mask);
464         if (invert)
465                 val = mask - val;
466         val <<= shift;
467         spin_lock_irqsave(&chip->reg_lock, flags);
468         val = (chip->cimage[reg] & ~(mask << shift)) | val;
469         change = val != chip->cimage[reg];
470         snd_cs4236_ctrl_out(chip, reg, val);
471         spin_unlock_irqrestore(&chip->reg_lock, flags);
472         return change;
473 }
474
475 #define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
476 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
477   .info = snd_cs4236_info_double, \
478   .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
479   .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
480
481 static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
482 {
483         int mask = (kcontrol->private_value >> 24) & 0xff;
484
485         uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
486         uinfo->count = 2;
487         uinfo->value.integer.min = 0;
488         uinfo->value.integer.max = mask;
489         return 0;
490 }
491
492 static int snd_cs4236_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
493 {
494         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
495         unsigned long flags;
496         int left_reg = kcontrol->private_value & 0xff;
497         int right_reg = (kcontrol->private_value >> 8) & 0xff;
498         int shift_left = (kcontrol->private_value >> 16) & 0x07;
499         int shift_right = (kcontrol->private_value >> 19) & 0x07;
500         int mask = (kcontrol->private_value >> 24) & 0xff;
501         int invert = (kcontrol->private_value >> 22) & 1;
502         
503         spin_lock_irqsave(&chip->reg_lock, flags);
504         ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask;
505         ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
506         spin_unlock_irqrestore(&chip->reg_lock, flags);
507         if (invert) {
508                 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
509                 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
510         }
511         return 0;
512 }
513
514 static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
515 {
516         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
517         unsigned long flags;
518         int left_reg = kcontrol->private_value & 0xff;
519         int right_reg = (kcontrol->private_value >> 8) & 0xff;
520         int shift_left = (kcontrol->private_value >> 16) & 0x07;
521         int shift_right = (kcontrol->private_value >> 19) & 0x07;
522         int mask = (kcontrol->private_value >> 24) & 0xff;
523         int invert = (kcontrol->private_value >> 22) & 1;
524         int change;
525         unsigned short val1, val2;
526         
527         val1 = ucontrol->value.integer.value[0] & mask;
528         val2 = ucontrol->value.integer.value[1] & mask;
529         if (invert) {
530                 val1 = mask - val1;
531                 val2 = mask - val2;
532         }
533         val1 <<= shift_left;
534         val2 <<= shift_right;
535         spin_lock_irqsave(&chip->reg_lock, flags);
536         if (left_reg != right_reg) {
537                 val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1;
538                 val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
539                 change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)];
540                 snd_cs4236_ext_out(chip, left_reg, val1);
541                 snd_cs4236_ext_out(chip, right_reg, val2);
542         } else {
543                 val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
544                 change = val1 != chip->eimage[CS4236_REG(left_reg)];
545                 snd_cs4236_ext_out(chip, left_reg, val1);
546         }
547         spin_unlock_irqrestore(&chip->reg_lock, flags);
548         return change;
549 }
550
551 #define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
552 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
553   .info = snd_cs4236_info_double, \
554   .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
555   .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
556
557 static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
558 {
559         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
560         unsigned long flags;
561         int left_reg = kcontrol->private_value & 0xff;
562         int right_reg = (kcontrol->private_value >> 8) & 0xff;
563         int shift_left = (kcontrol->private_value >> 16) & 0x07;
564         int shift_right = (kcontrol->private_value >> 19) & 0x07;
565         int mask = (kcontrol->private_value >> 24) & 0xff;
566         int invert = (kcontrol->private_value >> 22) & 1;
567         
568         spin_lock_irqsave(&chip->reg_lock, flags);
569         ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
570         ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
571         spin_unlock_irqrestore(&chip->reg_lock, flags);
572         if (invert) {
573                 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
574                 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
575         }
576         return 0;
577 }
578
579 static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
580 {
581         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
582         unsigned long flags;
583         int left_reg = kcontrol->private_value & 0xff;
584         int right_reg = (kcontrol->private_value >> 8) & 0xff;
585         int shift_left = (kcontrol->private_value >> 16) & 0x07;
586         int shift_right = (kcontrol->private_value >> 19) & 0x07;
587         int mask = (kcontrol->private_value >> 24) & 0xff;
588         int invert = (kcontrol->private_value >> 22) & 1;
589         int change;
590         unsigned short val1, val2;
591         
592         val1 = ucontrol->value.integer.value[0] & mask;
593         val2 = ucontrol->value.integer.value[1] & mask;
594         if (invert) {
595                 val1 = mask - val1;
596                 val2 = mask - val2;
597         }
598         val1 <<= shift_left;
599         val2 <<= shift_right;
600         spin_lock_irqsave(&chip->reg_lock, flags);
601         val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
602         val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
603         change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)];
604         snd_cs4231_out(chip, left_reg, val1);
605         snd_cs4236_ext_out(chip, right_reg, val2);
606         spin_unlock_irqrestore(&chip->reg_lock, flags);
607         return change;
608 }
609
610 #define CS4236_MASTER_DIGITAL(xname, xindex) \
611 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
612   .info = snd_cs4236_info_double, \
613   .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \
614   .private_value = 71 << 24 }
615
616 static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol)
617 {
618         return (vol < 64) ? 63 - vol : 64 + (71 - vol);
619 }        
620
621 static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
622 {
623         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
624         unsigned long flags;
625         
626         spin_lock_irqsave(&chip->reg_lock, flags);
627         ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f);
628         ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f);
629         spin_unlock_irqrestore(&chip->reg_lock, flags);
630         return 0;
631 }
632
633 static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
634 {
635         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
636         unsigned long flags;
637         int change;
638         unsigned short val1, val2;
639         
640         val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f);
641         val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f);
642         spin_lock_irqsave(&chip->reg_lock, flags);
643         val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1;
644         val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2;
645         change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)];
646         snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1);
647         snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val1);
648         spin_unlock_irqrestore(&chip->reg_lock, flags);
649         return change;
650 }
651
652 #define CS4235_OUTPUT_ACCU(xname, xindex) \
653 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
654   .info = snd_cs4236_info_double, \
655   .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \
656   .private_value = 3 << 24 }
657
658 static inline int snd_cs4235_mixer_output_accu_get_volume(int vol)
659 {
660         switch ((vol >> 5) & 3) {
661         case 0: return 1;
662         case 1: return 3;
663         case 2: return 2;
664         case 3: return 0;
665         }
666         return 3;
667 }
668
669 static inline int snd_cs4235_mixer_output_accu_set_volume(int vol)
670 {
671         switch (vol & 3) {
672         case 0: return 3 << 5;
673         case 1: return 0 << 5;
674         case 2: return 2 << 5;
675         case 3: return 1 << 5;
676         }
677         return 1 << 5;
678 }
679
680 static int snd_cs4235_get_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
681 {
682         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
683         unsigned long flags;
684         
685         spin_lock_irqsave(&chip->reg_lock, flags);
686         ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]);
687         ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]);
688         spin_unlock_irqrestore(&chip->reg_lock, flags);
689         return 0;
690 }
691
692 static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
693 {
694         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
695         unsigned long flags;
696         int change;
697         unsigned short val1, val2;
698         
699         val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]);
700         val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]);
701         spin_lock_irqsave(&chip->reg_lock, flags);
702         val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1;
703         val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2;
704         change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER];
705         snd_cs4231_out(chip, CS4235_LEFT_MASTER, val1);
706         snd_cs4231_out(chip, CS4235_RIGHT_MASTER, val2);
707         spin_unlock_irqrestore(&chip->reg_lock, flags);
708         return change;
709 }
710
711 static struct snd_kcontrol_new snd_cs4236_controls[] = {
712
713 CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
714 CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
715 CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
716
717 CS4236_DOUBLE("Capture Boost Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
718
719 CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
720 CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
721
722 CS4236_DOUBLE("DSP Playback Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
723 CS4236_DOUBLE("DSP Playback Volume", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1),
724
725 CS4236_DOUBLE("FM Playback Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
726 CS4236_DOUBLE("FM Playback Volume", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1),
727
728 CS4236_DOUBLE("Wavetable Playback Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
729 CS4236_DOUBLE("Wavetable Playback Volume", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1),
730
731 CS4231_DOUBLE("Synth Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
732 CS4231_DOUBLE("Synth Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
733 CS4231_DOUBLE("Synth Capture Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
734 CS4231_DOUBLE("Synth Capture Bypass", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1),
735
736 CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
737 CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
738 CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1),
739 CS4236_DOUBLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0),
740
741 CS4231_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
742 CS4231_DOUBLE("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
743 CS4231_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
744 CS4231_DOUBLE("Line Capture Bypass", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1),
745
746 CS4231_DOUBLE("CD Playback Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
747 CS4231_DOUBLE("CD Volume", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
748 CS4231_DOUBLE("CD Capture Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
749
750 CS4236_DOUBLE1("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
751 CS4236_DOUBLE1("Mono Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
752 CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
753 CS4231_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
754
755 CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
756 CS4231_DOUBLE("Analog Loopback Capture Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
757
758 CS4231_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
759 CS4236_DOUBLE1("Digital Loopback Playback Volume", 0, CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1)
760 };
761
762 static struct snd_kcontrol_new snd_cs4235_controls[] = {
763
764 CS4231_DOUBLE("Master Switch", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1),
765 CS4231_DOUBLE("Master Volume", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1),
766
767 CS4235_OUTPUT_ACCU("Playback Volume", 0),
768
769 CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
770 CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
771 CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
772
773 CS4231_DOUBLE("Master Digital Playback Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
774 CS4231_DOUBLE("Master Digital Capture Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
775 CS4231_DOUBLE("Master Digital Volume", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
776
777 CS4236_DOUBLE("Capture Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
778
779 CS4231_DOUBLE("PCM Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
780 CS4231_DOUBLE("PCM Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
781
782 CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
783
784 CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
785
786 CS4236_DOUBLE("Wavetable Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
787
788 CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
789 CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
790 CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1),
791 CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0),
792
793 CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
794 CS4231_DOUBLE("Aux Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
795 CS4231_DOUBLE("Aux Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
796
797 CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
798 CS4231_DOUBLE("Aux Capture Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
799 CS4231_DOUBLE("Aux Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
800
801 CS4236_DOUBLE1("Master Mono Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
802
803 CS4236_DOUBLE1("Mono Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
804 CS4231_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
805
806 CS4231_DOUBLE("Analog Loopback Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
807 };
808
809 #define CS4236_IEC958_ENABLE(xname, xindex) \
810 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
811   .info = snd_cs4236_info_single, \
812   .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \
813   .private_value = 1 << 16 }
814
815 static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
816 {
817         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
818         unsigned long flags;
819         
820         spin_lock_irqsave(&chip->reg_lock, flags);
821         ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0;
822 #if 0
823         printk("get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
824                         snd_cs4231_in(chip, CS4231_ALT_FEATURE_1),
825                         snd_cs4236_ctrl_in(chip, 3),
826                         snd_cs4236_ctrl_in(chip, 4),
827                         snd_cs4236_ctrl_in(chip, 5),
828                         snd_cs4236_ctrl_in(chip, 6),
829                         snd_cs4236_ctrl_in(chip, 8));
830 #endif
831         spin_unlock_irqrestore(&chip->reg_lock, flags);
832         return 0;
833 }
834
835 static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
836 {
837         struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
838         unsigned long flags;
839         int change;
840         unsigned short enable, val;
841         
842         enable = ucontrol->value.integer.value[0] & 1;
843
844         down(&chip->mce_mutex);
845         snd_cs4231_mce_up(chip);
846         spin_lock_irqsave(&chip->reg_lock, flags);
847         val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1);
848         change = val != chip->image[CS4231_ALT_FEATURE_1];
849         snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, val);
850         val = snd_cs4236_ctrl_in(chip, 4) | 0xc0;
851         snd_cs4236_ctrl_out(chip, 4, val);
852         udelay(100);
853         val &= ~0x40;
854         snd_cs4236_ctrl_out(chip, 4, val);
855         spin_unlock_irqrestore(&chip->reg_lock, flags);
856         snd_cs4231_mce_down(chip);
857         up(&chip->mce_mutex);
858
859 #if 0
860         printk("set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
861                         snd_cs4231_in(chip, CS4231_ALT_FEATURE_1),
862                         snd_cs4236_ctrl_in(chip, 3),
863                         snd_cs4236_ctrl_in(chip, 4),
864                         snd_cs4236_ctrl_in(chip, 5),
865                         snd_cs4236_ctrl_in(chip, 6),
866                         snd_cs4236_ctrl_in(chip, 8));
867 #endif
868         return change;
869 }
870
871 static struct snd_kcontrol_new snd_cs4236_iec958_controls[] = {
872 CS4236_IEC958_ENABLE("IEC958 Output Enable", 0),
873 CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0),
874 CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0),
875 CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0),
876 CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0),
877 CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0)
878 };
879
880 static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4235[] = {
881 CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
882 CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1)
883 };
884
885 static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4237[] = {
886 CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0),
887 CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
888 CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1),
889 CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0),
890 CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
891 };
892
893 static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4238[] = {
894 CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
895 CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
896 CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1),
897 CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
898 };
899
900 int snd_cs4236_mixer(struct snd_cs4231 *chip)
901 {
902         struct snd_card *card;
903         unsigned int idx, count;
904         int err;
905         struct snd_kcontrol_new *kcontrol;
906
907         snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
908         card = chip->card;
909         strcpy(card->mixername, snd_cs4231_chip_id(chip));
910
911         if (chip->hardware == CS4231_HW_CS4235 ||
912             chip->hardware == CS4231_HW_CS4239) {
913                 for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) {
914                         if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0)
915                                 return err;
916                 }
917         } else {
918                 for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) {
919                         if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0)
920                                 return err;
921                 }
922         }
923         switch (chip->hardware) {
924         case CS4231_HW_CS4235:
925         case CS4231_HW_CS4239:
926                 count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235);
927                 kcontrol = snd_cs4236_3d_controls_cs4235;
928                 break;
929         case CS4231_HW_CS4237B:
930                 count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237);
931                 kcontrol = snd_cs4236_3d_controls_cs4237;
932                 break;
933         case CS4231_HW_CS4238B:
934                 count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238);
935                 kcontrol = snd_cs4236_3d_controls_cs4238;
936                 break;
937         default:
938                 count = 0;
939                 kcontrol = NULL;
940         }
941         for (idx = 0; idx < count; idx++, kcontrol++) {
942                 if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0)
943                         return err;
944         }
945         if (chip->hardware == CS4231_HW_CS4237B ||
946             chip->hardware == CS4231_HW_CS4238B) {
947                 for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) {
948                         if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0)
949                                 return err;
950                 }
951         }
952         return 0;
953 }
954
955 EXPORT_SYMBOL(snd_cs4236_create);
956 EXPORT_SYMBOL(snd_cs4236_pcm);
957 EXPORT_SYMBOL(snd_cs4236_mixer);
958
959 /*
960  *  INIT part
961  */
962
963 static int __init alsa_cs4236_init(void)
964 {
965         return 0;
966 }
967
968 static void __exit alsa_cs4236_exit(void)
969 {
970 }
971
972 module_init(alsa_cs4236_init)
973 module_exit(alsa_cs4236_exit)