2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
4 * Lowlevel functions for ONKYO WAVIO SE-90PCI and SE-200PCI
6 * Copyright (c) 2007 Shin-ya Okada sh_okada(at)d4.dion.ne.jp
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31 #include <sound/tlv.h>
38 /****************************************************************************/
39 /* ONKYO WAVIO SE-200PCI */
40 /****************************************************************************/
42 * system configuration ICE_EEP2_SYSCONF=0x4b
45 * one stereo ADC and a S/PDIF receiver connected
46 * four stereo DACs connected
48 * AC-Link configuration ICE_EEP2_ACLINK=0x80
49 * use I2C, not use AC97
51 * I2S converters feature ICE_EEP2_I2S=0x78
52 * I2S codec has no volume/mute control feature
53 * I2S codec supports 96KHz and 192KHz
56 * S/PDIF configuration ICE_EEP2_SPDIF=0xc3
57 * Enable integrated S/PDIF transmitter
58 * internal S/PDIF out implemented
60 * External S/PDIF out implemented
63 * ** connected chips **
66 * A 2ch-DAC of main outputs.
67 * It setuped as I2S mode by wire, so no way to setup from software.
68 * The sample-rate are automatically changed.
69 * ML/I2S (28pin) --------+
70 * MC/DM1 (27pin) -- 5V |
71 * MD/DM0 (26pin) -- GND |
72 * MUTEB (25pin) -- NC |
73 * MODE (24pin) -- GND |
74 * CSBIW (23pin) --------+
76 * RSTB (22pin) --R(1K)-+
77 * Probably it reduce the noise from the control line.
80 * A 6ch-DAC for surrounds.
81 * It's control wire was connected to GPIOxx (3-wire serial interface)
82 * ML/I2S (11pin) -- GPIO18
83 * MC/IWL (12pin) -- GPIO17
84 * MD/DM (13pin) -- GPIO16
85 * MUTE (14pin) -- GPIO01
88 * A 2ch-ADC(with 10ch-selector) plus 2ch-DAC.
89 * It's control wire was connected to SDA/SCLK (2-wire serial interface)
90 * MODE (16pin) -- R(1K) -- GND
91 * CE (17pin) -- R(1K) -- GND 2-wire mode (address=0x34)
96 * ** output pins and device names **
98 * 7.1ch name -- output connector color -- device (-D option)
100 * FRONT 2ch -- green -- plughw:0,0
101 * CENTER(Lch) SUBWOOFER(Rch) -- black -- plughw:0,2,0
102 * SURROUND 2ch -- orange -- plughw:0,2,1
103 * SURROUND BACK 2ch -- white -- plughw:0,2,2
108 /****************************************************************************/
109 /* WM8740 interface */
110 /****************************************************************************/
112 static void __devinit se200pci_WM8740_init(struct snd_ice1712 *ice)
118 static void se200pci_WM8740_set_pro_rate(struct snd_ice1712 *ice,
125 /****************************************************************************/
126 /* WM8766 interface */
127 /****************************************************************************/
129 static void se200pci_WM8766_write(struct snd_ice1712 *ice,
130 unsigned int addr, unsigned int data)
135 const unsigned int DATA = 0x010000;
136 const unsigned int CLOCK = 0x020000;
137 const unsigned int LOAD = 0x040000;
138 const unsigned int ALL_MASK = (DATA | CLOCK | LOAD);
140 snd_ice1712_save_gpio_status(ice);
142 st = ((addr & 0x7f) << 9) | (data & 0x1ff);
143 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction | ALL_MASK);
144 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask & ~ALL_MASK);
145 bits = snd_ice1712_gpio_read(ice) & ~ALL_MASK;
147 snd_ice1712_gpio_write(ice, bits);
148 for (i = 0; i < 16; i++) {
157 snd_ice1712_gpio_write(ice, bits);
161 snd_ice1712_gpio_write(ice, bits);
166 snd_ice1712_gpio_write(ice, bits);
169 bits |= (DATA | CLOCK);
170 snd_ice1712_gpio_write(ice, bits);
172 snd_ice1712_restore_gpio_status(ice);
175 static void se200pci_WM8766_set_volume(struct snd_ice1712 *ice, int ch,
176 unsigned int vol1, unsigned int vol2)
180 se200pci_WM8766_write(ice, 0x000, vol1);
181 se200pci_WM8766_write(ice, 0x001, vol2 | 0x100);
184 se200pci_WM8766_write(ice, 0x004, vol1);
185 se200pci_WM8766_write(ice, 0x005, vol2 | 0x100);
188 se200pci_WM8766_write(ice, 0x006, vol1);
189 se200pci_WM8766_write(ice, 0x007, vol2 | 0x100);
194 static void __devinit se200pci_WM8766_init(struct snd_ice1712 *ice)
196 se200pci_WM8766_write(ice, 0x1f, 0x000); /* RESET ALL */
199 se200pci_WM8766_set_volume(ice, 0, 0, 0); /* volume L=0 R=0 */
200 se200pci_WM8766_set_volume(ice, 1, 0, 0); /* volume L=0 R=0 */
201 se200pci_WM8766_set_volume(ice, 2, 0, 0); /* volume L=0 R=0 */
203 se200pci_WM8766_write(ice, 0x03, 0x022); /* serial mode I2S-24bits */
204 se200pci_WM8766_write(ice, 0x0a, 0x080); /* MCLK=256fs */
205 se200pci_WM8766_write(ice, 0x12, 0x000); /* MDP=0 */
206 se200pci_WM8766_write(ice, 0x15, 0x000); /* MDP=0 */
207 se200pci_WM8766_write(ice, 0x09, 0x000); /* demp=off mute=off */
209 se200pci_WM8766_write(ice, 0x02, 0x124); /* ch-assign L=L R=R RESET */
210 se200pci_WM8766_write(ice, 0x02, 0x120); /* ch-assign L=L R=R */
213 static void se200pci_WM8766_set_pro_rate(struct snd_ice1712 *ice,
217 se200pci_WM8766_write(ice, 0x0a, 0x000); /* MCLK=128fs */
219 se200pci_WM8766_write(ice, 0x0a, 0x080); /* MCLK=256fs */
223 /****************************************************************************/
224 /* WM8776 interface */
225 /****************************************************************************/
227 static void se200pci_WM8776_write(struct snd_ice1712 *ice,
228 unsigned int addr, unsigned int data)
232 val = (addr << 9) | data;
233 snd_vt1724_write_i2c(ice, 0x34, val >> 8, val & 0xff);
237 static void se200pci_WM8776_set_output_volume(struct snd_ice1712 *ice,
238 unsigned int vol1, unsigned int vol2)
240 se200pci_WM8776_write(ice, 0x03, vol1);
241 se200pci_WM8776_write(ice, 0x04, vol2 | 0x100);
244 static void se200pci_WM8776_set_input_volume(struct snd_ice1712 *ice,
245 unsigned int vol1, unsigned int vol2)
247 se200pci_WM8776_write(ice, 0x0e, vol1);
248 se200pci_WM8776_write(ice, 0x0f, vol2 | 0x100);
251 static const char *se200pci_sel[] = {
252 "LINE-IN", "CD-IN", "MIC-IN", "ALL-MIX", NULL
255 static void se200pci_WM8776_set_input_selector(struct snd_ice1712 *ice,
258 static unsigned char vals[] = {
259 /* LINE, CD, MIC, ALL, GND */
260 0x10, 0x04, 0x08, 0x1c, 0x03
264 se200pci_WM8776_write(ice, 0x15, vals[sel]);
267 static void se200pci_WM8776_set_afl(struct snd_ice1712 *ice, unsigned int afl)
269 /* AFL -- After Fader Listening */
271 se200pci_WM8776_write(ice, 0x16, 0x005);
273 se200pci_WM8776_write(ice, 0x16, 0x001);
276 static const char *se200pci_agc[] = {
277 "Off", "LimiterMode", "ALCMode", NULL
280 static void se200pci_WM8776_set_agc(struct snd_ice1712 *ice, unsigned int agc)
282 /* AGC -- Auto Gain Control of the input */
285 se200pci_WM8776_write(ice, 0x11, 0x000); /* Off */
288 se200pci_WM8776_write(ice, 0x10, 0x07b);
289 se200pci_WM8776_write(ice, 0x11, 0x100); /* LimiterMode */
292 se200pci_WM8776_write(ice, 0x10, 0x1fb);
293 se200pci_WM8776_write(ice, 0x11, 0x100); /* ALCMode */
298 static void __devinit se200pci_WM8776_init(struct snd_ice1712 *ice)
301 static unsigned short __devinitdata default_values[] = {
304 0x000, 0x090, 0x000, 0x000,
306 0x008, 0x0cf, 0x0cf, 0x07b, 0x000,
307 0x032, 0x000, 0x0a6, 0x001, 0x001
310 se200pci_WM8776_write(ice, 0x17, 0x000); /* reset all */
311 /* ADC and DAC interface is I2S 24bits mode */
312 /* The sample-rate are automatically changed */
314 /* BUT my board can not do reset all, so I load all by manually. */
315 for (i = 0; i < ARRAY_SIZE(default_values); i++)
316 se200pci_WM8776_write(ice, i, default_values[i]);
318 se200pci_WM8776_set_input_selector(ice, 0);
319 se200pci_WM8776_set_afl(ice, 0);
320 se200pci_WM8776_set_agc(ice, 0);
321 se200pci_WM8776_set_input_volume(ice, 0, 0);
322 se200pci_WM8776_set_output_volume(ice, 0, 0);
324 /* head phone mute and power down */
325 se200pci_WM8776_write(ice, 0x00, 0);
326 se200pci_WM8776_write(ice, 0x01, 0);
327 se200pci_WM8776_write(ice, 0x02, 0x100);
328 se200pci_WM8776_write(ice, 0x0d, 0x080);
331 static void se200pci_WM8776_set_pro_rate(struct snd_ice1712 *ice,
338 /****************************************************************************/
339 /* runtime interface */
340 /****************************************************************************/
342 static void se200pci_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate)
344 se200pci_WM8740_set_pro_rate(ice, rate);
345 se200pci_WM8766_set_pro_rate(ice, rate);
346 se200pci_WM8776_set_pro_rate(ice, rate);
349 struct se200pci_control {
359 enum { VOLUME1, VOLUME2, BOOLEAN, ENUM } type;
365 static const struct se200pci_control se200pci_cont[] = {
367 .name = "Front Playback Volume",
370 .comment = "Front(green)"
373 .name = "Side Playback Volume",
377 .comment = "Surround(orange)"
380 .name = "Surround Playback Volume",
384 .comment = "SurroundBack(white)"
387 .name = "CLFE Playback Volume",
391 .comment = "Center(Lch)&SubWoofer(Rch)(black)"
394 .name = "Capture Volume",
399 .name = "Capture Select",
402 .member = se200pci_sel
405 .name = "AGC Capture Mode",
408 .member = se200pci_agc
411 .name = "AFL Bypass Playback Switch",
417 static int se200pci_get_enum_count(int n)
422 member = se200pci_cont[n].member;
425 for (c = 0; member[c]; c++)
430 static int se200pci_cont_volume_info(struct snd_kcontrol *kc,
431 struct snd_ctl_elem_info *uinfo)
433 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
435 uinfo->value.integer.min = 0; /* mute */
436 uinfo->value.integer.max = 0xff; /* 0dB */
440 #define se200pci_cont_boolean_info snd_ctl_boolean_mono_info
442 static int se200pci_cont_enum_info(struct snd_kcontrol *kc,
443 struct snd_ctl_elem_info *uinfo)
447 n = kc->private_value;
448 c = se200pci_get_enum_count(n);
451 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
453 uinfo->value.enumerated.items = c;
454 if (uinfo->value.enumerated.item >= c)
455 uinfo->value.enumerated.item = c - 1;
456 strcpy(uinfo->value.enumerated.name,
457 se200pci_cont[n].member[uinfo->value.enumerated.item]);
461 static int se200pci_cont_volume_get(struct snd_kcontrol *kc,
462 struct snd_ctl_elem_value *uc)
464 struct snd_ice1712 *ice = snd_kcontrol_chip(kc);
465 int n = kc->private_value;
466 uc->value.integer.value[0] = ice->spec.se.vol[n].ch1;
467 uc->value.integer.value[1] = ice->spec.se.vol[n].ch2;
471 static int se200pci_cont_boolean_get(struct snd_kcontrol *kc,
472 struct snd_ctl_elem_value *uc)
474 struct snd_ice1712 *ice = snd_kcontrol_chip(kc);
475 int n = kc->private_value;
476 uc->value.integer.value[0] = ice->spec.se.vol[n].ch1;
480 static int se200pci_cont_enum_get(struct snd_kcontrol *kc,
481 struct snd_ctl_elem_value *uc)
483 struct snd_ice1712 *ice = snd_kcontrol_chip(kc);
484 int n = kc->private_value;
485 uc->value.enumerated.item[0] = ice->spec.se.vol[n].ch1;
489 static void se200pci_cont_update(struct snd_ice1712 *ice, int n)
491 switch (se200pci_cont[n].target) {
493 se200pci_WM8766_set_volume(ice,
495 ice->spec.se.vol[n].ch1,
496 ice->spec.se.vol[n].ch2);
500 se200pci_WM8776_set_input_volume(ice,
501 ice->spec.se.vol[n].ch1,
502 ice->spec.se.vol[n].ch2);
506 se200pci_WM8776_set_output_volume(ice,
507 ice->spec.se.vol[n].ch1,
508 ice->spec.se.vol[n].ch2);
512 se200pci_WM8776_set_input_selector(ice,
513 ice->spec.se.vol[n].ch1);
517 se200pci_WM8776_set_agc(ice, ice->spec.se.vol[n].ch1);
521 se200pci_WM8776_set_afl(ice, ice->spec.se.vol[n].ch1);
529 static int se200pci_cont_volume_put(struct snd_kcontrol *kc,
530 struct snd_ctl_elem_value *uc)
532 struct snd_ice1712 *ice = snd_kcontrol_chip(kc);
533 int n = kc->private_value;
534 unsigned int vol1, vol2;
538 vol1 = uc->value.integer.value[0] & 0xff;
539 vol2 = uc->value.integer.value[1] & 0xff;
540 if (ice->spec.se.vol[n].ch1 != vol1) {
541 ice->spec.se.vol[n].ch1 = vol1;
544 if (ice->spec.se.vol[n].ch2 != vol2) {
545 ice->spec.se.vol[n].ch2 = vol2;
549 se200pci_cont_update(ice, n);
554 static int se200pci_cont_boolean_put(struct snd_kcontrol *kc,
555 struct snd_ctl_elem_value *uc)
557 struct snd_ice1712 *ice = snd_kcontrol_chip(kc);
558 int n = kc->private_value;
561 vol1 = !!uc->value.integer.value[0];
562 if (ice->spec.se.vol[n].ch1 != vol1) {
563 ice->spec.se.vol[n].ch1 = vol1;
564 se200pci_cont_update(ice, n);
570 static int se200pci_cont_enum_put(struct snd_kcontrol *kc,
571 struct snd_ctl_elem_value *uc)
573 struct snd_ice1712 *ice = snd_kcontrol_chip(kc);
574 int n = kc->private_value;
577 vol1 = uc->value.enumerated.item[0];
578 if (vol1 >= se200pci_get_enum_count(n))
580 if (ice->spec.se.vol[n].ch1 != vol1) {
581 ice->spec.se.vol[n].ch1 = vol1;
582 se200pci_cont_update(ice, n);
588 static const DECLARE_TLV_DB_SCALE(db_scale_gain1, -12750, 50, 1);
589 static const DECLARE_TLV_DB_SCALE(db_scale_gain2, -10350, 50, 1);
591 static int __devinit se200pci_add_controls(struct snd_ice1712 *ice)
594 struct snd_kcontrol_new cont;
597 memset(&cont, 0, sizeof(cont));
598 cont.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
599 for (i = 0; i < ARRAY_SIZE(se200pci_cont); i++) {
600 cont.private_value = i;
601 cont.name = se200pci_cont[i].name;
602 cont.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
604 switch (se200pci_cont[i].type) {
607 cont.info = se200pci_cont_volume_info;
608 cont.get = se200pci_cont_volume_get;
609 cont.put = se200pci_cont_volume_put;
610 cont.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
611 if (se200pci_cont[i].type == VOLUME1)
612 cont.tlv.p = db_scale_gain1;
614 cont.tlv.p = db_scale_gain2;
617 cont.info = se200pci_cont_boolean_info;
618 cont.get = se200pci_cont_boolean_get;
619 cont.put = se200pci_cont_boolean_put;
622 cont.info = se200pci_cont_enum_info;
623 cont.get = se200pci_cont_enum_get;
624 cont.put = se200pci_cont_enum_put;
630 err = snd_ctl_add(ice->card, snd_ctl_new1(&cont, ice));
639 /****************************************************************************/
640 /* ONKYO WAVIO SE-90PCI */
641 /****************************************************************************/
643 * system configuration ICE_EEP2_SYSCONF=0x4b
644 * AC-Link configuration ICE_EEP2_ACLINK=0x80
645 * I2S converters feature ICE_EEP2_I2S=0x78
646 * S/PDIF configuration ICE_EEP2_SPDIF=0xc3
648 * ** connected chip **
651 * A 2ch-DAC of main outputs.
652 * It setuped as I2S mode by wire, so no way to setup from software.
653 * ML/I2S (28pin) -- +5V
654 * MC/DM1 (27pin) -- GND
655 * MC/DM0 (26pin) -- GND
656 * MUTEB (25pin) -- open (internal pull-up)
657 * MODE (24pin) -- GND
658 * CSBIWO (23pin) -- +5V
662 /* Nothing to do for this chip. */
665 /****************************************************************************/
666 /* probe/initialize/setup */
667 /****************************************************************************/
669 static int __devinit se_init(struct snd_ice1712 *ice)
671 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_SE90PCI) {
672 ice->num_total_dacs = 2;
673 ice->num_total_adcs = 0;
677 } else if (ice->eeprom.subvendor == VT1724_SUBDEVICE_SE200PCI) {
678 ice->num_total_dacs = 8;
679 ice->num_total_adcs = 2;
680 se200pci_WM8740_init(ice);
681 se200pci_WM8766_init(ice);
682 se200pci_WM8776_init(ice);
683 ice->gpio.set_pro_rate = se200pci_set_pro_rate;
690 static int __devinit se_add_controls(struct snd_ice1712 *ice)
695 /* nothing to do for VT1724_SUBDEVICE_SE90PCI */
696 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_SE200PCI)
697 err = se200pci_add_controls(ice);
703 /****************************************************************************/
705 /****************************************************************************/
707 static unsigned char se200pci_eeprom[] __devinitdata = {
708 [ICE_EEP2_SYSCONF] = 0x4b, /* 49.152Hz, spdif-in/ADC, 4DACs */
709 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
710 [ICE_EEP2_I2S] = 0x78, /* 96k-ok, 24bit, 192k-ok */
711 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
713 [ICE_EEP2_GPIO_DIR] = 0x02, /* WM8766 mute 1=output */
714 [ICE_EEP2_GPIO_DIR1] = 0x00, /* not used */
715 [ICE_EEP2_GPIO_DIR2] = 0x07, /* WM8766 ML/MC/MD 1=output */
717 [ICE_EEP2_GPIO_MASK] = 0x00, /* 0=writable */
718 [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0=writable */
719 [ICE_EEP2_GPIO_MASK2] = 0x00, /* 0=writable */
721 [ICE_EEP2_GPIO_STATE] = 0x00, /* WM8766 mute=0 */
722 [ICE_EEP2_GPIO_STATE1] = 0x00, /* not used */
723 [ICE_EEP2_GPIO_STATE2] = 0x07, /* WM8766 ML/MC/MD */
726 static unsigned char se90pci_eeprom[] __devinitdata = {
727 [ICE_EEP2_SYSCONF] = 0x4b, /* 49.152Hz, spdif-in/ADC, 4DACs */
728 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
729 [ICE_EEP2_I2S] = 0x78, /* 96k-ok, 24bit, 192k-ok */
730 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
732 /* ALL GPIO bits are in input mode */
735 struct snd_ice1712_card_info snd_vt1724_se_cards[] __devinitdata = {
737 .subvendor = VT1724_SUBDEVICE_SE200PCI,
738 .name = "ONKYO SE200PCI",
740 .chip_init = se_init,
741 .build_controls = se_add_controls,
742 .eeprom_size = sizeof(se200pci_eeprom),
743 .eeprom_data = se200pci_eeprom,
746 .subvendor = VT1724_SUBDEVICE_SE90PCI,
747 .name = "ONKYO SE90PCI",
749 .chip_init = se_init,
750 .build_controls = se_add_controls,
751 .eeprom_size = sizeof(se90pci_eeprom),
752 .eeprom_data = se90pci_eeprom,