aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/Kconfig33
-rw-r--r--sound/pci/ac97/ac97_codec.c41
-rw-r--r--sound/pci/ac97/ac97_patch.c210
-rw-r--r--sound/pci/ad1889.c6
-rw-r--r--sound/pci/ak4531_codec.c10
-rw-r--r--sound/pci/als4000.c391
-rw-r--r--sound/pci/atiixp.c13
-rw-r--r--sound/pci/atiixp_modem.c10
-rw-r--r--sound/pci/au88x0/au88x0.h7
-rw-r--r--sound/pci/au88x0/au88x0_core.c40
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c14
-rw-r--r--sound/pci/azt3328.c6
-rw-r--r--sound/pci/bt87x.c5
-rw-r--r--sound/pci/ca0106/ca0106_main.c2
-rw-r--r--sound/pci/ca0106/ca_midi.c20
-rw-r--r--sound/pci/cmipci.c9
-rw-r--r--sound/pci/cs4281.c13
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c91
-rw-r--r--sound/pci/cs46xx/dsp_spos.c51
-rw-r--r--sound/pci/cs46xx/dsp_spos_scb_lib.c115
-rw-r--r--sound/pci/echoaudio/darla20_dsp.c3
-rw-r--r--sound/pci/echoaudio/darla24_dsp.c8
-rw-r--r--sound/pci/echoaudio/echo3g_dsp.c9
-rw-r--r--sound/pci/echoaudio/echoaudio.c22
-rw-r--r--sound/pci/echoaudio/echoaudio_3g.c11
-rw-r--r--sound/pci/echoaudio/echoaudio_dsp.c21
-rw-r--r--sound/pci/echoaudio/echoaudio_gml.c6
-rw-r--r--sound/pci/echoaudio/gina20_dsp.c6
-rw-r--r--sound/pci/echoaudio/gina24_dsp.c11
-rw-r--r--sound/pci/echoaudio/indigo_dsp.c8
-rw-r--r--sound/pci/echoaudio/indigodj_dsp.c8
-rw-r--r--sound/pci/echoaudio/indigoio_dsp.c8
-rw-r--r--sound/pci/echoaudio/layla20_dsp.c9
-rw-r--r--sound/pci/echoaudio/layla24_dsp.c11
-rw-r--r--sound/pci/echoaudio/mia_dsp.c13
-rw-r--r--sound/pci/echoaudio/midi.c6
-rw-r--r--sound/pci/echoaudio/mona_dsp.c6
-rw-r--r--sound/pci/emu10k1/emu10k1_callback.c6
-rw-r--r--sound/pci/emu10k1/emu10k1_patch.c23
-rw-r--r--sound/pci/emu10k1/emu10k1x.c18
-rw-r--r--sound/pci/emu10k1/emufx.c6
-rw-r--r--sound/pci/emu10k1/emumpu401.c18
-rw-r--r--sound/pci/emu10k1/memory.c31
-rw-r--r--sound/pci/emu10k1/voice.c9
-rw-r--r--sound/pci/es1938.c3
-rw-r--r--sound/pci/es1968.c6
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_beep.c134
-rw-r--r--sound/pci/hda/hda_beep.h44
-rw-r--r--sound/pci/hda/hda_codec.c113
-rw-r--r--sound/pci/hda/hda_codec.h93
-rw-r--r--sound/pci/hda/hda_generic.c3
-rw-r--r--sound/pci/hda/hda_intel.c146
-rw-r--r--sound/pci/hda/hda_local.h24
-rw-r--r--sound/pci/hda/hda_patch.h2
-rw-r--r--sound/pci/hda/hda_proc.c25
-rw-r--r--sound/pci/hda/patch_analog.c96
-rw-r--r--sound/pci/hda/patch_atihdmi.c45
-rw-r--r--sound/pci/hda/patch_nvhdmi.c164
-rw-r--r--sound/pci/hda/patch_realtek.c1816
-rw-r--r--sound/pci/hda/patch_sigmatel.c1008
-rw-r--r--sound/pci/hda/patch_via.c1407
-rw-r--r--sound/pci/ice1712/ak4xxx.c3
-rw-r--r--sound/pci/ice1712/aureon.c699
-rw-r--r--sound/pci/ice1712/delta.c2
-rw-r--r--sound/pci/ice1712/delta.h1
-rw-r--r--sound/pci/ice1712/ews.c9
-rw-r--r--sound/pci/ice1712/ice1712.c240
-rw-r--r--sound/pci/ice1712/ice1712.h52
-rw-r--r--sound/pci/ice1712/ice1724.c188
-rw-r--r--sound/pci/ice1712/juli.c47
-rw-r--r--sound/pci/ice1712/phase.c277
-rw-r--r--sound/pci/ice1712/phase.h8
-rw-r--r--sound/pci/ice1712/pontis.c5
-rw-r--r--sound/pci/ice1712/revo.c25
-rw-r--r--sound/pci/ice1712/wtm.c104
-rw-r--r--sound/pci/ice1712/wtm.h4
-rw-r--r--sound/pci/intel8x0.c50
-rw-r--r--sound/pci/intel8x0m.c3
-rw-r--r--sound/pci/korg1212/korg1212.c9
-rw-r--r--sound/pci/maestro3.c10
-rw-r--r--sound/pci/mixart/mixart.c4
-rw-r--r--sound/pci/mixart/mixart_core.c18
-rw-r--r--sound/pci/mixart/mixart_hwdep.c19
-rw-r--r--sound/pci/mixart/mixart_mixer.c8
-rw-r--r--sound/pci/nm256/nm256.c15
-rw-r--r--sound/pci/oxygen/hifier.c15
-rw-r--r--sound/pci/oxygen/oxygen.c92
-rw-r--r--sound/pci/oxygen/oxygen.h103
-rw-r--r--sound/pci/oxygen/oxygen_io.c22
-rw-r--r--sound/pci/oxygen/oxygen_lib.c101
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c48
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c47
-rw-r--r--sound/pci/oxygen/virtuoso.c594
-rw-r--r--sound/pci/pcxhr/pcxhr.c6
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c27
-rw-r--r--sound/pci/pcxhr/pcxhr_hwdep.c15
-rw-r--r--sound/pci/riptide/riptide.c31
-rw-r--r--sound/pci/rme9652/hdsp.c25
-rw-r--r--sound/pci/rme9652/hdspm.c52
-rw-r--r--sound/pci/rme9652/rme9652.c23
-rw-r--r--sound/pci/sonicvibes.c10
-rw-r--r--sound/pci/trident/trident_main.c22
-rw-r--r--sound/pci/trident/trident_memory.c37
-rw-r--r--sound/pci/via82xx.c60
-rw-r--r--sound/pci/via82xx_modem.c8
-rw-r--r--sound/pci/vx222/vx222_ops.c12
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c21
108 files changed, 7512 insertions, 2154 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 31f52d3fc21f..7003711f4fcc 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -517,6 +517,14 @@ config SND_HDA_HWDEP
517 This interface can be used for out-of-band communication 517 This interface can be used for out-of-band communication
518 with codecs for debugging purposes. 518 with codecs for debugging purposes.
519 519
520config SND_HDA_INPUT_BEEP
521 bool "Support digital beep via input layer"
522 depends on SND_HDA_INTEL
523 depends on INPUT=y || INPUT=SND_HDA_INTEL
524 help
525 Say Y here to build a digital beep interface for HD-audio
526 driver. This interface is used to generate digital beeps.
527
520config SND_HDA_CODEC_REALTEK 528config SND_HDA_CODEC_REALTEK
521 bool "Build Realtek HD-audio codec support" 529 bool "Build Realtek HD-audio codec support"
522 depends on SND_HDA_INTEL 530 depends on SND_HDA_INTEL
@@ -557,6 +565,14 @@ config SND_HDA_CODEC_ATIHDMI
557 Say Y here to include ATI HDMI HD-audio codec support in 565 Say Y here to include ATI HDMI HD-audio codec support in
558 snd-hda-intel driver, such as ATI RS600 HDMI. 566 snd-hda-intel driver, such as ATI RS600 HDMI.
559 567
568config SND_HDA_CODEC_NVHDMI
569 bool "Build NVIDIA HDMI HD-audio codec support"
570 depends on SND_HDA_INTEL
571 default y
572 help
573 Say Y here to include NVIDIA HDMI HD-audio codec support in
574 snd-hda-intel driver, such as NVIDIA MCP78 HDMI.
575
560config SND_HDA_CODEC_CONEXANT 576config SND_HDA_CODEC_CONEXANT
561 bool "Build Conexant HD-audio codec support" 577 bool "Build Conexant HD-audio codec support"
562 depends on SND_HDA_INTEL 578 depends on SND_HDA_INTEL
@@ -649,8 +665,9 @@ config SND_ICE1712
649 665
650 Currently supported hardware is: M-Audio Delta 1010(LT), 666 Currently supported hardware is: M-Audio Delta 1010(LT),
651 DiO 2496, 66, 44, 410, Audiophile 24/96; Digigram VX442; 667 DiO 2496, 66, 44, 410, Audiophile 24/96; Digigram VX442;
652 TerraTec EWX 24/96, EWS 88MT, 88D, DMX 6Fire, Phase 88; 668 TerraTec EWX 24/96, EWS 88MT/D, DMX 6Fire, Phase 88;
653 Hoontech SoundTrack DSP 24/Value/Media7.1; Event EZ8. 669 Hoontech SoundTrack DSP 24/Value/Media7.1; Event EZ8;
670 Lionstracs Mediastation, Terrasoniq TS 88.
654 671
655 To compile this driver as a module, choose M here: the module 672 To compile this driver as a module, choose M here: the module
656 will be called snd-ice1712. 673 will be called snd-ice1712.
@@ -665,9 +682,12 @@ config SND_ICE1724
665 ICE/VT1724/1720 (Envy24HT/PT) chips. 682 ICE/VT1724/1720 (Envy24HT/PT) chips.
666 683
667 Currently supported hardware is: AMP AUDIO2000; M-Audio 684 Currently supported hardware is: AMP AUDIO2000; M-Audio
668 Revolution 7.1; TerraTec Aureon 5.1 Sky, 7.1 Space/Universe; 685 Revolution 5.1, 7.1, Audiophile 192; TerraTec Aureon 5.1 Sky,
669 AudioTrak Prodigy 7.1; Pontis MS300; Albatron K8X800 Pro II; 686 7.1 Space/Universe, Phase 22/28; Onkyo SE-90PCI, SE-200PCI;
670 Chaintech ZNF3-150/250. 687 AudioTrak Prodigy 192, 7.1 (HIFI/LT/XT), HD2; Hercules
688 Fortissimo IV; ESI Juli@; Pontis MS300; EGO-SYS WaveTerminal
689 192M; Albatron K8X800 Pro II; Chaintech ZNF3-150/250, 9CJS,
690 AV-710; Shuttle SN25P.
671 691
672 To compile this driver as a module, choose M here: the module 692 To compile this driver as a module, choose M here: the module
673 will be called snd-ice1724. 693 will be called snd-ice1724.
@@ -845,7 +865,8 @@ config SND_VIRTUOSO
845 select SND_OXYGEN_LIB 865 select SND_OXYGEN_LIB
846 help 866 help
847 Say Y here to include support for sound cards based on the 867 Say Y here to include support for sound cards based on the
848 Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2 and D2X. 868 Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X and
869 HDAV1.3 (Deluxe).
849 870
850 To compile this driver as a module, choose M here: the module 871 To compile this driver as a module, choose M here: the module
851 will be called snd-virtuoso. 872 will be called snd-virtuoso.
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 8c49a00a5e39..6704acbca8c0 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -67,8 +67,8 @@ struct ac97_codec_id {
67}; 67};
68 68
69static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = { 69static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = {
70{ 0x414b4d00, 0xffffff00, "Asahi Kasei", NULL, NULL },
71{ 0x41445300, 0xffffff00, "Analog Devices", NULL, NULL }, 70{ 0x41445300, 0xffffff00, "Analog Devices", NULL, NULL },
71{ 0x414b4d00, 0xffffff00, "Asahi Kasei", NULL, NULL },
72{ 0x414c4300, 0xffffff00, "Realtek", NULL, NULL }, 72{ 0x414c4300, 0xffffff00, "Realtek", NULL, NULL },
73{ 0x414c4700, 0xffffff00, "Realtek", NULL, NULL }, 73{ 0x414c4700, 0xffffff00, "Realtek", NULL, NULL },
74{ 0x434d4900, 0xffffff00, "C-Media Electronics", NULL, NULL }, 74{ 0x434d4900, 0xffffff00, "C-Media Electronics", NULL, NULL },
@@ -94,11 +94,6 @@ static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = {
94}; 94};
95 95
96static const struct ac97_codec_id snd_ac97_codec_ids[] = { 96static const struct ac97_codec_id snd_ac97_codec_ids[] = {
97{ 0x414b4d00, 0xffffffff, "AK4540", NULL, NULL },
98{ 0x414b4d01, 0xffffffff, "AK4542", NULL, NULL },
99{ 0x414b4d02, 0xffffffff, "AK4543", NULL, NULL },
100{ 0x414b4d06, 0xffffffff, "AK4544A", NULL, NULL },
101{ 0x414b4d07, 0xffffffff, "AK4545", NULL, NULL },
102{ 0x41445303, 0xffffffff, "AD1819", patch_ad1819, NULL }, 97{ 0x41445303, 0xffffffff, "AD1819", patch_ad1819, NULL },
103{ 0x41445340, 0xffffffff, "AD1881", patch_ad1881, NULL }, 98{ 0x41445340, 0xffffffff, "AD1881", patch_ad1881, NULL },
104{ 0x41445348, 0xffffffff, "AD1881A", patch_ad1881, NULL }, 99{ 0x41445348, 0xffffffff, "AD1881A", patch_ad1881, NULL },
@@ -112,20 +107,25 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
112{ 0x41445374, 0xffffffff, "AD1981B", patch_ad1981b, NULL }, 107{ 0x41445374, 0xffffffff, "AD1981B", patch_ad1981b, NULL },
113{ 0x41445375, 0xffffffff, "AD1985", patch_ad1985, NULL }, 108{ 0x41445375, 0xffffffff, "AD1985", patch_ad1985, NULL },
114{ 0x41445378, 0xffffffff, "AD1986", patch_ad1986, NULL }, 109{ 0x41445378, 0xffffffff, "AD1986", patch_ad1986, NULL },
110{ 0x414b4d00, 0xffffffff, "AK4540", NULL, NULL },
111{ 0x414b4d01, 0xffffffff, "AK4542", NULL, NULL },
112{ 0x414b4d02, 0xffffffff, "AK4543", NULL, NULL },
113{ 0x414b4d06, 0xffffffff, "AK4544A", NULL, NULL },
114{ 0x414b4d07, 0xffffffff, "AK4545", NULL, NULL },
115{ 0x414c4300, 0xffffff00, "ALC100,100P", NULL, NULL }, 115{ 0x414c4300, 0xffffff00, "ALC100,100P", NULL, NULL },
116{ 0x414c4710, 0xfffffff0, "ALC200,200P", NULL, NULL }, 116{ 0x414c4710, 0xfffffff0, "ALC200,200P", NULL, NULL },
117{ 0x414c4721, 0xffffffff, "ALC650D", NULL, NULL }, /* already patched */ 117{ 0x414c4721, 0xffffffff, "ALC650D", NULL, NULL }, /* already patched */
118{ 0x414c4722, 0xffffffff, "ALC650E", NULL, NULL }, /* already patched */ 118{ 0x414c4722, 0xffffffff, "ALC650E", NULL, NULL }, /* already patched */
119{ 0x414c4723, 0xffffffff, "ALC650F", NULL, NULL }, /* already patched */ 119{ 0x414c4723, 0xffffffff, "ALC650F", NULL, NULL }, /* already patched */
120{ 0x414c4720, 0xfffffff0, "ALC650", patch_alc650, NULL }, 120{ 0x414c4720, 0xfffffff0, "ALC650", patch_alc650, NULL },
121{ 0x414c4730, 0xffffffff, "ALC101", NULL, NULL },
122{ 0x414c4740, 0xfffffff0, "ALC202", NULL, NULL },
123{ 0x414c4750, 0xfffffff0, "ALC250", NULL, NULL },
121{ 0x414c4760, 0xfffffff0, "ALC655", patch_alc655, NULL }, 124{ 0x414c4760, 0xfffffff0, "ALC655", patch_alc655, NULL },
125{ 0x414c4770, 0xfffffff0, "ALC203", patch_alc203, NULL },
122{ 0x414c4781, 0xffffffff, "ALC658D", NULL, NULL }, /* already patched */ 126{ 0x414c4781, 0xffffffff, "ALC658D", NULL, NULL }, /* already patched */
123{ 0x414c4780, 0xfffffff0, "ALC658", patch_alc655, NULL }, 127{ 0x414c4780, 0xfffffff0, "ALC658", patch_alc655, NULL },
124{ 0x414c4790, 0xfffffff0, "ALC850", patch_alc850, NULL }, 128{ 0x414c4790, 0xfffffff0, "ALC850", patch_alc850, NULL },
125{ 0x414c4730, 0xffffffff, "ALC101", NULL, NULL },
126{ 0x414c4740, 0xfffffff0, "ALC202", NULL, NULL },
127{ 0x414c4750, 0xfffffff0, "ALC250", NULL, NULL },
128{ 0x414c4770, 0xfffffff0, "ALC203", NULL, NULL },
129{ 0x434d4941, 0xffffffff, "CMI9738", patch_cm9738, NULL }, 129{ 0x434d4941, 0xffffffff, "CMI9738", patch_cm9738, NULL },
130{ 0x434d4961, 0xffffffff, "CMI9739", patch_cm9739, NULL }, 130{ 0x434d4961, 0xffffffff, "CMI9739", patch_cm9739, NULL },
131{ 0x434d4969, 0xffffffff, "CMI9780", patch_cm9780, NULL }, 131{ 0x434d4969, 0xffffffff, "CMI9780", patch_cm9780, NULL },
@@ -168,7 +168,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
168{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL }, 168{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL },
169{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF 169{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF
170{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF 170{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF
171{ 0x56494182, 0xffffffff, "VIA1618", NULL, NULL }, 171{ 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL },
172{ 0x57454301, 0xffffffff, "W83971D", NULL, NULL }, 172{ 0x57454301, 0xffffffff, "W83971D", NULL, NULL },
173{ 0x574d4c00, 0xffffffff, "WM9701,WM9701A", NULL, NULL }, 173{ 0x574d4c00, 0xffffffff, "WM9701,WM9701A", NULL, NULL },
174{ 0x574d4C03, 0xffffffff, "WM9703,WM9707,WM9708,WM9717", patch_wolfson03, NULL}, 174{ 0x574d4C03, 0xffffffff, "WM9703,WM9707,WM9708,WM9717", patch_wolfson03, NULL},
@@ -1890,8 +1890,8 @@ int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
1890 .dev_free = snd_ac97_bus_dev_free, 1890 .dev_free = snd_ac97_bus_dev_free,
1891 }; 1891 };
1892 1892
1893 snd_assert(card != NULL, return -EINVAL); 1893 if (snd_BUG_ON(!card))
1894 snd_assert(rbus != NULL, return -EINVAL); 1894 return -EINVAL;
1895 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 1895 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
1896 if (bus == NULL) 1896 if (bus == NULL)
1897 return -ENOMEM; 1897 return -ENOMEM;
@@ -1906,7 +1906,8 @@ int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
1906 snd_ac97_bus_free(bus); 1906 snd_ac97_bus_free(bus);
1907 return err; 1907 return err;
1908 } 1908 }
1909 *rbus = bus; 1909 if (rbus)
1910 *rbus = bus;
1910 return 0; 1911 return 0;
1911} 1912}
1912 1913
@@ -1991,10 +1992,14 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
1991 .dev_disconnect = snd_ac97_dev_disconnect, 1992 .dev_disconnect = snd_ac97_dev_disconnect,
1992 }; 1993 };
1993 1994
1994 snd_assert(rac97 != NULL, return -EINVAL); 1995 if (rac97)
1995 *rac97 = NULL; 1996 *rac97 = NULL;
1996 snd_assert(bus != NULL && template != NULL, return -EINVAL); 1997 if (snd_BUG_ON(!bus || !template))
1997 snd_assert(template->num < 4 && bus->codec[template->num] == NULL, return -EINVAL); 1998 return -EINVAL;
1999 if (snd_BUG_ON(template->num >= 4))
2000 return -EINVAL;
2001 if (bus->codec[template->num])
2002 return -EBUSY;
1998 2003
1999 card = bus->card; 2004 card = bus->card;
2000 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL); 2005 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index f4fbc795ee81..6e831aff1bd0 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -476,7 +476,7 @@ static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
476} 476}
477 477
478/* 478/*
479 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com> 479 * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk>
480 * removed broken wolfson00 patch. 480 * removed broken wolfson00 patch.
481 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. 481 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
482 */ 482 */
@@ -2560,6 +2560,14 @@ static int patch_ad1986(struct snd_ac97 * ac97)
2560 return 0; 2560 return 0;
2561} 2561}
2562 2562
2563/*
2564 * realtek ALC203: use mono-out for pin 37
2565 */
2566static int patch_alc203(struct snd_ac97 *ac97)
2567{
2568 snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
2569 return 0;
2570}
2563 2571
2564/* 2572/*
2565 * realtek ALC65x/850 codecs 2573 * realtek ALC65x/850 codecs
@@ -3457,7 +3465,7 @@ static int patch_vt1616(struct snd_ac97 * ac97)
3457 3465
3458/* 3466/*
3459 * unfortunately, the vt1617a stashes the twiddlers required for 3467 * unfortunately, the vt1617a stashes the twiddlers required for
3460 * nooding the i/o jacks on 2 different regs. * thameans that we cant 3468 * noodling the i/o jacks on 2 different regs. that means that we can't
3461 * use the easy way provided by AC97_ENUM_DOUBLE() we have to write 3469 * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3462 * are own funcs. 3470 * are own funcs.
3463 * 3471 *
@@ -3490,7 +3498,7 @@ static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3490 3498
3491 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3499 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3492 3500
3493 /* grab our desirec bits, then mash them together in a manner 3501 /* grab our desired bits, then mash them together in a manner
3494 * consistent with Table 6 on page 17 in the 1617a docs */ 3502 * consistent with Table 6 on page 17 in the 1617a docs */
3495 3503
3496 usSM51 = snd_ac97_read(pac97, 0x7a) >> 14; 3504 usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
@@ -3540,7 +3548,7 @@ static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3540 }, 3548 },
3541}; 3549};
3542 3550
3543int patch_vt1617a(struct snd_ac97 * ac97) 3551static int patch_vt1617a(struct snd_ac97 * ac97)
3544{ 3552{
3545 int err = 0; 3553 int err = 0;
3546 int val; 3554 int val;
@@ -3568,6 +3576,200 @@ int patch_vt1617a(struct snd_ac97 * ac97)
3568 return err; 3576 return err;
3569} 3577}
3570 3578
3579/* VIA VT1618 8 CHANNEL AC97 CODEC
3580 *
3581 * VIA implements 'Smart 5.1' completely differently on the 1618 than
3582 * it does on the 1617a. awesome! They seem to have sourced this
3583 * particular revision of the technology from somebody else, it's
3584 * called Universal Audio Jack and it shows up on some other folk's chips
3585 * as well.
3586 *
3587 * ordering in this list reflects vt1618 docs for Reg 60h and
3588 * the block diagram, DACs are as follows:
3589 *
3590 * OUT_O -> Front,
3591 * OUT_1 -> Surround,
3592 * OUT_2 -> C/LFE
3593 *
3594 * Unlike the 1617a, each OUT has a consistent set of mappings
3595 * for all bitpatterns other than 00:
3596 *
3597 * 01 Unmixed Output
3598 * 10 Line In
3599 * 11 Mic In
3600 *
3601 * Special Case of 00:
3602 *
3603 * OUT_0 Mixed Output
3604 * OUT_1 Reserved
3605 * OUT_2 Reserved
3606 *
3607 * I have no idea what the hell Reserved does, but on an MSI
3608 * CN700T, i have to set it to get 5.1 output - YMMV, bad
3609 * shit may happen.
3610 *
3611 * If other chips use Universal Audio Jack, then this code might be applicable
3612 * to them.
3613 */
3614
3615struct vt1618_uaj_item {
3616 unsigned short mask;
3617 unsigned short shift;
3618 const char *items[4];
3619};
3620
3621/* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
3622
3623static struct vt1618_uaj_item vt1618_uaj[3] = {
3624 {
3625 /* speaker jack */
3626 .mask = 0x03,
3627 .shift = 0,
3628 .items = {
3629 "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
3630 }
3631 },
3632 {
3633 /* line jack */
3634 .mask = 0x0c,
3635 .shift = 2,
3636 .items = {
3637 "Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
3638 }
3639 },
3640 {
3641 /* mic jack */
3642 .mask = 0x30,
3643 .shift = 4,
3644 .items = {
3645 "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
3646 },
3647 },
3648};
3649
3650static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
3651 struct snd_ctl_elem_info *uinfo)
3652{
3653 return ac97_enum_text_info(kcontrol, uinfo,
3654 vt1618_uaj[kcontrol->private_value].items,
3655 4);
3656}
3657
3658/* All of the vt1618 Universal Audio Jack twiddlers are on
3659 * Vendor Defined Register 0x60, page 0. The bits, and thus
3660 * the mask, are the only thing that changes
3661 */
3662static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
3663 struct snd_ctl_elem_value *ucontrol)
3664{
3665 unsigned short datpag, uaj;
3666 struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
3667
3668 mutex_lock(&pac97->page_mutex);
3669
3670 datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
3671 snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
3672
3673 uaj = snd_ac97_read(pac97, 0x60) &
3674 vt1618_uaj[kcontrol->private_value].mask;
3675
3676 snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
3677 mutex_unlock(&pac97->page_mutex);
3678
3679 ucontrol->value.enumerated.item[0] = uaj >>
3680 vt1618_uaj[kcontrol->private_value].shift;
3681
3682 return 0;
3683}
3684
3685static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
3686 struct snd_ctl_elem_value *ucontrol)
3687{
3688 return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
3689 vt1618_uaj[kcontrol->private_value].mask,
3690 ucontrol->value.enumerated.item[0]<<
3691 vt1618_uaj[kcontrol->private_value].shift,
3692 0);
3693}
3694
3695/* config aux in jack - not found on 3 jack motherboards or soundcards */
3696
3697static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
3698 struct snd_ctl_elem_info *uinfo)
3699{
3700 static const char *txt_aux[] = {"Aux In", "Back Surr Out"};
3701
3702 return ac97_enum_text_info(kcontrol, uinfo, txt_aux, 2);
3703}
3704
3705static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
3706 struct snd_ctl_elem_value *ucontrol)
3707{
3708 ucontrol->value.enumerated.item[0] =
3709 (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
3710 return 0;
3711}
3712
3713static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
3714 struct snd_ctl_elem_value *ucontrol)
3715{
3716 /* toggle surround rear dac power */
3717
3718 snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
3719 ucontrol->value.enumerated.item[0] << 3);
3720
3721 /* toggle aux in surround rear out jack */
3722
3723 return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
3724 ucontrol->value.enumerated.item[0] << 3);
3725}
3726
3727static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
3728 AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0),
3729 AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0),
3730 AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1),
3731 AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1),
3732 AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1),
3733 AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1),
3734 {
3735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3736 .name = "Speaker Jack Mode",
3737 .info = snd_ac97_vt1618_UAJ_info,
3738 .get = snd_ac97_vt1618_UAJ_get,
3739 .put = snd_ac97_vt1618_UAJ_put,
3740 .private_value = 0
3741 },
3742 {
3743 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3744 .name = "Line Jack Mode",
3745 .info = snd_ac97_vt1618_UAJ_info,
3746 .get = snd_ac97_vt1618_UAJ_get,
3747 .put = snd_ac97_vt1618_UAJ_put,
3748 .private_value = 1
3749 },
3750 {
3751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3752 .name = "Mic Jack Mode",
3753 .info = snd_ac97_vt1618_UAJ_info,
3754 .get = snd_ac97_vt1618_UAJ_get,
3755 .put = snd_ac97_vt1618_UAJ_put,
3756 .private_value = 2
3757 },
3758 {
3759 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3760 .name = "Aux Jack Mode",
3761 .info = snd_ac97_vt1618_aux_info,
3762 .get = snd_ac97_vt1618_aux_get,
3763 .put = snd_ac97_vt1618_aux_put,
3764 }
3765};
3766
3767static int patch_vt1618(struct snd_ac97 *ac97)
3768{
3769 return patch_build_controls(ac97, snd_ac97_controls_vt1618,
3770 ARRAY_SIZE(snd_ac97_controls_vt1618));
3771}
3772
3571/* 3773/*
3572 */ 3774 */
3573static void it2646_update_jacks(struct snd_ac97 *ac97) 3775static void it2646_update_jacks(struct snd_ac97 *ac97)
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index 39ec55b57b1e..92f3a976ef2e 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -549,7 +549,8 @@ snd_ad1889_playback_pointer(struct snd_pcm_substream *ss)
549 ptr = ad1889_readl(chip, AD_DMA_WAVCA); 549 ptr = ad1889_readl(chip, AD_DMA_WAVCA);
550 ptr -= chip->wave.addr; 550 ptr -= chip->wave.addr;
551 551
552 snd_assert((ptr >= 0) && (ptr < chip->wave.size), return 0); 552 if (snd_BUG_ON(ptr >= chip->wave.size))
553 return 0;
553 554
554 return bytes_to_frames(ss->runtime, ptr); 555 return bytes_to_frames(ss->runtime, ptr);
555} 556}
@@ -567,7 +568,8 @@ snd_ad1889_capture_pointer(struct snd_pcm_substream *ss)
567 ptr = ad1889_readl(chip, AD_DMA_ADCCA); 568 ptr = ad1889_readl(chip, AD_DMA_ADCCA);
568 ptr -= chip->ramc.addr; 569 ptr -= chip->ramc.addr;
569 570
570 snd_assert((ptr >= 0) && (ptr < chip->ramc.size), return 0); 571 if (snd_BUG_ON(ptr >= chip->ramc.size))
572 return 0;
571 573
572 return bytes_to_frames(ss->runtime, ptr); 574 return bytes_to_frames(ss->runtime, ptr);
573} 575}
diff --git a/sound/pci/ak4531_codec.c b/sound/pci/ak4531_codec.c
index 33d37b1c42fc..0f819ddb3ebf 100644
--- a/sound/pci/ak4531_codec.c
+++ b/sound/pci/ak4531_codec.c
@@ -392,9 +392,10 @@ int __devinit snd_ak4531_mixer(struct snd_card *card,
392 .dev_free = snd_ak4531_dev_free, 392 .dev_free = snd_ak4531_dev_free,
393 }; 393 };
394 394
395 snd_assert(rak4531 != NULL, return -EINVAL); 395 if (snd_BUG_ON(!card || !_ak4531))
396 *rak4531 = NULL; 396 return -EINVAL;
397 snd_assert(card != NULL && _ak4531 != NULL, return -EINVAL); 397 if (rak4531)
398 *rak4531 = NULL;
398 ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL); 399 ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL);
399 if (ak4531 == NULL) 400 if (ak4531 == NULL)
400 return -ENOMEM; 401 return -ENOMEM;
@@ -428,7 +429,8 @@ int __devinit snd_ak4531_mixer(struct snd_card *card,
428#if 0 429#if 0
429 snd_ak4531_dump(ak4531); 430 snd_ak4531_dump(ak4531);
430#endif 431#endif
431 *rak4531 = ak4531; 432 if (rak4531)
433 *rak4531 = ak4531;
432 return 0; 434 return 0;
433} 435}
434 436
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index 27ce6136ab00..ba570053d4d5 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -2,7 +2,7 @@
2 * card-als4000.c - driver for Avance Logic ALS4000 based soundcards. 2 * card-als4000.c - driver for Avance Logic ALS4000 based soundcards.
3 * Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>, 3 * Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>,
4 * Jaroslav Kysela <perex@perex.cz> 4 * Jaroslav Kysela <perex@perex.cz>
5 * Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com> 5 * Copyright (C) 2002, 2008 by Andreas Mohr <hw7oshyuv3001@sneakemail.com>
6 * 6 *
7 * Framework borrowed from Massimo Piccioni's card-als100.c. 7 * Framework borrowed from Massimo Piccioni's card-als100.c.
8 * 8 *
@@ -27,8 +27,10 @@
27 * bought an ALS4000 based soundcard, I was forced to base this driver 27 * bought an ALS4000 based soundcard, I was forced to base this driver
28 * on reverse engineering. 28 * on reverse engineering.
29 * 29 *
30 * Note: this is no longer true. Pretty verbose chip docu (ALS4000a.PDF) 30 * Note: this is no longer true (thank you!):
31 * can be found on the ALSA web site. 31 * pretty verbose chip docu (ALS4000a.PDF) can be found on the ALSA web site.
32 * Page numbers stated anywhere below with the "SPECS_PAGE:" tag
33 * refer to: ALS4000a.PDF specs Ver 1.0, May 28th, 1998.
32 * 34 *
33 * The ALS4000 seems to be the PCI-cousin of the ALS100. It contains an 35 * The ALS4000 seems to be the PCI-cousin of the ALS100. It contains an
34 * ALS100-like SB DSP/mixer, an OPL3 synth, a MPU401 and a gameport 36 * ALS100-like SB DSP/mixer, an OPL3 synth, a MPU401 and a gameport
@@ -59,7 +61,7 @@
59 * - value -> some port 0x0c0d 61 * - value -> some port 0x0c0d
60 * 62 *
61 * ToDo: 63 * ToDo:
62 * - Proper shared IRQ handling? 64 * - by default, don't enable legacy game and use PCI game I/O
63 * - power management? (card can do voice wakeup according to datasheet!!) 65 * - power management? (card can do voice wakeup according to datasheet!!)
64 */ 66 */
65 67
@@ -78,7 +80,7 @@
78#include <sound/sb.h> 80#include <sound/sb.h>
79#include <sound/initval.h> 81#include <sound/initval.h>
80 82
81MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>"); 83MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>, Andreas Mohr");
82MODULE_DESCRIPTION("Avance Logic ALS4000"); 84MODULE_DESCRIPTION("Avance Logic ALS4000");
83MODULE_LICENSE("GPL"); 85MODULE_LICENSE("GPL");
84MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}"); 86MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}");
@@ -107,7 +109,7 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0
107 109
108struct snd_card_als4000 { 110struct snd_card_als4000 {
109 /* most frequent access first */ 111 /* most frequent access first */
110 unsigned long gcr; 112 unsigned long iobase;
111 struct pci_dev *pci; 113 struct pci_dev *pci;
112 struct snd_sb *chip; 114 struct snd_sb *chip;
113#ifdef SUPPORT_JOYSTICK 115#ifdef SUPPORT_JOYSTICK
@@ -122,28 +124,168 @@ static struct pci_device_id snd_als4000_ids[] = {
122 124
123MODULE_DEVICE_TABLE(pci, snd_als4000_ids); 125MODULE_DEVICE_TABLE(pci, snd_als4000_ids);
124 126
125static inline void snd_als4000_gcr_write_addr(unsigned long port, u32 reg, u32 val) 127enum als4k_iobase_t {
128 /* IOx: B == Byte, W = Word, D = DWord; SPECS_PAGE: 37 */
129 ALS4K_IOD_00_AC97_ACCESS = 0x00,
130 ALS4K_IOW_04_AC97_READ = 0x04,
131 ALS4K_IOB_06_AC97_STATUS = 0x06,
132 ALS4K_IOB_07_IRQSTATUS = 0x07,
133 ALS4K_IOD_08_GCR_DATA = 0x08,
134 ALS4K_IOB_0C_GCR_INDEX = 0x0c,
135 ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU = 0x0e,
136 ALS4K_IOB_10_ADLIB_ADDR0 = 0x10,
137 ALS4K_IOB_11_ADLIB_ADDR1 = 0x11,
138 ALS4K_IOB_12_ADLIB_ADDR2 = 0x12,
139 ALS4K_IOB_13_ADLIB_ADDR3 = 0x13,
140 ALS4K_IOB_14_MIXER_INDEX = 0x14,
141 ALS4K_IOB_15_MIXER_DATA = 0x15,
142 ALS4K_IOB_16_ESP_RESET = 0x16,
143 ALS4K_IOB_16_ACK_FOR_CR1E = 0x16, /* 2nd function */
144 ALS4K_IOB_18_OPL_ADDR0 = 0x18,
145 ALS4K_IOB_19_OPL_ADDR1 = 0x19,
146 ALS4K_IOB_1A_ESP_RD_DATA = 0x1a,
147 ALS4K_IOB_1C_ESP_CMD_DATA = 0x1c,
148 ALS4K_IOB_1C_ESP_WR_STATUS = 0x1c, /* 2nd function */
149 ALS4K_IOB_1E_ESP_RD_STATUS8 = 0x1e,
150 ALS4K_IOB_1F_ESP_RD_STATUS16 = 0x1f,
151 ALS4K_IOB_20_ESP_GAMEPORT_200 = 0x20,
152 ALS4K_IOB_21_ESP_GAMEPORT_201 = 0x21,
153 ALS4K_IOB_30_MIDI_DATA = 0x30,
154 ALS4K_IOB_31_MIDI_STATUS = 0x31,
155 ALS4K_IOB_31_MIDI_COMMAND = 0x31, /* 2nd function */
156};
157
158enum als4k_iobase_0e_t {
159 ALS4K_IOB_0E_MPU_IRQ = 0x10,
160 ALS4K_IOB_0E_CR1E_IRQ = 0x40,
161 ALS4K_IOB_0E_SB_DMA_IRQ = 0x80,
162};
163
164enum als4k_gcr_t { /* all registers 32bit wide; SPECS_PAGE: 38 to 42 */
165 ALS4K_GCR8C_MISC_CTRL = 0x8c,
166 ALS4K_GCR90_TEST_MODE_REG = 0x90,
167 ALS4K_GCR91_DMA0_ADDR = 0x91,
168 ALS4K_GCR92_DMA0_MODE_COUNT = 0x92,
169 ALS4K_GCR93_DMA1_ADDR = 0x93,
170 ALS4K_GCR94_DMA1_MODE_COUNT = 0x94,
171 ALS4K_GCR95_DMA3_ADDR = 0x95,
172 ALS4K_GCR96_DMA3_MODE_COUNT = 0x96,
173 ALS4K_GCR99_DMA_EMULATION_CTRL = 0x99,
174 ALS4K_GCRA0_FIFO1_CURRENT_ADDR = 0xa0,
175 ALS4K_GCRA1_FIFO1_STATUS_BYTECOUNT = 0xa1,
176 ALS4K_GCRA2_FIFO2_PCIADDR = 0xa2,
177 ALS4K_GCRA3_FIFO2_COUNT = 0xa3,
178 ALS4K_GCRA4_FIFO2_CURRENT_ADDR = 0xa4,
179 ALS4K_GCRA5_FIFO1_STATUS_BYTECOUNT = 0xa5,
180 ALS4K_GCRA6_PM_CTRL = 0xa6,
181 ALS4K_GCRA7_PCI_ACCESS_STORAGE = 0xa7,
182 ALS4K_GCRA8_LEGACY_CFG1 = 0xa8,
183 ALS4K_GCRA9_LEGACY_CFG2 = 0xa9,
184 ALS4K_GCRFF_DUMMY_SCRATCH = 0xff,
185};
186
187enum als4k_gcr8c_t {
188 ALS4K_GCR8C_IRQ_MASK_CTRL_ENABLE = 0x8000,
189 ALS4K_GCR8C_CHIP_REV_MASK = 0xf0000
190};
191
192static inline void snd_als4k_iobase_writeb(unsigned long iobase,
193 enum als4k_iobase_t reg,
194 u8 val)
195{
196 outb(val, iobase + reg);
197}
198
199static inline void snd_als4k_iobase_writel(unsigned long iobase,
200 enum als4k_iobase_t reg,
201 u32 val)
202{
203 outl(val, iobase + reg);
204}
205
206static inline u8 snd_als4k_iobase_readb(unsigned long iobase,
207 enum als4k_iobase_t reg)
208{
209 return inb(iobase + reg);
210}
211
212static inline u32 snd_als4k_iobase_readl(unsigned long iobase,
213 enum als4k_iobase_t reg)
214{
215 return inl(iobase + reg);
216}
217
218static inline void snd_als4k_gcr_write_addr(unsigned long iobase,
219 enum als4k_gcr_t reg,
220 u32 val)
126{ 221{
127 outb(reg, port+0x0c); 222 snd_als4k_iobase_writeb(iobase, ALS4K_IOB_0C_GCR_INDEX, reg);
128 outl(val, port+0x08); 223 snd_als4k_iobase_writel(iobase, ALS4K_IOD_08_GCR_DATA, val);
129} 224}
130 225
131static inline void snd_als4000_gcr_write(struct snd_sb *sb, u32 reg, u32 val) 226static inline void snd_als4k_gcr_write(struct snd_sb *sb,
227 enum als4k_gcr_t reg,
228 u32 val)
132{ 229{
133 snd_als4000_gcr_write_addr(sb->alt_port, reg, val); 230 snd_als4k_gcr_write_addr(sb->alt_port, reg, val);
134} 231}
135 232
136static inline u32 snd_als4000_gcr_read_addr(unsigned long port, u32 reg) 233static inline u32 snd_als4k_gcr_read_addr(unsigned long iobase,
234 enum als4k_gcr_t reg)
137{ 235{
138 outb(reg, port+0x0c); 236 /* SPECS_PAGE: 37/38 */
139 return inl(port+0x08); 237 snd_als4k_iobase_writeb(iobase, ALS4K_IOB_0C_GCR_INDEX, reg);
238 return snd_als4k_iobase_readl(iobase, ALS4K_IOD_08_GCR_DATA);
140} 239}
141 240
142static inline u32 snd_als4000_gcr_read(struct snd_sb *sb, u32 reg) 241static inline u32 snd_als4k_gcr_read(struct snd_sb *sb, enum als4k_gcr_t reg)
143{ 242{
144 return snd_als4000_gcr_read_addr(sb->alt_port, reg); 243 return snd_als4k_gcr_read_addr(sb->alt_port, reg);
145} 244}
146 245
246enum als4k_cr_t { /* all registers 8bit wide; SPECS_PAGE: 20 to 23 */
247 ALS4K_CR0_SB_CONFIG = 0x00,
248 ALS4K_CR2_MISC_CONTROL = 0x02,
249 ALS4K_CR3_CONFIGURATION = 0x03,
250 ALS4K_CR17_FIFO_STATUS = 0x17,
251 ALS4K_CR18_ESP_MAJOR_VERSION = 0x18,
252 ALS4K_CR19_ESP_MINOR_VERSION = 0x19,
253 ALS4K_CR1A_MPU401_UART_MODE_CONTROL = 0x1a,
254 ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO = 0x1c,
255 ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI = 0x1d,
256 ALS4K_CR1E_FIFO2_CONTROL = 0x1e, /* secondary PCM FIFO (recording) */
257 ALS4K_CR3A_MISC_CONTROL = 0x3a,
258 ALS4K_CR3B_CRC32_BYTE0 = 0x3b, /* for testing, activate via CR3A */
259 ALS4K_CR3C_CRC32_BYTE1 = 0x3c,
260 ALS4K_CR3D_CRC32_BYTE2 = 0x3d,
261 ALS4K_CR3E_CRC32_BYTE3 = 0x3e,
262};
263
264enum als4k_cr0_t {
265 ALS4K_CR0_DMA_CONTIN_MODE_CTRL = 0x02, /* IRQ/FIFO controlled for 0/1 */
266 ALS4K_CR0_DMA_90H_MODE_CTRL = 0x04, /* IRQ/FIFO controlled for 0/1 */
267 ALS4K_CR0_MX80_81_REG_WRITE_ENABLE = 0x80,
268};
269
270static inline void snd_als4_cr_write(struct snd_sb *chip,
271 enum als4k_cr_t reg,
272 u8 data)
273{
274 /* Control Register is reg | 0xc0 (bit 7, 6 set) on sbmixer_index
275 * NOTE: assumes chip->mixer_lock to be locked externally already!
276 * SPECS_PAGE: 6 */
277 snd_sbmixer_write(chip, reg | 0xc0, data);
278}
279
280static inline u8 snd_als4_cr_read(struct snd_sb *chip,
281 enum als4k_cr_t reg)
282{
283 /* NOTE: assumes chip->mixer_lock to be locked externally already! */
284 return snd_sbmixer_read(chip, reg | 0xc0);
285}
286
287
288
147static void snd_als4000_set_rate(struct snd_sb *chip, unsigned int rate) 289static void snd_als4000_set_rate(struct snd_sb *chip, unsigned int rate)
148{ 290{
149 if (!(chip->mode & SB_RATE_LOCK)) { 291 if (!(chip->mode & SB_RATE_LOCK)) {
@@ -156,15 +298,19 @@ static void snd_als4000_set_rate(struct snd_sb *chip, unsigned int rate)
156static inline void snd_als4000_set_capture_dma(struct snd_sb *chip, 298static inline void snd_als4000_set_capture_dma(struct snd_sb *chip,
157 dma_addr_t addr, unsigned size) 299 dma_addr_t addr, unsigned size)
158{ 300{
159 snd_als4000_gcr_write(chip, 0xa2, addr); 301 /* SPECS_PAGE: 40 */
160 snd_als4000_gcr_write(chip, 0xa3, (size-1)); 302 snd_als4k_gcr_write(chip, ALS4K_GCRA2_FIFO2_PCIADDR, addr);
303 snd_als4k_gcr_write(chip, ALS4K_GCRA3_FIFO2_COUNT, (size-1));
161} 304}
162 305
163static inline void snd_als4000_set_playback_dma(struct snd_sb *chip, 306static inline void snd_als4000_set_playback_dma(struct snd_sb *chip,
164 dma_addr_t addr, unsigned size) 307 dma_addr_t addr,
308 unsigned size)
165{ 309{
166 snd_als4000_gcr_write(chip, 0x91, addr); 310 /* SPECS_PAGE: 38 */
167 snd_als4000_gcr_write(chip, 0x92, (size-1)|0x180000); 311 snd_als4k_gcr_write(chip, ALS4K_GCR91_DMA0_ADDR, addr);
312 snd_als4k_gcr_write(chip, ALS4K_GCR92_DMA0_MODE_COUNT,
313 (size-1)|0x180000);
168} 314}
169 315
170#define ALS4000_FORMAT_SIGNED (1<<0) 316#define ALS4000_FORMAT_SIGNED (1<<0)
@@ -248,7 +394,7 @@ static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream)
248 count = snd_pcm_lib_period_bytes(substream); 394 count = snd_pcm_lib_period_bytes(substream);
249 395
250 if (chip->capture_format & ALS4000_FORMAT_16BIT) 396 if (chip->capture_format & ALS4000_FORMAT_16BIT)
251 count >>=1; 397 count >>= 1;
252 count--; 398 count--;
253 399
254 spin_lock_irq(&chip->reg_lock); 400 spin_lock_irq(&chip->reg_lock);
@@ -256,8 +402,8 @@ static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream)
256 snd_als4000_set_capture_dma(chip, runtime->dma_addr, size); 402 snd_als4000_set_capture_dma(chip, runtime->dma_addr, size);
257 spin_unlock_irq(&chip->reg_lock); 403 spin_unlock_irq(&chip->reg_lock);
258 spin_lock_irq(&chip->mixer_lock); 404 spin_lock_irq(&chip->mixer_lock);
259 snd_sbmixer_write(chip, 0xdc, count); 405 snd_als4_cr_write(chip, ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO, count & 0xff);
260 snd_sbmixer_write(chip, 0xdd, count>>8); 406 snd_als4_cr_write(chip, ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI, count >> 8);
261 spin_unlock_irq(&chip->mixer_lock); 407 spin_unlock_irq(&chip->mixer_lock);
262 return 0; 408 return 0;
263} 409}
@@ -275,7 +421,7 @@ static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream)
275 count = snd_pcm_lib_period_bytes(substream); 421 count = snd_pcm_lib_period_bytes(substream);
276 422
277 if (chip->playback_format & ALS4000_FORMAT_16BIT) 423 if (chip->playback_format & ALS4000_FORMAT_16BIT)
278 count >>=1; 424 count >>= 1;
279 count--; 425 count--;
280 426
281 /* FIXME: from second playback on, there's a lot more clicks and pops 427 /* FIXME: from second playback on, there's a lot more clicks and pops
@@ -292,8 +438,8 @@ static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream)
292 /* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */ 438 /* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */
293 snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd); 439 snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd);
294 snd_sbdsp_command(chip, playback_cmd(chip).format); 440 snd_sbdsp_command(chip, playback_cmd(chip).format);
295 snd_sbdsp_command(chip, count); 441 snd_sbdsp_command(chip, count & 0xff);
296 snd_sbdsp_command(chip, count>>8); 442 snd_sbdsp_command(chip, count >> 8);
297 snd_sbdsp_command(chip, playback_cmd(chip).dma_off); 443 snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
298 spin_unlock_irq(&chip->reg_lock); 444 spin_unlock_irq(&chip->reg_lock);
299 445
@@ -305,17 +451,25 @@ static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int
305 struct snd_sb *chip = snd_pcm_substream_chip(substream); 451 struct snd_sb *chip = snd_pcm_substream_chip(substream);
306 int result = 0; 452 int result = 0;
307 453
454 /* FIXME race condition in here!!!
455 chip->mode non-atomic update gets consistently protected
456 by reg_lock always, _except_ for this place!!
457 Probably need to take reg_lock as outer (or inner??) lock, too.
458 (or serialize both lock operations? probably not, though... - racy?)
459 */
308 spin_lock(&chip->mixer_lock); 460 spin_lock(&chip->mixer_lock);
309 switch (cmd) { 461 switch (cmd) {
310 case SNDRV_PCM_TRIGGER_START: 462 case SNDRV_PCM_TRIGGER_START:
311 case SNDRV_PCM_TRIGGER_RESUME: 463 case SNDRV_PCM_TRIGGER_RESUME:
312 chip->mode |= SB_RATE_LOCK_CAPTURE; 464 chip->mode |= SB_RATE_LOCK_CAPTURE;
313 snd_sbmixer_write(chip, 0xde, capture_cmd(chip)); 465 snd_als4_cr_write(chip, ALS4K_CR1E_FIFO2_CONTROL,
466 capture_cmd(chip));
314 break; 467 break;
315 case SNDRV_PCM_TRIGGER_STOP: 468 case SNDRV_PCM_TRIGGER_STOP:
316 case SNDRV_PCM_TRIGGER_SUSPEND: 469 case SNDRV_PCM_TRIGGER_SUSPEND:
317 chip->mode &= ~SB_RATE_LOCK_CAPTURE; 470 chip->mode &= ~SB_RATE_LOCK_CAPTURE;
318 snd_sbmixer_write(chip, 0xde, 0); 471 snd_als4_cr_write(chip, ALS4K_CR1E_FIFO2_CONTROL,
472 capture_cmd(chip));
319 break; 473 break;
320 default: 474 default:
321 result = -EINVAL; 475 result = -EINVAL;
@@ -356,8 +510,9 @@ static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *s
356 unsigned int result; 510 unsigned int result;
357 511
358 spin_lock(&chip->reg_lock); 512 spin_lock(&chip->reg_lock);
359 result = snd_als4000_gcr_read(chip, 0xa4) & 0xffff; 513 result = snd_als4k_gcr_read(chip, ALS4K_GCRA4_FIFO2_CURRENT_ADDR);
360 spin_unlock(&chip->reg_lock); 514 spin_unlock(&chip->reg_lock);
515 result &= 0xffff;
361 return bytes_to_frames( substream->runtime, result ); 516 return bytes_to_frames( substream->runtime, result );
362} 517}
363 518
@@ -367,8 +522,9 @@ static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *
367 unsigned result; 522 unsigned result;
368 523
369 spin_lock(&chip->reg_lock); 524 spin_lock(&chip->reg_lock);
370 result = snd_als4000_gcr_read(chip, 0xa0) & 0xffff; 525 result = snd_als4k_gcr_read(chip, ALS4K_GCRA0_FIFO1_CURRENT_ADDR);
371 spin_unlock(&chip->reg_lock); 526 spin_unlock(&chip->reg_lock);
527 result &= 0xffff;
372 return bytes_to_frames( substream->runtime, result ); 528 return bytes_to_frames( substream->runtime, result );
373} 529}
374 530
@@ -376,45 +532,63 @@ static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *
376 * return IRQ_HANDLED no matter whether we actually had an IRQ flag or not). 532 * return IRQ_HANDLED no matter whether we actually had an IRQ flag or not).
377 * ALS4000a.PDF writes that while ACKing IRQ in PCI block will *not* ACK 533 * ALS4000a.PDF writes that while ACKing IRQ in PCI block will *not* ACK
378 * the IRQ in the SB core, ACKing IRQ in SB block *will* ACK the PCI IRQ 534 * the IRQ in the SB core, ACKing IRQ in SB block *will* ACK the PCI IRQ
379 * register (alt_port + 0x0e). Probably something could be optimized here to 535 * register (alt_port + ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU). Probably something
380 * query/write one register only... 536 * could be optimized here to query/write one register only...
381 * And even if both registers need to be queried, then there's still the 537 * And even if both registers need to be queried, then there's still the
382 * question of whether it's actually correct to ACK PCI IRQ before reading 538 * question of whether it's actually correct to ACK PCI IRQ before reading
383 * SB IRQ like we do now, since ALS4000a.PDF mentions that PCI IRQ will *clear* 539 * SB IRQ like we do now, since ALS4000a.PDF mentions that PCI IRQ will *clear*
384 * SB IRQ status. 540 * SB IRQ status.
541 * (hmm, SPECS_PAGE: 38 mentions it the other way around!)
385 * And do we *really* need the lock here for *reading* SB_DSP4_IRQSTATUS?? 542 * And do we *really* need the lock here for *reading* SB_DSP4_IRQSTATUS??
386 * */ 543 * */
387static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id) 544static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id)
388{ 545{
389 struct snd_sb *chip = dev_id; 546 struct snd_sb *chip = dev_id;
390 unsigned gcr_status; 547 unsigned pci_irqstatus;
391 unsigned sb_status; 548 unsigned sb_irqstatus;
392 549
393 /* find out which bit of the ALS4000 produced the interrupt */ 550 /* find out which bit of the ALS4000 PCI block produced the interrupt,
394 gcr_status = inb(chip->alt_port + 0xe); 551 SPECS_PAGE: 38, 5 */
395 552 pci_irqstatus = snd_als4k_iobase_readb(chip->alt_port,
396 if ((gcr_status & 0x80) && (chip->playback_substream)) /* playback */ 553 ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU);
554 if ((pci_irqstatus & ALS4K_IOB_0E_SB_DMA_IRQ)
555 && (chip->playback_substream)) /* playback */
397 snd_pcm_period_elapsed(chip->playback_substream); 556 snd_pcm_period_elapsed(chip->playback_substream);
398 if ((gcr_status & 0x40) && (chip->capture_substream)) /* capturing */ 557 if ((pci_irqstatus & ALS4K_IOB_0E_CR1E_IRQ)
558 && (chip->capture_substream)) /* capturing */
399 snd_pcm_period_elapsed(chip->capture_substream); 559 snd_pcm_period_elapsed(chip->capture_substream);
400 if ((gcr_status & 0x10) && (chip->rmidi)) /* MPU401 interrupt */ 560 if ((pci_irqstatus & ALS4K_IOB_0E_MPU_IRQ)
561 && (chip->rmidi)) /* MPU401 interrupt */
401 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); 562 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
402 /* release the gcr */ 563 /* ACK the PCI block IRQ */
403 outb(gcr_status, chip->alt_port + 0xe); 564 snd_als4k_iobase_writeb(chip->alt_port,
565 ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU, pci_irqstatus);
404 566
405 spin_lock(&chip->mixer_lock); 567 spin_lock(&chip->mixer_lock);
406 sb_status = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS); 568 /* SPECS_PAGE: 20 */
569 sb_irqstatus = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS);
407 spin_unlock(&chip->mixer_lock); 570 spin_unlock(&chip->mixer_lock);
408 571
409 if (sb_status & SB_IRQTYPE_8BIT) 572 if (sb_irqstatus & SB_IRQTYPE_8BIT)
410 snd_sb_ack_8bit(chip); 573 snd_sb_ack_8bit(chip);
411 if (sb_status & SB_IRQTYPE_16BIT) 574 if (sb_irqstatus & SB_IRQTYPE_16BIT)
412 snd_sb_ack_16bit(chip); 575 snd_sb_ack_16bit(chip);
413 if (sb_status & SB_IRQTYPE_MPUIN) 576 if (sb_irqstatus & SB_IRQTYPE_MPUIN)
414 inb(chip->mpu_port); 577 inb(chip->mpu_port);
415 if (sb_status & 0x20) 578 if (sb_irqstatus & ALS4K_IRQTYPE_CR1E_DMA)
416 inb(SBP(chip, RESET)); 579 snd_als4k_iobase_readb(chip->alt_port,
417 return IRQ_HANDLED; 580 ALS4K_IOB_16_ACK_FOR_CR1E);
581
582 /* printk(KERN_INFO "als4000: irq 0x%04x 0x%04x\n",
583 pci_irqstatus, sb_irqstatus); */
584
585 /* only ack the things we actually handled above */
586 return IRQ_RETVAL(
587 (pci_irqstatus & (ALS4K_IOB_0E_SB_DMA_IRQ|ALS4K_IOB_0E_CR1E_IRQ|
588 ALS4K_IOB_0E_MPU_IRQ))
589 || (sb_irqstatus & (SB_IRQTYPE_8BIT|SB_IRQTYPE_16BIT|
590 SB_IRQTYPE_MPUIN|ALS4K_IRQTYPE_CR1E_DMA))
591 );
418} 592}
419 593
420/*****************************************************************/ 594/*****************************************************************/
@@ -526,7 +700,8 @@ static int __devinit snd_als4000_pcm(struct snd_sb *chip, int device)
526 struct snd_pcm *pcm; 700 struct snd_pcm *pcm;
527 int err; 701 int err;
528 702
529 if ((err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm)) < 0) 703 err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm);
704 if (err < 0)
530 return err; 705 return err;
531 pcm->private_data = chip; 706 pcm->private_data = chip;
532 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; 707 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
@@ -543,48 +718,55 @@ static int __devinit snd_als4000_pcm(struct snd_sb *chip, int device)
543 718
544/******************************************************************/ 719/******************************************************************/
545 720
546static void snd_als4000_set_addr(unsigned long gcr, 721static void snd_als4000_set_addr(unsigned long iobase,
547 unsigned int sb, 722 unsigned int sb_io,
548 unsigned int mpu, 723 unsigned int mpu_io,
549 unsigned int opl, 724 unsigned int opl_io,
550 unsigned int game) 725 unsigned int game_io)
551{ 726{
552 u32 confA = 0; 727 u32 cfg1 = 0;
553 u32 confB = 0; 728 u32 cfg2 = 0;
554 729
555 if (mpu > 0) 730 if (mpu_io > 0)
556 confB |= (mpu | 1) << 16; 731 cfg2 |= (mpu_io | 1) << 16;
557 if (sb > 0) 732 if (sb_io > 0)
558 confB |= (sb | 1); 733 cfg2 |= (sb_io | 1);
559 if (game > 0) 734 if (game_io > 0)
560 confA |= (game | 1) << 16; 735 cfg1 |= (game_io | 1) << 16;
561 if (opl > 0) 736 if (opl_io > 0)
562 confA |= (opl | 1); 737 cfg1 |= (opl_io | 1);
563 snd_als4000_gcr_write_addr(gcr, 0xa8, confA); 738 snd_als4k_gcr_write_addr(iobase, ALS4K_GCRA8_LEGACY_CFG1, cfg1);
564 snd_als4000_gcr_write_addr(gcr, 0xa9, confB); 739 snd_als4k_gcr_write_addr(iobase, ALS4K_GCRA9_LEGACY_CFG2, cfg2);
565} 740}
566 741
567static void snd_als4000_configure(struct snd_sb *chip) 742static void snd_als4000_configure(struct snd_sb *chip)
568{ 743{
569 unsigned tmp; 744 u8 tmp;
570 int i; 745 int i;
571 746
572 /* do some more configuration */ 747 /* do some more configuration */
573 spin_lock_irq(&chip->mixer_lock); 748 spin_lock_irq(&chip->mixer_lock);
574 tmp = snd_sbmixer_read(chip, 0xc0); 749 tmp = snd_als4_cr_read(chip, ALS4K_CR0_SB_CONFIG);
575 snd_sbmixer_write(chip, 0xc0, tmp|0x80); 750 snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG,
576 /* always select DMA channel 0, since we do not actually use DMA */ 751 tmp|ALS4K_CR0_MX80_81_REG_WRITE_ENABLE);
752 /* always select DMA channel 0, since we do not actually use DMA
753 * SPECS_PAGE: 19/20 */
577 snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0); 754 snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0);
578 snd_sbmixer_write(chip, 0xc0, tmp&0x7f); 755 snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG,
756 tmp & ~ALS4K_CR0_MX80_81_REG_WRITE_ENABLE);
579 spin_unlock_irq(&chip->mixer_lock); 757 spin_unlock_irq(&chip->mixer_lock);
580 758
581 spin_lock_irq(&chip->reg_lock); 759 spin_lock_irq(&chip->reg_lock);
582 /* magic number. Enables interrupts(?) */ 760 /* enable interrupts */
583 snd_als4000_gcr_write(chip, 0x8c, 0x28000); 761 snd_als4k_gcr_write(chip, ALS4K_GCR8C_MISC_CTRL,
584 for(i = 0x91; i <= 0x96; ++i) 762 ALS4K_GCR8C_IRQ_MASK_CTRL_ENABLE);
585 snd_als4000_gcr_write(chip, i, 0); 763
764 /* SPECS_PAGE: 39 */
765 for (i = ALS4K_GCR91_DMA0_ADDR; i <= ALS4K_GCR96_DMA3_MODE_COUNT; ++i)
766 snd_als4k_gcr_write(chip, i, 0);
586 767
587 snd_als4000_gcr_write(chip, 0x99, snd_als4000_gcr_read(chip, 0x99)); 768 snd_als4k_gcr_write(chip, ALS4K_GCR99_DMA_EMULATION_CTRL,
769 snd_als4k_gcr_read(chip, ALS4K_GCR99_DMA_EMULATION_CTRL));
588 spin_unlock_irq(&chip->reg_lock); 770 spin_unlock_irq(&chip->reg_lock);
589} 771}
590 772
@@ -628,7 +810,7 @@ static int __devinit snd_als4000_create_gameport(struct snd_card_als4000 *acard,
628 gameport_set_port_data(gp, r); 810 gameport_set_port_data(gp, r);
629 811
630 /* Enable legacy joystick port */ 812 /* Enable legacy joystick port */
631 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 1); 813 snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1);
632 814
633 gameport_register_port(acard->gameport); 815 gameport_register_port(acard->gameport);
634 816
@@ -643,7 +825,9 @@ static void snd_als4000_free_gameport(struct snd_card_als4000 *acard)
643 gameport_unregister_port(acard->gameport); 825 gameport_unregister_port(acard->gameport);
644 acard->gameport = NULL; 826 acard->gameport = NULL;
645 827
646 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */ 828 /* disable joystick */
829 snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0);
830
647 release_and_free_resource(r); 831 release_and_free_resource(r);
648 } 832 }
649} 833}
@@ -654,10 +838,10 @@ static inline void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { }
654 838
655static void snd_card_als4000_free( struct snd_card *card ) 839static void snd_card_als4000_free( struct snd_card *card )
656{ 840{
657 struct snd_card_als4000 * acard = (struct snd_card_als4000 *)card->private_data; 841 struct snd_card_als4000 *acard = card->private_data;
658 842
659 /* make sure that interrupts are disabled */ 843 /* make sure that interrupts are disabled */
660 snd_als4000_gcr_write_addr( acard->gcr, 0x8c, 0); 844 snd_als4k_gcr_write_addr(acard->iobase, ALS4K_GCR8C_MISC_CTRL, 0);
661 /* free resources */ 845 /* free resources */
662 snd_als4000_free_gameport(acard); 846 snd_als4000_free_gameport(acard);
663 pci_release_regions(acard->pci); 847 pci_release_regions(acard->pci);
@@ -670,7 +854,7 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
670 static int dev; 854 static int dev;
671 struct snd_card *card; 855 struct snd_card *card;
672 struct snd_card_als4000 *acard; 856 struct snd_card_als4000 *acard;
673 unsigned long gcr; 857 unsigned long iobase;
674 struct snd_sb *chip; 858 struct snd_sb *chip;
675 struct snd_opl3 *opl3; 859 struct snd_opl3 *opl3;
676 unsigned short word; 860 unsigned short word;
@@ -699,31 +883,32 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
699 pci_disable_device(pci); 883 pci_disable_device(pci);
700 return err; 884 return err;
701 } 885 }
702 gcr = pci_resource_start(pci, 0); 886 iobase = pci_resource_start(pci, 0);
703 887
704 pci_read_config_word(pci, PCI_COMMAND, &word); 888 pci_read_config_word(pci, PCI_COMMAND, &word);
705 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO); 889 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
706 pci_set_master(pci); 890 pci_set_master(pci);
707 891
708 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 892 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
709 sizeof( struct snd_card_als4000 ) ); 893 sizeof(*acard) /* private_data: acard */);
710 if (card == NULL) { 894 if (card == NULL) {
711 pci_release_regions(pci); 895 pci_release_regions(pci);
712 pci_disable_device(pci); 896 pci_disable_device(pci);
713 return -ENOMEM; 897 return -ENOMEM;
714 } 898 }
715 899
716 acard = (struct snd_card_als4000 *)card->private_data; 900 acard = card->private_data;
717 acard->pci = pci; 901 acard->pci = pci;
718 acard->gcr = gcr; 902 acard->iobase = iobase;
719 card->private_free = snd_card_als4000_free; 903 card->private_free = snd_card_als4000_free;
720 904
721 /* disable all legacy ISA stuff */ 905 /* disable all legacy ISA stuff */
722 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); 906 snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0);
723 907
724 if ((err = snd_sbdsp_create(card, 908 if ((err = snd_sbdsp_create(card,
725 gcr + 0x10, 909 iobase + ALS4K_IOB_10_ADLIB_ADDR0,
726 pci->irq, 910 pci->irq,
911 /* internally registered as IRQF_SHARED in case of ALS4000 SB */
727 snd_als4000_interrupt, 912 snd_als4000_interrupt,
728 -1, 913 -1,
729 -1, 914 -1,
@@ -734,7 +919,7 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
734 acard->chip = chip; 919 acard->chip = chip;
735 920
736 chip->pci = pci; 921 chip->pci = pci;
737 chip->alt_port = gcr; 922 chip->alt_port = iobase;
738 snd_card_set_dev(card, &pci->dev); 923 snd_card_set_dev(card, &pci->dev);
739 924
740 snd_als4000_configure(chip); 925 snd_als4000_configure(chip);
@@ -745,11 +930,18 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
745 card->shortname, chip->alt_port, chip->irq); 930 card->shortname, chip->alt_port, chip->irq);
746 931
747 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, 932 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
748 gcr+0x30, MPU401_INFO_INTEGRATED, 933 iobase + ALS4K_IOB_30_MIDI_DATA,
934 MPU401_INFO_INTEGRATED,
749 pci->irq, 0, &chip->rmidi)) < 0) { 935 pci->irq, 0, &chip->rmidi)) < 0) {
750 printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", gcr+0x30); 936 printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n",
937 iobase + ALS4K_IOB_30_MIDI_DATA);
751 goto out_err; 938 goto out_err;
752 } 939 }
940 /* FIXME: ALS4000 has interesting MPU401 configuration features
941 * at ALS4K_CR1A_MPU401_UART_MODE_CONTROL
942 * (pass-thru / UART switching, fast MIDI clock, etc.),
943 * however there doesn't seem to be an ALSA API for this...
944 * SPECS_PAGE: 21 */
753 945
754 if ((err = snd_als4000_pcm(chip, 0)) < 0) { 946 if ((err = snd_als4000_pcm(chip, 0)) < 0) {
755 goto out_err; 947 goto out_err;
@@ -758,10 +950,13 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
758 goto out_err; 950 goto out_err;
759 } 951 }
760 952
761 if (snd_opl3_create(card, gcr+0x10, gcr+0x12, 953 if (snd_opl3_create(card,
954 iobase + ALS4K_IOB_10_ADLIB_ADDR0,
955 iobase + ALS4K_IOB_12_ADLIB_ADDR2,
762 OPL3_HW_AUTO, 1, &opl3) < 0) { 956 OPL3_HW_AUTO, 1, &opl3) < 0) {
763 printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?\n", 957 printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?\n",
764 gcr+0x10, gcr+0x12 ); 958 iobase + ALS4K_IOB_10_ADLIB_ADDR0,
959 iobase + ALS4K_IOB_12_ADLIB_ADDR2);
765 } else { 960 } else {
766 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 961 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
767 goto out_err; 962 goto out_err;
@@ -831,13 +1026,13 @@ static int snd_als4000_resume(struct pci_dev *pci)
831 1026
832#ifdef SUPPORT_JOYSTICK 1027#ifdef SUPPORT_JOYSTICK
833 if (acard->gameport) 1028 if (acard->gameport)
834 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 1); 1029 snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1);
835#endif 1030#endif
836 1031
837 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1032 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
838 return 0; 1033 return 0;
839} 1034}
840#endif 1035#endif /* CONFIG_PM */
841 1036
842 1037
843static struct pci_driver driver = { 1038static struct pci_driver driver = {
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 457228fb22aa..085a52b8c807 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -37,7 +37,7 @@
37MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); 37MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
38MODULE_DESCRIPTION("ATI IXP AC97 controller"); 38MODULE_DESCRIPTION("ATI IXP AC97 controller");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}"); 40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400/600}}");
41 41
42static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 42static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
43static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 43static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
@@ -290,6 +290,7 @@ static struct pci_device_id snd_atiixp_ids[] = {
290 { 0x1002, 0x4341, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */ 290 { 0x1002, 0x4341, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */
291 { 0x1002, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB300 */ 291 { 0x1002, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB300 */
292 { 0x1002, 0x4370, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */ 292 { 0x1002, 0x4370, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */
293 { 0x1002, 0x4382, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB600 */
293 { 0, } 294 { 0, }
294}; 295};
295 296
@@ -722,7 +723,9 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
722 struct atiixp_dma *dma = substream->runtime->private_data; 723 struct atiixp_dma *dma = substream->runtime->private_data;
723 int err = 0; 724 int err = 0;
724 725
725 snd_assert(dma->ops->enable_transfer && dma->ops->flush_dma, return -EINVAL); 726 if (snd_BUG_ON(!dma->ops->enable_transfer ||
727 !dma->ops->flush_dma))
728 return -EINVAL;
726 729
727 spin_lock(&chip->reg_lock); 730 spin_lock(&chip->reg_lock);
728 switch (cmd) { 731 switch (cmd) {
@@ -1032,7 +1035,8 @@ static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream,
1032 struct snd_pcm_runtime *runtime = substream->runtime; 1035 struct snd_pcm_runtime *runtime = substream->runtime;
1033 int err; 1036 int err;
1034 1037
1035 snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL); 1038 if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
1039 return -EINVAL;
1036 1040
1037 if (dma->opened) 1041 if (dma->opened)
1038 return -EBUSY; 1042 return -EBUSY;
@@ -1064,7 +1068,8 @@ static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,
1064{ 1068{
1065 struct atiixp *chip = snd_pcm_substream_chip(substream); 1069 struct atiixp *chip = snd_pcm_substream_chip(substream);
1066 /* disable DMA bits */ 1070 /* disable DMA bits */
1067 snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL); 1071 if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
1072 return -EINVAL;
1068 spin_lock_irq(&chip->reg_lock); 1073 spin_lock_irq(&chip->reg_lock);
1069 dma->ops->enable_dma(chip, 0); 1074 dma->ops->enable_dma(chip, 0);
1070 spin_unlock_irq(&chip->reg_lock); 1075 spin_unlock_irq(&chip->reg_lock);
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index d457a32a7939..2f106306c7fe 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -674,7 +674,9 @@ static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
674 struct atiixp_dma *dma = substream->runtime->private_data; 674 struct atiixp_dma *dma = substream->runtime->private_data;
675 int err = 0; 675 int err = 0;
676 676
677 snd_assert(dma->ops->enable_transfer && dma->ops->flush_dma, return -EINVAL); 677 if (snd_BUG_ON(!dma->ops->enable_transfer ||
678 !dma->ops->flush_dma))
679 return -EINVAL;
678 680
679 spin_lock(&chip->reg_lock); 681 spin_lock(&chip->reg_lock);
680 switch(cmd) { 682 switch(cmd) {
@@ -865,7 +867,8 @@ static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream,
865 .mask = 0, 867 .mask = 0,
866 }; 868 };
867 869
868 snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL); 870 if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
871 return -EINVAL;
869 872
870 if (dma->opened) 873 if (dma->opened)
871 return -EBUSY; 874 return -EBUSY;
@@ -895,7 +898,8 @@ static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,
895{ 898{
896 struct atiixp_modem *chip = snd_pcm_substream_chip(substream); 899 struct atiixp_modem *chip = snd_pcm_substream_chip(substream);
897 /* disable DMA bits */ 900 /* disable DMA bits */
898 snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL); 901 if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
902 return -EINVAL;
899 spin_lock_irq(&chip->reg_lock); 903 spin_lock_irq(&chip->reg_lock);
900 dma->ops->enable_dma(chip, 0); 904 dma->ops->enable_dma(chip, 0);
901 spin_unlock_irq(&chip->reg_lock); 905 spin_unlock_irq(&chip->reg_lock);
diff --git a/sound/pci/au88x0/au88x0.h b/sound/pci/au88x0/au88x0.h
index 4aad35bba11a..cf46bba563cf 100644
--- a/sound/pci/au88x0/au88x0.h
+++ b/sound/pci/au88x0/au88x0.h
@@ -125,7 +125,6 @@ typedef struct {
125 /* Virtual page extender stuff */ 125 /* Virtual page extender stuff */
126 int nr_periods; 126 int nr_periods;
127 int period_bytes; 127 int period_bytes;
128 struct snd_sg_buf *sgbuf; /* DMA Scatter Gather struct */
129 int period_real; 128 int period_real;
130 int period_virt; 129 int period_virt;
131 130
@@ -195,16 +194,14 @@ static void vortex_adb_setsrc(vortex_t * vortex, int adbdma,
195 194
196/* DMA Engines. */ 195/* DMA Engines. */
197static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma, 196static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
198 struct snd_sg_buf * sgbuf, int size, 197 int size, int count);
199 int count);
200static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie, 198static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie,
201 int dir, int fmt, int d, 199 int dir, int fmt, int d,
202 u32 offset); 200 u32 offset);
203static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb); 201static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb);
204#ifndef CHIP_AU8810 202#ifndef CHIP_AU8810
205static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma, 203static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
206 struct snd_sg_buf * sgbuf, int size, 204 int size, int count);
207 int count);
208static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */ 205static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */
209 u32 offset); 206 u32 offset);
210static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb); 207static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb);
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index 333c62de8620..b070e5714514 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -427,7 +427,7 @@ static void vortex_mixer_init(vortex_t * vortex)
427 427
428 /* Set clipping ceiling (this may be all wrong). */ 428 /* Set clipping ceiling (this may be all wrong). */
429 /* 429 /*
430 for (x = 0; x > 0x80; x++) { 430 for (x = 0; x < 0x80; x++) {
431 hwwrite(vortex->mmio, VORTEX_MIXER_CLIP + (x << 2), 0x3ffff); 431 hwwrite(vortex->mmio, VORTEX_MIXER_CLIP + (x << 2), 0x3ffff);
432 } 432 }
433 */ 433 */
@@ -1097,19 +1097,12 @@ static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb)
1097 1097
1098static void 1098static void
1099vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma, 1099vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
1100 struct snd_sg_buf * sgbuf, int psize, int count) 1100 int psize, int count)
1101{ 1101{
1102 stream_t *dma = &vortex->dma_adb[adbdma]; 1102 stream_t *dma = &vortex->dma_adb[adbdma];
1103 1103
1104 if (sgbuf == NULL) {
1105 printk(KERN_INFO "vortex: FATAL: sgbuf is NULL!\n");
1106 return;
1107 }
1108 //printk(KERN_INFO "vortex: page count = %d, tblcount = %d\n", count, sgbuf->tblsize);
1109
1110 dma->period_bytes = psize; 1104 dma->period_bytes = psize;
1111 dma->nr_periods = count; 1105 dma->nr_periods = count;
1112 dma->sgbuf = sgbuf;
1113 1106
1114 dma->cfg0 = 0; 1107 dma->cfg0 = 0;
1115 dma->cfg1 = 0; 1108 dma->cfg1 = 0;
@@ -1120,26 +1113,26 @@ vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
1120 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize - 1); 1113 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize - 1);
1121 hwwrite(vortex->mmio, 1114 hwwrite(vortex->mmio,
1122 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0xc, 1115 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0xc,
1123 snd_sgbuf_get_addr(sgbuf, psize * 3)); 1116 snd_pcm_sgbuf_get_addr(dma->substream, psize * 3));
1124 /* 3 pages */ 1117 /* 3 pages */
1125 case 3: 1118 case 3:
1126 dma->cfg0 |= 0x12000000; 1119 dma->cfg0 |= 0x12000000;
1127 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc); 1120 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc);
1128 hwwrite(vortex->mmio, 1121 hwwrite(vortex->mmio,
1129 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x8, 1122 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x8,
1130 snd_sgbuf_get_addr(sgbuf, psize * 2)); 1123 snd_pcm_sgbuf_get_addr(dma->substream, psize * 2));
1131 /* 2 pages */ 1124 /* 2 pages */
1132 case 2: 1125 case 2:
1133 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize - 1); 1126 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize - 1);
1134 hwwrite(vortex->mmio, 1127 hwwrite(vortex->mmio,
1135 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x4, 1128 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x4,
1136 snd_sgbuf_get_addr(sgbuf, psize)); 1129 snd_pcm_sgbuf_get_addr(dma->substream, psize));
1137 /* 1 page */ 1130 /* 1 page */
1138 case 1: 1131 case 1:
1139 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc); 1132 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc);
1140 hwwrite(vortex->mmio, 1133 hwwrite(vortex->mmio,
1141 VORTEX_ADBDMA_BUFBASE + (adbdma << 4), 1134 VORTEX_ADBDMA_BUFBASE + (adbdma << 4),
1142 snd_sgbuf_get_addr(sgbuf, 0)); 1135 snd_pcm_sgbuf_get_addr(dma->substream, 0));
1143 break; 1136 break;
1144 } 1137 }
1145 //printk("vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n", dma->cfg0, dma->cfg1); 1138 //printk("vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n", dma->cfg0, dma->cfg1);
@@ -1205,7 +1198,7 @@ static int vortex_adbdma_bufshift(vortex_t * vortex, int adbdma)
1205 //hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), dma->table[p].addr); 1198 //hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), dma->table[p].addr);
1206 hwwrite(vortex->mmio, 1199 hwwrite(vortex->mmio,
1207 VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2), 1200 VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2),
1208 snd_sgbuf_get_addr(dma->sgbuf, 1201 snd_pcm_sgbuf_get_addr(dma->substream,
1209 dma->period_bytes * p)); 1202 dma->period_bytes * p));
1210 /* Force write thru cache. */ 1203 /* Force write thru cache. */
1211 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + 1204 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE +
@@ -1244,7 +1237,10 @@ static void vortex_adbdma_resetup(vortex_t *vortex, int adbdma) {
1244 if (pp >= 4) 1237 if (pp >= 4)
1245 pp -= 4; 1238 pp -= 4;
1246 } 1239 }
1247 hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), snd_sgbuf_get_addr(dma->sgbuf, dma->period_bytes * p)); 1240 hwwrite(vortex->mmio,
1241 VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2),
1242 snd_pcm_sgbuf_get_addr(dma->substream,
1243 dma->period_bytes * p));
1248 /* Force write thru cache. */ 1244 /* Force write thru cache. */
1249 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + (((adbdma << 2)+pp) << 2)); 1245 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + (((adbdma << 2)+pp) << 2));
1250 } 1246 }
@@ -1367,13 +1363,12 @@ static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb)
1367 1363
1368static void 1364static void
1369vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma, 1365vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
1370 struct snd_sg_buf * sgbuf, int psize, int count) 1366 int psize, int count)
1371{ 1367{
1372 stream_t *dma = &vortex->dma_wt[wtdma]; 1368 stream_t *dma = &vortex->dma_wt[wtdma];
1373 1369
1374 dma->period_bytes = psize; 1370 dma->period_bytes = psize;
1375 dma->nr_periods = count; 1371 dma->nr_periods = count;
1376 dma->sgbuf = sgbuf;
1377 1372
1378 dma->cfg0 = 0; 1373 dma->cfg0 = 0;
1379 dma->cfg1 = 0; 1374 dma->cfg1 = 0;
@@ -1383,23 +1378,23 @@ vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
1383 case 4: 1378 case 4:
1384 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize-1); 1379 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize-1);
1385 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0xc, 1380 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0xc,
1386 snd_sgbuf_get_addr(sgbuf, psize * 3)); 1381 snd_pcm_sgbuf_get_addr(dma->substream, psize * 3));
1387 /* 3 pages */ 1382 /* 3 pages */
1388 case 3: 1383 case 3:
1389 dma->cfg0 |= 0x12000000; 1384 dma->cfg0 |= 0x12000000;
1390 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc); 1385 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc);
1391 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x8, 1386 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x8,
1392 snd_sgbuf_get_addr(sgbuf, psize * 2)); 1387 snd_pcm_sgbuf_get_addr(dma->substream, psize * 2));
1393 /* 2 pages */ 1388 /* 2 pages */
1394 case 2: 1389 case 2:
1395 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize-1); 1390 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize-1);
1396 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x4, 1391 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x4,
1397 snd_sgbuf_get_addr(sgbuf, psize)); 1392 snd_pcm_sgbuf_get_addr(dma->substream, psize));
1398 /* 1 page */ 1393 /* 1 page */
1399 case 1: 1394 case 1:
1400 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc); 1395 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc);
1401 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4), 1396 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4),
1402 snd_sgbuf_get_addr(sgbuf, 0)); 1397 snd_pcm_sgbuf_get_addr(dma->substream, 0));
1403 break; 1398 break;
1404 } 1399 }
1405 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFCFG0 + (wtdma << 3), dma->cfg0); 1400 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFCFG0 + (wtdma << 3), dma->cfg0);
@@ -1465,7 +1460,8 @@ static int vortex_wtdma_bufshift(vortex_t * vortex, int wtdma)
1465 hwwrite(vortex->mmio, 1460 hwwrite(vortex->mmio,
1466 VORTEX_WTDMA_BUFBASE + 1461 VORTEX_WTDMA_BUFBASE +
1467 (((wtdma << 2) + pp) << 2), 1462 (((wtdma << 2) + pp) << 2),
1468 snd_sgbuf_get_addr(dma->sgbuf, dma->period_bytes * p)); 1463 snd_pcm_sgbuf_get_addr(dma->substream,
1464 dma->period_bytes * p));
1469 /* Force write thru cache. */ 1465 /* Force write thru cache. */
1470 hwread(vortex->mmio, VORTEX_WTDMA_BUFBASE + 1466 hwread(vortex->mmio, VORTEX_WTDMA_BUFBASE +
1471 (((wtdma << 2) + pp) << 2)); 1467 (((wtdma << 2) + pp) << 2));
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index f9a58b4a30eb..b9d2f202cf9b 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -189,7 +189,6 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
189{ 189{
190 vortex_t *chip = snd_pcm_substream_chip(substream); 190 vortex_t *chip = snd_pcm_substream_chip(substream);
191 stream_t *stream = (stream_t *) (substream->runtime->private_data); 191 stream_t *stream = (stream_t *) (substream->runtime->private_data);
192 struct snd_sg_buf *sgbuf;
193 int err; 192 int err;
194 193
195 // Alloc buffer memory. 194 // Alloc buffer memory.
@@ -199,8 +198,6 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
199 printk(KERN_ERR "Vortex: pcm page alloc failed!\n"); 198 printk(KERN_ERR "Vortex: pcm page alloc failed!\n");
200 return err; 199 return err;
201 } 200 }
202 //sgbuf = (struct snd_sg_buf *) substream->runtime->dma_private;
203 sgbuf = snd_pcm_substream_sgbuf(substream);
204 /* 201 /*
205 printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params), 202 printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params),
206 params_period_bytes(hw_params), params_channels(hw_params)); 203 params_period_bytes(hw_params), params_channels(hw_params));
@@ -226,7 +223,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
226 stream = substream->runtime->private_data = &chip->dma_adb[dma]; 223 stream = substream->runtime->private_data = &chip->dma_adb[dma];
227 stream->substream = substream; 224 stream->substream = substream;
228 /* Setup Buffers. */ 225 /* Setup Buffers. */
229 vortex_adbdma_setbuffers(chip, dma, sgbuf, 226 vortex_adbdma_setbuffers(chip, dma,
230 params_period_bytes(hw_params), 227 params_period_bytes(hw_params),
231 params_periods(hw_params)); 228 params_periods(hw_params));
232 } 229 }
@@ -240,7 +237,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
240 &chip->dma_wt[substream->number]; 237 &chip->dma_wt[substream->number];
241 stream->dma = substream->number; 238 stream->dma = substream->number;
242 stream->substream = substream; 239 stream->substream = substream;
243 vortex_wtdma_setbuffers(chip, substream->number, sgbuf, 240 vortex_wtdma_setbuffers(chip, substream->number,
244 params_period_bytes(hw_params), 241 params_period_bytes(hw_params),
245 params_periods(hw_params)); 242 params_periods(hw_params));
246 } 243 }
@@ -392,13 +389,6 @@ static snd_pcm_uframes_t snd_vortex_pcm_pointer(struct snd_pcm_substream *substr
392 return (bytes_to_frames(substream->runtime, current_ptr)); 389 return (bytes_to_frames(substream->runtime, current_ptr));
393} 390}
394 391
395/* Page callback. */
396/*
397static struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset) {
398
399
400}
401*/
402/* operators */ 392/* operators */
403static struct snd_pcm_ops snd_vortex_playback_ops = { 393static struct snd_pcm_ops snd_vortex_playback_ops = {
404 .open = snd_vortex_pcm_open, 394 .open = snd_vortex_pcm_open,
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 22f18f3cfbc9..333007c523a1 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -816,7 +816,8 @@ snd_azf3328_mixer_new(struct snd_azf3328 *chip)
816 int err; 816 int err;
817 817
818 snd_azf3328_dbgcallenter(); 818 snd_azf3328_dbgcallenter();
819 snd_assert(chip != NULL && chip->card != NULL, return -EINVAL); 819 if (snd_BUG_ON(!chip || !chip->card))
820 return -EINVAL;
820 821
821 card = chip->card; 822 card = chip->card;
822 823
@@ -1471,7 +1472,8 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1471 u8 val; 1472 u8 val;
1472 unsigned long flags; 1473 unsigned long flags;
1473 1474
1474 snd_assert(chip, return 0); 1475 if (snd_BUG_ON(!chip))
1476 return 0;
1475 1477
1476 spin_lock_irqsave(&chip->reg_lock, flags); 1478 spin_lock_irqsave(&chip->reg_lock, flags);
1477 val = snd_azf3328_game_inb(chip, IDX_GAME_LEGACY_COMPATIBLE); 1479 val = snd_azf3328_game_inb(chip, IDX_GAME_LEGACY_COMPATIBLE);
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 4ecdd635ed1d..3aa8d973540a 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -227,7 +227,6 @@ static inline void snd_bt87x_writel(struct snd_bt87x *chip, u32 reg, u32 value)
227static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream, 227static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream,
228 unsigned int periods, unsigned int period_bytes) 228 unsigned int periods, unsigned int period_bytes)
229{ 229{
230 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
231 unsigned int i, offset; 230 unsigned int i, offset;
232 u32 *risc; 231 u32 *risc;
233 232
@@ -246,6 +245,7 @@ static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substrea
246 rest = period_bytes; 245 rest = period_bytes;
247 do { 246 do {
248 u32 cmd, len; 247 u32 cmd, len;
248 unsigned int addr;
249 249
250 len = PAGE_SIZE - (offset % PAGE_SIZE); 250 len = PAGE_SIZE - (offset % PAGE_SIZE);
251 if (len > rest) 251 if (len > rest)
@@ -260,7 +260,8 @@ static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substrea
260 if (len == rest) 260 if (len == rest)
261 cmd |= RISC_EOL | RISC_IRQ; 261 cmd |= RISC_EOL | RISC_IRQ;
262 *risc++ = cpu_to_le32(cmd); 262 *risc++ = cpu_to_le32(cmd);
263 *risc++ = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, offset)); 263 addr = snd_pcm_sgbuf_get_addr(substream, offset);
264 *risc++ = cpu_to_le32(addr);
264 offset += len; 265 offset += len;
265 rest -= len; 266 rest -= len;
266 } while (rest > 0); 267 } while (rest > 0);
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 6abe8a3bd365..a7d89662acf6 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -254,7 +254,7 @@ static struct snd_ca0106_details ca0106_chip_details[] = {
254 .name = "MSI K8N Diamond MB", 254 .name = "MSI K8N Diamond MB",
255 .gpio_type = 2, 255 .gpio_type = 2,
256 .i2c_adc = 1, 256 .i2c_adc = 1,
257 .spi_dac = 2 }, 257 .spi_dac = 2 } ,
258 /* Shuttle XPC SD31P which has an onboard Creative Labs 258 /* Shuttle XPC SD31P which has an onboard Creative Labs
259 * Sound Blaster Live! 24-bit EAX 259 * Sound Blaster Live! 24-bit EAX
260 * high-definition 7.1 audio processor". 260 * high-definition 7.1 audio processor".
diff --git a/sound/pci/ca0106/ca_midi.c b/sound/pci/ca0106/ca_midi.c
index 893ee4f1ea77..c7885117da33 100644
--- a/sound/pci/ca0106/ca_midi.c
+++ b/sound/pci/ca0106/ca_midi.c
@@ -125,7 +125,8 @@ static int ca_midi_input_open(struct snd_rawmidi_substream *substream)
125 struct snd_ca_midi *midi = substream->rmidi->private_data; 125 struct snd_ca_midi *midi = substream->rmidi->private_data;
126 unsigned long flags; 126 unsigned long flags;
127 127
128 snd_assert(midi->dev_id, return -ENXIO); 128 if (snd_BUG_ON(!midi->dev_id))
129 return -ENXIO;
129 spin_lock_irqsave(&midi->open_lock, flags); 130 spin_lock_irqsave(&midi->open_lock, flags);
130 midi->midi_mode |= CA_MIDI_MODE_INPUT; 131 midi->midi_mode |= CA_MIDI_MODE_INPUT;
131 midi->substream_input = substream; 132 midi->substream_input = substream;
@@ -144,7 +145,8 @@ static int ca_midi_output_open(struct snd_rawmidi_substream *substream)
144 struct snd_ca_midi *midi = substream->rmidi->private_data; 145 struct snd_ca_midi *midi = substream->rmidi->private_data;
145 unsigned long flags; 146 unsigned long flags;
146 147
147 snd_assert(midi->dev_id, return -ENXIO); 148 if (snd_BUG_ON(!midi->dev_id))
149 return -ENXIO;
148 spin_lock_irqsave(&midi->open_lock, flags); 150 spin_lock_irqsave(&midi->open_lock, flags);
149 midi->midi_mode |= CA_MIDI_MODE_OUTPUT; 151 midi->midi_mode |= CA_MIDI_MODE_OUTPUT;
150 midi->substream_output = substream; 152 midi->substream_output = substream;
@@ -163,7 +165,8 @@ static int ca_midi_input_close(struct snd_rawmidi_substream *substream)
163 struct snd_ca_midi *midi = substream->rmidi->private_data; 165 struct snd_ca_midi *midi = substream->rmidi->private_data;
164 unsigned long flags; 166 unsigned long flags;
165 167
166 snd_assert(midi->dev_id, return -ENXIO); 168 if (snd_BUG_ON(!midi->dev_id))
169 return -ENXIO;
167 spin_lock_irqsave(&midi->open_lock, flags); 170 spin_lock_irqsave(&midi->open_lock, flags);
168 midi->interrupt_disable(midi,midi->rx_enable); 171 midi->interrupt_disable(midi,midi->rx_enable);
169 midi->midi_mode &= ~CA_MIDI_MODE_INPUT; 172 midi->midi_mode &= ~CA_MIDI_MODE_INPUT;
@@ -181,7 +184,9 @@ static int ca_midi_output_close(struct snd_rawmidi_substream *substream)
181{ 184{
182 struct snd_ca_midi *midi = substream->rmidi->private_data; 185 struct snd_ca_midi *midi = substream->rmidi->private_data;
183 unsigned long flags; 186 unsigned long flags;
184 snd_assert(midi->dev_id, return -ENXIO); 187
188 if (snd_BUG_ON(!midi->dev_id))
189 return -ENXIO;
185 190
186 spin_lock_irqsave(&midi->open_lock, flags); 191 spin_lock_irqsave(&midi->open_lock, flags);
187 192
@@ -201,7 +206,9 @@ static int ca_midi_output_close(struct snd_rawmidi_substream *substream)
201static void ca_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) 206static void ca_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
202{ 207{
203 struct snd_ca_midi *midi = substream->rmidi->private_data; 208 struct snd_ca_midi *midi = substream->rmidi->private_data;
204 snd_assert(midi->dev_id, return); 209
210 if (snd_BUG_ON(!midi->dev_id))
211 return;
205 212
206 if (up) { 213 if (up) {
207 midi->interrupt_enable(midi,midi->rx_enable); 214 midi->interrupt_enable(midi,midi->rx_enable);
@@ -215,7 +222,8 @@ static void ca_midi_output_trigger(struct snd_rawmidi_substream *substream, int
215 struct snd_ca_midi *midi = substream->rmidi->private_data; 222 struct snd_ca_midi *midi = substream->rmidi->private_data;
216 unsigned long flags; 223 unsigned long flags;
217 224
218 snd_assert(midi->dev_id, return); 225 if (snd_BUG_ON(!midi->dev_id))
226 return;
219 227
220 if (up) { 228 if (up) {
221 int max = 4; 229 int max = 4;
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 9971b5b7735b..1a74ca62c314 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2357,7 +2357,8 @@ static int snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,
2357{ 2357{
2358 struct cmipci_switch_args *args; 2358 struct cmipci_switch_args *args;
2359 args = (struct cmipci_switch_args *)kcontrol->private_value; 2359 args = (struct cmipci_switch_args *)kcontrol->private_value;
2360 snd_assert(args != NULL, return -EINVAL); 2360 if (snd_BUG_ON(!args))
2361 return -EINVAL;
2361 return _snd_cmipci_uswitch_get(kcontrol, ucontrol, args); 2362 return _snd_cmipci_uswitch_get(kcontrol, ucontrol, args);
2362} 2363}
2363 2364
@@ -2401,7 +2402,8 @@ static int snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,
2401{ 2402{
2402 struct cmipci_switch_args *args; 2403 struct cmipci_switch_args *args;
2403 args = (struct cmipci_switch_args *)kcontrol->private_value; 2404 args = (struct cmipci_switch_args *)kcontrol->private_value;
2404 snd_assert(args != NULL, return -EINVAL); 2405 if (snd_BUG_ON(!args))
2406 return -EINVAL;
2405 return _snd_cmipci_uswitch_put(kcontrol, ucontrol, args); 2407 return _snd_cmipci_uswitch_put(kcontrol, ucontrol, args);
2406} 2408}
2407 2409
@@ -2662,7 +2664,8 @@ static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_devic
2662 unsigned int idx; 2664 unsigned int idx;
2663 int err; 2665 int err;
2664 2666
2665 snd_assert(cm != NULL && cm->card != NULL, return -EINVAL); 2667 if (snd_BUG_ON(!cm || !cm->card))
2668 return -EINVAL;
2666 2669
2667 card = cm->card; 2670 card = cm->card;
2668 2671
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index 7556fd90d0eb..ef9308f7c45b 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -766,13 +766,13 @@ static void snd_cs4281_mode(struct cs4281 *chip, struct cs4281_dma *dma,
766 if (!capture) { 766 if (!capture) {
767 if (dma->left_slot == chip->src_left_play_slot) { 767 if (dma->left_slot == chip->src_left_play_slot) {
768 unsigned int val = snd_cs4281_rate(runtime->rate, NULL); 768 unsigned int val = snd_cs4281_rate(runtime->rate, NULL);
769 snd_assert(dma->right_slot == chip->src_right_play_slot, ); 769 snd_BUG_ON(dma->right_slot != chip->src_right_play_slot);
770 snd_cs4281_pokeBA0(chip, BA0_DACSR, val); 770 snd_cs4281_pokeBA0(chip, BA0_DACSR, val);
771 } 771 }
772 } else { 772 } else {
773 if (dma->left_slot == chip->src_left_rec_slot) { 773 if (dma->left_slot == chip->src_left_rec_slot) {
774 unsigned int val = snd_cs4281_rate(runtime->rate, NULL); 774 unsigned int val = snd_cs4281_rate(runtime->rate, NULL);
775 snd_assert(dma->right_slot == chip->src_right_rec_slot, ); 775 snd_BUG_ON(dma->right_slot != chip->src_right_rec_slot);
776 snd_cs4281_pokeBA0(chip, BA0_ADCSR, val); 776 snd_cs4281_pokeBA0(chip, BA0_ADCSR, val);
777 } 777 }
778 } 778 }
@@ -1209,7 +1209,8 @@ static void snd_cs4281_gameport_trigger(struct gameport *gameport)
1209{ 1209{
1210 struct cs4281 *chip = gameport_get_port_data(gameport); 1210 struct cs4281 *chip = gameport_get_port_data(gameport);
1211 1211
1212 snd_assert(chip, return); 1212 if (snd_BUG_ON(!chip))
1213 return;
1213 snd_cs4281_pokeBA0(chip, BA0_JSPT, 0xff); 1214 snd_cs4281_pokeBA0(chip, BA0_JSPT, 0xff);
1214} 1215}
1215 1216
@@ -1217,7 +1218,8 @@ static unsigned char snd_cs4281_gameport_read(struct gameport *gameport)
1217{ 1218{
1218 struct cs4281 *chip = gameport_get_port_data(gameport); 1219 struct cs4281 *chip = gameport_get_port_data(gameport);
1219 1220
1220 snd_assert(chip, return 0); 1221 if (snd_BUG_ON(!chip))
1222 return 0;
1221 return snd_cs4281_peekBA0(chip, BA0_JSPT); 1223 return snd_cs4281_peekBA0(chip, BA0_JSPT);
1222} 1224}
1223 1225
@@ -1228,7 +1230,8 @@ static int snd_cs4281_gameport_cooked_read(struct gameport *gameport,
1228 struct cs4281 *chip = gameport_get_port_data(gameport); 1230 struct cs4281 *chip = gameport_get_port_data(gameport);
1229 unsigned js1, js2, jst; 1231 unsigned js1, js2, jst;
1230 1232
1231 snd_assert(chip, return 0); 1233 if (snd_BUG_ON(!chip))
1234 return 0;
1232 1235
1233 js1 = snd_cs4281_peekBA0(chip, BA0_JSC1); 1236 js1 = snd_cs4281_peekBA0(chip, BA0_JSC1);
1234 js2 = snd_cs4281_peekBA0(chip, BA0_JSC2); 1237 js2 = snd_cs4281_peekBA0(chip, BA0_JSC2);
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index e214e567dec8..fb6dc3980257 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -90,9 +90,10 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
90 int count; 90 int count;
91 unsigned short result,tmp; 91 unsigned short result,tmp;
92 u32 offset = 0; 92 u32 offset = 0;
93 snd_assert ( (codec_index == CS46XX_PRIMARY_CODEC_INDEX) || 93
94 (codec_index == CS46XX_SECONDARY_CODEC_INDEX), 94 if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
95 return -EINVAL); 95 codec_index != CS46XX_SECONDARY_CODEC_INDEX))
96 return -EINVAL;
96 97
97 chip->active_ctrl(chip, 1); 98 chip->active_ctrl(chip, 1);
98 99
@@ -212,9 +213,9 @@ static unsigned short snd_cs46xx_ac97_read(struct snd_ac97 * ac97,
212 unsigned short val; 213 unsigned short val;
213 int codec_index = ac97->num; 214 int codec_index = ac97->num;
214 215
215 snd_assert(codec_index == CS46XX_PRIMARY_CODEC_INDEX || 216 if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
216 codec_index == CS46XX_SECONDARY_CODEC_INDEX, 217 codec_index != CS46XX_SECONDARY_CODEC_INDEX))
217 return 0xffff); 218 return 0xffff;
218 219
219 val = snd_cs46xx_codec_read(chip, reg, codec_index); 220 val = snd_cs46xx_codec_read(chip, reg, codec_index);
220 221
@@ -229,9 +230,9 @@ static void snd_cs46xx_codec_write(struct snd_cs46xx *chip,
229{ 230{
230 int count; 231 int count;
231 232
232 snd_assert ((codec_index == CS46XX_PRIMARY_CODEC_INDEX) || 233 if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
233 (codec_index == CS46XX_SECONDARY_CODEC_INDEX), 234 codec_index != CS46XX_SECONDARY_CODEC_INDEX))
234 return); 235 return;
235 236
236 chip->active_ctrl(chip, 1); 237 chip->active_ctrl(chip, 1);
237 238
@@ -294,9 +295,9 @@ static void snd_cs46xx_ac97_write(struct snd_ac97 *ac97,
294 struct snd_cs46xx *chip = ac97->private_data; 295 struct snd_cs46xx *chip = ac97->private_data;
295 int codec_index = ac97->num; 296 int codec_index = ac97->num;
296 297
297 snd_assert(codec_index == CS46XX_PRIMARY_CODEC_INDEX || 298 if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX &&
298 codec_index == CS46XX_SECONDARY_CODEC_INDEX, 299 codec_index != CS46XX_SECONDARY_CODEC_INDEX))
299 return); 300 return;
300 301
301 snd_cs46xx_codec_write(chip, reg, val, codec_index); 302 snd_cs46xx_codec_write(chip, reg, val, codec_index);
302} 303}
@@ -315,7 +316,8 @@ int snd_cs46xx_download(struct snd_cs46xx *chip,
315 unsigned int bank = offset >> 16; 316 unsigned int bank = offset >> 16;
316 offset = offset & 0xffff; 317 offset = offset & 0xffff;
317 318
318 snd_assert(!(offset & 3) && !(len & 3), return -EINVAL); 319 if (snd_BUG_ON((offset & 3) || (len & 3)))
320 return -EINVAL;
319 dst = chip->region.idx[bank+1].remap_addr + offset; 321 dst = chip->region.idx[bank+1].remap_addr + offset;
320 len /= sizeof(u32); 322 len /= sizeof(u32);
321 323
@@ -343,7 +345,8 @@ int snd_cs46xx_clear_BA1(struct snd_cs46xx *chip,
343 unsigned int bank = offset >> 16; 345 unsigned int bank = offset >> 16;
344 offset = offset & 0xffff; 346 offset = offset & 0xffff;
345 347
346 snd_assert(!(offset & 3) && !(len & 3), return -EINVAL); 348 if (snd_BUG_ON((offset & 3) || (len & 3)))
349 return -EINVAL;
347 dst = chip->region.idx[bank+1].remap_addr + offset; 350 dst = chip->region.idx[bank+1].remap_addr + offset;
348 len /= sizeof(u32); 351 len /= sizeof(u32);
349 352
@@ -722,7 +725,9 @@ static snd_pcm_uframes_t snd_cs46xx_playback_direct_pointer(struct snd_pcm_subst
722 struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 725 struct snd_cs46xx *chip = snd_pcm_substream_chip(substream);
723 size_t ptr; 726 size_t ptr;
724 struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; 727 struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data;
725 snd_assert (cpcm->pcm_channel,return -ENXIO); 728
729 if (snd_BUG_ON(!cpcm->pcm_channel))
730 return -ENXIO;
726 731
727#ifdef CONFIG_SND_CS46XX_NEW_DSP 732#ifdef CONFIG_SND_CS46XX_NEW_DSP
728 ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2); 733 ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2);
@@ -740,7 +745,8 @@ static snd_pcm_uframes_t snd_cs46xx_playback_indirect_pointer(struct snd_pcm_sub
740 struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; 745 struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data;
741 746
742#ifdef CONFIG_SND_CS46XX_NEW_DSP 747#ifdef CONFIG_SND_CS46XX_NEW_DSP
743 snd_assert (cpcm->pcm_channel,return -ENXIO); 748 if (snd_BUG_ON(!cpcm->pcm_channel))
749 return -ENXIO;
744 ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2); 750 ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2);
745#else 751#else
746 ptr = snd_cs46xx_peek(chip, BA1_PBA); 752 ptr = snd_cs46xx_peek(chip, BA1_PBA);
@@ -908,7 +914,8 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
908 cpcm = runtime->private_data; 914 cpcm = runtime->private_data;
909 915
910#ifdef CONFIG_SND_CS46XX_NEW_DSP 916#ifdef CONFIG_SND_CS46XX_NEW_DSP
911 snd_assert (sample_rate != 0, return -ENXIO); 917 if (snd_BUG_ON(!sample_rate))
918 return -ENXIO;
912 919
913 mutex_lock(&chip->spos_mutex); 920 mutex_lock(&chip->spos_mutex);
914 921
@@ -917,7 +924,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
917 return -ENXIO; 924 return -ENXIO;
918 } 925 }
919 926
920 snd_assert (cpcm->pcm_channel != NULL); 927 snd_BUG_ON(!cpcm->pcm_channel);
921 if (!cpcm->pcm_channel) { 928 if (!cpcm->pcm_channel) {
922 mutex_unlock(&chip->spos_mutex); 929 mutex_unlock(&chip->spos_mutex);
923 return -ENXIO; 930 return -ENXIO;
@@ -952,7 +959,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
952 } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) { 959 } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) {
953 substream->ops = &snd_cs46xx_playback_iec958_ops; 960 substream->ops = &snd_cs46xx_playback_iec958_ops;
954 } else { 961 } else {
955 snd_assert(0); 962 snd_BUG();
956 } 963 }
957#else 964#else
958 substream->ops = &snd_cs46xx_playback_ops; 965 substream->ops = &snd_cs46xx_playback_ops;
@@ -981,7 +988,7 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
981 } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) { 988 } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) {
982 substream->ops = &snd_cs46xx_playback_indirect_iec958_ops; 989 substream->ops = &snd_cs46xx_playback_indirect_iec958_ops;
983 } else { 990 } else {
984 snd_assert(0); 991 snd_BUG();
985 } 992 }
986#else 993#else
987 substream->ops = &snd_cs46xx_playback_indirect_ops; 994 substream->ops = &snd_cs46xx_playback_indirect_ops;
@@ -1029,7 +1036,8 @@ static int snd_cs46xx_playback_prepare(struct snd_pcm_substream *substream)
1029 cpcm = runtime->private_data; 1036 cpcm = runtime->private_data;
1030 1037
1031#ifdef CONFIG_SND_CS46XX_NEW_DSP 1038#ifdef CONFIG_SND_CS46XX_NEW_DSP
1032 snd_assert (cpcm->pcm_channel != NULL, return -ENXIO); 1039 if (snd_BUG_ON(!cpcm->pcm_channel))
1040 return -ENXIO;
1033 1041
1034 pfie = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2 ); 1042 pfie = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2 );
1035 pfie &= ~0x0000f03f; 1043 pfie &= ~0x0000f03f;
@@ -1714,9 +1722,9 @@ static void snd_cs46xx_mixer_free_ac97(struct snd_ac97 *ac97)
1714{ 1722{
1715 struct snd_cs46xx *chip = ac97->private_data; 1723 struct snd_cs46xx *chip = ac97->private_data;
1716 1724
1717 snd_assert ((ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) || 1725 if (snd_BUG_ON(ac97 != chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] &&
1718 (ac97 == chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]), 1726 ac97 != chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]))
1719 return); 1727 return;
1720 1728
1721 if (ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) { 1729 if (ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) {
1722 chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] = NULL; 1730 chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] = NULL;
@@ -1864,7 +1872,7 @@ static int snd_cs46xx_iec958_put(struct snd_kcontrol *kcontrol,
1864 break; 1872 break;
1865 default: 1873 default:
1866 res = -EINVAL; 1874 res = -EINVAL;
1867 snd_assert(0, (void)0); 1875 snd_BUG(); /* should never happen ... */
1868 } 1876 }
1869 1877
1870 return res; 1878 return res;
@@ -2236,7 +2244,7 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97)
2236 snd_printdd("cs46xx: CODOEC2 mode %04x\n",0x3); 2244 snd_printdd("cs46xx: CODOEC2 mode %04x\n",0x3);
2237 snd_cs46xx_ac97_write(ac97,AC97_CSR_ACMODE,0x3); 2245 snd_cs46xx_ac97_write(ac97,AC97_CSR_ACMODE,0x3);
2238 } else { 2246 } else {
2239 snd_assert(0); /* should never happen ... */ 2247 snd_BUG(); /* should never happen ... */
2240 } 2248 }
2241 2249
2242 udelay(50); 2250 udelay(50);
@@ -2553,7 +2561,8 @@ static void snd_cs46xx_gameport_trigger(struct gameport *gameport)
2553{ 2561{
2554 struct snd_cs46xx *chip = gameport_get_port_data(gameport); 2562 struct snd_cs46xx *chip = gameport_get_port_data(gameport);
2555 2563
2556 snd_assert(chip, return); 2564 if (snd_BUG_ON(!chip))
2565 return;
2557 snd_cs46xx_pokeBA0(chip, BA0_JSPT, 0xFF); //outb(gameport->io, 0xFF); 2566 snd_cs46xx_pokeBA0(chip, BA0_JSPT, 0xFF); //outb(gameport->io, 0xFF);
2558} 2567}
2559 2568
@@ -2561,7 +2570,8 @@ static unsigned char snd_cs46xx_gameport_read(struct gameport *gameport)
2561{ 2570{
2562 struct snd_cs46xx *chip = gameport_get_port_data(gameport); 2571 struct snd_cs46xx *chip = gameport_get_port_data(gameport);
2563 2572
2564 snd_assert(chip, return 0); 2573 if (snd_BUG_ON(!chip))
2574 return 0;
2565 return snd_cs46xx_peekBA0(chip, BA0_JSPT); //inb(gameport->io); 2575 return snd_cs46xx_peekBA0(chip, BA0_JSPT); //inb(gameport->io);
2566} 2576}
2567 2577
@@ -2570,7 +2580,8 @@ static int snd_cs46xx_gameport_cooked_read(struct gameport *gameport, int *axes,
2570 struct snd_cs46xx *chip = gameport_get_port_data(gameport); 2580 struct snd_cs46xx *chip = gameport_get_port_data(gameport);
2571 unsigned js1, js2, jst; 2581 unsigned js1, js2, jst;
2572 2582
2573 snd_assert(chip, return 0); 2583 if (snd_BUG_ON(!chip))
2584 return 0;
2574 2585
2575 js1 = snd_cs46xx_peekBA0(chip, BA0_JSC1); 2586 js1 = snd_cs46xx_peekBA0(chip, BA0_JSC1);
2576 js2 = snd_cs46xx_peekBA0(chip, BA0_JSC2); 2587 js2 = snd_cs46xx_peekBA0(chip, BA0_JSC2);
@@ -2754,7 +2765,8 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2754{ 2765{
2755 int idx; 2766 int idx;
2756 2767
2757 snd_assert(chip != NULL, return -EINVAL); 2768 if (snd_BUG_ON(!chip))
2769 return -EINVAL;
2758 2770
2759 if (chip->active_ctrl) 2771 if (chip->active_ctrl)
2760 chip->active_ctrl(chip, 1); 2772 chip->active_ctrl(chip, 1);
@@ -3489,8 +3501,9 @@ static struct cs_card_type __devinitdata cards[] = {
3489 .name = "Mitac MI6020/21", 3501 .name = "Mitac MI6020/21",
3490 .amp = amp_voyetra, 3502 .amp = amp_voyetra,
3491 }, 3503 },
3504 /* Hercules Game Theatre XP */
3492 { 3505 {
3493 .vendor = 0x14AF, 3506 .vendor = 0x14af, /* Guillemot Corporation */
3494 .id = 0x0050, 3507 .id = 0x0050,
3495 .name = "Hercules Game Theatre XP", 3508 .name = "Hercules Game Theatre XP",
3496 .amp = amp_hercules, 3509 .amp = amp_hercules,
@@ -3532,9 +3545,25 @@ static struct cs_card_type __devinitdata cards[] = {
3532 .amp = amp_hercules, 3545 .amp = amp_hercules,
3533 .mixer_init = hercules_mixer_init, 3546 .mixer_init = hercules_mixer_init,
3534 }, 3547 },
3548 /* Herculess Fortissimo */
3549 {
3550 .vendor = 0x1681,
3551 .id = 0xa010,
3552 .name = "Hercules Gamesurround Fortissimo II",
3553 },
3554 {
3555 .vendor = 0x1681,
3556 .id = 0xa011,
3557 .name = "Hercules Gamesurround Fortissimo III 7.1",
3558 },
3535 /* Teratec */ 3559 /* Teratec */
3536 { 3560 {
3537 .vendor = 0x153b, 3561 .vendor = 0x153b,
3562 .id = 0x112e,
3563 .name = "Terratec DMX XFire 1024",
3564 },
3565 {
3566 .vendor = 0x153b,
3538 .id = 0x1136, 3567 .id = 0x1136,
3539 .name = "Terratec SiXPack 5.1", 3568 .name = "Terratec SiXPack 5.1",
3540 }, 3569 },
diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
index ccc8bedb5b1a..f4f0c8f5dad7 100644
--- a/sound/pci/cs46xx/dsp_spos.c
+++ b/sound/pci/cs46xx/dsp_spos.c
@@ -63,7 +63,8 @@ static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32
63 u32 mop_operands,mop_type,wide_op; 63 u32 mop_operands,mop_type,wide_op;
64 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 64 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
65 65
66 snd_assert( ((size % 2) == 0), return -EINVAL); 66 if (snd_BUG_ON(size %2))
67 return -EINVAL;
67 68
68 while (i < size) { 69 while (i < size) {
69 loval = data[i++]; 70 loval = data[i++];
@@ -289,7 +290,8 @@ void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip)
289 int i; 290 int i;
290 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 291 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
291 292
292 snd_assert(ins != NULL, return); 293 if (snd_BUG_ON(!ins))
294 return;
293 295
294 mutex_lock(&chip->spos_mutex); 296 mutex_lock(&chip->spos_mutex);
295 for (i = 0; i < ins->nscb; ++i) { 297 for (i = 0; i < ins->nscb; ++i) {
@@ -404,7 +406,8 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * m
404 406
405 /* if module has a code segment it must have 407 /* if module has a code segment it must have
406 symbol table */ 408 symbol table */
407 snd_assert(module->symbol_table.symbols != NULL ,return -ENOMEM); 409 if (snd_BUG_ON(!module->symbol_table.symbols))
410 return -ENOMEM;
408 if (add_symbols(chip,module)) { 411 if (add_symbols(chip,module)) {
409 snd_printk(KERN_ERR "dsp_spos: failed to load symbol table\n"); 412 snd_printk(KERN_ERR "dsp_spos: failed to load symbol table\n");
410 return -ENOMEM; 413 return -ENOMEM;
@@ -1369,7 +1372,8 @@ int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
1369 1372
1370 valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV); 1373 valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV);
1371 1374
1372 snd_assert (chip->nr_ac97_codecs == 1 || chip->nr_ac97_codecs == 2); 1375 if (snd_BUG_ON(chip->nr_ac97_codecs != 1 && chip->nr_ac97_codecs != 2))
1376 goto _fail_end;
1373 1377
1374 if (chip->nr_ac97_codecs == 1) { 1378 if (chip->nr_ac97_codecs == 1) {
1375 /* output on slot 5 and 11 1379 /* output on slot 5 and 11
@@ -1609,11 +1613,14 @@ static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
1609 1613
1610 spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST); 1614 spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST);
1611 1615
1612 snd_assert(spdifo_scb_desc, return -EIO); 1616 if (snd_BUG_ON(!spdifo_scb_desc))
1617 return -EIO;
1613 spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST); 1618 spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST);
1614 snd_assert(spdifi_scb_desc, return -EIO); 1619 if (snd_BUG_ON(!spdifi_scb_desc))
1620 return -EIO;
1615 async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB); 1621 async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB);
1616 snd_assert(async_codec_scb_desc, return -EIO); 1622 if (snd_BUG_ON(!async_codec_scb_desc))
1623 return -EIO;
1617 1624
1618 async_codec_scb_desc->parent_scb_ptr = NULL; 1625 async_codec_scb_desc->parent_scb_ptr = NULL;
1619 async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc; 1626 async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc;
@@ -1698,8 +1705,10 @@ int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip)
1698 chip->active_ctrl(chip, 1); 1705 chip->active_ctrl(chip, 1);
1699 chip->amplifier_ctrl(chip, 1); 1706 chip->amplifier_ctrl(chip, 1);
1700 1707
1701 snd_assert (ins->asynch_rx_scb == NULL,return -EINVAL); 1708 if (snd_BUG_ON(ins->asynch_rx_scb))
1702 snd_assert (ins->spdif_in_src != NULL,return -EINVAL); 1709 return -EINVAL;
1710 if (snd_BUG_ON(!ins->spdif_in_src))
1711 return -EINVAL;
1703 1712
1704 mutex_lock(&chip->spos_mutex); 1713 mutex_lock(&chip->spos_mutex);
1705 1714
@@ -1754,8 +1763,10 @@ int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip)
1754{ 1763{
1755 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1764 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1756 1765
1757 snd_assert (ins->asynch_rx_scb != NULL, return -EINVAL); 1766 if (snd_BUG_ON(!ins->asynch_rx_scb))
1758 snd_assert (ins->spdif_in_src != NULL,return -EINVAL); 1767 return -EINVAL;
1768 if (snd_BUG_ON(!ins->spdif_in_src))
1769 return -EINVAL;
1759 1770
1760 mutex_lock(&chip->spos_mutex); 1771 mutex_lock(&chip->spos_mutex);
1761 1772
@@ -1780,8 +1791,10 @@ int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip)
1780{ 1791{
1781 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1792 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1782 1793
1783 snd_assert (ins->pcm_input == NULL,return -EINVAL); 1794 if (snd_BUG_ON(ins->pcm_input))
1784 snd_assert (ins->ref_snoop_scb != NULL,return -EINVAL); 1795 return -EINVAL;
1796 if (snd_BUG_ON(!ins->ref_snoop_scb))
1797 return -EINVAL;
1785 1798
1786 mutex_lock(&chip->spos_mutex); 1799 mutex_lock(&chip->spos_mutex);
1787 ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR, 1800 ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR,
@@ -1795,7 +1808,8 @@ int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip)
1795{ 1808{
1796 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1809 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1797 1810
1798 snd_assert (ins->pcm_input != NULL,return -EINVAL); 1811 if (snd_BUG_ON(!ins->pcm_input))
1812 return -EINVAL;
1799 1813
1800 mutex_lock(&chip->spos_mutex); 1814 mutex_lock(&chip->spos_mutex);
1801 cs46xx_dsp_remove_scb (chip,ins->pcm_input); 1815 cs46xx_dsp_remove_scb (chip,ins->pcm_input);
@@ -1809,8 +1823,10 @@ int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip)
1809{ 1823{
1810 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1824 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1811 1825
1812 snd_assert (ins->adc_input == NULL,return -EINVAL); 1826 if (snd_BUG_ON(ins->adc_input))
1813 snd_assert (ins->codec_in_scb != NULL,return -EINVAL); 1827 return -EINVAL;
1828 if (snd_BUG_ON(!ins->codec_in_scb))
1829 return -EINVAL;
1814 1830
1815 mutex_lock(&chip->spos_mutex); 1831 mutex_lock(&chip->spos_mutex);
1816 ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR, 1832 ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR,
@@ -1824,7 +1840,8 @@ int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip)
1824{ 1840{
1825 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1841 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1826 1842
1827 snd_assert (ins->adc_input != NULL,return -EINVAL); 1843 if (snd_BUG_ON(!ins->adc_input))
1844 return -EINVAL;
1828 1845
1829 mutex_lock(&chip->spos_mutex); 1846 mutex_lock(&chip->spos_mutex);
1830 cs46xx_dsp_remove_scb (chip,ins->adc_input); 1847 cs46xx_dsp_remove_scb (chip,ins->adc_input);
diff --git a/sound/pci/cs46xx/dsp_spos_scb_lib.c b/sound/pci/cs46xx/dsp_spos_scb_lib.c
index 2873cfe48c33..dd7c41b037b4 100644
--- a/sound/pci/cs46xx/dsp_spos_scb_lib.c
+++ b/sound/pci/cs46xx/dsp_spos_scb_lib.c
@@ -46,8 +46,11 @@ static void remove_symbol (struct snd_cs46xx * chip, struct dsp_symbol_entry * s
46 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 46 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
47 int symbol_index = (int)(symbol - ins->symbol_table.symbols); 47 int symbol_index = (int)(symbol - ins->symbol_table.symbols);
48 48
49 snd_assert(ins->symbol_table.nsymbols > 0,return); 49 if (snd_BUG_ON(ins->symbol_table.nsymbols <= 0))
50 snd_assert(symbol_index >= 0 && symbol_index < ins->symbol_table.nsymbols, return); 50 return;
51 if (snd_BUG_ON(symbol_index < 0 ||
52 symbol_index >= ins->symbol_table.nsymbols))
53 return;
51 54
52 ins->symbol_table.symbols[symbol_index].deleted = 1; 55 ins->symbol_table.symbols[symbol_index].deleted = 1;
53 56
@@ -116,8 +119,9 @@ static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor
116 119
117 if ( scb->parent_scb_ptr ) { 120 if ( scb->parent_scb_ptr ) {
118 /* unlink parent SCB */ 121 /* unlink parent SCB */
119 snd_assert ((scb->parent_scb_ptr->sub_list_ptr == scb || 122 if (snd_BUG_ON(scb->parent_scb_ptr->sub_list_ptr != scb &&
120 scb->parent_scb_ptr->next_scb_ptr == scb),return); 123 scb->parent_scb_ptr->next_scb_ptr != scb))
124 return;
121 125
122 if (scb->parent_scb_ptr->sub_list_ptr == scb) { 126 if (scb->parent_scb_ptr->sub_list_ptr == scb) {
123 127
@@ -140,7 +144,6 @@ static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor
140 scb->next_scb_ptr = ins->the_null_scb; 144 scb->next_scb_ptr = ins->the_null_scb;
141 } 145 }
142 } else { 146 } else {
143 /* snd_assert ( (scb->sub_list_ptr == ins->the_null_scb), return); */
144 scb->parent_scb_ptr->next_scb_ptr = scb->next_scb_ptr; 147 scb->parent_scb_ptr->next_scb_ptr = scb->next_scb_ptr;
145 148
146 if (scb->next_scb_ptr != ins->the_null_scb) { 149 if (scb->next_scb_ptr != ins->the_null_scb) {
@@ -181,16 +184,17 @@ void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor *
181 unsigned long flags; 184 unsigned long flags;
182 185
183 /* check integrety */ 186 /* check integrety */
184 snd_assert ( (scb->index >= 0 && 187 if (snd_BUG_ON(scb->index < 0 ||
185 scb->index < ins->nscb && 188 scb->index >= ins->nscb ||
186 (ins->scbs + scb->index) == scb), return ); 189 (ins->scbs + scb->index) != scb))
190 return;
187 191
188#if 0 192#if 0
189 /* can't remove a SCB with childs before 193 /* can't remove a SCB with childs before
190 removing childs first */ 194 removing childs first */
191 snd_assert ( (scb->sub_list_ptr == ins->the_null_scb && 195 if (snd_BUG_ON(scb->sub_list_ptr != ins->the_null_scb ||
192 scb->next_scb_ptr == ins->the_null_scb), 196 scb->next_scb_ptr != ins->the_null_scb))
193 goto _end); 197 goto _end;
194#endif 198#endif
195 199
196 spin_lock_irqsave(&scb->lock, flags); 200 spin_lock_irqsave(&scb->lock, flags);
@@ -198,7 +202,8 @@ void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor *
198 spin_unlock_irqrestore(&scb->lock, flags); 202 spin_unlock_irqrestore(&scb->lock, flags);
199 203
200 cs46xx_dsp_proc_free_scb_desc(scb); 204 cs46xx_dsp_proc_free_scb_desc(scb);
201 snd_assert (scb->scb_symbol != NULL, return ); 205 if (snd_BUG_ON(!scb->scb_symbol))
206 return;
202 remove_symbol (chip,scb->scb_symbol); 207 remove_symbol (chip,scb->scb_symbol);
203 208
204 ins->scbs[scb->index].deleted = 1; 209 ins->scbs[scb->index].deleted = 1;
@@ -234,7 +239,6 @@ void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb)
234 snd_info_free_entry(scb->proc_info); 239 snd_info_free_entry(scb->proc_info);
235 scb->proc_info = NULL; 240 scb->proc_info = NULL;
236 241
237 snd_assert (scb_info != NULL, return);
238 kfree (scb_info); 242 kfree (scb_info);
239 } 243 }
240} 244}
@@ -291,7 +295,8 @@ _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u
291 295
292 unsigned long flags; 296 unsigned long flags;
293 297
294 snd_assert (ins->the_null_scb != NULL,return NULL); 298 if (snd_BUG_ON(!ins->the_null_scb))
299 return NULL;
295 300
296 /* fill the data that will be wroten to DSP */ 301 /* fill the data that will be wroten to DSP */
297 scb_data[SCBsubListPtr] = 302 scb_data[SCBsubListPtr] =
@@ -321,18 +326,20 @@ _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u
321#endif 326#endif
322 /* link to parent SCB */ 327 /* link to parent SCB */
323 if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) { 328 if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) {
324 snd_assert ( (scb->parent_scb_ptr->next_scb_ptr == ins->the_null_scb), 329 if (snd_BUG_ON(scb->parent_scb_ptr->next_scb_ptr !=
325 return NULL); 330 ins->the_null_scb))
331 return NULL;
326 332
327 scb->parent_scb_ptr->next_scb_ptr = scb; 333 scb->parent_scb_ptr->next_scb_ptr = scb;
328 334
329 } else if (scb_child_type == SCB_ON_PARENT_SUBLIST_SCB) { 335 } else if (scb_child_type == SCB_ON_PARENT_SUBLIST_SCB) {
330 snd_assert ( (scb->parent_scb_ptr->sub_list_ptr == ins->the_null_scb), 336 if (snd_BUG_ON(scb->parent_scb_ptr->sub_list_ptr !=
331 return NULL); 337 ins->the_null_scb))
338 return NULL;
332 339
333 scb->parent_scb_ptr->sub_list_ptr = scb; 340 scb->parent_scb_ptr->sub_list_ptr = scb;
334 } else { 341 } else {
335 snd_assert (0,return NULL); 342 snd_BUG();
336 } 343 }
337 344
338 spin_lock_irqsave(&chip->reg_lock, flags); 345 spin_lock_irqsave(&chip->reg_lock, flags);
@@ -675,7 +682,7 @@ cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
675 if (pass_through) { 682 if (pass_through) {
676 /* wont work with any other rate than 683 /* wont work with any other rate than
677 the native DSP rate */ 684 the native DSP rate */
678 snd_assert (rate == 48000); 685 snd_BUG_ON(rate != 48000);
679 686
680 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb, 687 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
681 dest,"DMAREADER",parent_scb, 688 dest,"DMAREADER",parent_scb,
@@ -1142,7 +1149,8 @@ find_next_free_scb (struct snd_cs46xx * chip, struct dsp_scb_descriptor * from)
1142 struct dsp_scb_descriptor * scb = from; 1149 struct dsp_scb_descriptor * scb = from;
1143 1150
1144 while (scb->next_scb_ptr != ins->the_null_scb) { 1151 while (scb->next_scb_ptr != ins->the_null_scb) {
1145 snd_assert (scb->next_scb_ptr != NULL, return NULL); 1152 if (snd_BUG_ON(!scb->next_scb_ptr))
1153 return NULL;
1146 1154
1147 scb = scb->next_scb_ptr; 1155 scb = scb->next_scb_ptr;
1148 } 1156 }
@@ -1246,10 +1254,11 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1246 break; 1254 break;
1247 case DSP_PCM_S71_CHANNEL: 1255 case DSP_PCM_S71_CHANNEL:
1248 /* TODO */ 1256 /* TODO */
1249 snd_assert(0); 1257 snd_BUG();
1250 break; 1258 break;
1251 case DSP_IEC958_CHANNEL: 1259 case DSP_IEC958_CHANNEL:
1252 snd_assert (ins->asynch_tx_scb != NULL, return NULL); 1260 if (snd_BUG_ON(!ins->asynch_tx_scb))
1261 return NULL;
1253 mixer_scb = ins->asynch_tx_scb; 1262 mixer_scb = ins->asynch_tx_scb;
1254 1263
1255 /* if sample rate is set to 48khz we pass 1264 /* if sample rate is set to 48khz we pass
@@ -1262,7 +1271,7 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1262 } 1271 }
1263 break; 1272 break;
1264 default: 1273 default:
1265 snd_assert (0); 1274 snd_BUG();
1266 return NULL; 1275 return NULL;
1267 } 1276 }
1268 /* default sample rate is 44100 */ 1277 /* default sample rate is 44100 */
@@ -1308,7 +1317,8 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1308 break; 1317 break;
1309 } 1318 }
1310 } 1319 }
1311 snd_assert (src_index != -1,return NULL); 1320 if (snd_BUG_ON(src_index == -1))
1321 return NULL;
1312 1322
1313 /* we need to create a new SRC SCB */ 1323 /* we need to create a new SRC SCB */
1314 if (mixer_scb->sub_list_ptr == ins->the_null_scb) { 1324 if (mixer_scb->sub_list_ptr == ins->the_null_scb) {
@@ -1462,9 +1472,10 @@ void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
1462 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1472 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1463 unsigned long flags; 1473 unsigned long flags;
1464 1474
1465 snd_assert(pcm_channel->active, return ); 1475 if (snd_BUG_ON(!pcm_channel->active ||
1466 snd_assert(ins->npcm_channels > 0, return ); 1476 ins->npcm_channels <= 0 ||
1467 snd_assert(pcm_channel->src_scb->ref_count > 0, return ); 1477 pcm_channel->src_scb->ref_count <= 0))
1478 return;
1468 1479
1469 spin_lock_irqsave(&chip->reg_lock, flags); 1480 spin_lock_irqsave(&chip->reg_lock, flags);
1470 pcm_channel->unlinked = 1; 1481 pcm_channel->unlinked = 1;
@@ -1479,8 +1490,9 @@ void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
1479 if (!pcm_channel->src_scb->ref_count) { 1490 if (!pcm_channel->src_scb->ref_count) {
1480 cs46xx_dsp_remove_scb(chip,pcm_channel->src_scb); 1491 cs46xx_dsp_remove_scb(chip,pcm_channel->src_scb);
1481 1492
1482 snd_assert (pcm_channel->src_slot >= 0 && pcm_channel->src_slot < DSP_MAX_SRC_NR, 1493 if (snd_BUG_ON(pcm_channel->src_slot < 0 ||
1483 return ); 1494 pcm_channel->src_slot >= DSP_MAX_SRC_NR))
1495 return;
1484 1496
1485 ins->src_scb_slots[pcm_channel->src_slot] = 0; 1497 ins->src_scb_slots[pcm_channel->src_slot] = 0;
1486 ins->nsrc_scb --; 1498 ins->nsrc_scb --;
@@ -1490,11 +1502,11 @@ void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
1490int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip, 1502int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
1491 struct dsp_pcm_channel_descriptor * pcm_channel) 1503 struct dsp_pcm_channel_descriptor * pcm_channel)
1492{ 1504{
1493 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1494 unsigned long flags; 1505 unsigned long flags;
1495 1506
1496 snd_assert(pcm_channel->active,return -EIO); 1507 if (snd_BUG_ON(!pcm_channel->active ||
1497 snd_assert(ins->npcm_channels > 0,return -EIO); 1508 chip->dsp_spos_instance->npcm_channels <= 0))
1509 return -EIO;
1498 1510
1499 spin_lock(&pcm_channel->src_scb->lock); 1511 spin_lock(&pcm_channel->src_scb->lock);
1500 1512
@@ -1537,7 +1549,7 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
1537 1549
1538 src_scb->sub_list_ptr = pcm_channel->pcm_reader_scb; 1550 src_scb->sub_list_ptr = pcm_channel->pcm_reader_scb;
1539 1551
1540 snd_assert (pcm_channel->pcm_reader_scb->parent_scb_ptr == NULL, ; ); 1552 snd_BUG_ON(pcm_channel->pcm_reader_scb->parent_scb_ptr);
1541 pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb; 1553 pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb;
1542 1554
1543 spin_lock_irqsave(&chip->reg_lock, flags); 1555 spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1564,7 +1576,8 @@ cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * s
1564 struct dsp_scb_descriptor * pcm_input; 1576 struct dsp_scb_descriptor * pcm_input;
1565 int insert_point; 1577 int insert_point;
1566 1578
1567 snd_assert (ins->record_mixer_scb != NULL,return NULL); 1579 if (snd_BUG_ON(!ins->record_mixer_scb))
1580 return NULL;
1568 1581
1569 if (ins->record_mixer_scb->sub_list_ptr != ins->the_null_scb) { 1582 if (ins->record_mixer_scb->sub_list_ptr != ins->the_null_scb) {
1570 parent = find_next_free_scb (chip,ins->record_mixer_scb->sub_list_ptr); 1583 parent = find_next_free_scb (chip,ins->record_mixer_scb->sub_list_ptr);
@@ -1583,7 +1596,8 @@ cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * s
1583 1596
1584int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src) 1597int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
1585{ 1598{
1586 snd_assert (src->parent_scb_ptr != NULL, return -EINVAL ); 1599 if (snd_BUG_ON(!src->parent_scb_ptr))
1600 return -EINVAL;
1587 1601
1588 /* mute SCB */ 1602 /* mute SCB */
1589 cs46xx_dsp_scb_set_volume (chip,src,0,0); 1603 cs46xx_dsp_scb_set_volume (chip,src,0,0);
@@ -1598,8 +1612,10 @@ int cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
1598 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1612 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1599 struct dsp_scb_descriptor * parent_scb; 1613 struct dsp_scb_descriptor * parent_scb;
1600 1614
1601 snd_assert (src->parent_scb_ptr == NULL, return -EINVAL ); 1615 if (snd_BUG_ON(src->parent_scb_ptr))
1602 snd_assert(ins->master_mix_scb !=NULL, return -EINVAL ); 1616 return -EINVAL;
1617 if (snd_BUG_ON(!ins->master_mix_scb))
1618 return -EINVAL;
1603 1619
1604 if (ins->master_mix_scb->sub_list_ptr != ins->the_null_scb) { 1620 if (ins->master_mix_scb->sub_list_ptr != ins->the_null_scb) {
1605 parent_scb = find_next_free_scb (chip,ins->master_mix_scb->sub_list_ptr); 1621 parent_scb = find_next_free_scb (chip,ins->master_mix_scb->sub_list_ptr);
@@ -1635,8 +1651,11 @@ int cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip)
1635 return -EBUSY; 1651 return -EBUSY;
1636 } 1652 }
1637 1653
1638 snd_assert (ins->asynch_tx_scb == NULL, return -EINVAL); 1654 if (snd_BUG_ON(ins->asynch_tx_scb))
1639 snd_assert (ins->master_mix_scb->next_scb_ptr == ins->the_null_scb, return -EINVAL); 1655 return -EINVAL;
1656 if (snd_BUG_ON(ins->master_mix_scb->next_scb_ptr !=
1657 ins->the_null_scb))
1658 return -EINVAL;
1640 1659
1641 /* reset output snooper sample buffer pointer */ 1660 /* reset output snooper sample buffer pointer */
1642 snd_cs46xx_poke (chip, (ins->ref_snoop_scb->address + 2) << 2, 1661 snd_cs46xx_poke (chip, (ins->ref_snoop_scb->address + 2) << 2,
@@ -1676,10 +1695,15 @@ int cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip)
1676 } 1695 }
1677 1696
1678 /* check integrety */ 1697 /* check integrety */
1679 snd_assert (ins->asynch_tx_scb != NULL, return -EINVAL); 1698 if (snd_BUG_ON(!ins->asynch_tx_scb))
1680 snd_assert (ins->spdif_pcm_input_scb != NULL,return -EINVAL); 1699 return -EINVAL;
1681 snd_assert (ins->master_mix_scb->next_scb_ptr == ins->asynch_tx_scb, return -EINVAL); 1700 if (snd_BUG_ON(!ins->spdif_pcm_input_scb))
1682 snd_assert (ins->asynch_tx_scb->parent_scb_ptr == ins->master_mix_scb, return -EINVAL); 1701 return -EINVAL;
1702 if (snd_BUG_ON(ins->master_mix_scb->next_scb_ptr != ins->asynch_tx_scb))
1703 return -EINVAL;
1704 if (snd_BUG_ON(ins->asynch_tx_scb->parent_scb_ptr !=
1705 ins->master_mix_scb))
1706 return -EINVAL;
1683 1707
1684 cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb); 1708 cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb);
1685 cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb); 1709 cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb);
@@ -1734,7 +1758,8 @@ int cs46xx_iec958_post_close (struct snd_cs46xx *chip)
1734{ 1758{
1735 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 1759 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1736 1760
1737 snd_assert (ins->asynch_tx_scb != NULL, return -EINVAL); 1761 if (snd_BUG_ON(!ins->asynch_tx_scb))
1762 return -EINVAL;
1738 1763
1739 ins->spdif_status_out &= ~DSP_SPDIF_STATUS_PLAYBACK_OPEN; 1764 ins->spdif_status_out &= ~DSP_SPDIF_STATUS_PLAYBACK_OPEN;
1740 1765
diff --git a/sound/pci/echoaudio/darla20_dsp.c b/sound/pci/echoaudio/darla20_dsp.c
index 4159e3bc186f..29043301ebb8 100644
--- a/sound/pci/echoaudio/darla20_dsp.c
+++ b/sound/pci/echoaudio/darla20_dsp.c
@@ -34,7 +34,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
34 int err; 34 int err;
35 35
36 DE_INIT(("init_hw() - Darla20\n")); 36 DE_INIT(("init_hw() - Darla20\n"));
37 snd_assert((subdevice_id & 0xfff0) == DARLA20, return -ENODEV); 37 if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA20))
38 return -ENODEV;
38 39
39 if ((err = init_dsp_comm_page(chip))) { 40 if ((err = init_dsp_comm_page(chip))) {
40 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 41 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
diff --git a/sound/pci/echoaudio/darla24_dsp.c b/sound/pci/echoaudio/darla24_dsp.c
index 79938eed7e9c..60228731841f 100644
--- a/sound/pci/echoaudio/darla24_dsp.c
+++ b/sound/pci/echoaudio/darla24_dsp.c
@@ -34,7 +34,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
34 int err; 34 int err;
35 35
36 DE_INIT(("init_hw() - Darla24\n")); 36 DE_INIT(("init_hw() - Darla24\n"));
37 snd_assert((subdevice_id & 0xfff0) == DARLA24, return -ENODEV); 37 if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA24))
38 return -ENODEV;
38 39
39 if ((err = init_dsp_comm_page(chip))) { 40 if ((err = init_dsp_comm_page(chip))) {
40 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 41 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -148,8 +149,9 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
148 149
149static int set_input_clock(struct echoaudio *chip, u16 clock) 150static int set_input_clock(struct echoaudio *chip, u16 clock)
150{ 151{
151 snd_assert(clock == ECHO_CLOCK_INTERNAL || 152 if (snd_BUG_ON(clock != ECHO_CLOCK_INTERNAL &&
152 clock == ECHO_CLOCK_ESYNC, return -EINVAL); 153 clock != ECHO_CLOCK_ESYNC))
154 return -EINVAL;
153 chip->input_clock = clock; 155 chip->input_clock = clock;
154 return set_sample_rate(chip, chip->sample_rate); 156 return set_sample_rate(chip, chip->sample_rate);
155} 157}
diff --git a/sound/pci/echoaudio/echo3g_dsp.c b/sound/pci/echoaudio/echo3g_dsp.c
index 48eb7c599111..417e25add82b 100644
--- a/sound/pci/echoaudio/echo3g_dsp.c
+++ b/sound/pci/echoaudio/echo3g_dsp.c
@@ -47,7 +47,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
47 47
48 local_irq_enable(); 48 local_irq_enable();
49 DE_INIT(("init_hw() - Echo3G\n")); 49 DE_INIT(("init_hw() - Echo3G\n"));
50 snd_assert((subdevice_id & 0xfff0) == ECHO3G, return -ENODEV); 50 if (snd_BUG_ON((subdevice_id & 0xfff0) != ECHO3G))
51 return -ENODEV;
51 52
52 if ((err = init_dsp_comm_page(chip))) { 53 if ((err = init_dsp_comm_page(chip))) {
53 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 54 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -104,9 +105,11 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
104 if ((err = init_line_levels(chip)) < 0) 105 if ((err = init_line_levels(chip)) < 0)
105 return err; 106 return err;
106 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA); 107 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
107 snd_assert(err >= 0, return err); 108 if (err < 0)
109 return err;
108 err = set_phantom_power(chip, 0); 110 err = set_phantom_power(chip, 0);
109 snd_assert(err >= 0, return err); 111 if (err < 0)
112 return err;
110 err = set_professional_spdif(chip, TRUE); 113 err = set_professional_spdif(chip, TRUE);
111 114
112 DE_INIT(("init_hw done\n")); 115 DE_INIT(("init_hw done\n"));
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index e16dc92e82fb..8dbc5c4ba421 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -490,7 +490,6 @@ static int init_engine(struct snd_pcm_substream *substream,
490{ 490{
491 struct echoaudio *chip; 491 struct echoaudio *chip;
492 int err, per, rest, page, edge, offs; 492 int err, per, rest, page, edge, offs;
493 struct snd_sg_buf *sgbuf;
494 struct audiopipe *pipe; 493 struct audiopipe *pipe;
495 494
496 chip = snd_pcm_substream_chip(substream); 495 chip = snd_pcm_substream_chip(substream);
@@ -503,7 +502,7 @@ static int init_engine(struct snd_pcm_substream *substream,
503 if (pipe->index >= 0) { 502 if (pipe->index >= 0) {
504 DE_HWP(("hwp_ie free(%d)\n", pipe->index)); 503 DE_HWP(("hwp_ie free(%d)\n", pipe->index));
505 err = free_pipes(chip, pipe); 504 err = free_pipes(chip, pipe);
506 snd_assert(!err); 505 snd_BUG_ON(err);
507 chip->substream[pipe->index] = NULL; 506 chip->substream[pipe->index] = NULL;
508 } 507 }
509 508
@@ -531,10 +530,6 @@ static int init_engine(struct snd_pcm_substream *substream,
531 return err; 530 return err;
532 } 531 }
533 532
534 sgbuf = snd_pcm_substream_sgbuf(substream);
535
536 DE_HWP(("pcm_hw_params table size=%d pages=%d\n",
537 sgbuf->size, sgbuf->pages));
538 sglist_init(chip, pipe); 533 sglist_init(chip, pipe);
539 edge = PAGE_SIZE; 534 edge = PAGE_SIZE;
540 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params); 535 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
@@ -543,16 +538,15 @@ static int init_engine(struct snd_pcm_substream *substream,
543 if (offs + rest > params_buffer_bytes(hw_params)) 538 if (offs + rest > params_buffer_bytes(hw_params))
544 rest = params_buffer_bytes(hw_params) - offs; 539 rest = params_buffer_bytes(hw_params) - offs;
545 while (rest) { 540 while (rest) {
541 dma_addr_t addr;
542 addr = snd_pcm_sgbuf_get_addr(substream, offs);
546 if (rest <= edge - offs) { 543 if (rest <= edge - offs) {
547 sglist_add_mapping(chip, pipe, 544 sglist_add_mapping(chip, pipe, addr, rest);
548 snd_sgbuf_get_addr(sgbuf, offs),
549 rest);
550 sglist_add_irq(chip, pipe); 545 sglist_add_irq(chip, pipe);
551 offs += rest; 546 offs += rest;
552 rest = 0; 547 rest = 0;
553 } else { 548 } else {
554 sglist_add_mapping(chip, pipe, 549 sglist_add_mapping(chip, pipe, addr,
555 snd_sgbuf_get_addr(sgbuf, offs),
556 edge - offs); 550 edge - offs);
557 rest -= edge - offs; 551 rest -= edge - offs;
558 offs = edge; 552 offs = edge;
@@ -690,8 +684,10 @@ static int pcm_prepare(struct snd_pcm_substream *substream)
690 return -EINVAL; 684 return -EINVAL;
691 } 685 }
692 686
693 snd_assert(pipe_index < px_num(chip), return -EINVAL); 687 if (snd_BUG_ON(pipe_index >= px_num(chip)))
694 snd_assert(is_pipe_allocated(chip, pipe_index), return -EINVAL); 688 return -EINVAL;
689 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
690 return -EINVAL;
695 set_audio_format(chip, pipe_index, &format); 691 set_audio_format(chip, pipe_index, &format);
696 return 0; 692 return 0;
697} 693}
diff --git a/sound/pci/echoaudio/echoaudio_3g.c b/sound/pci/echoaudio/echoaudio_3g.c
index 52a933189576..c3736bbd819e 100644
--- a/sound/pci/echoaudio/echoaudio_3g.c
+++ b/sound/pci/echoaudio/echoaudio_3g.c
@@ -103,9 +103,11 @@ static int set_digital_mode(struct echoaudio *chip, u8 mode)
103 int err, i, o; 103 int err, i, o;
104 104
105 /* All audio channels must be closed before changing the digital mode */ 105 /* All audio channels must be closed before changing the digital mode */
106 snd_assert(!chip->pipe_alloc_mask, return -EAGAIN); 106 if (snd_BUG_ON(chip->pipe_alloc_mask))
107 return -EAGAIN;
107 108
108 snd_assert(chip->digital_modes & (1 << mode), return -EINVAL); 109 if (snd_BUG_ON(!(chip->digital_modes & (1 << mode))))
110 return -EINVAL;
109 111
110 previous_mode = chip->digital_mode; 112 previous_mode = chip->digital_mode;
111 err = dsp_set_digital_mode(chip, mode); 113 err = dsp_set_digital_mode(chip, mode);
@@ -267,8 +269,9 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
267 return 0; 269 return 0;
268 } 270 }
269 271
270 snd_assert(rate < 50000 || chip->digital_mode != DIGITAL_MODE_ADAT, 272 if (snd_BUG_ON(rate >= 50000 &&
271 return -EINVAL); 273 chip->digital_mode == DIGITAL_MODE_ADAT))
274 return -EINVAL;
272 275
273 clock = 0; 276 clock = 0;
274 control_reg = le32_to_cpu(chip->comm_page->control_register); 277 control_reg = le32_to_cpu(chip->comm_page->control_register);
diff --git a/sound/pci/echoaudio/echoaudio_dsp.c b/sound/pci/echoaudio/echoaudio_dsp.c
index e6c100770392..be0e18192de3 100644
--- a/sound/pci/echoaudio/echoaudio_dsp.c
+++ b/sound/pci/echoaudio/echoaudio_dsp.c
@@ -474,7 +474,8 @@ static int load_firmware(struct echoaudio *chip)
474 const struct firmware *fw; 474 const struct firmware *fw;
475 int box_type, err; 475 int box_type, err;
476 476
477 snd_assert(chip->dsp_code_to_load && chip->comm_page, return -EPERM); 477 if (snd_BUG_ON(!chip->dsp_code_to_load || !chip->comm_page))
478 return -EPERM;
478 479
479 /* See if the ASIC is present and working - only if the DSP is already loaded */ 480 /* See if the ASIC is present and working - only if the DSP is already loaded */
480 if (chip->dsp_code) { 481 if (chip->dsp_code) {
@@ -512,8 +513,8 @@ static int load_firmware(struct echoaudio *chip)
512/* Set the nominal level for an input or output bus (true = -10dBV, false = +4dBu) */ 513/* Set the nominal level for an input or output bus (true = -10dBV, false = +4dBu) */
513static int set_nominal_level(struct echoaudio *chip, u16 index, char consumer) 514static int set_nominal_level(struct echoaudio *chip, u16 index, char consumer)
514{ 515{
515 snd_assert(index < num_busses_out(chip) + num_busses_in(chip), 516 if (snd_BUG_ON(index >= num_busses_out(chip) + num_busses_in(chip)))
516 return -EINVAL); 517 return -EINVAL;
517 518
518 /* Wait for the handshake (OK even if ASIC is not loaded) */ 519 /* Wait for the handshake (OK even if ASIC is not loaded) */
519 if (wait_handshake(chip)) 520 if (wait_handshake(chip))
@@ -536,7 +537,8 @@ static int set_nominal_level(struct echoaudio *chip, u16 index, char consumer)
536/* Set the gain for a single physical output channel (dB). */ 537/* Set the gain for a single physical output channel (dB). */
537static int set_output_gain(struct echoaudio *chip, u16 channel, s8 gain) 538static int set_output_gain(struct echoaudio *chip, u16 channel, s8 gain)
538{ 539{
539 snd_assert(channel < num_busses_out(chip), return -EINVAL); 540 if (snd_BUG_ON(channel >= num_busses_out(chip)))
541 return -EINVAL;
540 542
541 if (wait_handshake(chip)) 543 if (wait_handshake(chip))
542 return -EIO; 544 return -EIO;
@@ -554,8 +556,9 @@ static int set_output_gain(struct echoaudio *chip, u16 channel, s8 gain)
554static int set_monitor_gain(struct echoaudio *chip, u16 output, u16 input, 556static int set_monitor_gain(struct echoaudio *chip, u16 output, u16 input,
555 s8 gain) 557 s8 gain)
556{ 558{
557 snd_assert(output < num_busses_out(chip) && 559 if (snd_BUG_ON(output >= num_busses_out(chip) ||
558 input < num_busses_in(chip), return -EINVAL); 560 input >= num_busses_in(chip)))
561 return -EINVAL;
559 562
560 if (wait_handshake(chip)) 563 if (wait_handshake(chip))
561 return -EIO; 564 return -EIO;
@@ -1065,8 +1068,10 @@ static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe)
1065 int i; 1068 int i;
1066 1069
1067 DE_ACT(("free_pipes: Pipe %d\n", pipe->index)); 1070 DE_ACT(("free_pipes: Pipe %d\n", pipe->index));
1068 snd_assert(is_pipe_allocated(chip, pipe->index), return -EINVAL); 1071 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe->index)))
1069 snd_assert(pipe->state == PIPE_STATE_STOPPED, return -EINVAL); 1072 return -EINVAL;
1073 if (snd_BUG_ON(pipe->state != PIPE_STATE_STOPPED))
1074 return -EINVAL;
1070 1075
1071 for (channel_mask = i = 0; i < pipe->interleave; i++) 1076 for (channel_mask = i = 0; i < pipe->interleave; i++)
1072 channel_mask |= 1 << (pipe->index + i); 1077 channel_mask |= 1 << (pipe->index + i);
diff --git a/sound/pci/echoaudio/echoaudio_gml.c b/sound/pci/echoaudio/echoaudio_gml.c
index 3aa37e76ebab..afa273330e8a 100644
--- a/sound/pci/echoaudio/echoaudio_gml.c
+++ b/sound/pci/echoaudio/echoaudio_gml.c
@@ -112,9 +112,11 @@ static int set_digital_mode(struct echoaudio *chip, u8 mode)
112 return -EIO; 112 return -EIO;
113 113
114 /* All audio channels must be closed before changing the digital mode */ 114 /* All audio channels must be closed before changing the digital mode */
115 snd_assert(!chip->pipe_alloc_mask, return -EAGAIN); 115 if (snd_BUG_ON(chip->pipe_alloc_mask))
116 return -EAGAIN;
116 117
117 snd_assert(chip->digital_modes & (1 << mode), return -EINVAL); 118 if (snd_BUG_ON(!(chip->digital_modes & (1 << mode))))
119 return -EINVAL;
118 120
119 previous_mode = chip->digital_mode; 121 previous_mode = chip->digital_mode;
120 err = dsp_set_digital_mode(chip, mode); 122 err = dsp_set_digital_mode(chip, mode);
diff --git a/sound/pci/echoaudio/gina20_dsp.c b/sound/pci/echoaudio/gina20_dsp.c
index 2757c8960843..db6c952e9d7f 100644
--- a/sound/pci/echoaudio/gina20_dsp.c
+++ b/sound/pci/echoaudio/gina20_dsp.c
@@ -38,7 +38,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
38 int err; 38 int err;
39 39
40 DE_INIT(("init_hw() - Gina20\n")); 40 DE_INIT(("init_hw() - Gina20\n"));
41 snd_assert((subdevice_id & 0xfff0) == GINA20, return -ENODEV); 41 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA20))
42 return -ENODEV;
42 43
43 if ((err = init_dsp_comm_page(chip))) { 44 if ((err = init_dsp_comm_page(chip))) {
44 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 45 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -177,7 +178,8 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
177/* Set input bus gain (one unit is 0.5dB !) */ 178/* Set input bus gain (one unit is 0.5dB !) */
178static int set_input_gain(struct echoaudio *chip, u16 input, int gain) 179static int set_input_gain(struct echoaudio *chip, u16 input, int gain)
179{ 180{
180 snd_assert(input < num_busses_in(chip), return -EINVAL); 181 if (snd_BUG_ON(input >= num_busses_in(chip)))
182 return -EINVAL;
181 183
182 if (wait_handshake(chip)) 184 if (wait_handshake(chip))
183 return -EIO; 185 return -EIO;
diff --git a/sound/pci/echoaudio/gina24_dsp.c b/sound/pci/echoaudio/gina24_dsp.c
index 144fc567becf..2fef37a2a5b9 100644
--- a/sound/pci/echoaudio/gina24_dsp.c
+++ b/sound/pci/echoaudio/gina24_dsp.c
@@ -43,7 +43,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
43 int err; 43 int err;
44 44
45 DE_INIT(("init_hw() - Gina24\n")); 45 DE_INIT(("init_hw() - Gina24\n"));
46 snd_assert((subdevice_id & 0xfff0) == GINA24, return -ENODEV); 46 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA24))
47 return -ENODEV;
47 48
48 if ((err = init_dsp_comm_page(chip))) { 49 if ((err = init_dsp_comm_page(chip))) {
49 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 50 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -84,7 +85,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
84 if ((err = init_line_levels(chip)) < 0) 85 if ((err = init_line_levels(chip)) < 0)
85 return err; 86 return err;
86 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA); 87 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
87 snd_assert(err >= 0, return err); 88 if (err < 0)
89 return err;
88 err = set_professional_spdif(chip, TRUE); 90 err = set_professional_spdif(chip, TRUE);
89 91
90 DE_INIT(("init_hw done\n")); 92 DE_INIT(("init_hw done\n"));
@@ -163,8 +165,9 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
163{ 165{
164 u32 control_reg, clock; 166 u32 control_reg, clock;
165 167
166 snd_assert(rate < 50000 || chip->digital_mode != DIGITAL_MODE_ADAT, 168 if (snd_BUG_ON(rate >= 50000 &&
167 return -EINVAL); 169 chip->digital_mode == DIGITAL_MODE_ADAT))
170 return -EINVAL;
168 171
169 /* Only set the clock for internal mode. */ 172 /* Only set the clock for internal mode. */
170 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 173 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
diff --git a/sound/pci/echoaudio/indigo_dsp.c b/sound/pci/echoaudio/indigo_dsp.c
index d6ac7734609e..f05e39f7aad9 100644
--- a/sound/pci/echoaudio/indigo_dsp.c
+++ b/sound/pci/echoaudio/indigo_dsp.c
@@ -39,7 +39,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
39 int err; 39 int err;
40 40
41 DE_INIT(("init_hw() - Indigo\n")); 41 DE_INIT(("init_hw() - Indigo\n"));
42 snd_assert((subdevice_id & 0xfff0) == INDIGO, return -ENODEV); 42 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO))
43 return -ENODEV;
43 44
44 if ((err = init_dsp_comm_page(chip))) { 45 if ((err = init_dsp_comm_page(chip))) {
45 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 46 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -143,8 +144,9 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
143{ 144{
144 int index; 145 int index;
145 146
146 snd_assert(pipe < num_pipes_out(chip) && 147 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
147 output < num_busses_out(chip), return -EINVAL); 148 output >= num_busses_out(chip)))
149 return -EINVAL;
148 150
149 if (wait_handshake(chip)) 151 if (wait_handshake(chip))
150 return -EIO; 152 return -EIO;
diff --git a/sound/pci/echoaudio/indigodj_dsp.c b/sound/pci/echoaudio/indigodj_dsp.c
index 500e150b49fc..90730a5ecb42 100644
--- a/sound/pci/echoaudio/indigodj_dsp.c
+++ b/sound/pci/echoaudio/indigodj_dsp.c
@@ -39,7 +39,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
39 int err; 39 int err;
40 40
41 DE_INIT(("init_hw() - Indigo DJ\n")); 41 DE_INIT(("init_hw() - Indigo DJ\n"));
42 snd_assert((subdevice_id & 0xfff0) == INDIGO_DJ, return -ENODEV); 42 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_DJ))
43 return -ENODEV;
43 44
44 if ((err = init_dsp_comm_page(chip))) { 45 if ((err = init_dsp_comm_page(chip))) {
45 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 46 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -143,8 +144,9 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
143{ 144{
144 int index; 145 int index;
145 146
146 snd_assert(pipe < num_pipes_out(chip) && 147 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
147 output < num_busses_out(chip), return -EINVAL); 148 output >= num_busses_out(chip)))
149 return -EINVAL;
148 150
149 if (wait_handshake(chip)) 151 if (wait_handshake(chip))
150 return -EIO; 152 return -EIO;
diff --git a/sound/pci/echoaudio/indigoio_dsp.c b/sound/pci/echoaudio/indigoio_dsp.c
index f3ad13d06be0..a7e09ec21079 100644
--- a/sound/pci/echoaudio/indigoio_dsp.c
+++ b/sound/pci/echoaudio/indigoio_dsp.c
@@ -39,7 +39,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
39 int err; 39 int err;
40 40
41 DE_INIT(("init_hw() - Indigo IO\n")); 41 DE_INIT(("init_hw() - Indigo IO\n"));
42 snd_assert((subdevice_id & 0xfff0) == INDIGO_IO, return -ENODEV); 42 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IO))
43 return -ENODEV;
43 44
44 if ((err = init_dsp_comm_page(chip))) { 45 if ((err = init_dsp_comm_page(chip))) {
45 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 46 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -114,8 +115,9 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
114{ 115{
115 int index; 116 int index;
116 117
117 snd_assert(pipe < num_pipes_out(chip) && 118 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
118 output < num_busses_out(chip), return -EINVAL); 119 output >= num_busses_out(chip)))
120 return -EINVAL;
119 121
120 if (wait_handshake(chip)) 122 if (wait_handshake(chip))
121 return -EIO; 123 return -EIO;
diff --git a/sound/pci/echoaudio/layla20_dsp.c b/sound/pci/echoaudio/layla20_dsp.c
index 990c9a60a0a8..ede75c6ca0fb 100644
--- a/sound/pci/echoaudio/layla20_dsp.c
+++ b/sound/pci/echoaudio/layla20_dsp.c
@@ -42,7 +42,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
42 int err; 42 int err;
43 43
44 DE_INIT(("init_hw() - Layla20\n")); 44 DE_INIT(("init_hw() - Layla20\n"));
45 snd_assert((subdevice_id & 0xfff0) == LAYLA20, return -ENODEV); 45 if (snd_BUG_ON((subdevice_id & 0xfff0) != LAYLA20))
46 return -ENODEV;
46 47
47 if ((err = init_dsp_comm_page(chip))) { 48 if ((err = init_dsp_comm_page(chip))) {
48 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 49 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -155,7 +156,8 @@ static int load_asic(struct echoaudio *chip)
155 156
156static int set_sample_rate(struct echoaudio *chip, u32 rate) 157static int set_sample_rate(struct echoaudio *chip, u32 rate)
157{ 158{
158 snd_assert(rate >= 8000 && rate <= 50000, return -EINVAL); 159 if (snd_BUG_ON(rate < 8000 || rate > 50000))
160 return -EINVAL;
159 161
160 /* Only set the clock for internal mode. Do not return failure, 162 /* Only set the clock for internal mode. Do not return failure,
161 simply treat it as a non-event. */ 163 simply treat it as a non-event. */
@@ -252,7 +254,8 @@ static int set_output_clock(struct echoaudio *chip, u16 clock)
252/* Set input bus gain (one unit is 0.5dB !) */ 254/* Set input bus gain (one unit is 0.5dB !) */
253static int set_input_gain(struct echoaudio *chip, u16 input, int gain) 255static int set_input_gain(struct echoaudio *chip, u16 input, int gain)
254{ 256{
255 snd_assert(input < num_busses_in(chip), return -EINVAL); 257 if (snd_BUG_ON(input >= num_busses_in(chip)))
258 return -EINVAL;
256 259
257 if (wait_handshake(chip)) 260 if (wait_handshake(chip))
258 return -EIO; 261 return -EIO;
diff --git a/sound/pci/echoaudio/layla24_dsp.c b/sound/pci/echoaudio/layla24_dsp.c
index 97e42e115147..d61b5cbcccad 100644
--- a/sound/pci/echoaudio/layla24_dsp.c
+++ b/sound/pci/echoaudio/layla24_dsp.c
@@ -42,7 +42,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
42 int err; 42 int err;
43 43
44 DE_INIT(("init_hw() - Layla24\n")); 44 DE_INIT(("init_hw() - Layla24\n"));
45 snd_assert((subdevice_id & 0xfff0) == LAYLA24, return -ENODEV); 45 if (snd_BUG_ON((subdevice_id & 0xfff0) != LAYLA24))
46 return -ENODEV;
46 47
47 if ((err = init_dsp_comm_page(chip))) { 48 if ((err = init_dsp_comm_page(chip))) {
48 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 49 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -73,7 +74,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
73 return err; 74 return err;
74 75
75 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA); 76 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
76 snd_assert(err >= 0, return err); 77 if (err < 0)
78 return err;
77 err = set_professional_spdif(chip, TRUE); 79 err = set_professional_spdif(chip, TRUE);
78 80
79 DE_INIT(("init_hw done\n")); 81 DE_INIT(("init_hw done\n"));
@@ -158,8 +160,9 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
158{ 160{
159 u32 control_reg, clock, base_rate; 161 u32 control_reg, clock, base_rate;
160 162
161 snd_assert(rate < 50000 || chip->digital_mode != DIGITAL_MODE_ADAT, 163 if (snd_BUG_ON(rate >= 50000 &&
162 return -EINVAL); 164 chip->digital_mode == DIGITAL_MODE_ADAT))
165 return -EINVAL;
163 166
164 /* Only set the clock for internal mode. */ 167 /* Only set the clock for internal mode. */
165 if (chip->input_clock != ECHO_CLOCK_INTERNAL) { 168 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
diff --git a/sound/pci/echoaudio/mia_dsp.c b/sound/pci/echoaudio/mia_dsp.c
index 891c70519096..227386602f9b 100644
--- a/sound/pci/echoaudio/mia_dsp.c
+++ b/sound/pci/echoaudio/mia_dsp.c
@@ -42,7 +42,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
42 int err; 42 int err;
43 43
44 DE_INIT(("init_hw() - Mia\n")); 44 DE_INIT(("init_hw() - Mia\n"));
45 snd_assert((subdevice_id & 0xfff0) == MIA, return -ENODEV); 45 if (snd_BUG_ON((subdevice_id & 0xfff0) != MIA))
46 return -ENODEV;
46 47
47 if ((err = init_dsp_comm_page(chip))) { 48 if ((err = init_dsp_comm_page(chip))) {
48 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 49 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -161,8 +162,9 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
161static int set_input_clock(struct echoaudio *chip, u16 clock) 162static int set_input_clock(struct echoaudio *chip, u16 clock)
162{ 163{
163 DE_ACT(("set_input_clock(%d)\n", clock)); 164 DE_ACT(("set_input_clock(%d)\n", clock));
164 snd_assert(clock == ECHO_CLOCK_INTERNAL || clock == ECHO_CLOCK_SPDIF, 165 if (snd_BUG_ON(clock != ECHO_CLOCK_INTERNAL &&
165 return -EINVAL); 166 clock != ECHO_CLOCK_SPDIF))
167 return -EINVAL;
166 168
167 chip->input_clock = clock; 169 chip->input_clock = clock;
168 return set_sample_rate(chip, chip->sample_rate); 170 return set_sample_rate(chip, chip->sample_rate);
@@ -176,8 +178,9 @@ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
176{ 178{
177 int index; 179 int index;
178 180
179 snd_assert(pipe < num_pipes_out(chip) && 181 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
180 output < num_busses_out(chip), return -EINVAL); 182 output >= num_busses_out(chip)))
183 return -EINVAL;
181 184
182 if (wait_handshake(chip)) 185 if (wait_handshake(chip))
183 return -EIO; 186 return -EIO;
diff --git a/sound/pci/echoaudio/midi.c b/sound/pci/echoaudio/midi.c
index 91f5bff66d3f..77bf2a83d997 100644
--- a/sound/pci/echoaudio/midi.c
+++ b/sound/pci/echoaudio/midi.c
@@ -59,7 +59,8 @@ static int enable_midi_input(struct echoaudio *chip, char enable)
59Returns how many actually written or < 0 on error */ 59Returns how many actually written or < 0 on error */
60static int write_midi(struct echoaudio *chip, u8 *data, int bytes) 60static int write_midi(struct echoaudio *chip, u8 *data, int bytes)
61{ 61{
62 snd_assert(bytes > 0 && bytes < MIDI_OUT_BUFFER_SIZE, return -EINVAL); 62 if (snd_BUG_ON(bytes <= 0 || bytes >= MIDI_OUT_BUFFER_SIZE))
63 return -EINVAL;
63 64
64 if (wait_handshake(chip)) 65 if (wait_handshake(chip))
65 return -EIO; 66 return -EIO;
@@ -119,7 +120,8 @@ static int midi_service_irq(struct echoaudio *chip)
119 /* The count is at index 0, followed by actual data */ 120 /* The count is at index 0, followed by actual data */
120 count = le16_to_cpu(chip->comm_page->midi_input[0]); 121 count = le16_to_cpu(chip->comm_page->midi_input[0]);
121 122
122 snd_assert(count < MIDI_IN_BUFFER_SIZE, return 0); 123 if (snd_BUG_ON(count >= MIDI_IN_BUFFER_SIZE))
124 return 0;
123 125
124 /* Get the MIDI data from the comm page */ 126 /* Get the MIDI data from the comm page */
125 i = 1; 127 i = 1;
diff --git a/sound/pci/echoaudio/mona_dsp.c b/sound/pci/echoaudio/mona_dsp.c
index c0b4bf0be7d1..eaa619bd2a03 100644
--- a/sound/pci/echoaudio/mona_dsp.c
+++ b/sound/pci/echoaudio/mona_dsp.c
@@ -43,7 +43,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
43 int err; 43 int err;
44 44
45 DE_INIT(("init_hw() - Mona\n")); 45 DE_INIT(("init_hw() - Mona\n"));
46 snd_assert((subdevice_id & 0xfff0) == MONA, return -ENODEV); 46 if (snd_BUG_ON((subdevice_id & 0xfff0) != MONA))
47 return -ENODEV;
47 48
48 if ((err = init_dsp_comm_page(chip))) { 49 if ((err = init_dsp_comm_page(chip))) {
49 DE_INIT(("init_hw - could not initialize DSP comm page\n")); 50 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
@@ -79,7 +80,8 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
79 return err; 80 return err;
80 81
81 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA); 82 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
82 snd_assert(err >= 0, return err); 83 if (err < 0)
84 return err;
83 err = set_professional_spdif(chip, TRUE); 85 err = set_professional_spdif(chip, TRUE);
84 86
85 DE_INIT(("init_hw done\n")); 87 DE_INIT(("init_hw done\n"));
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index 45088ebcce50..0e649dcdbf64 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -145,7 +145,8 @@ terminate_voice(struct snd_emux_voice *vp)
145{ 145{
146 struct snd_emu10k1 *hw; 146 struct snd_emu10k1 *hw;
147 147
148 snd_assert(vp, return); 148 if (snd_BUG_ON(!vp))
149 return;
149 hw = vp->hw; 150 hw = vp->hw;
150 snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, 0x807f | DCYSUSV_CHANNELENABLE_MASK); 151 snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, 0x807f | DCYSUSV_CHANNELENABLE_MASK);
151 if (vp->block) { 152 if (vp->block) {
@@ -325,7 +326,8 @@ start_voice(struct snd_emux_voice *vp)
325 326
326 hw = vp->hw; 327 hw = vp->hw;
327 ch = vp->ch; 328 ch = vp->ch;
328 snd_assert(ch >= 0, return -EINVAL); 329 if (snd_BUG_ON(ch < 0))
330 return -EINVAL;
329 chan = vp->chan; 331 chan = vp->chan;
330 332
331 emem = (struct snd_emu10k1_memblk *)vp->block; 333 emem = (struct snd_emu10k1_memblk *)vp->block;
diff --git a/sound/pci/emu10k1/emu10k1_patch.c b/sound/pci/emu10k1/emu10k1_patch.c
index 42bae6f7e9a4..e10f027bde03 100644
--- a/sound/pci/emu10k1/emu10k1_patch.c
+++ b/sound/pci/emu10k1/emu10k1_patch.c
@@ -46,8 +46,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
46 struct snd_emu10k1 *emu; 46 struct snd_emu10k1 *emu;
47 47
48 emu = rec->hw; 48 emu = rec->hw;
49 snd_assert(sp != NULL, return -EINVAL); 49 if (snd_BUG_ON(!sp || !hdr))
50 snd_assert(hdr != NULL, return -EINVAL); 50 return -EINVAL;
51 51
52 if (sp->v.size == 0) { 52 if (sp->v.size == 0) {
53 snd_printd("emu: rom font for sample %d\n", sp->v.sample); 53 snd_printd("emu: rom font for sample %d\n", sp->v.sample);
@@ -104,7 +104,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
104 size = BLANK_HEAD_SIZE; 104 size = BLANK_HEAD_SIZE;
105 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) 105 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS))
106 size *= 2; 106 size *= 2;
107 snd_assert(offset + size <= blocksize, return -EINVAL); 107 if (offset + size > blocksize)
108 return -EINVAL;
108 snd_emu10k1_synth_bzero(emu, sp->block, offset, size); 109 snd_emu10k1_synth_bzero(emu, sp->block, offset, size);
109 offset += size; 110 offset += size;
110 111
@@ -112,7 +113,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
112 size = loopend; 113 size = loopend;
113 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) 114 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS))
114 size *= 2; 115 size *= 2;
115 snd_assert(offset + size <= blocksize, return -EINVAL); 116 if (offset + size > blocksize)
117 return -EINVAL;
116 if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) { 118 if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) {
117 snd_emu10k1_synth_free(emu, sp->block); 119 snd_emu10k1_synth_free(emu, sp->block);
118 sp->block = NULL; 120 sp->block = NULL;
@@ -129,12 +131,14 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
129 int woffset; 131 int woffset;
130 unsigned short *wblock = (unsigned short*)block; 132 unsigned short *wblock = (unsigned short*)block;
131 woffset = offset / 2; 133 woffset = offset / 2;
132 snd_assert(offset + loopsize*2 <= blocksize, return -EINVAL); 134 if (offset + loopsize * 2 > blocksize)
135 return -EINVAL;
133 for (i = 0; i < loopsize; i++) 136 for (i = 0; i < loopsize; i++)
134 wblock[woffset + i] = wblock[woffset - i -1]; 137 wblock[woffset + i] = wblock[woffset - i -1];
135 offset += loopsize * 2; 138 offset += loopsize * 2;
136 } else { 139 } else {
137 snd_assert(offset + loopsize <= blocksize, return -EINVAL); 140 if (offset + loopsize > blocksize)
141 return -EINVAL;
138 for (i = 0; i < loopsize; i++) 142 for (i = 0; i < loopsize; i++)
139 block[offset + i] = block[offset - i -1]; 143 block[offset + i] = block[offset - i -1];
140 offset += loopsize; 144 offset += loopsize;
@@ -154,7 +158,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
154 158
155 /* loopend -> sample end */ 159 /* loopend -> sample end */
156 size = sp->v.size - loopend; 160 size = sp->v.size - loopend;
157 snd_assert(size >= 0, return -EINVAL); 161 if (size < 0)
162 return -EINVAL;
158 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) 163 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS))
159 size *= 2; 164 size *= 2;
160 if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) { 165 if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) {
@@ -212,8 +217,8 @@ snd_emu10k1_sample_free(struct snd_emux *rec, struct snd_sf_sample *sp,
212 struct snd_emu10k1 *emu; 217 struct snd_emu10k1 *emu;
213 218
214 emu = rec->hw; 219 emu = rec->hw;
215 snd_assert(sp != NULL, return -EINVAL); 220 if (snd_BUG_ON(!sp || !hdr))
216 snd_assert(hdr != NULL, return -EINVAL); 221 return -EINVAL;
217 222
218 if (sp->block) { 223 if (sp->block) {
219 snd_emu10k1_synth_free(emu, sp->block); 224 snd_emu10k1_synth_free(emu, sp->block);
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 491a4a50f869..5ff4dbb62dad 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -1319,7 +1319,8 @@ static int snd_emu10k1x_midi_input_open(struct snd_rawmidi_substream *substream)
1319 unsigned long flags; 1319 unsigned long flags;
1320 1320
1321 emu = midi->emu; 1321 emu = midi->emu;
1322 snd_assert(emu, return -ENXIO); 1322 if (snd_BUG_ON(!emu))
1323 return -ENXIO;
1323 spin_lock_irqsave(&midi->open_lock, flags); 1324 spin_lock_irqsave(&midi->open_lock, flags);
1324 midi->midi_mode |= EMU10K1X_MIDI_MODE_INPUT; 1325 midi->midi_mode |= EMU10K1X_MIDI_MODE_INPUT;
1325 midi->substream_input = substream; 1326 midi->substream_input = substream;
@@ -1345,7 +1346,8 @@ static int snd_emu10k1x_midi_output_open(struct snd_rawmidi_substream *substream
1345 unsigned long flags; 1346 unsigned long flags;
1346 1347
1347 emu = midi->emu; 1348 emu = midi->emu;
1348 snd_assert(emu, return -ENXIO); 1349 if (snd_BUG_ON(!emu))
1350 return -ENXIO;
1349 spin_lock_irqsave(&midi->open_lock, flags); 1351 spin_lock_irqsave(&midi->open_lock, flags);
1350 midi->midi_mode |= EMU10K1X_MIDI_MODE_OUTPUT; 1352 midi->midi_mode |= EMU10K1X_MIDI_MODE_OUTPUT;
1351 midi->substream_output = substream; 1353 midi->substream_output = substream;
@@ -1372,7 +1374,8 @@ static int snd_emu10k1x_midi_input_close(struct snd_rawmidi_substream *substream
1372 int err = 0; 1374 int err = 0;
1373 1375
1374 emu = midi->emu; 1376 emu = midi->emu;
1375 snd_assert(emu, return -ENXIO); 1377 if (snd_BUG_ON(!emu))
1378 return -ENXIO;
1376 spin_lock_irqsave(&midi->open_lock, flags); 1379 spin_lock_irqsave(&midi->open_lock, flags);
1377 snd_emu10k1x_intr_disable(emu, midi->rx_enable); 1380 snd_emu10k1x_intr_disable(emu, midi->rx_enable);
1378 midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT; 1381 midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT;
@@ -1394,7 +1397,8 @@ static int snd_emu10k1x_midi_output_close(struct snd_rawmidi_substream *substrea
1394 int err = 0; 1397 int err = 0;
1395 1398
1396 emu = midi->emu; 1399 emu = midi->emu;
1397 snd_assert(emu, return -ENXIO); 1400 if (snd_BUG_ON(!emu))
1401 return -ENXIO;
1398 spin_lock_irqsave(&midi->open_lock, flags); 1402 spin_lock_irqsave(&midi->open_lock, flags);
1399 snd_emu10k1x_intr_disable(emu, midi->tx_enable); 1403 snd_emu10k1x_intr_disable(emu, midi->tx_enable);
1400 midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT; 1404 midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT;
@@ -1413,7 +1417,8 @@ static void snd_emu10k1x_midi_input_trigger(struct snd_rawmidi_substream *substr
1413 struct emu10k1x *emu; 1417 struct emu10k1x *emu;
1414 struct emu10k1x_midi *midi = substream->rmidi->private_data; 1418 struct emu10k1x_midi *midi = substream->rmidi->private_data;
1415 emu = midi->emu; 1419 emu = midi->emu;
1416 snd_assert(emu, return); 1420 if (snd_BUG_ON(!emu))
1421 return;
1417 1422
1418 if (up) 1423 if (up)
1419 snd_emu10k1x_intr_enable(emu, midi->rx_enable); 1424 snd_emu10k1x_intr_enable(emu, midi->rx_enable);
@@ -1428,7 +1433,8 @@ static void snd_emu10k1x_midi_output_trigger(struct snd_rawmidi_substream *subst
1428 unsigned long flags; 1433 unsigned long flags;
1429 1434
1430 emu = midi->emu; 1435 emu = midi->emu;
1431 snd_assert(emu, return); 1436 if (snd_BUG_ON(!emu))
1437 return;
1432 1438
1433 if (up) { 1439 if (up) {
1434 int max = 4; 1440 int max = 4;
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 71dc4c8865b8..7dba08f0ab8e 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -487,7 +487,8 @@ static void snd_emu10k1_write_op(struct snd_emu10k1_fx8010_code *icode,
487 u32 op, u32 r, u32 a, u32 x, u32 y) 487 u32 op, u32 r, u32 a, u32 x, u32 y)
488{ 488{
489 u_int32_t *code; 489 u_int32_t *code;
490 snd_assert(*ptr < 512, return); 490 if (snd_BUG_ON(*ptr >= 512))
491 return;
491 code = (u_int32_t __force *)icode->code + (*ptr) * 2; 492 code = (u_int32_t __force *)icode->code + (*ptr) * 2;
492 set_bit(*ptr, icode->code_valid); 493 set_bit(*ptr, icode->code_valid);
493 code[0] = ((x & 0x3ff) << 10) | (y & 0x3ff); 494 code[0] = ((x & 0x3ff) << 10) | (y & 0x3ff);
@@ -503,7 +504,8 @@ static void snd_emu10k1_audigy_write_op(struct snd_emu10k1_fx8010_code *icode,
503 u32 op, u32 r, u32 a, u32 x, u32 y) 504 u32 op, u32 r, u32 a, u32 x, u32 y)
504{ 505{
505 u_int32_t *code; 506 u_int32_t *code;
506 snd_assert(*ptr < 1024, return); 507 if (snd_BUG_ON(*ptr >= 1024))
508 return;
507 code = (u_int32_t __force *)icode->code + (*ptr) * 2; 509 code = (u_int32_t __force *)icode->code + (*ptr) * 2;
508 set_bit(*ptr, icode->code_valid); 510 set_bit(*ptr, icode->code_valid);
509 code[0] = ((x & 0x7ff) << 12) | (y & 0x7ff); 511 code[0] = ((x & 0x7ff) << 12) | (y & 0x7ff);
diff --git a/sound/pci/emu10k1/emumpu401.c b/sound/pci/emu10k1/emumpu401.c
index c4d76d16661e..8578c70c61f2 100644
--- a/sound/pci/emu10k1/emumpu401.c
+++ b/sound/pci/emu10k1/emumpu401.c
@@ -157,7 +157,8 @@ static int snd_emu10k1_midi_input_open(struct snd_rawmidi_substream *substream)
157 unsigned long flags; 157 unsigned long flags;
158 158
159 emu = midi->emu; 159 emu = midi->emu;
160 snd_assert(emu, return -ENXIO); 160 if (snd_BUG_ON(!emu))
161 return -ENXIO;
161 spin_lock_irqsave(&midi->open_lock, flags); 162 spin_lock_irqsave(&midi->open_lock, flags);
162 midi->midi_mode |= EMU10K1_MIDI_MODE_INPUT; 163 midi->midi_mode |= EMU10K1_MIDI_MODE_INPUT;
163 midi->substream_input = substream; 164 midi->substream_input = substream;
@@ -183,7 +184,8 @@ static int snd_emu10k1_midi_output_open(struct snd_rawmidi_substream *substream)
183 unsigned long flags; 184 unsigned long flags;
184 185
185 emu = midi->emu; 186 emu = midi->emu;
186 snd_assert(emu, return -ENXIO); 187 if (snd_BUG_ON(!emu))
188 return -ENXIO;
187 spin_lock_irqsave(&midi->open_lock, flags); 189 spin_lock_irqsave(&midi->open_lock, flags);
188 midi->midi_mode |= EMU10K1_MIDI_MODE_OUTPUT; 190 midi->midi_mode |= EMU10K1_MIDI_MODE_OUTPUT;
189 midi->substream_output = substream; 191 midi->substream_output = substream;
@@ -210,7 +212,8 @@ static int snd_emu10k1_midi_input_close(struct snd_rawmidi_substream *substream)
210 int err = 0; 212 int err = 0;
211 213
212 emu = midi->emu; 214 emu = midi->emu;
213 snd_assert(emu, return -ENXIO); 215 if (snd_BUG_ON(!emu))
216 return -ENXIO;
214 spin_lock_irqsave(&midi->open_lock, flags); 217 spin_lock_irqsave(&midi->open_lock, flags);
215 snd_emu10k1_intr_disable(emu, midi->rx_enable); 218 snd_emu10k1_intr_disable(emu, midi->rx_enable);
216 midi->midi_mode &= ~EMU10K1_MIDI_MODE_INPUT; 219 midi->midi_mode &= ~EMU10K1_MIDI_MODE_INPUT;
@@ -232,7 +235,8 @@ static int snd_emu10k1_midi_output_close(struct snd_rawmidi_substream *substream
232 int err = 0; 235 int err = 0;
233 236
234 emu = midi->emu; 237 emu = midi->emu;
235 snd_assert(emu, return -ENXIO); 238 if (snd_BUG_ON(!emu))
239 return -ENXIO;
236 spin_lock_irqsave(&midi->open_lock, flags); 240 spin_lock_irqsave(&midi->open_lock, flags);
237 snd_emu10k1_intr_disable(emu, midi->tx_enable); 241 snd_emu10k1_intr_disable(emu, midi->tx_enable);
238 midi->midi_mode &= ~EMU10K1_MIDI_MODE_OUTPUT; 242 midi->midi_mode &= ~EMU10K1_MIDI_MODE_OUTPUT;
@@ -251,7 +255,8 @@ static void snd_emu10k1_midi_input_trigger(struct snd_rawmidi_substream *substre
251 struct snd_emu10k1 *emu; 255 struct snd_emu10k1 *emu;
252 struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; 256 struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
253 emu = midi->emu; 257 emu = midi->emu;
254 snd_assert(emu, return); 258 if (snd_BUG_ON(!emu))
259 return;
255 260
256 if (up) 261 if (up)
257 snd_emu10k1_intr_enable(emu, midi->rx_enable); 262 snd_emu10k1_intr_enable(emu, midi->rx_enable);
@@ -266,7 +271,8 @@ static void snd_emu10k1_midi_output_trigger(struct snd_rawmidi_substream *substr
266 unsigned long flags; 271 unsigned long flags;
267 272
268 emu = midi->emu; 273 emu = midi->emu;
269 snd_assert(emu, return); 274 if (snd_BUG_ON(!emu))
275 return;
270 276
271 if (up) { 277 if (up) {
272 int max = 4; 278 int max = 4;
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index 7d379f5131fb..6a47672f930a 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -107,7 +107,8 @@ static int search_empty_map_area(struct snd_emu10k1 *emu, int npages, struct lis
107 107
108 list_for_each (pos, &emu->mapped_link_head) { 108 list_for_each (pos, &emu->mapped_link_head) {
109 struct snd_emu10k1_memblk *blk = get_emu10k1_memblk(pos, mapped_link); 109 struct snd_emu10k1_memblk *blk = get_emu10k1_memblk(pos, mapped_link);
110 snd_assert(blk->mapped_page >= 0, continue); 110 if (blk->mapped_page < 0)
111 continue;
111 size = blk->mapped_page - page; 112 size = blk->mapped_page - page;
112 if (size == npages) { 113 if (size == npages) {
113 *nextp = pos; 114 *nextp = pos;
@@ -295,15 +296,18 @@ struct snd_util_memblk *
295snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream) 296snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream)
296{ 297{
297 struct snd_pcm_runtime *runtime = substream->runtime; 298 struct snd_pcm_runtime *runtime = substream->runtime;
298 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
299 struct snd_util_memhdr *hdr; 299 struct snd_util_memhdr *hdr;
300 struct snd_emu10k1_memblk *blk; 300 struct snd_emu10k1_memblk *blk;
301 int page, err, idx; 301 int page, err, idx;
302 302
303 snd_assert(emu, return NULL); 303 if (snd_BUG_ON(!emu))
304 snd_assert(runtime->dma_bytes > 0 && runtime->dma_bytes < MAXPAGES * EMUPAGESIZE, return NULL); 304 return NULL;
305 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
306 runtime->dma_bytes >= MAXPAGES * EMUPAGESIZE))
307 return NULL;
305 hdr = emu->memhdr; 308 hdr = emu->memhdr;
306 snd_assert(hdr, return NULL); 309 if (snd_BUG_ON(!hdr))
310 return NULL;
307 311
308 mutex_lock(&hdr->block_mutex); 312 mutex_lock(&hdr->block_mutex);
309 blk = search_empty(emu, runtime->dma_bytes); 313 blk = search_empty(emu, runtime->dma_bytes);
@@ -316,16 +320,9 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
316 */ 320 */
317 idx = 0; 321 idx = 0;
318 for (page = blk->first_page; page <= blk->last_page; page++, idx++) { 322 for (page = blk->first_page; page <= blk->last_page; page++, idx++) {
323 unsigned long ofs = idx << PAGE_SHIFT;
319 dma_addr_t addr; 324 dma_addr_t addr;
320#ifdef CONFIG_SND_DEBUG 325 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
321 if (idx >= sgbuf->pages) {
322 printk(KERN_ERR "emu: pages overflow! (%d-%d) for %d\n",
323 blk->first_page, blk->last_page, sgbuf->pages);
324 mutex_unlock(&hdr->block_mutex);
325 return NULL;
326 }
327#endif
328 addr = sgbuf->table[idx].addr;
329 if (! is_valid_page(emu, addr)) { 326 if (! is_valid_page(emu, addr)) {
330 printk(KERN_ERR "emu: failure page = %d\n", idx); 327 printk(KERN_ERR "emu: failure page = %d\n", idx);
331 mutex_unlock(&hdr->block_mutex); 328 mutex_unlock(&hdr->block_mutex);
@@ -353,7 +350,8 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
353 */ 350 */
354int snd_emu10k1_free_pages(struct snd_emu10k1 *emu, struct snd_util_memblk *blk) 351int snd_emu10k1_free_pages(struct snd_emu10k1 *emu, struct snd_util_memblk *blk)
355{ 352{
356 snd_assert(emu && blk, return -EINVAL); 353 if (snd_BUG_ON(!emu || !blk))
354 return -EINVAL;
357 return snd_emu10k1_synth_free(emu, blk); 355 return snd_emu10k1_synth_free(emu, blk);
358} 356}
359 357
@@ -498,7 +496,8 @@ static int synth_free_pages(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *
498static inline void *offset_ptr(struct snd_emu10k1 *emu, int page, int offset) 496static inline void *offset_ptr(struct snd_emu10k1 *emu, int page, int offset)
499{ 497{
500 char *ptr; 498 char *ptr;
501 snd_assert(page >= 0 && page < emu->max_cache_pages, return NULL); 499 if (snd_BUG_ON(page < 0 || page >= emu->max_cache_pages))
500 return NULL;
502 ptr = emu->page_ptr_table[page]; 501 ptr = emu->page_ptr_table[page];
503 if (! ptr) { 502 if (! ptr) {
504 printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page); 503 printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page);
diff --git a/sound/pci/emu10k1/voice.c b/sound/pci/emu10k1/voice.c
index 958cb2a65a4e..d7300a1aa262 100644
--- a/sound/pci/emu10k1/voice.c
+++ b/sound/pci/emu10k1/voice.c
@@ -111,8 +111,10 @@ int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number,
111 unsigned long flags; 111 unsigned long flags;
112 int result; 112 int result;
113 113
114 snd_assert(rvoice != NULL, return -EINVAL); 114 if (snd_BUG_ON(!rvoice))
115 snd_assert(number, return -EINVAL); 115 return -EINVAL;
116 if (snd_BUG_ON(!number))
117 return -EINVAL;
116 118
117 spin_lock_irqsave(&emu->voice_lock, flags); 119 spin_lock_irqsave(&emu->voice_lock, flags);
118 for (;;) { 120 for (;;) {
@@ -145,7 +147,8 @@ int snd_emu10k1_voice_free(struct snd_emu10k1 *emu,
145{ 147{
146 unsigned long flags; 148 unsigned long flags;
147 149
148 snd_assert(pvoice != NULL, return -EINVAL); 150 if (snd_BUG_ON(!pvoice))
151 return -EINVAL;
149 spin_lock_irqsave(&emu->voice_lock, flags); 152 spin_lock_irqsave(&emu->voice_lock, flags);
150 pvoice->interrupt = NULL; 153 pvoice->interrupt = NULL;
151 pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0; 154 pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0;
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 84fac1fbf103..4cd9a1faaecc 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -860,7 +860,8 @@ static int snd_es1938_capture_copy(struct snd_pcm_substream *substream,
860 struct es1938 *chip = snd_pcm_substream_chip(substream); 860 struct es1938 *chip = snd_pcm_substream_chip(substream);
861 pos <<= chip->dma1_shift; 861 pos <<= chip->dma1_shift;
862 count <<= chip->dma1_shift; 862 count <<= chip->dma1_shift;
863 snd_assert(pos + count <= chip->dma1_size, return -EINVAL); 863 if (snd_BUG_ON(pos + count > chip->dma1_size))
864 return -EINVAL;
864 if (pos + count < chip->dma1_size) { 865 if (pos + count < chip->dma1_size) {
865 if (copy_to_user(dst, runtime->dma_area + pos + 1, count)) 866 if (copy_to_user(dst, runtime->dma_area + pos + 1, count))
866 return -EFAULT; 867 return -EFAULT;
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 1bf298d214b9..20ee7599600b 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -692,7 +692,8 @@ static void apu_data_set(struct es1968 *chip, u16 data)
692/* no spinlock */ 692/* no spinlock */
693static void __apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data) 693static void __apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data)
694{ 694{
695 snd_assert(channel < NR_APUS, return); 695 if (snd_BUG_ON(channel >= NR_APUS))
696 return;
696#ifdef CONFIG_PM 697#ifdef CONFIG_PM
697 chip->apu_map[channel][reg] = data; 698 chip->apu_map[channel][reg] = data;
698#endif 699#endif
@@ -711,7 +712,8 @@ static void apu_set_register(struct es1968 *chip, u16 channel, u8 reg, u16 data)
711 712
712static u16 __apu_get_register(struct es1968 *chip, u16 channel, u8 reg) 713static u16 __apu_get_register(struct es1968 *chip, u16 channel, u8 reg)
713{ 714{
714 snd_assert(channel < NR_APUS, return 0); 715 if (snd_BUG_ON(channel >= NR_APUS))
716 return 0;
715 reg |= (channel << 4); 717 reg |= (channel << 4);
716 apu_index_set(chip, reg); 718 apu_index_set(chip, reg);
717 return __maestro_read(chip, IDR0_DATA_PORT); 719 return __maestro_read(chip, IDR0_DATA_PORT);
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index ab0c726d648e..1980c6d207e7 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -5,6 +5,7 @@ snd-hda-intel-y := hda_intel.o
5snd-hda-intel-y += hda_codec.o 5snd-hda-intel-y += hda_codec.o
6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o 6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-intel-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 9snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
9snd-hda-intel-$(CONFIG_SND_HDA_CODEC_REALTEK) += patch_realtek.o 10snd-hda-intel-$(CONFIG_SND_HDA_CODEC_REALTEK) += patch_realtek.o
10snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CMEDIA) += patch_cmedia.o 11snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CMEDIA) += patch_cmedia.o
@@ -14,5 +15,6 @@ snd-hda-intel-$(CONFIG_SND_HDA_CODEC_SI3054) += patch_si3054.o
14snd-hda-intel-$(CONFIG_SND_HDA_CODEC_ATIHDMI) += patch_atihdmi.o 15snd-hda-intel-$(CONFIG_SND_HDA_CODEC_ATIHDMI) += patch_atihdmi.o
15snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CONEXANT) += patch_conexant.o 16snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CONEXANT) += patch_conexant.o
16snd-hda-intel-$(CONFIG_SND_HDA_CODEC_VIA) += patch_via.o 17snd-hda-intel-$(CONFIG_SND_HDA_CODEC_VIA) += patch_via.o
18snd-hda-intel-$(CONFIG_SND_HDA_CODEC_NVHDMI) += patch_nvhdmi.o
17 19
18obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-intel.o 20obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-intel.o
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
new file mode 100644
index 000000000000..9b77b3e0fa98
--- /dev/null
+++ b/sound/pci/hda/hda_beep.c
@@ -0,0 +1,134 @@
1/*
2 * Digital Beep Input Interface for HD-audio codec
3 *
4 * Author: Matthew Ranostay <mranostay@embeddedalley.com>
5 * Copyright (c) 2008 Embedded Alley Solutions Inc
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/input.h>
23#include <linux/pci.h>
24#include <linux/workqueue.h>
25#include <sound/core.h>
26#include "hda_beep.h"
27
28enum {
29 DIGBEEP_HZ_STEP = 46875, /* 46.875 Hz */
30 DIGBEEP_HZ_MIN = 93750, /* 93.750 Hz */
31 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */
32};
33
34static void snd_hda_generate_beep(struct work_struct *work)
35{
36 struct hda_beep *beep =
37 container_of(work, struct hda_beep, beep_work);
38 struct hda_codec *codec = beep->codec;
39
40 /* generate tone */
41 snd_hda_codec_write_cache(codec, beep->nid, 0,
42 AC_VERB_SET_BEEP_CONTROL, beep->tone);
43}
44
45static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
46 unsigned int code, int hz)
47{
48 struct hda_beep *beep = input_get_drvdata(dev);
49
50 switch (code) {
51 case SND_BELL:
52 if (hz)
53 hz = 1000;
54 case SND_TONE:
55 hz *= 1000; /* fixed point */
56 hz = hz - DIGBEEP_HZ_MIN;
57 if (hz < 0)
58 hz = 0; /* turn off PC beep*/
59 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN))
60 hz = 0xff;
61 else {
62 hz /= DIGBEEP_HZ_STEP;
63 hz++;
64 }
65 break;
66 default:
67 return -1;
68 }
69 beep->tone = hz;
70
71 /* schedule beep event */
72 schedule_work(&beep->beep_work);
73 return 0;
74}
75
76int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
77{
78 struct input_dev *input_dev;
79 struct hda_beep *beep;
80 int err;
81
82 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
83 if (beep == NULL)
84 return -ENOMEM;
85 snprintf(beep->phys, sizeof(beep->phys),
86 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
87 input_dev = input_allocate_device();
88
89 /* setup digital beep device */
90 input_dev->name = "HDA Digital PCBeep";
91 input_dev->phys = beep->phys;
92 input_dev->id.bustype = BUS_PCI;
93
94 input_dev->id.vendor = codec->vendor_id >> 16;
95 input_dev->id.product = codec->vendor_id & 0xffff;
96 input_dev->id.version = 0x01;
97
98 input_dev->evbit[0] = BIT_MASK(EV_SND);
99 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
100 input_dev->event = snd_hda_beep_event;
101 input_dev->dev.parent = &codec->bus->pci->dev;
102 input_set_drvdata(input_dev, beep);
103
104 err = input_register_device(input_dev);
105 if (err < 0) {
106 input_free_device(input_dev);
107 kfree(beep);
108 return err;
109 }
110
111 /* enable linear scale */
112 snd_hda_codec_write(codec, nid, 0,
113 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
114
115 beep->nid = nid;
116 beep->dev = input_dev;
117 beep->codec = codec;
118 codec->beep = beep;
119
120 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
121 return 0;
122}
123
124void snd_hda_detach_beep_device(struct hda_codec *codec)
125{
126 struct hda_beep *beep = codec->beep;
127 if (beep) {
128 cancel_work_sync(&beep->beep_work);
129 flush_scheduled_work();
130
131 input_unregister_device(beep->dev);
132 kfree(beep);
133 }
134}
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
new file mode 100644
index 000000000000..de4036e6e710
--- /dev/null
+++ b/sound/pci/hda/hda_beep.h
@@ -0,0 +1,44 @@
1/*
2 * Digital Beep Input Interface for HD-audio codec
3 *
4 * Author: Matthew Ranostay <mranostay@embeddedalley.com>
5 * Copyright (c) 2008 Embedded Alley Solutions Inc
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef __SOUND_HDA_BEEP_H
23#define __SOUND_HDA_BEEP_H
24
25#include "hda_codec.h"
26
27/* beep information */
28struct hda_beep {
29 struct input_dev *dev;
30 struct hda_codec *codec;
31 char phys[32];
32 int tone;
33 int nid;
34 struct work_struct beep_work; /* scheduled task for beep event */
35};
36
37#ifdef CONFIG_SND_HDA_INPUT_BEEP
38int snd_hda_attach_beep_device(struct hda_codec *codec, int nid);
39void snd_hda_detach_beep_device(struct hda_codec *codec);
40#else
41#define snd_hda_attach_beep_device(...)
42#define snd_hda_detach_beep_device(...)
43#endif
44#endif
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index d2e1093f8e97..6447754ae56e 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -94,6 +94,9 @@ static const struct hda_codec_preset *hda_preset_tables[] = {
94#ifdef CONFIG_SND_HDA_CODEC_VIA 94#ifdef CONFIG_SND_HDA_CODEC_VIA
95 snd_hda_preset_via, 95 snd_hda_preset_via,
96#endif 96#endif
97#ifdef CONFIG_SND_HDA_CODEC_NVHDMI
98 snd_hda_preset_nvhdmi,
99#endif
97 NULL 100 NULL
98}; 101};
99 102
@@ -211,7 +214,8 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
211 unsigned int shift, num_elems, mask; 214 unsigned int shift, num_elems, mask;
212 hda_nid_t prev_nid; 215 hda_nid_t prev_nid;
213 216
214 snd_assert(conn_list && max_conns > 0, return -EINVAL); 217 if (snd_BUG_ON(!conn_list || max_conns <= 0))
218 return -EINVAL;
215 219
216 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN); 220 parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
217 if (parm & AC_CLIST_LONG) { 221 if (parm & AC_CLIST_LONG) {
@@ -313,7 +317,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
313} 317}
314 318
315/* 319/*
316 * process queueud unsolicited events 320 * process queued unsolicited events
317 */ 321 */
318static void process_unsol_events(struct work_struct *work) 322static void process_unsol_events(struct work_struct *work)
319{ 323{
@@ -407,8 +411,10 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
407 .dev_free = snd_hda_bus_dev_free, 411 .dev_free = snd_hda_bus_dev_free,
408 }; 412 };
409 413
410 snd_assert(temp, return -EINVAL); 414 if (snd_BUG_ON(!temp))
411 snd_assert(temp->ops.command && temp->ops.get_response, return -EINVAL); 415 return -EINVAL;
416 if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
417 return -EINVAL;
412 418
413 if (busp) 419 if (busp)
414 *busp = NULL; 420 *busp = NULL;
@@ -585,11 +591,13 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
585 struct hda_codec **codecp) 591 struct hda_codec **codecp)
586{ 592{
587 struct hda_codec *codec; 593 struct hda_codec *codec;
588 char component[13]; 594 char component[31];
589 int err; 595 int err;
590 596
591 snd_assert(bus, return -EINVAL); 597 if (snd_BUG_ON(!bus))
592 snd_assert(codec_addr <= HDA_MAX_CODEC_ADDRESS, return -EINVAL); 598 return -EINVAL;
599 if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS))
600 return -EINVAL;
593 601
594 if (bus->caddr_tbl[codec_addr]) { 602 if (bus->caddr_tbl[codec_addr]) {
595 snd_printk(KERN_ERR "hda_codec: " 603 snd_printk(KERN_ERR "hda_codec: "
@@ -688,7 +696,7 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
688 snd_hda_create_hwdep(codec); 696 snd_hda_create_hwdep(codec);
689#endif 697#endif
690 698
691 sprintf(component, "HDA:%08x", codec->vendor_id); 699 sprintf(component, "HDA:%08x,%08x,%08x", codec->vendor_id, codec->subsystem_id, codec->revision_id);
692 snd_component_add(codec->bus->card, component); 700 snd_component_add(codec->bus->card, component);
693 701
694 if (codecp) 702 if (codecp)
@@ -956,15 +964,6 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
956} 964}
957#endif /* SND_HDA_NEEDS_RESUME */ 965#endif /* SND_HDA_NEEDS_RESUME */
958 966
959/*
960 * AMP control callbacks
961 */
962/* retrieve parameters from private_value */
963#define get_amp_nid(kc) ((kc)->private_value & 0xffff)
964#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
965#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
966#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
967
968/* volume */ 967/* volume */
969int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 968int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
970 struct snd_ctl_elem_info *uinfo) 969 struct snd_ctl_elem_info *uinfo)
@@ -1430,6 +1429,29 @@ static unsigned int convert_to_spdif_status(unsigned short val)
1430 return sbits; 1429 return sbits;
1431} 1430}
1432 1431
1432/* set digital convert verbs both for the given NID and its slaves */
1433static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
1434 int verb, int val)
1435{
1436 hda_nid_t *d;
1437
1438 snd_hda_codec_write(codec, nid, 0, verb, val);
1439 d = codec->slave_dig_outs;
1440 if (!d)
1441 return;
1442 for (; *d; d++)
1443 snd_hda_codec_write(codec, *d, 0, verb, val);
1444}
1445
1446static inline void set_dig_out_convert(struct hda_codec *codec, hda_nid_t nid,
1447 int dig1, int dig2)
1448{
1449 if (dig1 != -1)
1450 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_1, dig1);
1451 if (dig2 != -1)
1452 set_dig_out(codec, nid, AC_VERB_SET_DIGI_CONVERT_2, dig2);
1453}
1454
1433static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, 1455static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
1434 struct snd_ctl_elem_value *ucontrol) 1456 struct snd_ctl_elem_value *ucontrol)
1435{ 1457{
@@ -1448,14 +1470,8 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
1448 change = codec->spdif_ctls != val; 1470 change = codec->spdif_ctls != val;
1449 codec->spdif_ctls = val; 1471 codec->spdif_ctls = val;
1450 1472
1451 if (change) { 1473 if (change)
1452 snd_hda_codec_write_cache(codec, nid, 0, 1474 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
1453 AC_VERB_SET_DIGI_CONVERT_1,
1454 val & 0xff);
1455 snd_hda_codec_write_cache(codec, nid, 0,
1456 AC_VERB_SET_DIGI_CONVERT_2,
1457 val >> 8);
1458 }
1459 1475
1460 mutex_unlock(&codec->spdif_mutex); 1476 mutex_unlock(&codec->spdif_mutex);
1461 return change; 1477 return change;
@@ -1487,9 +1503,7 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
1487 change = codec->spdif_ctls != val; 1503 change = codec->spdif_ctls != val;
1488 if (change) { 1504 if (change) {
1489 codec->spdif_ctls = val; 1505 codec->spdif_ctls = val;
1490 snd_hda_codec_write_cache(codec, nid, 0, 1506 set_dig_out_convert(codec, nid, val & 0xff, -1);
1491 AC_VERB_SET_DIGI_CONVERT_1,
1492 val & 0xff);
1493 /* unmute amp switch (if any) */ 1507 /* unmute amp switch (if any) */
1494 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) && 1508 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
1495 (val & AC_DIG1_ENABLE)) 1509 (val & AC_DIG1_ENABLE))
@@ -2236,11 +2250,13 @@ static int __devinit set_pcm_default_values(struct hda_codec *codec,
2236 if (info->ops.close == NULL) 2250 if (info->ops.close == NULL)
2237 info->ops.close = hda_pcm_default_open_close; 2251 info->ops.close = hda_pcm_default_open_close;
2238 if (info->ops.prepare == NULL) { 2252 if (info->ops.prepare == NULL) {
2239 snd_assert(info->nid, return -EINVAL); 2253 if (snd_BUG_ON(!info->nid))
2254 return -EINVAL;
2240 info->ops.prepare = hda_pcm_default_prepare; 2255 info->ops.prepare = hda_pcm_default_prepare;
2241 } 2256 }
2242 if (info->ops.cleanup == NULL) { 2257 if (info->ops.cleanup == NULL) {
2243 snd_assert(info->nid, return -EINVAL); 2258 if (snd_BUG_ON(!info->nid))
2259 return -EINVAL;
2244 info->ops.cleanup = hda_pcm_default_cleanup; 2260 info->ops.cleanup = hda_pcm_default_cleanup;
2245 } 2261 }
2246 return 0; 2262 return 0;
@@ -2583,14 +2599,31 @@ static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
2583 unsigned int stream_tag, unsigned int format) 2599 unsigned int stream_tag, unsigned int format)
2584{ 2600{
2585 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ 2601 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
2586 if (codec->spdif_ctls & AC_DIG1_ENABLE) 2602 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
2587 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, 2603 set_dig_out_convert(codec, nid,
2588 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff); 2604 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff,
2605 -1);
2589 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); 2606 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
2607 if (codec->slave_dig_outs) {
2608 hda_nid_t *d;
2609 for (d = codec->slave_dig_outs; *d; d++)
2610 snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
2611 format);
2612 }
2590 /* turn on again (if needed) */ 2613 /* turn on again (if needed) */
2591 if (codec->spdif_ctls & AC_DIG1_ENABLE) 2614 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
2592 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, 2615 set_dig_out_convert(codec, nid,
2593 codec->spdif_ctls & 0xff); 2616 codec->spdif_ctls & 0xff, -1);
2617}
2618
2619static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
2620{
2621 snd_hda_codec_cleanup_stream(codec, nid);
2622 if (codec->slave_dig_outs) {
2623 hda_nid_t *d;
2624 for (d = codec->slave_dig_outs; *d; d++)
2625 snd_hda_codec_cleanup_stream(codec, *d);
2626 }
2594} 2627}
2595 2628
2596/* 2629/*
@@ -2602,7 +2635,7 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2602 mutex_lock(&codec->spdif_mutex); 2635 mutex_lock(&codec->spdif_mutex);
2603 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) 2636 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
2604 /* already opened as analog dup; reset it once */ 2637 /* already opened as analog dup; reset it once */
2605 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid); 2638 cleanup_dig_out_stream(codec, mout->dig_out_nid);
2606 mout->dig_out_used = HDA_DIG_EXCLUSIVE; 2639 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
2607 mutex_unlock(&codec->spdif_mutex); 2640 mutex_unlock(&codec->spdif_mutex);
2608 return 0; 2641 return 0;
@@ -2697,7 +2730,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2697 stream_tag, format); 2730 stream_tag, format);
2698 } else { 2731 } else {
2699 mout->dig_out_used = 0; 2732 mout->dig_out_used = 0;
2700 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid); 2733 cleanup_dig_out_stream(codec, mout->dig_out_nid);
2701 } 2734 }
2702 } 2735 }
2703 mutex_unlock(&codec->spdif_mutex); 2736 mutex_unlock(&codec->spdif_mutex);
@@ -2748,7 +2781,7 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2748 mout->extra_out_nid[i]); 2781 mout->extra_out_nid[i]);
2749 mutex_lock(&codec->spdif_mutex); 2782 mutex_lock(&codec->spdif_mutex);
2750 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) { 2783 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
2751 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid); 2784 cleanup_dig_out_stream(codec, mout->dig_out_nid);
2752 mout->dig_out_used = 0; 2785 mout->dig_out_used = 0;
2753 } 2786 }
2754 mutex_unlock(&codec->spdif_mutex); 2787 mutex_unlock(&codec->spdif_mutex);
@@ -2756,7 +2789,7 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2756} 2789}
2757 2790
2758/* 2791/*
2759 * Helper for automatic ping configuration 2792 * Helper for automatic pin configuration
2760 */ 2793 */
2761 2794
2762static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list) 2795static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index efc682888b31..60468f562400 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -90,6 +90,14 @@ enum {
90#define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c 90#define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c
91/* f20: AFG/MFG */ 91/* f20: AFG/MFG */
92#define AC_VERB_GET_SUBSYSTEM_ID 0x0f20 92#define AC_VERB_GET_SUBSYSTEM_ID 0x0f20
93#define AC_VERB_GET_CVT_CHAN_COUNT 0x0f2d
94#define AC_VERB_GET_HDMI_DIP_SIZE 0x0f2e
95#define AC_VERB_GET_HDMI_ELDD 0x0f2f
96#define AC_VERB_GET_HDMI_DIP_INDEX 0x0f30
97#define AC_VERB_GET_HDMI_DIP_DATA 0x0f31
98#define AC_VERB_GET_HDMI_DIP_XMIT 0x0f32
99#define AC_VERB_GET_HDMI_CP_CTRL 0x0f33
100#define AC_VERB_GET_HDMI_CHAN_SLOT 0x0f34
93 101
94/* 102/*
95 * SET verbs 103 * SET verbs
@@ -121,7 +129,14 @@ enum {
121#define AC_VERB_SET_CONFIG_DEFAULT_BYTES_1 0x71d 129#define AC_VERB_SET_CONFIG_DEFAULT_BYTES_1 0x71d
122#define AC_VERB_SET_CONFIG_DEFAULT_BYTES_2 0x71e 130#define AC_VERB_SET_CONFIG_DEFAULT_BYTES_2 0x71e
123#define AC_VERB_SET_CONFIG_DEFAULT_BYTES_3 0x71f 131#define AC_VERB_SET_CONFIG_DEFAULT_BYTES_3 0x71f
132#define AC_VERB_SET_EAPD 0x788
124#define AC_VERB_SET_CODEC_RESET 0x7ff 133#define AC_VERB_SET_CODEC_RESET 0x7ff
134#define AC_VERB_SET_CVT_CHAN_COUNT 0x72d
135#define AC_VERB_SET_HDMI_DIP_INDEX 0x730
136#define AC_VERB_SET_HDMI_DIP_DATA 0x731
137#define AC_VERB_SET_HDMI_DIP_XMIT 0x732
138#define AC_VERB_SET_HDMI_CP_CTRL 0x733
139#define AC_VERB_SET_HDMI_CHAN_SLOT 0x734
125 140
126/* 141/*
127 * Parameter IDs 142 * Parameter IDs
@@ -143,6 +158,7 @@ enum {
143#define AC_PAR_GPIO_CAP 0x11 158#define AC_PAR_GPIO_CAP 0x11
144#define AC_PAR_AMP_OUT_CAP 0x12 159#define AC_PAR_AMP_OUT_CAP 0x12
145#define AC_PAR_VOL_KNB_CAP 0x13 160#define AC_PAR_VOL_KNB_CAP 0x13
161#define AC_PAR_HDMI_LPCM_CAP 0x20
146 162
147/* 163/*
148 * AC_VERB_PARAMETERS results (32bit) 164 * AC_VERB_PARAMETERS results (32bit)
@@ -171,6 +187,8 @@ enum {
171#define AC_WCAP_DIGITAL (1<<9) /* digital I/O */ 187#define AC_WCAP_DIGITAL (1<<9) /* digital I/O */
172#define AC_WCAP_POWER (1<<10) /* power control */ 188#define AC_WCAP_POWER (1<<10) /* power control */
173#define AC_WCAP_LR_SWAP (1<<11) /* L/R swap */ 189#define AC_WCAP_LR_SWAP (1<<11) /* L/R swap */
190#define AC_WCAP_CP_CAPS (1<<12) /* content protection */
191#define AC_WCAP_CHAN_CNT_EXT (7<<13) /* channel count ext */
174#define AC_WCAP_DELAY (0xf<<16) 192#define AC_WCAP_DELAY (0xf<<16)
175#define AC_WCAP_DELAY_SHIFT 16 193#define AC_WCAP_DELAY_SHIFT 16
176#define AC_WCAP_TYPE (0xf<<20) 194#define AC_WCAP_TYPE (0xf<<20)
@@ -206,9 +224,20 @@ enum {
206/* Input converter SDI select */ 224/* Input converter SDI select */
207#define AC_SDI_SELECT (0xf<<0) 225#define AC_SDI_SELECT (0xf<<0)
208 226
209/* Unsolicited response */ 227/* Unsolicited response control */
210#define AC_UNSOL_TAG (0x3f<<0) 228#define AC_UNSOL_TAG (0x3f<<0)
211#define AC_UNSOL_ENABLED (1<<7) 229#define AC_UNSOL_ENABLED (1<<7)
230#define AC_USRSP_EN AC_UNSOL_ENABLED
231
232/* Unsolicited responses */
233#define AC_UNSOL_RES_TAG (0x3f<<26)
234#define AC_UNSOL_RES_TAG_SHIFT 26
235#define AC_UNSOL_RES_SUBTAG (0x1f<<21)
236#define AC_UNSOL_RES_SUBTAG_SHIFT 21
237#define AC_UNSOL_RES_ELDV (1<<1) /* ELD Data valid (for HDMI) */
238#define AC_UNSOL_RES_PD (1<<0) /* pinsense detect */
239#define AC_UNSOL_RES_CP_STATE (1<<1) /* content protection */
240#define AC_UNSOL_RES_CP_READY (1<<0) /* content protection */
212 241
213/* Pin widget capabilies */ 242/* Pin widget capabilies */
214#define AC_PINCAP_IMP_SENSE (1<<0) /* impedance sense capable */ 243#define AC_PINCAP_IMP_SENSE (1<<0) /* impedance sense capable */
@@ -222,6 +251,10 @@ enum {
222 * but is marked reserved in the Intel HDA specification. 251 * but is marked reserved in the Intel HDA specification.
223 */ 252 */
224#define AC_PINCAP_LR_SWAP (1<<7) /* L/R swap */ 253#define AC_PINCAP_LR_SWAP (1<<7) /* L/R swap */
254/* Note: The same bit as LR_SWAP is newly defined as HDMI capability
255 * in HD-audio specification
256 */
257#define AC_PINCAP_HDMI (1<<7) /* HDMI pin */
225#define AC_PINCAP_VREF (0x37<<8) 258#define AC_PINCAP_VREF (0x37<<8)
226#define AC_PINCAP_VREF_SHIFT 8 259#define AC_PINCAP_VREF_SHIFT 8
227#define AC_PINCAP_EAPD (1<<16) /* EAPD capable */ 260#define AC_PINCAP_EAPD (1<<16) /* EAPD capable */
@@ -272,6 +305,22 @@ enum {
272#define AC_KNBCAP_NUM_STEPS (0x7f<<0) 305#define AC_KNBCAP_NUM_STEPS (0x7f<<0)
273#define AC_KNBCAP_DELTA (1<<7) 306#define AC_KNBCAP_DELTA (1<<7)
274 307
308/* HDMI LPCM capabilities */
309#define AC_LPCMCAP_48K_CP_CHNS (0x0f<<0) /* max channels w/ CP-on */
310#define AC_LPCMCAP_48K_NO_CHNS (0x0f<<4) /* max channels w/o CP-on */
311#define AC_LPCMCAP_48K_20BIT (1<<8) /* 20b bitrate supported */
312#define AC_LPCMCAP_48K_24BIT (1<<9) /* 24b bitrate supported */
313#define AC_LPCMCAP_96K_CP_CHNS (0x0f<<10) /* max channels w/ CP-on */
314#define AC_LPCMCAP_96K_NO_CHNS (0x0f<<14) /* max channels w/o CP-on */
315#define AC_LPCMCAP_96K_20BIT (1<<18) /* 20b bitrate supported */
316#define AC_LPCMCAP_96K_24BIT (1<<19) /* 24b bitrate supported */
317#define AC_LPCMCAP_192K_CP_CHNS (0x0f<<20) /* max channels w/ CP-on */
318#define AC_LPCMCAP_192K_NO_CHNS (0x0f<<24) /* max channels w/o CP-on */
319#define AC_LPCMCAP_192K_20BIT (1<<28) /* 20b bitrate supported */
320#define AC_LPCMCAP_192K_24BIT (1<<29) /* 24b bitrate supported */
321#define AC_LPCMCAP_44K (1<<30) /* 44.1kHz support */
322#define AC_LPCMCAP_44K_MS (1<<31) /* 44.1kHz-multiplies support */
323
275/* 324/*
276 * Control Parameters 325 * Control Parameters
277 */ 326 */
@@ -317,18 +366,44 @@ enum {
317#define AC_PINCTL_OUT_EN (1<<6) 366#define AC_PINCTL_OUT_EN (1<<6)
318#define AC_PINCTL_HP_EN (1<<7) 367#define AC_PINCTL_HP_EN (1<<7)
319 368
320/* Unsolicited response - 8bit */
321#define AC_USRSP_EN (1<<7)
322
323/* Pin sense - 32bit */ 369/* Pin sense - 32bit */
324#define AC_PINSENSE_IMPEDANCE_MASK (0x7fffffff) 370#define AC_PINSENSE_IMPEDANCE_MASK (0x7fffffff)
325#define AC_PINSENSE_PRESENCE (1<<31) 371#define AC_PINSENSE_PRESENCE (1<<31)
372#define AC_PINSENSE_ELDV (1<<30) /* ELD valid (HDMI) */
326 373
327/* EAPD/BTL enable - 32bit */ 374/* EAPD/BTL enable - 32bit */
328#define AC_EAPDBTL_BALANCED (1<<0) 375#define AC_EAPDBTL_BALANCED (1<<0)
329#define AC_EAPDBTL_EAPD (1<<1) 376#define AC_EAPDBTL_EAPD (1<<1)
330#define AC_EAPDBTL_LR_SWAP (1<<2) 377#define AC_EAPDBTL_LR_SWAP (1<<2)
331 378
379/* HDMI ELD data */
380#define AC_ELDD_ELD_VALID (1<<31)
381#define AC_ELDD_ELD_DATA 0xff
382
383/* HDMI DIP size */
384#define AC_DIPSIZE_ELD_BUF (1<<3) /* ELD buf size of packet size */
385#define AC_DIPSIZE_PACK_IDX (0x07<<0) /* packet index */
386
387/* HDMI DIP index */
388#define AC_DIPIDX_PACK_IDX (0x07<<5) /* packet idnex */
389#define AC_DIPIDX_BYTE_IDX (0x1f<<0) /* byte index */
390
391/* HDMI DIP xmit (transmit) control */
392#define AC_DIPXMIT_MASK (0x3<<6)
393#define AC_DIPXMIT_DISABLE (0x0<<6) /* disable xmit */
394#define AC_DIPXMIT_ONCE (0x2<<6) /* xmit once then disable */
395#define AC_DIPXMIT_BEST (0x3<<6) /* best effort */
396
397/* HDMI content protection (CP) control */
398#define AC_CPCTRL_CES (1<<9) /* current encryption state */
399#define AC_CPCTRL_READY (1<<8) /* ready bit */
400#define AC_CPCTRL_SUBTAG (0x1f<<3) /* subtag for unsol-resp */
401#define AC_CPCTRL_STATE (3<<0) /* current CP request state */
402
403/* Converter channel <-> HDMI slot mapping */
404#define AC_CVTMAP_HDMI_SLOT (0xf<<0) /* HDMI slot number */
405#define AC_CVTMAP_CHAN (0xf<<4) /* converter channel number */
406
332/* configuration default - 32bit */ 407/* configuration default - 32bit */
333#define AC_DEFCFG_SEQUENCE (0xf<<0) 408#define AC_DEFCFG_SEQUENCE (0xf<<0)
334#define AC_DEFCFG_DEF_ASSOC (0xf<<4) 409#define AC_DEFCFG_DEF_ASSOC (0xf<<4)
@@ -449,6 +524,7 @@ enum {
449 */ 524 */
450 525
451struct hda_bus; 526struct hda_bus;
527struct hda_beep;
452struct hda_codec; 528struct hda_codec;
453struct hda_pcm; 529struct hda_pcm;
454struct hda_pcm_stream; 530struct hda_pcm_stream;
@@ -634,6 +710,9 @@ struct hda_codec {
634 /* codec specific info */ 710 /* codec specific info */
635 void *spec; 711 void *spec;
636 712
713 /* beep device */
714 struct hda_beep *beep;
715
637 /* widget capabilities cache */ 716 /* widget capabilities cache */
638 unsigned int num_nodes; 717 unsigned int num_nodes;
639 hda_nid_t start_nid; 718 hda_nid_t start_nid;
@@ -646,9 +725,15 @@ struct hda_codec {
646 unsigned int spdif_status; /* IEC958 status bits */ 725 unsigned int spdif_status; /* IEC958 status bits */
647 unsigned short spdif_ctls; /* SPDIF control bits */ 726 unsigned short spdif_ctls; /* SPDIF control bits */
648 unsigned int spdif_in_enable; /* SPDIF input enable? */ 727 unsigned int spdif_in_enable; /* SPDIF input enable? */
728 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
649 729
650 struct snd_hwdep *hwdep; /* assigned hwdep device */ 730 struct snd_hwdep *hwdep; /* assigned hwdep device */
651 731
732 /* misc flags */
733 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
734 * status change
735 * (e.g. Realtek codecs)
736 */
652#ifdef CONFIG_SND_HDA_POWER_SAVE 737#ifdef CONFIG_SND_HDA_POWER_SAVE
653 unsigned int power_on :1; /* current (global) power-state */ 738 unsigned int power_on :1; /* current (global) power-state */
654 unsigned int power_transition :1; /* power-state in transition */ 739 unsigned int power_transition :1; /* power-state in transition */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 59e4389c94a4..0ca30894f7c6 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -174,7 +174,8 @@ static int build_afg_tree(struct hda_codec *codec)
174 int i, nodes, err; 174 int i, nodes, err;
175 hda_nid_t nid; 175 hda_nid_t nid;
176 176
177 snd_assert(spec, return -EINVAL); 177 if (snd_BUG_ON(!spec))
178 return -EINVAL;
178 179
179 spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP); 180 spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP);
180 spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP); 181 spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 1c53e337ecb2..9f316c1b2790 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -222,9 +222,9 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
222#define RIRB_INT_OVERRUN 0x04 222#define RIRB_INT_OVERRUN 0x04
223#define RIRB_INT_MASK 0x05 223#define RIRB_INT_MASK 0x05
224 224
225/* STATESTS int mask: SD2,SD1,SD0 */ 225/* STATESTS int mask: S3,SD2,SD1,SD0 */
226#define AZX_MAX_CODECS 3 226#define AZX_MAX_CODECS 4
227#define STATESTS_INT_MASK 0x07 227#define STATESTS_INT_MASK 0x0f
228 228
229/* SD_CTL bits */ 229/* SD_CTL bits */
230#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ 230#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
@@ -286,6 +286,11 @@ enum {
286#define INTEL_SCH_HDA_DEVC 0x78 286#define INTEL_SCH_HDA_DEVC 0x78
287#define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11) 287#define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
288 288
289/* Define IN stream 0 FIFO size offset in VIA controller */
290#define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
291/* Define VIA HD Audio Device ID*/
292#define VIA_HDAC_DEVICE_ID 0x3288
293
289 294
290/* 295/*
291 */ 296 */
@@ -317,6 +322,12 @@ struct azx_dev {
317 unsigned int running :1; 322 unsigned int running :1;
318 unsigned int irq_pending :1; 323 unsigned int irq_pending :1;
319 unsigned int irq_ignore :1; 324 unsigned int irq_ignore :1;
325 /*
326 * For VIA:
327 * A flag to ensure DMA position is 0
328 * when link position is not greater than FIFO size
329 */
330 unsigned int insufficient :1;
320}; 331};
321 332
322/* CORB/RIRB */ 333/* CORB/RIRB */
@@ -379,6 +390,7 @@ struct azx {
379 unsigned int polling_mode :1; 390 unsigned int polling_mode :1;
380 unsigned int msi :1; 391 unsigned int msi :1;
381 unsigned int irq_pending_warned :1; 392 unsigned int irq_pending_warned :1;
393 unsigned int via_dmapos_patch :1; /* enable DMA-position fix for VIA */
382 394
383 /* for debugging */ 395 /* for debugging */
384 unsigned int last_cmd; /* last issued command (to sync) */ 396 unsigned int last_cmd; /* last issued command (to sync) */
@@ -398,6 +410,7 @@ enum {
398 AZX_DRIVER_ULI, 410 AZX_DRIVER_ULI,
399 AZX_DRIVER_NVIDIA, 411 AZX_DRIVER_NVIDIA,
400 AZX_DRIVER_TERA, 412 AZX_DRIVER_TERA,
413 AZX_NUM_DRIVERS, /* keep this as last entry */
401}; 414};
402 415
403static char *driver_short_names[] __devinitdata = { 416static char *driver_short_names[] __devinitdata = {
@@ -818,6 +831,11 @@ static void azx_int_clear(struct azx *chip)
818/* start a stream */ 831/* start a stream */
819static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev) 832static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
820{ 833{
834 /*
835 * Before stream start, initialize parameter
836 */
837 azx_dev->insufficient = 1;
838
821 /* enable SIE */ 839 /* enable SIE */
822 azx_writeb(chip, INTCTL, 840 azx_writeb(chip, INTCTL,
823 azx_readb(chip, INTCTL) | (1 << azx_dev->index)); 841 azx_readb(chip, INTCTL) | (1 << azx_dev->index));
@@ -998,7 +1016,6 @@ static int setup_bdle(struct snd_pcm_substream *substream,
998 struct azx_dev *azx_dev, u32 **bdlp, 1016 struct azx_dev *azx_dev, u32 **bdlp,
999 int ofs, int size, int with_ioc) 1017 int ofs, int size, int with_ioc)
1000{ 1018{
1001 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
1002 u32 *bdl = *bdlp; 1019 u32 *bdl = *bdlp;
1003 1020
1004 while (size > 0) { 1021 while (size > 0) {
@@ -1008,14 +1025,12 @@ static int setup_bdle(struct snd_pcm_substream *substream,
1008 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) 1025 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
1009 return -EINVAL; 1026 return -EINVAL;
1010 1027
1011 addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs); 1028 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
1012 /* program the address field of the BDL entry */ 1029 /* program the address field of the BDL entry */
1013 bdl[0] = cpu_to_le32((u32)addr); 1030 bdl[0] = cpu_to_le32((u32)addr);
1014 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 1031 bdl[1] = cpu_to_le32(upper_32_bits(addr));
1015 /* program the size field of the BDL entry */ 1032 /* program the size field of the BDL entry */
1016 chunk = PAGE_SIZE - (ofs % PAGE_SIZE); 1033 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
1017 if (size < chunk)
1018 chunk = size;
1019 bdl[2] = cpu_to_le32(chunk); 1034 bdl[2] = cpu_to_le32(chunk);
1020 /* program the IOC to enable interrupt 1035 /* program the IOC to enable interrupt
1021 * only when the whole fragment is processed 1036 * only when the whole fragment is processed
@@ -1151,7 +1166,8 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1151 1166
1152 /* enable the position buffer */ 1167 /* enable the position buffer */
1153 if (chip->position_fix == POS_FIX_POSBUF || 1168 if (chip->position_fix == POS_FIX_POSBUF ||
1154 chip->position_fix == POS_FIX_AUTO) { 1169 chip->position_fix == POS_FIX_AUTO ||
1170 chip->via_dmapos_patch) {
1155 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) 1171 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
1156 azx_writel(chip, DPLBASE, 1172 azx_writel(chip, DPLBASE,
1157 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE); 1173 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
@@ -1169,23 +1185,26 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1169 * Codec initialization 1185 * Codec initialization
1170 */ 1186 */
1171 1187
1172static unsigned int azx_max_codecs[] __devinitdata = { 1188/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
1173 [AZX_DRIVER_ICH] = 4, /* Some ICH9 boards use SD3 */ 1189static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1174 [AZX_DRIVER_SCH] = 3,
1175 [AZX_DRIVER_ATI] = 4,
1176 [AZX_DRIVER_ATIHDMI] = 4,
1177 [AZX_DRIVER_VIA] = 3, /* FIXME: correct? */
1178 [AZX_DRIVER_SIS] = 3, /* FIXME: correct? */
1179 [AZX_DRIVER_ULI] = 3, /* FIXME: correct? */
1180 [AZX_DRIVER_NVIDIA] = 3, /* FIXME: correct? */
1181 [AZX_DRIVER_TERA] = 1, 1190 [AZX_DRIVER_TERA] = 1,
1182}; 1191};
1183 1192
1193/* number of slots to probe as default
1194 * this can be different from azx_max_codecs[] -- e.g. some boards
1195 * report wrongly the non-existing 4th slot availability
1196 */
1197static unsigned int azx_default_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1198 [AZX_DRIVER_ICH] = 3,
1199 [AZX_DRIVER_ATI] = 3,
1200};
1201
1184static int __devinit azx_codec_create(struct azx *chip, const char *model, 1202static int __devinit azx_codec_create(struct azx *chip, const char *model,
1185 unsigned int codec_probe_mask) 1203 unsigned int codec_probe_mask)
1186{ 1204{
1187 struct hda_bus_template bus_temp; 1205 struct hda_bus_template bus_temp;
1188 int c, codecs, audio_codecs, err; 1206 int c, codecs, audio_codecs, err;
1207 int def_slots, max_slots;
1189 1208
1190 memset(&bus_temp, 0, sizeof(bus_temp)); 1209 memset(&bus_temp, 0, sizeof(bus_temp));
1191 bus_temp.private_data = chip; 1210 bus_temp.private_data = chip;
@@ -1201,8 +1220,17 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1201 if (err < 0) 1220 if (err < 0)
1202 return err; 1221 return err;
1203 1222
1223 if (chip->driver_type == AZX_DRIVER_NVIDIA)
1224 chip->bus->needs_damn_long_delay = 1;
1225
1204 codecs = audio_codecs = 0; 1226 codecs = audio_codecs = 0;
1205 for (c = 0; c < AZX_MAX_CODECS; c++) { 1227 max_slots = azx_max_codecs[chip->driver_type];
1228 if (!max_slots)
1229 max_slots = AZX_MAX_CODECS;
1230 def_slots = azx_default_codecs[chip->driver_type];
1231 if (!def_slots)
1232 def_slots = max_slots;
1233 for (c = 0; c < def_slots; c++) {
1206 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { 1234 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
1207 struct hda_codec *codec; 1235 struct hda_codec *codec;
1208 err = snd_hda_codec_new(chip->bus, c, &codec); 1236 err = snd_hda_codec_new(chip->bus, c, &codec);
@@ -1215,7 +1243,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1215 } 1243 }
1216 if (!audio_codecs) { 1244 if (!audio_codecs) {
1217 /* probe additional slots if no codec is found */ 1245 /* probe additional slots if no codec is found */
1218 for (; c < azx_max_codecs[chip->driver_type]; c++) { 1246 for (; c < max_slots; c++) {
1219 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { 1247 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) {
1220 err = snd_hda_codec_new(chip->bus, c, NULL); 1248 err = snd_hda_codec_new(chip->bus, c, NULL);
1221 if (err < 0) 1249 if (err < 0)
@@ -1507,13 +1535,71 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1507 return 0; 1535 return 0;
1508} 1536}
1509 1537
1538/* get the current DMA position with correction on VIA chips */
1539static unsigned int azx_via_get_position(struct azx *chip,
1540 struct azx_dev *azx_dev)
1541{
1542 unsigned int link_pos, mini_pos, bound_pos;
1543 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
1544 unsigned int fifo_size;
1545
1546 link_pos = azx_sd_readl(azx_dev, SD_LPIB);
1547 if (azx_dev->index >= 4) {
1548 /* Playback, no problem using link position */
1549 return link_pos;
1550 }
1551
1552 /* Capture */
1553 /* For new chipset,
1554 * use mod to get the DMA position just like old chipset
1555 */
1556 mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
1557 mod_dma_pos %= azx_dev->period_bytes;
1558
1559 /* azx_dev->fifo_size can't get FIFO size of in stream.
1560 * Get from base address + offset.
1561 */
1562 fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
1563
1564 if (azx_dev->insufficient) {
1565 /* Link position never gather than FIFO size */
1566 if (link_pos <= fifo_size)
1567 return 0;
1568
1569 azx_dev->insufficient = 0;
1570 }
1571
1572 if (link_pos <= fifo_size)
1573 mini_pos = azx_dev->bufsize + link_pos - fifo_size;
1574 else
1575 mini_pos = link_pos - fifo_size;
1576
1577 /* Find nearest previous boudary */
1578 mod_mini_pos = mini_pos % azx_dev->period_bytes;
1579 mod_link_pos = link_pos % azx_dev->period_bytes;
1580 if (mod_link_pos >= fifo_size)
1581 bound_pos = link_pos - mod_link_pos;
1582 else if (mod_dma_pos >= mod_mini_pos)
1583 bound_pos = mini_pos - mod_mini_pos;
1584 else {
1585 bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
1586 if (bound_pos >= azx_dev->bufsize)
1587 bound_pos = 0;
1588 }
1589
1590 /* Calculate real DMA position we want */
1591 return bound_pos + mod_dma_pos;
1592}
1593
1510static unsigned int azx_get_position(struct azx *chip, 1594static unsigned int azx_get_position(struct azx *chip,
1511 struct azx_dev *azx_dev) 1595 struct azx_dev *azx_dev)
1512{ 1596{
1513 unsigned int pos; 1597 unsigned int pos;
1514 1598
1515 if (chip->position_fix == POS_FIX_POSBUF || 1599 if (chip->via_dmapos_patch)
1516 chip->position_fix == POS_FIX_AUTO) { 1600 pos = azx_via_get_position(chip, azx_dev);
1601 else if (chip->position_fix == POS_FIX_POSBUF ||
1602 chip->position_fix == POS_FIX_AUTO) {
1517 /* use the position buffer */ 1603 /* use the position buffer */
1518 pos = le32_to_cpu(*azx_dev->posbuf); 1604 pos = le32_to_cpu(*azx_dev->posbuf);
1519 } else { 1605 } else {
@@ -1559,6 +1645,8 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
1559 chip->position_fix = POS_FIX_POSBUF; 1645 chip->position_fix = POS_FIX_POSBUF;
1560 } 1646 }
1561 1647
1648 if (!bdl_pos_adj[chip->dev_index])
1649 return 1; /* no delayed ack */
1562 if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) 1650 if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
1563 return 0; /* NG - it's below the period boundary */ 1651 return 0; /* NG - it's below the period boundary */
1564 return 1; /* OK, it's fine */ 1652 return 1; /* OK, it's fine */
@@ -1646,7 +1734,8 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1646 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) 1734 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
1647 return 0; 1735 return 0;
1648 1736
1649 snd_assert(cpcm->name, return -EINVAL); 1737 if (snd_BUG_ON(!cpcm->name))
1738 return -EINVAL;
1650 1739
1651 err = snd_pcm_new(chip->card, cpcm->name, cpcm->device, 1740 err = snd_pcm_new(chip->card, cpcm->name, cpcm->device,
1652 cpcm->stream[0].substreams, 1741 cpcm->stream[0].substreams,
@@ -1670,7 +1759,7 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1670 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops); 1759 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops);
1671 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1760 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1672 snd_dma_pci_data(chip->pci), 1761 snd_dma_pci_data(chip->pci),
1673 1024 * 64, 1024 * 1024); 1762 1024 * 64, 32 * 1024 * 1024);
1674 chip->pcm[cpcm->device] = pcm; 1763 chip->pcm[cpcm->device] = pcm;
1675 return 0; 1764 return 0;
1676} 1765}
@@ -1946,6 +2035,15 @@ static int __devinit check_position_fix(struct azx *chip, int fix)
1946{ 2035{
1947 const struct snd_pci_quirk *q; 2036 const struct snd_pci_quirk *q;
1948 2037
2038 /* Check VIA HD Audio Controller exist */
2039 if (chip->pci->vendor == PCI_VENDOR_ID_VIA &&
2040 chip->pci->device == VIA_HDAC_DEVICE_ID) {
2041 chip->via_dmapos_patch = 1;
2042 /* Use link position directly, avoid any transfer problem. */
2043 return POS_FIX_LPIB;
2044 }
2045 chip->via_dmapos_patch = 0;
2046
1949 if (fix == POS_FIX_AUTO) { 2047 if (fix == POS_FIX_AUTO) {
1950 q = snd_pci_quirk_lookup(chip->pci, position_fix_list); 2048 q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
1951 if (q) { 2049 if (q) {
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 5c9e578f7f2d..7957fefda730 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -368,12 +368,15 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
368#define AMP_OUT_UNMUTE 0xb000 368#define AMP_OUT_UNMUTE 0xb000
369#define AMP_OUT_ZERO 0xb000 369#define AMP_OUT_ZERO 0xb000
370/* pinctl values */ 370/* pinctl values */
371#define PIN_IN 0x20 371#define PIN_IN (AC_PINCTL_IN_EN)
372#define PIN_VREF80 0x24 372#define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
373#define PIN_VREF50 0x21 373#define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
374#define PIN_OUT 0x40 374#define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
375#define PIN_HP 0xc0 375#define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
376#define PIN_HP_AMP 0x80 376#define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
377#define PIN_OUT (AC_PINCTL_OUT_EN)
378#define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
379#define PIN_HP_AMP (AC_PINCTL_HP_EN)
377 380
378/* 381/*
379 * get widget capabilities 382 * get widget capabilities
@@ -418,4 +421,13 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
418 hda_nid_t nid); 421 hda_nid_t nid);
419#endif /* CONFIG_SND_HDA_POWER_SAVE */ 422#endif /* CONFIG_SND_HDA_POWER_SAVE */
420 423
424/*
425 * AMP control callbacks
426 */
427/* retrieve parameters from private_value */
428#define get_amp_nid(kc) ((kc)->private_value & 0xffff)
429#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
430#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
431#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
432
421#endif /* __SOUND_HDA_LOCAL_H */ 433#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_patch.h b/sound/pci/hda/hda_patch.h
index 2fdf2358dbc2..dfbcfa88da44 100644
--- a/sound/pci/hda/hda_patch.h
+++ b/sound/pci/hda/hda_patch.h
@@ -18,3 +18,5 @@ extern struct hda_codec_preset snd_hda_preset_atihdmi[];
18extern struct hda_codec_preset snd_hda_preset_conexant[]; 18extern struct hda_codec_preset snd_hda_preset_conexant[];
19/* VIA codecs */ 19/* VIA codecs */
20extern struct hda_codec_preset snd_hda_preset_via[]; 20extern struct hda_codec_preset snd_hda_preset_via[];
21/* NVIDIA HDMI codecs */
22extern struct hda_codec_preset snd_hda_preset_nvhdmi[];
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 1e5aff5c48d1..743d77922bce 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -216,7 +216,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
216 unsigned int caps, val; 216 unsigned int caps, val;
217 217
218 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 218 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
219 snd_iprintf(buffer, " Pincap 0x08%x:", caps); 219 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
220 if (caps & AC_PINCAP_IN) 220 if (caps & AC_PINCAP_IN)
221 snd_iprintf(buffer, " IN"); 221 snd_iprintf(buffer, " IN");
222 if (caps & AC_PINCAP_OUT) 222 if (caps & AC_PINCAP_OUT)
@@ -229,8 +229,13 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
229 snd_iprintf(buffer, " Detect"); 229 snd_iprintf(buffer, " Detect");
230 if (caps & AC_PINCAP_BALANCE) 230 if (caps & AC_PINCAP_BALANCE)
231 snd_iprintf(buffer, " Balanced"); 231 snd_iprintf(buffer, " Balanced");
232 if (caps & AC_PINCAP_LR_SWAP) 232 if (caps & AC_PINCAP_HDMI) {
233 snd_iprintf(buffer, " R/L"); 233 /* Realtek uses this bit as a different meaning */
234 if ((codec->vendor_id >> 16) == 0x10ec)
235 snd_iprintf(buffer, " R/L");
236 else
237 snd_iprintf(buffer, " HDMI");
238 }
234 if (caps & AC_PINCAP_TRIG_REQ) 239 if (caps & AC_PINCAP_TRIG_REQ)
235 snd_iprintf(buffer, " Trigger"); 240 snd_iprintf(buffer, " Trigger");
236 if (caps & AC_PINCAP_IMP_SENSE) 241 if (caps & AC_PINCAP_IMP_SENSE)
@@ -552,9 +557,15 @@ static void print_codec_info(struct snd_info_entry *entry,
552 557
553 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid, 558 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
554 get_wid_type_name(wid_type), wid_caps); 559 get_wid_type_name(wid_type), wid_caps);
555 if (wid_caps & AC_WCAP_STEREO) 560 if (wid_caps & AC_WCAP_STEREO) {
556 snd_iprintf(buffer, " Stereo"); 561 unsigned int chans;
557 else 562 chans = (wid_caps & AC_WCAP_CHAN_CNT_EXT) >> 13;
563 chans = ((chans << 1) | 1) + 1;
564 if (chans == 2)
565 snd_iprintf(buffer, " Stereo");
566 else
567 snd_iprintf(buffer, " %d-Channels", chans);
568 } else
558 snd_iprintf(buffer, " Mono"); 569 snd_iprintf(buffer, " Mono");
559 if (wid_caps & AC_WCAP_DIGITAL) 570 if (wid_caps & AC_WCAP_DIGITAL)
560 snd_iprintf(buffer, " Digital"); 571 snd_iprintf(buffer, " Digital");
@@ -566,6 +577,8 @@ static void print_codec_info(struct snd_info_entry *entry,
566 snd_iprintf(buffer, " Stripe"); 577 snd_iprintf(buffer, " Stripe");
567 if (wid_caps & AC_WCAP_LR_SWAP) 578 if (wid_caps & AC_WCAP_LR_SWAP)
568 snd_iprintf(buffer, " R/L"); 579 snd_iprintf(buffer, " R/L");
580 if (wid_caps & AC_WCAP_CP_CAPS)
581 snd_iprintf(buffer, " CP");
569 snd_iprintf(buffer, "\n"); 582 snd_iprintf(buffer, "\n");
570 583
571 /* volume knob is a special widget that always have connection 584 /* volume knob is a special widget that always have connection
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index e8003d99f0bf..2b00c4afdf97 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -1826,9 +1826,14 @@ static hda_nid_t ad1988_capsrc_nids[3] = {
1826 0x0c, 0x0d, 0x0e 1826 0x0c, 0x0d, 0x0e
1827}; 1827};
1828 1828
1829#define AD1988_SPDIF_OUT 0x02 1829#define AD1988_SPDIF_OUT 0x02
1830#define AD1988_SPDIF_OUT_HDMI 0x0b
1830#define AD1988_SPDIF_IN 0x07 1831#define AD1988_SPDIF_IN 0x07
1831 1832
1833static hda_nid_t ad1989b_slave_dig_outs[2] = {
1834 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI
1835};
1836
1832static struct hda_input_mux ad1988_6stack_capture_source = { 1837static struct hda_input_mux ad1988_6stack_capture_source = {
1833 .num_items = 5, 1838 .num_items = 5,
1834 .items = { 1839 .items = {
@@ -2143,6 +2148,7 @@ static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2143 2148
2144static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = { 2149static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2145 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT), 2150 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2151 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
2146 { } /* end */ 2152 { } /* end */
2147}; 2153};
2148 2154
@@ -2207,6 +2213,8 @@ static struct hda_verb ad1988_6stack_init_verbs[] = {
2207 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0}, 2213 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2208 /* Analog CD Input */ 2214 /* Analog CD Input */
2209 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2215 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2216 /* Analog Mix output amp */
2217 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2210 2218
2211 { } 2219 { }
2212}; 2220};
@@ -2247,8 +2255,12 @@ static struct hda_verb ad1988_spdif_init_verbs[] = {
2247 2255
2248/* AD1989 has no ADC -> SPDIF route */ 2256/* AD1989 has no ADC -> SPDIF route */
2249static struct hda_verb ad1989_spdif_init_verbs[] = { 2257static struct hda_verb ad1989_spdif_init_verbs[] = {
2250 /* SPDIF out pin */ 2258 /* SPDIF-1 out pin */
2259 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2251 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */ 2260 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2261 /* SPDIF-2/HDMI out pin */
2262 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2263 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2252 { } 2264 { }
2253}; 2265};
2254 2266
@@ -2336,6 +2348,8 @@ static struct hda_verb ad1988_3stack_init_verbs[] = {
2336 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2348 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2349 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2338 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2350 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2351 /* Analog Mix output amp */
2352 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2339 { } 2353 { }
2340}; 2354};
2341 2355
@@ -2409,6 +2423,8 @@ static struct hda_verb ad1988_laptop_init_verbs[] = {
2409 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2423 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2410 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2424 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2411 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2425 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2426 /* Analog Mix output amp */
2427 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2412 { } 2428 { }
2413}; 2429};
2414 2430
@@ -2868,6 +2884,7 @@ static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2868 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG), 2884 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2869 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG), 2885 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2870 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG), 2886 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2887 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
2871 {} 2888 {}
2872}; 2889};
2873 2890
@@ -2975,6 +2992,7 @@ static int patch_ad1988(struct hda_codec *codec)
2975 ad1989_spdif_out_mixers; 2992 ad1989_spdif_out_mixers;
2976 spec->init_verbs[spec->num_init_verbs++] = 2993 spec->init_verbs[spec->num_init_verbs++] =
2977 ad1989_spdif_init_verbs; 2994 ad1989_spdif_init_verbs;
2995 codec->slave_dig_outs = ad1989b_slave_dig_outs;
2978 } else { 2996 } else {
2979 spec->mixers[spec->num_mixers++] = 2997 spec->mixers[spec->num_mixers++] =
2980 ad1988_spdif_out_mixers; 2998 ad1988_spdif_out_mixers;
@@ -3911,7 +3929,7 @@ static int patch_ad1884a(struct hda_codec *codec)
3911 3929
3912 3930
3913/* 3931/*
3914 * AD1882 3932 * AD1882 / AD1882A
3915 * 3933 *
3916 * port-A - front hp-out 3934 * port-A - front hp-out
3917 * port-B - front mic-in 3935 * port-B - front mic-in
@@ -3948,6 +3966,18 @@ static struct hda_input_mux ad1882_capture_source = {
3948 }, 3966 },
3949}; 3967};
3950 3968
3969/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
3970static struct hda_input_mux ad1882a_capture_source = {
3971 .num_items = 5,
3972 .items = {
3973 { "Front Mic", 0x1 },
3974 { "Mic", 0x4},
3975 { "Line", 0x2 },
3976 { "Digital Mic", 0x06 },
3977 { "Mix", 0x7 },
3978 },
3979};
3980
3951static struct snd_kcontrol_new ad1882_base_mixers[] = { 3981static struct snd_kcontrol_new ad1882_base_mixers[] = {
3952 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), 3982 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3953 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT), 3983 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
@@ -3957,16 +3987,7 @@ static struct snd_kcontrol_new ad1882_base_mixers[] = {
3957 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT), 3987 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3958 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT), 3988 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3959 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT), 3989 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3960 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT), 3990
3961 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3962 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3963 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3964 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3965 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3966 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3967 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3968 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3969 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3970 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT), 3991 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3971 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT), 3992 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3972 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT), 3993 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
@@ -3999,6 +4020,35 @@ static struct snd_kcontrol_new ad1882_base_mixers[] = {
3999 { } /* end */ 4020 { } /* end */
4000}; 4021};
4001 4022
4023static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4024 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4025 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4026 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4027 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4028 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4029 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4030 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4031 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4032 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4033 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4034 { } /* end */
4035};
4036
4037static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4038 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4039 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4040 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4041 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4042 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4043 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4044 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4045 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4046 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4047 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4048 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4049 { } /* end */
4050};
4051
4002static struct snd_kcontrol_new ad1882_3stack_mixers[] = { 4052static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4003 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT), 4053 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4004 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT), 4054 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
@@ -4168,9 +4218,16 @@ static int patch_ad1882(struct hda_codec *codec)
4168 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids); 4218 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4169 spec->adc_nids = ad1882_adc_nids; 4219 spec->adc_nids = ad1882_adc_nids;
4170 spec->capsrc_nids = ad1882_capsrc_nids; 4220 spec->capsrc_nids = ad1882_capsrc_nids;
4171 spec->input_mux = &ad1882_capture_source; 4221 if (codec->vendor_id == 0x11d1882)
4172 spec->num_mixers = 1; 4222 spec->input_mux = &ad1882_capture_source;
4223 else
4224 spec->input_mux = &ad1882a_capture_source;
4225 spec->num_mixers = 2;
4173 spec->mixers[0] = ad1882_base_mixers; 4226 spec->mixers[0] = ad1882_base_mixers;
4227 if (codec->vendor_id == 0x11d1882)
4228 spec->mixers[1] = ad1882_loopback_mixers;
4229 else
4230 spec->mixers[1] = ad1882a_loopback_mixers;
4174 spec->num_init_verbs = 1; 4231 spec->num_init_verbs = 1;
4175 spec->init_verbs[0] = ad1882_init_verbs; 4232 spec->init_verbs[0] = ad1882_init_verbs;
4176 spec->spdif_route = 0; 4233 spec->spdif_route = 0;
@@ -4187,8 +4244,8 @@ static int patch_ad1882(struct hda_codec *codec)
4187 switch (board_config) { 4244 switch (board_config) {
4188 default: 4245 default:
4189 case AD1882_3STACK: 4246 case AD1882_3STACK:
4190 spec->num_mixers = 2; 4247 spec->num_mixers = 3;
4191 spec->mixers[1] = ad1882_3stack_mixers; 4248 spec->mixers[2] = ad1882_3stack_mixers;
4192 spec->channel_mode = ad1882_modes; 4249 spec->channel_mode = ad1882_modes;
4193 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes); 4250 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4194 spec->need_dac_fix = 1; 4251 spec->need_dac_fix = 1;
@@ -4196,8 +4253,8 @@ static int patch_ad1882(struct hda_codec *codec)
4196 spec->multiout.num_dacs = 1; 4253 spec->multiout.num_dacs = 1;
4197 break; 4254 break;
4198 case AD1882_6STACK: 4255 case AD1882_6STACK:
4199 spec->num_mixers = 2; 4256 spec->num_mixers = 3;
4200 spec->mixers[1] = ad1882_6stack_mixers; 4257 spec->mixers[2] = ad1882_6stack_mixers;
4201 break; 4258 break;
4202 } 4259 }
4203 return 0; 4260 return 0;
@@ -4220,6 +4277,7 @@ struct hda_codec_preset snd_hda_preset_analog[] = {
4220 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, 4277 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4221 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, 4278 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4222 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 }, 4279 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4280 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
4223 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 }, 4281 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4224 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 }, 4282 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4225 {} /* terminator */ 4283 {} /* terminator */
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index 12272508b112..ba61575983fd 100644
--- a/sound/pci/hda/patch_atihdmi.c
+++ b/sound/pci/hda/patch_atihdmi.c
@@ -35,6 +35,9 @@ struct atihdmi_spec {
35 struct hda_pcm pcm_rec; 35 struct hda_pcm pcm_rec;
36}; 36};
37 37
38#define CVT_NID 0x02 /* audio converter */
39#define PIN_NID 0x03 /* HDMI output pin */
40
38static struct hda_verb atihdmi_basic_init[] = { 41static struct hda_verb atihdmi_basic_init[] = {
39 /* enable digital output on pin widget */ 42 /* enable digital output on pin widget */
40 { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 43 { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
@@ -60,8 +63,9 @@ static int atihdmi_init(struct hda_codec *codec)
60{ 63{
61 snd_hda_sequence_write(codec, atihdmi_basic_init); 64 snd_hda_sequence_write(codec, atihdmi_basic_init);
62 /* SI codec requires to unmute the pin */ 65 /* SI codec requires to unmute the pin */
63 if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP) 66 if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
64 snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE, 67 snd_hda_codec_write(codec, PIN_NID, 0,
68 AC_VERB_SET_AMP_GAIN_MUTE,
65 AMP_OUT_UNMUTE); 69 AMP_OUT_UNMUTE);
66 return 0; 70 return 0;
67} 71}
@@ -92,15 +96,29 @@ static int atihdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
92 struct snd_pcm_substream *substream) 96 struct snd_pcm_substream *substream)
93{ 97{
94 struct atihdmi_spec *spec = codec->spec; 98 struct atihdmi_spec *spec = codec->spec;
95 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, 99 int chans = substream->runtime->channels;
96 format, substream); 100 int i, err;
101
102 err = snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
103 format, substream);
104 if (err < 0)
105 return err;
106 snd_hda_codec_write(codec, CVT_NID, 0, AC_VERB_SET_CVT_CHAN_COUNT,
107 chans - 1);
108 /* FIXME: XXX */
109 for (i = 0; i < chans; i++) {
110 snd_hda_codec_write(codec, CVT_NID, 0,
111 AC_VERB_SET_HDMI_CHAN_SLOT,
112 (i << 4) | i);
113 }
114 return 0;
97} 115}
98 116
99static struct hda_pcm_stream atihdmi_pcm_digital_playback = { 117static struct hda_pcm_stream atihdmi_pcm_digital_playback = {
100 .substreams = 1, 118 .substreams = 1,
101 .channels_min = 2, 119 .channels_min = 2,
102 .channels_max = 2, 120 .channels_max = 2,
103 .nid = 0x2, /* NID to query formats and rates and setup streams */ 121 .nid = CVT_NID, /* NID to query formats and rates and setup streams */
104 .ops = { 122 .ops = {
105 .open = atihdmi_dig_playback_pcm_open, 123 .open = atihdmi_dig_playback_pcm_open,
106 .close = atihdmi_dig_playback_pcm_close, 124 .close = atihdmi_dig_playback_pcm_close,
@@ -112,6 +130,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
112{ 130{
113 struct atihdmi_spec *spec = codec->spec; 131 struct atihdmi_spec *spec = codec->spec;
114 struct hda_pcm *info = &spec->pcm_rec; 132 struct hda_pcm *info = &spec->pcm_rec;
133 unsigned int chans;
115 134
116 codec->num_pcms = 1; 135 codec->num_pcms = 1;
117 codec->pcm_info = info; 136 codec->pcm_info = info;
@@ -120,6 +139,13 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
120 info->pcm_type = HDA_PCM_TYPE_HDMI; 139 info->pcm_type = HDA_PCM_TYPE_HDMI;
121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback; 140 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
122 141
142 /* FIXME: we must check ELD and change the PCM parameters dynamically
143 */
144 chans = get_wcaps(codec, CVT_NID);
145 chans = (chans & AC_WCAP_CHAN_CNT_EXT) >> 13;
146 chans = ((chans << 1) | 1) + 1;
147 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
148
123 return 0; 149 return 0;
124} 150}
125 151
@@ -147,9 +173,11 @@ static int patch_atihdmi(struct hda_codec *codec)
147 173
148 spec->multiout.num_dacs = 0; /* no analog */ 174 spec->multiout.num_dacs = 0; /* no analog */
149 spec->multiout.max_channels = 2; 175 spec->multiout.max_channels = 2;
150 spec->multiout.dig_out_nid = 0x2; /* NID for copying analog to digital, 176 /* NID for copying analog to digital,
151 * seems to be unused in pure-digital 177 * seems to be unused in pure-digital
152 * case. */ 178 * case.
179 */
180 spec->multiout.dig_out_nid = CVT_NID;
153 181
154 codec->patch_ops = atihdmi_patch_ops; 182 codec->patch_ops = atihdmi_patch_ops;
155 183
@@ -164,6 +192,7 @@ struct hda_codec_preset snd_hda_preset_atihdmi[] = {
164 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, 192 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
165 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, 193 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
166 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, 194 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
195 { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_atihdmi },
167 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi }, 196 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
168 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi }, 197 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
169 {} /* terminator */ 198 {} /* terminator */
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
new file mode 100644
index 000000000000..1a65775d28e1
--- /dev/null
+++ b/sound/pci/hda/patch_nvhdmi.c
@@ -0,0 +1,164 @@
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for NVIDIA HDMI codecs
5 *
6 * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
7 * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
8 *
9 *
10 * This driver is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This driver is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/slab.h>
28#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
32struct nvhdmi_spec {
33 struct hda_multi_out multiout;
34
35 struct hda_pcm pcm_rec;
36};
37
38static struct hda_verb nvhdmi_basic_init[] = {
39 /* enable digital output on pin widget */
40 { 0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
41 {} /* terminator */
42};
43
44/*
45 * Controls
46 */
47static int nvhdmi_build_controls(struct hda_codec *codec)
48{
49 struct nvhdmi_spec *spec = codec->spec;
50 int err;
51
52 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
53 if (err < 0)
54 return err;
55
56 return 0;
57}
58
59static int nvhdmi_init(struct hda_codec *codec)
60{
61 snd_hda_sequence_write(codec, nvhdmi_basic_init);
62 return 0;
63}
64
65/*
66 * Digital out
67 */
68static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
69 struct hda_codec *codec,
70 struct snd_pcm_substream *substream)
71{
72 struct nvhdmi_spec *spec = codec->spec;
73 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
74}
75
76static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
77 struct hda_codec *codec,
78 struct snd_pcm_substream *substream)
79{
80 struct nvhdmi_spec *spec = codec->spec;
81 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
82}
83
84static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
85 struct hda_codec *codec,
86 unsigned int stream_tag,
87 unsigned int format,
88 struct snd_pcm_substream *substream)
89{
90 struct nvhdmi_spec *spec = codec->spec;
91 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
92 format, substream);
93}
94
95static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
96 .substreams = 1,
97 .channels_min = 2,
98 .channels_max = 2,
99 .nid = 0x4, /* NID to query formats and rates and setup streams */
100 .rates = SNDRV_PCM_RATE_48000,
101 .maxbps = 16,
102 .formats = SNDRV_PCM_FMTBIT_S16_LE,
103 .ops = {
104 .open = nvhdmi_dig_playback_pcm_open,
105 .close = nvhdmi_dig_playback_pcm_close,
106 .prepare = nvhdmi_dig_playback_pcm_prepare
107 },
108};
109
110static int nvhdmi_build_pcms(struct hda_codec *codec)
111{
112 struct nvhdmi_spec *spec = codec->spec;
113 struct hda_pcm *info = &spec->pcm_rec;
114
115 codec->num_pcms = 1;
116 codec->pcm_info = info;
117
118 info->name = "NVIDIA HDMI";
119 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
120
121 return 0;
122}
123
124static void nvhdmi_free(struct hda_codec *codec)
125{
126 kfree(codec->spec);
127}
128
129static struct hda_codec_ops nvhdmi_patch_ops = {
130 .build_controls = nvhdmi_build_controls,
131 .build_pcms = nvhdmi_build_pcms,
132 .init = nvhdmi_init,
133 .free = nvhdmi_free,
134};
135
136static int patch_nvhdmi(struct hda_codec *codec)
137{
138 struct nvhdmi_spec *spec;
139
140 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
141 if (spec == NULL)
142 return -ENOMEM;
143
144 codec->spec = spec;
145
146 spec->multiout.num_dacs = 0; /* no analog */
147 spec->multiout.max_channels = 2;
148 spec->multiout.dig_out_nid = 0x4; /* NID for copying analog to digital,
149 * seems to be unused in pure-digital
150 * case. */
151
152 codec->patch_ops = nvhdmi_patch_ops;
153
154 return 0;
155}
156
157/*
158 * patch entries
159 */
160struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
161 { .id = 0x10de0002, .name = "NVIDIA MCP78 HDMI", .patch = patch_nvhdmi },
162 { .id = 0x10de0007, .name = "NVIDIA MCP7A HDMI", .patch = patch_nvhdmi },
163 {} /* terminator */
164};
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 66025161bd69..0b6e682c46d0 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -72,6 +72,7 @@ enum {
72enum { 72enum {
73 ALC260_BASIC, 73 ALC260_BASIC,
74 ALC260_HP, 74 ALC260_HP,
75 ALC260_HP_DC7600,
75 ALC260_HP_3013, 76 ALC260_HP_3013,
76 ALC260_FUJITSU_S702X, 77 ALC260_FUJITSU_S702X,
77 ALC260_ACER, 78 ALC260_ACER,
@@ -100,6 +101,9 @@ enum {
100 ALC262_BENQ_T31, 101 ALC262_BENQ_T31,
101 ALC262_ULTRA, 102 ALC262_ULTRA,
102 ALC262_LENOVO_3000, 103 ALC262_LENOVO_3000,
104 ALC262_NEC,
105 ALC262_TOSHIBA_S06,
106 ALC262_TOSHIBA_RX1,
103 ALC262_AUTO, 107 ALC262_AUTO,
104 ALC262_MODEL_LAST /* last tag */ 108 ALC262_MODEL_LAST /* last tag */
105}; 109};
@@ -110,6 +114,7 @@ enum {
110 ALC268_3ST, 114 ALC268_3ST,
111 ALC268_TOSHIBA, 115 ALC268_TOSHIBA,
112 ALC268_ACER, 116 ALC268_ACER,
117 ALC268_ACER_ASPIRE_ONE,
113 ALC268_DELL, 118 ALC268_DELL,
114 ALC268_ZEPTO, 119 ALC268_ZEPTO,
115#ifdef CONFIG_SND_DEBUG 120#ifdef CONFIG_SND_DEBUG
@@ -122,6 +127,7 @@ enum {
122/* ALC269 models */ 127/* ALC269 models */
123enum { 128enum {
124 ALC269_BASIC, 129 ALC269_BASIC,
130 ALC269_QUANTA_FL1,
125 ALC269_ASUS_EEEPC_P703, 131 ALC269_ASUS_EEEPC_P703,
126 ALC269_ASUS_EEEPC_P901, 132 ALC269_ASUS_EEEPC_P901,
127 ALC269_AUTO, 133 ALC269_AUTO,
@@ -169,6 +175,13 @@ enum {
169 ALC663_ASUS_G71V, 175 ALC663_ASUS_G71V,
170 ALC663_ASUS_H13, 176 ALC663_ASUS_H13,
171 ALC663_ASUS_G50V, 177 ALC663_ASUS_G50V,
178 ALC662_ECS,
179 ALC663_ASUS_MODE1,
180 ALC662_ASUS_MODE2,
181 ALC663_ASUS_MODE3,
182 ALC663_ASUS_MODE4,
183 ALC663_ASUS_MODE5,
184 ALC663_ASUS_MODE6,
172 ALC662_AUTO, 185 ALC662_AUTO,
173 ALC662_MODEL_LAST, 186 ALC662_MODEL_LAST,
174}; 187};
@@ -200,18 +213,21 @@ enum {
200 ALC883_ACER, 213 ALC883_ACER,
201 ALC883_ACER_ASPIRE, 214 ALC883_ACER_ASPIRE,
202 ALC883_MEDION, 215 ALC883_MEDION,
203 ALC883_MEDION_MD2, 216 ALC883_MEDION_MD2,
204 ALC883_LAPTOP_EAPD, 217 ALC883_LAPTOP_EAPD,
205 ALC883_LENOVO_101E_2ch, 218 ALC883_LENOVO_101E_2ch,
206 ALC883_LENOVO_NB0763, 219 ALC883_LENOVO_NB0763,
207 ALC888_LENOVO_MS7195_DIG, 220 ALC888_LENOVO_MS7195_DIG,
208 ALC883_HAIER_W66, 221 ALC888_LENOVO_SKY,
222 ALC883_HAIER_W66,
209 ALC888_3ST_HP, 223 ALC888_3ST_HP,
210 ALC888_6ST_DELL, 224 ALC888_6ST_DELL,
211 ALC883_MITAC, 225 ALC883_MITAC,
212 ALC883_CLEVO_M720, 226 ALC883_CLEVO_M720,
213 ALC883_FUJITSU_PI2515, 227 ALC883_FUJITSU_PI2515,
214 ALC883_3ST_6ch_INTEL, 228 ALC883_3ST_6ch_INTEL,
229 ALC888_ASUS_M90V,
230 ALC888_ASUS_EEE1601,
215 ALC883_AUTO, 231 ALC883_AUTO,
216 ALC883_MODEL_LAST, 232 ALC883_MODEL_LAST,
217}; 233};
@@ -398,7 +414,7 @@ static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
398 414
399/* 415/*
400 * Control the mode of pin widget settings via the mixer. "pc" is used 416 * Control the mode of pin widget settings via the mixer. "pc" is used
401 * instead of "%" to avoid consequences of accidently treating the % as 417 * instead of "%" to avoid consequences of accidently treating the % as
402 * being part of a format specifier. Maximum allowed length of a value is 418 * being part of a format specifier. Maximum allowed length of a value is
403 * 63 characters plus NULL terminator. 419 * 63 characters plus NULL terminator.
404 * 420 *
@@ -429,7 +445,7 @@ static unsigned char alc_pin_mode_values[] = {
429#define ALC_PIN_DIR_IN_NOMICBIAS 0x03 445#define ALC_PIN_DIR_IN_NOMICBIAS 0x03
430#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04 446#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
431 447
432/* Info about the pin modes supported by the different pin direction modes. 448/* Info about the pin modes supported by the different pin direction modes.
433 * For each direction the minimum and maximum values are given. 449 * For each direction the minimum and maximum values are given.
434 */ 450 */
435static signed char alc_pin_mode_dir_info[5][2] = { 451static signed char alc_pin_mode_dir_info[5][2] = {
@@ -502,7 +518,7 @@ static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
502 AC_VERB_SET_PIN_WIDGET_CONTROL, 518 AC_VERB_SET_PIN_WIDGET_CONTROL,
503 alc_pin_mode_values[val]); 519 alc_pin_mode_values[val]);
504 520
505 /* Also enable the retasking pin's input/output as required 521 /* Also enable the retasking pin's input/output as required
506 * for the requested pin mode. Enum values of 2 or less are 522 * for the requested pin mode. Enum values of 2 or less are
507 * input modes. 523 * input modes.
508 * 524 *
@@ -707,7 +723,7 @@ static void setup_preset(struct alc_spec *spec,
707 i++) 723 i++)
708 spec->init_verbs[spec->num_init_verbs++] = 724 spec->init_verbs[spec->num_init_verbs++] =
709 preset->init_verbs[i]; 725 preset->init_verbs[i];
710 726
711 spec->channel_mode = preset->channel_mode; 727 spec->channel_mode = preset->channel_mode;
712 spec->num_channel_mode = preset->num_channel_mode; 728 spec->num_channel_mode = preset->num_channel_mode;
713 spec->need_dac_fix = preset->need_dac_fix; 729 spec->need_dac_fix = preset->need_dac_fix;
@@ -718,7 +734,7 @@ static void setup_preset(struct alc_spec *spec,
718 spec->multiout.dac_nids = preset->dac_nids; 734 spec->multiout.dac_nids = preset->dac_nids;
719 spec->multiout.dig_out_nid = preset->dig_out_nid; 735 spec->multiout.dig_out_nid = preset->dig_out_nid;
720 spec->multiout.hp_nid = preset->hp_nid; 736 spec->multiout.hp_nid = preset->hp_nid;
721 737
722 spec->num_mux_defs = preset->num_mux_defs; 738 spec->num_mux_defs = preset->num_mux_defs;
723 if (!spec->num_mux_defs) 739 if (!spec->num_mux_defs)
724 spec->num_mux_defs = 1; 740 spec->num_mux_defs = 1;
@@ -855,7 +871,7 @@ static void alc_subsystem_id(struct hda_codec *codec,
855 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) 871 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
856 goto do_sku; 872 goto do_sku;
857 873
858 /* 874 /*
859 * 31~30 : port conetcivity 875 * 31~30 : port conetcivity
860 * 29~21 : reserve 876 * 29~21 : reserve
861 * 20 : PCBEEP input 877 * 20 : PCBEEP input
@@ -946,7 +962,7 @@ do_sku:
946 tmp = snd_hda_codec_read(codec, 0x20, 0, 962 tmp = snd_hda_codec_read(codec, 0x20, 0,
947 AC_VERB_GET_PROC_COEF, 0); 963 AC_VERB_GET_PROC_COEF, 0);
948 snd_hda_codec_write(codec, 0x20, 0, 964 snd_hda_codec_write(codec, 0x20, 0,
949 AC_VERB_SET_COEF_INDEX, 7); 965 AC_VERB_SET_COEF_INDEX, 7);
950 snd_hda_codec_write(codec, 0x20, 0, 966 snd_hda_codec_write(codec, 0x20, 0,
951 AC_VERB_SET_PROC_COEF, 967 AC_VERB_SET_PROC_COEF,
952 tmp | 0x2010); 968 tmp | 0x2010);
@@ -961,7 +977,7 @@ do_sku:
961 tmp = snd_hda_codec_read(codec, 0x20, 0, 977 tmp = snd_hda_codec_read(codec, 0x20, 0,
962 AC_VERB_GET_PROC_COEF, 0); 978 AC_VERB_GET_PROC_COEF, 0);
963 snd_hda_codec_write(codec, 0x20, 0, 979 snd_hda_codec_write(codec, 0x20, 0,
964 AC_VERB_SET_COEF_INDEX, 7); 980 AC_VERB_SET_COEF_INDEX, 7);
965 snd_hda_codec_write(codec, 0x20, 0, 981 snd_hda_codec_write(codec, 0x20, 0,
966 AC_VERB_SET_PROC_COEF, 982 AC_VERB_SET_PROC_COEF,
967 tmp | 0x3000); 983 tmp | 0x3000);
@@ -970,7 +986,7 @@ do_sku:
970 default: 986 default:
971 break; 987 break;
972 } 988 }
973 989
974 /* is laptop or Desktop and enable the function "Mute internal speaker 990 /* is laptop or Desktop and enable the function "Mute internal speaker
975 * when the external headphone out jack is plugged" 991 * when the external headphone out jack is plugged"
976 */ 992 */
@@ -1006,6 +1022,7 @@ do_sku:
1006 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0, 1022 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1007 AC_VERB_SET_UNSOLICITED_ENABLE, 1023 AC_VERB_SET_UNSOLICITED_ENABLE,
1008 AC_USRSP_EN | ALC880_HP_EVENT); 1024 AC_USRSP_EN | ALC880_HP_EVENT);
1025
1009 spec->unsol_event = alc_sku_unsol_event; 1026 spec->unsol_event = alc_sku_unsol_event;
1010} 1027}
1011 1028
@@ -1296,7 +1313,7 @@ static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1296 * 1313 *
1297 * The system also has a pair of internal speakers, and a headphone jack. 1314 * The system also has a pair of internal speakers, and a headphone jack.
1298 * These are both connected to Line2 on the codec, hence to DAC 02. 1315 * These are both connected to Line2 on the codec, hence to DAC 02.
1299 * 1316 *
1300 * There is a variable resistor to control the speaker or headphone 1317 * There is a variable resistor to control the speaker or headphone
1301 * volume. This is a hardware-only device without a software API. 1318 * volume. This is a hardware-only device without a software API.
1302 * 1319 *
@@ -1824,7 +1841,7 @@ static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1824 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1841 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1825 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1842 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1826 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1843 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1827 1844
1828 { } 1845 { }
1829}; 1846};
1830 1847
@@ -1869,7 +1886,7 @@ static struct hda_verb alc880_uniwill_init_verbs[] = {
1869 1886
1870/* 1887/*
1871* Uniwill P53 1888* Uniwill P53
1872* HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 1889* HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1873 */ 1890 */
1874static struct hda_verb alc880_uniwill_p53_init_verbs[] = { 1891static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1875 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 1892 {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
@@ -1968,7 +1985,7 @@ static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1968static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 1985static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1969{ 1986{
1970 unsigned int present; 1987 unsigned int present;
1971 1988
1972 present = snd_hda_codec_read(codec, 0x21, 0, 1989 present = snd_hda_codec_read(codec, 0x21, 0,
1973 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0); 1990 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1974 present &= HDA_AMP_VOLMASK; 1991 present &= HDA_AMP_VOLMASK;
@@ -2050,7 +2067,7 @@ static struct hda_verb alc880_pin_asus_init_verbs[] = {
2050 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2067 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2051 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2068 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2052 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2069 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2053 2070
2054 { } 2071 { }
2055}; 2072};
2056 2073
@@ -2632,12 +2649,14 @@ static int alc_build_pcms(struct hda_codec *codec)
2632 2649
2633 info->name = spec->stream_name_analog; 2650 info->name = spec->stream_name_analog;
2634 if (spec->stream_analog_playback) { 2651 if (spec->stream_analog_playback) {
2635 snd_assert(spec->multiout.dac_nids, return -EINVAL); 2652 if (snd_BUG_ON(!spec->multiout.dac_nids))
2653 return -EINVAL;
2636 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); 2654 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2637 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 2655 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2638 } 2656 }
2639 if (spec->stream_analog_capture) { 2657 if (spec->stream_analog_capture) {
2640 snd_assert(spec->adc_nids, return -EINVAL); 2658 if (snd_BUG_ON(!spec->adc_nids))
2659 return -EINVAL;
2641 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); 2660 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2642 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 2661 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2643 } 2662 }
@@ -2667,6 +2686,8 @@ static int alc_build_pcms(struct hda_codec *codec)
2667 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture); 2686 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2668 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; 2687 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2669 } 2688 }
2689 /* FIXME: do we need this for all Realtek codec models? */
2690 codec->spdif_status_reset = 1;
2670 } 2691 }
2671 2692
2672 /* If the use of more than one ADC is requested for the current 2693 /* If the use of more than one ADC is requested for the current
@@ -3683,7 +3704,7 @@ static void alc880_auto_init_multi_out(struct hda_codec *codec)
3683{ 3704{
3684 struct alc_spec *spec = codec->spec; 3705 struct alc_spec *spec = codec->spec;
3685 int i; 3706 int i;
3686 3707
3687 alc_subsystem_id(codec, 0x15, 0x1b, 0x14); 3708 alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3688 for (i = 0; i < spec->autocfg.line_outs; i++) { 3709 for (i = 0; i < spec->autocfg.line_outs; i++) {
3689 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 3710 hda_nid_t nid = spec->autocfg.line_out_pins[i];
@@ -4124,6 +4145,33 @@ static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4124 { } /* end */ 4145 { } /* end */
4125}; 4146};
4126 4147
4148static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4149 .ops = &snd_hda_bind_vol,
4150 .values = {
4151 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4152 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4153 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4154 0
4155 },
4156};
4157
4158static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4159 .ops = &snd_hda_bind_sw,
4160 .values = {
4161 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4162 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4163 0
4164 },
4165};
4166
4167static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4168 HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4169 HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4170 HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4171 HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4172 { } /* end */
4173};
4174
4127static struct hda_verb alc260_hp_3013_unsol_verbs[] = { 4175static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4128 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 4176 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4129 {}, 4177 {},
@@ -4147,7 +4195,30 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4147 alc260_hp_3013_automute(codec); 4195 alc260_hp_3013_automute(codec);
4148} 4196}
4149 4197
4150/* Fujitsu S702x series laptops. ALC260 pin usage: Mic/Line jack = 0x12, 4198static void alc260_hp_3012_automute(struct hda_codec *codec)
4199{
4200 unsigned int present, bits;
4201
4202 present = snd_hda_codec_read(codec, 0x10, 0,
4203 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4204
4205 bits = present ? 0 : PIN_OUT;
4206 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4207 bits);
4208 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4209 bits);
4210 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4211 bits);
4212}
4213
4214static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4215 unsigned int res)
4216{
4217 if ((res >> 26) == ALC880_HP_EVENT)
4218 alc260_hp_3012_automute(codec);
4219}
4220
4221/* Fujitsu S702x series laptops. ALC260 pin usage: Mic/Line jack = 0x12,
4151 * HP jack = 0x14, CD audio = 0x16, internal speaker = 0x10. 4222 * HP jack = 0x14, CD audio = 0x16, internal speaker = 0x10.
4152 */ 4223 */
4153static struct snd_kcontrol_new alc260_fujitsu_mixer[] = { 4224static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
@@ -4478,7 +4549,7 @@ static struct hda_verb alc260_fujitsu_init_verbs[] = {
4478 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0}, 4549 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4479 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0}, 4550 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4480 4551
4481 /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 4552 /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4482 * when acting as an output. 4553 * when acting as an output.
4483 */ 4554 */
4484 {0x0d, AC_VERB_SET_CONNECT_SEL, 0}, 4555 {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
@@ -4503,14 +4574,14 @@ static struct hda_verb alc260_fujitsu_init_verbs[] = {
4503 * stage. 4574 * stage.
4504 */ 4575 */
4505 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 4576 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4506 /* Unmute input buffer of pin widget used for Line-in (no equiv 4577 /* Unmute input buffer of pin widget used for Line-in (no equiv
4507 * mixer ctrl) 4578 * mixer ctrl)
4508 */ 4579 */
4509 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 4580 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4510 4581
4511 /* Mute capture amp left and right */ 4582 /* Mute capture amp left and right */
4512 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 4583 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4513 /* Set ADC connection select to match default mixer setting - line 4584 /* Set ADC connection select to match default mixer setting - line
4514 * in (on mic1 pin) 4585 * in (on mic1 pin)
4515 */ 4586 */
4516 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00}, 4587 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -4564,7 +4635,7 @@ static struct hda_verb alc260_acer_init_verbs[] = {
4564 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0}, 4635 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4565 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0}, 4636 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4566 4637
4567 /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 4638 /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4568 * bus when acting as outputs. 4639 * bus when acting as outputs.
4569 */ 4640 */
4570 {0x0b, AC_VERB_SET_CONNECT_SEL, 0}, 4641 {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
@@ -4675,6 +4746,20 @@ static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4675 alc260_replacer_672v_automute(codec); 4746 alc260_replacer_672v_automute(codec);
4676} 4747}
4677 4748
4749static struct hda_verb alc260_hp_dc7600_verbs[] = {
4750 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
4751 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4752 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4753 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4754 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4755 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4756 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4757 {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4758 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4759 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4760 {}
4761};
4762
4678/* Test configuration for debugging, modelled after the ALC880 test 4763/* Test configuration for debugging, modelled after the ALC880 test
4679 * configuration. 4764 * configuration.
4680 */ 4765 */
@@ -4686,7 +4771,7 @@ static hda_nid_t alc260_test_adc_nids[2] = {
4686 0x04, 0x05, 4771 0x04, 0x05,
4687}; 4772};
4688/* For testing the ALC260, each input MUX needs its own definition since 4773/* For testing the ALC260, each input MUX needs its own definition since
4689 * the signal assignments are different. This assumes that the first ADC 4774 * the signal assignments are different. This assumes that the first ADC
4690 * is NID 0x04. 4775 * is NID 0x04.
4691 */ 4776 */
4692static struct hda_input_mux alc260_test_capture_sources[2] = { 4777static struct hda_input_mux alc260_test_capture_sources[2] = {
@@ -4769,7 +4854,7 @@ static struct snd_kcontrol_new alc260_test_mixer[] = {
4769 4854
4770 /* Switches to allow the digital IO pins to be enabled. The datasheet 4855 /* Switches to allow the digital IO pins to be enabled. The datasheet
4771 * is ambigious as to which NID is which; testing on laptops which 4856 * is ambigious as to which NID is which; testing on laptops which
4772 * make this output available should provide clarification. 4857 * make this output available should provide clarification.
4773 */ 4858 */
4774 ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01), 4859 ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4775 ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01), 4860 ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
@@ -4805,7 +4890,7 @@ static struct hda_verb alc260_test_init_verbs[] = {
4805 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0}, 4890 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4806 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0}, 4891 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4807 4892
4808 /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 4893 /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
4809 * OUT1 sum bus when acting as an output. 4894 * OUT1 sum bus when acting as an output.
4810 */ 4895 */
4811 {0x0b, AC_VERB_SET_CONNECT_SEL, 0}, 4896 {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
@@ -4897,7 +4982,7 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4897 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); 4982 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4898 } else 4983 } else
4899 return 0; /* N/A */ 4984 return 0; /* N/A */
4900 4985
4901 snprintf(name, sizeof(name), "%s Playback Volume", pfx); 4986 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4902 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val); 4987 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4903 if (err < 0) 4988 if (err < 0)
@@ -5003,7 +5088,7 @@ static void alc260_auto_init_multi_out(struct hda_codec *codec)
5003 int pin_type = get_pin_type(spec->autocfg.line_out_type); 5088 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5004 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0); 5089 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5005 } 5090 }
5006 5091
5007 nid = spec->autocfg.speaker_pins[0]; 5092 nid = spec->autocfg.speaker_pins[0];
5008 if (nid) 5093 if (nid)
5009 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0); 5094 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
@@ -5045,7 +5130,7 @@ static struct hda_verb alc260_volume_init_verbs[] = {
5045 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 5130 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5046 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00}, 5131 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5047 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 5132 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5048 5133
5049 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback 5134 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5050 * mixer widget 5135 * mixer widget
5051 * Note: PASD motherboards uses the Line In 2 as the input for 5136 * Note: PASD motherboards uses the Line In 2 as the input for
@@ -5074,7 +5159,7 @@ static struct hda_verb alc260_volume_init_verbs[] = {
5074 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 5159 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5075 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 5160 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5076 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 5161 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5077 5162
5078 { } 5163 { }
5079}; 5164};
5080 5165
@@ -5155,6 +5240,7 @@ static const char *alc260_models[ALC260_MODEL_LAST] = {
5155 [ALC260_BASIC] = "basic", 5240 [ALC260_BASIC] = "basic",
5156 [ALC260_HP] = "hp", 5241 [ALC260_HP] = "hp",
5157 [ALC260_HP_3013] = "hp-3013", 5242 [ALC260_HP_3013] = "hp-3013",
5243 [ALC260_HP_DC7600] = "hp-dc7600",
5158 [ALC260_FUJITSU_S702X] = "fujitsu", 5244 [ALC260_FUJITSU_S702X] = "fujitsu",
5159 [ALC260_ACER] = "acer", 5245 [ALC260_ACER] = "acer",
5160 [ALC260_WILL] = "will", 5246 [ALC260_WILL] = "will",
@@ -5172,7 +5258,7 @@ static struct snd_pci_quirk alc260_cfg_tbl[] = {
5172 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013), 5258 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5173 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013), 5259 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5174 SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013), 5260 SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5175 SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013), 5261 SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5176 SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013), 5262 SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5177 SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP), 5263 SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5178 SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP), 5264 SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
@@ -5218,6 +5304,22 @@ static struct alc_config_preset alc260_presets[] = {
5218 .unsol_event = alc260_hp_unsol_event, 5304 .unsol_event = alc260_hp_unsol_event,
5219 .init_hook = alc260_hp_automute, 5305 .init_hook = alc260_hp_automute,
5220 }, 5306 },
5307 [ALC260_HP_DC7600] = {
5308 .mixers = { alc260_hp_dc7600_mixer,
5309 alc260_input_mixer,
5310 alc260_capture_alt_mixer },
5311 .init_verbs = { alc260_init_verbs,
5312 alc260_hp_dc7600_verbs },
5313 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5314 .dac_nids = alc260_dac_nids,
5315 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5316 .adc_nids = alc260_hp_adc_nids,
5317 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5318 .channel_mode = alc260_modes,
5319 .input_mux = &alc260_capture_source,
5320 .unsol_event = alc260_hp_3012_unsol_event,
5321 .init_hook = alc260_hp_3012_automute,
5322 },
5221 [ALC260_HP_3013] = { 5323 [ALC260_HP_3013] = {
5222 .mixers = { alc260_hp_3013_mixer, 5324 .mixers = { alc260_hp_3013_mixer,
5223 alc260_input_mixer, 5325 alc260_input_mixer,
@@ -5933,7 +6035,7 @@ static struct hda_verb alc882_targa_verbs[] = {
5933 6035
5934 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 6036 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5935 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 6037 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5936 6038
5937 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */ 6039 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5938 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */ 6040 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5939 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 6041 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
@@ -5949,7 +6051,7 @@ static struct hda_verb alc882_targa_verbs[] = {
5949static void alc882_targa_automute(struct hda_codec *codec) 6051static void alc882_targa_automute(struct hda_codec *codec)
5950{ 6052{
5951 unsigned int present; 6053 unsigned int present;
5952 6054
5953 present = snd_hda_codec_read(codec, 0x14, 0, 6055 present = snd_hda_codec_read(codec, 0x14, 0,
5954 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 6056 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5955 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0, 6057 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
@@ -5975,7 +6077,7 @@ static struct hda_verb alc882_asus_a7j_verbs[] = {
5975 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 6077 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5976 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 6078 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5977 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 6079 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5978 6080
5979 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */ 6081 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5980 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 6082 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5981 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */ 6083 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
@@ -5993,7 +6095,7 @@ static struct hda_verb alc882_asus_a7m_verbs[] = {
5993 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 6095 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5994 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 6096 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5995 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 6097 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5996 6098
5997 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */ 6099 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5998 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 6100 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5999 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */ 6101 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
@@ -6319,7 +6421,7 @@ static struct alc_config_preset alc882_presets[] = {
6319 .channel_mode = alc882_3ST_6ch_modes, 6421 .channel_mode = alc882_3ST_6ch_modes,
6320 .need_dac_fix = 1, 6422 .need_dac_fix = 1,
6321 .input_mux = &alc882_capture_source, 6423 .input_mux = &alc882_capture_source,
6322 }, 6424 },
6323 [ALC882_ASUS_A7M] = { 6425 [ALC882_ASUS_A7M] = {
6324 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer }, 6426 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6325 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs, 6427 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
@@ -6332,14 +6434,14 @@ static struct alc_config_preset alc882_presets[] = {
6332 .channel_mode = alc880_threestack_modes, 6434 .channel_mode = alc880_threestack_modes,
6333 .need_dac_fix = 1, 6435 .need_dac_fix = 1,
6334 .input_mux = &alc882_capture_source, 6436 .input_mux = &alc882_capture_source,
6335 }, 6437 },
6336}; 6438};
6337 6439
6338 6440
6339/* 6441/*
6340 * Pin config fixes 6442 * Pin config fixes
6341 */ 6443 */
6342enum { 6444enum {
6343 PINFIX_ABIT_AW9D_MAX 6445 PINFIX_ABIT_AW9D_MAX
6344}; 6446};
6345 6447
@@ -6554,16 +6656,19 @@ static int patch_alc882(struct hda_codec *codec)
6554 board_config = ALC885_MACPRO; 6656 board_config = ALC885_MACPRO;
6555 break; 6657 break;
6556 case 0x106b1000: /* iMac 24 */ 6658 case 0x106b1000: /* iMac 24 */
6659 case 0x106b2800: /* AppleTV */
6557 board_config = ALC885_IMAC24; 6660 board_config = ALC885_IMAC24;
6558 break; 6661 break;
6559 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */ 6662 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6663 case 0x106b00a4: /* MacbookPro4,1 */
6560 case 0x106b2c00: /* Macbook Pro rev3 */ 6664 case 0x106b2c00: /* Macbook Pro rev3 */
6561 case 0x106b3600: /* Macbook 3.1 */ 6665 case 0x106b3600: /* Macbook 3.1 */
6562 board_config = ALC885_MBP3; 6666 board_config = ALC885_MBP3;
6563 break; 6667 break;
6564 default: 6668 default:
6565 /* ALC889A is handled better as ALC888-compatible */ 6669 /* ALC889A is handled better as ALC888-compatible */
6566 if (codec->revision_id == 0x100103) { 6670 if (codec->revision_id == 0x100101 ||
6671 codec->revision_id == 0x100103) {
6567 alc_free(codec); 6672 alc_free(codec);
6568 return patch_alc883(codec); 6673 return patch_alc883(codec);
6569 } 6674 }
@@ -6718,6 +6823,23 @@ static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6718 }, 6823 },
6719}; 6824};
6720 6825
6826static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6827 .num_items = 3,
6828 .items = {
6829 { "Mic", 0x0 },
6830 { "Front Mic", 0x1 },
6831 { "Line", 0x4 },
6832 },
6833};
6834
6835static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6836 .num_items = 2,
6837 .items = {
6838 { "Mic", 0x0 },
6839 { "Line", 0x2 },
6840 },
6841};
6842
6721#define alc883_mux_enum_info alc_mux_enum_info 6843#define alc883_mux_enum_info alc_mux_enum_info
6722#define alc883_mux_enum_get alc_mux_enum_get 6844#define alc883_mux_enum_get alc_mux_enum_get
6723/* ALC883 has the ALC882-type input selection */ 6845/* ALC883 has the ALC882-type input selection */
@@ -7032,13 +7154,11 @@ static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7032 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT), 7154 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7033 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 7155 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7034 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 7156 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7035 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7036 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7037 { 7157 {
7038 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 7158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7039 /* .name = "Capture Source", */ 7159 /* .name = "Capture Source", */
7040 .name = "Input Source", 7160 .name = "Input Source",
7041 .count = 2, 7161 .count = 1,
7042 .info = alc883_mux_enum_info, 7162 .info = alc883_mux_enum_info,
7043 .get = alc883_mux_enum_get, 7163 .get = alc883_mux_enum_get,
7044 .put = alc883_mux_enum_put, 7164 .put = alc883_mux_enum_put,
@@ -7256,7 +7376,7 @@ static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7256 .put = alc883_mux_enum_put, 7376 .put = alc883_mux_enum_put,
7257 }, 7377 },
7258 { } /* end */ 7378 { } /* end */
7259}; 7379};
7260 7380
7261static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = { 7381static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7262 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7382 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -7283,6 +7403,87 @@ static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7283 { } /* end */ 7403 { } /* end */
7284}; 7404};
7285 7405
7406static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7407 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7408 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7409 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7410 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7411 HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7412 0x0d, 1, 0x0, HDA_OUTPUT),
7413 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7414 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7415 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7416 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7417 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7418 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7419 HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7420 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7421 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7422 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7423 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7424 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7425 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7426 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7427 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7428 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7429 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7430 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7431 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7432 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7433 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7434 {
7435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7436 /* .name = "Capture Source", */
7437 .name = "Input Source",
7438 .count = 2,
7439 .info = alc883_mux_enum_info,
7440 .get = alc883_mux_enum_get,
7441 .put = alc883_mux_enum_put,
7442 },
7443 { } /* end */
7444};
7445
7446static struct hda_bind_ctls alc883_bind_cap_vol = {
7447 .ops = &snd_hda_bind_vol,
7448 .values = {
7449 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7450 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7451 0
7452 },
7453};
7454
7455static struct hda_bind_ctls alc883_bind_cap_switch = {
7456 .ops = &snd_hda_bind_sw,
7457 .values = {
7458 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7459 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7460 0
7461 },
7462};
7463
7464static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7465 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7466 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7467 HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7468 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7469 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7470 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7471 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7472 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7473 HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7474 HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7475 {
7476 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7477 /* .name = "Capture Source", */
7478 .name = "Input Source",
7479 .count = 1,
7480 .info = alc883_mux_enum_info,
7481 .get = alc883_mux_enum_get,
7482 .put = alc883_mux_enum_put,
7483 },
7484 { } /* end */
7485};
7486
7286static struct snd_kcontrol_new alc883_chmode_mixer[] = { 7487static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7287 { 7488 {
7288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 7489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -7296,7 +7497,7 @@ static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7296 7497
7297static struct hda_verb alc883_init_verbs[] = { 7498static struct hda_verb alc883_init_verbs[] = {
7298 /* ADC1: mute amp left and right */ 7499 /* ADC1: mute amp left and right */
7299 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7500 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7300 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 7501 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7301 /* ADC2: mute amp left and right */ 7502 /* ADC2: mute amp left and right */
7302 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7503 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
@@ -7361,14 +7562,14 @@ static struct hda_verb alc883_init_verbs[] = {
7361 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 7562 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7362 /* Input mixer2 */ 7563 /* Input mixer2 */
7363 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7564 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7364 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 7565 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7365 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 7566 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7366 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, 7567 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7367 /* Input mixer3 */ 7568 /* Input mixer3 */
7368 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7569 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7369 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 7570 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7370 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 7571 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7371 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, 7572 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7372 { } 7573 { }
7373}; 7574};
7374 7575
@@ -7468,7 +7669,7 @@ static struct hda_verb alc883_tagra_verbs[] = {
7468 7669
7469 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 7670 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7470 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7671 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7471 7672
7472 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */ 7673 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7473 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */ 7674 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7474 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */ 7675 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
@@ -7518,6 +7719,18 @@ static struct hda_verb alc883_haier_w66_verbs[] = {
7518 { } /* end */ 7719 { } /* end */
7519}; 7720};
7520 7721
7722static struct hda_verb alc888_lenovo_sky_verbs[] = {
7723 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7724 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7725 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7726 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7727 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7728 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7729 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7730 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7731 { } /* end */
7732};
7733
7521static struct hda_verb alc888_3st_hp_verbs[] = { 7734static struct hda_verb alc888_3st_hp_verbs[] = {
7522 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */ 7735 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7523 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */ 7736 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */
@@ -7555,7 +7768,7 @@ static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7555static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec) 7768static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7556{ 7769{
7557 unsigned int present; 7770 unsigned int present;
7558 7771
7559 present = snd_hda_codec_read(codec, 0x1b, 0, 7772 present = snd_hda_codec_read(codec, 0x1b, 0,
7560 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 7773 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7561 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 7774 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -7568,7 +7781,7 @@ static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7568static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec) 7781static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7569{ 7782{
7570 unsigned int present; 7783 unsigned int present;
7571 7784
7572 present = snd_hda_codec_read(codec, 0x14, 0, 7785 present = snd_hda_codec_read(codec, 0x14, 0,
7573 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 7786 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7574 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 7787 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -7598,7 +7811,7 @@ static struct hda_verb alc883_medion_md2_verbs[] = {
7598static void alc883_medion_md2_automute(struct hda_codec *codec) 7811static void alc883_medion_md2_automute(struct hda_codec *codec)
7599{ 7812{
7600 unsigned int present; 7813 unsigned int present;
7601 7814
7602 present = snd_hda_codec_read(codec, 0x14, 0, 7815 present = snd_hda_codec_read(codec, 0x14, 0,
7603 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 7816 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7604 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 7817 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -7753,7 +7966,7 @@ static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7753static void alc883_acer_aspire_automute(struct hda_codec *codec) 7966static void alc883_acer_aspire_automute(struct hda_codec *codec)
7754{ 7967{
7755 unsigned int present; 7968 unsigned int present;
7756 7969
7757 present = snd_hda_codec_read(codec, 0x14, 0, 7970 present = snd_hda_codec_read(codec, 0x14, 0,
7758 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 7971 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7759 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 7972 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -7790,7 +8003,7 @@ static struct hda_verb alc883_acer_eapd_verbs[] = {
7790static void alc888_6st_dell_front_automute(struct hda_codec *codec) 8003static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7791{ 8004{
7792 unsigned int present; 8005 unsigned int present;
7793 8006
7794 present = snd_hda_codec_read(codec, 0x1b, 0, 8007 present = snd_hda_codec_read(codec, 0x1b, 0,
7795 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 8008 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7796 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8009 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -7814,6 +8027,50 @@ static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7814 } 8027 }
7815} 8028}
7816 8029
8030static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8031{
8032 unsigned int mute;
8033 unsigned int present;
8034
8035 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8036 present = snd_hda_codec_read(codec, 0x1b, 0,
8037 AC_VERB_GET_PIN_SENSE, 0);
8038 present = (present & 0x80000000) != 0;
8039 if (present) {
8040 /* mute internal speaker */
8041 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8042 HDA_AMP_MUTE, HDA_AMP_MUTE);
8043 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8044 HDA_AMP_MUTE, HDA_AMP_MUTE);
8045 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8046 HDA_AMP_MUTE, HDA_AMP_MUTE);
8047 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8048 HDA_AMP_MUTE, HDA_AMP_MUTE);
8049 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8050 HDA_AMP_MUTE, HDA_AMP_MUTE);
8051 } else {
8052 /* unmute internal speaker if necessary */
8053 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8054 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8055 HDA_AMP_MUTE, mute);
8056 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8057 HDA_AMP_MUTE, mute);
8058 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8059 HDA_AMP_MUTE, mute);
8060 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8061 HDA_AMP_MUTE, mute);
8062 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8063 HDA_AMP_MUTE, mute);
8064 }
8065}
8066
8067static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8068 unsigned int res)
8069{
8070 if ((res >> 26) == ALC880_HP_EVENT)
8071 alc888_lenovo_sky_front_automute(codec);
8072}
8073
7817/* 8074/*
7818 * generic initialization of ADC, input mixers and output mixers 8075 * generic initialization of ADC, input mixers and output mixers
7819 */ 8076 */
@@ -7898,6 +8155,105 @@ static struct snd_kcontrol_new alc883_capture_mixer[] = {
7898 { } /* end */ 8155 { } /* end */
7899}; 8156};
7900 8157
8158static struct hda_verb alc888_asus_m90v_verbs[] = {
8159 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8160 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8161 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8162 /* enable unsolicited event */
8163 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8164 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8165 { } /* end */
8166};
8167
8168static void alc883_nb_mic_automute(struct hda_codec *codec)
8169{
8170 unsigned int present;
8171
8172 present = snd_hda_codec_read(codec, 0x18, 0,
8173 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8174 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8175 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8176 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8177 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8178}
8179
8180static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8181{
8182 unsigned int present;
8183 unsigned char bits;
8184
8185 present = snd_hda_codec_read(codec, 0x1b, 0,
8186 AC_VERB_GET_PIN_SENSE, 0)
8187 & AC_PINSENSE_PRESENCE;
8188 bits = present ? 0 : PIN_OUT;
8189 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8190 bits);
8191 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8192 bits);
8193 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8194 bits);
8195}
8196
8197static void alc883_mode2_unsol_event(struct hda_codec *codec,
8198 unsigned int res)
8199{
8200 switch (res >> 26) {
8201 case ALC880_HP_EVENT:
8202 alc883_M90V_speaker_automute(codec);
8203 break;
8204 case ALC880_MIC_EVENT:
8205 alc883_nb_mic_automute(codec);
8206 break;
8207 }
8208}
8209
8210static void alc883_mode2_inithook(struct hda_codec *codec)
8211{
8212 alc883_M90V_speaker_automute(codec);
8213 alc883_nb_mic_automute(codec);
8214}
8215
8216static struct hda_verb alc888_asus_eee1601_verbs[] = {
8217 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8218 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8219 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8220 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8221 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8222 {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8223 {0x20, AC_VERB_SET_PROC_COEF, 0x0838},
8224 /* enable unsolicited event */
8225 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8226 { } /* end */
8227};
8228
8229static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8230{
8231 unsigned int present;
8232 unsigned char bits;
8233
8234 present = snd_hda_codec_read(codec, 0x14, 0,
8235 AC_VERB_GET_PIN_SENSE, 0)
8236 & AC_PINSENSE_PRESENCE;
8237 bits = present ? 0 : PIN_OUT;
8238 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8239 bits);
8240}
8241
8242static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8243 unsigned int res)
8244{
8245 switch (res >> 26) {
8246 case ALC880_HP_EVENT:
8247 alc883_eee1601_speaker_automute(codec);
8248 break;
8249 }
8250}
8251
8252static void alc883_eee1601_inithook(struct hda_codec *codec)
8253{
8254 alc883_eee1601_speaker_automute(codec);
8255}
8256
7901#ifdef CONFIG_SND_HDA_POWER_SAVE 8257#ifdef CONFIG_SND_HDA_POWER_SAVE
7902#define alc883_loopbacks alc880_loopbacks 8258#define alc883_loopbacks alc880_loopbacks
7903#endif 8259#endif
@@ -7927,6 +8283,7 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
7927 [ALC883_LENOVO_101E_2ch] = "lenovo-101e", 8283 [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7928 [ALC883_LENOVO_NB0763] = "lenovo-nb0763", 8284 [ALC883_LENOVO_NB0763] = "lenovo-nb0763",
7929 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig", 8285 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8286 [ALC888_LENOVO_SKY] = "lenovo-sky",
7930 [ALC883_HAIER_W66] = "haier-w66", 8287 [ALC883_HAIER_W66] = "haier-w66",
7931 [ALC888_3ST_HP] = "3stack-hp", 8288 [ALC888_3ST_HP] = "3stack-hp",
7932 [ALC888_6ST_DELL] = "6stack-dell", 8289 [ALC888_6ST_DELL] = "6stack-dell",
@@ -7942,7 +8299,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7942 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE), 8299 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7943 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE), 8300 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7944 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE), 8301 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7945 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE), 8302 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
7946 SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */ 8303 SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7947 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL), 8304 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7948 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 8305 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
@@ -7950,10 +8307,13 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7950 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 8307 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7951 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG), 8308 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7952 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 8309 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8310 SND_PCI_QUIRK(0x1043, 0x8317, "Asus M90V", ALC888_ASUS_M90V),
8311 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
7953 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG), 8312 SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
7954 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 8313 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7955 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC), 8314 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7956 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD), 8315 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8316 SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
7957 SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch), 8317 SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7958 SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG), 8318 SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7959 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG), 8319 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
@@ -7989,6 +8349,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7989 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763), 8349 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7990 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763), 8350 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7991 SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763), 8351 SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8352 SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
7992 SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2), 8353 SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7993 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG), 8354 SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7994 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66), 8355 SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
@@ -8128,7 +8489,7 @@ static struct alc_config_preset alc883_presets[] = {
8128 .input_mux = &alc883_capture_source, 8489 .input_mux = &alc883_capture_source,
8129 .unsol_event = alc883_medion_md2_unsol_event, 8490 .unsol_event = alc883_medion_md2_unsol_event,
8130 .init_hook = alc883_medion_md2_automute, 8491 .init_hook = alc883_medion_md2_automute,
8131 }, 8492 },
8132 [ALC883_LAPTOP_EAPD] = { 8493 [ALC883_LAPTOP_EAPD] = {
8133 .mixers = { alc883_base_mixer }, 8494 .mixers = { alc883_base_mixer },
8134 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs }, 8495 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
@@ -8245,6 +8606,49 @@ static struct alc_config_preset alc883_presets[] = {
8245 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event, 8606 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8246 .init_hook = alc883_2ch_fujitsu_pi2515_automute, 8607 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8247 }, 8608 },
8609 [ALC888_LENOVO_SKY] = {
8610 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8611 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8612 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8613 .dac_nids = alc883_dac_nids,
8614 .dig_out_nid = ALC883_DIGOUT_NID,
8615 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
8616 .adc_nids = alc883_adc_nids,
8617 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8618 .channel_mode = alc883_sixstack_modes,
8619 .need_dac_fix = 1,
8620 .input_mux = &alc883_lenovo_sky_capture_source,
8621 .unsol_event = alc883_lenovo_sky_unsol_event,
8622 .init_hook = alc888_lenovo_sky_front_automute,
8623 },
8624 [ALC888_ASUS_M90V] = {
8625 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8626 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8627 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8628 .dac_nids = alc883_dac_nids,
8629 .dig_out_nid = ALC883_DIGOUT_NID,
8630 .dig_in_nid = ALC883_DIGIN_NID,
8631 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8632 .channel_mode = alc883_3ST_6ch_modes,
8633 .need_dac_fix = 1,
8634 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8635 .unsol_event = alc883_mode2_unsol_event,
8636 .init_hook = alc883_mode2_inithook,
8637 },
8638 [ALC888_ASUS_EEE1601] = {
8639 .mixers = { alc883_asus_eee1601_mixer },
8640 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8641 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8642 .dac_nids = alc883_dac_nids,
8643 .dig_out_nid = ALC883_DIGOUT_NID,
8644 .dig_in_nid = ALC883_DIGIN_NID,
8645 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8646 .channel_mode = alc883_3ST_2ch_modes,
8647 .need_dac_fix = 1,
8648 .input_mux = &alc883_asus_eee1601_capture_source,
8649 .unsol_event = alc883_eee1601_unsol_event,
8650 .init_hook = alc883_eee1601_inithook,
8651 },
8248}; 8652};
8249 8653
8250 8654
@@ -8452,6 +8856,13 @@ static int patch_alc883(struct hda_codec *codec)
8452#define alc262_modes alc260_modes 8856#define alc262_modes alc260_modes
8453#define alc262_capture_source alc882_capture_source 8857#define alc262_capture_source alc882_capture_source
8454 8858
8859static hda_nid_t alc262_dmic_adc_nids[1] = {
8860 /* ADC0 */
8861 0x09
8862};
8863
8864static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
8865
8455static struct snd_kcontrol_new alc262_base_mixer[] = { 8866static struct snd_kcontrol_new alc262_base_mixer[] = {
8456 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 8867 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8457 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), 8868 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
@@ -8833,10 +9244,10 @@ static struct hda_verb alc262_init_verbs[] = {
8833 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000}, 9244 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8834 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000}, 9245 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8835 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000}, 9246 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8836 9247
8837 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, 9248 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8838 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 9249 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8839 9250
8840 /* FIXME: use matrix-type input source selection */ 9251 /* FIXME: use matrix-type input source selection */
8841 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 9252 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8842 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */ 9253 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
@@ -8858,6 +9269,12 @@ static struct hda_verb alc262_init_verbs[] = {
8858 { } 9269 { }
8859}; 9270};
8860 9271
9272static struct hda_verb alc262_eapd_verbs[] = {
9273 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9274 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9275 { }
9276};
9277
8861static struct hda_verb alc262_hippo_unsol_verbs[] = { 9278static struct hda_verb alc262_hippo_unsol_verbs[] = {
8862 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 9279 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8863 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 9280 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
@@ -8884,6 +9301,91 @@ static struct hda_verb alc262_sony_unsol_verbs[] = {
8884 {} 9301 {}
8885}; 9302};
8886 9303
9304static struct hda_input_mux alc262_dmic_capture_source = {
9305 .num_items = 2,
9306 .items = {
9307 { "Int DMic", 0x9 },
9308 { "Mic", 0x0 },
9309 },
9310};
9311
9312static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9313 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9314 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9315 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9316 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9317 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9318 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9319 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9320 {
9321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9322 /* The multiple "Capture Source" controls confuse alsamixer
9323 * So call somewhat different..
9324 */
9325 /* .name = "Capture Source", */
9326 .name = "Input Source",
9327 .count = 1,
9328 .info = alc_mux_enum_info,
9329 .get = alc_mux_enum_get,
9330 .put = alc_mux_enum_put,
9331 },
9332 { } /* end */
9333};
9334
9335static struct hda_verb alc262_toshiba_s06_verbs[] = {
9336 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9337 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9338 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9339 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9340 {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9341 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9342 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9343 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9344 {}
9345};
9346
9347static void alc262_dmic_automute(struct hda_codec *codec)
9348{
9349 unsigned int present;
9350
9351 present = snd_hda_codec_read(codec, 0x18, 0,
9352 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9353 snd_hda_codec_write(codec, 0x22, 0,
9354 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9355}
9356
9357/* toggle speaker-output according to the hp-jack state */
9358static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9359{
9360 unsigned int present;
9361 unsigned char bits;
9362
9363 present = snd_hda_codec_read(codec, 0x15, 0,
9364 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9365 bits = present ? 0 : PIN_OUT;
9366 snd_hda_codec_write(codec, 0x14, 0,
9367 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9368}
9369
9370
9371
9372/* unsolicited event for HP jack sensing */
9373static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9374 unsigned int res)
9375{
9376 if ((res >> 26) == ALC880_HP_EVENT)
9377 alc262_toshiba_s06_speaker_automute(codec);
9378 if ((res >> 26) == ALC880_MIC_EVENT)
9379 alc262_dmic_automute(codec);
9380
9381}
9382
9383static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9384{
9385 alc262_toshiba_s06_speaker_automute(codec);
9386 alc262_dmic_automute(codec);
9387}
9388
8887/* mute/unmute internal speaker according to the hp jack and mute state */ 9389/* mute/unmute internal speaker according to the hp jack and mute state */
8888static void alc262_hippo_automute(struct hda_codec *codec) 9390static void alc262_hippo_automute(struct hda_codec *codec)
8889{ 9391{
@@ -8948,6 +9450,41 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8948} 9450}
8949 9451
8950/* 9452/*
9453 * nec model
9454 * 0x15 = headphone
9455 * 0x16 = internal speaker
9456 * 0x18 = external mic
9457 */
9458
9459static struct snd_kcontrol_new alc262_nec_mixer[] = {
9460 HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9461 HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9462
9463 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9464 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9465 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9466
9467 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9468 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9469 { } /* end */
9470};
9471
9472static struct hda_verb alc262_nec_verbs[] = {
9473 /* Unmute Speaker */
9474 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9475
9476 /* Headphone */
9477 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9478 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9479
9480 /* External mic to headphone */
9481 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9482 /* External mic to speaker */
9483 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9484 {}
9485};
9486
9487/*
8951 * fujitsu model 9488 * fujitsu model
8952 * 0x14 = headphone/spdif-out, 0x15 = internal speaker, 9489 * 0x14 = headphone/spdif-out, 0x15 = internal speaker,
8953 * 0x1b = port replicator headphone out 9490 * 0x1b = port replicator headphone out
@@ -9179,6 +9716,25 @@ static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9179 { } /* end */ 9716 { } /* end */
9180}; 9717};
9181 9718
9719static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9720 HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9721 {
9722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9723 .name = "Master Playback Switch",
9724 .info = snd_hda_mixer_amp_switch_info,
9725 .get = snd_hda_mixer_amp_switch_get,
9726 .put = alc262_sony_master_sw_put,
9727 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9728 },
9729 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9730 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9731 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9732 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9733 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9734 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9735 { } /* end */
9736};
9737
9182/* additional init verbs for Benq laptops */ 9738/* additional init verbs for Benq laptops */
9183static struct hda_verb alc262_EAPD_verbs[] = { 9739static struct hda_verb alc262_EAPD_verbs[] = {
9184 {0x20, AC_VERB_SET_COEF_INDEX, 0x07}, 9740 {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
@@ -9427,7 +9983,7 @@ static struct hda_verb alc262_volume_init_verbs[] = {
9427 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 9983 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9428 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 9984 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9429 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 9985 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9430 9986
9431 /* set up input amps for analog loopback */ 9987 /* set up input amps for analog loopback */
9432 /* Amp Indices: DAC = 0, mixer = 1 */ 9988 /* Amp Indices: DAC = 0, mixer = 1 */
9433 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 9989 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -9482,7 +10038,7 @@ static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9482 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 10038 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9483 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, 10039 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9484 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, 10040 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9485 10041
9486 /* 10042 /*
9487 * Set up output mixers (0x0c - 0x0e) 10043 * Set up output mixers (0x0c - 0x0e)
9488 */ 10044 */
@@ -9643,6 +10199,24 @@ static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9643 { } 10199 { }
9644}; 10200};
9645 10201
10202static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10203
10204 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Front Speaker */
10205 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10206 {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10207
10208 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* MIC jack */
10209 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Front MIC */
10210 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10211 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10212
10213 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP jack */
10214 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10215 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10216 {}
10217};
10218
10219
9646#ifdef CONFIG_SND_HDA_POWER_SAVE 10220#ifdef CONFIG_SND_HDA_POWER_SAVE
9647#define alc262_loopbacks alc880_loopbacks 10221#define alc262_loopbacks alc880_loopbacks
9648#endif 10222#endif
@@ -9729,13 +10303,17 @@ static const char *alc262_models[ALC262_MODEL_LAST] = {
9729 [ALC262_BENQ_ED8] = "benq", 10303 [ALC262_BENQ_ED8] = "benq",
9730 [ALC262_BENQ_T31] = "benq-t31", 10304 [ALC262_BENQ_T31] = "benq-t31",
9731 [ALC262_SONY_ASSAMD] = "sony-assamd", 10305 [ALC262_SONY_ASSAMD] = "sony-assamd",
10306 [ALC262_TOSHIBA_S06] = "toshiba-s06",
10307 [ALC262_TOSHIBA_RX1] = "toshiba-rx1",
9732 [ALC262_ULTRA] = "ultra", 10308 [ALC262_ULTRA] = "ultra",
9733 [ALC262_LENOVO_3000] = "lenovo-3000", 10309 [ALC262_LENOVO_3000] = "lenovo-3000",
10310 [ALC262_NEC] = "nec",
9734 [ALC262_AUTO] = "auto", 10311 [ALC262_AUTO] = "auto",
9735}; 10312};
9736 10313
9737static struct snd_pci_quirk alc262_cfg_tbl[] = { 10314static struct snd_pci_quirk alc262_cfg_tbl[] = {
9738 SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO), 10315 SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10316 SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
9739 SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC), 10317 SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9740 SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC), 10318 SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9741 SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC), 10319 SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
@@ -9764,7 +10342,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
9764 SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD), 10342 SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9765 SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD), 10343 SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9766 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 10344 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
9767 ALC262_SONY_ASSAMD), 10345 ALC262_TOSHIBA_RX1),
10346 SND_PCI_QUIRK(0x1179, 0x0268, "Toshiba S06", ALC262_TOSHIBA_S06),
9768 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU), 10347 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9769 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU), 10348 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9770 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA), 10349 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
@@ -9918,7 +10497,7 @@ static struct alc_config_preset alc262_presets[] = {
9918 .input_mux = &alc262_capture_source, 10497 .input_mux = &alc262_capture_source,
9919 .unsol_event = alc262_hippo_unsol_event, 10498 .unsol_event = alc262_hippo_unsol_event,
9920 .init_hook = alc262_hippo_automute, 10499 .init_hook = alc262_hippo_automute,
9921 }, 10500 },
9922 [ALC262_ULTRA] = { 10501 [ALC262_ULTRA] = {
9923 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer }, 10502 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9924 .init_verbs = { alc262_ultra_verbs }, 10503 .init_verbs = { alc262_ultra_verbs },
@@ -9946,6 +10525,43 @@ static struct alc_config_preset alc262_presets[] = {
9946 .input_mux = &alc262_fujitsu_capture_source, 10525 .input_mux = &alc262_fujitsu_capture_source,
9947 .unsol_event = alc262_lenovo_3000_unsol_event, 10526 .unsol_event = alc262_lenovo_3000_unsol_event,
9948 }, 10527 },
10528 [ALC262_NEC] = {
10529 .mixers = { alc262_nec_mixer },
10530 .init_verbs = { alc262_nec_verbs },
10531 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10532 .dac_nids = alc262_dac_nids,
10533 .hp_nid = 0x03,
10534 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10535 .channel_mode = alc262_modes,
10536 .input_mux = &alc262_capture_source,
10537 },
10538 [ALC262_TOSHIBA_S06] = {
10539 .mixers = { alc262_toshiba_s06_mixer },
10540 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10541 alc262_eapd_verbs },
10542 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10543 .capsrc_nids = alc262_dmic_capsrc_nids,
10544 .dac_nids = alc262_dac_nids,
10545 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10546 .dig_out_nid = ALC262_DIGOUT_NID,
10547 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10548 .channel_mode = alc262_modes,
10549 .input_mux = &alc262_dmic_capture_source,
10550 .unsol_event = alc262_toshiba_s06_unsol_event,
10551 .init_hook = alc262_toshiba_s06_init_hook,
10552 },
10553 [ALC262_TOSHIBA_RX1] = {
10554 .mixers = { alc262_toshiba_rx1_mixer },
10555 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10556 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10557 .dac_nids = alc262_dac_nids,
10558 .hp_nid = 0x03,
10559 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10560 .channel_mode = alc262_modes,
10561 .input_mux = &alc262_capture_source,
10562 .unsol_event = alc262_hippo_unsol_event,
10563 .init_hook = alc262_hippo_automute,
10564 },
9949}; 10565};
9950 10566
9951static int patch_alc262(struct hda_codec *codec) 10567static int patch_alc262(struct hda_codec *codec)
@@ -10004,7 +10620,7 @@ static int patch_alc262(struct hda_codec *codec)
10004 spec->stream_name_analog = "ALC262 Analog"; 10620 spec->stream_name_analog = "ALC262 Analog";
10005 spec->stream_analog_playback = &alc262_pcm_analog_playback; 10621 spec->stream_analog_playback = &alc262_pcm_analog_playback;
10006 spec->stream_analog_capture = &alc262_pcm_analog_capture; 10622 spec->stream_analog_capture = &alc262_pcm_analog_capture;
10007 10623
10008 spec->stream_name_digital = "ALC262 Digital"; 10624 spec->stream_name_digital = "ALC262 Digital";
10009 spec->stream_digital_playback = &alc262_pcm_digital_playback; 10625 spec->stream_digital_playback = &alc262_pcm_digital_playback;
10010 spec->stream_digital_capture = &alc262_pcm_digital_capture; 10626 spec->stream_digital_capture = &alc262_pcm_digital_capture;
@@ -10040,7 +10656,7 @@ static int patch_alc262(struct hda_codec *codec)
10040 if (!spec->loopback.amplist) 10656 if (!spec->loopback.amplist)
10041 spec->loopback.amplist = alc262_loopbacks; 10657 spec->loopback.amplist = alc262_loopbacks;
10042#endif 10658#endif
10043 10659
10044 return 0; 10660 return 0;
10045} 10661}
10046 10662
@@ -10049,7 +10665,7 @@ static int patch_alc262(struct hda_codec *codec)
10049 */ 10665 */
10050#define ALC268_DIGOUT_NID ALC880_DIGOUT_NID 10666#define ALC268_DIGOUT_NID ALC880_DIGOUT_NID
10051#define alc268_modes alc260_modes 10667#define alc268_modes alc260_modes
10052 10668
10053static hda_nid_t alc268_dac_nids[2] = { 10669static hda_nid_t alc268_dac_nids[2] = {
10054 /* front, hp */ 10670 /* front, hp */
10055 0x02, 0x03 10671 0x02, 0x03
@@ -10109,6 +10725,14 @@ static struct hda_verb alc268_toshiba_verbs[] = {
10109 { } /* end */ 10725 { } /* end */
10110}; 10726};
10111 10727
10728static struct hda_input_mux alc268_acer_lc_capture_source = {
10729 .num_items = 2,
10730 .items = {
10731 { "i-Mic", 0x6 },
10732 { "E-Mic", 0x0 },
10733 },
10734};
10735
10112/* Acer specific */ 10736/* Acer specific */
10113/* bind volumes of both NID 0x02 and 0x03 */ 10737/* bind volumes of both NID 0x02 and 0x03 */
10114static struct hda_bind_ctls alc268_acer_bind_master_vol = { 10738static struct hda_bind_ctls alc268_acer_bind_master_vol = {
@@ -10161,6 +10785,21 @@ static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10161 return change; 10785 return change;
10162} 10786}
10163 10787
10788static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10789 /* output mixer control */
10790 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10791 {
10792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10793 .name = "Master Playback Switch",
10794 .info = snd_hda_mixer_amp_switch_info,
10795 .get = snd_hda_mixer_amp_switch_get,
10796 .put = alc268_acer_master_sw_put,
10797 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10798 },
10799 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10800 { }
10801};
10802
10164static struct snd_kcontrol_new alc268_acer_mixer[] = { 10803static struct snd_kcontrol_new alc268_acer_mixer[] = {
10165 /* output mixer control */ 10804 /* output mixer control */
10166 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol), 10805 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
@@ -10178,6 +10817,16 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
10178 { } 10817 { }
10179}; 10818};
10180 10819
10820static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10821 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10822 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10823 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10824 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10825 {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
10826 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
10827 { }
10828};
10829
10181static struct hda_verb alc268_acer_verbs[] = { 10830static struct hda_verb alc268_acer_verbs[] = {
10182 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */ 10831 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10183 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 10832 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
@@ -10185,7 +10834,6 @@ static struct hda_verb alc268_acer_verbs[] = {
10185 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10834 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10186 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 10835 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10187 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 10836 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10188
10189 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 10837 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10190 { } 10838 { }
10191}; 10839};
@@ -10212,6 +10860,47 @@ static void alc268_acer_init_hook(struct hda_codec *codec)
10212 alc268_acer_automute(codec, 1); 10860 alc268_acer_automute(codec, 1);
10213} 10861}
10214 10862
10863/* toggle speaker-output according to the hp-jack state */
10864static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
10865{
10866 unsigned int present;
10867 unsigned char bits;
10868
10869 present = snd_hda_codec_read(codec, 0x15, 0,
10870 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10871 bits = present ? AMP_IN_MUTE(0) : 0;
10872 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
10873 AMP_IN_MUTE(0), bits);
10874 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
10875 AMP_IN_MUTE(0), bits);
10876}
10877
10878
10879static void alc268_acer_mic_automute(struct hda_codec *codec)
10880{
10881 unsigned int present;
10882
10883 present = snd_hda_codec_read(codec, 0x18, 0,
10884 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10885 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
10886 present ? 0x0 : 0x6);
10887}
10888
10889static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
10890 unsigned int res)
10891{
10892 if ((res >> 26) == ALC880_HP_EVENT)
10893 alc268_aspire_one_speaker_automute(codec);
10894 if ((res >> 26) == ALC880_MIC_EVENT)
10895 alc268_acer_mic_automute(codec);
10896}
10897
10898static void alc268_acer_lc_init_hook(struct hda_codec *codec)
10899{
10900 alc268_aspire_one_speaker_automute(codec);
10901 alc268_acer_mic_automute(codec);
10902}
10903
10215static struct snd_kcontrol_new alc268_dell_mixer[] = { 10904static struct snd_kcontrol_new alc268_dell_mixer[] = {
10216 /* output mixer control */ 10905 /* output mixer control */
10217 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT), 10906 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
@@ -10360,7 +11049,7 @@ static struct hda_verb alc268_base_init_verbs[] = {
10360 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 11049 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10361 11050
10362 /* Unmute Selector 23h,24h and set the default input to mic-in */ 11051 /* Unmute Selector 23h,24h and set the default input to mic-in */
10363 11052
10364 {0x23, AC_VERB_SET_CONNECT_SEL, 0x00}, 11053 {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10365 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 11054 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10366 {0x24, AC_VERB_SET_CONNECT_SEL, 0x00}, 11055 {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -10559,7 +11248,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10559 11248
10560 nid = cfg->line_out_pins[0]; 11249 nid = cfg->line_out_pins[0];
10561 if (nid) 11250 if (nid)
10562 alc268_new_analog_output(spec, nid, "Front", 0); 11251 alc268_new_analog_output(spec, nid, "Front", 0);
10563 11252
10564 nid = cfg->speaker_pins[0]; 11253 nid = cfg->speaker_pins[0];
10565 if (nid == 0x1d) { 11254 if (nid == 0x1d) {
@@ -10581,7 +11270,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10581 if (err < 0) 11270 if (err < 0)
10582 return err; 11271 return err;
10583 } 11272 }
10584 return 0; 11273 return 0;
10585} 11274}
10586 11275
10587/* create playback/capture controls for input pins */ 11276/* create playback/capture controls for input pins */
@@ -10602,7 +11291,7 @@ static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10602 case 0x1a: 11291 case 0x1a:
10603 idx1 = 2; /* Line In */ 11292 idx1 = 2; /* Line In */
10604 break; 11293 break;
10605 case 0x1c: 11294 case 0x1c:
10606 idx1 = 3; /* CD */ 11295 idx1 = 3; /* CD */
10607 break; 11296 break;
10608 case 0x12: 11297 case 0x12:
@@ -10614,7 +11303,7 @@ static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10614 } 11303 }
10615 imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; 11304 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10616 imux->items[imux->num_items].index = idx1; 11305 imux->items[imux->num_items].index = idx1;
10617 imux->num_items++; 11306 imux->num_items++;
10618 } 11307 }
10619 return 0; 11308 return 0;
10620} 11309}
@@ -10644,11 +11333,11 @@ static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10644 } 11333 }
10645 11334
10646 dac_vol1 = dac_vol2 = 0xb000 | 0x40; /* set max volume */ 11335 dac_vol1 = dac_vol2 = 0xb000 | 0x40; /* set max volume */
10647 if (line_nid == 0x14) 11336 if (line_nid == 0x14)
10648 dac_vol2 = AMP_OUT_ZERO; 11337 dac_vol2 = AMP_OUT_ZERO;
10649 else if (line_nid == 0x15) 11338 else if (line_nid == 0x15)
10650 dac_vol1 = AMP_OUT_ZERO; 11339 dac_vol1 = AMP_OUT_ZERO;
10651 if (hp_nid == 0x14) 11340 if (hp_nid == 0x14)
10652 dac_vol2 = AMP_OUT_ZERO; 11341 dac_vol2 = AMP_OUT_ZERO;
10653 else if (hp_nid == 0x15) 11342 else if (hp_nid == 0x15)
10654 dac_vol1 = AMP_OUT_ZERO; 11343 dac_vol1 = AMP_OUT_ZERO;
@@ -10739,6 +11428,7 @@ static const char *alc268_models[ALC268_MODEL_LAST] = {
10739 [ALC268_3ST] = "3stack", 11428 [ALC268_3ST] = "3stack",
10740 [ALC268_TOSHIBA] = "toshiba", 11429 [ALC268_TOSHIBA] = "toshiba",
10741 [ALC268_ACER] = "acer", 11430 [ALC268_ACER] = "acer",
11431 [ALC268_ACER_ASPIRE_ONE] = "acer-aspire",
10742 [ALC268_DELL] = "dell", 11432 [ALC268_DELL] = "dell",
10743 [ALC268_ZEPTO] = "zepto", 11433 [ALC268_ZEPTO] = "zepto",
10744#ifdef CONFIG_SND_DEBUG 11434#ifdef CONFIG_SND_DEBUG
@@ -10753,11 +11443,14 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
10753 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER), 11443 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10754 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER), 11444 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10755 SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER), 11445 SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11446 SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11447 ALC268_ACER_ASPIRE_ONE),
10756 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL), 11448 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10757 SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA), 11449 SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10758 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST), 11450 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10759 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA), 11451 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10760 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA), 11452 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11453 SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
10761 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA), 11454 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
10762 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 11455 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10763 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1), 11456 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
@@ -10830,6 +11523,23 @@ static struct alc_config_preset alc268_presets[] = {
10830 .unsol_event = alc268_acer_unsol_event, 11523 .unsol_event = alc268_acer_unsol_event,
10831 .init_hook = alc268_acer_init_hook, 11524 .init_hook = alc268_acer_init_hook,
10832 }, 11525 },
11526 [ALC268_ACER_ASPIRE_ONE] = {
11527 .mixers = { alc268_acer_aspire_one_mixer,
11528 alc268_capture_alt_mixer },
11529 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11530 alc268_acer_aspire_one_verbs },
11531 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11532 .dac_nids = alc268_dac_nids,
11533 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11534 .adc_nids = alc268_adc_nids_alt,
11535 .capsrc_nids = alc268_capsrc_nids,
11536 .hp_nid = 0x03,
11537 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11538 .channel_mode = alc268_modes,
11539 .input_mux = &alc268_acer_lc_capture_source,
11540 .unsol_event = alc268_acer_lc_unsol_event,
11541 .init_hook = alc268_acer_lc_init_hook,
11542 },
10833 [ALC268_DELL] = { 11543 [ALC268_DELL] = {
10834 .mixers = { alc268_dell_mixer, alc268_beep_mixer }, 11544 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10835 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 11545 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
@@ -10974,7 +11684,7 @@ static int patch_alc268(struct hda_codec *codec)
10974 codec->patch_ops = alc_patch_ops; 11684 codec->patch_ops = alc_patch_ops;
10975 if (board_config == ALC268_AUTO) 11685 if (board_config == ALC268_AUTO)
10976 spec->init_hook = alc268_auto_init; 11686 spec->init_hook = alc268_auto_init;
10977 11687
10978 return 0; 11688 return 0;
10979} 11689}
10980 11690
@@ -10990,6 +11700,14 @@ static hda_nid_t alc269_adc_nids[1] = {
10990 0x08, 11700 0x08,
10991}; 11701};
10992 11702
11703static hda_nid_t alc269_capsrc_nids[1] = {
11704 0x23,
11705};
11706
11707/* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11708 * not a mux!
11709 */
11710
10993static struct hda_input_mux alc269_eeepc_dmic_capture_source = { 11711static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
10994 .num_items = 2, 11712 .num_items = 2,
10995 .items = { 11713 .items = {
@@ -11016,6 +11734,8 @@ static struct snd_kcontrol_new alc269_base_mixer[] = {
11016 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 11734 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11017 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 11735 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11018 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 11736 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11737 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11738 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11019 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11739 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11020 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 11740 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11021 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 11741 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
@@ -11025,6 +11745,28 @@ static struct snd_kcontrol_new alc269_base_mixer[] = {
11025 { } /* end */ 11745 { } /* end */
11026}; 11746};
11027 11747
11748static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11749 /* output mixer control */
11750 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11751 {
11752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11753 .name = "Master Playback Switch",
11754 .info = snd_hda_mixer_amp_switch_info,
11755 .get = snd_hda_mixer_amp_switch_get,
11756 .put = alc268_acer_master_sw_put,
11757 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11758 },
11759 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11760 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11761 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11762 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11763 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11764 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11765 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11766 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11767 { }
11768};
11769
11028/* bind volumes of both NID 0x0c and 0x0d */ 11770/* bind volumes of both NID 0x0c and 0x0d */
11029static struct hda_bind_ctls alc269_epc_bind_vol = { 11771static struct hda_bind_ctls alc269_epc_bind_vol = {
11030 .ops = &snd_hda_bind_vol, 11772 .ops = &snd_hda_bind_vol,
@@ -11068,75 +11810,72 @@ static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11068 { } /* end */ 11810 { } /* end */
11069}; 11811};
11070 11812
11071/* 11813/* beep control */
11072 * generic initialization of ADC, input mixers and output mixers 11814static struct snd_kcontrol_new alc269_beep_mixer[] = {
11073 */ 11815 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11074static struct hda_verb alc269_init_verbs[] = { 11816 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11075 /* 11817 { } /* end */
11076 * Unmute ADC0 and set the default input to mic-in 11818};
11077 */
11078 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11079 11819
11080 /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the 11820static struct hda_verb alc269_quanta_fl1_verbs[] = {
11081 * analog-loopback mixer widget 11821 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11082 * Note: PASD motherboards uses the Line In 2 as the input for 11822 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11083 * front panel mic (mic 2) 11823 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11084 */ 11824 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11085 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */ 11825 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11086 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 11826 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11087 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 11827 { }
11088 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 11828};
11089 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11090 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11091 11829
11092 /* 11830/* toggle speaker-output according to the hp-jack state */
11093 * Set up output mixers (0x0c - 0x0e) 11831static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11094 */ 11832{
11095 /* set vol=0 to output mixers */ 11833 unsigned int present;
11096 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 11834 unsigned char bits;
11097 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11098 11835
11099 /* set up input amps for analog loopback */ 11836 present = snd_hda_codec_read(codec, 0x15, 0,
11100 /* Amp Indices: DAC = 0, mixer = 1 */ 11837 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11101 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11838 bits = present ? AMP_IN_MUTE(0) : 0;
11102 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 11839 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11103 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11840 AMP_IN_MUTE(0), bits);
11104 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 11841 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11105 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11842 AMP_IN_MUTE(0), bits);
11106 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11107 11843
11108 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 11844 snd_hda_codec_write(codec, 0x20, 0,
11109 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 11845 AC_VERB_SET_COEF_INDEX, 0x0c);
11110 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 11846 snd_hda_codec_write(codec, 0x20, 0,
11111 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 11847 AC_VERB_SET_PROC_COEF, 0x680);
11112 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11113 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11114 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11115 11848
11116 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 11849 snd_hda_codec_write(codec, 0x20, 0,
11117 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 11850 AC_VERB_SET_COEF_INDEX, 0x0c);
11118 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11851 snd_hda_codec_write(codec, 0x20, 0,
11119 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11852 AC_VERB_SET_PROC_COEF, 0x480);
11120 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11853}
11121 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11122 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11123 11854
11124 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, 11855static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11125 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 11856{
11857 unsigned int present;
11126 11858
11127 /* FIXME: use matrix-type input source selection */ 11859 present = snd_hda_codec_read(codec, 0x18, 0,
11128 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */ 11860 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11129 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */ 11861 snd_hda_codec_write(codec, 0x23, 0,
11130 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11862 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11131 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 11863}
11132 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11133 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11134 11864
11135 /* set EAPD */ 11865static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11136 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, 11866 unsigned int res)
11137 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, 11867{
11138 { } 11868 if ((res >> 26) == ALC880_HP_EVENT)
11139}; 11869 alc269_quanta_fl1_speaker_automute(codec);
11870 if ((res >> 26) == ALC880_MIC_EVENT)
11871 alc269_quanta_fl1_mic_automute(codec);
11872}
11873
11874static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
11875{
11876 alc269_quanta_fl1_speaker_automute(codec);
11877 alc269_quanta_fl1_mic_automute(codec);
11878}
11140 11879
11141static struct hda_verb alc269_eeepc_dmic_init_verbs[] = { 11880static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11142 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 11881 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -11163,42 +11902,42 @@ static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11163static void alc269_speaker_automute(struct hda_codec *codec) 11902static void alc269_speaker_automute(struct hda_codec *codec)
11164{ 11903{
11165 unsigned int present; 11904 unsigned int present;
11166 unsigned int bits; 11905 unsigned char bits;
11167 11906
11168 present = snd_hda_codec_read(codec, 0x15, 0, 11907 present = snd_hda_codec_read(codec, 0x15, 0,
11169 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 11908 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11170 bits = present ? AMP_IN_MUTE(0) : 0; 11909 bits = present ? AMP_IN_MUTE(0) : 0;
11171 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 11910 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11172 AMP_IN_MUTE(0), bits); 11911 AMP_IN_MUTE(0), bits);
11173 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 11912 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11174 AMP_IN_MUTE(0), bits); 11913 AMP_IN_MUTE(0), bits);
11175} 11914}
11176 11915
11177static void alc269_eeepc_dmic_automute(struct hda_codec *codec) 11916static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11178{ 11917{
11179 unsigned int present; 11918 unsigned int present;
11180 11919
11181 present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0) 11920 present = snd_hda_codec_read(codec, 0x18, 0,
11182 & AC_PINSENSE_PRESENCE; 11921 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11183 snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL, 11922 snd_hda_codec_write(codec, 0x23, 0,
11184 present ? 0 : 5); 11923 AC_VERB_SET_CONNECT_SEL, (present ? 0 : 5));
11185} 11924}
11186 11925
11187static void alc269_eeepc_amic_automute(struct hda_codec *codec) 11926static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11188{ 11927{
11189 unsigned int present; 11928 unsigned int present;
11190 11929
11191 present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0) 11930 present = snd_hda_codec_read(codec, 0x18, 0,
11192 & AC_PINSENSE_PRESENCE; 11931 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11193 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE, 11932 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11194 present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0)); 11933 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
11195 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE, 11934 snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11196 present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1)); 11935 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
11197} 11936}
11198 11937
11199/* unsolicited event for HP jack sensing */ 11938/* unsolicited event for HP jack sensing */
11200static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec, 11939static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11201 unsigned int res) 11940 unsigned int res)
11202{ 11941{
11203 if ((res >> 26) == ALC880_HP_EVENT) 11942 if ((res >> 26) == ALC880_HP_EVENT)
11204 alc269_speaker_automute(codec); 11943 alc269_speaker_automute(codec);
@@ -11215,7 +11954,7 @@ static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11215 11954
11216/* unsolicited event for HP jack sensing */ 11955/* unsolicited event for HP jack sensing */
11217static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec, 11956static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11218 unsigned int res) 11957 unsigned int res)
11219{ 11958{
11220 if ((res >> 26) == ALC880_HP_EVENT) 11959 if ((res >> 26) == ALC880_HP_EVENT)
11221 alc269_speaker_automute(codec); 11960 alc269_speaker_automute(codec);
@@ -11230,6 +11969,76 @@ static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11230 alc269_eeepc_amic_automute(codec); 11969 alc269_eeepc_amic_automute(codec);
11231} 11970}
11232 11971
11972/*
11973 * generic initialization of ADC, input mixers and output mixers
11974 */
11975static struct hda_verb alc269_init_verbs[] = {
11976 /*
11977 * Unmute ADC0 and set the default input to mic-in
11978 */
11979 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11980
11981 /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11982 * analog-loopback mixer widget
11983 * Note: PASD motherboards uses the Line In 2 as the input for
11984 * front panel mic (mic 2)
11985 */
11986 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11987 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11988 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11989 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11990 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11991 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11992
11993 /*
11994 * Set up output mixers (0x0c - 0x0e)
11995 */
11996 /* set vol=0 to output mixers */
11997 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11998 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11999
12000 /* set up input amps for analog loopback */
12001 /* Amp Indices: DAC = 0, mixer = 1 */
12002 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12003 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12004 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12005 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12006 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12007 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12008
12009 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12010 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12011 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12012 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12013 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12014 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12015 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12016
12017 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12018 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12019 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12020 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12021 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12022 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12023 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12024
12025 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12026 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12027
12028 /* FIXME: use matrix-type input source selection */
12029 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12030 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12031 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12032 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12033 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12034 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12035
12036 /* set EAPD */
12037 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12038 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12039 { }
12040};
12041
11233/* add playback controls from the parsed DAC table */ 12042/* add playback controls from the parsed DAC table */
11234static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec, 12043static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11235 const struct auto_pin_cfg *cfg) 12044 const struct auto_pin_cfg *cfg)
@@ -11330,7 +12139,7 @@ static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11330static int alc269_parse_auto_config(struct hda_codec *codec) 12139static int alc269_parse_auto_config(struct hda_codec *codec)
11331{ 12140{
11332 struct alc_spec *spec = codec->spec; 12141 struct alc_spec *spec = codec->spec;
11333 int err; 12142 int i, err;
11334 static hda_nid_t alc269_ignore[] = { 0x1d, 0 }; 12143 static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
11335 12144
11336 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, 12145 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
@@ -11353,9 +12162,20 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
11353 if (spec->kctl_alloc) 12162 if (spec->kctl_alloc)
11354 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 12163 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11355 12164
12165 /* create a beep mixer control if the pin 0x1d isn't assigned */
12166 for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12167 if (spec->autocfg.input_pins[i] == 0x1d)
12168 break;
12169 if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12170 spec->mixers[spec->num_mixers++] = alc269_beep_mixer;
12171
11356 spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs; 12172 spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
11357 spec->num_mux_defs = 1; 12173 spec->num_mux_defs = 1;
11358 spec->input_mux = &spec->private_imux; 12174 spec->input_mux = &spec->private_imux;
12175 /* set default input source */
12176 snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12177 0, AC_VERB_SET_CONNECT_SEL,
12178 spec->input_mux->items[0].index);
11359 12179
11360 err = alc_auto_add_mic_boost(codec); 12180 err = alc_auto_add_mic_boost(codec);
11361 if (err < 0) 12181 if (err < 0)
@@ -11387,14 +12207,20 @@ static void alc269_auto_init(struct hda_codec *codec)
11387 * configuration and preset 12207 * configuration and preset
11388 */ 12208 */
11389static const char *alc269_models[ALC269_MODEL_LAST] = { 12209static const char *alc269_models[ALC269_MODEL_LAST] = {
11390 [ALC269_BASIC] = "basic", 12210 [ALC269_BASIC] = "basic",
12211 [ALC269_QUANTA_FL1] = "quanta",
12212 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703",
12213 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901"
11391}; 12214};
11392 12215
11393static struct snd_pci_quirk alc269_cfg_tbl[] = { 12216static struct snd_pci_quirk alc269_cfg_tbl[] = {
12217 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
11394 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", 12218 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
11395 ALC269_ASUS_EEEPC_P703), 12219 ALC269_ASUS_EEEPC_P703),
11396 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901", 12220 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
11397 ALC269_ASUS_EEEPC_P901), 12221 ALC269_ASUS_EEEPC_P901),
12222 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12223 ALC269_ASUS_EEEPC_P901),
11398 {} 12224 {}
11399}; 12225};
11400 12226
@@ -11409,6 +12235,18 @@ static struct alc_config_preset alc269_presets[] = {
11409 .channel_mode = alc269_modes, 12235 .channel_mode = alc269_modes,
11410 .input_mux = &alc269_capture_source, 12236 .input_mux = &alc269_capture_source,
11411 }, 12237 },
12238 [ALC269_QUANTA_FL1] = {
12239 .mixers = { alc269_quanta_fl1_mixer },
12240 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12241 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12242 .dac_nids = alc269_dac_nids,
12243 .hp_nid = 0x03,
12244 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12245 .channel_mode = alc269_modes,
12246 .input_mux = &alc269_capture_source,
12247 .unsol_event = alc269_quanta_fl1_unsol_event,
12248 .init_hook = alc269_quanta_fl1_init_hook,
12249 },
11412 [ALC269_ASUS_EEEPC_P703] = { 12250 [ALC269_ASUS_EEEPC_P703] = {
11413 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer }, 12251 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
11414 .init_verbs = { alc269_init_verbs, 12252 .init_verbs = { alc269_init_verbs,
@@ -11488,6 +12326,7 @@ static int patch_alc269(struct hda_codec *codec)
11488 12326
11489 spec->adc_nids = alc269_adc_nids; 12327 spec->adc_nids = alc269_adc_nids;
11490 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); 12328 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12329 spec->capsrc_nids = alc269_capsrc_nids;
11491 12330
11492 codec->patch_ops = alc_patch_ops; 12331 codec->patch_ops = alc_patch_ops;
11493 if (board_config == ALC269_AUTO) 12332 if (board_config == ALC269_AUTO)
@@ -11689,7 +12528,7 @@ static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11689 HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT), 12528 HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11690 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT), 12529 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11691 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT), 12530 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11692 12531
11693 /*Capture mixer control */ 12532 /*Capture mixer control */
11694 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 12533 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11695 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 12534 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
@@ -11832,20 +12671,20 @@ static struct hda_verb alc861_base_init_verbs[] = {
11832 /* route front mic to ADC1*/ 12671 /* route front mic to ADC1*/
11833 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 12672 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11834 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12673 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11835 12674
11836 /* Unmute DAC0~3 & spdif out*/ 12675 /* Unmute DAC0~3 & spdif out*/
11837 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12676 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11838 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12677 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11839 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12678 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11840 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12679 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11841 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12680 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11842 12681
11843 /* Unmute Mixer 14 (mic) 1c (Line in)*/ 12682 /* Unmute Mixer 14 (mic) 1c (Line in)*/
11844 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12683 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11845 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12684 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11846 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12685 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11847 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12686 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11848 12687
11849 /* Unmute Stereo Mixer 15 */ 12688 /* Unmute Stereo Mixer 15 */
11850 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12689 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12690 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -11901,13 +12740,13 @@ static struct hda_verb alc861_threestack_init_verbs[] = {
11901 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12740 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11902 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12741 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11903 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12742 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11904 12743
11905 /* Unmute Mixer 14 (mic) 1c (Line in)*/ 12744 /* Unmute Mixer 14 (mic) 1c (Line in)*/
11906 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12745 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11907 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12746 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11908 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12747 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11909 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12748 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11910 12749
11911 /* Unmute Stereo Mixer 15 */ 12750 /* Unmute Stereo Mixer 15 */
11912 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12751 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11913 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12752 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -11963,13 +12802,13 @@ static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11963 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12802 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11964 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12803 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11965 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12804 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11966 12805
11967 /* Unmute Mixer 14 (mic) 1c (Line in)*/ 12806 /* Unmute Mixer 14 (mic) 1c (Line in)*/
11968 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12807 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11969 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12808 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11970 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12809 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11971 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12810 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11972 12811
11973 /* Unmute Stereo Mixer 15 */ 12812 /* Unmute Stereo Mixer 15 */
11974 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11975 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12814 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -12034,7 +12873,7 @@ static struct hda_verb alc861_asus_init_verbs[] = {
12034 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12873 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12035 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12874 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12036 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12875 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12037 12876
12038 /* Unmute Stereo Mixer 15 */ 12877 /* Unmute Stereo Mixer 15 */
12039 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12878 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12040 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12879 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -12071,20 +12910,20 @@ static struct hda_verb alc861_auto_init_verbs[] = {
12071 */ 12910 */
12072 /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */ 12911 /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12073 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12912 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12074 12913
12075 /* Unmute DAC0~3 & spdif out*/ 12914 /* Unmute DAC0~3 & spdif out*/
12076 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12915 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12077 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12916 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12078 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12917 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12079 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12918 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12080 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 12919 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12081 12920
12082 /* Unmute Mixer 14 (mic) 1c (Line in)*/ 12921 /* Unmute Mixer 14 (mic) 1c (Line in)*/
12083 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12922 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12084 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12923 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12085 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12924 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12086 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12925 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12087 12926
12088 /* Unmute Stereo Mixer 15 */ 12927 /* Unmute Stereo Mixer 15 */
12089 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 12928 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12090 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 12929 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -12659,7 +13498,7 @@ static int patch_alc861(struct hda_codec *codec)
12659 if (!spec->loopback.amplist) 13498 if (!spec->loopback.amplist)
12660 spec->loopback.amplist = alc861_loopbacks; 13499 spec->loopback.amplist = alc861_loopbacks;
12661#endif 13500#endif
12662 13501
12663 return 0; 13502 return 0;
12664} 13503}
12665 13504
@@ -12913,7 +13752,7 @@ static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12913 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 13752 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12914 HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 13753 HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12915 HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 13754 HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12916 13755
12917 { } /* end */ 13756 { } /* end */
12918}; 13757};
12919 13758
@@ -13058,7 +13897,7 @@ static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13058 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 13897 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13059 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, 13898 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13060 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 13899 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13061 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 13900 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13062 {} 13901 {}
13063}; 13902};
13064 13903
@@ -13120,7 +13959,7 @@ static struct hda_verb alc861vd_dallas_verbs[] = {
13120 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 13959 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13121 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 13960 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13122 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 13961 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13123 13962
13124 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 13963 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13125 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 13964 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13126 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 13965 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
@@ -13145,7 +13984,7 @@ static struct hda_verb alc861vd_dallas_verbs[] = {
13145 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 13984 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13146 13985
13147 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 13986 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13148 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00}, 13987 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13149 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 13988 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13150 13989
13151 { } /* end */ 13990 { } /* end */
@@ -13304,7 +14143,7 @@ static struct alc_config_preset alc861vd_presets[] = {
13304 .input_mux = &alc861vd_hp_capture_source, 14143 .input_mux = &alc861vd_hp_capture_source,
13305 .unsol_event = alc861vd_dallas_unsol_event, 14144 .unsol_event = alc861vd_dallas_unsol_event,
13306 .init_hook = alc861vd_dallas_automute, 14145 .init_hook = alc861vd_dallas_automute,
13307 }, 14146 },
13308}; 14147};
13309 14148
13310/* 14149/*
@@ -13883,13 +14722,120 @@ static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13883 { } /* end */ 14722 { } /* end */
13884}; 14723};
13885 14724
14725static struct hda_bind_ctls alc663_asus_bind_master_vol = {
14726 .ops = &snd_hda_bind_vol,
14727 .values = {
14728 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14729 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
14730 0
14731 },
14732};
14733
14734static struct hda_bind_ctls alc663_asus_one_bind_switch = {
14735 .ops = &snd_hda_bind_sw,
14736 .values = {
14737 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14738 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14739 0
14740 },
14741};
14742
13886static struct snd_kcontrol_new alc663_m51va_mixer[] = { 14743static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14744 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14745 HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
14746 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14747 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14748 { } /* end */
14749};
14750
14751static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
14752 .ops = &snd_hda_bind_sw,
14753 .values = {
14754 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14755 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14756 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14757 0
14758 },
14759};
14760
14761static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
14762 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14763 HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
14764 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14765 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14766 HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14767 HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14768
14769 { } /* end */
14770};
14771
14772static struct hda_bind_ctls alc663_asus_four_bind_switch = {
14773 .ops = &snd_hda_bind_sw,
14774 .values = {
14775 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14776 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14777 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
14778 0
14779 },
14780};
14781
14782static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
14783 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14784 HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
14785 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14786 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14787 HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14788 HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14789 { } /* end */
14790};
14791
14792static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
13887 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT), 14793 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13888 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 14794 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14795 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14796 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14797 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14798 HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14799 HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14800 { } /* end */
14801};
14802
14803static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
14804 .ops = &snd_hda_bind_vol,
14805 .values = {
14806 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14807 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
14808 0
14809 },
14810};
14811
14812static struct hda_bind_ctls alc663_asus_two_bind_switch = {
14813 .ops = &snd_hda_bind_sw,
14814 .values = {
14815 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14816 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
14817 0
14818 },
14819};
14820
14821static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
14822 HDA_BIND_VOL("Master Playback Volume",
14823 &alc663_asus_two_bind_master_vol),
14824 HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14825 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13889 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT), 14826 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13890 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 14827 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13891 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 14828 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13892 HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT), 14829 { } /* end */
14830};
14831
14832static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
14833 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14834 HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14835 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14836 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14837 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14838 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13893 { } /* end */ 14839 { } /* end */
13894}; 14840};
13895 14841
@@ -14074,14 +15020,81 @@ static struct hda_verb alc663_auto_init_verbs[] = {
14074}; 15020};
14075 15021
14076static struct hda_verb alc663_m51va_init_verbs[] = { 15022static struct hda_verb alc663_m51va_init_verbs[] = {
15023 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15024 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14077 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 15025 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14078 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 15026 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14079 {0x21, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Headphone */ 15027 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15028 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15029 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15030 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15031 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15032 {}
15033};
14080 15034
14081 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)}, 15035static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15036 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15037 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15038 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15039 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15040 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15041 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15042 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15043 {}
15044};
14082 15045
15046static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15047 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15048 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15049 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15050 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Headphone */
15051 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15052 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15053 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15054 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15055 {}
15056};
15057
15058static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15059 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15060 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15061 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15062 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15063 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15064 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15065 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15066 {}
15067};
15068
15069static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15070 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15071 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15072 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15073 {0x21, AC_VERB_SET_CONNECT_SEL, 0x0}, /* Headphone */
15074 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15075 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15076 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0}, /* Headphone */
15077 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15078 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14083 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 15079 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14084 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 15080 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15081 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15082 {}
15083};
15084
15085static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15086 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15087 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15088 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15089 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15090 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15091 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15092 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15093 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15094 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15095 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15096 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15097 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14085 {} 15098 {}
14086}; 15099};
14087 15100
@@ -14110,6 +15123,14 @@ static struct hda_verb alc663_g50v_init_verbs[] = {
14110 {} 15123 {}
14111}; 15124};
14112 15125
15126static struct hda_verb alc662_ecs_init_verbs[] = {
15127 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15128 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15129 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15130 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15131 {}
15132};
15133
14113/* capture mixer elements */ 15134/* capture mixer elements */
14114static struct snd_kcontrol_new alc662_capture_mixer[] = { 15135static struct snd_kcontrol_new alc662_capture_mixer[] = {
14115 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 15136 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
@@ -14129,6 +15150,12 @@ static struct snd_kcontrol_new alc662_capture_mixer[] = {
14129 { } /* end */ 15150 { } /* end */
14130}; 15151};
14131 15152
15153static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15154 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15155 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15156 { } /* end */
15157};
15158
14132static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 15159static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14133{ 15160{
14134 unsigned int present; 15161 unsigned int present;
@@ -14209,12 +15236,12 @@ static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14209 if (present) { 15236 if (present) {
14210 /* mute internal speaker */ 15237 /* mute internal speaker */
14211 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0, 15238 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14212 HDA_AMP_MUTE, HDA_AMP_MUTE); 15239 HDA_AMP_MUTE, HDA_AMP_MUTE);
14213 } else { 15240 } else {
14214 /* unmute internal speaker if necessary */ 15241 /* unmute internal speaker if necessary */
14215 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0); 15242 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14216 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0, 15243 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14217 HDA_AMP_MUTE, mute); 15244 HDA_AMP_MUTE, mute);
14218 } 15245 }
14219} 15246}
14220 15247
@@ -14237,11 +15264,108 @@ static void alc663_m51va_speaker_automute(struct hda_codec *codec)
14237 unsigned char bits; 15264 unsigned char bits;
14238 15265
14239 present = snd_hda_codec_read(codec, 0x21, 0, 15266 present = snd_hda_codec_read(codec, 0x21, 0,
14240 AC_VERB_GET_PIN_SENSE, 0) 15267 AC_VERB_GET_PIN_SENSE, 0)
14241 & AC_PINSENSE_PRESENCE; 15268 & AC_PINSENSE_PRESENCE;
14242 bits = present ? HDA_AMP_MUTE : 0; 15269 bits = present ? HDA_AMP_MUTE : 0;
14243 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 15270 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
14244 HDA_AMP_MUTE, bits); 15271 AMP_IN_MUTE(0), bits);
15272 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15273 AMP_IN_MUTE(0), bits);
15274}
15275
15276static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15277{
15278 unsigned int present;
15279 unsigned char bits;
15280
15281 present = snd_hda_codec_read(codec, 0x21, 0,
15282 AC_VERB_GET_PIN_SENSE, 0)
15283 & AC_PINSENSE_PRESENCE;
15284 bits = present ? HDA_AMP_MUTE : 0;
15285 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15286 AMP_IN_MUTE(0), bits);
15287 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15288 AMP_IN_MUTE(0), bits);
15289 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15290 AMP_IN_MUTE(0), bits);
15291 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15292 AMP_IN_MUTE(0), bits);
15293}
15294
15295static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15296{
15297 unsigned int present;
15298 unsigned char bits;
15299
15300 present = snd_hda_codec_read(codec, 0x15, 0,
15301 AC_VERB_GET_PIN_SENSE, 0)
15302 & AC_PINSENSE_PRESENCE;
15303 bits = present ? HDA_AMP_MUTE : 0;
15304 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15305 AMP_IN_MUTE(0), bits);
15306 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15307 AMP_IN_MUTE(0), bits);
15308 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15309 AMP_IN_MUTE(0), bits);
15310 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15311 AMP_IN_MUTE(0), bits);
15312}
15313
15314static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15315{
15316 unsigned int present;
15317 unsigned char bits;
15318
15319 present = snd_hda_codec_read(codec, 0x1b, 0,
15320 AC_VERB_GET_PIN_SENSE, 0)
15321 & AC_PINSENSE_PRESENCE;
15322 bits = present ? 0 : PIN_OUT;
15323 snd_hda_codec_write(codec, 0x14, 0,
15324 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15325}
15326
15327static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15328{
15329 unsigned int present1, present2;
15330
15331 present1 = snd_hda_codec_read(codec, 0x21, 0,
15332 AC_VERB_GET_PIN_SENSE, 0)
15333 & AC_PINSENSE_PRESENCE;
15334 present2 = snd_hda_codec_read(codec, 0x15, 0,
15335 AC_VERB_GET_PIN_SENSE, 0)
15336 & AC_PINSENSE_PRESENCE;
15337
15338 if (present1 || present2) {
15339 snd_hda_codec_write_cache(codec, 0x14, 0,
15340 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15341 } else {
15342 snd_hda_codec_write_cache(codec, 0x14, 0,
15343 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15344 }
15345}
15346
15347static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15348{
15349 unsigned int present1, present2;
15350
15351 present1 = snd_hda_codec_read(codec, 0x1b, 0,
15352 AC_VERB_GET_PIN_SENSE, 0)
15353 & AC_PINSENSE_PRESENCE;
15354 present2 = snd_hda_codec_read(codec, 0x15, 0,
15355 AC_VERB_GET_PIN_SENSE, 0)
15356 & AC_PINSENSE_PRESENCE;
15357
15358 if (present1 || present2) {
15359 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15360 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15361 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15362 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15363 } else {
15364 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15365 AMP_IN_MUTE(0), 0);
15366 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15367 AMP_IN_MUTE(0), 0);
15368 }
14245} 15369}
14246 15370
14247static void alc663_m51va_mic_automute(struct hda_codec *codec) 15371static void alc663_m51va_mic_automute(struct hda_codec *codec)
@@ -14249,16 +15373,16 @@ static void alc663_m51va_mic_automute(struct hda_codec *codec)
14249 unsigned int present; 15373 unsigned int present;
14250 15374
14251 present = snd_hda_codec_read(codec, 0x18, 0, 15375 present = snd_hda_codec_read(codec, 0x18, 0,
14252 AC_VERB_GET_PIN_SENSE, 0) 15376 AC_VERB_GET_PIN_SENSE, 0)
14253 & AC_PINSENSE_PRESENCE; 15377 & AC_PINSENSE_PRESENCE;
14254 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE, 15378 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14255 0x7000 | (0x00 << 8) | (present ? 0 : 0x80)); 15379 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14256 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE, 15380 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14257 0x7000 | (0x00 << 8) | (present ? 0 : 0x80)); 15381 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14258 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE, 15382 snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14259 0x7000 | (0x09 << 8) | (present ? 0x80 : 0)); 15383 0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14260 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE, 15384 snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14261 0x7000 | (0x09 << 8) | (present ? 0x80 : 0)); 15385 0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14262} 15386}
14263 15387
14264static void alc663_m51va_unsol_event(struct hda_codec *codec, 15388static void alc663_m51va_unsol_event(struct hda_codec *codec,
@@ -14280,6 +15404,121 @@ static void alc663_m51va_inithook(struct hda_codec *codec)
14280 alc663_m51va_mic_automute(codec); 15404 alc663_m51va_mic_automute(codec);
14281} 15405}
14282 15406
15407/* ***************** Mode1 ******************************/
15408static void alc663_mode1_unsol_event(struct hda_codec *codec,
15409 unsigned int res)
15410{
15411 switch (res >> 26) {
15412 case ALC880_HP_EVENT:
15413 alc663_m51va_speaker_automute(codec);
15414 break;
15415 case ALC880_MIC_EVENT:
15416 alc662_eeepc_mic_automute(codec);
15417 break;
15418 }
15419}
15420
15421static void alc663_mode1_inithook(struct hda_codec *codec)
15422{
15423 alc663_m51va_speaker_automute(codec);
15424 alc662_eeepc_mic_automute(codec);
15425}
15426/* ***************** Mode2 ******************************/
15427static void alc662_mode2_unsol_event(struct hda_codec *codec,
15428 unsigned int res)
15429{
15430 switch (res >> 26) {
15431 case ALC880_HP_EVENT:
15432 alc662_f5z_speaker_automute(codec);
15433 break;
15434 case ALC880_MIC_EVENT:
15435 alc662_eeepc_mic_automute(codec);
15436 break;
15437 }
15438}
15439
15440static void alc662_mode2_inithook(struct hda_codec *codec)
15441{
15442 alc662_f5z_speaker_automute(codec);
15443 alc662_eeepc_mic_automute(codec);
15444}
15445/* ***************** Mode3 ******************************/
15446static void alc663_mode3_unsol_event(struct hda_codec *codec,
15447 unsigned int res)
15448{
15449 switch (res >> 26) {
15450 case ALC880_HP_EVENT:
15451 alc663_two_hp_m1_speaker_automute(codec);
15452 break;
15453 case ALC880_MIC_EVENT:
15454 alc662_eeepc_mic_automute(codec);
15455 break;
15456 }
15457}
15458
15459static void alc663_mode3_inithook(struct hda_codec *codec)
15460{
15461 alc663_two_hp_m1_speaker_automute(codec);
15462 alc662_eeepc_mic_automute(codec);
15463}
15464/* ***************** Mode4 ******************************/
15465static void alc663_mode4_unsol_event(struct hda_codec *codec,
15466 unsigned int res)
15467{
15468 switch (res >> 26) {
15469 case ALC880_HP_EVENT:
15470 alc663_21jd_two_speaker_automute(codec);
15471 break;
15472 case ALC880_MIC_EVENT:
15473 alc662_eeepc_mic_automute(codec);
15474 break;
15475 }
15476}
15477
15478static void alc663_mode4_inithook(struct hda_codec *codec)
15479{
15480 alc663_21jd_two_speaker_automute(codec);
15481 alc662_eeepc_mic_automute(codec);
15482}
15483/* ***************** Mode5 ******************************/
15484static void alc663_mode5_unsol_event(struct hda_codec *codec,
15485 unsigned int res)
15486{
15487 switch (res >> 26) {
15488 case ALC880_HP_EVENT:
15489 alc663_15jd_two_speaker_automute(codec);
15490 break;
15491 case ALC880_MIC_EVENT:
15492 alc662_eeepc_mic_automute(codec);
15493 break;
15494 }
15495}
15496
15497static void alc663_mode5_inithook(struct hda_codec *codec)
15498{
15499 alc663_15jd_two_speaker_automute(codec);
15500 alc662_eeepc_mic_automute(codec);
15501}
15502/* ***************** Mode6 ******************************/
15503static void alc663_mode6_unsol_event(struct hda_codec *codec,
15504 unsigned int res)
15505{
15506 switch (res >> 26) {
15507 case ALC880_HP_EVENT:
15508 alc663_two_hp_m2_speaker_automute(codec);
15509 break;
15510 case ALC880_MIC_EVENT:
15511 alc662_eeepc_mic_automute(codec);
15512 break;
15513 }
15514}
15515
15516static void alc663_mode6_inithook(struct hda_codec *codec)
15517{
15518 alc663_two_hp_m2_speaker_automute(codec);
15519 alc662_eeepc_mic_automute(codec);
15520}
15521
14283static void alc663_g71v_hp_automute(struct hda_codec *codec) 15522static void alc663_g71v_hp_automute(struct hda_codec *codec)
14284{ 15523{
14285 unsigned int present; 15524 unsigned int present;
@@ -14350,6 +15589,46 @@ static void alc663_g50v_inithook(struct hda_codec *codec)
14350 alc662_eeepc_mic_automute(codec); 15589 alc662_eeepc_mic_automute(codec);
14351} 15590}
14352 15591
15592/* bind hp and internal speaker mute (with plug check) */
15593static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15594 struct snd_ctl_elem_value *ucontrol)
15595{
15596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15597 long *valp = ucontrol->value.integer.value;
15598 int change;
15599
15600 change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15601 HDA_AMP_MUTE,
15602 valp[0] ? 0 : HDA_AMP_MUTE);
15603 change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15604 HDA_AMP_MUTE,
15605 valp[1] ? 0 : HDA_AMP_MUTE);
15606 if (change)
15607 alc262_hippo1_automute(codec);
15608 return change;
15609}
15610
15611static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15612 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15613 {
15614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15615 .name = "Master Playback Switch",
15616 .info = snd_hda_mixer_amp_switch_info,
15617 .get = snd_hda_mixer_amp_switch_get,
15618 .put = alc662_ecs_master_sw_put,
15619 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15620 },
15621
15622 HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15623 HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15624 HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15625
15626 HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15627 HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15628 HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15629 { } /* end */
15630};
15631
14353#ifdef CONFIG_SND_HDA_POWER_SAVE 15632#ifdef CONFIG_SND_HDA_POWER_SAVE
14354#define alc662_loopbacks alc880_loopbacks 15633#define alc662_loopbacks alc880_loopbacks
14355#endif 15634#endif
@@ -14372,21 +15651,67 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
14372 [ALC662_LENOVO_101E] = "lenovo-101e", 15651 [ALC662_LENOVO_101E] = "lenovo-101e",
14373 [ALC662_ASUS_EEEPC_P701] = "eeepc-p701", 15652 [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
14374 [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20", 15653 [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15654 [ALC662_ECS] = "ecs",
14375 [ALC663_ASUS_M51VA] = "m51va", 15655 [ALC663_ASUS_M51VA] = "m51va",
14376 [ALC663_ASUS_G71V] = "g71v", 15656 [ALC663_ASUS_G71V] = "g71v",
14377 [ALC663_ASUS_H13] = "h13", 15657 [ALC663_ASUS_H13] = "h13",
14378 [ALC663_ASUS_G50V] = "g50v", 15658 [ALC663_ASUS_G50V] = "g50v",
15659 [ALC663_ASUS_MODE1] = "asus-mode1",
15660 [ALC662_ASUS_MODE2] = "asus-mode2",
15661 [ALC663_ASUS_MODE3] = "asus-mode3",
15662 [ALC663_ASUS_MODE4] = "asus-mode4",
15663 [ALC663_ASUS_MODE5] = "asus-mode5",
15664 [ALC663_ASUS_MODE6] = "asus-mode6",
14379 [ALC662_AUTO] = "auto", 15665 [ALC662_AUTO] = "auto",
14380}; 15666};
14381 15667
14382static struct snd_pci_quirk alc662_cfg_tbl[] = { 15668static struct snd_pci_quirk alc662_cfg_tbl[] = {
14383 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
14384 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA), 15669 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
14385 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V), 15670 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
14386 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG), 15671 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
14387 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701), 15672 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
14388 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20), 15673 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15674 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15675 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15676 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15677 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15678 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15679 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15680 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15681 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15682 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15683 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15684 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15685 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15686 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15687 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15688 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15689 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15690 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15691 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15692 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15693 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15694 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15695 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15696 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15697 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15698 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15699 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15700 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15701 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15702 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15703 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15704 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15705 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15706 ALC662_3ST_6ch_DIG),
14389 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E), 15707 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15708 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15709 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15710 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15711 ALC662_3ST_6ch_DIG),
15712 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15713 SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15714 ALC662_3ST_6ch_DIG),
14390 SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13), 15715 SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
14391 SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13), 15716 SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
14392 SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13), 15717 SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
@@ -14477,6 +15802,18 @@ static struct alc_config_preset alc662_presets[] = {
14477 .unsol_event = alc662_eeepc_ep20_unsol_event, 15802 .unsol_event = alc662_eeepc_ep20_unsol_event,
14478 .init_hook = alc662_eeepc_ep20_inithook, 15803 .init_hook = alc662_eeepc_ep20_inithook,
14479 }, 15804 },
15805 [ALC662_ECS] = {
15806 .mixers = { alc662_ecs_mixer, alc662_capture_mixer },
15807 .init_verbs = { alc662_init_verbs,
15808 alc662_ecs_init_verbs },
15809 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15810 .dac_nids = alc662_dac_nids,
15811 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15812 .channel_mode = alc662_3ST_2ch_modes,
15813 .input_mux = &alc662_eeepc_capture_source,
15814 .unsol_event = alc662_eeepc_unsol_event,
15815 .init_hook = alc662_eeepc_inithook,
15816 },
14480 [ALC663_ASUS_M51VA] = { 15817 [ALC663_ASUS_M51VA] = {
14481 .mixers = { alc663_m51va_mixer, alc662_capture_mixer}, 15818 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14482 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs }, 15819 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
@@ -14524,6 +15861,91 @@ static struct alc_config_preset alc662_presets[] = {
14524 .unsol_event = alc663_g50v_unsol_event, 15861 .unsol_event = alc663_g50v_unsol_event,
14525 .init_hook = alc663_g50v_inithook, 15862 .init_hook = alc663_g50v_inithook,
14526 }, 15863 },
15864 [ALC663_ASUS_MODE1] = {
15865 .mixers = { alc663_m51va_mixer, alc662_auto_capture_mixer },
15866 .init_verbs = { alc662_init_verbs,
15867 alc663_21jd_amic_init_verbs },
15868 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15869 .hp_nid = 0x03,
15870 .dac_nids = alc662_dac_nids,
15871 .dig_out_nid = ALC662_DIGOUT_NID,
15872 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15873 .channel_mode = alc662_3ST_2ch_modes,
15874 .input_mux = &alc662_eeepc_capture_source,
15875 .unsol_event = alc663_mode1_unsol_event,
15876 .init_hook = alc663_mode1_inithook,
15877 },
15878 [ALC662_ASUS_MODE2] = {
15879 .mixers = { alc662_1bjd_mixer, alc662_auto_capture_mixer },
15880 .init_verbs = { alc662_init_verbs,
15881 alc662_1bjd_amic_init_verbs },
15882 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15883 .dac_nids = alc662_dac_nids,
15884 .dig_out_nid = ALC662_DIGOUT_NID,
15885 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15886 .channel_mode = alc662_3ST_2ch_modes,
15887 .input_mux = &alc662_eeepc_capture_source,
15888 .unsol_event = alc662_mode2_unsol_event,
15889 .init_hook = alc662_mode2_inithook,
15890 },
15891 [ALC663_ASUS_MODE3] = {
15892 .mixers = { alc663_two_hp_m1_mixer, alc662_auto_capture_mixer },
15893 .init_verbs = { alc662_init_verbs,
15894 alc663_two_hp_amic_m1_init_verbs },
15895 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15896 .hp_nid = 0x03,
15897 .dac_nids = alc662_dac_nids,
15898 .dig_out_nid = ALC662_DIGOUT_NID,
15899 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15900 .channel_mode = alc662_3ST_2ch_modes,
15901 .input_mux = &alc662_eeepc_capture_source,
15902 .unsol_event = alc663_mode3_unsol_event,
15903 .init_hook = alc663_mode3_inithook,
15904 },
15905 [ALC663_ASUS_MODE4] = {
15906 .mixers = { alc663_asus_21jd_clfe_mixer,
15907 alc662_auto_capture_mixer},
15908 .init_verbs = { alc662_init_verbs,
15909 alc663_21jd_amic_init_verbs},
15910 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15911 .hp_nid = 0x03,
15912 .dac_nids = alc662_dac_nids,
15913 .dig_out_nid = ALC662_DIGOUT_NID,
15914 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15915 .channel_mode = alc662_3ST_2ch_modes,
15916 .input_mux = &alc662_eeepc_capture_source,
15917 .unsol_event = alc663_mode4_unsol_event,
15918 .init_hook = alc663_mode4_inithook,
15919 },
15920 [ALC663_ASUS_MODE5] = {
15921 .mixers = { alc663_asus_15jd_clfe_mixer,
15922 alc662_auto_capture_mixer },
15923 .init_verbs = { alc662_init_verbs,
15924 alc663_15jd_amic_init_verbs },
15925 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15926 .hp_nid = 0x03,
15927 .dac_nids = alc662_dac_nids,
15928 .dig_out_nid = ALC662_DIGOUT_NID,
15929 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15930 .channel_mode = alc662_3ST_2ch_modes,
15931 .input_mux = &alc662_eeepc_capture_source,
15932 .unsol_event = alc663_mode5_unsol_event,
15933 .init_hook = alc663_mode5_inithook,
15934 },
15935 [ALC663_ASUS_MODE6] = {
15936 .mixers = { alc663_two_hp_m2_mixer, alc662_auto_capture_mixer },
15937 .init_verbs = { alc662_init_verbs,
15938 alc663_two_hp_amic_m2_init_verbs },
15939 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15940 .hp_nid = 0x03,
15941 .dac_nids = alc662_dac_nids,
15942 .dig_out_nid = ALC662_DIGOUT_NID,
15943 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15944 .channel_mode = alc662_3ST_2ch_modes,
15945 .input_mux = &alc662_eeepc_capture_source,
15946 .unsol_event = alc663_mode6_unsol_event,
15947 .init_hook = alc663_mode6_inithook,
15948 },
14527}; 15949};
14528 15950
14529 15951
@@ -14560,15 +15982,15 @@ static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14560 HDA_OUTPUT)); 15982 HDA_OUTPUT));
14561 if (err < 0) 15983 if (err < 0)
14562 return err; 15984 return err;
14563 err = add_control(spec, ALC_CTL_BIND_MUTE, 15985 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
14564 "Center Playback Switch", 15986 "Center Playback Switch",
14565 HDA_COMPOSE_AMP_VAL(nid, 1, 2, 15987 HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
14566 HDA_INPUT)); 15988 HDA_INPUT));
14567 if (err < 0) 15989 if (err < 0)
14568 return err; 15990 return err;
14569 err = add_control(spec, ALC_CTL_BIND_MUTE, 15991 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
14570 "LFE Playback Switch", 15992 "LFE Playback Switch",
14571 HDA_COMPOSE_AMP_VAL(nid, 2, 2, 15993 HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
14572 HDA_INPUT)); 15994 HDA_INPUT));
14573 if (err < 0) 15995 if (err < 0)
14574 return err; 15996 return err;
@@ -14580,9 +16002,9 @@ static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14580 if (err < 0) 16002 if (err < 0)
14581 return err; 16003 return err;
14582 sprintf(name, "%s Playback Switch", chname[i]); 16004 sprintf(name, "%s Playback Switch", chname[i]);
14583 err = add_control(spec, ALC_CTL_BIND_MUTE, name, 16005 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14584 HDA_COMPOSE_AMP_VAL(nid, 3, 2, 16006 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
14585 HDA_INPUT)); 16007 3, 0, HDA_INPUT));
14586 if (err < 0) 16008 if (err < 0)
14587 return err; 16009 return err;
14588 } 16010 }
@@ -14777,7 +16199,7 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
14777 16199
14778 spec->num_mux_defs = 1; 16200 spec->num_mux_defs = 1;
14779 spec->input_mux = &spec->private_imux; 16201 spec->input_mux = &spec->private_imux;
14780 16202
14781 spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs; 16203 spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14782 if (codec->vendor_id == 0x10ec0663) 16204 if (codec->vendor_id == 0x10ec0663)
14783 spec->init_verbs[spec->num_init_verbs++] = 16205 spec->init_verbs[spec->num_init_verbs++] =
@@ -14896,6 +16318,8 @@ struct hda_codec_preset snd_hda_preset_realtek[] = {
14896 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 16318 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14897 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 16319 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14898 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 }, 16320 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16321 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16322 .patch = patch_alc882 }, /* should be patch_alc883() in future */
14899 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", 16323 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14900 .patch = patch_alc882 }, /* should be patch_alc883() in future */ 16324 .patch = patch_alc882 }, /* should be patch_alc883() in future */
14901 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 16325 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index ad994fcab725..c59065513118 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -33,10 +33,12 @@
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_patch.h" 35#include "hda_patch.h"
36#include "hda_beep.h"
36 37
37#define NUM_CONTROL_ALLOC 32 38#define NUM_CONTROL_ALLOC 32
38#define STAC_PWR_EVENT 0x20 39#define STAC_PWR_EVENT 0x20
39#define STAC_HP_EVENT 0x30 40#define STAC_HP_EVENT 0x30
41#define STAC_VREF_EVENT 0x40
40 42
41enum { 43enum {
42 STAC_REF, 44 STAC_REF,
@@ -71,9 +73,15 @@ enum {
71}; 73};
72 74
73enum { 75enum {
76 STAC_92HD83XXX_REF,
77 STAC_92HD83XXX_MODELS
78};
79
80enum {
74 STAC_92HD71BXX_REF, 81 STAC_92HD71BXX_REF,
75 STAC_DELL_M4_1, 82 STAC_DELL_M4_1,
76 STAC_DELL_M4_2, 83 STAC_DELL_M4_2,
84 STAC_HP_M4,
77 STAC_92HD71BXX_MODELS 85 STAC_92HD71BXX_MODELS
78}; 86};
79 87
@@ -104,6 +112,7 @@ enum {
104 STAC_MACBOOK_PRO_V2, 112 STAC_MACBOOK_PRO_V2,
105 STAC_IMAC_INTEL, 113 STAC_IMAC_INTEL,
106 STAC_IMAC_INTEL_20, 114 STAC_IMAC_INTEL_20,
115 STAC_ECS_202,
107 STAC_922X_DELL_D81, 116 STAC_922X_DELL_D81,
108 STAC_922X_DELL_D82, 117 STAC_922X_DELL_D82,
109 STAC_922X_DELL_M81, 118 STAC_922X_DELL_M81,
@@ -130,6 +139,7 @@ struct sigmatel_spec {
130 unsigned int mic_switch: 1; 139 unsigned int mic_switch: 1;
131 unsigned int alt_switch: 1; 140 unsigned int alt_switch: 1;
132 unsigned int hp_detect: 1; 141 unsigned int hp_detect: 1;
142 unsigned int spdif_mute: 1;
133 143
134 /* gpio lines */ 144 /* gpio lines */
135 unsigned int eapd_mask; 145 unsigned int eapd_mask;
@@ -138,17 +148,22 @@ struct sigmatel_spec {
138 unsigned int gpio_data; 148 unsigned int gpio_data;
139 unsigned int gpio_mute; 149 unsigned int gpio_mute;
140 150
151 /* stream */
152 unsigned int stream_delay;
153
141 /* analog loopback */ 154 /* analog loopback */
142 unsigned char aloopback_mask; 155 unsigned char aloopback_mask;
143 unsigned char aloopback_shift; 156 unsigned char aloopback_shift;
144 157
145 /* power management */ 158 /* power management */
146 unsigned int num_pwrs; 159 unsigned int num_pwrs;
160 unsigned int *pwr_mapping;
147 hda_nid_t *pwr_nids; 161 hda_nid_t *pwr_nids;
148 hda_nid_t *dac_list; 162 hda_nid_t *dac_list;
149 163
150 /* playback */ 164 /* playback */
151 struct hda_input_mux *mono_mux; 165 struct hda_input_mux *mono_mux;
166 struct hda_input_mux *amp_mux;
152 unsigned int cur_mmux; 167 unsigned int cur_mmux;
153 struct hda_multi_out multiout; 168 struct hda_multi_out multiout;
154 hda_nid_t dac_nids[5]; 169 hda_nid_t dac_nids[5];
@@ -162,8 +177,14 @@ struct sigmatel_spec {
162 unsigned int num_dmics; 177 unsigned int num_dmics;
163 hda_nid_t *dmux_nids; 178 hda_nid_t *dmux_nids;
164 unsigned int num_dmuxes; 179 unsigned int num_dmuxes;
180 hda_nid_t *smux_nids;
181 unsigned int num_smuxes;
182 const char **spdif_labels;
183
165 hda_nid_t dig_in_nid; 184 hda_nid_t dig_in_nid;
166 hda_nid_t mono_nid; 185 hda_nid_t mono_nid;
186 hda_nid_t anabeep_nid;
187 hda_nid_t digbeep_nid;
167 188
168 /* pin widgets */ 189 /* pin widgets */
169 hda_nid_t *pin_nids; 190 hda_nid_t *pin_nids;
@@ -180,6 +201,12 @@ struct sigmatel_spec {
180 unsigned int cur_dmux[2]; 201 unsigned int cur_dmux[2];
181 struct hda_input_mux *input_mux; 202 struct hda_input_mux *input_mux;
182 unsigned int cur_mux[3]; 203 unsigned int cur_mux[3];
204 struct hda_input_mux *sinput_mux;
205 unsigned int cur_smux[2];
206 unsigned int cur_amux;
207 hda_nid_t *amp_nids;
208 unsigned int num_amps;
209 unsigned int powerdown_adcs;
183 210
184 /* i/o switches */ 211 /* i/o switches */
185 unsigned int io_switch[2]; 212 unsigned int io_switch[2];
@@ -195,6 +222,8 @@ struct sigmatel_spec {
195 struct snd_kcontrol_new *kctl_alloc; 222 struct snd_kcontrol_new *kctl_alloc;
196 struct hda_input_mux private_dimux; 223 struct hda_input_mux private_dimux;
197 struct hda_input_mux private_imux; 224 struct hda_input_mux private_imux;
225 struct hda_input_mux private_smux;
226 struct hda_input_mux private_amp_mux;
198 struct hda_input_mux private_mono_mux; 227 struct hda_input_mux private_mono_mux;
199}; 228};
200 229
@@ -215,10 +244,19 @@ static hda_nid_t stac92hd73xx_pwr_nids[8] = {
215 0x0f, 0x10, 0x11 244 0x0f, 0x10, 0x11
216}; 245};
217 246
247static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
248 0x26, 0,
249};
250
218static hda_nid_t stac92hd73xx_adc_nids[2] = { 251static hda_nid_t stac92hd73xx_adc_nids[2] = {
219 0x1a, 0x1b 252 0x1a, 0x1b
220}; 253};
221 254
255#define DELL_M6_AMP 2
256static hda_nid_t stac92hd73xx_amp_nids[3] = {
257 0x0b, 0x0c, 0x0e
258};
259
222#define STAC92HD73XX_NUM_DMICS 2 260#define STAC92HD73XX_NUM_DMICS 2
223static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = { 261static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
224 0x13, 0x14, 0 262 0x13, 0x14, 0
@@ -237,6 +275,41 @@ static hda_nid_t stac92hd73xx_dmux_nids[2] = {
237 0x20, 0x21, 275 0x20, 0x21,
238}; 276};
239 277
278static hda_nid_t stac92hd73xx_smux_nids[2] = {
279 0x22, 0x23,
280};
281
282#define STAC92HD83XXX_NUM_DMICS 2
283static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
284 0x11, 0x12, 0
285};
286
287#define STAC92HD81_DAC_COUNT 2
288#define STAC92HD83_DAC_COUNT 3
289static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
290 0x13, 0x14, 0x22,
291};
292
293static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
294 0x17, 0x18,
295};
296
297static hda_nid_t stac92hd83xxx_adc_nids[2] = {
298 0x15, 0x16,
299};
300
301static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
302 0xa, 0xb, 0xd, 0xe,
303};
304
305static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
306 0x1e, 0,
307};
308
309static unsigned int stac92hd83xxx_pwr_mapping[4] = {
310 0x03, 0x0c, 0x10, 0x40,
311};
312
240static hda_nid_t stac92hd71bxx_pwr_nids[3] = { 313static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
241 0x0a, 0x0d, 0x0f 314 0x0a, 0x0d, 0x0f
242}; 315};
@@ -249,8 +322,12 @@ static hda_nid_t stac92hd71bxx_mux_nids[2] = {
249 0x1a, 0x1b 322 0x1a, 0x1b
250}; 323};
251 324
252static hda_nid_t stac92hd71bxx_dmux_nids[1] = { 325static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
253 0x1c, 326 0x1c, 0x1d,
327};
328
329static hda_nid_t stac92hd71bxx_smux_nids[2] = {
330 0x24, 0x25,
254}; 331};
255 332
256static hda_nid_t stac92hd71bxx_dac_nids[1] = { 333static hda_nid_t stac92hd71bxx_dac_nids[1] = {
@@ -262,6 +339,10 @@ static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
262 0x18, 0x19, 0 339 0x18, 0x19, 0
263}; 340};
264 341
342static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
343 0x22, 0
344};
345
265static hda_nid_t stac925x_adc_nids[1] = { 346static hda_nid_t stac925x_adc_nids[1] = {
266 0x03, 347 0x03,
267}; 348};
@@ -299,6 +380,10 @@ static hda_nid_t stac927x_mux_nids[3] = {
299 0x15, 0x16, 0x17 380 0x15, 0x16, 0x17
300}; 381};
301 382
383static hda_nid_t stac927x_smux_nids[1] = {
384 0x21,
385};
386
302static hda_nid_t stac927x_dac_nids[6] = { 387static hda_nid_t stac927x_dac_nids[6] = {
303 0x02, 0x03, 0x04, 0x05, 0x06, 0 388 0x02, 0x03, 0x04, 0x05, 0x06, 0
304}; 389};
@@ -312,6 +397,11 @@ static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
312 0x13, 0x14, 0 397 0x13, 0x14, 0
313}; 398};
314 399
400static const char *stac927x_spdif_labels[5] = {
401 "Digital Playback", "ADAT", "Analog Mux 1",
402 "Analog Mux 2", "Analog Mux 3"
403};
404
315static hda_nid_t stac9205_adc_nids[2] = { 405static hda_nid_t stac9205_adc_nids[2] = {
316 0x12, 0x13 406 0x12, 0x13
317}; 407};
@@ -324,6 +414,10 @@ static hda_nid_t stac9205_dmux_nids[1] = {
324 0x1d, 414 0x1d,
325}; 415};
326 416
417static hda_nid_t stac9205_smux_nids[1] = {
418 0x21,
419};
420
327#define STAC9205_NUM_DMICS 2 421#define STAC9205_NUM_DMICS 2
328static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = { 422static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
329 0x17, 0x18, 0 423 0x17, 0x18, 0
@@ -347,12 +441,18 @@ static hda_nid_t stac922x_pin_nids[10] = {
347static hda_nid_t stac92hd73xx_pin_nids[13] = { 441static hda_nid_t stac92hd73xx_pin_nids[13] = {
348 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 442 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
349 0x0f, 0x10, 0x11, 0x12, 0x13, 443 0x0f, 0x10, 0x11, 0x12, 0x13,
350 0x14, 0x1e, 0x22 444 0x14, 0x22, 0x23
351}; 445};
352 446
353static hda_nid_t stac92hd71bxx_pin_nids[10] = { 447static hda_nid_t stac92hd83xxx_pin_nids[14] = {
448 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
449 0x0f, 0x10, 0x11, 0x12, 0x13,
450 0x1d, 0x1e, 0x1f, 0x20
451};
452static hda_nid_t stac92hd71bxx_pin_nids[11] = {
354 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 453 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
355 0x0f, 0x14, 0x18, 0x19, 0x1e, 454 0x0f, 0x14, 0x18, 0x19, 0x1e,
455 0x1f,
356}; 456};
357 457
358static hda_nid_t stac927x_pin_nids[14] = { 458static hda_nid_t stac927x_pin_nids[14] = {
@@ -367,6 +467,34 @@ static hda_nid_t stac9205_pin_nids[12] = {
367 0x21, 0x22, 467 0x21, 0x22,
368}; 468};
369 469
470#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
471
472static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
473 struct snd_ctl_elem_value *ucontrol)
474{
475 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
476 struct sigmatel_spec *spec = codec->spec;
477 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
478
479 kcontrol->private_value ^= get_amp_nid(kcontrol);
480 kcontrol->private_value |= nid;
481
482 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
483}
484
485static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
486 struct snd_ctl_elem_value *ucontrol)
487{
488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
489 struct sigmatel_spec *spec = codec->spec;
490 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
491
492 kcontrol->private_value ^= get_amp_nid(kcontrol);
493 kcontrol->private_value |= nid;
494
495 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
496}
497
370static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol, 498static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_info *uinfo) 499 struct snd_ctl_elem_info *uinfo)
372{ 500{
@@ -397,6 +525,58 @@ static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
397 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]); 525 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
398} 526}
399 527
528static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
529 struct snd_ctl_elem_info *uinfo)
530{
531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
532 struct sigmatel_spec *spec = codec->spec;
533 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
534}
535
536static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
537 struct snd_ctl_elem_value *ucontrol)
538{
539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
540 struct sigmatel_spec *spec = codec->spec;
541 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
542
543 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
544 return 0;
545}
546
547static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
548 struct snd_ctl_elem_value *ucontrol)
549{
550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551 struct sigmatel_spec *spec = codec->spec;
552 struct hda_input_mux *smux = &spec->private_smux;
553 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
554 int err, val;
555 hda_nid_t nid;
556
557 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
558 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
559 if (err < 0)
560 return err;
561
562 if (spec->spdif_mute) {
563 if (smux_idx == 0)
564 nid = spec->multiout.dig_out_nid;
565 else
566 nid = codec->slave_dig_outs[smux_idx - 1];
567 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
568 val = AMP_OUT_MUTE;
569 if (smux_idx == 0)
570 nid = spec->multiout.dig_out_nid;
571 else
572 nid = codec->slave_dig_outs[smux_idx - 1];
573 /* un/mute SPDIF out */
574 snd_hda_codec_write_cache(codec, nid, 0,
575 AC_VERB_SET_AMP_GAIN_MUTE, val);
576 }
577 return 0;
578}
579
400static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 580static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
401{ 581{
402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 582 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
@@ -452,6 +632,41 @@ static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
452 spec->mono_nid, &spec->cur_mmux); 632 spec->mono_nid, &spec->cur_mmux);
453} 633}
454 634
635static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_info *uinfo)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct sigmatel_spec *spec = codec->spec;
640 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
641}
642
643static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct sigmatel_spec *spec = codec->spec;
648
649 ucontrol->value.enumerated.item[0] = spec->cur_amux;
650 return 0;
651}
652
653static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
655{
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct sigmatel_spec *spec = codec->spec;
658 struct snd_kcontrol *ctl =
659 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
660 if (!ctl)
661 return -EINVAL;
662
663 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
664 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
665
666 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
667 0, &spec->cur_amux);
668}
669
455#define stac92xx_aloopback_info snd_ctl_boolean_mono_info 670#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
456 671
457static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol, 672static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
@@ -546,8 +761,8 @@ static struct hda_verb dell_eq_core_init[] = {
546 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec}, 761 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
547 /* setup audio connections */ 762 /* setup audio connections */
548 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00}, 763 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
549 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01}, 764 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
550 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02}, 765 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
551 /* setup adcs to point to mixer */ 766 /* setup adcs to point to mixer */
552 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b}, 767 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
553 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b}, 768 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -628,25 +843,36 @@ static struct hda_verb stac92hd73xx_10ch_core_init[] = {
628 {} 843 {}
629}; 844};
630 845
846static struct hda_verb stac92hd83xxx_core_init[] = {
847 /* start of config #1 */
848 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
849
850 /* start of config #2 */
851 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
852 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
853 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
854
855 /* power state controls amps */
856 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
857};
858
631static struct hda_verb stac92hd71bxx_core_init[] = { 859static struct hda_verb stac92hd71bxx_core_init[] = {
632 /* set master volume and direct control */ 860 /* set master volume and direct control */
633 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 861 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
634 /* connect headphone jack to dac1 */ 862 /* connect headphone jack to dac1 */
635 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01}, 863 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
636 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
637 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */ 864 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
638 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 865 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
639 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 866 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
640 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 867 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
641}; 868};
642 869
643#define HD_DISABLE_PORTF 3 870#define HD_DISABLE_PORTF 2
644static struct hda_verb stac92hd71bxx_analog_core_init[] = { 871static struct hda_verb stac92hd71bxx_analog_core_init[] = {
645 /* start of config #1 */ 872 /* start of config #1 */
646 873
647 /* connect port 0f to audio mixer */ 874 /* connect port 0f to audio mixer */
648 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2}, 875 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
649 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
650 /* unmute right and left channels for node 0x0f */ 876 /* unmute right and left channels for node 0x0f */
651 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 877 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
652 /* start of config #2 */ 878 /* start of config #2 */
@@ -655,10 +881,6 @@ static struct hda_verb stac92hd71bxx_analog_core_init[] = {
655 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 881 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
656 /* connect headphone jack to dac1 */ 882 /* connect headphone jack to dac1 */
657 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01}, 883 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
658 /* connect port 0d to audio mixer */
659 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
660 /* unmute dac0 input in audio mixer */
661 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
662 /* unmute right and left channels for nodes 0x0a, 0xd */ 884 /* unmute right and left channels for nodes 0x0a, 0xd */
663 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 885 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
664 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 886 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -690,12 +912,16 @@ static struct hda_verb d965_core_init[] = {
690static struct hda_verb stac927x_core_init[] = { 912static struct hda_verb stac927x_core_init[] = {
691 /* set master volume and direct control */ 913 /* set master volume and direct control */
692 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 914 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
915 /* enable analog pc beep path */
916 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
693 {} 917 {}
694}; 918};
695 919
696static struct hda_verb stac9205_core_init[] = { 920static struct hda_verb stac9205_core_init[] = {
697 /* set master volume and direct control */ 921 /* set master volume and direct control */
698 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 922 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
923 /* enable analog pc beep path */
924 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
699 {} 925 {}
700}; 926};
701 927
@@ -709,6 +935,31 @@ static struct hda_verb stac9205_core_init[] = {
709 .put = stac92xx_mono_mux_enum_put, \ 935 .put = stac92xx_mono_mux_enum_put, \
710 } 936 }
711 937
938#define STAC_AMP_MUX \
939 { \
940 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
941 .name = "Amp Selector Capture Switch", \
942 .count = 1, \
943 .info = stac92xx_amp_mux_enum_info, \
944 .get = stac92xx_amp_mux_enum_get, \
945 .put = stac92xx_amp_mux_enum_put, \
946 }
947
948#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
949 { \
950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
951 .name = xname, \
952 .index = 0, \
953 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
954 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
955 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
956 .info = stac92xx_amp_volume_info, \
957 .get = stac92xx_amp_volume_get, \
958 .put = stac92xx_amp_volume_put, \
959 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
960 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
961 }
962
712#define STAC_INPUT_SOURCE(cnt) \ 963#define STAC_INPUT_SOURCE(cnt) \
713 { \ 964 { \
714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -736,33 +987,36 @@ static struct snd_kcontrol_new stac9200_mixer[] = {
736 STAC_INPUT_SOURCE(1), 987 STAC_INPUT_SOURCE(1),
737 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT), 988 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
738 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT), 989 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
739 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
740 { } /* end */ 990 { } /* end */
741}; 991};
742 992
993#define DELL_M6_MIXER 6
743static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = { 994static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
744 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3), 995 /* start of config #1 */
745
746 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
747 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
748
749 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
750 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
751
752 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT), 996 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
753 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT), 997 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
754 998
755 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
756 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
757
758 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT), 999 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
759 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT), 1000 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
760 1001
1002 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1003 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1004
1005 /* start of config #2 */
1006 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1007 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1008
761 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT), 1009 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
762 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT), 1010 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
763 1011
764 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT), 1012 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
765 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT), 1013
1014 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1015 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1016
1017 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1018 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1019
766 { } /* end */ 1020 { } /* end */
767}; 1021};
768 1022
@@ -818,22 +1072,59 @@ static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
818 { } /* end */ 1072 { } /* end */
819}; 1073};
820 1074
1075
1076static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1077 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1078 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1079
1080 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1081 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1082
1083 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1084 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1085
1086 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1087 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1088
1089 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1090 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1091
1092 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1093 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1094
1095 /*
1096 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1097 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1098 */
1099 { } /* end */
1100};
1101
821static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = { 1102static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
822 STAC_INPUT_SOURCE(2), 1103 STAC_INPUT_SOURCE(2),
1104 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
823 1105
824 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1106 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
825 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1107 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
826 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
827 1108
828 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT), 1109 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
829 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT), 1110 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
830 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT), 1111 /* analog pc-beep replaced with digital beep support */
831 1112 /*
832 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT), 1113 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
833 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT), 1114 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
1115 */
1116
1117 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1118 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
1119
1120 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1121 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
834 1122
835 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT), 1123 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
836 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT), 1124 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1125
1126 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1127 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
837 { } /* end */ 1128 { } /* end */
838}; 1129};
839 1130
@@ -843,11 +1134,9 @@ static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
843 1134
844 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1135 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
845 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1136 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
846 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
847 1137
848 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT), 1138 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
849 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT), 1139 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
850 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
851 { } /* end */ 1140 { } /* end */
852}; 1141};
853 1142
@@ -855,7 +1144,6 @@ static struct snd_kcontrol_new stac925x_mixer[] = {
855 STAC_INPUT_SOURCE(1), 1144 STAC_INPUT_SOURCE(1),
856 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT), 1145 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
857 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT), 1146 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
858 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
859 { } /* end */ 1147 { } /* end */
860}; 1148};
861 1149
@@ -865,12 +1153,9 @@ static struct snd_kcontrol_new stac9205_mixer[] = {
865 1153
866 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT), 1154 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
867 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT), 1155 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
868 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
869 1156
870 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT), 1157 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
871 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT), 1158 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
872 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
873
874 { } /* end */ 1159 { } /* end */
875}; 1160};
876 1161
@@ -879,11 +1164,9 @@ static struct snd_kcontrol_new stac922x_mixer[] = {
879 STAC_INPUT_SOURCE(2), 1164 STAC_INPUT_SOURCE(2),
880 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT), 1165 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
881 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT), 1166 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
882 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
883 1167
884 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT), 1168 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
885 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT), 1169 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
886 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
887 { } /* end */ 1170 { } /* end */
888}; 1171};
889 1172
@@ -894,15 +1177,12 @@ static struct snd_kcontrol_new stac927x_mixer[] = {
894 1177
895 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT), 1178 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
896 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT), 1179 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
897 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
898 1180
899 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT), 1181 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
900 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT), 1182 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
901 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
902 1183
903 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT), 1184 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
904 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT), 1185 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
905 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
906 { } /* end */ 1186 { } /* end */
907}; 1187};
908 1188
@@ -915,6 +1195,15 @@ static struct snd_kcontrol_new stac_dmux_mixer = {
915 .put = stac92xx_dmux_enum_put, 1195 .put = stac92xx_dmux_enum_put,
916}; 1196};
917 1197
1198static struct snd_kcontrol_new stac_smux_mixer = {
1199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1200 .name = "IEC958 Playback Source",
1201 /* count set later */
1202 .info = stac92xx_smux_enum_info,
1203 .get = stac92xx_smux_enum_get,
1204 .put = stac92xx_smux_enum_put,
1205};
1206
918static const char *slave_vols[] = { 1207static const char *slave_vols[] = {
919 "Front Playback Volume", 1208 "Front Playback Volume",
920 "Surround Playback Volume", 1209 "Surround Playback Volume",
@@ -966,6 +1255,22 @@ static int stac92xx_build_controls(struct hda_codec *codec)
966 if (err < 0) 1255 if (err < 0)
967 return err; 1256 return err;
968 } 1257 }
1258 if (spec->num_smuxes > 0) {
1259 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1260 struct hda_input_mux *smux = &spec->private_smux;
1261 /* check for mute support on SPDIF out */
1262 if (wcaps & AC_WCAP_OUT_AMP) {
1263 smux->items[smux->num_items].label = "Off";
1264 smux->items[smux->num_items].index = 0;
1265 smux->num_items++;
1266 spec->spdif_mute = 1;
1267 }
1268 stac_smux_mixer.count = spec->num_smuxes;
1269 err = snd_ctl_add(codec->bus->card,
1270 snd_ctl_new1(&stac_smux_mixer, codec));
1271 if (err < 0)
1272 return err;
1273 }
969 1274
970 if (spec->multiout.dig_out_nid) { 1275 if (spec->multiout.dig_out_nid) {
971 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 1276 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
@@ -977,7 +1282,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
977 return err; 1282 return err;
978 spec->multiout.share_spdif = 1; 1283 spec->multiout.share_spdif = 1;
979 } 1284 }
980 if (spec->dig_in_nid) { 1285 if (spec->dig_in_nid && (!spec->gpio_dir & 0x01)) {
981 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 1286 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
982 if (err < 0) 1287 if (err < 0)
983 return err; 1288 return err;
@@ -1325,40 +1630,65 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1325 {} /* terminator */ 1630 {} /* terminator */
1326}; 1631};
1327 1632
1328static unsigned int ref92hd71bxx_pin_configs[10] = { 1633static unsigned int ref92hd83xxx_pin_configs[14] = {
1634 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1635 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1636 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1637 0x01451160, 0x98560170,
1638};
1639
1640static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1641 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1642};
1643
1644static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1645 [STAC_92HD83XXX_REF] = "ref",
1646};
1647
1648static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1649 /* SigmaTel reference board */
1650 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1651 "DFI LanParty", STAC_92HD71BXX_REF),
1652};
1653
1654static unsigned int ref92hd71bxx_pin_configs[11] = {
1329 0x02214030, 0x02a19040, 0x01a19020, 0x01014010, 1655 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1330 0x0181302e, 0x01114010, 0x01019020, 0x90a000f0, 1656 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1331 0x90a000f0, 0x01452050, 1657 0x90a000f0, 0x01452050, 0x01452050,
1332}; 1658};
1333 1659
1334static unsigned int dell_m4_1_pin_configs[10] = { 1660static unsigned int dell_m4_1_pin_configs[11] = {
1335 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110, 1661 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1336 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0, 1662 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1337 0x40f000f0, 0x4f0000f0, 1663 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
1338}; 1664};
1339 1665
1340static unsigned int dell_m4_2_pin_configs[10] = { 1666static unsigned int dell_m4_2_pin_configs[11] = {
1341 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110, 1667 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1342 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0, 1668 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1343 0x40f000f0, 0x044413b0, 1669 0x40f000f0, 0x044413b0, 0x044413b0,
1344}; 1670};
1345 1671
1346static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { 1672static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1347 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs, 1673 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1348 [STAC_DELL_M4_1] = dell_m4_1_pin_configs, 1674 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1349 [STAC_DELL_M4_2] = dell_m4_2_pin_configs, 1675 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1676 [STAC_HP_M4] = NULL,
1350}; 1677};
1351 1678
1352static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { 1679static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1353 [STAC_92HD71BXX_REF] = "ref", 1680 [STAC_92HD71BXX_REF] = "ref",
1354 [STAC_DELL_M4_1] = "dell-m4-1", 1681 [STAC_DELL_M4_1] = "dell-m4-1",
1355 [STAC_DELL_M4_2] = "dell-m4-2", 1682 [STAC_DELL_M4_2] = "dell-m4-2",
1683 [STAC_HP_M4] = "hp-m4",
1356}; 1684};
1357 1685
1358static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { 1686static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1359 /* SigmaTel reference board */ 1687 /* SigmaTel reference board */
1360 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1361 "DFI LanParty", STAC_92HD71BXX_REF), 1689 "DFI LanParty", STAC_92HD71BXX_REF),
1690 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1691 "unknown HP", STAC_HP_M4),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233, 1692 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1363 "unknown Dell", STAC_DELL_M4_1), 1693 "unknown Dell", STAC_DELL_M4_1),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234, 1694 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
@@ -1477,6 +1807,11 @@ static unsigned int intel_mac_v5_pin_configs[10] = {
1477 0x400000fc, 0x400000fb, 1807 0x400000fc, 0x400000fb,
1478}; 1808};
1479 1809
1810static unsigned int ecs202_pin_configs[10] = {
1811 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1812 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1813 0x9037012e, 0x40e000f2,
1814};
1480 1815
1481static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = { 1816static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1482 [STAC_D945_REF] = ref922x_pin_configs, 1817 [STAC_D945_REF] = ref922x_pin_configs,
@@ -1495,6 +1830,7 @@ static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1495 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs, 1830 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1496 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs, 1831 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1497 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs, 1832 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
1833 [STAC_ECS_202] = ecs202_pin_configs,
1498 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs, 1834 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1499 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs, 1835 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1500 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs, 1836 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
@@ -1518,6 +1854,7 @@ static const char *stac922x_models[STAC_922X_MODELS] = {
1518 [STAC_MACBOOK_PRO_V2] = "macbook-pro", 1854 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
1519 [STAC_IMAC_INTEL] = "imac-intel", 1855 [STAC_IMAC_INTEL] = "imac-intel",
1520 [STAC_IMAC_INTEL_20] = "imac-intel-20", 1856 [STAC_IMAC_INTEL_20] = "imac-intel-20",
1857 [STAC_ECS_202] = "ecs202",
1521 [STAC_922X_DELL_D81] = "dell-d81", 1858 [STAC_922X_DELL_D81] = "dell-d81",
1522 [STAC_922X_DELL_D82] = "dell-d82", 1859 [STAC_922X_DELL_D82] = "dell-d82",
1523 [STAC_922X_DELL_M81] = "dell-m81", 1860 [STAC_922X_DELL_M81] = "dell-m81",
@@ -1604,6 +1941,33 @@ static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1604 "unknown Dell", STAC_922X_DELL_D81), 1941 "unknown Dell", STAC_922X_DELL_D81),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7, 1942 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1606 "Dell XPS M1210", STAC_922X_DELL_M82), 1943 "Dell XPS M1210", STAC_922X_DELL_M82),
1944 /* ECS/PC Chips boards */
1945 SND_PCI_QUIRK(0x1019, 0x2144,
1946 "ECS/PC chips", STAC_ECS_202),
1947 SND_PCI_QUIRK(0x1019, 0x2608,
1948 "ECS/PC chips", STAC_ECS_202),
1949 SND_PCI_QUIRK(0x1019, 0x2633,
1950 "ECS/PC chips P17G/1333", STAC_ECS_202),
1951 SND_PCI_QUIRK(0x1019, 0x2811,
1952 "ECS/PC chips", STAC_ECS_202),
1953 SND_PCI_QUIRK(0x1019, 0x2812,
1954 "ECS/PC chips", STAC_ECS_202),
1955 SND_PCI_QUIRK(0x1019, 0x2813,
1956 "ECS/PC chips", STAC_ECS_202),
1957 SND_PCI_QUIRK(0x1019, 0x2814,
1958 "ECS/PC chips", STAC_ECS_202),
1959 SND_PCI_QUIRK(0x1019, 0x2815,
1960 "ECS/PC chips", STAC_ECS_202),
1961 SND_PCI_QUIRK(0x1019, 0x2816,
1962 "ECS/PC chips", STAC_ECS_202),
1963 SND_PCI_QUIRK(0x1019, 0x2817,
1964 "ECS/PC chips", STAC_ECS_202),
1965 SND_PCI_QUIRK(0x1019, 0x2818,
1966 "ECS/PC chips", STAC_ECS_202),
1967 SND_PCI_QUIRK(0x1019, 0x2819,
1968 "ECS/PC chips", STAC_ECS_202),
1969 SND_PCI_QUIRK(0x1019, 0x2820,
1970 "ECS/PC chips", STAC_ECS_202),
1607 {} /* terminator */ 1971 {} /* terminator */
1608}; 1972};
1609 1973
@@ -1683,8 +2047,8 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1683 /* Dell 3 stack systems with verb table in BIOS */ 2047 /* Dell 3 stack systems with verb table in BIOS */
1684 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS), 2048 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
1685 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS), 2049 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
1686 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell ", STAC_DELL_BIOS),
1687 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS), 2050 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
2051 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
1688 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS), 2052 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
1689 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS), 2053 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
1690 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS), 2054 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
@@ -1867,6 +2231,8 @@ static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1867 struct snd_pcm_substream *substream) 2231 struct snd_pcm_substream *substream)
1868{ 2232{
1869 struct sigmatel_spec *spec = codec->spec; 2233 struct sigmatel_spec *spec = codec->spec;
2234 if (spec->stream_delay)
2235 msleep(spec->stream_delay);
1870 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 2236 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1871 hinfo); 2237 hinfo);
1872} 2238}
@@ -1930,9 +2296,14 @@ static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1930 struct snd_pcm_substream *substream) 2296 struct snd_pcm_substream *substream)
1931{ 2297{
1932 struct sigmatel_spec *spec = codec->spec; 2298 struct sigmatel_spec *spec = codec->spec;
2299 hda_nid_t nid = spec->adc_nids[substream->number];
1933 2300
1934 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 2301 if (spec->powerdown_adcs) {
1935 stream_tag, 0, format); 2302 msleep(40);
2303 snd_hda_codec_write_cache(codec, nid, 0,
2304 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2305 }
2306 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
1936 return 0; 2307 return 0;
1937} 2308}
1938 2309
@@ -1941,8 +2312,12 @@ static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1941 struct snd_pcm_substream *substream) 2312 struct snd_pcm_substream *substream)
1942{ 2313{
1943 struct sigmatel_spec *spec = codec->spec; 2314 struct sigmatel_spec *spec = codec->spec;
2315 hda_nid_t nid = spec->adc_nids[substream->number];
1944 2316
1945 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 2317 snd_hda_codec_cleanup_stream(codec, nid);
2318 if (spec->powerdown_adcs)
2319 snd_hda_codec_write_cache(codec, nid, 0,
2320 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1946 return 0; 2321 return 0;
1947} 2322}
1948 2323
@@ -2193,6 +2568,8 @@ enum {
2193 STAC_CTL_WIDGET_VOL, 2568 STAC_CTL_WIDGET_VOL,
2194 STAC_CTL_WIDGET_MUTE, 2569 STAC_CTL_WIDGET_MUTE,
2195 STAC_CTL_WIDGET_MONO_MUX, 2570 STAC_CTL_WIDGET_MONO_MUX,
2571 STAC_CTL_WIDGET_AMP_MUX,
2572 STAC_CTL_WIDGET_AMP_VOL,
2196 STAC_CTL_WIDGET_HP_SWITCH, 2573 STAC_CTL_WIDGET_HP_SWITCH,
2197 STAC_CTL_WIDGET_IO_SWITCH, 2574 STAC_CTL_WIDGET_IO_SWITCH,
2198 STAC_CTL_WIDGET_CLFE_SWITCH 2575 STAC_CTL_WIDGET_CLFE_SWITCH
@@ -2202,13 +2579,16 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2202 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2579 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2203 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2580 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2204 STAC_MONO_MUX, 2581 STAC_MONO_MUX,
2582 STAC_AMP_MUX,
2583 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
2205 STAC_CODEC_HP_SWITCH(NULL), 2584 STAC_CODEC_HP_SWITCH(NULL),
2206 STAC_CODEC_IO_SWITCH(NULL, 0), 2585 STAC_CODEC_IO_SWITCH(NULL, 0),
2207 STAC_CODEC_CLFE_SWITCH(NULL, 0), 2586 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2208}; 2587};
2209 2588
2210/* add dynamic controls */ 2589/* add dynamic controls */
2211static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val) 2590static int stac92xx_add_control_idx(struct sigmatel_spec *spec, int type,
2591 int idx, const char *name, unsigned long val)
2212{ 2592{
2213 struct snd_kcontrol_new *knew; 2593 struct snd_kcontrol_new *knew;
2214 2594
@@ -2228,6 +2608,7 @@ static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char
2228 2608
2229 knew = &spec->kctl_alloc[spec->num_kctl_used]; 2609 knew = &spec->kctl_alloc[spec->num_kctl_used];
2230 *knew = stac92xx_control_templates[type]; 2610 *knew = stac92xx_control_templates[type];
2611 knew->index = idx;
2231 knew->name = kstrdup(name, GFP_KERNEL); 2612 knew->name = kstrdup(name, GFP_KERNEL);
2232 if (! knew->name) 2613 if (! knew->name)
2233 return -ENOMEM; 2614 return -ENOMEM;
@@ -2236,6 +2617,14 @@ static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char
2236 return 0; 2617 return 0;
2237} 2618}
2238 2619
2620
2621/* add dynamic controls */
2622static int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2623 const char *name, unsigned long val)
2624{
2625 return stac92xx_add_control_idx(spec, type, 0, name, val);
2626}
2627
2239/* flag inputs as additional dynamic lineouts */ 2628/* flag inputs as additional dynamic lineouts */
2240static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg) 2629static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2241{ 2630{
@@ -2467,6 +2856,10 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2467 } 2856 }
2468 } 2857 }
2469 2858
2859 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2860 cfg->hp_outs && !spec->multiout.hp_nid)
2861 spec->multiout.hp_nid = nid;
2862
2470 if (cfg->hp_outs > 1) { 2863 if (cfg->hp_outs > 1) {
2471 err = stac92xx_add_control(spec, 2864 err = stac92xx_add_control(spec,
2472 STAC_CTL_WIDGET_HP_SWITCH, 2865 STAC_CTL_WIDGET_HP_SWITCH,
@@ -2579,8 +2972,8 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2579} 2972}
2580 2973
2581/* labels for mono mux outputs */ 2974/* labels for mono mux outputs */
2582static const char *stac92xx_mono_labels[3] = { 2975static const char *stac92xx_mono_labels[4] = {
2583 "DAC0", "DAC1", "Mixer" 2976 "DAC0", "DAC1", "Mixer", "DAC2"
2584}; 2977};
2585 2978
2586/* create mono mux for mono out on capable codecs */ 2979/* create mono mux for mono out on capable codecs */
@@ -2609,6 +3002,116 @@ static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
2609 "Mono Mux", spec->mono_nid); 3002 "Mono Mux", spec->mono_nid);
2610} 3003}
2611 3004
3005/* labels for amp mux outputs */
3006static const char *stac92xx_amp_labels[3] = {
3007 "Front Microphone", "Microphone", "Line In",
3008};
3009
3010/* create amp out controls mux on capable codecs */
3011static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3012{
3013 struct sigmatel_spec *spec = codec->spec;
3014 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3015 int i, err;
3016
3017 for (i = 0; i < spec->num_amps; i++) {
3018 amp_mux->items[amp_mux->num_items].label =
3019 stac92xx_amp_labels[i];
3020 amp_mux->items[amp_mux->num_items].index = i;
3021 amp_mux->num_items++;
3022 }
3023
3024 if (spec->num_amps > 1) {
3025 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3026 "Amp Selector Capture Switch", 0);
3027 if (err < 0)
3028 return err;
3029 }
3030 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3031 "Amp Capture Volume",
3032 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3033}
3034
3035
3036/* create PC beep volume controls */
3037static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3038 hda_nid_t nid)
3039{
3040 struct sigmatel_spec *spec = codec->spec;
3041 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3042 int err;
3043
3044 /* check for mute support for the the amp */
3045 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3046 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3047 "PC Beep Playback Switch",
3048 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3049 if (err < 0)
3050 return err;
3051 }
3052
3053 /* check to see if there is volume support for the amp */
3054 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3055 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3056 "PC Beep Playback Volume",
3057 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3058 if (err < 0)
3059 return err;
3060 }
3061 return 0;
3062}
3063
3064static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3065{
3066 struct sigmatel_spec *spec = codec->spec;
3067 int wcaps, nid, i, err = 0;
3068
3069 for (i = 0; i < spec->num_muxes; i++) {
3070 nid = spec->mux_nids[i];
3071 wcaps = get_wcaps(codec, nid);
3072
3073 if (wcaps & AC_WCAP_OUT_AMP) {
3074 err = stac92xx_add_control_idx(spec,
3075 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3076 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3077 if (err < 0)
3078 return err;
3079 }
3080 }
3081 return 0;
3082};
3083
3084static const char *stac92xx_spdif_labels[3] = {
3085 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
3086};
3087
3088static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3089{
3090 struct sigmatel_spec *spec = codec->spec;
3091 struct hda_input_mux *spdif_mux = &spec->private_smux;
3092 const char **labels = spec->spdif_labels;
3093 int i, num_cons;
3094 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3095
3096 num_cons = snd_hda_get_connections(codec,
3097 spec->smux_nids[0],
3098 con_lst,
3099 HDA_MAX_NUM_INPUTS);
3100 if (!num_cons)
3101 return -EINVAL;
3102
3103 if (!labels)
3104 labels = stac92xx_spdif_labels;
3105
3106 for (i = 0; i < num_cons; i++) {
3107 spdif_mux->items[spdif_mux->num_items].label = labels[i];
3108 spdif_mux->items[spdif_mux->num_items].index = i;
3109 spdif_mux->num_items++;
3110 }
3111
3112 return 0;
3113}
3114
2612/* labels for dmic mux inputs */ 3115/* labels for dmic mux inputs */
2613static const char *stac92xx_dmic_labels[5] = { 3116static const char *stac92xx_dmic_labels[5] = {
2614 "Analog Inputs", "Digital Mic 1", "Digital Mic 2", 3117 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
@@ -2656,16 +3159,19 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2656 } 3159 }
2657 continue; 3160 continue;
2658found: 3161found:
2659 wcaps = get_wcaps(codec, nid); 3162 wcaps = get_wcaps(codec, nid) &
3163 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
2660 3164
2661 if (wcaps & AC_WCAP_OUT_AMP) { 3165 if (wcaps) {
2662 sprintf(name, "%s Capture Volume", 3166 sprintf(name, "%s Capture Volume",
2663 stac92xx_dmic_labels[dimux->num_items]); 3167 stac92xx_dmic_labels[dimux->num_items]);
2664 3168
2665 err = stac92xx_add_control(spec, 3169 err = stac92xx_add_control(spec,
2666 STAC_CTL_WIDGET_VOL, 3170 STAC_CTL_WIDGET_VOL,
2667 name, 3171 name,
2668 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 3172 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3173 (wcaps & AC_WCAP_OUT_AMP) ?
3174 HDA_OUTPUT : HDA_INPUT));
2669 if (err < 0) 3175 if (err < 0)
2670 return err; 3176 return err;
2671 } 3177 }
@@ -2789,8 +3295,8 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
2789 hp_speaker_swap = 1; 3295 hp_speaker_swap = 1;
2790 } 3296 }
2791 if (spec->autocfg.mono_out_pin) { 3297 if (spec->autocfg.mono_out_pin) {
2792 int dir = (get_wcaps(codec, spec->autocfg.mono_out_pin) 3298 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
2793 & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT; 3299 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
2794 u32 caps = query_amp_caps(codec, 3300 u32 caps = query_amp_caps(codec,
2795 spec->autocfg.mono_out_pin, dir); 3301 spec->autocfg.mono_out_pin, dir);
2796 hda_nid_t conn_list[1]; 3302 hda_nid_t conn_list[1];
@@ -2812,21 +3318,26 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
2812 !(wcaps & AC_WCAP_LR_SWAP)) 3318 !(wcaps & AC_WCAP_LR_SWAP))
2813 spec->mono_nid = conn_list[0]; 3319 spec->mono_nid = conn_list[0];
2814 } 3320 }
2815 /* all mono outs have a least a mute/unmute switch */ 3321 if (dir) {
2816 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, 3322 hda_nid_t nid = spec->autocfg.mono_out_pin;
2817 "Mono Playback Switch", 3323
2818 HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin, 3324 /* most mono outs have a least a mute/unmute switch */
2819 1, 0, dir)); 3325 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
2820 if (err < 0) 3326 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
2821 return err; 3327 "Mono Playback Switch",
2822 /* check to see if there is volume support for the amp */ 3328 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
2823 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
2824 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
2825 "Mono Playback Volume",
2826 HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
2827 1, 0, dir));
2828 if (err < 0) 3329 if (err < 0)
2829 return err; 3330 return err;
3331 /* check for volume support for the amp */
3332 if ((caps & AC_AMPCAP_NUM_STEPS)
3333 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3334 err = stac92xx_add_control(spec,
3335 STAC_CTL_WIDGET_VOL,
3336 "Mono Playback Volume",
3337 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3338 if (err < 0)
3339 return err;
3340 }
2830 } 3341 }
2831 3342
2832 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin, 3343 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
@@ -2844,6 +3355,28 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
2844 if (err < 0) 3355 if (err < 0)
2845 return err; 3356 return err;
2846 3357
3358 /* setup analog beep controls */
3359 if (spec->anabeep_nid > 0) {
3360 err = stac92xx_auto_create_beep_ctls(codec,
3361 spec->anabeep_nid);
3362 if (err < 0)
3363 return err;
3364 }
3365
3366 /* setup digital beep controls and input device */
3367#ifdef CONFIG_SND_HDA_INPUT_BEEP
3368 if (spec->digbeep_nid > 0) {
3369 hda_nid_t nid = spec->digbeep_nid;
3370
3371 err = stac92xx_auto_create_beep_ctls(codec, nid);
3372 if (err < 0)
3373 return err;
3374 err = snd_hda_attach_beep_device(codec, nid);
3375 if (err < 0)
3376 return err;
3377 }
3378#endif
3379
2847 if (hp_speaker_swap == 1) { 3380 if (hp_speaker_swap == 1) {
2848 /* Restore the hp_outs and line_outs */ 3381 /* Restore the hp_outs and line_outs */
2849 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins, 3382 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
@@ -2872,11 +3405,25 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
2872 if (err < 0) 3405 if (err < 0)
2873 return err; 3406 return err;
2874 } 3407 }
2875 3408 if (spec->num_amps > 0) {
2876 if (spec->num_dmics > 0) 3409 err = stac92xx_auto_create_amp_output_ctls(codec);
3410 if (err < 0)
3411 return err;
3412 }
3413 if (spec->num_dmics > 0 && !spec->dinput_mux)
2877 if ((err = stac92xx_auto_create_dmic_input_ctls(codec, 3414 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2878 &spec->autocfg)) < 0) 3415 &spec->autocfg)) < 0)
2879 return err; 3416 return err;
3417 if (spec->num_muxes > 0) {
3418 err = stac92xx_auto_create_mux_input_ctls(codec);
3419 if (err < 0)
3420 return err;
3421 }
3422 if (spec->num_smuxes > 0) {
3423 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3424 if (err < 0)
3425 return err;
3426 }
2880 3427
2881 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3428 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2882 if (spec->multiout.max_channels > 2) 3429 if (spec->multiout.max_channels > 2)
@@ -2884,17 +3431,17 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
2884 3431
2885 if (spec->autocfg.dig_out_pin) 3432 if (spec->autocfg.dig_out_pin)
2886 spec->multiout.dig_out_nid = dig_out; 3433 spec->multiout.dig_out_nid = dig_out;
2887 if (spec->autocfg.dig_in_pin) 3434 if (dig_in && spec->autocfg.dig_in_pin)
2888 spec->dig_in_nid = dig_in; 3435 spec->dig_in_nid = dig_in;
2889 3436
2890 if (spec->kctl_alloc) 3437 if (spec->kctl_alloc)
2891 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 3438 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2892 3439
2893 spec->input_mux = &spec->private_imux; 3440 spec->input_mux = &spec->private_imux;
2894 if (!spec->dinput_mux) 3441 spec->dinput_mux = &spec->private_dimux;
2895 spec->dinput_mux = &spec->private_dimux; 3442 spec->sinput_mux = &spec->private_smux;
2896 spec->mono_mux = &spec->private_mono_mux; 3443 spec->mono_mux = &spec->private_mono_mux;
2897 3444 spec->amp_mux = &spec->private_amp_mux;
2898 return 1; 3445 return 1;
2899} 3446}
2900 3447
@@ -3074,6 +3621,12 @@ static int stac92xx_init(struct hda_codec *codec)
3074 3621
3075 snd_hda_sequence_write(codec, spec->init); 3622 snd_hda_sequence_write(codec, spec->init);
3076 3623
3624 /* power down adcs initially */
3625 if (spec->powerdown_adcs)
3626 for (i = 0; i < spec->num_adcs; i++)
3627 snd_hda_codec_write_cache(codec,
3628 spec->adc_nids[i], 0,
3629 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3077 /* set up pins */ 3630 /* set up pins */
3078 if (spec->hp_detect) { 3631 if (spec->hp_detect) {
3079 /* Enable unsolicited responses on the HP widget */ 3632 /* Enable unsolicited responses on the HP widget */
@@ -3095,7 +3648,12 @@ static int stac92xx_init(struct hda_codec *codec)
3095 for (i = 0; i < AUTO_PIN_LAST; i++) { 3648 for (i = 0; i < AUTO_PIN_LAST; i++) {
3096 hda_nid_t nid = cfg->input_pins[i]; 3649 hda_nid_t nid = cfg->input_pins[i];
3097 if (nid) { 3650 if (nid) {
3098 unsigned int pinctl = AC_PINCTL_IN_EN; 3651 unsigned int pinctl = snd_hda_codec_read(codec, nid,
3652 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3653 /* if PINCTL already set then skip */
3654 if (pinctl & AC_PINCAP_IN)
3655 continue;
3656 pinctl = AC_PINCTL_IN_EN;
3099 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) 3657 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
3100 pinctl |= stac92xx_get_vref(codec, nid); 3658 pinctl |= stac92xx_get_vref(codec, nid);
3101 stac92xx_auto_set_pinctl(codec, nid, pinctl); 3659 stac92xx_auto_set_pinctl(codec, nid, pinctl);
@@ -3158,6 +3716,7 @@ static void stac92xx_free(struct hda_codec *codec)
3158 kfree(spec->bios_pin_configs); 3716 kfree(spec->bios_pin_configs);
3159 3717
3160 kfree(spec); 3718 kfree(spec);
3719 snd_hda_detach_beep_device(codec);
3161} 3720}
3162 3721
3163static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, 3722static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
@@ -3279,7 +3838,12 @@ static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
3279 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) 3838 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0)
3280 & 0x000000ff; 3839 & 0x000000ff;
3281 presence = get_hp_pin_presence(codec, nid); 3840 presence = get_hp_pin_presence(codec, nid);
3282 idx = 1 << idx; 3841
3842 /* several codecs have two power down bits */
3843 if (spec->pwr_mapping)
3844 idx = spec->pwr_mapping[idx];
3845 else
3846 idx = 1 << idx;
3283 3847
3284 if (presence) 3848 if (presence)
3285 val &= ~idx; 3849 val &= ~idx;
@@ -3295,13 +3859,22 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
3295 struct sigmatel_spec *spec = codec->spec; 3859 struct sigmatel_spec *spec = codec->spec;
3296 int idx = res >> 26 & 0x0f; 3860 int idx = res >> 26 & 0x0f;
3297 3861
3298 switch ((res >> 26) & 0x30) { 3862 switch ((res >> 26) & 0x70) {
3299 case STAC_HP_EVENT: 3863 case STAC_HP_EVENT:
3300 stac92xx_hp_detect(codec, res); 3864 stac92xx_hp_detect(codec, res);
3301 /* fallthru */ 3865 /* fallthru */
3302 case STAC_PWR_EVENT: 3866 case STAC_PWR_EVENT:
3303 if (spec->num_pwrs > 0) 3867 if (spec->num_pwrs > 0)
3304 stac92xx_pin_sense(codec, idx); 3868 stac92xx_pin_sense(codec, idx);
3869 break;
3870 case STAC_VREF_EVENT: {
3871 int data = snd_hda_codec_read(codec, codec->afg, 0,
3872 AC_VERB_GET_GPIO_DATA, 0);
3873 /* toggle VREF state based on GPIOx status */
3874 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
3875 !!(data & (1 << idx)));
3876 break;
3877 }
3305 } 3878 }
3306} 3879}
3307 3880
@@ -3478,9 +4051,9 @@ static struct hda_input_mux stac92hd73xx_dmux = {
3478 .num_items = 4, 4051 .num_items = 4,
3479 .items = { 4052 .items = {
3480 { "Analog Inputs", 0x0b }, 4053 { "Analog Inputs", 0x0b },
3481 { "CD", 0x08 },
3482 { "Digital Mic 1", 0x09 }, 4054 { "Digital Mic 1", 0x09 },
3483 { "Digital Mic 2", 0x0a }, 4055 { "Digital Mic 2", 0x0a },
4056 { "CD", 0x08 },
3484 } 4057 }
3485}; 4058};
3486 4059
@@ -3495,6 +4068,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
3495 return -ENOMEM; 4068 return -ENOMEM;
3496 4069
3497 codec->spec = spec; 4070 codec->spec = spec;
4071 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
3498 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids); 4072 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
3499 spec->pin_nids = stac92hd73xx_pin_nids; 4073 spec->pin_nids = stac92hd73xx_pin_nids;
3500 spec->board_config = snd_hda_check_board_config(codec, 4074 spec->board_config = snd_hda_check_board_config(codec,
@@ -3527,17 +4101,14 @@ again:
3527 4101
3528 switch (spec->multiout.num_dacs) { 4102 switch (spec->multiout.num_dacs) {
3529 case 0x3: /* 6 Channel */ 4103 case 0x3: /* 6 Channel */
3530 spec->multiout.hp_nid = 0x17;
3531 spec->mixer = stac92hd73xx_6ch_mixer; 4104 spec->mixer = stac92hd73xx_6ch_mixer;
3532 spec->init = stac92hd73xx_6ch_core_init; 4105 spec->init = stac92hd73xx_6ch_core_init;
3533 break; 4106 break;
3534 case 0x4: /* 8 Channel */ 4107 case 0x4: /* 8 Channel */
3535 spec->multiout.hp_nid = 0x18;
3536 spec->mixer = stac92hd73xx_8ch_mixer; 4108 spec->mixer = stac92hd73xx_8ch_mixer;
3537 spec->init = stac92hd73xx_8ch_core_init; 4109 spec->init = stac92hd73xx_8ch_core_init;
3538 break; 4110 break;
3539 case 0x5: /* 10 Channel */ 4111 case 0x5: /* 10 Channel */
3540 spec->multiout.hp_nid = 0x19;
3541 spec->mixer = stac92hd73xx_10ch_mixer; 4112 spec->mixer = stac92hd73xx_10ch_mixer;
3542 spec->init = stac92hd73xx_10ch_core_init; 4113 spec->init = stac92hd73xx_10ch_core_init;
3543 }; 4114 };
@@ -3546,27 +4117,34 @@ again:
3546 spec->aloopback_mask = 0x01; 4117 spec->aloopback_mask = 0x01;
3547 spec->aloopback_shift = 8; 4118 spec->aloopback_shift = 8;
3548 4119
4120 spec->digbeep_nid = 0x1c;
3549 spec->mux_nids = stac92hd73xx_mux_nids; 4121 spec->mux_nids = stac92hd73xx_mux_nids;
3550 spec->adc_nids = stac92hd73xx_adc_nids; 4122 spec->adc_nids = stac92hd73xx_adc_nids;
3551 spec->dmic_nids = stac92hd73xx_dmic_nids; 4123 spec->dmic_nids = stac92hd73xx_dmic_nids;
3552 spec->dmux_nids = stac92hd73xx_dmux_nids; 4124 spec->dmux_nids = stac92hd73xx_dmux_nids;
4125 spec->smux_nids = stac92hd73xx_smux_nids;
4126 spec->amp_nids = stac92hd73xx_amp_nids;
4127 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
3553 4128
3554 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids); 4129 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3555 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids); 4130 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3556 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 4131 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
3557 spec->dinput_mux = &stac92hd73xx_dmux; 4132 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
3558 /* GPIO0 High = Enable EAPD */ 4133 sizeof(stac92hd73xx_dmux));
3559 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3560 spec->gpio_data = 0x01;
3561 4134
3562 switch (spec->board_config) { 4135 switch (spec->board_config) {
3563 case STAC_DELL_M6: 4136 case STAC_DELL_M6:
3564 spec->init = dell_eq_core_init; 4137 spec->init = dell_eq_core_init;
4138 spec->num_smuxes = 0;
4139 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4140 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
4141 spec->num_amps = 1;
3565 switch (codec->subsystem_id) { 4142 switch (codec->subsystem_id) {
3566 case 0x1028025e: /* Analog Mics */ 4143 case 0x1028025e: /* Analog Mics */
3567 case 0x1028025f: 4144 case 0x1028025f:
3568 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170); 4145 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3569 spec->num_dmics = 0; 4146 spec->num_dmics = 0;
4147 spec->private_dimux.num_items = 1;
3570 break; 4148 break;
3571 case 0x10280271: /* Digital Mics */ 4149 case 0x10280271: /* Digital Mics */
3572 case 0x10280272: 4150 case 0x10280272:
@@ -3576,23 +4154,32 @@ again:
3576 case 0x10280255: 4154 case 0x10280255:
3577 stac92xx_set_config_reg(codec, 0x13, 0x90A60160); 4155 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3578 spec->num_dmics = 1; 4156 spec->num_dmics = 1;
4157 spec->private_dimux.num_items = 2;
3579 break; 4158 break;
3580 case 0x10280256: /* Both */ 4159 case 0x10280256: /* Both */
3581 case 0x10280057: 4160 case 0x10280057:
3582 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170); 4161 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3583 stac92xx_set_config_reg(codec, 0x13, 0x90A60160); 4162 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3584 spec->num_dmics = 1; 4163 spec->num_dmics = 1;
4164 spec->private_dimux.num_items = 2;
3585 break; 4165 break;
3586 } 4166 }
3587 break; 4167 break;
3588 default: 4168 default:
3589 spec->num_dmics = STAC92HD73XX_NUM_DMICS; 4169 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
4170 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
3590 } 4171 }
4172 if (spec->board_config > STAC_92HD73XX_REF) {
4173 /* GPIO0 High = Enable EAPD */
4174 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4175 spec->gpio_data = 0x01;
4176 }
4177 spec->dinput_mux = &spec->private_dimux;
3591 4178
3592 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 4179 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3593 spec->pwr_nids = stac92hd73xx_pwr_nids; 4180 spec->pwr_nids = stac92hd73xx_pwr_nids;
3594 4181
3595 err = stac92xx_parse_auto_config(codec, 0x22, 0x24); 4182 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
3596 4183
3597 if (!err) { 4184 if (!err) {
3598 if (spec->board_config < 0) { 4185 if (spec->board_config < 0) {
@@ -3614,6 +4201,146 @@ again:
3614 return 0; 4201 return 0;
3615} 4202}
3616 4203
4204static struct hda_input_mux stac92hd83xxx_dmux = {
4205 .num_items = 3,
4206 .items = {
4207 { "Analog Inputs", 0x03 },
4208 { "Digital Mic 1", 0x04 },
4209 { "Digital Mic 2", 0x05 },
4210 }
4211};
4212
4213static int patch_stac92hd83xxx(struct hda_codec *codec)
4214{
4215 struct sigmatel_spec *spec;
4216 int err;
4217
4218 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4219 if (spec == NULL)
4220 return -ENOMEM;
4221
4222 codec->spec = spec;
4223 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
4224 spec->mono_nid = 0x19;
4225 spec->digbeep_nid = 0x21;
4226 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4227 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4228 spec->adc_nids = stac92hd83xxx_adc_nids;
4229 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4230 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4231 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4232 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4233
4234 spec->init = stac92hd83xxx_core_init;
4235 switch (codec->vendor_id) {
4236 case 0x111d7605:
4237 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4238 break;
4239 default:
4240 spec->num_pwrs--;
4241 spec->init++; /* switch to config #2 */
4242 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4243 }
4244
4245 spec->mixer = stac92hd83xxx_mixer;
4246 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4247 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4248 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4249 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4250 spec->dinput_mux = &stac92hd83xxx_dmux;
4251 spec->pin_nids = stac92hd83xxx_pin_nids;
4252 spec->board_config = snd_hda_check_board_config(codec,
4253 STAC_92HD83XXX_MODELS,
4254 stac92hd83xxx_models,
4255 stac92hd83xxx_cfg_tbl);
4256again:
4257 if (spec->board_config < 0) {
4258 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4259 " STAC92HD83XXX, using BIOS defaults\n");
4260 err = stac92xx_save_bios_config_regs(codec);
4261 if (err < 0) {
4262 stac92xx_free(codec);
4263 return err;
4264 }
4265 spec->pin_configs = spec->bios_pin_configs;
4266 } else {
4267 spec->pin_configs = stac92hd83xxx_brd_tbl[spec->board_config];
4268 stac92xx_set_config_regs(codec);
4269 }
4270
4271 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4272 if (!err) {
4273 if (spec->board_config < 0) {
4274 printk(KERN_WARNING "hda_codec: No auto-config is "
4275 "available, default to model=ref\n");
4276 spec->board_config = STAC_92HD83XXX_REF;
4277 goto again;
4278 }
4279 err = -EINVAL;
4280 }
4281
4282 if (err < 0) {
4283 stac92xx_free(codec);
4284 return err;
4285 }
4286
4287 codec->patch_ops = stac92xx_patch_ops;
4288
4289 return 0;
4290}
4291
4292#ifdef SND_HDA_NEEDS_RESUME
4293static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4294{
4295 struct sigmatel_spec *spec = codec->spec;
4296 int i;
4297 snd_hda_codec_write_cache(codec, codec->afg, 0,
4298 AC_VERB_SET_POWER_STATE, pwr);
4299
4300 msleep(1);
4301 for (i = 0; i < spec->num_adcs; i++) {
4302 snd_hda_codec_write_cache(codec,
4303 spec->adc_nids[i], 0,
4304 AC_VERB_SET_POWER_STATE, pwr);
4305 }
4306};
4307
4308static int stac92hd71xx_resume(struct hda_codec *codec)
4309{
4310 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4311 return stac92xx_resume(codec);
4312}
4313
4314static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4315{
4316 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
4317 return 0;
4318};
4319
4320#endif
4321
4322static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4323 .build_controls = stac92xx_build_controls,
4324 .build_pcms = stac92xx_build_pcms,
4325 .init = stac92xx_init,
4326 .free = stac92xx_free,
4327 .unsol_event = stac92xx_unsol_event,
4328#ifdef SND_HDA_NEEDS_RESUME
4329 .resume = stac92hd71xx_resume,
4330 .suspend = stac92hd71xx_suspend,
4331#endif
4332};
4333
4334static struct hda_input_mux stac92hd71bxx_dmux = {
4335 .num_items = 4,
4336 .items = {
4337 { "Analog Inputs", 0x00 },
4338 { "Mixer", 0x01 },
4339 { "Digital Mic 1", 0x02 },
4340 { "Digital Mic 2", 0x03 },
4341 }
4342};
4343
3617static int patch_stac92hd71bxx(struct hda_codec *codec) 4344static int patch_stac92hd71bxx(struct hda_codec *codec)
3618{ 4345{
3619 struct sigmatel_spec *spec; 4346 struct sigmatel_spec *spec;
@@ -3624,9 +4351,12 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
3624 return -ENOMEM; 4351 return -ENOMEM;
3625 4352
3626 codec->spec = spec; 4353 codec->spec = spec;
4354 codec->patch_ops = stac92xx_patch_ops;
3627 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids); 4355 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
3628 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids); 4356 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
3629 spec->pin_nids = stac92hd71bxx_pin_nids; 4357 spec->pin_nids = stac92hd71bxx_pin_nids;
4358 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4359 sizeof(stac92hd71bxx_dmux));
3630 spec->board_config = snd_hda_check_board_config(codec, 4360 spec->board_config = snd_hda_check_board_config(codec,
3631 STAC_92HD71BXX_MODELS, 4361 STAC_92HD71BXX_MODELS,
3632 stac92hd71bxx_models, 4362 stac92hd71bxx_models,
@@ -3653,47 +4383,101 @@ again:
3653 case 0x111d76b5: 4383 case 0x111d76b5:
3654 spec->mixer = stac92hd71bxx_mixer; 4384 spec->mixer = stac92hd71bxx_mixer;
3655 spec->init = stac92hd71bxx_core_init; 4385 spec->init = stac92hd71bxx_core_init;
4386 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
3656 break; 4387 break;
3657 case 0x111d7608: /* 5 Port with Analog Mixer */ 4388 case 0x111d7608: /* 5 Port with Analog Mixer */
4389 switch (codec->subsystem_id) {
4390 case 0x103c361a:
4391 /* Enable VREF power saving on GPIO1 detect */
4392 snd_hda_codec_write(codec, codec->afg, 0,
4393 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4394 snd_hda_codec_write_cache(codec, codec->afg, 0,
4395 AC_VERB_SET_UNSOLICITED_ENABLE,
4396 (AC_USRSP_EN | STAC_VREF_EVENT | 0x01));
4397 spec->gpio_mask |= 0x02;
4398 break;
4399 }
4400 if ((codec->revision_id & 0xf) == 0 ||
4401 (codec->revision_id & 0xf) == 1) {
4402#ifdef SND_HDA_NEEDS_RESUME
4403 codec->patch_ops = stac92hd71bxx_patch_ops;
4404#endif
4405 spec->stream_delay = 40; /* 40 milliseconds */
4406 }
4407
3658 /* no output amps */ 4408 /* no output amps */
3659 spec->num_pwrs = 0; 4409 spec->num_pwrs = 0;
3660 spec->mixer = stac92hd71bxx_analog_mixer; 4410 spec->mixer = stac92hd71bxx_analog_mixer;
4411 spec->dinput_mux = &spec->private_dimux;
3661 4412
3662 /* disable VSW */ 4413 /* disable VSW */
3663 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF]; 4414 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
3664 stac92xx_set_config_reg(codec, 0xf, 0x40f000f0); 4415 stac92xx_set_config_reg(codec, 0xf, 0x40f000f0);
3665 break; 4416 break;
3666 case 0x111d7603: /* 6 Port with Analog Mixer */ 4417 case 0x111d7603: /* 6 Port with Analog Mixer */
4418 if ((codec->revision_id & 0xf) == 1) {
4419#ifdef SND_HDA_NEEDS_RESUME
4420 codec->patch_ops = stac92hd71bxx_patch_ops;
4421#endif
4422 spec->stream_delay = 40; /* 40 milliseconds */
4423 }
4424
3667 /* no output amps */ 4425 /* no output amps */
3668 spec->num_pwrs = 0; 4426 spec->num_pwrs = 0;
3669 /* fallthru */ 4427 /* fallthru */
3670 default: 4428 default:
4429 spec->dinput_mux = &spec->private_dimux;
3671 spec->mixer = stac92hd71bxx_analog_mixer; 4430 spec->mixer = stac92hd71bxx_analog_mixer;
3672 spec->init = stac92hd71bxx_analog_core_init; 4431 spec->init = stac92hd71bxx_analog_core_init;
4432 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
3673 } 4433 }
3674 4434
3675 spec->aloopback_mask = 0x20; 4435 spec->aloopback_mask = 0x50;
3676 spec->aloopback_shift = 0; 4436 spec->aloopback_shift = 0;
3677 4437
3678 /* GPIO0 High = EAPD */ 4438 if (spec->board_config > STAC_92HD71BXX_REF) {
3679 spec->gpio_mask = 0x01; 4439 /* GPIO0 = EAPD */
3680 spec->gpio_dir = 0x01; 4440 spec->gpio_mask = 0x01;
3681 spec->gpio_data = 0x01; 4441 spec->gpio_dir = 0x01;
4442 spec->gpio_data = 0x01;
4443 }
3682 4444
4445 spec->powerdown_adcs = 1;
4446 spec->digbeep_nid = 0x26;
3683 spec->mux_nids = stac92hd71bxx_mux_nids; 4447 spec->mux_nids = stac92hd71bxx_mux_nids;
3684 spec->adc_nids = stac92hd71bxx_adc_nids; 4448 spec->adc_nids = stac92hd71bxx_adc_nids;
3685 spec->dmic_nids = stac92hd71bxx_dmic_nids; 4449 spec->dmic_nids = stac92hd71bxx_dmic_nids;
3686 spec->dmux_nids = stac92hd71bxx_dmux_nids; 4450 spec->dmux_nids = stac92hd71bxx_dmux_nids;
4451 spec->smux_nids = stac92hd71bxx_smux_nids;
3687 spec->pwr_nids = stac92hd71bxx_pwr_nids; 4452 spec->pwr_nids = stac92hd71bxx_pwr_nids;
3688 4453
3689 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids); 4454 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
3690 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids); 4455 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
3691 spec->num_dmics = STAC92HD71BXX_NUM_DMICS; 4456
3692 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 4457 switch (spec->board_config) {
4458 case STAC_HP_M4:
4459 spec->num_dmics = 0;
4460 spec->num_smuxes = 0;
4461 spec->num_dmuxes = 0;
4462
4463 /* enable internal microphone */
4464 stac92xx_set_config_reg(codec, 0x0e, 0x01813040);
4465 stac92xx_auto_set_pinctl(codec, 0x0e,
4466 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
4467 break;
4468 default:
4469 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4470 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4471 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4472 };
3693 4473
3694 spec->multiout.num_dacs = 1; 4474 spec->multiout.num_dacs = 1;
3695 spec->multiout.hp_nid = 0x11; 4475 spec->multiout.hp_nid = 0x11;
3696 spec->multiout.dac_nids = stac92hd71bxx_dac_nids; 4476 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
4477 if (spec->dinput_mux)
4478 spec->private_dimux.num_items +=
4479 spec->num_dmics -
4480 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
3697 4481
3698 err = stac92xx_parse_auto_config(codec, 0x21, 0x23); 4482 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
3699 if (!err) { 4483 if (!err) {
@@ -3711,8 +4495,6 @@ again:
3711 return err; 4495 return err;
3712 } 4496 }
3713 4497
3714 codec->patch_ops = stac92xx_patch_ops;
3715
3716 return 0; 4498 return 0;
3717}; 4499};
3718 4500
@@ -3854,10 +4636,14 @@ static int patch_stac927x(struct hda_codec *codec)
3854 stac92xx_set_config_regs(codec); 4636 stac92xx_set_config_regs(codec);
3855 } 4637 }
3856 4638
4639 spec->digbeep_nid = 0x23;
3857 spec->adc_nids = stac927x_adc_nids; 4640 spec->adc_nids = stac927x_adc_nids;
3858 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); 4641 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3859 spec->mux_nids = stac927x_mux_nids; 4642 spec->mux_nids = stac927x_mux_nids;
3860 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); 4643 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
4644 spec->smux_nids = stac927x_smux_nids;
4645 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
4646 spec->spdif_labels = stac927x_spdif_labels;
3861 spec->dac_list = stac927x_dac_nids; 4647 spec->dac_list = stac927x_dac_nids;
3862 spec->multiout.dac_nids = spec->dac_nids; 4648 spec->multiout.dac_nids = spec->dac_nids;
3863 4649
@@ -3900,9 +4686,11 @@ static int patch_stac927x(struct hda_codec *codec)
3900 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids); 4686 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
3901 break; 4687 break;
3902 default: 4688 default:
3903 /* GPIO0 High = Enable EAPD */ 4689 if (spec->board_config > STAC_D965_REF) {
3904 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1; 4690 /* GPIO0 High = Enable EAPD */
3905 spec->gpio_data = 0x01; 4691 spec->eapd_mask = spec->gpio_mask = 0x01;
4692 spec->gpio_dir = spec->gpio_data = 0x01;
4693 }
3906 spec->num_dmics = 0; 4694 spec->num_dmics = 0;
3907 4695
3908 spec->init = stac927x_core_init; 4696 spec->init = stac927x_core_init;
@@ -3974,10 +4762,13 @@ static int patch_stac9205(struct hda_codec *codec)
3974 stac92xx_set_config_regs(codec); 4762 stac92xx_set_config_regs(codec);
3975 } 4763 }
3976 4764
4765 spec->digbeep_nid = 0x23;
3977 spec->adc_nids = stac9205_adc_nids; 4766 spec->adc_nids = stac9205_adc_nids;
3978 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids); 4767 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
3979 spec->mux_nids = stac9205_mux_nids; 4768 spec->mux_nids = stac9205_mux_nids;
3980 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids); 4769 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
4770 spec->smux_nids = stac9205_smux_nids;
4771 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
3981 spec->dmic_nids = stac9205_dmic_nids; 4772 spec->dmic_nids = stac9205_dmic_nids;
3982 spec->num_dmics = STAC9205_NUM_DMICS; 4773 spec->num_dmics = STAC9205_NUM_DMICS;
3983 spec->dmux_nids = stac9205_dmux_nids; 4774 spec->dmux_nids = stac9205_dmux_nids;
@@ -4013,6 +4804,9 @@ static int patch_stac9205(struct hda_codec *codec)
4013 */ 4804 */
4014 spec->gpio_data = 0x01; 4805 spec->gpio_data = 0x01;
4015 break; 4806 break;
4807 case STAC_9205_REF:
4808 /* SPDIF-In enabled */
4809 break;
4016 default: 4810 default:
4017 /* GPIO0 High = EAPD */ 4811 /* GPIO0 High = EAPD */
4018 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1; 4812 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
@@ -4332,6 +5126,8 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = {
4332 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 }, 5126 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
4333 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 }, 5127 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
4334 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx}, 5128 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
5129 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5130 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
4335 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx}, 5131 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
4336 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx }, 5132 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
4337 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx }, 5133 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index e7e43524f8c7..63e4871e5d8f 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * Universal Interface for Intel High Definition Audio Codec 2 * Universal Interface for Intel High Definition Audio Codec
3 * 3 *
4 * HD audio interface patch for VIA VT1708 codec 4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
5 * 5 *
6 * Copyright (c) 2006 Lydia Wang <lydiawang@viatech.com> 6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * Takashi Iwai <tiwai@suse.de> 7 * Takashi Iwai <tiwai@suse.de>
8 * 8 *
9 * This driver is free software; you can redistribute it and/or modify 9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -29,6 +29,13 @@
29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ 29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ 30/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */ 31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
32/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */
37/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
32/* */ 39/* */
33/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 40/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34 41
@@ -37,6 +44,7 @@
37#include <linux/delay.h> 44#include <linux/delay.h>
38#include <linux/slab.h> 45#include <linux/slab.h>
39#include <sound/core.h> 46#include <sound/core.h>
47#include <sound/asoundef.h>
40#include "hda_codec.h" 48#include "hda_codec.h"
41#include "hda_local.h" 49#include "hda_local.h"
42#include "hda_patch.h" 50#include "hda_patch.h"
@@ -53,6 +61,8 @@
53#define VT1708_DIGOUT_NID 0x14 61#define VT1708_DIGOUT_NID 0x14
54#define VT1708_DIGIN_NID 0x16 62#define VT1708_DIGIN_NID 0x16
55#define VT1708_DIGIN_PIN 0x26 63#define VT1708_DIGIN_PIN 0x26
64#define VT1708_HP_PIN_NID 0x20
65#define VT1708_CD_PIN_NID 0x24
56 66
57#define VT1709_HP_DAC_NID 0x28 67#define VT1709_HP_DAC_NID 0x28
58#define VT1709_DIGOUT_NID 0x13 68#define VT1709_DIGOUT_NID 0x13
@@ -64,12 +74,64 @@
64#define VT1708B_DIGIN_NID 0x15 74#define VT1708B_DIGIN_NID 0x15
65#define VT1708B_DIGIN_PIN 0x21 75#define VT1708B_DIGIN_PIN 0x21
66 76
77#define VT1708S_HP_NID 0x25
78#define VT1708S_DIGOUT_NID 0x12
79
80#define VT1702_HP_NID 0x17
81#define VT1702_DIGOUT_NID 0x11
82
67#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b) 83#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
68#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713) 84#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
69#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717) 85#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
70#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723) 86#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
71#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727) 87#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
88#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
89#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
90
91enum VIA_HDA_CODEC {
92 UNKNOWN = -1,
93 VT1708,
94 VT1709_10CH,
95 VT1709_6CH,
96 VT1708B_8CH,
97 VT1708B_4CH,
98 VT1708S,
99 VT1702,
100 CODEC_TYPES,
101};
102
103static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
104{
105 u16 ven_id = vendor_id >> 16;
106 u16 dev_id = vendor_id & 0xffff;
107 enum VIA_HDA_CODEC codec_type;
108
109 /* get codec type */
110 if (ven_id != 0x1106)
111 codec_type = UNKNOWN;
112 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
113 codec_type = VT1708;
114 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
115 codec_type = VT1709_10CH;
116 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
117 codec_type = VT1709_6CH;
118 else if (dev_id >= 0xe720 && dev_id <= 0xe723)
119 codec_type = VT1708B_8CH;
120 else if (dev_id >= 0xe724 && dev_id <= 0xe727)
121 codec_type = VT1708B_4CH;
122 else if ((dev_id & 0xfff) == 0x397
123 && (dev_id >> 12) < 8)
124 codec_type = VT1708S;
125 else if ((dev_id & 0xfff) == 0x398
126 && (dev_id >> 12) < 8)
127 codec_type = VT1702;
128 else
129 codec_type = UNKNOWN;
130 return codec_type;
131};
72 132
133#define VIA_HP_EVENT 0x01
134#define VIA_GPIO_EVENT 0x02
73 135
74enum { 136enum {
75 VIA_CTL_WIDGET_VOL, 137 VIA_CTL_WIDGET_VOL,
@@ -77,12 +139,54 @@ enum {
77}; 139};
78 140
79enum { 141enum {
80 AUTO_SEQ_FRONT, 142 AUTO_SEQ_FRONT = 0,
81 AUTO_SEQ_SURROUND, 143 AUTO_SEQ_SURROUND,
82 AUTO_SEQ_CENLFE, 144 AUTO_SEQ_CENLFE,
83 AUTO_SEQ_SIDE 145 AUTO_SEQ_SIDE
84}; 146};
85 147
148#define get_amp_nid(kc) ((kc)->private_value & 0xffff)
149
150/* Some VT1708S based boards gets the micboost setting wrong, so we have
151 * to apply some brute-force and re-write the TLV's by software. */
152static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
153 unsigned int size, unsigned int __user *_tlv)
154{
155 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
156 hda_nid_t nid = get_amp_nid(kcontrol);
157
158 if (get_codec_type(codec->vendor_id) == VT1708S
159 && (nid == 0x1a || nid == 0x1e)) {
160 if (size < 4 * sizeof(unsigned int))
161 return -ENOMEM;
162 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
163 return -EFAULT;
164 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
165 return -EFAULT;
166 if (put_user(0, _tlv + 2)) /* offset = 0 */
167 return -EFAULT;
168 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
169 return -EFAULT;
170 }
171 return 0;
172}
173
174static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
175 struct snd_ctl_elem_info *uinfo)
176{
177 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
178 hda_nid_t nid = get_amp_nid(kcontrol);
179
180 if (get_codec_type(codec->vendor_id) == VT1708S
181 && (nid == 0x1a || nid == 0x1e)) {
182 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
183 uinfo->count = 2;
184 uinfo->value.integer.min = 0;
185 uinfo->value.integer.max = 3;
186 }
187 return 0;
188}
189
86static struct snd_kcontrol_new vt1708_control_templates[] = { 190static struct snd_kcontrol_new vt1708_control_templates[] = {
87 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 191 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
88 HDA_CODEC_MUTE(NULL, 0, 0, 0), 192 HDA_CODEC_MUTE(NULL, 0, 0, 0),
@@ -94,7 +198,8 @@ struct via_spec {
94 struct snd_kcontrol_new *mixers[3]; 198 struct snd_kcontrol_new *mixers[3];
95 unsigned int num_mixers; 199 unsigned int num_mixers;
96 200
97 struct hda_verb *init_verbs; 201 struct hda_verb *init_verbs[5];
202 unsigned int num_iverbs;
98 203
99 char *stream_name_analog; 204 char *stream_name_analog;
100 struct hda_pcm_stream *stream_analog_playback; 205 struct hda_pcm_stream *stream_analog_playback;
@@ -106,6 +211,7 @@ struct via_spec {
106 211
107 /* playback */ 212 /* playback */
108 struct hda_multi_out multiout; 213 struct hda_multi_out multiout;
214 hda_nid_t extra_dig_out_nid;
109 215
110 /* capture */ 216 /* capture */
111 unsigned int num_adc_nids; 217 unsigned int num_adc_nids;
@@ -117,15 +223,19 @@ struct via_spec {
117 unsigned int cur_mux[3]; 223 unsigned int cur_mux[3];
118 224
119 /* PCM information */ 225 /* PCM information */
120 struct hda_pcm pcm_rec[2]; 226 struct hda_pcm pcm_rec[3];
121 227
122 /* dynamic controls, init_verbs and input_mux */ 228 /* dynamic controls, init_verbs and input_mux */
123 struct auto_pin_cfg autocfg; 229 struct auto_pin_cfg autocfg;
124 unsigned int num_kctl_alloc, num_kctl_used; 230 unsigned int num_kctl_alloc, num_kctl_used;
125 struct snd_kcontrol_new *kctl_alloc; 231 struct snd_kcontrol_new *kctl_alloc;
126 struct hda_input_mux private_imux; 232 struct hda_input_mux private_imux[2];
127 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 233 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
128 234
235 /* HP mode source */
236 const struct hda_input_mux *hp_mux;
237 unsigned int hp_independent_mode;
238
129#ifdef CONFIG_SND_HDA_POWER_SAVE 239#ifdef CONFIG_SND_HDA_POWER_SAVE
130 struct hda_loopback_check loopback; 240 struct hda_loopback_check loopback;
131#endif 241#endif
@@ -146,6 +256,16 @@ static hda_nid_t vt1708B_adc_nids[2] = {
146 0x13, 0x14 256 0x13, 0x14
147}; 257};
148 258
259static hda_nid_t vt1708S_adc_nids[2] = {
260 /* ADC1-2 */
261 0x13, 0x14
262};
263
264static hda_nid_t vt1702_adc_nids[3] = {
265 /* ADC1-2 */
266 0x12, 0x20, 0x1F
267};
268
149/* add dynamic controls */ 269/* add dynamic controls */
150static int via_add_control(struct via_spec *spec, int type, const char *name, 270static int via_add_control(struct via_spec *spec, int type, const char *name,
151 unsigned long val) 271 unsigned long val)
@@ -283,19 +403,108 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
283 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 403 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
284 0x18, &spec->cur_mux[adc_idx]); 404 0x18, &spec->cur_mux[adc_idx]);
285 else if ((IS_VT1709_10CH_VENDORID(vendor_id) || 405 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
286 IS_VT1709_6CH_VENDORID(vendor_id)) && adc_idx == 0) 406 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
287 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 407 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
288 0x19, &spec->cur_mux[adc_idx]); 408 0x19, &spec->cur_mux[adc_idx]);
289 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) || 409 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
290 IS_VT1708B_4CH_VENDORID(vendor_id)) && adc_idx == 0) 410 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
291 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 411 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
292 0x17, &spec->cur_mux[adc_idx]); 412 0x17, &spec->cur_mux[adc_idx]);
413 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
414 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
415 0x13, &spec->cur_mux[adc_idx]);
293 else 416 else
294 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 417 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
295 spec->adc_nids[adc_idx], 418 spec->adc_nids[adc_idx],
296 &spec->cur_mux[adc_idx]); 419 &spec->cur_mux[adc_idx]);
297} 420}
298 421
422static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
423 struct snd_ctl_elem_info *uinfo)
424{
425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
426 struct via_spec *spec = codec->spec;
427 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
428}
429
430static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
431 struct snd_ctl_elem_value *ucontrol)
432{
433 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
434 struct via_spec *spec = codec->spec;
435 hda_nid_t nid = spec->autocfg.hp_pins[0];
436 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
437 AC_VERB_GET_CONNECT_SEL,
438 0x00);
439
440 ucontrol->value.enumerated.item[0] = pinsel;
441
442 return 0;
443}
444
445static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
446 struct snd_ctl_elem_value *ucontrol)
447{
448 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
449 struct via_spec *spec = codec->spec;
450 hda_nid_t nid = spec->autocfg.hp_pins[0];
451 unsigned int pinsel = ucontrol->value.enumerated.item[0];
452 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
453 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
454
455 if (con_nid == spec->multiout.hp_nid) {
456 if (pinsel == 0) {
457 if (!spec->hp_independent_mode) {
458 if (spec->multiout.num_dacs > 1)
459 spec->multiout.num_dacs -= 1;
460 spec->hp_independent_mode = 1;
461 }
462 } else if (pinsel == 1) {
463 if (spec->hp_independent_mode) {
464 if (spec->multiout.num_dacs > 1)
465 spec->multiout.num_dacs += 1;
466 spec->hp_independent_mode = 0;
467 }
468 }
469 } else {
470 if (pinsel == 0) {
471 if (spec->hp_independent_mode) {
472 if (spec->multiout.num_dacs > 1)
473 spec->multiout.num_dacs += 1;
474 spec->hp_independent_mode = 0;
475 }
476 } else if (pinsel == 1) {
477 if (!spec->hp_independent_mode) {
478 if (spec->multiout.num_dacs > 1)
479 spec->multiout.num_dacs -= 1;
480 spec->hp_independent_mode = 1;
481 }
482 }
483 }
484 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
485 pinsel);
486
487 if (spec->multiout.hp_nid &&
488 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
489 snd_hda_codec_setup_stream(codec,
490 spec->multiout.hp_nid,
491 0, 0, 0);
492
493 return 0;
494}
495
496static struct snd_kcontrol_new via_hp_mixer[] = {
497 {
498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
499 .name = "Independent HP",
500 .count = 1,
501 .info = via_independent_hp_info,
502 .get = via_independent_hp_get,
503 .put = via_independent_hp_put,
504 },
505 { } /* end */
506};
507
299/* capture mixer elements */ 508/* capture mixer elements */
300static struct snd_kcontrol_new vt1708_capture_mixer[] = { 509static struct snd_kcontrol_new vt1708_capture_mixer[] = {
301 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), 510 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
@@ -380,6 +589,138 @@ static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
380 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 589 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
381} 590}
382 591
592
593static void playback_multi_pcm_prep_0(struct hda_codec *codec,
594 unsigned int stream_tag,
595 unsigned int format,
596 struct snd_pcm_substream *substream)
597{
598 struct via_spec *spec = codec->spec;
599 struct hda_multi_out *mout = &spec->multiout;
600 hda_nid_t *nids = mout->dac_nids;
601 int chs = substream->runtime->channels;
602 int i;
603
604 mutex_lock(&codec->spdif_mutex);
605 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
606 if (chs == 2 &&
607 snd_hda_is_supported_format(codec, mout->dig_out_nid,
608 format) &&
609 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
610 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
611 /* turn off SPDIF once; otherwise the IEC958 bits won't
612 * be updated */
613 if (codec->spdif_ctls & AC_DIG1_ENABLE)
614 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
615 AC_VERB_SET_DIGI_CONVERT_1,
616 codec->spdif_ctls &
617 ~AC_DIG1_ENABLE & 0xff);
618 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
619 stream_tag, 0, format);
620 /* turn on again (if needed) */
621 if (codec->spdif_ctls & AC_DIG1_ENABLE)
622 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
623 AC_VERB_SET_DIGI_CONVERT_1,
624 codec->spdif_ctls & 0xff);
625 } else {
626 mout->dig_out_used = 0;
627 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
628 0, 0, 0);
629 }
630 }
631 mutex_unlock(&codec->spdif_mutex);
632
633 /* front */
634 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
635 0, format);
636
637 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
638 !spec->hp_independent_mode)
639 /* headphone out will just decode front left/right (stereo) */
640 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
641 0, format);
642
643 /* extra outputs copied from front */
644 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
645 if (mout->extra_out_nid[i])
646 snd_hda_codec_setup_stream(codec,
647 mout->extra_out_nid[i],
648 stream_tag, 0, format);
649
650 /* surrounds */
651 for (i = 1; i < mout->num_dacs; i++) {
652 if (chs >= (i + 1) * 2) /* independent out */
653 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
654 i * 2, format);
655 else /* copy front */
656 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
657 0, format);
658 }
659}
660
661static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
662 struct hda_codec *codec,
663 unsigned int stream_tag,
664 unsigned int format,
665 struct snd_pcm_substream *substream)
666{
667 struct via_spec *spec = codec->spec;
668 struct hda_multi_out *mout = &spec->multiout;
669 hda_nid_t *nids = mout->dac_nids;
670
671 if (substream->number == 0)
672 playback_multi_pcm_prep_0(codec, stream_tag, format,
673 substream);
674 else {
675 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
676 spec->hp_independent_mode)
677 snd_hda_codec_setup_stream(codec, mout->hp_nid,
678 stream_tag, 0, format);
679 }
680
681 return 0;
682}
683
684static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
685 struct hda_codec *codec,
686 struct snd_pcm_substream *substream)
687{
688 struct via_spec *spec = codec->spec;
689 struct hda_multi_out *mout = &spec->multiout;
690 hda_nid_t *nids = mout->dac_nids;
691 int i;
692
693 if (substream->number == 0) {
694 for (i = 0; i < mout->num_dacs; i++)
695 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
696
697 if (mout->hp_nid && !spec->hp_independent_mode)
698 snd_hda_codec_setup_stream(codec, mout->hp_nid,
699 0, 0, 0);
700
701 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
702 if (mout->extra_out_nid[i])
703 snd_hda_codec_setup_stream(codec,
704 mout->extra_out_nid[i],
705 0, 0, 0);
706 mutex_lock(&codec->spdif_mutex);
707 if (mout->dig_out_nid &&
708 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
709 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
710 0, 0, 0);
711 mout->dig_out_used = 0;
712 }
713 mutex_unlock(&codec->spdif_mutex);
714 } else {
715 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
716 spec->hp_independent_mode)
717 snd_hda_codec_setup_stream(codec, mout->hp_nid,
718 0, 0, 0);
719 }
720
721 return 0;
722}
723
383/* 724/*
384 * Digital out 725 * Digital out
385 */ 726 */
@@ -399,6 +740,21 @@ static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
399 return snd_hda_multi_out_dig_close(codec, &spec->multiout); 740 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
400} 741}
401 742
743/* setup SPDIF output stream */
744static void setup_dig_playback_stream(struct hda_codec *codec, hda_nid_t nid,
745 unsigned int stream_tag, unsigned int format)
746{
747 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
748 if (codec->spdif_ctls & AC_DIG1_ENABLE)
749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
750 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
751 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
752 /* turn on again (if needed) */
753 if (codec->spdif_ctls & AC_DIG1_ENABLE)
754 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
755 codec->spdif_ctls & 0xff);
756}
757
402static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 758static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
403 struct hda_codec *codec, 759 struct hda_codec *codec,
404 unsigned int stream_tag, 760 unsigned int stream_tag,
@@ -406,8 +762,20 @@ static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
406 struct snd_pcm_substream *substream) 762 struct snd_pcm_substream *substream)
407{ 763{
408 struct via_spec *spec = codec->spec; 764 struct via_spec *spec = codec->spec;
409 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 765 hda_nid_t nid;
410 stream_tag, format, substream); 766
767 /* 1st or 2nd S/PDIF */
768 if (substream->number == 0)
769 nid = spec->multiout.dig_out_nid;
770 else if (substream->number == 1)
771 nid = spec->extra_dig_out_nid;
772 else
773 return -1;
774
775 mutex_lock(&codec->spdif_mutex);
776 setup_dig_playback_stream(codec, nid, stream_tag, format);
777 mutex_unlock(&codec->spdif_mutex);
778 return 0;
411} 779}
412 780
413/* 781/*
@@ -436,14 +804,14 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
436} 804}
437 805
438static struct hda_pcm_stream vt1708_pcm_analog_playback = { 806static struct hda_pcm_stream vt1708_pcm_analog_playback = {
439 .substreams = 1, 807 .substreams = 2,
440 .channels_min = 2, 808 .channels_min = 2,
441 .channels_max = 8, 809 .channels_max = 8,
442 .nid = 0x10, /* NID to query formats and rates */ 810 .nid = 0x10, /* NID to query formats and rates */
443 .ops = { 811 .ops = {
444 .open = via_playback_pcm_open, 812 .open = via_playback_pcm_open,
445 .prepare = via_playback_pcm_prepare, 813 .prepare = via_playback_multi_pcm_prepare,
446 .cleanup = via_playback_pcm_cleanup 814 .cleanup = via_playback_multi_pcm_cleanup
447 }, 815 },
448}; 816};
449 817
@@ -515,6 +883,13 @@ static int via_build_controls(struct hda_codec *codec)
515 if (err < 0) 883 if (err < 0)
516 return err; 884 return err;
517 spec->multiout.share_spdif = 1; 885 spec->multiout.share_spdif = 1;
886
887 if (spec->extra_dig_out_nid) {
888 err = snd_hda_create_spdif_out_ctls(codec,
889 spec->extra_dig_out_nid);
890 if (err < 0)
891 return err;
892 }
518 } 893 }
519 if (spec->dig_in_nid) { 894 if (spec->dig_in_nid) {
520 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 895 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -580,10 +955,89 @@ static void via_free(struct hda_codec *codec)
580 kfree(codec->spec); 955 kfree(codec->spec);
581} 956}
582 957
958/* mute internal speaker if HP is plugged */
959static void via_hp_automute(struct hda_codec *codec)
960{
961 unsigned int present;
962 struct via_spec *spec = codec->spec;
963
964 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
965 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
966 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
967 HDA_OUTPUT, 0, HDA_AMP_MUTE,
968 present ? HDA_AMP_MUTE : 0);
969}
970
971static void via_gpio_control(struct hda_codec *codec)
972{
973 unsigned int gpio_data;
974 unsigned int vol_counter;
975 unsigned int vol;
976 unsigned int master_vol;
977
978 struct via_spec *spec = codec->spec;
979
980 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
981 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
982
983 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
984 0xF84, 0) & 0x3F0000) >> 16;
985
986 vol = vol_counter & 0x1F;
987 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
988 AC_VERB_GET_AMP_GAIN_MUTE,
989 AC_AMP_GET_INPUT);
990
991 if (gpio_data == 0x02) {
992 /* unmute line out */
993 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
994 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
995
996 if (vol_counter & 0x20) {
997 /* decrease volume */
998 if (vol > master_vol)
999 vol = master_vol;
1000 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1001 0, HDA_AMP_VOLMASK,
1002 master_vol-vol);
1003 } else {
1004 /* increase volume */
1005 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1006 HDA_AMP_VOLMASK,
1007 ((master_vol+vol) > 0x2A) ? 0x2A :
1008 (master_vol+vol));
1009 }
1010 } else if (!(gpio_data & 0x02)) {
1011 /* mute line out */
1012 snd_hda_codec_amp_stereo(codec,
1013 spec->autocfg.line_out_pins[0],
1014 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1015 HDA_AMP_MUTE);
1016 }
1017}
1018
1019/* unsolicited event for jack sensing */
1020static void via_unsol_event(struct hda_codec *codec,
1021 unsigned int res)
1022{
1023 res >>= 26;
1024 if (res == VIA_HP_EVENT)
1025 via_hp_automute(codec);
1026 else if (res == VIA_GPIO_EVENT)
1027 via_gpio_control(codec);
1028}
1029
1030static hda_nid_t slave_dig_outs[] = {
1031 0,
1032};
1033
583static int via_init(struct hda_codec *codec) 1034static int via_init(struct hda_codec *codec)
584{ 1035{
585 struct via_spec *spec = codec->spec; 1036 struct via_spec *spec = codec->spec;
586 snd_hda_sequence_write(codec, spec->init_verbs); 1037 int i;
1038 for (i = 0; i < spec->num_iverbs; i++)
1039 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1040
587 /* Lydia Add for EAPD enable */ 1041 /* Lydia Add for EAPD enable */
588 if (!spec->dig_in_nid) { /* No Digital In connection */ 1042 if (!spec->dig_in_nid) { /* No Digital In connection */
589 if (IS_VT1708_VENDORID(codec->vendor_id)) { 1043 if (IS_VT1708_VENDORID(codec->vendor_id)) {
@@ -611,6 +1065,9 @@ static int via_init(struct hda_codec *codec)
611 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, 1065 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
612 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 1066 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
613 1067
1068 /* no slave outs */
1069 codec->slave_dig_outs = slave_dig_outs;
1070
614 return 0; 1071 return 0;
615} 1072}
616 1073
@@ -657,10 +1114,10 @@ static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
657 spec->multiout.dac_nids[i] = 0x12; 1114 spec->multiout.dac_nids[i] = 0x12;
658 break; 1115 break;
659 case AUTO_SEQ_SURROUND: 1116 case AUTO_SEQ_SURROUND:
660 spec->multiout.dac_nids[i] = 0x13; 1117 spec->multiout.dac_nids[i] = 0x11;
661 break; 1118 break;
662 case AUTO_SEQ_SIDE: 1119 case AUTO_SEQ_SIDE:
663 spec->multiout.dac_nids[i] = 0x11; 1120 spec->multiout.dac_nids[i] = 0x13;
664 break; 1121 break;
665 } 1122 }
666 } 1123 }
@@ -685,7 +1142,7 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
685 continue; 1142 continue;
686 1143
687 if (i != AUTO_SEQ_FRONT) 1144 if (i != AUTO_SEQ_FRONT)
688 nid_vol = 0x1b - i + 1; 1145 nid_vol = 0x18 + i;
689 1146
690 if (i == AUTO_SEQ_CENLFE) { 1147 if (i == AUTO_SEQ_CENLFE) {
691 /* Center/LFE */ 1148 /* Center/LFE */
@@ -760,6 +1217,24 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
760 return 0; 1217 return 0;
761} 1218}
762 1219
1220static void create_hp_imux(struct via_spec *spec)
1221{
1222 int i;
1223 struct hda_input_mux *imux = &spec->private_imux[1];
1224 static const char *texts[] = { "OFF", "ON", NULL};
1225
1226 /* for hp mode select */
1227 i = 0;
1228 while (texts[i] != NULL) {
1229 imux->items[imux->num_items].label = texts[i];
1230 imux->items[imux->num_items].index = i;
1231 imux->num_items++;
1232 i++;
1233 }
1234
1235 spec->hp_mux = &spec->private_imux[1];
1236}
1237
763static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) 1238static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
764{ 1239{
765 int err; 1240 int err;
@@ -780,6 +1255,8 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
780 if (err < 0) 1255 if (err < 0)
781 return err; 1256 return err;
782 1257
1258 create_hp_imux(spec);
1259
783 return 0; 1260 return 0;
784} 1261}
785 1262
@@ -790,7 +1267,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
790 static char *labels[] = { 1267 static char *labels[] = {
791 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 1268 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
792 }; 1269 };
793 struct hda_input_mux *imux = &spec->private_imux; 1270 struct hda_input_mux *imux = &spec->private_imux[0];
794 int i, err, idx = 0; 1271 int i, err, idx = 0;
795 1272
796 /* for internal loopback recording select */ 1273 /* for internal loopback recording select */
@@ -840,11 +1317,36 @@ static struct hda_amp_list vt1708_loopbacks[] = {
840}; 1317};
841#endif 1318#endif
842 1319
1320static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1321{
1322 unsigned int def_conf;
1323 unsigned char seqassoc;
1324
1325 def_conf = snd_hda_codec_read(codec, nid, 0,
1326 AC_VERB_GET_CONFIG_DEFAULT, 0);
1327 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1328 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1329 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1330 if (seqassoc == 0xff) {
1331 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1332 snd_hda_codec_write(codec, nid, 0,
1333 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1334 def_conf >> 24);
1335 }
1336 }
1337
1338 return;
1339}
1340
843static int vt1708_parse_auto_config(struct hda_codec *codec) 1341static int vt1708_parse_auto_config(struct hda_codec *codec)
844{ 1342{
845 struct via_spec *spec = codec->spec; 1343 struct via_spec *spec = codec->spec;
846 int err; 1344 int err;
847 1345
1346 /* Add HP and CD pin config connect bit re-config action */
1347 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1348 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1349
848 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 1350 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
849 if (err < 0) 1351 if (err < 0)
850 return err; 1352 return err;
@@ -874,9 +1376,12 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
874 if (spec->kctl_alloc) 1376 if (spec->kctl_alloc)
875 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 1377 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
876 1378
877 spec->init_verbs = vt1708_volume_init_verbs; 1379 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1380
1381 spec->input_mux = &spec->private_imux[0];
878 1382
879 spec->input_mux = &spec->private_imux; 1383 if (spec->hp_mux)
1384 spec->mixers[spec->num_mixers++] = via_hp_mixer;
880 1385
881 return 1; 1386 return 1;
882} 1387}
@@ -897,7 +1402,7 @@ static int patch_vt1708(struct hda_codec *codec)
897 int err; 1402 int err;
898 1403
899 /* create a codec specific record */ 1404 /* create a codec specific record */
900 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 1405 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
901 if (spec == NULL) 1406 if (spec == NULL)
902 return -ENOMEM; 1407 return -ENOMEM;
903 1408
@@ -966,6 +1471,11 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = {
966 { } /* end */ 1471 { } /* end */
967}; 1472};
968 1473
1474static struct hda_verb vt1709_uniwill_init_verbs[] = {
1475 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1476 { }
1477};
1478
969/* 1479/*
970 * generic initialization of ADC, input mixers and output mixers 1480 * generic initialization of ADC, input mixers and output mixers
971 */ 1481 */
@@ -1090,11 +1600,11 @@ static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1090 break; 1600 break;
1091 case AUTO_SEQ_SURROUND: 1601 case AUTO_SEQ_SURROUND:
1092 /* AOW3 */ 1602 /* AOW3 */
1093 spec->multiout.dac_nids[i] = 0x27; 1603 spec->multiout.dac_nids[i] = 0x11;
1094 break; 1604 break;
1095 case AUTO_SEQ_SIDE: 1605 case AUTO_SEQ_SIDE:
1096 /* AOW1 */ 1606 /* AOW1 */
1097 spec->multiout.dac_nids[i] = 0x11; 1607 spec->multiout.dac_nids[i] = 0x27;
1098 break; 1608 break;
1099 default: 1609 default:
1100 break; 1610 break;
@@ -1203,26 +1713,26 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1203 } else if (i == AUTO_SEQ_SURROUND) { 1713 } else if (i == AUTO_SEQ_SURROUND) {
1204 sprintf(name, "%s Playback Volume", chname[i]); 1714 sprintf(name, "%s Playback Volume", chname[i]);
1205 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 1715 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1206 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 1716 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1207 HDA_OUTPUT)); 1717 HDA_OUTPUT));
1208 if (err < 0) 1718 if (err < 0)
1209 return err; 1719 return err;
1210 sprintf(name, "%s Playback Switch", chname[i]); 1720 sprintf(name, "%s Playback Switch", chname[i]);
1211 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 1721 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1212 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 1722 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1213 HDA_OUTPUT)); 1723 HDA_OUTPUT));
1214 if (err < 0) 1724 if (err < 0)
1215 return err; 1725 return err;
1216 } else if (i == AUTO_SEQ_SIDE) { 1726 } else if (i == AUTO_SEQ_SIDE) {
1217 sprintf(name, "%s Playback Volume", chname[i]); 1727 sprintf(name, "%s Playback Volume", chname[i]);
1218 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 1728 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1219 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 1729 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1220 HDA_OUTPUT)); 1730 HDA_OUTPUT));
1221 if (err < 0) 1731 if (err < 0)
1222 return err; 1732 return err;
1223 sprintf(name, "%s Playback Switch", chname[i]); 1733 sprintf(name, "%s Playback Switch", chname[i]);
1224 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 1734 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1225 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 1735 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1226 HDA_OUTPUT)); 1736 HDA_OUTPUT));
1227 if (err < 0) 1737 if (err < 0)
1228 return err; 1738 return err;
@@ -1265,7 +1775,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1265 static char *labels[] = { 1775 static char *labels[] = {
1266 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 1776 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1267 }; 1777 };
1268 struct hda_input_mux *imux = &spec->private_imux; 1778 struct hda_input_mux *imux = &spec->private_imux[0];
1269 int i, err, idx = 0; 1779 int i, err, idx = 0;
1270 1780
1271 /* for internal loopback recording select */ 1781 /* for internal loopback recording select */
@@ -1339,7 +1849,10 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1339 if (spec->kctl_alloc) 1849 if (spec->kctl_alloc)
1340 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 1850 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1341 1851
1342 spec->input_mux = &spec->private_imux; 1852 spec->input_mux = &spec->private_imux[0];
1853
1854 if (spec->hp_mux)
1855 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1343 1856
1344 return 1; 1857 return 1;
1345} 1858}
@@ -1360,7 +1873,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1360 int err; 1873 int err;
1361 1874
1362 /* create a codec specific record */ 1875 /* create a codec specific record */
1363 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 1876 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1364 if (spec == NULL) 1877 if (spec == NULL)
1365 return -ENOMEM; 1878 return -ENOMEM;
1366 1879
@@ -1375,7 +1888,8 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1375 "Using genenic mode...\n"); 1888 "Using genenic mode...\n");
1376 } 1889 }
1377 1890
1378 spec->init_verbs = vt1709_10ch_volume_init_verbs; 1891 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1892 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1379 1893
1380 spec->stream_name_analog = "VT1709 Analog"; 1894 spec->stream_name_analog = "VT1709 Analog";
1381 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; 1895 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
@@ -1396,6 +1910,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1396 codec->patch_ops = via_patch_ops; 1910 codec->patch_ops = via_patch_ops;
1397 1911
1398 codec->patch_ops.init = via_auto_init; 1912 codec->patch_ops.init = via_auto_init;
1913 codec->patch_ops.unsol_event = via_unsol_event;
1399#ifdef CONFIG_SND_HDA_POWER_SAVE 1914#ifdef CONFIG_SND_HDA_POWER_SAVE
1400 spec->loopback.amplist = vt1709_loopbacks; 1915 spec->loopback.amplist = vt1709_loopbacks;
1401#endif 1916#endif
@@ -1451,7 +1966,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1451 int err; 1966 int err;
1452 1967
1453 /* create a codec specific record */ 1968 /* create a codec specific record */
1454 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 1969 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1455 if (spec == NULL) 1970 if (spec == NULL)
1456 return -ENOMEM; 1971 return -ENOMEM;
1457 1972
@@ -1466,7 +1981,8 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1466 "Using genenic mode...\n"); 1981 "Using genenic mode...\n");
1467 } 1982 }
1468 1983
1469 spec->init_verbs = vt1709_6ch_volume_init_verbs; 1984 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1985 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1470 1986
1471 spec->stream_name_analog = "VT1709 Analog"; 1987 spec->stream_name_analog = "VT1709 Analog";
1472 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; 1988 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
@@ -1487,6 +2003,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1487 codec->patch_ops = via_patch_ops; 2003 codec->patch_ops = via_patch_ops;
1488 2004
1489 codec->patch_ops.init = via_auto_init; 2005 codec->patch_ops.init = via_auto_init;
2006 codec->patch_ops.unsol_event = via_unsol_event;
1490#ifdef CONFIG_SND_HDA_POWER_SAVE 2007#ifdef CONFIG_SND_HDA_POWER_SAVE
1491 spec->loopback.amplist = vt1709_loopbacks; 2008 spec->loopback.amplist = vt1709_loopbacks;
1492#endif 2009#endif
@@ -1586,27 +2103,32 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
1586 { } 2103 { }
1587}; 2104};
1588 2105
2106static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2107 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2108 { }
2109};
2110
1589static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { 2111static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
1590 .substreams = 1, 2112 .substreams = 2,
1591 .channels_min = 2, 2113 .channels_min = 2,
1592 .channels_max = 8, 2114 .channels_max = 8,
1593 .nid = 0x10, /* NID to query formats and rates */ 2115 .nid = 0x10, /* NID to query formats and rates */
1594 .ops = { 2116 .ops = {
1595 .open = via_playback_pcm_open, 2117 .open = via_playback_pcm_open,
1596 .prepare = via_playback_pcm_prepare, 2118 .prepare = via_playback_multi_pcm_prepare,
1597 .cleanup = via_playback_pcm_cleanup 2119 .cleanup = via_playback_multi_pcm_cleanup
1598 }, 2120 },
1599}; 2121};
1600 2122
1601static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { 2123static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
1602 .substreams = 1, 2124 .substreams = 2,
1603 .channels_min = 2, 2125 .channels_min = 2,
1604 .channels_max = 4, 2126 .channels_max = 4,
1605 .nid = 0x10, /* NID to query formats and rates */ 2127 .nid = 0x10, /* NID to query formats and rates */
1606 .ops = { 2128 .ops = {
1607 .open = via_playback_pcm_open, 2129 .open = via_playback_pcm_open,
1608 .prepare = via_playback_pcm_prepare, 2130 .prepare = via_playback_multi_pcm_prepare,
1609 .cleanup = via_playback_pcm_cleanup 2131 .cleanup = via_playback_multi_pcm_cleanup
1610 }, 2132 },
1611}; 2133};
1612 2134
@@ -1662,10 +2184,10 @@ static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
1662 spec->multiout.dac_nids[i] = 0x24; 2184 spec->multiout.dac_nids[i] = 0x24;
1663 break; 2185 break;
1664 case AUTO_SEQ_SURROUND: 2186 case AUTO_SEQ_SURROUND:
1665 spec->multiout.dac_nids[i] = 0x25; 2187 spec->multiout.dac_nids[i] = 0x11;
1666 break; 2188 break;
1667 case AUTO_SEQ_SIDE: 2189 case AUTO_SEQ_SIDE:
1668 spec->multiout.dac_nids[i] = 0x11; 2190 spec->multiout.dac_nids[i] = 0x25;
1669 break; 2191 break;
1670 } 2192 }
1671 } 2193 }
@@ -1680,7 +2202,7 @@ static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
1680{ 2202{
1681 char name[32]; 2203 char name[32];
1682 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2204 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1683 hda_nid_t nid_vols[] = {0x16, 0x27, 0x26, 0x18}; 2205 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
1684 hda_nid_t nid, nid_vol = 0; 2206 hda_nid_t nid, nid_vol = 0;
1685 int i, err; 2207 int i, err;
1686 2208
@@ -1785,6 +2307,8 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1785 if (err < 0) 2307 if (err < 0)
1786 return err; 2308 return err;
1787 2309
2310 create_hp_imux(spec);
2311
1788 return 0; 2312 return 0;
1789} 2313}
1790 2314
@@ -1795,7 +2319,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
1795 static char *labels[] = { 2319 static char *labels[] = {
1796 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 2320 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1797 }; 2321 };
1798 struct hda_input_mux *imux = &spec->private_imux; 2322 struct hda_input_mux *imux = &spec->private_imux[0];
1799 int i, err, idx = 0; 2323 int i, err, idx = 0;
1800 2324
1801 /* for internal loopback recording select */ 2325 /* for internal loopback recording select */
@@ -1869,7 +2393,10 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
1869 if (spec->kctl_alloc) 2393 if (spec->kctl_alloc)
1870 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 2394 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1871 2395
1872 spec->input_mux = &spec->private_imux; 2396 spec->input_mux = &spec->private_imux[0];
2397
2398 if (spec->hp_mux)
2399 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1873 2400
1874 return 1; 2401 return 1;
1875} 2402}
@@ -1890,7 +2417,7 @@ static int patch_vt1708B_8ch(struct hda_codec *codec)
1890 int err; 2417 int err;
1891 2418
1892 /* create a codec specific record */ 2419 /* create a codec specific record */
1893 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 2420 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1894 if (spec == NULL) 2421 if (spec == NULL)
1895 return -ENOMEM; 2422 return -ENOMEM;
1896 2423
@@ -1906,7 +2433,8 @@ static int patch_vt1708B_8ch(struct hda_codec *codec)
1906 "from BIOS. Using genenic mode...\n"); 2433 "from BIOS. Using genenic mode...\n");
1907 } 2434 }
1908 2435
1909 spec->init_verbs = vt1708B_8ch_volume_init_verbs; 2436 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2437 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
1910 2438
1911 spec->stream_name_analog = "VT1708B Analog"; 2439 spec->stream_name_analog = "VT1708B Analog";
1912 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; 2440 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
@@ -1926,6 +2454,7 @@ static int patch_vt1708B_8ch(struct hda_codec *codec)
1926 codec->patch_ops = via_patch_ops; 2454 codec->patch_ops = via_patch_ops;
1927 2455
1928 codec->patch_ops.init = via_auto_init; 2456 codec->patch_ops.init = via_auto_init;
2457 codec->patch_ops.unsol_event = via_unsol_event;
1929#ifdef CONFIG_SND_HDA_POWER_SAVE 2458#ifdef CONFIG_SND_HDA_POWER_SAVE
1930 spec->loopback.amplist = vt1708B_loopbacks; 2459 spec->loopback.amplist = vt1708B_loopbacks;
1931#endif 2460#endif
@@ -1939,7 +2468,7 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
1939 int err; 2468 int err;
1940 2469
1941 /* create a codec specific record */ 2470 /* create a codec specific record */
1942 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 2471 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1943 if (spec == NULL) 2472 if (spec == NULL)
1944 return -ENOMEM; 2473 return -ENOMEM;
1945 2474
@@ -1955,7 +2484,8 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
1955 "from BIOS. Using genenic mode...\n"); 2484 "from BIOS. Using genenic mode...\n");
1956 } 2485 }
1957 2486
1958 spec->init_verbs = vt1708B_4ch_volume_init_verbs; 2487 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2488 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
1959 2489
1960 spec->stream_name_analog = "VT1708B Analog"; 2490 spec->stream_name_analog = "VT1708B Analog";
1961 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; 2491 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
@@ -1975,6 +2505,7 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
1975 codec->patch_ops = via_patch_ops; 2505 codec->patch_ops = via_patch_ops;
1976 2506
1977 codec->patch_ops.init = via_auto_init; 2507 codec->patch_ops.init = via_auto_init;
2508 codec->patch_ops.unsol_event = via_unsol_event;
1978#ifdef CONFIG_SND_HDA_POWER_SAVE 2509#ifdef CONFIG_SND_HDA_POWER_SAVE
1979 spec->loopback.amplist = vt1708B_loopbacks; 2510 spec->loopback.amplist = vt1708B_loopbacks;
1980#endif 2511#endif
@@ -1982,6 +2513,752 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
1982 return 0; 2513 return 0;
1983} 2514}
1984 2515
2516/* Patch for VT1708S */
2517
2518/* VT1708S software backdoor based override for buggy hardware micboost
2519 * setting */
2520#define MIC_BOOST_VOLUME(xname, nid) { \
2521 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2522 .name = xname, \
2523 .index = 0, \
2524 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2525 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2526 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2527 .info = mic_boost_volume_info, \
2528 .get = snd_hda_mixer_amp_volume_get, \
2529 .put = snd_hda_mixer_amp_volume_put, \
2530 .tlv = { .c = mic_boost_tlv }, \
2531 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2532
2533/* capture mixer elements */
2534static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2535 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2536 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2537 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2538 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2539 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2540 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2541 {
2542 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2543 /* The multiple "Capture Source" controls confuse alsamixer
2544 * So call somewhat different..
2545 */
2546 /* .name = "Capture Source", */
2547 .name = "Input Source",
2548 .count = 1,
2549 .info = via_mux_enum_info,
2550 .get = via_mux_enum_get,
2551 .put = via_mux_enum_put,
2552 },
2553 { } /* end */
2554};
2555
2556static struct hda_verb vt1708S_volume_init_verbs[] = {
2557 /* Unmute ADC0-1 and set the default input to mic-in */
2558 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2559 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2560
2561 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2562 * analog-loopback mixer widget */
2563 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2564 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2565 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2566 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2567 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2568 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2569
2570 /* Setup default input of PW4 to MW0 */
2571 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2572 /* PW9, PW10 Output enable */
2573 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2574 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2575 /* Enable Mic Boost Volume backdoor */
2576 {0x1, 0xf98, 0x1},
2577 { }
2578};
2579
2580static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2581 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2582 { }
2583};
2584
2585static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2586 .substreams = 2,
2587 .channels_min = 2,
2588 .channels_max = 8,
2589 .nid = 0x10, /* NID to query formats and rates */
2590 .ops = {
2591 .open = via_playback_pcm_open,
2592 .prepare = via_playback_pcm_prepare,
2593 .cleanup = via_playback_pcm_cleanup
2594 },
2595};
2596
2597static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2598 .substreams = 2,
2599 .channels_min = 2,
2600 .channels_max = 2,
2601 .nid = 0x13, /* NID to query formats and rates */
2602 .ops = {
2603 .prepare = via_capture_pcm_prepare,
2604 .cleanup = via_capture_pcm_cleanup
2605 },
2606};
2607
2608static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
2609 .substreams = 2,
2610 .channels_min = 2,
2611 .channels_max = 2,
2612 /* NID is set in via_build_pcms */
2613 .ops = {
2614 .open = via_dig_playback_pcm_open,
2615 .close = via_dig_playback_pcm_close,
2616 .prepare = via_dig_playback_pcm_prepare
2617 },
2618};
2619
2620/* fill in the dac_nids table from the parsed pin configuration */
2621static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2622 const struct auto_pin_cfg *cfg)
2623{
2624 int i;
2625 hda_nid_t nid;
2626
2627 spec->multiout.num_dacs = cfg->line_outs;
2628
2629 spec->multiout.dac_nids = spec->private_dac_nids;
2630
2631 for (i = 0; i < 4; i++) {
2632 nid = cfg->line_out_pins[i];
2633 if (nid) {
2634 /* config dac list */
2635 switch (i) {
2636 case AUTO_SEQ_FRONT:
2637 spec->multiout.dac_nids[i] = 0x10;
2638 break;
2639 case AUTO_SEQ_CENLFE:
2640 spec->multiout.dac_nids[i] = 0x24;
2641 break;
2642 case AUTO_SEQ_SURROUND:
2643 spec->multiout.dac_nids[i] = 0x11;
2644 break;
2645 case AUTO_SEQ_SIDE:
2646 spec->multiout.dac_nids[i] = 0x25;
2647 break;
2648 }
2649 }
2650 }
2651
2652 return 0;
2653}
2654
2655/* add playback controls from the parsed DAC table */
2656static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2657 const struct auto_pin_cfg *cfg)
2658{
2659 char name[32];
2660 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2661 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2662 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2663 hda_nid_t nid, nid_vol, nid_mute;
2664 int i, err;
2665
2666 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2667 nid = cfg->line_out_pins[i];
2668
2669 if (!nid)
2670 continue;
2671
2672 nid_vol = nid_vols[i];
2673 nid_mute = nid_mutes[i];
2674
2675 if (i == AUTO_SEQ_CENLFE) {
2676 /* Center/LFE */
2677 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2678 "Center Playback Volume",
2679 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2680 HDA_OUTPUT));
2681 if (err < 0)
2682 return err;
2683 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2684 "LFE Playback Volume",
2685 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2686 HDA_OUTPUT));
2687 if (err < 0)
2688 return err;
2689 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2690 "Center Playback Switch",
2691 HDA_COMPOSE_AMP_VAL(nid_mute,
2692 1, 0,
2693 HDA_OUTPUT));
2694 if (err < 0)
2695 return err;
2696 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2697 "LFE Playback Switch",
2698 HDA_COMPOSE_AMP_VAL(nid_mute,
2699 2, 0,
2700 HDA_OUTPUT));
2701 if (err < 0)
2702 return err;
2703 } else if (i == AUTO_SEQ_FRONT) {
2704 /* add control to mixer index 0 */
2705 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2706 "Master Front Playback Volume",
2707 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2708 HDA_INPUT));
2709 if (err < 0)
2710 return err;
2711 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2712 "Master Front Playback Switch",
2713 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2714 HDA_INPUT));
2715 if (err < 0)
2716 return err;
2717
2718 /* Front */
2719 sprintf(name, "%s Playback Volume", chname[i]);
2720 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2721 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2722 HDA_OUTPUT));
2723 if (err < 0)
2724 return err;
2725 sprintf(name, "%s Playback Switch", chname[i]);
2726 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2727 HDA_COMPOSE_AMP_VAL(nid_mute,
2728 3, 0,
2729 HDA_OUTPUT));
2730 if (err < 0)
2731 return err;
2732 } else {
2733 sprintf(name, "%s Playback Volume", chname[i]);
2734 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2735 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2736 HDA_OUTPUT));
2737 if (err < 0)
2738 return err;
2739 sprintf(name, "%s Playback Switch", chname[i]);
2740 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2741 HDA_COMPOSE_AMP_VAL(nid_mute,
2742 3, 0,
2743 HDA_OUTPUT));
2744 if (err < 0)
2745 return err;
2746 }
2747 }
2748
2749 return 0;
2750}
2751
2752static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2753{
2754 int err;
2755
2756 if (!pin)
2757 return 0;
2758
2759 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2760
2761 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2762 "Headphone Playback Volume",
2763 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2764 if (err < 0)
2765 return err;
2766
2767 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2768 "Headphone Playback Switch",
2769 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2770 if (err < 0)
2771 return err;
2772
2773 create_hp_imux(spec);
2774
2775 return 0;
2776}
2777
2778/* create playback/capture controls for input pins */
2779static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2780 const struct auto_pin_cfg *cfg)
2781{
2782 static char *labels[] = {
2783 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2784 };
2785 struct hda_input_mux *imux = &spec->private_imux[0];
2786 int i, err, idx = 0;
2787
2788 /* for internal loopback recording select */
2789 imux->items[imux->num_items].label = "Stereo Mixer";
2790 imux->items[imux->num_items].index = 5;
2791 imux->num_items++;
2792
2793 for (i = 0; i < AUTO_PIN_LAST; i++) {
2794 if (!cfg->input_pins[i])
2795 continue;
2796
2797 switch (cfg->input_pins[i]) {
2798 case 0x1a: /* Mic */
2799 idx = 2;
2800 break;
2801
2802 case 0x1b: /* Line In */
2803 idx = 3;
2804 break;
2805
2806 case 0x1e: /* Front Mic */
2807 idx = 4;
2808 break;
2809
2810 case 0x1f: /* CD */
2811 idx = 1;
2812 break;
2813 }
2814 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2815 idx, 0x16);
2816 if (err < 0)
2817 return err;
2818 imux->items[imux->num_items].label = labels[i];
2819 imux->items[imux->num_items].index = idx-1;
2820 imux->num_items++;
2821 }
2822 return 0;
2823}
2824
2825static int vt1708S_parse_auto_config(struct hda_codec *codec)
2826{
2827 struct via_spec *spec = codec->spec;
2828 int err;
2829 static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2830
2831 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2832 vt1708s_ignore);
2833 if (err < 0)
2834 return err;
2835 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2836 if (err < 0)
2837 return err;
2838 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2839 return 0; /* can't find valid BIOS pin config */
2840
2841 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2842 if (err < 0)
2843 return err;
2844 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2845 if (err < 0)
2846 return err;
2847 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2848 if (err < 0)
2849 return err;
2850
2851 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2852
2853 if (spec->autocfg.dig_out_pin)
2854 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2855
2856 spec->extra_dig_out_nid = 0x15;
2857
2858 if (spec->kctl_alloc)
2859 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2860
2861 spec->input_mux = &spec->private_imux[0];
2862
2863 if (spec->hp_mux)
2864 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2865
2866 return 1;
2867}
2868
2869#ifdef CONFIG_SND_HDA_POWER_SAVE
2870static struct hda_amp_list vt1708S_loopbacks[] = {
2871 { 0x16, HDA_INPUT, 1 },
2872 { 0x16, HDA_INPUT, 2 },
2873 { 0x16, HDA_INPUT, 3 },
2874 { 0x16, HDA_INPUT, 4 },
2875 { } /* end */
2876};
2877#endif
2878
2879static int patch_vt1708S(struct hda_codec *codec)
2880{
2881 struct via_spec *spec;
2882 int err;
2883
2884 /* create a codec specific record */
2885 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2886 if (spec == NULL)
2887 return -ENOMEM;
2888
2889 codec->spec = spec;
2890
2891 /* automatic parse from the BIOS config */
2892 err = vt1708S_parse_auto_config(codec);
2893 if (err < 0) {
2894 via_free(codec);
2895 return err;
2896 } else if (!err) {
2897 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2898 "from BIOS. Using genenic mode...\n");
2899 }
2900
2901 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2902 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2903
2904 spec->stream_name_analog = "VT1708S Analog";
2905 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2906 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2907
2908 spec->stream_name_digital = "VT1708S Digital";
2909 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2910
2911 if (!spec->adc_nids && spec->input_mux) {
2912 spec->adc_nids = vt1708S_adc_nids;
2913 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2914 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2915 spec->num_mixers++;
2916 }
2917
2918 codec->patch_ops = via_patch_ops;
2919
2920 codec->patch_ops.init = via_auto_init;
2921 codec->patch_ops.unsol_event = via_unsol_event;
2922#ifdef CONFIG_SND_HDA_POWER_SAVE
2923 spec->loopback.amplist = vt1708S_loopbacks;
2924#endif
2925
2926 return 0;
2927}
2928
2929/* Patch for VT1702 */
2930
2931/* capture mixer elements */
2932static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2933 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2934 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2935 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2936 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2937 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2938 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2939 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2940 HDA_INPUT),
2941 {
2942 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2943 /* The multiple "Capture Source" controls confuse alsamixer
2944 * So call somewhat different..
2945 */
2946 /* .name = "Capture Source", */
2947 .name = "Input Source",
2948 .count = 1,
2949 .info = via_mux_enum_info,
2950 .get = via_mux_enum_get,
2951 .put = via_mux_enum_put,
2952 },
2953 { } /* end */
2954};
2955
2956static struct hda_verb vt1702_volume_init_verbs[] = {
2957 /*
2958 * Unmute ADC0-1 and set the default input to mic-in
2959 */
2960 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2961 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2962 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2963
2964
2965 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2966 * mixer widget
2967 */
2968 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2969 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2970 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2971 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2972 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2973 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2974
2975 /* Setup default input of PW4 to MW0 */
2976 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2977 /* PW6 PW7 Output enable */
2978 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2979 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2980 { }
2981};
2982
2983static struct hda_verb vt1702_uniwill_init_verbs[] = {
2984 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2985 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2986 { }
2987};
2988
2989static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2990 .substreams = 2,
2991 .channels_min = 2,
2992 .channels_max = 2,
2993 .nid = 0x10, /* NID to query formats and rates */
2994 .ops = {
2995 .open = via_playback_pcm_open,
2996 .prepare = via_playback_multi_pcm_prepare,
2997 .cleanup = via_playback_multi_pcm_cleanup
2998 },
2999};
3000
3001static struct hda_pcm_stream vt1702_pcm_analog_capture = {
3002 .substreams = 3,
3003 .channels_min = 2,
3004 .channels_max = 2,
3005 .nid = 0x12, /* NID to query formats and rates */
3006 .ops = {
3007 .prepare = via_capture_pcm_prepare,
3008 .cleanup = via_capture_pcm_cleanup
3009 },
3010};
3011
3012static struct hda_pcm_stream vt1702_pcm_digital_playback = {
3013 .substreams = 2,
3014 .channels_min = 2,
3015 .channels_max = 2,
3016 /* NID is set in via_build_pcms */
3017 .ops = {
3018 .open = via_dig_playback_pcm_open,
3019 .close = via_dig_playback_pcm_close,
3020 .prepare = via_dig_playback_pcm_prepare
3021 },
3022};
3023
3024/* fill in the dac_nids table from the parsed pin configuration */
3025static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3026 const struct auto_pin_cfg *cfg)
3027{
3028 spec->multiout.num_dacs = 1;
3029 spec->multiout.dac_nids = spec->private_dac_nids;
3030
3031 if (cfg->line_out_pins[0]) {
3032 /* config dac list */
3033 spec->multiout.dac_nids[0] = 0x10;
3034 }
3035
3036 return 0;
3037}
3038
3039/* add playback controls from the parsed DAC table */
3040static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3041 const struct auto_pin_cfg *cfg)
3042{
3043 int err;
3044
3045 if (!cfg->line_out_pins[0])
3046 return -1;
3047
3048 /* add control to mixer index 0 */
3049 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3050 "Master Front Playback Volume",
3051 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3052 if (err < 0)
3053 return err;
3054 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3055 "Master Front Playback Switch",
3056 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3057 if (err < 0)
3058 return err;
3059
3060 /* Front */
3061 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3062 "Front Playback Volume",
3063 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3064 if (err < 0)
3065 return err;
3066 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3067 "Front Playback Switch",
3068 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3069 if (err < 0)
3070 return err;
3071
3072 return 0;
3073}
3074
3075static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3076{
3077 int err;
3078
3079 if (!pin)
3080 return 0;
3081
3082 spec->multiout.hp_nid = 0x1D;
3083
3084 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3085 "Headphone Playback Volume",
3086 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3087 if (err < 0)
3088 return err;
3089
3090 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3091 "Headphone Playback Switch",
3092 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3093 if (err < 0)
3094 return err;
3095
3096 create_hp_imux(spec);
3097
3098 return 0;
3099}
3100
3101/* create playback/capture controls for input pins */
3102static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3103 const struct auto_pin_cfg *cfg)
3104{
3105 static char *labels[] = {
3106 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3107 };
3108 struct hda_input_mux *imux = &spec->private_imux[0];
3109 int i, err, idx = 0;
3110
3111 /* for internal loopback recording select */
3112 imux->items[imux->num_items].label = "Stereo Mixer";
3113 imux->items[imux->num_items].index = 3;
3114 imux->num_items++;
3115
3116 for (i = 0; i < AUTO_PIN_LAST; i++) {
3117 if (!cfg->input_pins[i])
3118 continue;
3119
3120 switch (cfg->input_pins[i]) {
3121 case 0x14: /* Mic */
3122 idx = 1;
3123 break;
3124
3125 case 0x15: /* Line In */
3126 idx = 2;
3127 break;
3128
3129 case 0x18: /* Front Mic */
3130 idx = 3;
3131 break;
3132 }
3133 err = via_new_analog_input(spec, cfg->input_pins[i],
3134 labels[i], idx, 0x1A);
3135 if (err < 0)
3136 return err;
3137 imux->items[imux->num_items].label = labels[i];
3138 imux->items[imux->num_items].index = idx-1;
3139 imux->num_items++;
3140 }
3141 return 0;
3142}
3143
3144static int vt1702_parse_auto_config(struct hda_codec *codec)
3145{
3146 struct via_spec *spec = codec->spec;
3147 int err;
3148 static hda_nid_t vt1702_ignore[] = {0x1C, 0};
3149
3150 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3151 vt1702_ignore);
3152 if (err < 0)
3153 return err;
3154 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3155 if (err < 0)
3156 return err;
3157 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3158 return 0; /* can't find valid BIOS pin config */
3159
3160 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3161 if (err < 0)
3162 return err;
3163 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3164 if (err < 0)
3165 return err;
3166 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3167 if (err < 0)
3168 return err;
3169
3170 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3171
3172 if (spec->autocfg.dig_out_pin)
3173 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3174
3175 spec->extra_dig_out_nid = 0x1B;
3176
3177 if (spec->kctl_alloc)
3178 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3179
3180 spec->input_mux = &spec->private_imux[0];
3181
3182 if (spec->hp_mux)
3183 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3184
3185 return 1;
3186}
3187
3188#ifdef CONFIG_SND_HDA_POWER_SAVE
3189static struct hda_amp_list vt1702_loopbacks[] = {
3190 { 0x1A, HDA_INPUT, 1 },
3191 { 0x1A, HDA_INPUT, 2 },
3192 { 0x1A, HDA_INPUT, 3 },
3193 { 0x1A, HDA_INPUT, 4 },
3194 { } /* end */
3195};
3196#endif
3197
3198static int patch_vt1702(struct hda_codec *codec)
3199{
3200 struct via_spec *spec;
3201 int err;
3202 unsigned int response;
3203 unsigned char control;
3204
3205 /* create a codec specific record */
3206 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3207 if (spec == NULL)
3208 return -ENOMEM;
3209
3210 codec->spec = spec;
3211
3212 /* automatic parse from the BIOS config */
3213 err = vt1702_parse_auto_config(codec);
3214 if (err < 0) {
3215 via_free(codec);
3216 return err;
3217 } else if (!err) {
3218 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3219 "from BIOS. Using genenic mode...\n");
3220 }
3221
3222 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3223 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3224
3225 spec->stream_name_analog = "VT1702 Analog";
3226 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3227 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3228
3229 spec->stream_name_digital = "VT1702 Digital";
3230 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3231
3232 if (!spec->adc_nids && spec->input_mux) {
3233 spec->adc_nids = vt1702_adc_nids;
3234 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3235 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3236 spec->num_mixers++;
3237 }
3238
3239 codec->patch_ops = via_patch_ops;
3240
3241 codec->patch_ops.init = via_auto_init;
3242 codec->patch_ops.unsol_event = via_unsol_event;
3243#ifdef CONFIG_SND_HDA_POWER_SAVE
3244 spec->loopback.amplist = vt1702_loopbacks;
3245#endif
3246
3247 /* Open backdoor */
3248 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3249 control = (unsigned char)(response & 0xff);
3250 control |= 0x3;
3251 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3252
3253 /* Enable GPIO 0&1 for volume&mute control */
3254 /* Enable GPIO 2 for DMIC-DATA */
3255 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3256 control = (unsigned char)((response >> 16) & 0x3f);
3257 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3258
3259 return 0;
3260}
3261
1985/* 3262/*
1986 * patch entries 3263 * patch entries
1987 */ 3264 */
@@ -2022,5 +3299,37 @@ struct hda_codec_preset snd_hda_preset_via[] = {
2022 .patch = patch_vt1708B_4ch}, 3299 .patch = patch_vt1708B_4ch},
2023 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch", 3300 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
2024 .patch = patch_vt1708B_4ch}, 3301 .patch = patch_vt1708B_4ch},
3302 { .id = 0x11060397, .name = "VIA VT1708S",
3303 .patch = patch_vt1708S},
3304 { .id = 0x11061397, .name = "VIA VT1708S",
3305 .patch = patch_vt1708S},
3306 { .id = 0x11062397, .name = "VIA VT1708S",
3307 .patch = patch_vt1708S},
3308 { .id = 0x11063397, .name = "VIA VT1708S",
3309 .patch = patch_vt1708S},
3310 { .id = 0x11064397, .name = "VIA VT1708S",
3311 .patch = patch_vt1708S},
3312 { .id = 0x11065397, .name = "VIA VT1708S",
3313 .patch = patch_vt1708S},
3314 { .id = 0x11066397, .name = "VIA VT1708S",
3315 .patch = patch_vt1708S},
3316 { .id = 0x11067397, .name = "VIA VT1708S",
3317 .patch = patch_vt1708S},
3318 { .id = 0x11060398, .name = "VIA VT1702",
3319 .patch = patch_vt1702},
3320 { .id = 0x11061398, .name = "VIA VT1702",
3321 .patch = patch_vt1702},
3322 { .id = 0x11062398, .name = "VIA VT1702",
3323 .patch = patch_vt1702},
3324 { .id = 0x11063398, .name = "VIA VT1702",
3325 .patch = patch_vt1702},
3326 { .id = 0x11064398, .name = "VIA VT1702",
3327 .patch = patch_vt1702},
3328 { .id = 0x11065398, .name = "VIA VT1702",
3329 .patch = patch_vt1702},
3330 { .id = 0x11066398, .name = "VIA VT1702",
3331 .patch = patch_vt1702},
3332 { .id = 0x11067398, .name = "VIA VT1702",
3333 .patch = patch_vt1702},
2025 {} /* terminator */ 3334 {} /* terminator */
2026}; 3335};
diff --git a/sound/pci/ice1712/ak4xxx.c b/sound/pci/ice1712/ak4xxx.c
index dab31b2756a6..03391da8c8c7 100644
--- a/sound/pci/ice1712/ak4xxx.c
+++ b/sound/pci/ice1712/ak4xxx.c
@@ -59,7 +59,8 @@ static void snd_ice1712_akm4xxx_write(struct snd_akm4xxx *ak, int chip,
59 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0]; 59 struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
60 struct snd_ice1712 *ice = ak->private_data[0]; 60 struct snd_ice1712 *ice = ak->private_data[0];
61 61
62 snd_assert(chip >= 0 && chip < 4, return); 62 if (snd_BUG_ON(chip < 0 || chip >= 4))
63 return;
63 64
64 tmp = snd_ice1712_gpio_read(ice); 65 tmp = snd_ice1712_gpio_read(ice);
65 tmp |= priv->add_flags; 66 tmp |= priv->add_flags;
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 868ae291b960..110d16e52733 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -44,10 +44,9 @@
44 * not working: prety much everything else, at least i could verify that 44 * not working: prety much everything else, at least i could verify that
45 * we have no digital output, no capture, pretty bad clicks and poops 45 * we have no digital output, no capture, pretty bad clicks and poops
46 * on mixer switch and other coll stuff. 46 * on mixer switch and other coll stuff.
47 * 47 */
48 */
49 48
50#include <asm/io.h> 49#include <linux/io.h>
51#include <linux/delay.h> 50#include <linux/delay.h>
52#include <linux/interrupt.h> 51#include <linux/interrupt.h>
53#include <linux/init.h> 52#include <linux/init.h>
@@ -131,7 +130,7 @@ static void aureon_pca9554_write(struct snd_ice1712 *ice, unsigned char reg,
131 snd_ice1712_gpio_write(ice, tmp); 130 snd_ice1712_gpio_write(ice, tmp);
132 udelay(50); 131 udelay(50);
133 132
134 /* 133 /*
135 * send i2c stop condition and start condition 134 * send i2c stop condition and start condition
136 * to obtain sane state 135 * to obtain sane state
137 */ 136 */
@@ -152,10 +151,16 @@ static void aureon_pca9554_write(struct snd_ice1712 *ice, unsigned char reg,
152 * skipping ack cycles inbetween 151 * skipping ack cycles inbetween
153 */ 152 */
154 for (j = 0; j < 3; j++) { 153 for (j = 0; j < 3; j++) {
155 switch(j) { 154 switch (j) {
156 case 0: val = dev; break; 155 case 0:
157 case 1: val = reg; break; 156 val = dev;
158 case 2: val = data; break; 157 break;
158 case 1:
159 val = reg;
160 break;
161 case 2:
162 val = data;
163 break;
159 } 164 }
160 for (i = 7; i >= 0; i--) { 165 for (i = 7; i >= 0; i--) {
161 tmp &= ~AUREON_SPI_CLK; 166 tmp &= ~AUREON_SPI_CLK;
@@ -171,7 +176,7 @@ static void aureon_pca9554_write(struct snd_ice1712 *ice, unsigned char reg,
171 snd_ice1712_gpio_write(ice, tmp); 176 snd_ice1712_gpio_write(ice, tmp);
172 udelay(40); 177 udelay(40);
173 } 178 }
174 tmp &= ~AUREON_SPI_CLK; 179 tmp &= ~AUREON_SPI_CLK;
175 snd_ice1712_gpio_write(ice, tmp); 180 snd_ice1712_gpio_write(ice, tmp);
176 udelay(40); 181 udelay(40);
177 tmp |= AUREON_SPI_CLK; 182 tmp |= AUREON_SPI_CLK;
@@ -203,7 +208,7 @@ static int aureon_universe_inmux_info(struct snd_kcontrol *kcontrol,
203 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 208 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
204 uinfo->count = 1; 209 uinfo->count = 1;
205 uinfo->value.enumerated.items = 3; 210 uinfo->value.enumerated.items = 3;
206 if(uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 211 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
207 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 212 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
208 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 213 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
209 return 0; 214 return 0;
@@ -231,12 +236,12 @@ static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol,
231 return -EINVAL; 236 return -EINVAL;
232 snd_ice1712_save_gpio_status(ice); 237 snd_ice1712_save_gpio_status(ice);
233 oval = spec->pca9554_out; 238 oval = spec->pca9554_out;
234 if ((change = (oval != nval))) { 239 change = (oval != nval);
240 if (change) {
235 aureon_pca9554_write(ice, PCA9554_OUT, nval); 241 aureon_pca9554_write(ice, PCA9554_OUT, nval);
236 spec->pca9554_out = nval; 242 spec->pca9554_out = nval;
237 } 243 }
238 snd_ice1712_restore_gpio_status(ice); 244 snd_ice1712_restore_gpio_status(ice);
239
240 return change; 245 return change;
241} 246}
242 247
@@ -256,7 +261,7 @@ static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg,
256 udelay(10); 261 udelay(10);
257 tmp &= ~AUREON_AC97_ADDR; 262 tmp &= ~AUREON_AC97_ADDR;
258 snd_ice1712_gpio_write(ice, tmp); 263 snd_ice1712_gpio_write(ice, tmp);
259 udelay(10); 264 udelay(10);
260 265
261 /* Send low-order byte to XILINX chip */ 266 /* Send low-order byte to XILINX chip */
262 tmp &= ~AUREON_AC97_DATA_MASK; 267 tmp &= ~AUREON_AC97_DATA_MASK;
@@ -269,7 +274,7 @@ static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg,
269 tmp &= ~AUREON_AC97_DATA_LOW; 274 tmp &= ~AUREON_AC97_DATA_LOW;
270 snd_ice1712_gpio_write(ice, tmp); 275 snd_ice1712_gpio_write(ice, tmp);
271 udelay(10); 276 udelay(10);
272 277
273 /* Send high-order byte to XILINX chip */ 278 /* Send high-order byte to XILINX chip */
274 tmp &= ~AUREON_AC97_DATA_MASK; 279 tmp &= ~AUREON_AC97_DATA_MASK;
275 tmp |= (val >> 8) & AUREON_AC97_DATA_MASK; 280 tmp |= (val >> 8) & AUREON_AC97_DATA_MASK;
@@ -282,7 +287,7 @@ static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg,
282 tmp &= ~AUREON_AC97_DATA_HIGH; 287 tmp &= ~AUREON_AC97_DATA_HIGH;
283 snd_ice1712_gpio_write(ice, tmp); 288 snd_ice1712_gpio_write(ice, tmp);
284 udelay(10); 289 udelay(10);
285 290
286 /* Instruct XILINX chip to parse the data to the STAC9744 chip */ 291 /* Instruct XILINX chip to parse the data to the STAC9744 chip */
287 tmp |= AUREON_AC97_COMMIT; 292 tmp |= AUREON_AC97_COMMIT;
288 snd_ice1712_gpio_write(ice, tmp); 293 snd_ice1712_gpio_write(ice, tmp);
@@ -290,7 +295,7 @@ static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg,
290 tmp &= ~AUREON_AC97_COMMIT; 295 tmp &= ~AUREON_AC97_COMMIT;
291 snd_ice1712_gpio_write(ice, tmp); 296 snd_ice1712_gpio_write(ice, tmp);
292 udelay(10); 297 udelay(10);
293 298
294 /* Store the data in out private buffer */ 299 /* Store the data in out private buffer */
295 spec->stac9744[(reg & 0x7F) >> 1] = val; 300 spec->stac9744[(reg & 0x7F) >> 1] = val;
296} 301}
@@ -304,7 +309,7 @@ static unsigned short aureon_ac97_read(struct snd_ice1712 *ice, unsigned short r
304/* 309/*
305 * Initialize STAC9744 chip 310 * Initialize STAC9744 chip
306 */ 311 */
307static int aureon_ac97_init (struct snd_ice1712 *ice) 312static int aureon_ac97_init(struct snd_ice1712 *ice)
308{ 313{
309 struct aureon_spec *spec = ice->spec; 314 struct aureon_spec *spec = ice->spec;
310 int i; 315 int i;
@@ -335,20 +340,21 @@ static int aureon_ac97_init (struct snd_ice1712 *ice)
335 tmp = (snd_ice1712_gpio_read(ice) | AUREON_AC97_RESET) & ~AUREON_AC97_DATA_MASK; 340 tmp = (snd_ice1712_gpio_read(ice) | AUREON_AC97_RESET) & ~AUREON_AC97_DATA_MASK;
336 snd_ice1712_gpio_write(ice, tmp); 341 snd_ice1712_gpio_write(ice, tmp);
337 udelay(3); 342 udelay(3);
338 343
339 tmp &= ~AUREON_AC97_RESET; 344 tmp &= ~AUREON_AC97_RESET;
340 snd_ice1712_gpio_write(ice, tmp); 345 snd_ice1712_gpio_write(ice, tmp);
341 udelay(3); 346 udelay(3);
342 347
343 tmp |= AUREON_AC97_RESET; 348 tmp |= AUREON_AC97_RESET;
344 snd_ice1712_gpio_write(ice, tmp); 349 snd_ice1712_gpio_write(ice, tmp);
345 udelay(3); 350 udelay(3);
346 351
347 memset(&spec->stac9744, 0, sizeof(spec->stac9744)); 352 memset(&spec->stac9744, 0, sizeof(spec->stac9744));
348 for (i=0; ac97_defaults[i] != (unsigned short)-1; i+=2) 353 for (i = 0; ac97_defaults[i] != (unsigned short)-1; i += 2)
349 spec->stac9744[(ac97_defaults[i]) >> 1] = ac97_defaults[i+1]; 354 spec->stac9744[(ac97_defaults[i]) >> 1] = ac97_defaults[i+1];
350 355
351 aureon_ac97_write(ice, AC97_MASTER, 0x0000); // Unmute AC'97 master volume permanently - muting is done by WM8770 356 /* Unmute AC'97 master volume permanently - muting is done by WM8770 */
357 aureon_ac97_write(ice, AC97_MASTER, 0x0000);
352 358
353 return 0; 359 return 0;
354} 360}
@@ -388,7 +394,7 @@ static int aureon_ac97_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
388 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 394 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
389 unsigned short ovol, nvol; 395 unsigned short ovol, nvol;
390 int change; 396 int change;
391 397
392 snd_ice1712_save_gpio_status(ice); 398 snd_ice1712_save_gpio_status(ice);
393 399
394 ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F); 400 ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
@@ -396,13 +402,14 @@ static int aureon_ac97_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
396 if (kcontrol->private_value & AUREON_AC97_STEREO) 402 if (kcontrol->private_value & AUREON_AC97_STEREO)
397 nvol |= ((0x1F - ucontrol->value.integer.value[1]) << 8) & 0x1F00; 403 nvol |= ((0x1F - ucontrol->value.integer.value[1]) << 8) & 0x1F00;
398 nvol |= ovol & ~0x1F1F; 404 nvol |= ovol & ~0x1F1F;
399 405
400 if ((change = (ovol != nvol))) 406 change = (ovol != nvol);
407 if (change)
401 aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol); 408 aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);
402 409
403 snd_ice1712_restore_gpio_status(ice); 410 snd_ice1712_restore_gpio_status(ice);
404 411
405 return change; 412 return change;
406} 413}
407 414
408/* 415/*
@@ -416,7 +423,8 @@ static int aureon_ac97_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_el
416 423
417 mutex_lock(&ice->gpio_mutex); 424 mutex_lock(&ice->gpio_mutex);
418 425
419 ucontrol->value.integer.value[0] = aureon_ac97_read(ice, kcontrol->private_value & 0x7F) & 0x8000 ? 0 : 1; 426 ucontrol->value.integer.value[0] = aureon_ac97_read(ice,
427 kcontrol->private_value & 0x7F) & 0x8000 ? 0 : 1;
420 428
421 mutex_unlock(&ice->gpio_mutex); 429 mutex_unlock(&ice->gpio_mutex);
422 return 0; 430 return 0;
@@ -429,13 +437,14 @@ static int aureon_ac97_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
429 int change; 437 int change;
430 438
431 snd_ice1712_save_gpio_status(ice); 439 snd_ice1712_save_gpio_status(ice);
432 440
433 ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F); 441 ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
434 nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x8000) | (ovol & ~ 0x8000); 442 nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x8000) | (ovol & ~0x8000);
435 443
436 if ((change = (ovol != nvol))) 444 change = (ovol != nvol);
445 if (change)
437 aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol); 446 aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);
438 447
439 snd_ice1712_restore_gpio_status(ice); 448 snd_ice1712_restore_gpio_status(ice);
440 449
441 return change; 450 return change;
@@ -465,13 +474,14 @@ static int aureon_ac97_micboost_put(struct snd_kcontrol *kcontrol, struct snd_ct
465 int change; 474 int change;
466 475
467 snd_ice1712_save_gpio_status(ice); 476 snd_ice1712_save_gpio_status(ice);
468 477
469 ovol = aureon_ac97_read(ice, AC97_MIC); 478 ovol = aureon_ac97_read(ice, AC97_MIC);
470 nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x0020) | (ovol & ~0x0020); 479 nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x0020) | (ovol & ~0x0020);
471 480
472 if ((change = (ovol != nvol))) 481 change = (ovol != nvol);
482 if (change)
473 aureon_ac97_write(ice, AC97_MIC, nvol); 483 aureon_ac97_write(ice, AC97_MIC, nvol);
474 484
475 snd_ice1712_restore_gpio_status(ice); 485 snd_ice1712_restore_gpio_status(ice);
476 486
477 return change; 487 return change;
@@ -493,16 +503,15 @@ static void aureon_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned
493 snd_ice1712_gpio_set_mask(ice, ~(PRODIGY_SPI_MOSI|PRODIGY_SPI_CLK|PRODIGY_WM_CS)); 503 snd_ice1712_gpio_set_mask(ice, ~(PRODIGY_SPI_MOSI|PRODIGY_SPI_CLK|PRODIGY_WM_CS));
494 mosi = PRODIGY_SPI_MOSI; 504 mosi = PRODIGY_SPI_MOSI;
495 clk = PRODIGY_SPI_CLK; 505 clk = PRODIGY_SPI_CLK;
496 } 506 } else {
497 else {
498 snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RW|AUREON_SPI_MOSI|AUREON_SPI_CLK| 507 snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RW|AUREON_SPI_MOSI|AUREON_SPI_CLK|
499 AUREON_WM_CS|AUREON_CS8415_CS)); 508 AUREON_WM_CS|AUREON_CS8415_CS));
500 mosi = AUREON_SPI_MOSI; 509 mosi = AUREON_SPI_MOSI;
501 clk = AUREON_SPI_CLK; 510 clk = AUREON_SPI_CLK;
502 511
503 tmp |= AUREON_WM_RW; 512 tmp |= AUREON_WM_RW;
504 } 513 }
505 514
506 tmp &= ~cs; 515 tmp &= ~cs;
507 snd_ice1712_gpio_write(ice, tmp); 516 snd_ice1712_gpio_write(ice, tmp);
508 udelay(1); 517 udelay(1);
@@ -534,7 +543,9 @@ static void aureon_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned
534/* 543/*
535 * Read data in SPI mode 544 * Read data in SPI mode
536 */ 545 */
537static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits, unsigned char *buffer, int size) { 546static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs,
547 unsigned int data, int bits, unsigned char *buffer, int size)
548{
538 int i, j; 549 int i, j;
539 unsigned int tmp; 550 unsigned int tmp;
540 551
@@ -544,7 +555,7 @@ static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs, unsigned i
544 snd_ice1712_gpio_write(ice, tmp); 555 snd_ice1712_gpio_write(ice, tmp);
545 udelay(1); 556 udelay(1);
546 557
547 for (i=bits-1; i>=0; i--) { 558 for (i = bits-1; i >= 0; i--) {
548 if (data & (1 << i)) 559 if (data & (1 << i))
549 tmp |= AUREON_SPI_MOSI; 560 tmp |= AUREON_SPI_MOSI;
550 else 561 else
@@ -561,9 +572,9 @@ static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs, unsigned i
561 udelay(1); 572 udelay(1);
562 } 573 }
563 574
564 for (j=0; j<size; j++) { 575 for (j = 0; j < size; j++) {
565 unsigned char outdata = 0; 576 unsigned char outdata = 0;
566 for (i=7; i>=0; i--) { 577 for (i = 7; i >= 0; i--) {
567 tmp = snd_ice1712_gpio_read(ice); 578 tmp = snd_ice1712_gpio_read(ice);
568 outdata <<= 1; 579 outdata <<= 1;
569 outdata |= (tmp & AUREON_SPI_MISO) ? 1 : 0; 580 outdata |= (tmp & AUREON_SPI_MISO) ? 1 : 0;
@@ -584,19 +595,24 @@ static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs, unsigned i
584 snd_ice1712_gpio_write(ice, tmp); 595 snd_ice1712_gpio_write(ice, tmp);
585} 596}
586 597
587static unsigned char aureon_cs8415_get(struct snd_ice1712 *ice, int reg) { 598static unsigned char aureon_cs8415_get(struct snd_ice1712 *ice, int reg)
599{
588 unsigned char val; 600 unsigned char val;
589 aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16); 601 aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16);
590 aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, &val, 1); 602 aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, &val, 1);
591 return val; 603 return val;
592} 604}
593 605
594static void aureon_cs8415_read(struct snd_ice1712 *ice, int reg, unsigned char *buffer, int size) { 606static void aureon_cs8415_read(struct snd_ice1712 *ice, int reg,
607 unsigned char *buffer, int size)
608{
595 aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16); 609 aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16);
596 aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, buffer, size); 610 aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, buffer, size);
597} 611}
598 612
599static void aureon_cs8415_put(struct snd_ice1712 *ice, int reg, unsigned char val) { 613static void aureon_cs8415_put(struct snd_ice1712 *ice, int reg,
614 unsigned char val)
615{
600 aureon_spi_write(ice, AUREON_CS8415_CS, 0x200000 | (reg << 8) | val, 24); 616 aureon_spi_write(ice, AUREON_CS8415_CS, 0x200000 | (reg << 8) | val, 24);
601} 617}
602 618
@@ -654,18 +670,20 @@ static int aureon_ac97_mmute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
654 return 0; 670 return 0;
655} 671}
656 672
657static int aureon_ac97_mmute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { 673static int aureon_ac97_mmute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
674{
658 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 675 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
659 unsigned short ovol, nvol; 676 unsigned short ovol, nvol;
660 int change; 677 int change;
661 678
662 snd_ice1712_save_gpio_status(ice); 679 snd_ice1712_save_gpio_status(ice);
663 680
664 ovol = wm_get(ice, WM_OUT_MUX1); 681 ovol = wm_get(ice, WM_OUT_MUX1);
665 nvol = (ovol & ~0x02) | (ucontrol->value.integer.value[0] ? 0x02 : 0x00); 682 nvol = (ovol & ~0x02) | (ucontrol->value.integer.value[0] ? 0x02 : 0x00);
666 if ((change = (ovol != nvol))) 683 change = (ovol != nvol);
684 if (change)
667 wm_put(ice, WM_OUT_MUX1, nvol); 685 wm_put(ice, WM_OUT_MUX1, nvol);
668 686
669 snd_ice1712_restore_gpio_status(ice); 687 snd_ice1712_restore_gpio_status(ice);
670 688
671 return change; 689 return change;
@@ -702,12 +720,12 @@ static const unsigned char wm_vol[256] = {
702static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master) 720static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
703{ 721{
704 unsigned char nvol; 722 unsigned char nvol;
705 723
706 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE)) 724 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
707 nvol = 0; 725 nvol = 0;
708 else 726 else
709 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX]; 727 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX];
710 728
711 wm_put(ice, index, nvol); 729 wm_put(ice, index, nvol);
712 wm_put_nocache(ice, index, 0x180 | nvol); 730 wm_put_nocache(ice, index, 0x180 | nvol);
713} 731}
@@ -736,7 +754,8 @@ static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va
736 snd_ice1712_save_gpio_status(ice); 754 snd_ice1712_save_gpio_status(ice);
737 oval = wm_get(ice, WM_MUTE); 755 oval = wm_get(ice, WM_MUTE);
738 nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10); 756 nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10);
739 if ((change = (nval != oval))) 757 change = (oval != nval);
758 if (change)
740 wm_put(ice, WM_MUTE, nval); 759 wm_put(ice, WM_MUTE, nval);
741 snd_ice1712_restore_gpio_status(ice); 760 snd_ice1712_restore_gpio_status(ice);
742 761
@@ -760,7 +779,7 @@ static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
760 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 779 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
761 struct aureon_spec *spec = ice->spec; 780 struct aureon_spec *spec = ice->spec;
762 int i; 781 int i;
763 for (i=0; i<2; i++) 782 for (i = 0; i < 2; i++)
764 ucontrol->value.integer.value[i] = 783 ucontrol->value.integer.value[i] =
765 spec->master[i] & ~WM_VOL_MUTE; 784 spec->master[i] & ~WM_VOL_MUTE;
766 return 0; 785 return 0;
@@ -849,7 +868,8 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *
849/* 868/*
850 * WM8770 mute control 869 * WM8770 mute control
851 */ 870 */
852static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { 871static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
872{
853 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 873 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
854 uinfo->count = kcontrol->private_value >> 8; 874 uinfo->count = kcontrol->private_value >> 8;
855 uinfo->value.integer.min = 0; 875 uinfo->value.integer.min = 0;
@@ -862,7 +882,7 @@ static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value
862 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 882 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
863 struct aureon_spec *spec = ice->spec; 883 struct aureon_spec *spec = ice->spec;
864 int voices, ofs, i; 884 int voices, ofs, i;
865 885
866 voices = kcontrol->private_value >> 8; 886 voices = kcontrol->private_value >> 8;
867 ofs = kcontrol->private_value & 0xFF; 887 ofs = kcontrol->private_value & 0xFF;
868 888
@@ -907,7 +927,7 @@ static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
907{ 927{
908 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 928 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
909 struct aureon_spec *spec = ice->spec; 929 struct aureon_spec *spec = ice->spec;
910 930
911 ucontrol->value.integer.value[0] = 931 ucontrol->value.integer.value[0] =
912 (spec->master[0] & WM_VOL_MUTE) ? 0 : 1; 932 (spec->master[0] & WM_VOL_MUTE) ? 0 : 1;
913 ucontrol->value.integer.value[1] = 933 ucontrol->value.integer.value[1] =
@@ -1083,21 +1103,21 @@ static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
1083static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1103static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1084{ 1104{
1085 static const char * const texts[] = { 1105 static const char * const texts[] = {
1086 "CD", //AIN1 1106 "CD", /* AIN1 */
1087 "Aux", //AIN2 1107 "Aux", /* AIN2 */
1088 "Line", //AIN3 1108 "Line", /* AIN3 */
1089 "Mic", //AIN4 1109 "Mic", /* AIN4 */
1090 "AC97" //AIN5 1110 "AC97" /* AIN5 */
1091 }; 1111 };
1092 static const char * const universe_texts[] = { 1112 static const char * const universe_texts[] = {
1093 "Aux1", //AIN1 1113 "Aux1", /* AIN1 */
1094 "CD", //AIN2 1114 "CD", /* AIN2 */
1095 "Phono", //AIN3 1115 "Phono", /* AIN3 */
1096 "Line", //AIN4 1116 "Line", /* AIN4 */
1097 "Aux2", //AIN5 1117 "Aux2", /* AIN5 */
1098 "Mic", //AIN6 1118 "Mic", /* AIN6 */
1099 "Aux3", //AIN7 1119 "Aux3", /* AIN7 */
1100 "AC97" //AIN8 1120 "AC97" /* AIN8 */
1101 }; 1121 };
1102 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1122 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1103 1123
@@ -1108,8 +1128,7 @@ static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_in
1108 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1128 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1109 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1129 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1110 strcpy(uinfo->value.enumerated.name, universe_texts[uinfo->value.enumerated.item]); 1130 strcpy(uinfo->value.enumerated.name, universe_texts[uinfo->value.enumerated.item]);
1111 } 1131 } else {
1112 else {
1113 uinfo->value.enumerated.items = 5; 1132 uinfo->value.enumerated.items = 5;
1114 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1133 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1115 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1134 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
@@ -1156,8 +1175,8 @@ static int aureon_cs8415_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
1156{ 1175{
1157 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1176 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1158 static const char * const aureon_texts[] = { 1177 static const char * const aureon_texts[] = {
1159 "CD", //RXP0 1178 "CD", /* RXP0 */
1160 "Optical" //RXP1 1179 "Optical" /* RXP1 */
1161 }; 1180 };
1162 static const char * const prodigy_texts[] = { 1181 static const char * const prodigy_texts[] = {
1163 "CD", 1182 "CD",
@@ -1180,10 +1199,10 @@ static int aureon_cs8415_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1180 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1199 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1181 struct aureon_spec *spec = ice->spec; 1200 struct aureon_spec *spec = ice->spec;
1182 1201
1183 //snd_ice1712_save_gpio_status(ice); 1202 /* snd_ice1712_save_gpio_status(ice); */
1184 //val = aureon_cs8415_get(ice, CS8415_CTRL2); 1203 /* val = aureon_cs8415_get(ice, CS8415_CTRL2); */
1185 ucontrol->value.enumerated.item[0] = spec->cs8415_mux; 1204 ucontrol->value.enumerated.item[0] = spec->cs8415_mux;
1186 //snd_ice1712_restore_gpio_status(ice); 1205 /* snd_ice1712_restore_gpio_status(ice); */
1187 return 0; 1206 return 0;
1188} 1207}
1189 1208
@@ -1206,7 +1225,7 @@ static int aureon_cs8415_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1206 return change; 1225 return change;
1207} 1226}
1208 1227
1209static int aureon_cs8415_rate_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1228static int aureon_cs8415_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1210{ 1229{
1211 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1230 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1212 uinfo->count = 1; 1231 uinfo->count = 1;
@@ -1215,7 +1234,7 @@ static int aureon_cs8415_rate_info (struct snd_kcontrol *kcontrol, struct snd_ct
1215 return 0; 1234 return 0;
1216} 1235}
1217 1236
1218static int aureon_cs8415_rate_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1237static int aureon_cs8415_rate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1219{ 1238{
1220 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1239 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1221 unsigned char ratio; 1240 unsigned char ratio;
@@ -1229,7 +1248,7 @@ static int aureon_cs8415_rate_get (struct snd_kcontrol *kcontrol, struct snd_ctl
1229 */ 1248 */
1230#define aureon_cs8415_mute_info snd_ctl_boolean_mono_info 1249#define aureon_cs8415_mute_info snd_ctl_boolean_mono_info
1231 1250
1232static int aureon_cs8415_mute_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1251static int aureon_cs8415_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1233{ 1252{
1234 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1253 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1235 snd_ice1712_save_gpio_status(ice); 1254 snd_ice1712_save_gpio_status(ice);
@@ -1238,7 +1257,7 @@ static int aureon_cs8415_mute_get (struct snd_kcontrol *kcontrol, struct snd_ctl
1238 return 0; 1257 return 0;
1239} 1258}
1240 1259
1241static int aureon_cs8415_mute_put (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1260static int aureon_cs8415_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1242{ 1261{
1243 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1262 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1244 unsigned char oval, nval; 1263 unsigned char oval, nval;
@@ -1249,7 +1268,8 @@ static int aureon_cs8415_mute_put (struct snd_kcontrol *kcontrol, struct snd_ctl
1249 nval = oval & ~0x20; 1268 nval = oval & ~0x20;
1250 else 1269 else
1251 nval = oval | 0x20; 1270 nval = oval | 0x20;
1252 if ((change = (oval != nval))) 1271 change = (oval != nval);
1272 if (change)
1253 aureon_cs8415_put(ice, CS8415_CTRL1, nval); 1273 aureon_cs8415_put(ice, CS8415_CTRL1, nval);
1254 snd_ice1712_restore_gpio_status(ice); 1274 snd_ice1712_restore_gpio_status(ice);
1255 return change; 1275 return change;
@@ -1258,15 +1278,17 @@ static int aureon_cs8415_mute_put (struct snd_kcontrol *kcontrol, struct snd_ctl
1258/* 1278/*
1259 * CS8415A Q-Sub info 1279 * CS8415A Q-Sub info
1260 */ 1280 */
1261static int aureon_cs8415_qsub_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { 1281static int aureon_cs8415_qsub_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1282{
1262 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 1283 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1263 uinfo->count = 10; 1284 uinfo->count = 10;
1264 return 0; 1285 return 0;
1265} 1286}
1266 1287
1267static int aureon_cs8415_qsub_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { 1288static int aureon_cs8415_qsub_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1289{
1268 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1290 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1269 1291
1270 snd_ice1712_save_gpio_status(ice); 1292 snd_ice1712_save_gpio_status(ice);
1271 aureon_cs8415_read(ice, CS8415_QSUB, ucontrol->value.bytes.data, 10); 1293 aureon_cs8415_read(ice, CS8415_QSUB, ucontrol->value.bytes.data, 10);
1272 snd_ice1712_restore_gpio_status(ice); 1294 snd_ice1712_restore_gpio_status(ice);
@@ -1274,18 +1296,21 @@ static int aureon_cs8415_qsub_get (struct snd_kcontrol *kcontrol, struct snd_ctl
1274 return 0; 1296 return 0;
1275} 1297}
1276 1298
1277static int aureon_cs8415_spdif_info (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { 1299static int aureon_cs8415_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1300{
1278 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 1301 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1279 uinfo->count = 1; 1302 uinfo->count = 1;
1280 return 0; 1303 return 0;
1281} 1304}
1282 1305
1283static int aureon_cs8415_mask_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { 1306static int aureon_cs8415_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1307{
1284 memset(ucontrol->value.iec958.status, 0xFF, 24); 1308 memset(ucontrol->value.iec958.status, 0xFF, 24);
1285 return 0; 1309 return 0;
1286} 1310}
1287 1311
1288static int aureon_cs8415_spdif_get (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { 1312static int aureon_cs8415_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1313{
1289 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1314 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1290 1315
1291 snd_ice1712_save_gpio_status(ice); 1316 snd_ice1712_save_gpio_status(ice);
@@ -1311,9 +1336,9 @@ static int aureon_set_headphone_amp(struct snd_ice1712 *ice, int enable)
1311 else 1336 else
1312 if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT && 1337 if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
1313 ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT) 1338 ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT)
1314 tmp &= ~ AUREON_HP_SEL; 1339 tmp &= ~AUREON_HP_SEL;
1315 else 1340 else
1316 tmp &= ~ PRODIGY_HP_SEL; 1341 tmp &= ~PRODIGY_HP_SEL;
1317 if (tmp != tmp2) { 1342 if (tmp != tmp2) {
1318 snd_ice1712_gpio_write(ice, tmp); 1343 snd_ice1712_gpio_write(ice, tmp);
1319 return 1; 1344 return 1;
@@ -1325,7 +1350,7 @@ static int aureon_get_headphone_amp(struct snd_ice1712 *ice)
1325{ 1350{
1326 unsigned int tmp = snd_ice1712_gpio_read(ice); 1351 unsigned int tmp = snd_ice1712_gpio_read(ice);
1327 1352
1328 return ( tmp & AUREON_HP_SEL )!= 0; 1353 return (tmp & AUREON_HP_SEL) != 0;
1329} 1354}
1330 1355
1331#define aureon_hpamp_info snd_ctl_boolean_mono_info 1356#define aureon_hpamp_info snd_ctl_boolean_mono_info
@@ -1343,7 +1368,7 @@ static int aureon_hpamp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
1343{ 1368{
1344 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1369 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1345 1370
1346 return aureon_set_headphone_amp(ice,ucontrol->value.integer.value[0]); 1371 return aureon_set_headphone_amp(ice, ucontrol->value.integer.value[0]);
1347} 1372}
1348 1373
1349/* 1374/*
@@ -1390,7 +1415,7 @@ static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_
1390 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1415 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1391 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1416 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1392 1417
1393 return 0; 1418 return 0;
1394} 1419}
1395 1420
1396static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1421static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1434,7 +1459,7 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1434 { 1459 {
1435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1436 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1461 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1437 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1462 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1438 .name = "Master Playback Volume", 1463 .name = "Master Playback Volume",
1439 .info = wm_master_vol_info, 1464 .info = wm_master_vol_info,
1440 .get = wm_master_vol_get, 1465 .get = wm_master_vol_get,
@@ -1452,7 +1477,7 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1452 { 1477 {
1453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1454 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1479 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1455 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1480 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1456 .name = "Front Playback Volume", 1481 .name = "Front Playback Volume",
1457 .info = wm_vol_info, 1482 .info = wm_vol_info,
1458 .get = wm_vol_get, 1483 .get = wm_vol_get,
@@ -1471,7 +1496,7 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1471 { 1496 {
1472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1498 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1474 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1499 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1475 .name = "Rear Playback Volume", 1500 .name = "Rear Playback Volume",
1476 .info = wm_vol_info, 1501 .info = wm_vol_info,
1477 .get = wm_vol_get, 1502 .get = wm_vol_get,
@@ -1490,7 +1515,7 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1490 { 1515 {
1491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1516 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1492 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1517 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1493 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1518 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1494 .name = "Center Playback Volume", 1519 .name = "Center Playback Volume",
1495 .info = wm_vol_info, 1520 .info = wm_vol_info,
1496 .get = wm_vol_get, 1521 .get = wm_vol_get,
@@ -1509,7 +1534,7 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1509 { 1534 {
1510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1535 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1511 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1536 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1512 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1537 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1513 .name = "LFE Playback Volume", 1538 .name = "LFE Playback Volume",
1514 .info = wm_vol_info, 1539 .info = wm_vol_info,
1515 .get = wm_vol_get, 1540 .get = wm_vol_get,
@@ -1528,7 +1553,7 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1528 { 1553 {
1529 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1554 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1530 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1555 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1531 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1556 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1532 .name = "Side Playback Volume", 1557 .name = "Side Playback Volume",
1533 .info = wm_vol_info, 1558 .info = wm_vol_info,
1534 .get = wm_vol_get, 1559 .get = wm_vol_get,
@@ -1539,23 +1564,23 @@ static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
1539}; 1564};
1540 1565
1541static struct snd_kcontrol_new wm_controls[] __devinitdata = { 1566static struct snd_kcontrol_new wm_controls[] __devinitdata = {
1542 { 1567 {
1543 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1568 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1544 .name = "PCM Playback Switch", 1569 .name = "PCM Playback Switch",
1545 .info = wm_pcm_mute_info, 1570 .info = wm_pcm_mute_info,
1546 .get = wm_pcm_mute_get, 1571 .get = wm_pcm_mute_get,
1547 .put = wm_pcm_mute_put 1572 .put = wm_pcm_mute_put
1548 }, 1573 },
1549 { 1574 {
1550 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1551 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1576 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1552 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1577 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1553 .name = "PCM Playback Volume", 1578 .name = "PCM Playback Volume",
1554 .info = wm_pcm_vol_info, 1579 .info = wm_pcm_vol_info,
1555 .get = wm_pcm_vol_get, 1580 .get = wm_pcm_vol_get,
1556 .put = wm_pcm_vol_put, 1581 .put = wm_pcm_vol_put,
1557 .tlv = { .p = db_scale_wm_pcm } 1582 .tlv = { .p = db_scale_wm_pcm }
1558 }, 1583 },
1559 { 1584 {
1560 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1561 .name = "Capture Switch", 1586 .name = "Capture Switch",
@@ -1566,7 +1591,7 @@ static struct snd_kcontrol_new wm_controls[] __devinitdata = {
1566 { 1591 {
1567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1592 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1568 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1593 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1569 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1594 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1570 .name = "Capture Volume", 1595 .name = "Capture Volume",
1571 .info = wm_adc_vol_info, 1596 .info = wm_adc_vol_info,
1572 .get = wm_adc_vol_get, 1597 .get = wm_adc_vol_get,
@@ -1605,232 +1630,232 @@ static struct snd_kcontrol_new wm_controls[] __devinitdata = {
1605}; 1630};
1606 1631
1607static struct snd_kcontrol_new ac97_controls[] __devinitdata = { 1632static struct snd_kcontrol_new ac97_controls[] __devinitdata = {
1608 { 1633 {
1609 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1634 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1610 .name = "AC97 Playback Switch", 1635 .name = "AC97 Playback Switch",
1611 .info = aureon_ac97_mmute_info, 1636 .info = aureon_ac97_mmute_info,
1612 .get = aureon_ac97_mmute_get, 1637 .get = aureon_ac97_mmute_get,
1613 .put = aureon_ac97_mmute_put, 1638 .put = aureon_ac97_mmute_put,
1614 .private_value = AC97_MASTER 1639 .private_value = AC97_MASTER
1615 }, 1640 },
1616 { 1641 {
1617 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1618 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1643 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1619 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1644 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1620 .name = "AC97 Playback Volume", 1645 .name = "AC97 Playback Volume",
1621 .info = aureon_ac97_vol_info, 1646 .info = aureon_ac97_vol_info,
1622 .get = aureon_ac97_vol_get, 1647 .get = aureon_ac97_vol_get,
1623 .put = aureon_ac97_vol_put, 1648 .put = aureon_ac97_vol_put,
1624 .private_value = AC97_MASTER|AUREON_AC97_STEREO, 1649 .private_value = AC97_MASTER|AUREON_AC97_STEREO,
1625 .tlv = { .p = db_scale_ac97_master } 1650 .tlv = { .p = db_scale_ac97_master }
1626 }, 1651 },
1627 { 1652 {
1628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1629 .name = "CD Playback Switch", 1654 .name = "CD Playback Switch",
1630 .info = aureon_ac97_mute_info, 1655 .info = aureon_ac97_mute_info,
1631 .get = aureon_ac97_mute_get, 1656 .get = aureon_ac97_mute_get,
1632 .put = aureon_ac97_mute_put, 1657 .put = aureon_ac97_mute_put,
1633 .private_value = AC97_CD 1658 .private_value = AC97_CD
1634 }, 1659 },
1635 { 1660 {
1636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1637 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1662 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1638 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1663 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1639 .name = "CD Playback Volume", 1664 .name = "CD Playback Volume",
1640 .info = aureon_ac97_vol_info, 1665 .info = aureon_ac97_vol_info,
1641 .get = aureon_ac97_vol_get, 1666 .get = aureon_ac97_vol_get,
1642 .put = aureon_ac97_vol_put, 1667 .put = aureon_ac97_vol_put,
1643 .private_value = AC97_CD|AUREON_AC97_STEREO, 1668 .private_value = AC97_CD|AUREON_AC97_STEREO,
1644 .tlv = { .p = db_scale_ac97_gain } 1669 .tlv = { .p = db_scale_ac97_gain }
1645 }, 1670 },
1646 { 1671 {
1647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1648 .name = "Aux Playback Switch", 1673 .name = "Aux Playback Switch",
1649 .info = aureon_ac97_mute_info, 1674 .info = aureon_ac97_mute_info,
1650 .get = aureon_ac97_mute_get, 1675 .get = aureon_ac97_mute_get,
1651 .put = aureon_ac97_mute_put, 1676 .put = aureon_ac97_mute_put,
1652 .private_value = AC97_AUX, 1677 .private_value = AC97_AUX,
1653 }, 1678 },
1654 { 1679 {
1655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1680 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1656 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1681 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1657 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1682 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1658 .name = "Aux Playback Volume", 1683 .name = "Aux Playback Volume",
1659 .info = aureon_ac97_vol_info, 1684 .info = aureon_ac97_vol_info,
1660 .get = aureon_ac97_vol_get, 1685 .get = aureon_ac97_vol_get,
1661 .put = aureon_ac97_vol_put, 1686 .put = aureon_ac97_vol_put,
1662 .private_value = AC97_AUX|AUREON_AC97_STEREO, 1687 .private_value = AC97_AUX|AUREON_AC97_STEREO,
1663 .tlv = { .p = db_scale_ac97_gain } 1688 .tlv = { .p = db_scale_ac97_gain }
1664 }, 1689 },
1665 { 1690 {
1666 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1667 .name = "Line Playback Switch", 1692 .name = "Line Playback Switch",
1668 .info = aureon_ac97_mute_info, 1693 .info = aureon_ac97_mute_info,
1669 .get = aureon_ac97_mute_get, 1694 .get = aureon_ac97_mute_get,
1670 .put = aureon_ac97_mute_put, 1695 .put = aureon_ac97_mute_put,
1671 .private_value = AC97_LINE 1696 .private_value = AC97_LINE
1672 }, 1697 },
1673 { 1698 {
1674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1675 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1700 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1676 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1701 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1677 .name = "Line Playback Volume", 1702 .name = "Line Playback Volume",
1678 .info = aureon_ac97_vol_info, 1703 .info = aureon_ac97_vol_info,
1679 .get = aureon_ac97_vol_get, 1704 .get = aureon_ac97_vol_get,
1680 .put = aureon_ac97_vol_put, 1705 .put = aureon_ac97_vol_put,
1681 .private_value = AC97_LINE|AUREON_AC97_STEREO, 1706 .private_value = AC97_LINE|AUREON_AC97_STEREO,
1682 .tlv = { .p = db_scale_ac97_gain } 1707 .tlv = { .p = db_scale_ac97_gain }
1683 }, 1708 },
1684 { 1709 {
1685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1710 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1686 .name = "Mic Playback Switch", 1711 .name = "Mic Playback Switch",
1687 .info = aureon_ac97_mute_info, 1712 .info = aureon_ac97_mute_info,
1688 .get = aureon_ac97_mute_get, 1713 .get = aureon_ac97_mute_get,
1689 .put = aureon_ac97_mute_put, 1714 .put = aureon_ac97_mute_put,
1690 .private_value = AC97_MIC 1715 .private_value = AC97_MIC
1691 }, 1716 },
1692 { 1717 {
1693 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1694 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1719 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1695 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1720 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1696 .name = "Mic Playback Volume", 1721 .name = "Mic Playback Volume",
1697 .info = aureon_ac97_vol_info, 1722 .info = aureon_ac97_vol_info,
1698 .get = aureon_ac97_vol_get, 1723 .get = aureon_ac97_vol_get,
1699 .put = aureon_ac97_vol_put, 1724 .put = aureon_ac97_vol_put,
1700 .private_value = AC97_MIC, 1725 .private_value = AC97_MIC,
1701 .tlv = { .p = db_scale_ac97_gain } 1726 .tlv = { .p = db_scale_ac97_gain }
1702 }, 1727 },
1703 { 1728 {
1704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1729 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1705 .name = "Mic Boost (+20dB)", 1730 .name = "Mic Boost (+20dB)",
1706 .info = aureon_ac97_micboost_info, 1731 .info = aureon_ac97_micboost_info,
1707 .get = aureon_ac97_micboost_get, 1732 .get = aureon_ac97_micboost_get,
1708 .put = aureon_ac97_micboost_put 1733 .put = aureon_ac97_micboost_put
1709 } 1734 }
1710}; 1735};
1711 1736
1712static struct snd_kcontrol_new universe_ac97_controls[] __devinitdata = { 1737static struct snd_kcontrol_new universe_ac97_controls[] __devinitdata = {
1713 { 1738 {
1714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1715 .name = "AC97 Playback Switch", 1740 .name = "AC97 Playback Switch",
1716 .info = aureon_ac97_mmute_info, 1741 .info = aureon_ac97_mmute_info,
1717 .get = aureon_ac97_mmute_get, 1742 .get = aureon_ac97_mmute_get,
1718 .put = aureon_ac97_mmute_put, 1743 .put = aureon_ac97_mmute_put,
1719 .private_value = AC97_MASTER 1744 .private_value = AC97_MASTER
1720 }, 1745 },
1721 { 1746 {
1722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1747 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1723 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1748 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1724 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1749 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1725 .name = "AC97 Playback Volume", 1750 .name = "AC97 Playback Volume",
1726 .info = aureon_ac97_vol_info, 1751 .info = aureon_ac97_vol_info,
1727 .get = aureon_ac97_vol_get, 1752 .get = aureon_ac97_vol_get,
1728 .put = aureon_ac97_vol_put, 1753 .put = aureon_ac97_vol_put,
1729 .private_value = AC97_MASTER|AUREON_AC97_STEREO, 1754 .private_value = AC97_MASTER|AUREON_AC97_STEREO,
1730 .tlv = { .p = db_scale_ac97_master } 1755 .tlv = { .p = db_scale_ac97_master }
1731 }, 1756 },
1732 { 1757 {
1733 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1734 .name = "CD Playback Switch", 1759 .name = "CD Playback Switch",
1735 .info = aureon_ac97_mute_info, 1760 .info = aureon_ac97_mute_info,
1736 .get = aureon_ac97_mute_get, 1761 .get = aureon_ac97_mute_get,
1737 .put = aureon_ac97_mute_put, 1762 .put = aureon_ac97_mute_put,
1738 .private_value = AC97_AUX 1763 .private_value = AC97_AUX
1739 }, 1764 },
1740 { 1765 {
1741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1742 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1767 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1743 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1768 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1744 .name = "CD Playback Volume", 1769 .name = "CD Playback Volume",
1745 .info = aureon_ac97_vol_info, 1770 .info = aureon_ac97_vol_info,
1746 .get = aureon_ac97_vol_get, 1771 .get = aureon_ac97_vol_get,
1747 .put = aureon_ac97_vol_put, 1772 .put = aureon_ac97_vol_put,
1748 .private_value = AC97_AUX|AUREON_AC97_STEREO, 1773 .private_value = AC97_AUX|AUREON_AC97_STEREO,
1749 .tlv = { .p = db_scale_ac97_gain } 1774 .tlv = { .p = db_scale_ac97_gain }
1750 }, 1775 },
1751 { 1776 {
1752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1777 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1753 .name = "Phono Playback Switch", 1778 .name = "Phono Playback Switch",
1754 .info = aureon_ac97_mute_info, 1779 .info = aureon_ac97_mute_info,
1755 .get = aureon_ac97_mute_get, 1780 .get = aureon_ac97_mute_get,
1756 .put = aureon_ac97_mute_put, 1781 .put = aureon_ac97_mute_put,
1757 .private_value = AC97_CD 1782 .private_value = AC97_CD
1758 }, 1783 },
1759 { 1784 {
1760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1761 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1786 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1762 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1787 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1763 .name = "Phono Playback Volume", 1788 .name = "Phono Playback Volume",
1764 .info = aureon_ac97_vol_info, 1789 .info = aureon_ac97_vol_info,
1765 .get = aureon_ac97_vol_get, 1790 .get = aureon_ac97_vol_get,
1766 .put = aureon_ac97_vol_put, 1791 .put = aureon_ac97_vol_put,
1767 .private_value = AC97_CD|AUREON_AC97_STEREO, 1792 .private_value = AC97_CD|AUREON_AC97_STEREO,
1768 .tlv = { .p = db_scale_ac97_gain } 1793 .tlv = { .p = db_scale_ac97_gain }
1769 }, 1794 },
1770 { 1795 {
1771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1772 .name = "Line Playback Switch", 1797 .name = "Line Playback Switch",
1773 .info = aureon_ac97_mute_info, 1798 .info = aureon_ac97_mute_info,
1774 .get = aureon_ac97_mute_get, 1799 .get = aureon_ac97_mute_get,
1775 .put = aureon_ac97_mute_put, 1800 .put = aureon_ac97_mute_put,
1776 .private_value = AC97_LINE 1801 .private_value = AC97_LINE
1777 }, 1802 },
1778 { 1803 {
1779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1780 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1805 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1781 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1806 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1782 .name = "Line Playback Volume", 1807 .name = "Line Playback Volume",
1783 .info = aureon_ac97_vol_info, 1808 .info = aureon_ac97_vol_info,
1784 .get = aureon_ac97_vol_get, 1809 .get = aureon_ac97_vol_get,
1785 .put = aureon_ac97_vol_put, 1810 .put = aureon_ac97_vol_put,
1786 .private_value = AC97_LINE|AUREON_AC97_STEREO, 1811 .private_value = AC97_LINE|AUREON_AC97_STEREO,
1787 .tlv = { .p = db_scale_ac97_gain } 1812 .tlv = { .p = db_scale_ac97_gain }
1788 }, 1813 },
1789 { 1814 {
1790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1791 .name = "Mic Playback Switch", 1816 .name = "Mic Playback Switch",
1792 .info = aureon_ac97_mute_info, 1817 .info = aureon_ac97_mute_info,
1793 .get = aureon_ac97_mute_get, 1818 .get = aureon_ac97_mute_get,
1794 .put = aureon_ac97_mute_put, 1819 .put = aureon_ac97_mute_put,
1795 .private_value = AC97_MIC 1820 .private_value = AC97_MIC
1796 }, 1821 },
1797 { 1822 {
1798 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1823 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1799 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1824 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1800 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1825 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1801 .name = "Mic Playback Volume", 1826 .name = "Mic Playback Volume",
1802 .info = aureon_ac97_vol_info, 1827 .info = aureon_ac97_vol_info,
1803 .get = aureon_ac97_vol_get, 1828 .get = aureon_ac97_vol_get,
1804 .put = aureon_ac97_vol_put, 1829 .put = aureon_ac97_vol_put,
1805 .private_value = AC97_MIC, 1830 .private_value = AC97_MIC,
1806 .tlv = { .p = db_scale_ac97_gain } 1831 .tlv = { .p = db_scale_ac97_gain }
1807 }, 1832 },
1808 { 1833 {
1809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1834 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1810 .name = "Mic Boost (+20dB)", 1835 .name = "Mic Boost (+20dB)",
1811 .info = aureon_ac97_micboost_info, 1836 .info = aureon_ac97_micboost_info,
1812 .get = aureon_ac97_micboost_get, 1837 .get = aureon_ac97_micboost_get,
1813 .put = aureon_ac97_micboost_put 1838 .put = aureon_ac97_micboost_put
1814 }, 1839 },
1815 { 1840 {
1816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1841 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1817 .name = "Aux Playback Switch", 1842 .name = "Aux Playback Switch",
1818 .info = aureon_ac97_mute_info, 1843 .info = aureon_ac97_mute_info,
1819 .get = aureon_ac97_mute_get, 1844 .get = aureon_ac97_mute_get,
1820 .put = aureon_ac97_mute_put, 1845 .put = aureon_ac97_mute_put,
1821 .private_value = AC97_VIDEO, 1846 .private_value = AC97_VIDEO,
1822 }, 1847 },
1823 { 1848 {
1824 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1825 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1850 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1826 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1851 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1827 .name = "Aux Playback Volume", 1852 .name = "Aux Playback Volume",
1828 .info = aureon_ac97_vol_info, 1853 .info = aureon_ac97_vol_info,
1829 .get = aureon_ac97_vol_get, 1854 .get = aureon_ac97_vol_get,
1830 .put = aureon_ac97_vol_put, 1855 .put = aureon_ac97_vol_put,
1831 .private_value = AC97_VIDEO|AUREON_AC97_STEREO, 1856 .private_value = AC97_VIDEO|AUREON_AC97_STEREO,
1832 .tlv = { .p = db_scale_ac97_gain } 1857 .tlv = { .p = db_scale_ac97_gain }
1833 }, 1858 },
1834 { 1859 {
1835 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1860 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1836 .name = "Aux Source", 1861 .name = "Aux Source",
@@ -1844,43 +1869,43 @@ static struct snd_kcontrol_new universe_ac97_controls[] __devinitdata = {
1844static struct snd_kcontrol_new cs8415_controls[] __devinitdata = { 1869static struct snd_kcontrol_new cs8415_controls[] __devinitdata = {
1845 { 1870 {
1846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1847 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 1872 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
1848 .info = aureon_cs8415_mute_info, 1873 .info = aureon_cs8415_mute_info,
1849 .get = aureon_cs8415_mute_get, 1874 .get = aureon_cs8415_mute_get,
1850 .put = aureon_cs8415_mute_put 1875 .put = aureon_cs8415_mute_put
1851 }, 1876 },
1852 { 1877 {
1853 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1854 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Source", 1879 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) "Source",
1855 .info = aureon_cs8415_mux_info, 1880 .info = aureon_cs8415_mux_info,
1856 .get = aureon_cs8415_mux_get, 1881 .get = aureon_cs8415_mux_get,
1857 .put = aureon_cs8415_mux_put, 1882 .put = aureon_cs8415_mux_put,
1858 }, 1883 },
1859 { 1884 {
1860 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1885 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1861 .name = SNDRV_CTL_NAME_IEC958("Q-subcode ",CAPTURE,DEFAULT), 1886 .name = SNDRV_CTL_NAME_IEC958("Q-subcode ", CAPTURE, DEFAULT),
1862 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1887 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1863 .info = aureon_cs8415_qsub_info, 1888 .info = aureon_cs8415_qsub_info,
1864 .get = aureon_cs8415_qsub_get, 1889 .get = aureon_cs8415_qsub_get,
1865 }, 1890 },
1866 { 1891 {
1867 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1892 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1868 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK), 1893 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
1869 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1894 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1870 .info = aureon_cs8415_spdif_info, 1895 .info = aureon_cs8415_spdif_info,
1871 .get = aureon_cs8415_mask_get 1896 .get = aureon_cs8415_mask_get
1872 }, 1897 },
1873 { 1898 {
1874 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1899 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1875 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), 1900 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
1876 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1901 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1877 .info = aureon_cs8415_spdif_info, 1902 .info = aureon_cs8415_spdif_info,
1878 .get = aureon_cs8415_spdif_get 1903 .get = aureon_cs8415_spdif_get
1879 }, 1904 },
1880 { 1905 {
1881 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1906 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1882 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Rate", 1907 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) "Rate",
1883 .access =SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1908 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
1884 .info = aureon_cs8415_rate_info, 1909 .info = aureon_cs8415_rate_info,
1885 .get = aureon_cs8415_rate_get 1910 .get = aureon_cs8415_rate_get
1886 } 1911 }
@@ -1905,15 +1930,14 @@ static int __devinit aureon_add_controls(struct snd_ice1712 *ice)
1905 if (err < 0) 1930 if (err < 0)
1906 return err; 1931 return err;
1907 } 1932 }
1908 1933
1909 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) { 1934 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) {
1910 for (i = 0; i < ARRAY_SIZE(universe_ac97_controls); i++) { 1935 for (i = 0; i < ARRAY_SIZE(universe_ac97_controls); i++) {
1911 err = snd_ctl_add(ice->card, snd_ctl_new1(&universe_ac97_controls[i], ice)); 1936 err = snd_ctl_add(ice->card, snd_ctl_new1(&universe_ac97_controls[i], ice));
1912 if (err < 0) 1937 if (err < 0)
1913 return err; 1938 return err;
1914 } 1939 }
1915 } 1940 } else if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
1916 else if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
1917 ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT) { 1941 ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT) {
1918 for (i = 0; i < ARRAY_SIZE(ac97_controls); i++) { 1942 for (i = 0; i < ARRAY_SIZE(ac97_controls); i++) {
1919 err = snd_ctl_add(ice->card, snd_ctl_new1(&ac97_controls[i], ice)); 1943 err = snd_ctl_add(ice->card, snd_ctl_new1(&ac97_controls[i], ice));
@@ -1932,7 +1956,7 @@ static int __devinit aureon_add_controls(struct snd_ice1712 *ice)
1932 else if ((id & 0x0F) != 0x01) 1956 else if ((id & 0x0F) != 0x01)
1933 snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1)); 1957 snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1));
1934 else { 1958 else {
1935 for (i = 0; i< ARRAY_SIZE(cs8415_controls); i++) { 1959 for (i = 0; i < ARRAY_SIZE(cs8415_controls); i++) {
1936 struct snd_kcontrol *kctl; 1960 struct snd_kcontrol *kctl;
1937 err = snd_ctl_add(ice->card, (kctl = snd_ctl_new1(&cs8415_controls[i], ice))); 1961 err = snd_ctl_add(ice->card, (kctl = snd_ctl_new1(&cs8415_controls[i], ice)));
1938 if (err < 0) 1962 if (err < 0)
@@ -1943,7 +1967,7 @@ static int __devinit aureon_add_controls(struct snd_ice1712 *ice)
1943 } 1967 }
1944 snd_ice1712_restore_gpio_status(ice); 1968 snd_ice1712_restore_gpio_status(ice);
1945 } 1969 }
1946 1970
1947 return 0; 1971 return 0;
1948} 1972}
1949 1973
@@ -2059,11 +2083,12 @@ static int __devinit aureon_init(struct snd_ice1712 *ice)
2059 2083
2060 /* to remeber the register values of CS8415 */ 2084 /* to remeber the register values of CS8415 */
2061 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); 2085 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
2062 if (! ice->akm) 2086 if (!ice->akm)
2063 return -ENOMEM; 2087 return -ENOMEM;
2064 ice->akm_codecs = 1; 2088 ice->akm_codecs = 1;
2065 2089
2066 if ((err = aureon_ac97_init(ice)) != 0) 2090 err = aureon_ac97_init(ice);
2091 if (err != 0)
2067 return err; 2092 return err;
2068 2093
2069 snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */ 2094 snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */
@@ -2086,7 +2111,7 @@ static int __devinit aureon_init(struct snd_ice1712 *ice)
2086 /* initialize WM8770 codec */ 2111 /* initialize WM8770 codec */
2087 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71 || 2112 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71 ||
2088 ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT || 2113 ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT ||
2089 ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT) 2114 ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT)
2090 p = wm_inits_prodigy; 2115 p = wm_inits_prodigy;
2091 else 2116 else
2092 p = wm_inits_aureon; 2117 p = wm_inits_aureon;
@@ -2105,10 +2130,10 @@ static int __devinit aureon_init(struct snd_ice1712 *ice)
2105 2130
2106 snd_ice1712_restore_gpio_status(ice); 2131 snd_ice1712_restore_gpio_status(ice);
2107 2132
2108 /* initialize PCA9554 pin directions & set default input*/ 2133 /* initialize PCA9554 pin directions & set default input */
2109 aureon_pca9554_write(ice, PCA9554_DIR, 0x00); 2134 aureon_pca9554_write(ice, PCA9554_DIR, 0x00);
2110 aureon_pca9554_write(ice, PCA9554_OUT, 0x00); /* internal AUX */ 2135 aureon_pca9554_write(ice, PCA9554_OUT, 0x00); /* internal AUX */
2111 2136
2112 spec->master[0] = WM_VOL_MUTE; 2137 spec->master[0] = WM_VOL_MUTE;
2113 spec->master[1] = WM_VOL_MUTE; 2138 spec->master[1] = WM_VOL_MUTE;
2114 for (i = 0; i < ice->num_total_dacs; i++) { 2139 for (i = 0; i < ice->num_total_dacs; i++) {
@@ -2158,6 +2183,24 @@ static unsigned char aureon71_eeprom[] __devinitdata = {
2158}; 2183};
2159#define prodigy71_eeprom aureon71_eeprom 2184#define prodigy71_eeprom aureon71_eeprom
2160 2185
2186static unsigned char aureon71_universe_eeprom[] __devinitdata = {
2187 [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, spdif-in/ADC,
2188 * 4DACs
2189 */
2190 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
2191 [ICE_EEP2_I2S] = 0xfc, /* vol, 96k, 24bit, 192k */
2192 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
2193 [ICE_EEP2_GPIO_DIR] = 0xff,
2194 [ICE_EEP2_GPIO_DIR1] = 0xff,
2195 [ICE_EEP2_GPIO_DIR2] = 0x5f,
2196 [ICE_EEP2_GPIO_MASK] = 0x00,
2197 [ICE_EEP2_GPIO_MASK1] = 0x00,
2198 [ICE_EEP2_GPIO_MASK2] = 0x00,
2199 [ICE_EEP2_GPIO_STATE] = 0x00,
2200 [ICE_EEP2_GPIO_STATE1] = 0x00,
2201 [ICE_EEP2_GPIO_STATE2] = 0x00,
2202};
2203
2161static unsigned char prodigy71lt_eeprom[] __devinitdata = { 2204static unsigned char prodigy71lt_eeprom[] __devinitdata = {
2162 [ICE_EEP2_SYSCONF] = 0x4b, /* clock 384, spdif-in/ADC, 4DACs */ 2205 [ICE_EEP2_SYSCONF] = 0x4b, /* clock 384, spdif-in/ADC, 4DACs */
2163 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 2206 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
@@ -2197,14 +2240,14 @@ struct snd_ice1712_card_info snd_vt1724_aureon_cards[] __devinitdata = {
2197 .eeprom_data = aureon71_eeprom, 2240 .eeprom_data = aureon71_eeprom,
2198 .driver = "Aureon71", 2241 .driver = "Aureon71",
2199 }, 2242 },
2200 { 2243 {
2201 .subvendor = VT1724_SUBDEVICE_AUREON71_UNIVERSE, 2244 .subvendor = VT1724_SUBDEVICE_AUREON71_UNIVERSE,
2202 .name = "Terratec Aureon 7.1-Universe", 2245 .name = "Terratec Aureon 7.1-Universe",
2203 .model = "universe", 2246 .model = "universe",
2204 .chip_init = aureon_init, 2247 .chip_init = aureon_init,
2205 .build_controls = aureon_add_controls, 2248 .build_controls = aureon_add_controls,
2206 .eeprom_size = sizeof(aureon71_eeprom), 2249 .eeprom_size = sizeof(aureon71_universe_eeprom),
2207 .eeprom_data = aureon71_eeprom, 2250 .eeprom_data = aureon71_universe_eeprom,
2208 .driver = "Aureon71Univ", /* keep in 15 letters */ 2251 .driver = "Aureon71Univ", /* keep in 15 letters */
2209 }, 2252 },
2210 { 2253 {
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index 0ed96c178059..d216362626d0 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -400,7 +400,7 @@ static void delta_setup_spdif(struct snd_ice1712 *ice, int rate)
400static int snd_ice1712_delta1010lt_wordclock_status_get(struct snd_kcontrol *kcontrol, 400static int snd_ice1712_delta1010lt_wordclock_status_get(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_value *ucontrol) 401 struct snd_ctl_elem_value *ucontrol)
402{ 402{
403 char reg = 0x10; // cs8427 receiver error register 403 char reg = 0x10; /* CS8427 receiver error register */
404 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 404 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
405 405
406 if (snd_i2c_sendbytes(ice->cs8427, &reg, 1) != 1) 406 if (snd_i2c_sendbytes(ice->cs8427, &reg, 1) != 1)
diff --git a/sound/pci/ice1712/delta.h b/sound/pci/ice1712/delta.h
index ea7116c304c0..f7f14df81f26 100644
--- a/sound/pci/ice1712/delta.h
+++ b/sound/pci/ice1712/delta.h
@@ -31,6 +31,7 @@
31 "{MidiMan M Audio,Delta DiO 2496},"\ 31 "{MidiMan M Audio,Delta DiO 2496},"\
32 "{MidiMan M Audio,Delta 66},"\ 32 "{MidiMan M Audio,Delta 66},"\
33 "{MidiMan M Audio,Delta 44},"\ 33 "{MidiMan M Audio,Delta 44},"\
34 "{MidiMan M Audio,Delta 410},"\
34 "{MidiMan M Audio,Audiophile 24/96},"\ 35 "{MidiMan M Audio,Audiophile 24/96},"\
35 "{Digigram,VX442},"\ 36 "{Digigram,VX442},"\
36 "{Lionstracs,Mediastation}," 37 "{Lionstracs,Mediastation},"
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index 013fc4f04822..6fe35b812040 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -149,7 +149,8 @@ static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mas
149 struct ews_spec *spec = ice->spec; 149 struct ews_spec *spec = ice->spec;
150 unsigned char data, ndata; 150 unsigned char data, ndata;
151 151
152 snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return -EINVAL); 152 if (snd_BUG_ON(chip_mask < 0 || chip_mask > 0x0f))
153 return -EINVAL;
153 snd_i2c_lock(ice->i2c); 154 snd_i2c_lock(ice->i2c);
154 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) 155 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1)
155 goto __error; 156 goto __error;
@@ -685,7 +686,8 @@ static int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, st
685 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 686 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
686 unsigned char data; 687 unsigned char data;
687 688
688 snd_assert(channel >= 0 && channel <= 7, return 0); 689 if (snd_BUG_ON(channel < 0 || channel > 7))
690 return 0;
689 snd_i2c_lock(ice->i2c); 691 snd_i2c_lock(ice->i2c);
690 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) { 692 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
691 snd_i2c_unlock(ice->i2c); 693 snd_i2c_unlock(ice->i2c);
@@ -705,7 +707,8 @@ static int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, st
705 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 707 int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
706 unsigned char data, ndata; 708 unsigned char data, ndata;
707 709
708 snd_assert(channel >= 0 && channel <= 7, return 0); 710 if (snd_BUG_ON(channel < 0 || channel > 7))
711 return 0;
709 snd_i2c_lock(ice->i2c); 712 snd_i2c_lock(ice->i2c);
710 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) { 713 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
711 snd_i2c_unlock(ice->i2c); 714 snd_i2c_unlock(ice->i2c);
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 29d449d73c98..5b442383fcda 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -17,7 +17,7 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 */ 20 */
21 21
22/* 22/*
23 NOTES: 23 NOTES:
@@ -35,7 +35,7 @@
35 * 35 *
36 * 2002.11.26 James Stafford <jstafford@ampltd.com> 36 * 2002.11.26 James Stafford <jstafford@ampltd.com>
37 * Added support for VT1724 (Envy24HT) 37 * Added support for VT1724 (Envy24HT)
38 * I have left out support for 176.4 and 192 KHz for the moment. 38 * I have left out support for 176.4 and 192 KHz for the moment.
39 * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401 39 * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
40 * 40 *
41 * 2003.02.20 Taksahi Iwai <tiwai@suse.de> 41 * 2003.02.20 Taksahi Iwai <tiwai@suse.de>
@@ -47,7 +47,7 @@
47 */ 47 */
48 48
49 49
50#include <asm/io.h> 50#include <linux/io.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53#include <linux/init.h> 53#include <linux/init.h>
@@ -123,7 +123,7 @@ static unsigned int PRO_RATE_DEFAULT = 44100;
123/* 123/*
124 * Basic I/O 124 * Basic I/O
125 */ 125 */
126 126
127/* check whether the clock mode is spdif-in */ 127/* check whether the clock mode is spdif-in */
128static inline int is_spdif_master(struct snd_ice1712 *ice) 128static inline int is_spdif_master(struct snd_ice1712 *ice)
129{ 129{
@@ -135,13 +135,13 @@ static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
135 return is_spdif_master(ice) || PRO_RATE_LOCKED; 135 return is_spdif_master(ice) || PRO_RATE_LOCKED;
136} 136}
137 137
138static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data) 138static inline void snd_ice1712_ds_write(struct snd_ice1712 *ice, u8 channel, u8 addr, u32 data)
139{ 139{
140 outb((channel << 4) | addr, ICEDS(ice, INDEX)); 140 outb((channel << 4) | addr, ICEDS(ice, INDEX));
141 outl(data, ICEDS(ice, DATA)); 141 outl(data, ICEDS(ice, DATA));
142} 142}
143 143
144static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr) 144static inline u32 snd_ice1712_ds_read(struct snd_ice1712 *ice, u8 channel, u8 addr)
145{ 145{
146 outb((channel << 4) | addr, ICEDS(ice, INDEX)); 146 outb((channel << 4) | addr, ICEDS(ice, INDEX));
147 return inl(ICEDS(ice, DATA)); 147 return inl(ICEDS(ice, DATA));
@@ -260,7 +260,7 @@ static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
260static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 260static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
261{ 261{
262 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 262 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
263 263
264 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0; 264 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
265 return 0; 265 return 0;
266} 266}
@@ -269,11 +269,12 @@ static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, stru
269{ 269{
270 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 270 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
271 unsigned char val, nval; 271 unsigned char val, nval;
272 272
273 spin_lock_irq(&ice->reg_lock); 273 spin_lock_irq(&ice->reg_lock);
274 val = inb(ICEMT(ice, MONITOR_ROUTECTRL)); 274 val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
275 nval = val & ~ICE1712_ROUTE_AC97; 275 nval = val & ~ICE1712_ROUTE_AC97;
276 if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97; 276 if (ucontrol->value.integer.value[0])
277 nval |= ICE1712_ROUTE_AC97;
277 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL)); 278 outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
278 spin_unlock_irq(&ice->reg_lock); 279 spin_unlock_irq(&ice->reg_lock);
279 return val != nval; 280 return val != nval;
@@ -329,7 +330,7 @@ static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif
329 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */ 330 unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
330 unsigned char val, nval; 331 unsigned char val, nval;
331 int res = 0; 332 int res = 0;
332 333
333 snd_i2c_lock(ice->i2c); 334 snd_i2c_lock(ice->i2c);
334 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) { 335 if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
335 snd_i2c_unlock(ice->i2c); 336 snd_i2c_unlock(ice->i2c);
@@ -381,9 +382,9 @@ int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
381{ 382{
382 int err; 383 int err;
383 384
384 if ((err = snd_cs8427_create(ice->i2c, addr, 385 err = snd_cs8427_create(ice->i2c, addr,
385 (ice->cs8427_timeout * HZ) / 1000, 386 (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427);
386 &ice->cs8427)) < 0) { 387 if (err < 0) {
387 snd_printk(KERN_ERR "CS8427 initialization failed\n"); 388 snd_printk(KERN_ERR "CS8427 initialization failed\n");
388 return err; 389 return err;
389 } 390 }
@@ -395,9 +396,9 @@ int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
395 396
396static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master) 397static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master)
397{ 398{
398 /* change CS8427 clock source too */ 399 /* change CS8427 clock source too */
399 if (ice->cs8427) 400 if (ice->cs8427)
400 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master); 401 snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
401 /* notify ak4524 chip as well */ 402 /* notify ak4524 chip as well */
402 if (spdif_is_master) { 403 if (spdif_is_master) {
403 unsigned int i; 404 unsigned int i;
@@ -457,11 +458,12 @@ static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id)
457 u16 pbkstatus; 458 u16 pbkstatus;
458 struct snd_pcm_substream *substream; 459 struct snd_pcm_substream *substream;
459 pbkstatus = inw(ICEDS(ice, INTSTAT)); 460 pbkstatus = inw(ICEDS(ice, INTSTAT));
460 //printk("pbkstatus = 0x%x\n", pbkstatus); 461 /* printk("pbkstatus = 0x%x\n", pbkstatus); */
461 for (idx = 0; idx < 6; idx++) { 462 for (idx = 0; idx < 6; idx++) {
462 if ((pbkstatus & (3 << (idx * 2))) == 0) 463 if ((pbkstatus & (3 << (idx * 2))) == 0)
463 continue; 464 continue;
464 if ((substream = ice->playback_con_substream_ds[idx]) != NULL) 465 substream = ice->playback_con_substream_ds[idx];
466 if (substream != NULL)
465 snd_pcm_period_elapsed(substream); 467 snd_pcm_period_elapsed(substream);
466 outw(3 << (idx * 2), ICEDS(ice, INTSTAT)); 468 outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
467 } 469 }
@@ -507,7 +509,7 @@ static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
507 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 509 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
508 int result = 0; 510 int result = 0;
509 u32 tmp; 511 u32 tmp;
510 512
511 spin_lock(&ice->reg_lock); 513 spin_lock(&ice->reg_lock);
512 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL); 514 tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
513 if (cmd == SNDRV_PCM_TRIGGER_START) { 515 if (cmd == SNDRV_PCM_TRIGGER_START) {
@@ -532,7 +534,7 @@ static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
532 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 534 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
533 int result = 0; 535 int result = 0;
534 u32 tmp; 536 u32 tmp;
535 537
536 spin_lock(&ice->reg_lock); 538 spin_lock(&ice->reg_lock);
537 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL); 539 tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
538 if (cmd == SNDRV_PCM_TRIGGER_START) { 540 if (cmd == SNDRV_PCM_TRIGGER_START) {
@@ -557,7 +559,7 @@ static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
557 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 559 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
558 int result = 0; 560 int result = 0;
559 u8 tmp; 561 u8 tmp;
560 562
561 spin_lock(&ice->reg_lock); 563 spin_lock(&ice->reg_lock);
562 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL); 564 tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
563 if (cmd == SNDRV_PCM_TRIGGER_START) { 565 if (cmd == SNDRV_PCM_TRIGGER_START) {
@@ -711,8 +713,7 @@ static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *s
711 return bytes_to_frames(substream->runtime, ptr); 713 return bytes_to_frames(substream->runtime, ptr);
712} 714}
713 715
714static const struct snd_pcm_hardware snd_ice1712_playback = 716static const struct snd_pcm_hardware snd_ice1712_playback = {
715{
716 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 717 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
717 SNDRV_PCM_INFO_BLOCK_TRANSFER | 718 SNDRV_PCM_INFO_BLOCK_TRANSFER |
718 SNDRV_PCM_INFO_MMAP_VALID | 719 SNDRV_PCM_INFO_MMAP_VALID |
@@ -731,8 +732,7 @@ static const struct snd_pcm_hardware snd_ice1712_playback =
731 .fifo_size = 0, 732 .fifo_size = 0,
732}; 733};
733 734
734static const struct snd_pcm_hardware snd_ice1712_playback_ds = 735static const struct snd_pcm_hardware snd_ice1712_playback_ds = {
735{
736 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 736 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
737 SNDRV_PCM_INFO_BLOCK_TRANSFER | 737 SNDRV_PCM_INFO_BLOCK_TRANSFER |
738 SNDRV_PCM_INFO_MMAP_VALID | 738 SNDRV_PCM_INFO_MMAP_VALID |
@@ -751,8 +751,7 @@ static const struct snd_pcm_hardware snd_ice1712_playback_ds =
751 .fifo_size = 0, 751 .fifo_size = 0,
752}; 752};
753 753
754static const struct snd_pcm_hardware snd_ice1712_capture = 754static const struct snd_pcm_hardware snd_ice1712_capture = {
755{
756 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 755 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
757 SNDRV_PCM_INFO_BLOCK_TRANSFER | 756 SNDRV_PCM_INFO_BLOCK_TRANSFER |
758 SNDRV_PCM_INFO_MMAP_VALID), 757 SNDRV_PCM_INFO_MMAP_VALID),
@@ -788,7 +787,7 @@ static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
788 787
789 ice->playback_con_substream_ds[substream->number] = substream; 788 ice->playback_con_substream_ds[substream->number] = substream;
790 runtime->hw = snd_ice1712_playback_ds; 789 runtime->hw = snd_ice1712_playback_ds;
791 spin_lock_irq(&ice->reg_lock); 790 spin_lock_irq(&ice->reg_lock);
792 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2)); 791 tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
793 outw(tmp, ICEDS(ice, INTMASK)); 792 outw(tmp, ICEDS(ice, INTMASK));
794 spin_unlock_irq(&ice->reg_lock); 793 spin_unlock_irq(&ice->reg_lock);
@@ -821,7 +820,7 @@ static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
821 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 820 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
822 u32 tmp; 821 u32 tmp;
823 822
824 spin_lock_irq(&ice->reg_lock); 823 spin_lock_irq(&ice->reg_lock);
825 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2)); 824 tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
826 outw(tmp, ICEDS(ice, INTMASK)); 825 outw(tmp, ICEDS(ice, INTMASK));
827 spin_unlock_irq(&ice->reg_lock); 826 spin_unlock_irq(&ice->reg_lock);
@@ -870,7 +869,7 @@ static struct snd_pcm_ops snd_ice1712_capture_ops = {
870 .pointer = snd_ice1712_capture_pointer, 869 .pointer = snd_ice1712_capture_pointer,
871}; 870};
872 871
873static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm) 872static int __devinit snd_ice1712_pcm(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
874{ 873{
875 struct snd_pcm *pcm; 874 struct snd_pcm *pcm;
876 int err; 875 int err;
@@ -900,7 +899,7 @@ static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struc
900 return 0; 899 return 0;
901} 900}
902 901
903static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm) 902static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
904{ 903{
905 struct snd_pcm *pcm; 904 struct snd_pcm *pcm;
906 int err; 905 int err;
@@ -1029,14 +1028,14 @@ static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
1029 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW| 1028 if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
1030 ICE1712_PLAYBACK_PAUSE| 1029 ICE1712_PLAYBACK_PAUSE|
1031 ICE1712_PLAYBACK_START)) { 1030 ICE1712_PLAYBACK_START)) {
1032 __out: 1031__out:
1033 spin_unlock_irqrestore(&ice->reg_lock, flags); 1032 spin_unlock_irqrestore(&ice->reg_lock, flags);
1034 return; 1033 return;
1035 } 1034 }
1036 if (!force && is_pro_rate_locked(ice)) 1035 if (!force && is_pro_rate_locked(ice))
1037 goto __out; 1036 goto __out;
1038 1037
1039 old = inb(ICEMT(ice, RATE)); 1038 old = inb(ICEMT(ice, RATE));
1040 if (!force && old == val) 1039 if (!force && old == val)
1041 goto __out; 1040 goto __out;
1042 outb(val, ICEMT(ice, RATE)); 1041 outb(val, ICEMT(ice, RATE));
@@ -1123,8 +1122,7 @@ static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substrea
1123 return bytes_to_frames(substream->runtime, ptr); 1122 return bytes_to_frames(substream->runtime, ptr);
1124} 1123}
1125 1124
1126static const struct snd_pcm_hardware snd_ice1712_playback_pro = 1125static const struct snd_pcm_hardware snd_ice1712_playback_pro = {
1127{
1128 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1126 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1129 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1127 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1130 SNDRV_PCM_INFO_MMAP_VALID | 1128 SNDRV_PCM_INFO_MMAP_VALID |
@@ -1143,8 +1141,7 @@ static const struct snd_pcm_hardware snd_ice1712_playback_pro =
1143 .fifo_size = 0, 1141 .fifo_size = 0,
1144}; 1142};
1145 1143
1146static const struct snd_pcm_hardware snd_ice1712_capture_pro = 1144static const struct snd_pcm_hardware snd_ice1712_capture_pro = {
1147{
1148 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1145 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1149 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1146 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1150 SNDRV_PCM_INFO_MMAP_VALID | 1147 SNDRV_PCM_INFO_MMAP_VALID |
@@ -1238,7 +1235,7 @@ static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
1238 .pointer = snd_ice1712_capture_pro_pointer, 1235 .pointer = snd_ice1712_capture_pro_pointer,
1239}; 1236};
1240 1237
1241static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm) 1238static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm)
1242{ 1239{
1243 struct snd_pcm *pcm; 1240 struct snd_pcm *pcm;
1244 int err; 1241 int err;
@@ -1262,7 +1259,7 @@ static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device,
1262 ice->pcm_pro = pcm; 1259 ice->pcm_pro = pcm;
1263 if (rpcm) 1260 if (rpcm)
1264 *rpcm = pcm; 1261 *rpcm = pcm;
1265 1262
1266 if (ice->cs8427) { 1263 if (ice->cs8427) {
1267 /* assign channels to iec958 */ 1264 /* assign channels to iec958 */
1268 err = snd_cs8427_iec958_build(ice->cs8427, 1265 err = snd_cs8427_iec958_build(ice->cs8427,
@@ -1272,7 +1269,8 @@ static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device,
1272 return err; 1269 return err;
1273 } 1270 }
1274 1271
1275 if ((err = snd_ice1712_build_pro_mixer(ice)) < 0) 1272 err = snd_ice1712_build_pro_mixer(ice);
1273 if (err < 0)
1276 return err; 1274 return err;
1277 return 0; 1275 return 0;
1278} 1276}
@@ -1299,7 +1297,7 @@ static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struc
1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1297 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1300 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + 1298 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1301 kcontrol->private_value; 1299 kcontrol->private_value;
1302 1300
1303 spin_lock_irq(&ice->reg_lock); 1301 spin_lock_irq(&ice->reg_lock);
1304 ucontrol->value.integer.value[0] = 1302 ucontrol->value.integer.value[0] =
1305 !((ice->pro_volumes[priv_idx] >> 15) & 1); 1303 !((ice->pro_volumes[priv_idx] >> 15) & 1);
@@ -1341,7 +1339,7 @@ static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struc
1341 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1339 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1342 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + 1340 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1343 kcontrol->private_value; 1341 kcontrol->private_value;
1344 1342
1345 spin_lock_irq(&ice->reg_lock); 1343 spin_lock_irq(&ice->reg_lock);
1346 ucontrol->value.integer.value[0] = 1344 ucontrol->value.integer.value[0] =
1347 (ice->pro_volumes[priv_idx] >> 0) & 127; 1345 (ice->pro_volumes[priv_idx] >> 0) & 127;
@@ -1406,7 +1404,7 @@ static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinit
1406 1404
1407static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = { 1405static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
1408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1406 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1409 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH), 1407 .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, SWITCH),
1410 .info = snd_ice1712_pro_mixer_switch_info, 1408 .info = snd_ice1712_pro_mixer_switch_info,
1411 .get = snd_ice1712_pro_mixer_switch_get, 1409 .get = snd_ice1712_pro_mixer_switch_get,
1412 .put = snd_ice1712_pro_mixer_switch_put, 1410 .put = snd_ice1712_pro_mixer_switch_put,
@@ -1428,7 +1426,7 @@ static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinit
1428 1426
1429static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = { 1427static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
1430 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1431 .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME), 1429 .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, VOLUME),
1432 .info = snd_ice1712_pro_mixer_volume_info, 1430 .info = snd_ice1712_pro_mixer_volume_info,
1433 .get = snd_ice1712_pro_mixer_volume_get, 1431 .get = snd_ice1712_pro_mixer_volume_get,
1434 .put = snd_ice1712_pro_mixer_volume_put, 1432 .put = snd_ice1712_pro_mixer_volume_put,
@@ -1448,7 +1446,7 @@ static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
1448 if (err < 0) 1446 if (err < 0)
1449 return err; 1447 return err;
1450 } 1448 }
1451 1449
1452 if (ice->num_total_adcs > 0) { 1450 if (ice->num_total_adcs > 0) {
1453 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch; 1451 struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
1454 tmp.count = ice->num_total_adcs; 1452 tmp.count = ice->num_total_adcs;
@@ -1495,7 +1493,7 @@ static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
1495 ice->ac97 = NULL; 1493 ice->ac97 = NULL;
1496} 1494}
1497 1495
1498static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice) 1496static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 *ice)
1499{ 1497{
1500 int err, bus_num = 0; 1498 int err, bus_num = 0;
1501 struct snd_ac97_template ac97; 1499 struct snd_ac97_template ac97;
@@ -1510,27 +1508,32 @@ static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
1510 }; 1508 };
1511 1509
1512 if (ice_has_con_ac97(ice)) { 1510 if (ice_has_con_ac97(ice)) {
1513 if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0) 1511 err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus);
1512 if (err < 0)
1514 return err; 1513 return err;
1515 memset(&ac97, 0, sizeof(ac97)); 1514 memset(&ac97, 0, sizeof(ac97));
1516 ac97.private_data = ice; 1515 ac97.private_data = ice;
1517 ac97.private_free = snd_ice1712_mixer_free_ac97; 1516 ac97.private_free = snd_ice1712_mixer_free_ac97;
1518 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0) 1517 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1518 if (err < 0)
1519 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n"); 1519 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
1520 else { 1520 else {
1521 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0) 1521 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice));
1522 if (err < 0)
1522 return err; 1523 return err;
1523 return 0; 1524 return 0;
1524 } 1525 }
1525 } 1526 }
1526 1527
1527 if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) { 1528 if (!(ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
1528 if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0) 1529 err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus);
1530 if (err < 0)
1529 return err; 1531 return err;
1530 memset(&ac97, 0, sizeof(ac97)); 1532 memset(&ac97, 0, sizeof(ac97));
1531 ac97.private_data = ice; 1533 ac97.private_data = ice;
1532 ac97.private_free = snd_ice1712_mixer_free_ac97; 1534 ac97.private_free = snd_ice1712_mixer_free_ac97;
1533 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0) 1535 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1536 if (err < 0)
1534 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n"); 1537 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1535 else 1538 else
1536 return 0; 1539 return 0;
@@ -1549,7 +1552,7 @@ static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
1549 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8); 1552 return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
1550} 1553}
1551 1554
1552static void snd_ice1712_proc_read(struct snd_info_entry *entry, 1555static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1553 struct snd_info_buffer *buffer) 1556 struct snd_info_buffer *buffer)
1554{ 1557{
1555 struct snd_ice1712 *ice = entry->private_data; 1558 struct snd_ice1712 *ice = entry->private_data;
@@ -1585,15 +1588,15 @@ static void snd_ice1712_proc_read(struct snd_info_entry *entry,
1585 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT))); 1588 snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
1586 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE))); 1589 snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
1587 snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice)); 1590 snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice));
1588 snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK)); 1591 snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK));
1589 snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION)); 1592 snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION));
1590} 1593}
1591 1594
1592static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice) 1595static void __devinit snd_ice1712_proc_init(struct snd_ice1712 *ice)
1593{ 1596{
1594 struct snd_info_entry *entry; 1597 struct snd_info_entry *entry;
1595 1598
1596 if (! snd_card_proc_new(ice->card, "ice1712", &entry)) 1599 if (!snd_card_proc_new(ice->card, "ice1712", &entry))
1597 snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read); 1600 snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
1598} 1601}
1599 1602
@@ -1613,7 +1616,7 @@ static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
1613 struct snd_ctl_elem_value *ucontrol) 1616 struct snd_ctl_elem_value *ucontrol)
1614{ 1617{
1615 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1618 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1616 1619
1617 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom)); 1620 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1618 return 0; 1621 return 0;
1619} 1622}
@@ -1641,7 +1644,7 @@ static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
1641{ 1644{
1642 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1645 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1643 if (ice->spdif.ops.default_get) 1646 if (ice->spdif.ops.default_get)
1644 ice->spdif.ops.default_get(ice, ucontrol); 1647 ice->spdif.ops.default_get(ice, ucontrol);
1645 return 0; 1648 return 0;
1646} 1649}
1647 1650
@@ -1657,7 +1660,7 @@ static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
1657static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata = 1660static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
1658{ 1661{
1659 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1662 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1660 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 1663 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1661 .info = snd_ice1712_spdif_info, 1664 .info = snd_ice1712_spdif_info,
1662 .get = snd_ice1712_spdif_default_get, 1665 .get = snd_ice1712_spdif_default_get,
1663 .put = snd_ice1712_spdif_default_put 1666 .put = snd_ice1712_spdif_default_put
@@ -1709,7 +1712,7 @@ static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
1709{ 1712{
1710 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1713 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1711 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1714 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1712 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 1715 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
1713 .info = snd_ice1712_spdif_info, 1716 .info = snd_ice1712_spdif_info,
1714 .get = snd_ice1712_spdif_maskc_get, 1717 .get = snd_ice1712_spdif_maskc_get,
1715}; 1718};
@@ -1718,7 +1721,7 @@ static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
1718{ 1721{
1719 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1722 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1720 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1723 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1721 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), 1724 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
1722 .info = snd_ice1712_spdif_info, 1725 .info = snd_ice1712_spdif_info,
1723 .get = snd_ice1712_spdif_maskp_get, 1726 .get = snd_ice1712_spdif_maskp_get,
1724}; 1727};
@@ -1746,7 +1749,7 @@ static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
1746 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1749 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1747 SNDRV_CTL_ELEM_ACCESS_INACTIVE), 1750 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
1748 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1751 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1749 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), 1752 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
1750 .info = snd_ice1712_spdif_info, 1753 .info = snd_ice1712_spdif_info,
1751 .get = snd_ice1712_spdif_stream_get, 1754 .get = snd_ice1712_spdif_stream_get,
1752 .put = snd_ice1712_spdif_stream_put 1755 .put = snd_ice1712_spdif_stream_put
@@ -1758,7 +1761,7 @@ int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
1758 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1761 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1759 unsigned char mask = kcontrol->private_value & 0xff; 1762 unsigned char mask = kcontrol->private_value & 0xff;
1760 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0; 1763 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1761 1764
1762 snd_ice1712_save_gpio_status(ice); 1765 snd_ice1712_save_gpio_status(ice);
1763 ucontrol->value.integer.value[0] = 1766 ucontrol->value.integer.value[0] =
1764 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert; 1767 (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
@@ -1825,7 +1828,7 @@ static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1825 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10 1828 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
1826 }; 1829 };
1827 unsigned char val; 1830 unsigned char val;
1828 1831
1829 spin_lock_irq(&ice->reg_lock); 1832 spin_lock_irq(&ice->reg_lock);
1830 if (is_spdif_master(ice)) { 1833 if (is_spdif_master(ice)) {
1831 ucontrol->value.enumerated.item[0] = 13; 1834 ucontrol->value.enumerated.item[0] = 13;
@@ -1867,7 +1870,7 @@ static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1867 1870
1868 if ((oval & ICE1712_SPDIF_MASTER) != 1871 if ((oval & ICE1712_SPDIF_MASTER) !=
1869 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) 1872 (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
1870 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice)); 1873 snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
1871 1874
1872 return change; 1875 return change;
1873} 1876}
@@ -1897,7 +1900,7 @@ static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcon
1897 "64000", /* 10: 15 */ 1900 "64000", /* 10: 15 */
1898 "88200", /* 11: 11 */ 1901 "88200", /* 11: 11 */
1899 "96000", /* 12: 7 */ 1902 "96000", /* 12: 7 */
1900 // "IEC958 Input", /* 13: -- */ 1903 /* "IEC958 Input", 13: -- */
1901 }; 1904 };
1902 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1905 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1903 uinfo->count = 1; 1906 uinfo->count = 1;
@@ -2026,7 +2029,7 @@ static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
2026 "IEC958 In L", "IEC958 In R", /* 9-10 */ 2029 "IEC958 In L", "IEC958 In R", /* 9-10 */
2027 "Digital Mixer", /* 11 - optional */ 2030 "Digital Mixer", /* 11 - optional */
2028 }; 2031 };
2029 2032
2030 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2033 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2031 uinfo->count = 1; 2034 uinfo->count = 1;
2032 uinfo->value.enumerated.items = 2035 uinfo->value.enumerated.items =
@@ -2070,7 +2073,7 @@ static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
2070 int change, shift; 2073 int change, shift;
2071 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 2074 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2072 unsigned int val, old_val, nval; 2075 unsigned int val, old_val, nval;
2073 2076
2074 /* update PSDOUT */ 2077 /* update PSDOUT */
2075 if (ucontrol->value.enumerated.item[0] >= 11) 2078 if (ucontrol->value.enumerated.item[0] >= 11)
2076 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */ 2079 nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
@@ -2140,7 +2143,7 @@ static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
2140 int change, shift; 2143 int change, shift;
2141 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 2144 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2142 unsigned int val, old_val, nval; 2145 unsigned int val, old_val, nval;
2143 2146
2144 /* update SPDOUT */ 2147 /* update SPDOUT */
2145 spin_lock_irq(&ice->reg_lock); 2148 spin_lock_irq(&ice->reg_lock);
2146 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT)); 2149 val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
@@ -2182,7 +2185,7 @@ static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata
2182 2185
2183static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = { 2186static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
2184 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2187 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2185 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route", 2188 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route",
2186 .info = snd_ice1712_pro_route_info, 2189 .info = snd_ice1712_pro_route_info,
2187 .get = snd_ice1712_pro_route_spdif_get, 2190 .get = snd_ice1712_pro_route_spdif_get,
2188 .put = snd_ice1712_pro_route_spdif_put, 2191 .put = snd_ice1712_pro_route_spdif_put,
@@ -2204,7 +2207,7 @@ static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
2204 struct snd_ctl_elem_value *ucontrol) 2207 struct snd_ctl_elem_value *ucontrol)
2205{ 2208{
2206 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 2209 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2207 2210
2208 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE)); 2211 ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
2209 return 0; 2212 return 0;
2210} 2213}
@@ -2245,7 +2248,7 @@ static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2245{ 2248{
2246 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 2249 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2247 int idx; 2250 int idx;
2248 2251
2249 spin_lock_irq(&ice->reg_lock); 2252 spin_lock_irq(&ice->reg_lock);
2250 for (idx = 0; idx < 22; idx++) { 2253 for (idx = 0; idx < 22; idx++) {
2251 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX)); 2254 outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
@@ -2296,12 +2299,12 @@ static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2296 unsigned int i, size; 2299 unsigned int i, size;
2297 struct snd_ice1712_card_info * const *tbl, *c; 2300 struct snd_ice1712_card_info * const *tbl, *c;
2298 2301
2299 if (! modelname || ! *modelname) { 2302 if (!modelname || !*modelname) {
2300 ice->eeprom.subvendor = 0; 2303 ice->eeprom.subvendor = 0;
2301 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0) 2304 if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
2302 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) | 2305 ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
2303 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) | 2306 (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
2304 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) | 2307 (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
2305 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24); 2308 (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
2306 if (ice->eeprom.subvendor == 0 || 2309 if (ice->eeprom.subvendor == 0 ||
2307 ice->eeprom.subvendor == (unsigned int)-1) { 2310 ice->eeprom.subvendor == (unsigned int)-1) {
@@ -2318,12 +2321,12 @@ static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2318 } 2321 }
2319 for (tbl = card_tables; *tbl; tbl++) { 2322 for (tbl = card_tables; *tbl; tbl++) {
2320 for (c = *tbl; c->subvendor; c++) { 2323 for (c = *tbl; c->subvendor; c++) {
2321 if (modelname && c->model && ! strcmp(modelname, c->model)) { 2324 if (modelname && c->model && !strcmp(modelname, c->model)) {
2322 printk(KERN_INFO "ice1712: Using board model %s\n", c->name); 2325 printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
2323 ice->eeprom.subvendor = c->subvendor; 2326 ice->eeprom.subvendor = c->subvendor;
2324 } else if (c->subvendor != ice->eeprom.subvendor) 2327 } else if (c->subvendor != ice->eeprom.subvendor)
2325 continue; 2328 continue;
2326 if (! c->eeprom_size || ! c->eeprom_data) 2329 if (!c->eeprom_size || !c->eeprom_data)
2327 goto found; 2330 goto found;
2328 /* if the EEPROM is given by the driver, use it */ 2331 /* if the EEPROM is given by the driver, use it */
2329 snd_printdd("using the defined eeprom..\n"); 2332 snd_printdd("using the defined eeprom..\n");
@@ -2416,7 +2419,8 @@ int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
2416 int err; 2419 int err;
2417 struct snd_kcontrol *kctl; 2420 struct snd_kcontrol *kctl;
2418 2421
2419 snd_assert(ice->pcm_pro != NULL, return -EIO); 2422 if (snd_BUG_ON(!ice->pcm_pro))
2423 return -EIO;
2420 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice)); 2424 err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
2421 if (err < 0) 2425 if (err < 0)
2422 return err; 2426 return err;
@@ -2483,13 +2487,13 @@ static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
2483 2487
2484static int snd_ice1712_free(struct snd_ice1712 *ice) 2488static int snd_ice1712_free(struct snd_ice1712 *ice)
2485{ 2489{
2486 if (! ice->port) 2490 if (!ice->port)
2487 goto __hw_end; 2491 goto __hw_end;
2488 /* mask all interrupts */ 2492 /* mask all interrupts */
2489 outb(0xc0, ICEMT(ice, IRQ)); 2493 outb(0xc0, ICEMT(ice, IRQ));
2490 outb(0xff, ICEREG(ice, IRQMASK)); 2494 outb(0xff, ICEREG(ice, IRQMASK));
2491 /* --- */ 2495 /* --- */
2492 __hw_end: 2496__hw_end:
2493 if (ice->irq >= 0) 2497 if (ice->irq >= 0)
2494 free_irq(ice->irq, ice); 2498 free_irq(ice->irq, ice);
2495 2499
@@ -2514,7 +2518,7 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2514 int omni, 2518 int omni,
2515 int cs8427_timeout, 2519 int cs8427_timeout,
2516 int dxr_enable, 2520 int dxr_enable,
2517 struct snd_ice1712 ** r_ice1712) 2521 struct snd_ice1712 **r_ice1712)
2518{ 2522{
2519 struct snd_ice1712 *ice; 2523 struct snd_ice1712 *ice;
2520 int err; 2524 int err;
@@ -2524,8 +2528,9 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2524 2528
2525 *r_ice1712 = NULL; 2529 *r_ice1712 = NULL;
2526 2530
2527 /* enable PCI device */ 2531 /* enable PCI device */
2528 if ((err = pci_enable_device(pci)) < 0) 2532 err = pci_enable_device(pci);
2533 if (err < 0)
2529 return err; 2534 return err;
2530 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2535 /* check, if we can restrict PCI DMA transfers to 28 bits */
2531 if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 || 2536 if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
@@ -2569,7 +2574,8 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2569 snd_ice1712_proc_init(ice); 2574 snd_ice1712_proc_init(ice);
2570 synchronize_irq(pci->irq); 2575 synchronize_irq(pci->irq);
2571 2576
2572 if ((err = pci_request_regions(pci, "ICE1712")) < 0) { 2577 err = pci_request_regions(pci, "ICE1712");
2578 if (err < 0) {
2573 kfree(ice); 2579 kfree(ice);
2574 pci_disable_device(pci); 2580 pci_disable_device(pci);
2575 return err; 2581 return err;
@@ -2585,7 +2591,7 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2585 snd_ice1712_free(ice); 2591 snd_ice1712_free(ice);
2586 return -EIO; 2592 return -EIO;
2587 } 2593 }
2588 2594
2589 ice->irq = pci->irq; 2595 ice->irq = pci->irq;
2590 2596
2591 if (snd_ice1712_read_eeprom(ice, modelname) < 0) { 2597 if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
@@ -2605,9 +2611,10 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2605 ICEREG(ice, IRQMASK)); 2611 ICEREG(ice, IRQMASK));
2606 outb(0x00, ICEMT(ice, IRQ)); 2612 outb(0x00, ICEMT(ice, IRQ));
2607 2613
2608 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) { 2614 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops);
2615 if (err < 0) {
2609 snd_ice1712_free(ice); 2616 snd_ice1712_free(ice);
2610 return err; 2617 return err;
2611 } 2618 }
2612 2619
2613 snd_card_set_dev(card, &pci->dev); 2620 snd_card_set_dev(card, &pci->dev);
@@ -2647,10 +2654,10 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2647 2654
2648 strcpy(card->driver, "ICE1712"); 2655 strcpy(card->driver, "ICE1712");
2649 strcpy(card->shortname, "ICEnsemble ICE1712"); 2656 strcpy(card->shortname, "ICEnsemble ICE1712");
2650 2657
2651 if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev], 2658 err = snd_ice1712_create(card, pci, model[dev], omni[dev],
2652 cs8427_timeout[dev], dxr_enable[dev], 2659 cs8427_timeout[dev], dxr_enable[dev], &ice);
2653 &ice)) < 0) { 2660 if (err < 0) {
2654 snd_card_free(card); 2661 snd_card_free(card);
2655 return err; 2662 return err;
2656 } 2663 }
@@ -2662,7 +2669,8 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2662 if (c->driver) /* specific driver? */ 2669 if (c->driver) /* specific driver? */
2663 strcpy(card->driver, c->driver); 2670 strcpy(card->driver, c->driver);
2664 if (c->chip_init) { 2671 if (c->chip_init) {
2665 if ((err = c->chip_init(ice)) < 0) { 2672 err = c->chip_init(ice);
2673 if (err < 0) {
2666 snd_card_free(card); 2674 snd_card_free(card);
2667 return err; 2675 return err;
2668 } 2676 }
@@ -2674,47 +2682,52 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2674 c = &no_matched; 2682 c = &no_matched;
2675 __found: 2683 __found:
2676 2684
2677 if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) { 2685 err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL);
2686 if (err < 0) {
2678 snd_card_free(card); 2687 snd_card_free(card);
2679 return err; 2688 return err;
2680 } 2689 }
2681 2690
2682 if (ice_has_con_ac97(ice)) 2691 if (ice_has_con_ac97(ice))
2683 if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) { 2692 err = snd_ice1712_pcm(ice, pcm_dev++, NULL);
2693 if (err < 0) {
2684 snd_card_free(card); 2694 snd_card_free(card);
2685 return err; 2695 return err;
2686 } 2696 }
2687 2697
2688 if ((err = snd_ice1712_ac97_mixer(ice)) < 0) { 2698 err = snd_ice1712_ac97_mixer(ice);
2699 if (err < 0) {
2689 snd_card_free(card); 2700 snd_card_free(card);
2690 return err; 2701 return err;
2691 } 2702 }
2692 2703
2693 if ((err = snd_ice1712_build_controls(ice)) < 0) { 2704 err = snd_ice1712_build_controls(ice);
2705 if (err < 0) {
2694 snd_card_free(card); 2706 snd_card_free(card);
2695 return err; 2707 return err;
2696 } 2708 }
2697 2709
2698 if (c->build_controls) { 2710 if (c->build_controls) {
2699 if ((err = c->build_controls(ice)) < 0) { 2711 err = c->build_controls(ice);
2712 if (err < 0) {
2700 snd_card_free(card); 2713 snd_card_free(card);
2701 return err; 2714 return err;
2702 } 2715 }
2703 } 2716 }
2704 2717
2705 if (ice_has_con_ac97(ice)) 2718 if (ice_has_con_ac97(ice))
2706 if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) { 2719 err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL);
2720 if (err < 0) {
2707 snd_card_free(card); 2721 snd_card_free(card);
2708 return err; 2722 return err;
2709 } 2723 }
2710 2724
2711 if (! c->no_mpu401) { 2725 if (!c->no_mpu401) {
2712 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, 2726 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2713 ICEREG(ice, MPU1_CTRL), 2727 ICEREG(ice, MPU1_CTRL),
2714 (c->mpu401_1_info_flags | 2728 (c->mpu401_1_info_flags | MPU401_INFO_INTEGRATED),
2715 MPU401_INFO_INTEGRATED), 2729 ice->irq, 0, &ice->rmidi[0]);
2716 ice->irq, 0, 2730 if (err < 0) {
2717 &ice->rmidi[0])) < 0) {
2718 snd_card_free(card); 2731 snd_card_free(card);
2719 return err; 2732 return err;
2720 } 2733 }
@@ -2726,12 +2739,12 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2726 2739
2727 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) { 2740 if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
2728 /* 2nd port used */ 2741 /* 2nd port used */
2729 if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712, 2742 err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2730 ICEREG(ice, MPU2_CTRL), 2743 ICEREG(ice, MPU2_CTRL),
2731 (c->mpu401_2_info_flags | 2744 (c->mpu401_2_info_flags | MPU401_INFO_INTEGRATED),
2732 MPU401_INFO_INTEGRATED), 2745 ice->irq, 0, &ice->rmidi[1]);
2733 ice->irq, 0, 2746
2734 &ice->rmidi[1])) < 0) { 2747 if (err < 0) {
2735 snd_card_free(card); 2748 snd_card_free(card);
2736 return err; 2749 return err;
2737 } 2750 }
@@ -2749,7 +2762,8 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2749 sprintf(card->longname, "%s at 0x%lx, irq %i", 2762 sprintf(card->longname, "%s at 0x%lx, irq %i",
2750 card->shortname, ice->port, ice->irq); 2763 card->shortname, ice->port, ice->irq);
2751 2764
2752 if ((err = snd_card_register(card)) < 0) { 2765 err = snd_card_register(card);
2766 if (err < 0) {
2753 snd_card_free(card); 2767 snd_card_free(card);
2754 return err; 2768 return err;
2755 } 2769 }
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index 762fbd7a7507..fdae6deba16b 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -20,7 +20,7 @@
20 * along with this program; if not, write to the Free Software 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 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 22 *
23 */ 23 */
24 24
25#include <sound/control.h> 25#include <sound/control.h>
26#include <sound/ac97_codec.h> 26#include <sound/ac97_codec.h>
@@ -112,7 +112,7 @@
112 */ 112 */
113 113
114#define ICEDS(ice, x) ((ice)->dmapath_port + ICE1712_DS_##x) 114#define ICEDS(ice, x) ((ice)->dmapath_port + ICE1712_DS_##x)
115 115
116#define ICE1712_DS_INTMASK 0x00 /* word - interrupt mask */ 116#define ICE1712_DS_INTMASK 0x00 /* word - interrupt mask */
117#define ICE1712_DS_INTSTAT 0x02 /* word - interrupt status */ 117#define ICE1712_DS_INTSTAT 0x02 /* word - interrupt status */
118#define ICE1712_DS_DATA 0x04 /* dword - channel data */ 118#define ICE1712_DS_DATA 0x04 /* dword - channel data */
@@ -121,7 +121,7 @@
121/* 121/*
122 * Consumer section channel registers 122 * Consumer section channel registers
123 */ 123 */
124 124
125#define ICE1712_DSC_ADDR0 0x00 /* dword - base address 0 */ 125#define ICE1712_DSC_ADDR0 0x00 /* dword - base address 0 */
126#define ICE1712_DSC_COUNT0 0x01 /* word - count 0 */ 126#define ICE1712_DSC_COUNT0 0x01 /* word - count 0 */
127#define ICE1712_DSC_ADDR1 0x02 /* dword - base address 1 */ 127#define ICE1712_DSC_ADDR1 0x02 /* dword - base address 1 */
@@ -138,7 +138,7 @@
138#define ICE1712_DSC_RATE 0x05 /* dword - rate */ 138#define ICE1712_DSC_RATE 0x05 /* dword - rate */
139#define ICE1712_DSC_VOLUME 0x06 /* word - volume control */ 139#define ICE1712_DSC_VOLUME 0x06 /* word - volume control */
140 140
141/* 141/*
142 * Professional multi-track direct control registers 142 * Professional multi-track direct control registers
143 */ 143 */
144 144
@@ -214,7 +214,7 @@
214 214
215 215
216/* 216/*
217 * 217 *
218 */ 218 */
219 219
220struct snd_ice1712; 220struct snd_ice1712;
@@ -253,12 +253,12 @@ enum {
253 ICE_EEP1_ADC_ID2, 253 ICE_EEP1_ADC_ID2,
254 ICE_EEP1_ADC_ID3 254 ICE_EEP1_ADC_ID3
255}; 255};
256 256
257#define ice_has_con_ac97(ice) (!((ice)->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) 257#define ice_has_con_ac97(ice) (!((ice)->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97))
258 258
259 259
260struct snd_ak4xxx_private { 260struct snd_ak4xxx_private {
261 unsigned int cif: 1; /* CIF mode */ 261 unsigned int cif:1; /* CIF mode */
262 unsigned char caddr; /* C0 and C1 bits */ 262 unsigned char caddr; /* C0 and C1 bits */
263 unsigned int data_mask; /* DATA gpio bit */ 263 unsigned int data_mask; /* DATA gpio bit */
264 unsigned int clk_mask; /* CLK gpio bit */ 264 unsigned int clk_mask; /* CLK gpio bit */
@@ -306,11 +306,11 @@ struct snd_ice1712 {
306 struct snd_pcm *pcm; 306 struct snd_pcm *pcm;
307 struct snd_pcm *pcm_ds; 307 struct snd_pcm *pcm_ds;
308 struct snd_pcm *pcm_pro; 308 struct snd_pcm *pcm_pro;
309 struct snd_pcm_substream *playback_con_substream; 309 struct snd_pcm_substream *playback_con_substream;
310 struct snd_pcm_substream *playback_con_substream_ds[6]; 310 struct snd_pcm_substream *playback_con_substream_ds[6];
311 struct snd_pcm_substream *capture_con_substream; 311 struct snd_pcm_substream *capture_con_substream;
312 struct snd_pcm_substream *playback_pro_substream; 312 struct snd_pcm_substream *playback_pro_substream;
313 struct snd_pcm_substream *capture_pro_substream; 313 struct snd_pcm_substream *capture_pro_substream;
314 unsigned int playback_pro_size; 314 unsigned int playback_pro_size;
315 unsigned int capture_pro_size; 315 unsigned int capture_pro_size;
316 unsigned int playback_con_virt_addr[6]; 316 unsigned int playback_con_virt_addr[6];
@@ -326,15 +326,15 @@ struct snd_ice1712 {
326 struct snd_ice1712_eeprom eeprom; 326 struct snd_ice1712_eeprom eeprom;
327 327
328 unsigned int pro_volumes[20]; 328 unsigned int pro_volumes[20];
329 unsigned int omni: 1; /* Delta Omni I/O */ 329 unsigned int omni:1; /* Delta Omni I/O */
330 unsigned int dxr_enable: 1; /* Terratec DXR enable for DMX6FIRE */ 330 unsigned int dxr_enable:1; /* Terratec DXR enable for DMX6FIRE */
331 unsigned int vt1724: 1; 331 unsigned int vt1724:1;
332 unsigned int vt1720: 1; 332 unsigned int vt1720:1;
333 unsigned int has_spdif: 1; /* VT1720/4 - has SPDIF I/O */ 333 unsigned int has_spdif:1; /* VT1720/4 - has SPDIF I/O */
334 unsigned int force_pdma4: 1; /* VT1720/4 - PDMA4 as non-spdif */ 334 unsigned int force_pdma4:1; /* VT1720/4 - PDMA4 as non-spdif */
335 unsigned int force_rdma1: 1; /* VT1720/4 - RDMA1 as non-spdif */ 335 unsigned int force_rdma1:1; /* VT1720/4 - RDMA1 as non-spdif */
336 unsigned int midi_output: 1; /* VT1720/4: MIDI output triggered */ 336 unsigned int midi_output:1; /* VT1720/4: MIDI output triggered */
337 unsigned int midi_input: 1; /* VT1720/4: MIDI input triggered */ 337 unsigned int midi_input:1; /* VT1720/4: MIDI input triggered */
338 unsigned int num_total_dacs; /* total DACs */ 338 unsigned int num_total_dacs; /* total DACs */
339 unsigned int num_total_adcs; /* total ADCs */ 339 unsigned int num_total_adcs; /* total ADCs */
340 unsigned int cur_rate; /* current rate */ 340 unsigned int cur_rate; /* current rate */
@@ -351,7 +351,7 @@ struct snd_ice1712 {
351 struct snd_i2c_bus *i2c; /* I2C bus */ 351 struct snd_i2c_bus *i2c; /* I2C bus */
352 struct snd_i2c_device *cs8427; /* CS8427 I2C device */ 352 struct snd_i2c_device *cs8427; /* CS8427 I2C device */
353 unsigned int cs8427_timeout; /* CS8427 reset timeout in HZ/100 */ 353 unsigned int cs8427_timeout; /* CS8427 reset timeout in HZ/100 */
354 354
355 struct ice1712_gpio { 355 struct ice1712_gpio {
356 unsigned int direction; /* current direction bits */ 356 unsigned int direction; /* current direction bits */
357 unsigned int write_mask; /* current mask bits */ 357 unsigned int write_mask; /* current mask bits */
@@ -455,7 +455,7 @@ static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice,
455{ 455{
456 ice->gpio.direction &= ~mask; 456 ice->gpio.direction &= ~mask;
457 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 457 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
458 return (snd_ice1712_gpio_read(ice) & mask); 458 return snd_ice1712_gpio_read(ice) & mask;
459} 459}
460 460
461int snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice); 461int snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice);
@@ -467,13 +467,13 @@ int snd_ice1712_akm4xxx_build_controls(struct snd_ice1712 *ice);
467 467
468int snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr); 468int snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr);
469 469
470static inline void snd_ice1712_write(struct snd_ice1712 * ice, u8 addr, u8 data) 470static inline void snd_ice1712_write(struct snd_ice1712 *ice, u8 addr, u8 data)
471{ 471{
472 outb(addr, ICEREG(ice, INDEX)); 472 outb(addr, ICEREG(ice, INDEX));
473 outb(data, ICEREG(ice, DATA)); 473 outb(data, ICEREG(ice, DATA));
474} 474}
475 475
476static inline u8 snd_ice1712_read(struct snd_ice1712 * ice, u8 addr) 476static inline u8 snd_ice1712_read(struct snd_ice1712 *ice, u8 addr)
477{ 477{
478 outb(addr, ICEREG(ice, INDEX)); 478 outb(addr, ICEREG(ice, INDEX));
479 return inb(ICEREG(ice, DATA)); 479 return inb(ICEREG(ice, DATA));
@@ -491,7 +491,7 @@ struct snd_ice1712_card_info {
491 char *driver; 491 char *driver;
492 int (*chip_init)(struct snd_ice1712 *); 492 int (*chip_init)(struct snd_ice1712 *);
493 int (*build_controls)(struct snd_ice1712 *); 493 int (*build_controls)(struct snd_ice1712 *);
494 unsigned int no_mpu401: 1; 494 unsigned int no_mpu401:1;
495 unsigned int mpu401_1_info_flags; 495 unsigned int mpu401_1_info_flags;
496 unsigned int mpu401_2_info_flags; 496 unsigned int mpu401_2_info_flags;
497 const char *mpu401_1_name; 497 const char *mpu401_1_name;
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index e596d777d9dd..1b3f11702713 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -20,9 +20,9 @@
20 * along with this program; if not, write to the Free Software 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 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 22 *
23 */ 23 */
24 24
25#include <asm/io.h> 25#include <linux/io.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/init.h> 28#include <linux/init.h>
@@ -105,7 +105,7 @@ static unsigned int PRO_RATE_DEFAULT = 44100;
105/* 105/*
106 * Basic I/O 106 * Basic I/O
107 */ 107 */
108 108
109/* 109/*
110 * default rates, default clock routines 110 * default rates, default clock routines
111 */ 111 */
@@ -198,7 +198,7 @@ static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
198static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) 198static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
199{ 199{
200 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK)); 200 outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
201 if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */ 201 if (!ice->vt1720) /* VT1720 supports only 16 GPIO bits */
202 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22)); 202 outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
203 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */ 203 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
204} 204}
@@ -206,7 +206,7 @@ static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
206static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data) 206static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
207{ 207{
208 outw(data, ICEREG1724(ice, GPIO_DATA)); 208 outw(data, ICEREG1724(ice, GPIO_DATA));
209 if (! ice->vt1720) 209 if (!ice->vt1720)
210 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22)); 210 outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
211 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */ 211 inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
212} 212}
@@ -214,7 +214,7 @@ static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
214static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice) 214static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
215{ 215{
216 unsigned int data; 216 unsigned int data;
217 if (! ice->vt1720) 217 if (!ice->vt1720)
218 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22)); 218 data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
219 else 219 else
220 data = 0; 220 data = 0;
@@ -399,7 +399,7 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
399 break; 399 break;
400 } 400 }
401#endif 401#endif
402 handled = 1; 402 handled = 1;
403 if (status & VT1724_IRQ_MPU_TX) { 403 if (status & VT1724_IRQ_MPU_TX) {
404 spin_lock(&ice->reg_lock); 404 spin_lock(&ice->reg_lock);
405 if (ice->midi_output) 405 if (ice->midi_output)
@@ -468,8 +468,8 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
468 /* ought to really handle this properly */ 468 /* ought to really handle this properly */
469 if (mtstat & VT1724_MULTI_FIFO_ERR) { 469 if (mtstat & VT1724_MULTI_FIFO_ERR) {
470 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR)); 470 unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
471 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR)); 471 outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
472 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK)); 472 outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
473 /* If I don't do this, I get machine lockup due to continual interrupts */ 473 /* If I don't do this, I get machine lockup due to continual interrupts */
474 } 474 }
475 475
@@ -733,17 +733,17 @@ static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
733 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR)); 733 outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
734 734
735 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1; 735 size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
736 // outl(size, ICEMT1724(ice, PLAYBACK_SIZE)); 736 /* outl(size, ICEMT1724(ice, PLAYBACK_SIZE)); */
737 outw(size, ICEMT1724(ice, PLAYBACK_SIZE)); 737 outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
738 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2); 738 outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
739 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1; 739 size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
740 // outl(size, ICEMT1724(ice, PLAYBACK_COUNT)); 740 /* outl(size, ICEMT1724(ice, PLAYBACK_COUNT)); */
741 outw(size, ICEMT1724(ice, PLAYBACK_COUNT)); 741 outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
742 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2); 742 outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
743 743
744 spin_unlock_irq(&ice->reg_lock); 744 spin_unlock_irq(&ice->reg_lock);
745 745
746 // printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream)); 746 /* printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream)); */
747 return 0; 747 return 0;
748} 748}
749 749
@@ -771,7 +771,7 @@ static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substrea
771 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff; 771 ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
772 ptr = (ptr + 1) << 2; 772 ptr = (ptr + 1) << 2;
773 ptr = bytes_to_frames(substream->runtime, ptr); 773 ptr = bytes_to_frames(substream->runtime, ptr);
774 if (! ptr) 774 if (!ptr)
775 ; 775 ;
776 else if (ptr <= substream->runtime->buffer_size) 776 else if (ptr <= substream->runtime->buffer_size)
777 ptr = substream->runtime->buffer_size - ptr; 777 ptr = substream->runtime->buffer_size - ptr;
@@ -815,7 +815,7 @@ static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substr
815 ptr = inw(ice->profi_port + reg->size); 815 ptr = inw(ice->profi_port + reg->size);
816 ptr = (ptr + 1) << 2; 816 ptr = (ptr + 1) << 2;
817 ptr = bytes_to_frames(substream->runtime, ptr); 817 ptr = bytes_to_frames(substream->runtime, ptr);
818 if (! ptr) 818 if (!ptr)
819 ; 819 ;
820 else if (ptr <= substream->runtime->buffer_size) 820 else if (ptr <= substream->runtime->buffer_size)
821 ptr = substream->runtime->buffer_size - ptr; 821 ptr = substream->runtime->buffer_size - ptr;
@@ -842,8 +842,7 @@ static const struct vt1724_pcm_reg vt1724_capture_pro_reg = {
842 .start = VT1724_RDMA0_START, 842 .start = VT1724_RDMA0_START,
843}; 843};
844 844
845static const struct snd_pcm_hardware snd_vt1724_playback_pro = 845static const struct snd_pcm_hardware snd_vt1724_playback_pro = {
846{
847 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 846 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
848 SNDRV_PCM_INFO_BLOCK_TRANSFER | 847 SNDRV_PCM_INFO_BLOCK_TRANSFER |
849 SNDRV_PCM_INFO_MMAP_VALID | 848 SNDRV_PCM_INFO_MMAP_VALID |
@@ -861,8 +860,7 @@ static const struct snd_pcm_hardware snd_vt1724_playback_pro =
861 .periods_max = 1024, 860 .periods_max = 1024,
862}; 861};
863 862
864static const struct snd_pcm_hardware snd_vt1724_spdif = 863static const struct snd_pcm_hardware snd_vt1724_spdif = {
865{
866 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 864 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
867 SNDRV_PCM_INFO_BLOCK_TRANSFER | 865 SNDRV_PCM_INFO_BLOCK_TRANSFER |
868 SNDRV_PCM_INFO_MMAP_VALID | 866 SNDRV_PCM_INFO_MMAP_VALID |
@@ -883,8 +881,7 @@ static const struct snd_pcm_hardware snd_vt1724_spdif =
883 .periods_max = 1024, 881 .periods_max = 1024,
884}; 882};
885 883
886static const struct snd_pcm_hardware snd_vt1724_2ch_stereo = 884static const struct snd_pcm_hardware snd_vt1724_2ch_stereo = {
887{
888 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 885 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
889 SNDRV_PCM_INFO_BLOCK_TRANSFER | 886 SNDRV_PCM_INFO_BLOCK_TRANSFER |
890 SNDRV_PCM_INFO_MMAP_VALID | 887 SNDRV_PCM_INFO_MMAP_VALID |
@@ -942,7 +939,7 @@ static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
942{ 939{
943 struct snd_pcm_runtime *runtime = substream->runtime; 940 struct snd_pcm_runtime *runtime = substream->runtime;
944 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 941 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
945 int chs; 942 int chs, num_indeps;
946 943
947 runtime->private_data = (void *)&vt1724_playback_pro_reg; 944 runtime->private_data = (void *)&vt1724_playback_pro_reg;
948 ice->playback_pro_substream = substream; 945 ice->playback_pro_substream = substream;
@@ -952,7 +949,8 @@ static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
952 set_rate_constraints(ice, substream); 949 set_rate_constraints(ice, substream);
953 mutex_lock(&ice->open_mutex); 950 mutex_lock(&ice->open_mutex);
954 /* calculate the currently available channels */ 951 /* calculate the currently available channels */
955 for (chs = 0; chs < 3; chs++) { 952 num_indeps = ice->num_total_dacs / 2 - 1;
953 for (chs = 0; chs < num_indeps; chs++) {
956 if (ice->pcm_reserved[chs]) 954 if (ice->pcm_reserved[chs])
957 break; 955 break;
958 } 956 }
@@ -1029,7 +1027,7 @@ static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
1029 .pointer = snd_vt1724_pcm_pointer, 1027 .pointer = snd_vt1724_pcm_pointer,
1030}; 1028};
1031 1029
1032static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device) 1030static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 *ice, int device)
1033{ 1031{
1034 struct snd_pcm *pcm; 1032 struct snd_pcm *pcm;
1035 int err; 1033 int err;
@@ -1114,7 +1112,7 @@ static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
1114static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream) 1112static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
1115{ 1113{
1116 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1114 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1117 if (! ice->force_pdma4) 1115 if (!ice->force_pdma4)
1118 update_spdif_rate(ice, substream->runtime->rate); 1116 update_spdif_rate(ice, substream->runtime->rate);
1119 return snd_vt1724_pcm_prepare(substream); 1117 return snd_vt1724_pcm_prepare(substream);
1120} 1118}
@@ -1214,7 +1212,7 @@ static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
1214}; 1212};
1215 1213
1216 1214
1217static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device) 1215static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 *ice, int device)
1218{ 1216{
1219 char *name; 1217 char *name;
1220 struct snd_pcm *pcm; 1218 struct snd_pcm *pcm;
@@ -1233,7 +1231,7 @@ static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
1233 ice->has_spdif = 1; 1231 ice->has_spdif = 1;
1234 } else 1232 } else
1235 capt = 0; 1233 capt = 0;
1236 if (! play && ! capt) 1234 if (!play && !capt)
1237 return 0; /* no spdif device */ 1235 return 0; /* no spdif device */
1238 1236
1239 if (ice->force_pdma4 || ice->force_rdma1) 1237 if (ice->force_pdma4 || ice->force_rdma1)
@@ -1348,7 +1346,7 @@ static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
1348}; 1346};
1349 1347
1350 1348
1351static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device) 1349static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 *ice, int device)
1352{ 1350{
1353 struct snd_pcm *pcm; 1351 struct snd_pcm *pcm;
1354 int play; 1352 int play;
@@ -1383,11 +1381,11 @@ static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
1383 * Mixer section 1381 * Mixer section
1384 */ 1382 */
1385 1383
1386static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice) 1384static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 *ice)
1387{ 1385{
1388 int err; 1386 int err;
1389 1387
1390 if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) { 1388 if (!(ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
1391 struct snd_ac97_bus *pbus; 1389 struct snd_ac97_bus *pbus;
1392 struct snd_ac97_template ac97; 1390 struct snd_ac97_template ac97;
1393 static struct snd_ac97_bus_ops ops = { 1391 static struct snd_ac97_bus_ops ops = {
@@ -1400,11 +1398,13 @@ static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
1400 mdelay(5); /* FIXME */ 1398 mdelay(5); /* FIXME */
1401 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD)); 1399 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
1402 1400
1403 if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0) 1401 err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus);
1402 if (err < 0)
1404 return err; 1403 return err;
1405 memset(&ac97, 0, sizeof(ac97)); 1404 memset(&ac97, 0, sizeof(ac97));
1406 ac97.private_data = ice; 1405 ac97.private_data = ice;
1407 if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0) 1406 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1407 if (err < 0)
1408 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n"); 1408 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
1409 else 1409 else
1410 return 0; 1410 return 0;
@@ -1425,7 +1425,7 @@ static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
1425 ((unsigned int)ice->eeprom.data[idx + 2] << 16); 1425 ((unsigned int)ice->eeprom.data[idx + 2] << 16);
1426} 1426}
1427 1427
1428static void snd_vt1724_proc_read(struct snd_info_entry *entry, 1428static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1429 struct snd_info_buffer *buffer) 1429 struct snd_info_buffer *buffer)
1430{ 1430{
1431 struct snd_ice1712 *ice = entry->private_data; 1431 struct snd_ice1712 *ice = entry->private_data;
@@ -1467,11 +1467,11 @@ static void snd_vt1724_proc_read(struct snd_info_entry *entry,
1467 idx, inb(ice->profi_port+idx)); 1467 idx, inb(ice->profi_port+idx));
1468} 1468}
1469 1469
1470static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice) 1470static void __devinit snd_vt1724_proc_init(struct snd_ice1712 *ice)
1471{ 1471{
1472 struct snd_info_entry *entry; 1472 struct snd_info_entry *entry;
1473 1473
1474 if (! snd_card_proc_new(ice->card, "ice1724", &entry)) 1474 if (!snd_card_proc_new(ice->card, "ice1724", &entry))
1475 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read); 1475 snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
1476} 1476}
1477 1477
@@ -1491,7 +1491,7 @@ static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
1491 struct snd_ctl_elem_value *ucontrol) 1491 struct snd_ctl_elem_value *ucontrol)
1492{ 1492{
1493 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1493 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1494 1494
1495 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom)); 1495 memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
1496 return 0; 1496 return 0;
1497} 1497}
@@ -1606,13 +1606,13 @@ static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
1606 if (val != old) 1606 if (val != old)
1607 update_spdif_bits(ice, val); 1607 update_spdif_bits(ice, val);
1608 spin_unlock_irq(&ice->reg_lock); 1608 spin_unlock_irq(&ice->reg_lock);
1609 return (val != old); 1609 return val != old;
1610} 1610}
1611 1611
1612static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata = 1612static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
1613{ 1613{
1614 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1614 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1615 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 1615 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1616 .info = snd_vt1724_spdif_info, 1616 .info = snd_vt1724_spdif_info,
1617 .get = snd_vt1724_spdif_default_get, 1617 .get = snd_vt1724_spdif_default_get,
1618 .put = snd_vt1724_spdif_default_put 1618 .put = snd_vt1724_spdif_default_put
@@ -1645,7 +1645,7 @@ static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
1645{ 1645{
1646 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1646 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1647 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1647 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1648 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 1648 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
1649 .info = snd_vt1724_spdif_info, 1649 .info = snd_vt1724_spdif_info,
1650 .get = snd_vt1724_spdif_maskc_get, 1650 .get = snd_vt1724_spdif_maskc_get,
1651}; 1651};
@@ -1654,7 +1654,7 @@ static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
1654{ 1654{
1655 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1655 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1656 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1656 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1657 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), 1657 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
1658 .info = snd_vt1724_spdif_info, 1658 .info = snd_vt1724_spdif_info,
1659 .get = snd_vt1724_spdif_maskp_get, 1659 .get = snd_vt1724_spdif_maskp_get,
1660}; 1660};
@@ -1691,8 +1691,8 @@ static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
1691{ 1691{
1692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1693 /* FIXME: the following conflict with IEC958 Playback Route */ 1693 /* FIXME: the following conflict with IEC958 Playback Route */
1694 // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 1694 /* .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), */
1695 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 1695 .name = SNDRV_CTL_NAME_IEC958("Output ", NONE, SWITCH),
1696 .info = snd_vt1724_spdif_sw_info, 1696 .info = snd_vt1724_spdif_sw_info,
1697 .get = snd_vt1724_spdif_sw_get, 1697 .get = snd_vt1724_spdif_sw_get,
1698 .put = snd_vt1724_spdif_sw_put 1698 .put = snd_vt1724_spdif_sw_put
@@ -1712,7 +1712,7 @@ int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
1712 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1712 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1713 int shift = kcontrol->private_value & 0xff; 1713 int shift = kcontrol->private_value & 0xff;
1714 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0; 1714 int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
1715 1715
1716 snd_ice1712_save_gpio_status(ice); 1716 snd_ice1712_save_gpio_status(ice);
1717 ucontrol->value.integer.value[0] = 1717 ucontrol->value.integer.value[0] =
1718 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert; 1718 (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
@@ -1767,7 +1767,7 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1767{ 1767{
1768 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1768 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1769 unsigned int i, rate; 1769 unsigned int i, rate;
1770 1770
1771 spin_lock_irq(&ice->reg_lock); 1771 spin_lock_irq(&ice->reg_lock);
1772 if (ice->is_spdif_master(ice)) { 1772 if (ice->is_spdif_master(ice)) {
1773 ucontrol->value.enumerated.item[0] = ice->hw_rates->count; 1773 ucontrol->value.enumerated.item[0] = ice->hw_rates->count;
@@ -1923,7 +1923,7 @@ static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
1923 "H/W In 0", "H/W In 1", /* 1-2 */ 1923 "H/W In 0", "H/W In 1", /* 1-2 */
1924 "IEC958 In L", "IEC958 In R", /* 3-4 */ 1924 "IEC958 In L", "IEC958 In R", /* 3-4 */
1925 }; 1925 };
1926 1926
1927 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1927 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1928 uinfo->count = 1; 1928 uinfo->count = 1;
1929 uinfo->value.enumerated.items = 5; 1929 uinfo->value.enumerated.items = 5;
@@ -1953,7 +1953,7 @@ static int get_route_val(struct snd_ice1712 *ice, int shift)
1953 1953
1954 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK)); 1954 val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
1955 val >>= shift; 1955 val >>= shift;
1956 val &= 7; //we now have 3 bits per output 1956 val &= 7; /* we now have 3 bits per output */
1957 eitem = xlate[val]; 1957 eitem = xlate[val];
1958 if (eitem == 255) { 1958 if (eitem == 255) {
1959 snd_BUG(); 1959 snd_BUG();
@@ -2032,7 +2032,7 @@ static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata =
2032 2032
2033static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = { 2033static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
2034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2035 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route", 2035 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route",
2036 .info = snd_vt1724_pro_route_info, 2036 .info = snd_vt1724_pro_route_info,
2037 .get = snd_vt1724_pro_route_spdif_get, 2037 .get = snd_vt1724_pro_route_spdif_get,
2038 .put = snd_vt1724_pro_route_spdif_put, 2038 .put = snd_vt1724_pro_route_spdif_put,
@@ -2055,7 +2055,7 @@ static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
2055{ 2055{
2056 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 2056 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
2057 int idx; 2057 int idx;
2058 2058
2059 spin_lock_irq(&ice->reg_lock); 2059 spin_lock_irq(&ice->reg_lock);
2060 for (idx = 0; idx < 22; idx++) { 2060 for (idx = 0; idx < 22; idx++) {
2061 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX)); 2061 outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
@@ -2082,7 +2082,7 @@ static struct snd_ice1712_card_info no_matched __devinitdata;
2082 2082
2083static struct snd_ice1712_card_info *card_tables[] __devinitdata = { 2083static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2084 snd_vt1724_revo_cards, 2084 snd_vt1724_revo_cards,
2085 snd_vt1724_amp_cards, 2085 snd_vt1724_amp_cards,
2086 snd_vt1724_aureon_cards, 2086 snd_vt1724_aureon_cards,
2087 snd_vt1720_mobo_cards, 2087 snd_vt1720_mobo_cards,
2088 snd_vt1720_pontis_cards, 2088 snd_vt1720_pontis_cards,
@@ -2120,7 +2120,7 @@ unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
2120 wait_i2c_busy(ice); 2120 wait_i2c_busy(ice);
2121 val = inb(ICEREG1724(ice, I2C_DATA)); 2121 val = inb(ICEREG1724(ice, I2C_DATA));
2122 mutex_unlock(&ice->i2c_mutex); 2122 mutex_unlock(&ice->i2c_mutex);
2123 //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val); 2123 /* printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val); */
2124 return val; 2124 return val;
2125} 2125}
2126 2126
@@ -2129,7 +2129,7 @@ void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
2129{ 2129{
2130 mutex_lock(&ice->i2c_mutex); 2130 mutex_lock(&ice->i2c_mutex);
2131 wait_i2c_busy(ice); 2131 wait_i2c_busy(ice);
2132 //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data); 2132 /* printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data); */
2133 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR)); 2133 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
2134 outb(data, ICEREG1724(ice, I2C_DATA)); 2134 outb(data, ICEREG1724(ice, I2C_DATA));
2135 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR)); 2135 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
@@ -2144,13 +2144,13 @@ static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2144 unsigned int i, size; 2144 unsigned int i, size;
2145 struct snd_ice1712_card_info * const *tbl, *c; 2145 struct snd_ice1712_card_info * const *tbl, *c;
2146 2146
2147 if (! modelname || ! *modelname) { 2147 if (!modelname || !*modelname) {
2148 ice->eeprom.subvendor = 0; 2148 ice->eeprom.subvendor = 0;
2149 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0) 2149 if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
2150 ice->eeprom.subvendor = 2150 ice->eeprom.subvendor =
2151 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) | 2151 (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
2152 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) | 2152 (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
2153 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) | 2153 (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
2154 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24); 2154 (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
2155 if (ice->eeprom.subvendor == 0 || 2155 if (ice->eeprom.subvendor == 0 ||
2156 ice->eeprom.subvendor == (unsigned int)-1) { 2156 ice->eeprom.subvendor == (unsigned int)-1) {
@@ -2173,13 +2173,13 @@ static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2173 for (tbl = card_tables; *tbl; tbl++) { 2173 for (tbl = card_tables; *tbl; tbl++) {
2174 for (c = *tbl; c->subvendor; c++) { 2174 for (c = *tbl; c->subvendor; c++) {
2175 if (modelname && c->model && 2175 if (modelname && c->model &&
2176 ! strcmp(modelname, c->model)) { 2176 !strcmp(modelname, c->model)) {
2177 printk(KERN_INFO "ice1724: Using board model %s\n", 2177 printk(KERN_INFO "ice1724: Using board model %s\n",
2178 c->name); 2178 c->name);
2179 ice->eeprom.subvendor = c->subvendor; 2179 ice->eeprom.subvendor = c->subvendor;
2180 } else if (c->subvendor != ice->eeprom.subvendor) 2180 } else if (c->subvendor != ice->eeprom.subvendor)
2181 continue; 2181 continue;
2182 if (! c->eeprom_size || ! c->eeprom_data) 2182 if (!c->eeprom_size || !c->eeprom_data)
2183 goto found; 2183 goto found;
2184 /* if the EEPROM is given by the driver, use it */ 2184 /* if the EEPROM is given by the driver, use it */
2185 snd_printdd("using the defined eeprom..\n"); 2185 snd_printdd("using the defined eeprom..\n");
@@ -2250,7 +2250,8 @@ static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
2250 int err; 2250 int err;
2251 struct snd_kcontrol *kctl; 2251 struct snd_kcontrol *kctl;
2252 2252
2253 snd_assert(ice->pcm != NULL, return -EIO); 2253 if (snd_BUG_ON(!ice->pcm))
2254 return -EIO;
2254 2255
2255 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice)); 2256 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
2256 if (err < 0) 2257 if (err < 0)
@@ -2320,13 +2321,13 @@ static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
2320 2321
2321static int snd_vt1724_free(struct snd_ice1712 *ice) 2322static int snd_vt1724_free(struct snd_ice1712 *ice)
2322{ 2323{
2323 if (! ice->port) 2324 if (!ice->port)
2324 goto __hw_end; 2325 goto __hw_end;
2325 /* mask all interrupts */ 2326 /* mask all interrupts */
2326 outb(0xff, ICEMT1724(ice, DMA_INT_MASK)); 2327 outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
2327 outb(0xff, ICEREG1724(ice, IRQMASK)); 2328 outb(0xff, ICEREG1724(ice, IRQMASK));
2328 /* --- */ 2329 /* --- */
2329 __hw_end: 2330__hw_end:
2330 if (ice->irq >= 0) 2331 if (ice->irq >= 0)
2331 free_irq(ice->irq, ice); 2332 free_irq(ice->irq, ice);
2332 pci_release_regions(ice->pci); 2333 pci_release_regions(ice->pci);
@@ -2346,7 +2347,7 @@ static int snd_vt1724_dev_free(struct snd_device *device)
2346static int __devinit snd_vt1724_create(struct snd_card *card, 2347static int __devinit snd_vt1724_create(struct snd_card *card,
2347 struct pci_dev *pci, 2348 struct pci_dev *pci,
2348 const char *modelname, 2349 const char *modelname,
2349 struct snd_ice1712 ** r_ice1712) 2350 struct snd_ice1712 **r_ice1712)
2350{ 2351{
2351 struct snd_ice1712 *ice; 2352 struct snd_ice1712 *ice;
2352 int err; 2353 int err;
@@ -2357,8 +2358,9 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2357 2358
2358 *r_ice1712 = NULL; 2359 *r_ice1712 = NULL;
2359 2360
2360 /* enable PCI device */ 2361 /* enable PCI device */
2361 if ((err = pci_enable_device(pci)) < 0) 2362 err = pci_enable_device(pci);
2363 if (err < 0)
2362 return err; 2364 return err;
2363 2365
2364 ice = kzalloc(sizeof(*ice), GFP_KERNEL); 2366 ice = kzalloc(sizeof(*ice), GFP_KERNEL);
@@ -2382,7 +2384,8 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2382 snd_vt1724_proc_init(ice); 2384 snd_vt1724_proc_init(ice);
2383 synchronize_irq(pci->irq); 2385 synchronize_irq(pci->irq);
2384 2386
2385 if ((err = pci_request_regions(pci, "ICE1724")) < 0) { 2387 err = pci_request_regions(pci, "ICE1724");
2388 if (err < 0) {
2386 kfree(ice); 2389 kfree(ice);
2387 pci_disable_device(pci); 2390 pci_disable_device(pci);
2388 return err; 2391 return err;
@@ -2417,9 +2420,10 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2417 */ 2420 */
2418 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK)); 2421 outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
2419 2422
2420 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) { 2423 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops);
2424 if (err < 0) {
2421 snd_vt1724_free(ice); 2425 snd_vt1724_free(ice);
2422 return err; 2426 return err;
2423 } 2427 }
2424 2428
2425 snd_card_set_dev(card, &pci->dev); 2429 snd_card_set_dev(card, &pci->dev);
@@ -2457,8 +2461,9 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2457 2461
2458 strcpy(card->driver, "ICE1724"); 2462 strcpy(card->driver, "ICE1724");
2459 strcpy(card->shortname, "ICEnsemble ICE1724"); 2463 strcpy(card->shortname, "ICEnsemble ICE1724");
2460 2464
2461 if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) { 2465 err = snd_vt1724_create(card, pci, model[dev], &ice);
2466 if (err < 0) {
2462 snd_card_free(card); 2467 snd_card_free(card);
2463 return err; 2468 return err;
2464 } 2469 }
@@ -2470,7 +2475,8 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2470 if (c->driver) /* specific driver? */ 2475 if (c->driver) /* specific driver? */
2471 strcpy(card->driver, c->driver); 2476 strcpy(card->driver, c->driver);
2472 if (c->chip_init) { 2477 if (c->chip_init) {
2473 if ((err = c->chip_init(ice)) < 0) { 2478 err = c->chip_init(ice);
2479 if (err < 0) {
2474 snd_card_free(card); 2480 snd_card_free(card);
2475 return err; 2481 return err;
2476 } 2482 }
@@ -2480,15 +2486,15 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2480 } 2486 }
2481 } 2487 }
2482 c = &no_matched; 2488 c = &no_matched;
2483 __found: 2489__found:
2484 /* 2490 /*
2485 * VT1724 has separate DMAs for the analog and the SPDIF streams while 2491 * VT1724 has separate DMAs for the analog and the SPDIF streams while
2486 * ICE1712 has only one for both (mixed up). 2492 * ICE1712 has only one for both (mixed up).
2487 * 2493 *
2488 * Confusingly the analog PCM is named "professional" here because it 2494 * Confusingly the analog PCM is named "professional" here because it
2489 * was called so in ice1712 driver, and vt1724 driver is derived from 2495 * was called so in ice1712 driver, and vt1724 driver is derived from
2490 * ice1712 driver. 2496 * ice1712 driver.
2491 */ 2497 */
2492 ice->pro_rate_default = PRO_RATE_DEFAULT; 2498 ice->pro_rate_default = PRO_RATE_DEFAULT;
2493 if (!ice->is_spdif_master) 2499 if (!ice->is_spdif_master)
2494 ice->is_spdif_master = stdclock_is_spdif_master; 2500 ice->is_spdif_master = stdclock_is_spdif_master;
@@ -2503,46 +2509,53 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2503 if (!ice->hw_rates) 2509 if (!ice->hw_rates)
2504 set_std_hw_rates(ice); 2510 set_std_hw_rates(ice);
2505 2511
2506 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) { 2512 err = snd_vt1724_pcm_profi(ice, pcm_dev++);
2513 if (err < 0) {
2507 snd_card_free(card); 2514 snd_card_free(card);
2508 return err; 2515 return err;
2509 } 2516 }
2510 2517
2511 if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) { 2518 err = snd_vt1724_pcm_spdif(ice, pcm_dev++);
2519 if (err < 0) {
2512 snd_card_free(card); 2520 snd_card_free(card);
2513 return err; 2521 return err;
2514 } 2522 }
2515 2523
2516 if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) { 2524 err = snd_vt1724_pcm_indep(ice, pcm_dev++);
2525 if (err < 0) {
2517 snd_card_free(card); 2526 snd_card_free(card);
2518 return err; 2527 return err;
2519 } 2528 }
2520 2529
2521 if ((err = snd_vt1724_ac97_mixer(ice)) < 0) { 2530 err = snd_vt1724_ac97_mixer(ice);
2531 if (err < 0) {
2522 snd_card_free(card); 2532 snd_card_free(card);
2523 return err; 2533 return err;
2524 } 2534 }
2525 2535
2526 if ((err = snd_vt1724_build_controls(ice)) < 0) { 2536 err = snd_vt1724_build_controls(ice);
2537 if (err < 0) {
2527 snd_card_free(card); 2538 snd_card_free(card);
2528 return err; 2539 return err;
2529 } 2540 }
2530 2541
2531 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */ 2542 if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
2532 if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) { 2543 err = snd_vt1724_spdif_build_controls(ice);
2544 if (err < 0) {
2533 snd_card_free(card); 2545 snd_card_free(card);
2534 return err; 2546 return err;
2535 } 2547 }
2536 } 2548 }
2537 2549
2538 if (c->build_controls) { 2550 if (c->build_controls) {
2539 if ((err = c->build_controls(ice)) < 0) { 2551 err = c->build_controls(ice);
2552 if (err < 0) {
2540 snd_card_free(card); 2553 snd_card_free(card);
2541 return err; 2554 return err;
2542 } 2555 }
2543 } 2556 }
2544 2557
2545 if (! c->no_mpu401) { 2558 if (!c->no_mpu401) {
2546 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) { 2559 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2547 struct snd_rawmidi *rmidi; 2560 struct snd_rawmidi *rmidi;
2548 2561
@@ -2574,7 +2587,8 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2574 sprintf(card->longname, "%s at 0x%lx, irq %i", 2587 sprintf(card->longname, "%s at 0x%lx, irq %i",
2575 card->shortname, ice->port, ice->irq); 2588 card->shortname, ice->port, ice->irq);
2576 2589
2577 if ((err = snd_card_register(card)) < 0) { 2590 err = snd_card_register(card);
2591 if (err < 0) {
2578 snd_card_free(card); 2592 snd_card_free(card);
2579 return err; 2593 return err;
2580 } 2594 }
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index b4e0c16852a6..c51659b9caf6 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -21,7 +21,7 @@
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 */ 24 */
25 25
26#include <asm/io.h> 26#include <asm/io.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
@@ -34,9 +34,10 @@
34#include "ice1712.h" 34#include "ice1712.h"
35#include "envy24ht.h" 35#include "envy24ht.h"
36#include "juli.h" 36#include "juli.h"
37
37struct juli_spec { 38struct juli_spec {
38 struct ak4114 *ak4114; 39 struct ak4114 *ak4114;
39 unsigned int analog: 1; 40 unsigned int analog:1;
40}; 41};
41 42
42/* 43/*
@@ -160,14 +161,17 @@ static int get_gpio_val(int rate)
160 return 0; 161 return 0;
161} 162}
162 163
163static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val) 164static void juli_ak4114_write(void *private_data, unsigned char reg,
165 unsigned char val)
164{ 166{
165 snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR, reg, val); 167 snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR,
168 reg, val);
166} 169}
167 170
168static unsigned char juli_ak4114_read(void *private_data, unsigned char reg) 171static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
169{ 172{
170 return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR, reg); 173 return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data,
174 AK4114_ADDR, reg);
171} 175}
172 176
173/* 177/*
@@ -175,7 +179,7 @@ static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
175 * to the external rate 179 * to the external rate
176 */ 180 */
177static void juli_spdif_in_open(struct snd_ice1712 *ice, 181static void juli_spdif_in_open(struct snd_ice1712 *ice,
178 struct snd_pcm_substream *substream) 182 struct snd_pcm_substream *substream)
179{ 183{
180 struct juli_spec *spec = ice->spec; 184 struct juli_spec *spec = ice->spec;
181 struct snd_pcm_runtime *runtime = substream->runtime; 185 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -208,7 +212,8 @@ static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
208{ 212{
209 struct snd_ice1712 *ice = ak->private_data[0]; 213 struct snd_ice1712 *ice = ak->private_data[0];
210 214
211 snd_assert(chip == 0, return); 215 if (snd_BUG_ON(chip))
216 return;
212 snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data); 217 snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data);
213} 218}
214 219
@@ -571,10 +576,12 @@ static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
571static int __devinit juli_init(struct snd_ice1712 *ice) 576static int __devinit juli_init(struct snd_ice1712 *ice)
572{ 577{
573 static const unsigned char ak4114_init_vals[] = { 578 static const unsigned char ak4114_init_vals[] = {
574 /* AK4117_REG_PWRDN */ AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1, 579 /* AK4117_REG_PWRDN */ AK4114_RST | AK4114_PWN |
580 AK4114_OCKS0 | AK4114_OCKS1,
575 /* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S, 581 /* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S,
576 /* AK4114_REG_IO0 */ AK4114_TX1E, 582 /* AK4114_REG_IO0 */ AK4114_TX1E,
577 /* AK4114_REG_IO1 */ AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1), 583 /* AK4114_REG_IO1 */ AK4114_EFH_1024 | AK4114_DIT |
584 AK4114_IPS(1),
578 /* AK4114_REG_INT0_MASK */ 0, 585 /* AK4114_REG_INT0_MASK */ 0,
579 /* AK4114_REG_INT1_MASK */ 0 586 /* AK4114_REG_INT1_MASK */ 0
580 }; 587 };
@@ -604,12 +611,14 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
604 spec->ak4114->check_flags = 0; 611 spec->ak4114->check_flags = 0;
605 612
606#if 0 613#if 0
607 /* it seems that the analog doughter board detection does not work 614/*
608 reliably, so force the analog flag; it should be very rare 615 * it seems that the analog doughter board detection does not work reliably, so
609 to use Juli@ without the analog doughter board */ 616 * force the analog flag; it should be very rare (if ever) to come at Juli@
617 * used without the analog daughter board
618 */
610 spec->analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1; 619 spec->analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1;
611#else 620#else
612 spec->analog = 1; 621 spec->analog = 1;
613#endif 622#endif
614 623
615 if (spec->analog) { 624 if (spec->analog) {
@@ -617,14 +626,16 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
617 ice->num_total_dacs = 2; 626 ice->num_total_dacs = 2;
618 ice->num_total_adcs = 2; 627 ice->num_total_adcs = 2;
619 628
620 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); 629 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
621 if (! ak) 630 ak = ice->akm;
631 if (!ak)
622 return -ENOMEM; 632 return -ENOMEM;
623 ice->akm_codecs = 1; 633 ice->akm_codecs = 1;
624 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice)) < 0) 634 err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice);
635 if (err < 0)
625 return err; 636 return err;
626 } 637 }
627 638
628 /* juli is clocked by Xilinx array */ 639 /* juli is clocked by Xilinx array */
629 ice->hw_rates = &juli_rates_info; 640 ice->hw_rates = &juli_rates_info;
630 ice->is_spdif_master = juli_is_spdif_master; 641 ice->is_spdif_master = juli_is_spdif_master;
diff --git a/sound/pci/ice1712/phase.c b/sound/pci/ice1712/phase.c
index 5a158b73dcaa..de29be8c9657 100644
--- a/sound/pci/ice1712/phase.c
+++ b/sound/pci/ice1712/phase.c
@@ -22,15 +22,24 @@
22 */ 22 */
23 23
24/* PHASE 22 overview: 24/* PHASE 22 overview:
25 * Audio controller: VIA Envy24HT-S (slightly trimmed down version of Envy24HT) 25 * Audio controller: VIA Envy24HT-S (slightly trimmed down Envy24HT, 4in/4out)
26 * Analog chip: AK4524 (partially via Philip's 74HCT125) 26 * Analog chip: AK4524 (partially via Philip's 74HCT125)
27 * Digital receiver: CS8414-CS (not supported in this release) 27 * Digital receiver: CS8414-CS (supported in this release)
28 * PHASE 22 revision 2.0 and Terrasoniq/Musonik TS22PCI have CS8416
29 * (support status unknown, please test and report)
28 * 30 *
29 * Envy connects to AK4524 31 * Envy connects to AK4524
30 * - CS directly from GPIO 10 32 * - CS directly from GPIO 10
31 * - CCLK via 74HCT125's gate #4 from GPIO 4 33 * - CCLK via 74HCT125's gate #4 from GPIO 4
32 * - CDTI via 74HCT125's gate #2 from GPIO 5 34 * - CDTI via 74HCT125's gate #2 from GPIO 5
33 * CDTI may be completely blocked by 74HCT125's gate #1 controlled by GPIO 3 35 * CDTI may be completely blocked by 74HCT125's gate #1
36 * controlled by GPIO 3
37 */
38
39/* PHASE 28 overview:
40 * Audio controller: VIA Envy24HT (full untrimmed version, 4in/8out)
41 * Analog chip: WM8770 (8 channel 192k DAC, 2 channel 96k ADC)
42 * Digital receiver: CS8414-CS (supported in this release)
34 */ 43 */
35 44
36#include <asm/io.h> 45#include <asm/io.h>
@@ -77,18 +86,18 @@ struct phase28_spec {
77 * Computed as 20 * Log10(255 / x) 86 * Computed as 20 * Log10(255 / x)
78 */ 87 */
79static const unsigned char wm_vol[256] = { 88static const unsigned char wm_vol[256] = {
80 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23, 89 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24,
81 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17, 90 24, 23, 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18,
82 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 91 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14,
83 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 92 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11,
84 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 93 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
85 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 94 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
86 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 95 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5,
87 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 96 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
88 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 97 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
89 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 98 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
91 0, 0 100 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
92}; 101};
93 102
94#define WM_VOL_MAX (sizeof(wm_vol) - 1) 103#define WM_VOL_MAX (sizeof(wm_vol) - 1)
@@ -117,26 +126,31 @@ static int __devinit phase22_init(struct snd_ice1712 *ice)
117 struct snd_akm4xxx *ak; 126 struct snd_akm4xxx *ak;
118 int err; 127 int err;
119 128
120 // Configure DAC/ADC description for generic part of ice1724 129 /* Configure DAC/ADC description for generic part of ice1724 */
121 switch (ice->eeprom.subvendor) { 130 switch (ice->eeprom.subvendor) {
122 case VT1724_SUBDEVICE_PHASE22: 131 case VT1724_SUBDEVICE_PHASE22:
132 case VT1724_SUBDEVICE_TS22:
123 ice->num_total_dacs = 2; 133 ice->num_total_dacs = 2;
124 ice->num_total_adcs = 2; 134 ice->num_total_adcs = 2;
125 ice->vt1720 = 1; // Envy24HT-S have 16 bit wide GPIO 135 ice->vt1720 = 1; /* Envy24HT-S have 16 bit wide GPIO */
126 break; 136 break;
127 default: 137 default:
128 snd_BUG(); 138 snd_BUG();
129 return -EINVAL; 139 return -EINVAL;
130 } 140 }
131 141
132 // Initialize analog chips 142 /* Initialize analog chips */
133 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); 143 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
134 if (! ak) 144 ak = ice->akm;
145 if (!ak)
135 return -ENOMEM; 146 return -ENOMEM;
136 ice->akm_codecs = 1; 147 ice->akm_codecs = 1;
137 switch (ice->eeprom.subvendor) { 148 switch (ice->eeprom.subvendor) {
138 case VT1724_SUBDEVICE_PHASE22: 149 case VT1724_SUBDEVICE_PHASE22:
139 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_phase22, &akm_phase22_priv, ice)) < 0) 150 case VT1724_SUBDEVICE_TS22:
151 err = snd_ice1712_akm4xxx_init(ak, &akm_phase22,
152 &akm_phase22_priv, ice);
153 if (err < 0)
140 return err; 154 return err;
141 break; 155 break;
142 } 156 }
@@ -150,6 +164,7 @@ static int __devinit phase22_add_controls(struct snd_ice1712 *ice)
150 164
151 switch (ice->eeprom.subvendor) { 165 switch (ice->eeprom.subvendor) {
152 case VT1724_SUBDEVICE_PHASE22: 166 case VT1724_SUBDEVICE_PHASE22:
167 case VT1724_SUBDEVICE_TS22:
153 err = snd_ice1712_akm4xxx_build_controls(ice); 168 err = snd_ice1712_akm4xxx_build_controls(ice);
154 if (err < 0) 169 if (err < 0)
155 return err; 170 return err;
@@ -158,9 +173,10 @@ static int __devinit phase22_add_controls(struct snd_ice1712 *ice)
158} 173}
159 174
160static unsigned char phase22_eeprom[] __devinitdata = { 175static unsigned char phase22_eeprom[] __devinitdata = {
161 [ICE_EEP2_SYSCONF] = 0x00, /* 1xADC, 1xDACs */ 176 [ICE_EEP2_SYSCONF] = 0x28, /* clock 512, mpu 401,
177 spdif-in/1xADC, 1xDACs */
162 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 178 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
163 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit */ 179 [ICE_EEP2_I2S] = 0xf0, /* vol, 96k, 24bit */
164 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 180 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
165 [ICE_EEP2_GPIO_DIR] = 0xff, 181 [ICE_EEP2_GPIO_DIR] = 0xff,
166 [ICE_EEP2_GPIO_DIR1] = 0xff, 182 [ICE_EEP2_GPIO_DIR1] = 0xff,
@@ -174,7 +190,8 @@ static unsigned char phase22_eeprom[] __devinitdata = {
174}; 190};
175 191
176static unsigned char phase28_eeprom[] __devinitdata = { 192static unsigned char phase28_eeprom[] __devinitdata = {
177 [ICE_EEP2_SYSCONF] = 0x0b, /* clock 512, spdif-in/ADC, 4DACs */ 193 [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401,
194 spdif-in/1xADC, 4xDACs */
178 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 195 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
179 [ICE_EEP2_I2S] = 0xfc, /* vol, 96k, 24bit, 192k */ 196 [ICE_EEP2_I2S] = 0xfc, /* vol, 96k, 24bit, 192k */
180 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 197 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
@@ -192,15 +209,16 @@ static unsigned char phase28_eeprom[] __devinitdata = {
192/* 209/*
193 * write data in the SPI mode 210 * write data in the SPI mode
194 */ 211 */
195static void phase28_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits) 212static void phase28_spi_write(struct snd_ice1712 *ice, unsigned int cs,
213 unsigned int data, int bits)
196{ 214{
197 unsigned int tmp; 215 unsigned int tmp;
198 int i; 216 int i;
199 217
200 tmp = snd_ice1712_gpio_read(ice); 218 tmp = snd_ice1712_gpio_read(ice);
201 219
202 snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RW|PHASE28_SPI_MOSI|PHASE28_SPI_CLK| 220 snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RW|PHASE28_SPI_MOSI|
203 PHASE28_WM_CS)); 221 PHASE28_SPI_CLK|PHASE28_WM_CS));
204 tmp |= PHASE28_WM_RW; 222 tmp |= PHASE28_WM_RW;
205 tmp &= ~cs; 223 tmp &= ~cs;
206 snd_ice1712_gpio_write(ice, tmp); 224 snd_ice1712_gpio_write(ice, tmp);
@@ -259,14 +277,16 @@ static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
259 ice->akm[0].images[reg + 1] = val; 277 ice->akm[0].images[reg + 1] = val;
260} 278}
261 279
262static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master) 280static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index,
281 unsigned short vol, unsigned short master)
263{ 282{
264 unsigned char nvol; 283 unsigned char nvol;
265 284
266 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE)) 285 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
267 nvol = 0; 286 nvol = 0;
268 else 287 else
269 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX]; 288 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) *
289 (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX];
270 290
271 wm_put(ice, index, nvol); 291 wm_put(ice, index, nvol);
272 wm_put_nocache(ice, index, 0x180 | nvol); 292 wm_put_nocache(ice, index, 0x180 | nvol);
@@ -277,17 +297,20 @@ static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned sho
277 */ 297 */
278#define wm_pcm_mute_info snd_ctl_boolean_mono_info 298#define wm_pcm_mute_info snd_ctl_boolean_mono_info
279 299
280static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 300static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
281{ 302{
282 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 303 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
283 304
284 mutex_lock(&ice->gpio_mutex); 305 mutex_lock(&ice->gpio_mutex);
285 ucontrol->value.integer.value[0] = (wm_get(ice, WM_MUTE) & 0x10) ? 0 : 1; 306 ucontrol->value.integer.value[0] = (wm_get(ice, WM_MUTE) & 0x10) ?
307 0 : 1;
286 mutex_unlock(&ice->gpio_mutex); 308 mutex_unlock(&ice->gpio_mutex);
287 return 0; 309 return 0;
288} 310}
289 311
290static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 312static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
291{ 314{
292 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 315 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
293 unsigned short nval, oval; 316 unsigned short nval, oval;
@@ -296,7 +319,8 @@ static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va
296 snd_ice1712_save_gpio_status(ice); 319 snd_ice1712_save_gpio_status(ice);
297 oval = wm_get(ice, WM_MUTE); 320 oval = wm_get(ice, WM_MUTE);
298 nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10); 321 nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10);
299 if ((change = (nval != oval))) 322 change = (nval != oval);
323 if (change)
300 wm_put(ice, WM_MUTE, nval); 324 wm_put(ice, WM_MUTE, nval);
301 snd_ice1712_restore_gpio_status(ice); 325 snd_ice1712_restore_gpio_status(ice);
302 326
@@ -306,7 +330,8 @@ static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va
306/* 330/*
307 * Master volume attenuation mixer control 331 * Master volume attenuation mixer control
308 */ 332 */
309static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 333static int wm_master_vol_info(struct snd_kcontrol *kcontrol,
334 struct snd_ctl_elem_info *uinfo)
310{ 335{
311 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 336 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
312 uinfo->count = 2; 337 uinfo->count = 2;
@@ -315,17 +340,20 @@ static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
315 return 0; 340 return 0;
316} 341}
317 342
318static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 343static int wm_master_vol_get(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
319{ 345{
320 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 346 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
321 struct phase28_spec *spec = ice->spec; 347 struct phase28_spec *spec = ice->spec;
322 int i; 348 int i;
323 for (i=0; i<2; i++) 349 for (i = 0; i < 2; i++)
324 ucontrol->value.integer.value[i] = spec->master[i] & ~WM_VOL_MUTE; 350 ucontrol->value.integer.value[i] = spec->master[i] &
351 ~WM_VOL_MUTE;
325 return 0; 352 return 0;
326} 353}
327 354
328static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 355static int wm_master_vol_put(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
329{ 357{
330 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 358 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
331 struct phase28_spec *spec = ice->spec; 359 struct phase28_spec *spec = ice->spec;
@@ -355,38 +383,38 @@ static int __devinit phase28_init(struct snd_ice1712 *ice)
355{ 383{
356 static const unsigned short wm_inits_phase28[] = { 384 static const unsigned short wm_inits_phase28[] = {
357 /* These come first to reduce init pop noise */ 385 /* These come first to reduce init pop noise */
358 0x1b, 0x044, /* ADC Mux (AC'97 source) */ 386 0x1b, 0x044, /* ADC Mux (AC'97 source) */
359 0x1c, 0x00B, /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */ 387 0x1c, 0x00B, /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
360 0x1d, 0x009, /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */ 388 0x1d, 0x009, /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */
361 389
362 0x18, 0x000, /* All power-up */ 390 0x18, 0x000, /* All power-up */
363 391
364 0x16, 0x122, /* I2S, normal polarity, 24bit */ 392 0x16, 0x122, /* I2S, normal polarity, 24bit */
365 0x17, 0x022, /* 256fs, slave mode */ 393 0x17, 0x022, /* 256fs, slave mode */
366 0x00, 0, /* DAC1 analog mute */ 394 0x00, 0, /* DAC1 analog mute */
367 0x01, 0, /* DAC2 analog mute */ 395 0x01, 0, /* DAC2 analog mute */
368 0x02, 0, /* DAC3 analog mute */ 396 0x02, 0, /* DAC3 analog mute */
369 0x03, 0, /* DAC4 analog mute */ 397 0x03, 0, /* DAC4 analog mute */
370 0x04, 0, /* DAC5 analog mute */ 398 0x04, 0, /* DAC5 analog mute */
371 0x05, 0, /* DAC6 analog mute */ 399 0x05, 0, /* DAC6 analog mute */
372 0x06, 0, /* DAC7 analog mute */ 400 0x06, 0, /* DAC7 analog mute */
373 0x07, 0, /* DAC8 analog mute */ 401 0x07, 0, /* DAC8 analog mute */
374 0x08, 0x100, /* master analog mute */ 402 0x08, 0x100, /* master analog mute */
375 0x09, 0xff, /* DAC1 digital full */ 403 0x09, 0xff, /* DAC1 digital full */
376 0x0a, 0xff, /* DAC2 digital full */ 404 0x0a, 0xff, /* DAC2 digital full */
377 0x0b, 0xff, /* DAC3 digital full */ 405 0x0b, 0xff, /* DAC3 digital full */
378 0x0c, 0xff, /* DAC4 digital full */ 406 0x0c, 0xff, /* DAC4 digital full */
379 0x0d, 0xff, /* DAC5 digital full */ 407 0x0d, 0xff, /* DAC5 digital full */
380 0x0e, 0xff, /* DAC6 digital full */ 408 0x0e, 0xff, /* DAC6 digital full */
381 0x0f, 0xff, /* DAC7 digital full */ 409 0x0f, 0xff, /* DAC7 digital full */
382 0x10, 0xff, /* DAC8 digital full */ 410 0x10, 0xff, /* DAC8 digital full */
383 0x11, 0x1ff, /* master digital full */ 411 0x11, 0x1ff, /* master digital full */
384 0x12, 0x000, /* phase normal */ 412 0x12, 0x000, /* phase normal */
385 0x13, 0x090, /* unmute DAC L/R */ 413 0x13, 0x090, /* unmute DAC L/R */
386 0x14, 0x000, /* all unmute */ 414 0x14, 0x000, /* all unmute */
387 0x15, 0x000, /* no deemphasis, no ZFLG */ 415 0x15, 0x000, /* no deemphasis, no ZFLG */
388 0x19, 0x000, /* -12dB ADC/L */ 416 0x19, 0x000, /* -12dB ADC/L */
389 0x1a, 0x000, /* -12dB ADC/R */ 417 0x1a, 0x000, /* -12dB ADC/R */
390 (unsigned short)-1 418 (unsigned short)-1
391 }; 419 };
392 420
@@ -404,17 +432,19 @@ static int __devinit phase28_init(struct snd_ice1712 *ice)
404 return -ENOMEM; 432 return -ENOMEM;
405 ice->spec = spec; 433 ice->spec = spec;
406 434
407 // Initialize analog chips 435 /* Initialize analog chips */
408 ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); 436 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
437 ak = ice->akm;
409 if (!ak) 438 if (!ak)
410 return -ENOMEM; 439 return -ENOMEM;
411 ice->akm_codecs = 1; 440 ice->akm_codecs = 1;
412 441
413 snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */ 442 snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for time being */
414 443
415 /* reset the wm codec as the SPI mode */ 444 /* reset the wm codec as the SPI mode */
416 snd_ice1712_save_gpio_status(ice); 445 snd_ice1712_save_gpio_status(ice);
417 snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RESET|PHASE28_WM_CS|PHASE28_HP_SEL)); 446 snd_ice1712_gpio_set_mask(ice, ~(PHASE28_WM_RESET|PHASE28_WM_CS|
447 PHASE28_HP_SEL));
418 448
419 tmp = snd_ice1712_gpio_read(ice); 449 tmp = snd_ice1712_gpio_read(ice);
420 tmp &= ~PHASE28_WM_RESET; 450 tmp &= ~PHASE28_WM_RESET;
@@ -446,7 +476,8 @@ static int __devinit phase28_init(struct snd_ice1712 *ice)
446/* 476/*
447 * DAC volume attenuation mixer control 477 * DAC volume attenuation mixer control
448 */ 478 */
449static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 479static int wm_vol_info(struct snd_kcontrol *kcontrol,
480 struct snd_ctl_elem_info *uinfo)
450{ 481{
451 int voices = kcontrol->private_value >> 8; 482 int voices = kcontrol->private_value >> 8;
452 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 483 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -456,7 +487,8 @@ static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *
456 return 0; 487 return 0;
457} 488}
458 489
459static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 490static int wm_vol_get(struct snd_kcontrol *kcontrol,
491 struct snd_ctl_elem_value *ucontrol)
460{ 492{
461 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 493 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
462 struct phase28_spec *spec = ice->spec; 494 struct phase28_spec *spec = ice->spec;
@@ -470,7 +502,8 @@ static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *
470 return 0; 502 return 0;
471} 503}
472 504
473static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 505static int wm_vol_put(struct snd_kcontrol *kcontrol,
506 struct snd_ctl_elem_value *ucontrol)
474{ 507{
475 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 508 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
476 struct phase28_spec *spec = ice->spec; 509 struct phase28_spec *spec = ice->spec;
@@ -501,7 +534,8 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *
501/* 534/*
502 * WM8770 mute control 535 * WM8770 mute control
503 */ 536 */
504static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { 537static int wm_mute_info(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_info *uinfo) {
505 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 539 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
506 uinfo->count = kcontrol->private_value >> 8; 540 uinfo->count = kcontrol->private_value >> 8;
507 uinfo->value.integer.min = 0; 541 uinfo->value.integer.min = 0;
@@ -509,7 +543,8 @@ static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info
509 return 0; 543 return 0;
510} 544}
511 545
512static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 546static int wm_mute_get(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
513{ 548{
514 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 549 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
515 struct phase28_spec *spec = ice->spec; 550 struct phase28_spec *spec = ice->spec;
@@ -524,7 +559,8 @@ static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value
524 return 0; 559 return 0;
525} 560}
526 561
527static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 562static int wm_mute_put(struct snd_kcontrol *kcontrol,
563 struct snd_ctl_elem_value *ucontrol)
528{ 564{
529 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 565 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
530 struct phase28_spec *spec = ice->spec; 566 struct phase28_spec *spec = ice->spec;
@@ -539,9 +575,10 @@ static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value
539 if (ucontrol->value.integer.value[i] != val) { 575 if (ucontrol->value.integer.value[i] != val) {
540 spec->vol[ofs + i] &= ~WM_VOL_MUTE; 576 spec->vol[ofs + i] &= ~WM_VOL_MUTE;
541 spec->vol[ofs + i] |= 577 spec->vol[ofs + i] |=
542 ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE; 578 ucontrol->value.integer.value[i] ? 0 :
579 WM_VOL_MUTE;
543 wm_set_vol(ice, ofs + i, spec->vol[ofs + i], 580 wm_set_vol(ice, ofs + i, spec->vol[ofs + i],
544 spec->master[i]); 581 spec->master[i]);
545 change = 1; 582 change = 1;
546 } 583 }
547 } 584 }
@@ -555,7 +592,8 @@ static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value
555 */ 592 */
556#define wm_master_mute_info snd_ctl_boolean_stereo_info 593#define wm_master_mute_info snd_ctl_boolean_stereo_info
557 594
558static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 595static int wm_master_mute_get(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_value *ucontrol)
559{ 597{
560 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 598 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
561 struct phase28_spec *spec = ice->spec; 599 struct phase28_spec *spec = ice->spec;
@@ -567,7 +605,8 @@ static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
567 return 0; 605 return 0;
568} 606}
569 607
570static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 608static int wm_master_mute_put(struct snd_kcontrol *kcontrol,
609 struct snd_ctl_elem_value *ucontrol)
571{ 610{
572 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 611 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
573 struct phase28_spec *spec = ice->spec; 612 struct phase28_spec *spec = ice->spec;
@@ -580,11 +619,12 @@ static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
580 int dac; 619 int dac;
581 spec->master[i] &= ~WM_VOL_MUTE; 620 spec->master[i] &= ~WM_VOL_MUTE;
582 spec->master[i] |= 621 spec->master[i] |=
583 ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE; 622 ucontrol->value.integer.value[i] ? 0 :
623 WM_VOL_MUTE;
584 for (dac = 0; dac < ice->num_total_dacs; dac += 2) 624 for (dac = 0; dac < ice->num_total_dacs; dac += 2)
585 wm_set_vol(ice, WM_DAC_ATTEN + dac + i, 625 wm_set_vol(ice, WM_DAC_ATTEN + dac + i,
586 spec->vol[dac + i], 626 spec->vol[dac + i],
587 spec->master[i]); 627 spec->master[i]);
588 change = 1; 628 change = 1;
589 } 629 }
590 } 630 }
@@ -597,7 +637,8 @@ static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
597#define PCM_0dB 0xff 637#define PCM_0dB 0xff
598#define PCM_RES 128 /* -64dB */ 638#define PCM_RES 128 /* -64dB */
599#define PCM_MIN (PCM_0dB - PCM_RES) 639#define PCM_MIN (PCM_0dB - PCM_RES)
600static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 640static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_info *uinfo)
601{ 642{
602 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 643 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
603 uinfo->count = 1; 644 uinfo->count = 1;
@@ -606,7 +647,8 @@ static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_in
606 return 0; 647 return 0;
607} 648}
608 649
609static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 650static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
610{ 652{
611 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 653 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
612 unsigned short val; 654 unsigned short val;
@@ -619,7 +661,8 @@ static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
619 return 0; 661 return 0;
620} 662}
621 663
622static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 664static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol,
665 struct snd_ctl_elem_value *ucontrol)
623{ 666{
624 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 667 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
625 unsigned short ovol, nvol; 668 unsigned short ovol, nvol;
@@ -633,7 +676,8 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
633 ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; 676 ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
634 if (ovol != nvol) { 677 if (ovol != nvol) {
635 wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */ 678 wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */
636 wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100); /* update */ 679 /* update */
680 wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100);
637 change = 1; 681 change = 1;
638 } 682 }
639 snd_ice1712_restore_gpio_status(ice); 683 snd_ice1712_restore_gpio_status(ice);
@@ -645,18 +689,22 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
645 */ 689 */
646#define phase28_deemp_info snd_ctl_boolean_mono_info 690#define phase28_deemp_info snd_ctl_boolean_mono_info
647 691
648static int phase28_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 692static int phase28_deemp_get(struct snd_kcontrol *kcontrol,
693 struct snd_ctl_elem_value *ucontrol)
649{ 694{
650 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 695 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
651 ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf; 696 ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) ==
697 0xf;
652 return 0; 698 return 0;
653} 699}
654 700
655static int phase28_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 701static int phase28_deemp_put(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_value *ucontrol)
656{ 703{
657 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 704 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
658 int temp, temp2; 705 int temp, temp2;
659 temp2 = temp = wm_get(ice, WM_DAC_CTRL2); 706 temp = wm_get(ice, WM_DAC_CTRL2);
707 temp2 = temp;
660 if (ucontrol->value.integer.value[0]) 708 if (ucontrol->value.integer.value[0])
661 temp |= 0xf; 709 temp |= 0xf;
662 else 710 else
@@ -671,7 +719,8 @@ static int phase28_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
671/* 719/*
672 * ADC Oversampling 720 * ADC Oversampling
673 */ 721 */
674static int phase28_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo) 722static int phase28_oversampling_info(struct snd_kcontrol *k,
723 struct snd_ctl_elem_info *uinfo)
675{ 724{
676 static char *texts[2] = { "128x", "64x" }; 725 static char *texts[2] = { "128x", "64x" };
677 726
@@ -680,25 +729,31 @@ static int phase28_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem
680 uinfo->value.enumerated.items = 2; 729 uinfo->value.enumerated.items = 2;
681 730
682 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 731 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
683 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 732 uinfo->value.enumerated.item = uinfo->value.enumerated.items -
684 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 733 1;
734 strcpy(uinfo->value.enumerated.name,
735 texts[uinfo->value.enumerated.item]);
685 736
686 return 0; 737 return 0;
687} 738}
688 739
689static int phase28_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 740static int phase28_oversampling_get(struct snd_kcontrol *kcontrol,
741 struct snd_ctl_elem_value *ucontrol)
690{ 742{
691 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 743 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
692 ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8; 744 ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) ==
745 0x8;
693 return 0; 746 return 0;
694} 747}
695 748
696static int phase28_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 749static int phase28_oversampling_put(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_value *ucontrol)
697{ 751{
698 int temp, temp2; 752 int temp, temp2;
699 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 753 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
700 754
701 temp2 = temp = wm_get(ice, WM_MASTER); 755 temp = wm_get(ice, WM_MASTER);
756 temp2 = temp;
702 757
703 if (ucontrol->value.enumerated.item[0]) 758 if (ucontrol->value.enumerated.item[0])
704 temp |= 0x8; 759 temp |= 0x8;
@@ -871,13 +926,16 @@ static int __devinit phase28_add_controls(struct snd_ice1712 *ice)
871 926
872 counts = ARRAY_SIZE(phase28_dac_controls); 927 counts = ARRAY_SIZE(phase28_dac_controls);
873 for (i = 0; i < counts; i++) { 928 for (i = 0; i < counts; i++) {
874 err = snd_ctl_add(ice->card, snd_ctl_new1(&phase28_dac_controls[i], ice)); 929 err = snd_ctl_add(ice->card,
930 snd_ctl_new1(&phase28_dac_controls[i],
931 ice));
875 if (err < 0) 932 if (err < 0)
876 return err; 933 return err;
877 } 934 }
878 935
879 for (i = 0; i < ARRAY_SIZE(wm_controls); i++) { 936 for (i = 0; i < ARRAY_SIZE(wm_controls); i++) {
880 err = snd_ctl_add(ice->card, snd_ctl_new1(&wm_controls[i], ice)); 937 err = snd_ctl_add(ice->card,
938 snd_ctl_new1(&wm_controls[i], ice));
881 if (err < 0) 939 if (err < 0)
882 return err; 940 return err;
883 } 941 }
@@ -904,5 +962,14 @@ struct snd_ice1712_card_info snd_vt1724_phase_cards[] __devinitdata = {
904 .eeprom_size = sizeof(phase28_eeprom), 962 .eeprom_size = sizeof(phase28_eeprom),
905 .eeprom_data = phase28_eeprom, 963 .eeprom_data = phase28_eeprom,
906 }, 964 },
965 {
966 .subvendor = VT1724_SUBDEVICE_TS22,
967 .name = "Terrasoniq TS22 PCI",
968 .model = "TS22",
969 .chip_init = phase22_init,
970 .build_controls = phase22_add_controls,
971 .eeprom_size = sizeof(phase22_eeprom),
972 .eeprom_data = phase22_eeprom,
973 },
907 { } /* terminator */ 974 { } /* terminator */
908}; 975};
diff --git a/sound/pci/ice1712/phase.h b/sound/pci/ice1712/phase.h
index 13e841b55488..7fc22d9d442f 100644
--- a/sound/pci/ice1712/phase.h
+++ b/sound/pci/ice1712/phase.h
@@ -22,13 +22,15 @@
22 * along with this program; if not, write to the Free Software 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 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * 24 *
25 */ 25 */
26 26
27#define PHASE_DEVICE_DESC "{Terratec,Phase 22},"\ 27#define PHASE_DEVICE_DESC "{Terratec,Phase 22},"\
28 "{Terratec,Phase 28}," 28 "{Terratec,Phase 28},"\
29 "{Terrasoniq,TS22},"
29 30
30#define VT1724_SUBDEVICE_PHASE22 0x3b155011 31#define VT1724_SUBDEVICE_PHASE22 0x3b155011
31#define VT1724_SUBDEVICE_PHASE28 0x3b154911 32#define VT1724_SUBDEVICE_PHASE28 0x3b154911
33#define VT1724_SUBDEVICE_TS22 0x3b157b11
32 34
33/* entry point */ 35/* entry point */
34extern struct snd_ice1712_card_info snd_vt1724_phase_cards[]; 36extern struct snd_ice1712_card_info snd_vt1724_phase_cards[];
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index 203cdc1bf8da..6bc3f91b7281 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -43,7 +43,8 @@
43/* WM8776 registers */ 43/* WM8776 registers */
44#define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */ 44#define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */
45#define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */ 45#define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */
46#define WM_HP_MASTER 0x02 /* headphone master (both channels), override LLR */ 46#define WM_HP_MASTER 0x02 /* headphone master (both channels) */
47 /* override LLR */
47#define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */ 48#define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */
48#define WM_DAC_ATTEN_R 0x04 49#define WM_DAC_ATTEN_R 0x04
49#define WM_DAC_MASTER 0x05 50#define WM_DAC_MASTER 0x05
@@ -740,7 +741,7 @@ static int __devinit pontis_init(struct snd_ice1712 *ice)
740 WM_DAC_ATTEN_L, 0x0100, /* DAC 0dB */ 741 WM_DAC_ATTEN_L, 0x0100, /* DAC 0dB */
741 WM_DAC_ATTEN_R, 0x0000, /* DAC 0dB */ 742 WM_DAC_ATTEN_R, 0x0000, /* DAC 0dB */
742 WM_DAC_ATTEN_R, 0x0100, /* DAC 0dB */ 743 WM_DAC_ATTEN_R, 0x0100, /* DAC 0dB */
743 // WM_DAC_MASTER, 0x0100, /* DAC master muted */ 744 /* WM_DAC_MASTER, 0x0100, */ /* DAC master muted */
744 WM_PHASE_SWAP, 0x0000, /* phase normal */ 745 WM_PHASE_SWAP, 0x0000, /* phase normal */
745 WM_DAC_CTRL2, 0x0000, /* no deemphasis, no ZFLG */ 746 WM_DAC_CTRL2, 0x0000, /* no deemphasis, no ZFLG */
746 WM_ADC_ATTEN_L, 0x0000, /* ADC muted */ 747 WM_ADC_ATTEN_L, 0x0000, /* ADC muted */
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index 4d2631434dc8..b508bb360b97 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24) 2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 * 3 *
4 * Lowlevel functions for M-Audio Revolution 7.1 4 * Lowlevel functions for M-Audio Audiophile 192, Revolution 7.1 and 5.1
5 * 5 *
6 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de> 6 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
7 * 7 *
@@ -48,7 +48,7 @@ static void revo_i2s_mclk_changed(struct snd_ice1712 *ice)
48} 48}
49 49
50/* 50/*
51 * change the rate of envy24HT, AK4355 and AK4381 51 * change the rate of Envy24HT, AK4355 and AK4381
52 */ 52 */
53static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 53static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
54{ 54{
@@ -83,8 +83,8 @@ static void revo_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
83 tmp = snd_akm4xxx_get(ak, 0, reg); 83 tmp = snd_akm4xxx_get(ak, 0, reg);
84 tmp &= ~(0x03 << shift); 84 tmp &= ~(0x03 << shift);
85 tmp |= dfs << shift; 85 tmp |= dfs << shift;
86 // snd_akm4xxx_write(ak, 0, reg, tmp); 86 /* snd_akm4xxx_write(ak, 0, reg, tmp); */
87 snd_akm4xxx_set(ak, 0, reg, tmp); /* the value is written in reset(0) */ 87 snd_akm4xxx_set(ak, 0, reg, tmp); /* value is written in reset(0) */
88 snd_akm4xxx_reset(ak, 0); 88 snd_akm4xxx_reset(ak, 0);
89} 89}
90 90
@@ -216,6 +216,7 @@ static const struct snd_akm4xxx_dac_channel revo51_dac[] = {
216 AK_DAC("PCM Center Playback Volume", 1), 216 AK_DAC("PCM Center Playback Volume", 1),
217 AK_DAC("PCM LFE Playback Volume", 1), 217 AK_DAC("PCM LFE Playback Volume", 1),
218 AK_DAC("PCM Rear Playback Volume", 2), 218 AK_DAC("PCM Rear Playback Volume", 2),
219 AK_DAC("PCM Headphone Volume", 2),
219}; 220};
220 221
221static const char *revo51_adc_input_names[] = { 222static const char *revo51_adc_input_names[] = {
@@ -279,7 +280,7 @@ static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
279 280
280static struct snd_akm4xxx akm_revo51 __devinitdata = { 281static struct snd_akm4xxx akm_revo51 __devinitdata = {
281 .type = SND_AK4358, 282 .type = SND_AK4358,
282 .num_dacs = 6, 283 .num_dacs = 8,
283 .ops = { 284 .ops = {
284 .set_rate_val = revo_set_rate_val 285 .set_rate_val = revo_set_rate_val
285 }, 286 },
@@ -508,7 +509,7 @@ static int __devinit revo_init(struct snd_ice1712 *ice)
508 ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed; 509 ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
509 break; 510 break;
510 case VT1724_SUBDEVICE_REVOLUTION51: 511 case VT1724_SUBDEVICE_REVOLUTION51:
511 ice->num_total_dacs = 6; 512 ice->num_total_dacs = 8;
512 ice->num_total_adcs = 2; 513 ice->num_total_adcs = 2;
513 break; 514 break;
514 case VT1724_SUBDEVICE_AUDIOPHILE192: 515 case VT1724_SUBDEVICE_AUDIOPHILE192:
@@ -524,16 +525,20 @@ static int __devinit revo_init(struct snd_ice1712 *ice)
524 ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL); 525 ak = ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
525 if (! ak) 526 if (! ak)
526 return -ENOMEM; 527 return -ENOMEM;
527 ice->akm_codecs = 2;
528 switch (ice->eeprom.subvendor) { 528 switch (ice->eeprom.subvendor) {
529 case VT1724_SUBDEVICE_REVOLUTION71: 529 case VT1724_SUBDEVICE_REVOLUTION71:
530 ice->akm_codecs = 2; 530 ice->akm_codecs = 2;
531 if ((err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice)) < 0) 531 err = snd_ice1712_akm4xxx_init(ak, &akm_revo_front,
532 &akm_revo_front_priv, ice);
533 if (err < 0)
532 return err; 534 return err;
533 if ((err = snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice)) < 0) 535 err = snd_ice1712_akm4xxx_init(ak+1, &akm_revo_surround,
536 &akm_revo_surround_priv, ice);
537 if (err < 0)
534 return err; 538 return err;
535 /* unmute all codecs */ 539 /* unmute all codecs */
536 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE); 540 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
541 VT1724_REVO_MUTE);
537 break; 542 break;
538 case VT1724_SUBDEVICE_REVOLUTION51: 543 case VT1724_SUBDEVICE_REVOLUTION51:
539 ice->akm_codecs = 2; 544 ice->akm_codecs = 2;
diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c
index a08d17c7e651..5af9e84456d1 100644
--- a/sound/pci/ice1712/wtm.c
+++ b/sound/pci/ice1712/wtm.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * ALSA driver for ICEnsemble VT1724 (Envy24HT) 2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
3 * 3 *
4 * Lowlevel functions for Ego Sys Waveterminal 192M 4 * Lowlevel functions for Ego Sys Waveterminal 192M
5 * 5 *
6 * Copyright (c) 2006 Guedez Clement <klem.dev@gmail.com> 6 * Copyright (c) 2006 Guedez Clement <klem.dev@gmail.com>
7 * Some functions are taken from the Prodigy192 driver 7 * Some functions are taken from the Prodigy192 driver
8 * source 8 * source
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
@@ -20,12 +20,12 @@
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 */ 24 */
25 25
26 26
27 27
28#include <asm/io.h> 28#include <linux/io.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/init.h> 31#include <linux/init.h>
@@ -39,9 +39,9 @@
39 39
40 40
41/* 41/*
42 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus 42 * 2*ADC 6*DAC no1 ringbuffer r/w on i2c bus
43 */ 43 */
44static inline void stac9460_put(struct snd_ice1712 *ice, int reg, 44static inline void stac9460_put(struct snd_ice1712 *ice, int reg,
45 unsigned char val) 45 unsigned char val)
46{ 46{
47 snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val); 47 snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val);
@@ -73,7 +73,7 @@ static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
73#define stac9460_dac_mute_info snd_ctl_boolean_mono_info 73#define stac9460_dac_mute_info snd_ctl_boolean_mono_info
74 74
75static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, 75static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
76 struct snd_ctl_elem_value *ucontrol) 76 struct snd_ctl_elem_value *ucontrol)
77{ 77{
78 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 78 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
79 unsigned char val; 79 unsigned char val;
@@ -88,14 +88,14 @@ static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
88 } 88 }
89 if (id < 6) 89 if (id < 6)
90 val = stac9460_get(ice, idx); 90 val = stac9460_get(ice, idx);
91 else 91 else
92 val = stac9460_2_get(ice,idx - 6); 92 val = stac9460_2_get(ice, idx - 6);
93 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; 93 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
94 return 0; 94 return 0;
95} 95}
96 96
97static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, 97static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
98 struct snd_ctl_elem_value *ucontrol) 98 struct snd_ctl_elem_value *ucontrol)
99{ 99{
100 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 100 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
101 unsigned char new, old; 101 unsigned char new, old;
@@ -105,8 +105,8 @@ static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
105 if (kcontrol->private_value) { 105 if (kcontrol->private_value) {
106 idx = STAC946X_MASTER_VOLUME; 106 idx = STAC946X_MASTER_VOLUME;
107 old = stac9460_get(ice, idx); 107 old = stac9460_get(ice, idx);
108 new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | 108 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
109 (old & ~0x80); 109 (old & ~0x80);
110 change = (new != old); 110 change = (new != old);
111 if (change) { 111 if (change) {
112 stac9460_put(ice, idx, new); 112 stac9460_put(ice, idx, new);
@@ -117,16 +117,16 @@ static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
117 idx = id + STAC946X_LF_VOLUME; 117 idx = id + STAC946X_LF_VOLUME;
118 if (id < 6) 118 if (id < 6)
119 old = stac9460_get(ice, idx); 119 old = stac9460_get(ice, idx);
120 else 120 else
121 old = stac9460_2_get(ice, idx - 6); 121 old = stac9460_2_get(ice, idx - 6);
122 new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | 122 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
123 (old & ~0x80); 123 (old & ~0x80);
124 change = (new != old); 124 change = (new != old);
125 if (change) { 125 if (change) {
126 if (id < 6) 126 if (id < 6)
127 stac9460_put(ice, idx, new); 127 stac9460_put(ice, idx, new);
128 else 128 else
129 stac9460_2_put(ice, idx - 6, new); 129 stac9460_2_put(ice, idx - 6, new);
130 } 130 }
131 } 131 }
132 return change; 132 return change;
@@ -136,7 +136,7 @@ static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
136 * DAC volume attenuation mixer control 136 * DAC volume attenuation mixer control
137 */ 137 */
138static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, 138static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
139 struct snd_ctl_elem_info *uinfo) 139 struct snd_ctl_elem_info *uinfo)
140{ 140{
141 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 141 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
142 uinfo->count = 1; 142 uinfo->count = 1;
@@ -146,7 +146,7 @@ static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
146} 146}
147 147
148static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, 148static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
149 struct snd_ctl_elem_value *ucontrol) 149 struct snd_ctl_elem_value *ucontrol)
150{ 150{
151 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 151 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
152 int idx, id; 152 int idx, id;
@@ -161,14 +161,14 @@ static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
161 } 161 }
162 if (id < 6) 162 if (id < 6)
163 vol = stac9460_get(ice, idx) & 0x7f; 163 vol = stac9460_get(ice, idx) & 0x7f;
164 else 164 else
165 vol = stac9460_2_get(ice, idx - 6) & 0x7f; 165 vol = stac9460_2_get(ice, idx - 6) & 0x7f;
166 ucontrol->value.integer.value[0] = 0x7f - vol; 166 ucontrol->value.integer.value[0] = 0x7f - vol;
167 return 0; 167 return 0;
168} 168}
169 169
170static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, 170static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
171 struct snd_ctl_elem_value *ucontrol) 171 struct snd_ctl_elem_value *ucontrol)
172{ 172{
173 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 173 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
174 int idx, id; 174 int idx, id;
@@ -182,8 +182,8 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
182 ovol = 0x7f - (tmp & 0x7f); 182 ovol = 0x7f - (tmp & 0x7f);
183 change = (ovol != nvol); 183 change = (ovol != nvol);
184 if (change) { 184 if (change) {
185 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); 185 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
186 stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); 186 stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
187 } 187 }
188 } else { 188 } else {
189 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 189 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
@@ -191,17 +191,17 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
191 nvol = ucontrol->value.integer.value[0] & 0x7f; 191 nvol = ucontrol->value.integer.value[0] & 0x7f;
192 if (id < 6) 192 if (id < 6)
193 tmp = stac9460_get(ice, idx); 193 tmp = stac9460_get(ice, idx);
194 else 194 else
195 tmp = stac9460_2_get(ice, idx - 6); 195 tmp = stac9460_2_get(ice, idx - 6);
196 ovol = 0x7f - (tmp & 0x7f); 196 ovol = 0x7f - (tmp & 0x7f);
197 change = (ovol != nvol); 197 change = (ovol != nvol);
198 if (change) { 198 if (change) {
199 if (id < 6) 199 if (id < 6)
200 stac9460_put(ice, idx, (0x7f - nvol) | 200 stac9460_put(ice, idx, (0x7f - nvol) |
201 (tmp & 0x80)); 201 (tmp & 0x80));
202 else 202 else
203 stac9460_2_put(ice, idx-6, (0x7f - nvol) | 203 stac9460_2_put(ice, idx-6, (0x7f - nvol) |
204 (tmp & 0x80)); 204 (tmp & 0x80));
205 } 205 }
206 } 206 }
207 return change; 207 return change;
@@ -213,12 +213,12 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
213#define stac9460_adc_mute_info snd_ctl_boolean_stereo_info 213#define stac9460_adc_mute_info snd_ctl_boolean_stereo_info
214 214
215static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, 215static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
216 struct snd_ctl_elem_value *ucontrol) 216 struct snd_ctl_elem_value *ucontrol)
217{ 217{
218 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 218 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
219 unsigned char val; 219 unsigned char val;
220 int i, id; 220 int i, id;
221 221
222 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 222 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
223 if (id == 0) { 223 if (id == 0) {
224 for (i = 0; i < 2; ++i) { 224 for (i = 0; i < 2; ++i) {
@@ -235,20 +235,20 @@ static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
235} 235}
236 236
237static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, 237static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
238 struct snd_ctl_elem_value *ucontrol) 238 struct snd_ctl_elem_value *ucontrol)
239{ 239{
240 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 240 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
241 unsigned char new, old; 241 unsigned char new, old;
242 int i, reg, id; 242 int i, reg, id;
243 int change; 243 int change;
244 244
245 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 245 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
246 if (id == 0) { 246 if (id == 0) {
247 for (i = 0; i < 2; ++i) { 247 for (i = 0; i < 2; ++i) {
248 reg = STAC946X_MIC_L_VOLUME + i; 248 reg = STAC946X_MIC_L_VOLUME + i;
249 old = stac9460_get(ice, reg); 249 old = stac9460_get(ice, reg);
250 new = (~ucontrol->value.integer.value[i]<<7&0x80) | 250 new = (~ucontrol->value.integer.value[i]<<7&0x80) |
251 (old&~0x80); 251 (old&~0x80);
252 change = (new != old); 252 change = (new != old);
253 if (change) 253 if (change)
254 stac9460_put(ice, reg, new); 254 stac9460_put(ice, reg, new);
@@ -258,7 +258,7 @@ static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
258 reg = STAC946X_MIC_L_VOLUME + i; 258 reg = STAC946X_MIC_L_VOLUME + i;
259 old = stac9460_2_get(ice, reg); 259 old = stac9460_2_get(ice, reg);
260 new = (~ucontrol->value.integer.value[i]<<7&0x80) | 260 new = (~ucontrol->value.integer.value[i]<<7&0x80) |
261 (old&~0x80); 261 (old&~0x80);
262 change = (new != old); 262 change = (new != old);
263 if (change) 263 if (change)
264 stac9460_2_put(ice, reg, new); 264 stac9460_2_put(ice, reg, new);
@@ -271,7 +271,7 @@ static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
271 *ADC gain mixer control 271 *ADC gain mixer control
272 */ 272 */
273static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, 273static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_info *uinfo) 274 struct snd_ctl_elem_info *uinfo)
275{ 275{
276 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 276 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
277 uinfo->count = 2; 277 uinfo->count = 2;
@@ -281,12 +281,12 @@ static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
281} 281}
282 282
283static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, 283static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
284 struct snd_ctl_elem_value *ucontrol) 284 struct snd_ctl_elem_value *ucontrol)
285{ 285{
286 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 286 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
287 int i, reg, id; 287 int i, reg, id;
288 unsigned char vol; 288 unsigned char vol;
289 289
290 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 290 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
291 if (id == 0) { 291 if (id == 0) {
292 for (i = 0; i < 2; ++i) { 292 for (i = 0; i < 2; ++i) {
@@ -305,13 +305,13 @@ static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
305} 305}
306 306
307static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, 307static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
308 struct snd_ctl_elem_value *ucontrol) 308 struct snd_ctl_elem_value *ucontrol)
309{ 309{
310 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 310 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
311 int i, reg, id; 311 int i, reg, id;
312 unsigned char ovol, nvol; 312 unsigned char ovol, nvol;
313 int change; 313 int change;
314 314
315 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 315 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
316 if (id == 0) { 316 if (id == 0) {
317 for (i = 0; i < 2; ++i) { 317 for (i = 0; i < 2; ++i) {
@@ -321,7 +321,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
321 change = ((ovol & 0x0f) != nvol); 321 change = ((ovol & 0x0f) != nvol);
322 if (change) 322 if (change)
323 stac9460_put(ice, reg, (0x0f - nvol) | 323 stac9460_put(ice, reg, (0x0f - nvol) |
324 (ovol & ~0x0f)); 324 (ovol & ~0x0f));
325 } 325 }
326 } else { 326 } else {
327 for (i = 0; i < 2; ++i) { 327 for (i = 0; i < 2; ++i) {
@@ -331,7 +331,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
331 change = ((ovol & 0x0f) != nvol); 331 change = ((ovol & 0x0f) != nvol);
332 if (change) 332 if (change)
333 stac9460_2_put(ice, reg, (0x0f - nvol) | 333 stac9460_2_put(ice, reg, (0x0f - nvol) |
334 (ovol & ~0x0f)); 334 (ovol & ~0x0f));
335 } 335 }
336 } 336 }
337 return change; 337 return change;
@@ -344,23 +344,23 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
344#define stac9460_mic_sw_info snd_ctl_boolean_mono_info 344#define stac9460_mic_sw_info snd_ctl_boolean_mono_info
345 345
346static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, 346static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_value *ucontrol) 347 struct snd_ctl_elem_value *ucontrol)
348{ 348{
349 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 349 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
350 unsigned char val; 350 unsigned char val;
351 int id; 351 int id;
352 352
353 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 353 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
354 if (id == 0) 354 if (id == 0)
355 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 355 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
356 else 356 else
357 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); 357 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
358 ucontrol->value.integer.value[0] = ~val>>7 & 0x1; 358 ucontrol->value.integer.value[0] = ~val>>7 & 0x1;
359 return 0; 359 return 0;
360} 360}
361 361
362static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, 362static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_value *ucontrol) 363 struct snd_ctl_elem_value *ucontrol)
364{ 364{
365 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 365 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
366 unsigned char new, old; 366 unsigned char new, old;
@@ -368,16 +368,16 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
368 368
369 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 369 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
370 if (id == 0) 370 if (id == 0)
371 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 371 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
372 else 372 else
373 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE); 373 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
374 new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | (old & ~0x80); 374 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) | (old & ~0x80);
375 change = (new != old); 375 change = (new != old);
376 if (change) { 376 if (change) {
377 if (id == 0) 377 if (id == 0)
378 stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new); 378 stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
379 else 379 else
380 stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new); 380 stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new);
381 } 381 }
382 return change; 382 return change;
383} 383}
@@ -443,7 +443,7 @@ static struct snd_kcontrol_new stac9640_controls[] __devinitdata = {
443 .get = stac9460_adc_vol_get, 443 .get = stac9460_adc_vol_get,
444 .put = stac9460_adc_vol_put, 444 .put = stac9460_adc_vol_put,
445 445
446 } 446 }
447}; 447};
448 448
449 449
@@ -470,7 +470,7 @@ static int __devinit wtm_init(struct snd_ice1712 *ice)
470 (unsigned short)-1 470 (unsigned short)-1
471 }; 471 };
472 unsigned short *p; 472 unsigned short *p;
473 473
474 /*WTM 192M*/ 474 /*WTM 192M*/
475 ice->num_total_dacs = 8; 475 ice->num_total_dacs = 8;
476 ice->num_total_adcs = 4; 476 ice->num_total_adcs = 4;
diff --git a/sound/pci/ice1712/wtm.h b/sound/pci/ice1712/wtm.h
index 03a394e442f1..423c1a204c0b 100644
--- a/sound/pci/ice1712/wtm.h
+++ b/sound/pci/ice1712/wtm.h
@@ -10,8 +10,8 @@
10 */ 10 */
11 11
12#define AK4114_ADDR 0x20 /*S/PDIF receiver*/ 12#define AK4114_ADDR 0x20 /*S/PDIF receiver*/
13#define STAC9460_I2C_ADDR 0x54 /* ADC*2 | DAC*6 */ 13#define STAC9460_I2C_ADDR 0x54 /* ADC*2 | DAC*6 */
14#define STAC9460_2_I2C_ADDR 0x56 /* ADC|DAC *2 */ 14#define STAC9460_2_I2C_ADDR 0x56 /* ADC|DAC *2 */
15 15
16 16
17extern struct snd_ice1712_card_info snd_vt1724_wtm_cards[]; 17extern struct snd_ice1712_card_info snd_vt1724_wtm_cards[];
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 048d99e25ab0..c88d1eace1c4 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -59,6 +59,12 @@ MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
59 "{SiS,SI7012}," 59 "{SiS,SI7012},"
60 "{NVidia,nForce Audio}," 60 "{NVidia,nForce Audio},"
61 "{NVidia,nForce2 Audio}," 61 "{NVidia,nForce2 Audio},"
62 "{NVidia,nForce3 Audio},"
63 "{NVidia,MCP04},"
64 "{NVidia,MCP501},"
65 "{NVidia,CK804},"
66 "{NVidia,CK8},"
67 "{NVidia,CK8S},"
62 "{AMD,AMD768}," 68 "{AMD,AMD768},"
63 "{AMD,AMD8111}," 69 "{AMD,AMD8111},"
64 "{ALI,M5455}}"); 70 "{ALI,M5455}}");
@@ -77,7 +83,7 @@ MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
77module_param(id, charp, 0444); 83module_param(id, charp, 0444);
78MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard."); 84MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
79module_param(ac97_clock, int, 0444); 85module_param(ac97_clock, int, 0444);
80MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect)."); 86MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = whitelist + auto-detect, 1 = force autodetect).");
81module_param(ac97_quirk, charp, 0444); 87module_param(ac97_quirk, charp, 0444);
82MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 88MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
83module_param(buggy_semaphore, bool, 0444); 89module_param(buggy_semaphore, bool, 0444);
@@ -1957,6 +1963,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1957 }, 1963 },
1958 { 1964 {
1959 .subvendor = 0x10cf, 1965 .subvendor = 0x10cf,
1966 .subdevice = 0x127d,
1967 .name = "Fujitsu Lifebook P7010",
1968 .type = AC97_TUNE_HP_ONLY
1969 },
1970 {
1971 .subvendor = 0x10cf,
1960 .subdevice = 0x127e, 1972 .subdevice = 0x127e,
1961 .name = "Fujitsu Lifebook C1211D", 1973 .name = "Fujitsu Lifebook C1211D",
1962 .type = AC97_TUNE_HP_ONLY 1974 .type = AC97_TUNE_HP_ONLY
@@ -2132,8 +2144,8 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
2132 snd_intel8x0_codec_read_test(chip, codecs); 2144 snd_intel8x0_codec_read_test(chip, codecs);
2133 chip->ac97_sdin[codecs] = 2145 chip->ac97_sdin[codecs] =
2134 igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK; 2146 igetbyte(chip, ICHREG(SDM)) & ICH_LDI_MASK;
2135 snd_assert(chip->ac97_sdin[codecs] < 3, 2147 if (snd_BUG_ON(chip->ac97_sdin[codecs] >= 3))
2136 chip->ac97_sdin[codecs] = 0); 2148 chip->ac97_sdin[codecs] = 0;
2137 } else 2149 } else
2138 chip->ac97_sdin[codecs] = i; 2150 chip->ac97_sdin[codecs] = i;
2139 codecs++; 2151 codecs++;
@@ -2686,6 +2698,28 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2686 snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0); 2698 snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
2687} 2699}
2688 2700
2701static struct snd_pci_quirk intel8x0_clock_list[] __devinitdata = {
2702 SND_PCI_QUIRK(0x0e11, 0x008a, "AD1885", 41000),
2703 SND_PCI_QUIRK(0x1028, 0x00be, "AD1885", 44100),
2704 SND_PCI_QUIRK(0x1028, 0x0177, "AD1980", 48000),
2705 SND_PCI_QUIRK(0x1043, 0x80f3, "AD1985", 48000),
2706 { } /* terminator */
2707};
2708
2709static int __devinit intel8x0_in_clock_list(struct intel8x0 *chip)
2710{
2711 struct pci_dev *pci = chip->pci;
2712 const struct snd_pci_quirk *wl;
2713
2714 wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
2715 if (!wl)
2716 return 0;
2717 printk(KERN_INFO "intel8x0: white list rate for %04x:%04x is %i\n",
2718 pci->subsystem_vendor, pci->subsystem_device, wl->value);
2719 chip->ac97_bus->clock = wl->value;
2720 return 1;
2721}
2722
2689#ifdef CONFIG_PROC_FS 2723#ifdef CONFIG_PROC_FS
2690static void snd_intel8x0_proc_read(struct snd_info_entry * entry, 2724static void snd_intel8x0_proc_read(struct snd_info_entry * entry,
2691 struct snd_info_buffer *buffer) 2725 struct snd_info_buffer *buffer)
@@ -3081,8 +3115,14 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
3081 "%s with %s at irq %i", card->shortname, 3115 "%s with %s at irq %i", card->shortname,
3082 snd_ac97_get_short_name(chip->ac97[0]), chip->irq); 3116 snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
3083 3117
3084 if (! ac97_clock) 3118 if (ac97_clock == 0 || ac97_clock == 1) {
3085 intel8x0_measure_ac97_clock(chip); 3119 if (ac97_clock == 0) {
3120 if (intel8x0_in_clock_list(chip) == 0)
3121 intel8x0_measure_ac97_clock(chip);
3122 } else {
3123 intel8x0_measure_ac97_clock(chip);
3124 }
3125 }
3086 3126
3087 if ((err = snd_card_register(card)) < 0) { 3127 if ((err = snd_card_register(card)) < 0) {
3088 snd_card_free(card); 3128 snd_card_free(card);
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index faf674e671ac..93449e464566 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -306,7 +306,8 @@ static unsigned int get_ich_codec_bit(struct intel8x0m *chip, unsigned int codec
306 static unsigned int codec_bit[3] = { 306 static unsigned int codec_bit[3] = {
307 ICH_PCR, ICH_SCR, ICH_TCR 307 ICH_PCR, ICH_SCR, ICH_TCR
308 }; 308 };
309 snd_assert(codec < 3, return ICH_PCR); 309 if (snd_BUG_ON(codec >= 3))
310 return ICH_PCR;
310 return codec_bit[codec]; 311 return codec_bit[codec];
311} 312}
312 313
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 4a44c0f20f76..5f8006b42750 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -1281,7 +1281,8 @@ static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int coun
1281 1281
1282 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", 1282 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n",
1283 pos, offset, size, count); 1283 pos, offset, size, count);
1284 snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); 1284 if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES))
1285 return -EINVAL;
1285 1286
1286 for (i=0; i < count; i++) { 1287 for (i=0; i < count; i++) {
1287#if K1212_DEBUG_LEVEL > 0 1288#if K1212_DEBUG_LEVEL > 0
@@ -1306,7 +1307,8 @@ static int snd_korg1212_copy_to(struct snd_korg1212 *korg1212, void __user *dst,
1306 1307
1307 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n", 1308 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n",
1308 pos, offset, size); 1309 pos, offset, size);
1309 snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); 1310 if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES))
1311 return -EINVAL;
1310 1312
1311 for (i=0; i < count; i++) { 1313 for (i=0; i < count; i++) {
1312#if K1212_DEBUG_LEVEL > 0 1314#if K1212_DEBUG_LEVEL > 0
@@ -1336,7 +1338,8 @@ static int snd_korg1212_copy_from(struct snd_korg1212 *korg1212, void __user *sr
1336 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n", 1338 K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n",
1337 pos, offset, size, count); 1339 pos, offset, size, count);
1338 1340
1339 snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL); 1341 if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES))
1342 return -EINVAL;
1340 1343
1341 for (i=0; i < count; i++) { 1344 for (i=0; i < count; i++) {
1342#if K1212_DEBUG_LEVEL > 0 1345#if K1212_DEBUG_LEVEL > 0
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 0037be74fdea..9ff3f9e34404 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -1175,7 +1175,8 @@ snd_m3_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
1175 struct m3_dma *s = subs->runtime->private_data; 1175 struct m3_dma *s = subs->runtime->private_data;
1176 int err = -EINVAL; 1176 int err = -EINVAL;
1177 1177
1178 snd_assert(s != NULL, return -ENXIO); 1178 if (snd_BUG_ON(!s))
1179 return -ENXIO;
1179 1180
1180 spin_lock(&chip->reg_lock); 1181 spin_lock(&chip->reg_lock);
1181 switch (cmd) { 1182 switch (cmd) {
@@ -1487,7 +1488,8 @@ snd_m3_pcm_prepare(struct snd_pcm_substream *subs)
1487 struct snd_pcm_runtime *runtime = subs->runtime; 1488 struct snd_pcm_runtime *runtime = subs->runtime;
1488 struct m3_dma *s = runtime->private_data; 1489 struct m3_dma *s = runtime->private_data;
1489 1490
1490 snd_assert(s != NULL, return -ENXIO); 1491 if (snd_BUG_ON(!s))
1492 return -ENXIO;
1491 1493
1492 if (runtime->format != SNDRV_PCM_FORMAT_U8 && 1494 if (runtime->format != SNDRV_PCM_FORMAT_U8 &&
1493 runtime->format != SNDRV_PCM_FORMAT_S16_LE) 1495 runtime->format != SNDRV_PCM_FORMAT_S16_LE)
@@ -1546,7 +1548,9 @@ snd_m3_pcm_pointer(struct snd_pcm_substream *subs)
1546 struct snd_m3 *chip = snd_pcm_substream_chip(subs); 1548 struct snd_m3 *chip = snd_pcm_substream_chip(subs);
1547 unsigned int ptr; 1549 unsigned int ptr;
1548 struct m3_dma *s = subs->runtime->private_data; 1550 struct m3_dma *s = subs->runtime->private_data;
1549 snd_assert(s != NULL, return 0); 1551
1552 if (snd_BUG_ON(!s))
1553 return 0;
1550 1554
1551 spin_lock(&chip->reg_lock); 1555 spin_lock(&chip->reg_lock);
1552 ptr = snd_m3_get_pointer(chip, s, subs); 1556 ptr = snd_m3_get_pointer(chip, s, subs);
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 3dd0c7963273..2d0dce649a64 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -708,7 +708,7 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
708 pcm_number = MIXART_PCM_ANALOG; 708 pcm_number = MIXART_PCM_ANALOG;
709 runtime->hw = snd_mixart_analog_caps; 709 runtime->hw = snd_mixart_analog_caps;
710 } else { 710 } else {
711 snd_assert ( pcm == chip->pcm_dig ); 711 snd_BUG_ON(pcm != chip->pcm_dig);
712 pcm_number = MIXART_PCM_DIGITAL; 712 pcm_number = MIXART_PCM_DIGITAL;
713 runtime->hw = snd_mixart_digital_caps; 713 runtime->hw = snd_mixart_digital_caps;
714 } 714 }
@@ -783,7 +783,7 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
783 pcm_number = MIXART_PCM_ANALOG; 783 pcm_number = MIXART_PCM_ANALOG;
784 runtime->hw = snd_mixart_analog_caps; 784 runtime->hw = snd_mixart_analog_caps;
785 } else { 785 } else {
786 snd_assert ( pcm == chip->pcm_dig ); 786 snd_BUG_ON(pcm != chip->pcm_dig);
787 pcm_number = MIXART_PCM_DIGITAL; 787 pcm_number = MIXART_PCM_DIGITAL;
788 runtime->hw = snd_mixart_digital_caps; 788 runtime->hw = snd_mixart_digital_caps;
789 } 789 }
diff --git a/sound/pci/mixart/mixart_core.c b/sound/pci/mixart/mixart_core.c
index 785085e48353..b9a06c279397 100644
--- a/sound/pci/mixart/mixart_core.c
+++ b/sound/pci/mixart/mixart_core.c
@@ -56,8 +56,10 @@ static int retrieve_msg_frame(struct mixart_mgr *mgr, u32 *msg_frame)
56 if (tailptr == headptr) 56 if (tailptr == headptr)
57 return 0; /* no message posted */ 57 return 0; /* no message posted */
58 58
59 snd_assert( tailptr >= MSG_OUTBOUND_POST_STACK, return 0); /* error */ 59 if (tailptr < MSG_OUTBOUND_POST_STACK)
60 snd_assert( tailptr < (MSG_OUTBOUND_POST_STACK+MSG_BOUND_STACK_SIZE), return 0); /* error */ 60 return 0; /* error */
61 if (tailptr >= MSG_OUTBOUND_POST_STACK + MSG_BOUND_STACK_SIZE)
62 return 0; /* error */
61 63
62 *msg_frame = readl_be(MIXART_MEM(mgr, tailptr)); 64 *msg_frame = readl_be(MIXART_MEM(mgr, tailptr));
63 65
@@ -149,7 +151,8 @@ static int send_msg( struct mixart_mgr *mgr,
149 u32 msg_frame_address; 151 u32 msg_frame_address;
150 int err, i; 152 int err, i;
151 153
152 snd_assert(msg->size % 4 == 0, return -EINVAL); 154 if (snd_BUG_ON(msg->size % 4))
155 return -EINVAL;
153 156
154 err = 0; 157 err = 0;
155 158
@@ -289,9 +292,12 @@ int snd_mixart_send_msg_wait_notif(struct mixart_mgr *mgr,
289 wait_queue_t wait; 292 wait_queue_t wait;
290 long timeout; 293 long timeout;
291 294
292 snd_assert(notif_event != 0, return -EINVAL); 295 if (snd_BUG_ON(!notif_event))
293 snd_assert((notif_event & MSG_TYPE_MASK) == MSG_TYPE_NOTIFY, return -EINVAL); 296 return -EINVAL;
294 snd_assert((notif_event & MSG_CANCEL_NOTIFY_MASK) == 0, return -EINVAL); 297 if (snd_BUG_ON((notif_event & MSG_TYPE_MASK) != MSG_TYPE_NOTIFY))
298 return -EINVAL;
299 if (snd_BUG_ON(notif_event & MSG_CANCEL_NOTIFY_MASK))
300 return -EINVAL;
295 301
296 mutex_lock(&mgr->msg_mutex); 302 mutex_lock(&mgr->msg_mutex);
297 303
diff --git a/sound/pci/mixart/mixart_hwdep.c b/sound/pci/mixart/mixart_hwdep.c
index f98603146132..3782b52bc0e8 100644
--- a/sound/pci/mixart/mixart_hwdep.c
+++ b/sound/pci/mixart/mixart_hwdep.c
@@ -288,7 +288,9 @@ static int mixart_enum_physio(struct mixart_mgr *mgr)
288 return -EINVAL; 288 return -EINVAL;
289 } 289 }
290 290
291 snd_assert(phys_io.nb_uid >= (MIXART_MAX_CARDS * 2), return -EINVAL); /* min 2 phys io per card (analog in + analog out) */ 291 /* min 2 phys io per card (analog in + analog out) */
292 if (phys_io.nb_uid < MIXART_MAX_CARDS * 2)
293 return -EINVAL;
292 294
293 for(k=0; k<mgr->num_cards; k++) { 295 for(k=0; k<mgr->num_cards; k++) {
294 mgr->chip[k]->uid_in_analog_physio = phys_io.uid[k]; 296 mgr->chip[k]->uid_in_analog_physio = phys_io.uid[k];
@@ -363,8 +365,10 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
363 } 365 }
364 366
365 /* check xilinx validity */ 367 /* check xilinx validity */
366 snd_assert(((u32*)(dsp->data))[0]==0xFFFFFFFF, return -EINVAL); 368 if (((u32*)(dsp->data))[0] == 0xffffffff)
367 snd_assert(dsp->size % 4 == 0, return -EINVAL); 369 return -EINVAL;
370 if (dsp->size % 4)
371 return -EINVAL;
368 372
369 /* set xilinx status to copying */ 373 /* set xilinx status to copying */
370 writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET )); 374 writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET ));
@@ -462,8 +466,10 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
462 } 466 }
463 467
464 /* check daughterboard xilinx validity */ 468 /* check daughterboard xilinx validity */
465 snd_assert(((u32*)(dsp->data))[0]==0xFFFFFFFF, return -EINVAL); 469 if (((u32*)(dsp->data))[0] == 0xffffffff)
466 snd_assert(dsp->size % 4 == 0, return -EINVAL); 470 return -EINVAL;
471 if (dsp->size % 4)
472 return -EINVAL;
467 473
468 /* inform mixart about the size of the file */ 474 /* inform mixart about the size of the file */
469 writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET )); 475 writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET ));
@@ -480,7 +486,8 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
480 486
481 /* get the address where to write the file */ 487 /* get the address where to write the file */
482 val = readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_BASE_ADDR_OFFSET )); 488 val = readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_BASE_ADDR_OFFSET ));
483 snd_assert(val != 0, return -EINVAL); 489 if (!val)
490 return -EINVAL;
484 491
485 /* copy daughterboard xilinx code */ 492 /* copy daughterboard xilinx code */
486 memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size); 493 memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size);
diff --git a/sound/pci/mixart/mixart_mixer.c b/sound/pci/mixart/mixart_mixer.c
index 6fdda1f70b25..3ba6174c3df1 100644
--- a/sound/pci/mixart/mixart_mixer.c
+++ b/sound/pci/mixart/mixart_mixer.c
@@ -837,7 +837,7 @@ static int mixart_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
837 if(is_aes) stored_volume = chip->digital_capture_volume[1]; /* AES capture */ 837 if(is_aes) stored_volume = chip->digital_capture_volume[1]; /* AES capture */
838 else stored_volume = chip->digital_capture_volume[0]; /* analog capture */ 838 else stored_volume = chip->digital_capture_volume[0]; /* analog capture */
839 } else { 839 } else {
840 snd_assert ( idx < MIXART_PLAYBACK_STREAMS ); 840 snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS);
841 if(is_aes) stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; /* AES playback */ 841 if(is_aes) stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; /* AES playback */
842 else stored_volume = chip->digital_playback_volume[idx]; /* analog playback */ 842 else stored_volume = chip->digital_playback_volume[idx]; /* analog playback */
843 } 843 }
@@ -863,7 +863,7 @@ static int mixart_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
863 else /* analog capture */ 863 else /* analog capture */
864 stored_volume = chip->digital_capture_volume[0]; 864 stored_volume = chip->digital_capture_volume[0];
865 } else { 865 } else {
866 snd_assert ( idx < MIXART_PLAYBACK_STREAMS ); 866 snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS);
867 if (is_aes) /* AES playback */ 867 if (is_aes) /* AES playback */
868 stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; 868 stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx];
869 else /* analog playback */ 869 else /* analog playback */
@@ -909,7 +909,7 @@ static int mixart_pcm_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
909{ 909{
910 struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); 910 struct snd_mixart *chip = snd_kcontrol_chip(kcontrol);
911 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ 911 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
912 snd_assert ( idx < MIXART_PLAYBACK_STREAMS ); 912 snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS);
913 mutex_lock(&chip->mgr->mixer_mutex); 913 mutex_lock(&chip->mgr->mixer_mutex);
914 if(kcontrol->private_value & MIXART_VOL_AES_MASK) /* AES playback */ 914 if(kcontrol->private_value & MIXART_VOL_AES_MASK) /* AES playback */
915 idx += MIXART_PLAYBACK_STREAMS; 915 idx += MIXART_PLAYBACK_STREAMS;
@@ -926,7 +926,7 @@ static int mixart_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
926 int is_aes = kcontrol->private_value & MIXART_VOL_AES_MASK; 926 int is_aes = kcontrol->private_value & MIXART_VOL_AES_MASK;
927 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ 927 int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */
928 int i, j; 928 int i, j;
929 snd_assert ( idx < MIXART_PLAYBACK_STREAMS ); 929 snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS);
930 mutex_lock(&chip->mgr->mixer_mutex); 930 mutex_lock(&chip->mgr->mixer_mutex);
931 j = idx; 931 j = idx;
932 if (is_aes) 932 if (is_aes)
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 06d13e717114..50c9f8a05082 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -562,7 +562,8 @@ snd_nm256_playback_trigger(struct snd_pcm_substream *substream, int cmd)
562 struct nm256_stream *s = substream->runtime->private_data; 562 struct nm256_stream *s = substream->runtime->private_data;
563 int err = 0; 563 int err = 0;
564 564
565 snd_assert(s != NULL, return -ENXIO); 565 if (snd_BUG_ON(!s))
566 return -ENXIO;
566 567
567 spin_lock(&chip->reg_lock); 568 spin_lock(&chip->reg_lock);
568 switch (cmd) { 569 switch (cmd) {
@@ -599,7 +600,8 @@ snd_nm256_capture_trigger(struct snd_pcm_substream *substream, int cmd)
599 struct nm256_stream *s = substream->runtime->private_data; 600 struct nm256_stream *s = substream->runtime->private_data;
600 int err = 0; 601 int err = 0;
601 602
602 snd_assert(s != NULL, return -ENXIO); 603 if (snd_BUG_ON(!s))
604 return -ENXIO;
603 605
604 spin_lock(&chip->reg_lock); 606 spin_lock(&chip->reg_lock);
605 switch (cmd) { 607 switch (cmd) {
@@ -635,7 +637,8 @@ static int snd_nm256_pcm_prepare(struct snd_pcm_substream *substream)
635 struct snd_pcm_runtime *runtime = substream->runtime; 637 struct snd_pcm_runtime *runtime = substream->runtime;
636 struct nm256_stream *s = runtime->private_data; 638 struct nm256_stream *s = runtime->private_data;
637 639
638 snd_assert(s, return -ENXIO); 640 if (snd_BUG_ON(!s))
641 return -ENXIO;
639 s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size); 642 s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size);
640 s->period_size = frames_to_bytes(runtime, substream->runtime->period_size); 643 s->period_size = frames_to_bytes(runtime, substream->runtime->period_size);
641 s->periods = substream->runtime->periods; 644 s->periods = substream->runtime->periods;
@@ -660,7 +663,8 @@ snd_nm256_playback_pointer(struct snd_pcm_substream *substream)
660 struct nm256_stream *s = substream->runtime->private_data; 663 struct nm256_stream *s = substream->runtime->private_data;
661 unsigned long curp; 664 unsigned long curp;
662 665
663 snd_assert(s, return 0); 666 if (snd_BUG_ON(!s))
667 return 0;
664 curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf; 668 curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf;
665 curp %= s->dma_size; 669 curp %= s->dma_size;
666 return bytes_to_frames(substream->runtime, curp); 670 return bytes_to_frames(substream->runtime, curp);
@@ -673,7 +677,8 @@ snd_nm256_capture_pointer(struct snd_pcm_substream *substream)
673 struct nm256_stream *s = substream->runtime->private_data; 677 struct nm256_stream *s = substream->runtime->private_data;
674 unsigned long curp; 678 unsigned long curp;
675 679
676 snd_assert(s != NULL, return 0); 680 if (snd_BUG_ON(!s))
681 return 0;
677 curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf; 682 curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf;
678 curp %= s->dma_size; 683 curp %= s->dma_size;
679 return bytes_to_frames(substream->runtime, curp); 684 return bytes_to_frames(substream->runtime, curp);
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index dad393ae040a..1ab833f843eb 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -94,6 +94,11 @@ static void hifier_cleanup(struct oxygen *chip)
94{ 94{
95} 95}
96 96
97static void hifier_resume(struct oxygen *chip)
98{
99 hifier_registers_init(chip);
100}
101
97static void set_ak4396_params(struct oxygen *chip, 102static void set_ak4396_params(struct oxygen *chip,
98 struct snd_pcm_hw_params *params) 103 struct snd_pcm_hw_params *params)
99{ 104{
@@ -150,16 +155,16 @@ static const struct oxygen_model model_hifier = {
150 .init = hifier_init, 155 .init = hifier_init,
151 .control_filter = hifier_control_filter, 156 .control_filter = hifier_control_filter,
152 .cleanup = hifier_cleanup, 157 .cleanup = hifier_cleanup,
153 .resume = hifier_registers_init, 158 .resume = hifier_resume,
154 .set_dac_params = set_ak4396_params, 159 .set_dac_params = set_ak4396_params,
155 .set_adc_params = set_cs5340_params, 160 .set_adc_params = set_cs5340_params,
156 .update_dac_volume = update_ak4396_volume, 161 .update_dac_volume = update_ak4396_volume,
157 .update_dac_mute = update_ak4396_mute, 162 .update_dac_mute = update_ak4396_mute,
158 .dac_tlv = ak4396_db_scale, 163 .dac_tlv = ak4396_db_scale,
159 .model_data_size = sizeof(struct hifier_data), 164 .model_data_size = sizeof(struct hifier_data),
160 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 165 .device_config = PLAYBACK_0_TO_I2S |
161 PLAYBACK_1_TO_SPDIF | 166 PLAYBACK_1_TO_SPDIF |
162 CAPTURE_0_FROM_I2S_1, 167 CAPTURE_0_FROM_I2S_1,
163 .dac_channels = 2, 168 .dac_channels = 2,
164 .dac_volume_min = 0, 169 .dac_volume_min = 0,
165 .dac_volume_max = 255, 170 .dac_volume_max = 255,
@@ -180,7 +185,7 @@ static int __devinit hifier_probe(struct pci_dev *pci,
180 ++dev; 185 ++dev;
181 return -ENOENT; 186 return -ENOENT;
182 } 187 }
183 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier); 188 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier, 0);
184 if (err >= 0) 189 if (err >= 0)
185 ++dev; 190 ++dev;
186 return err; 191 return err;
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index c5829d30ef86..b60f6212745a 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -58,17 +58,22 @@ MODULE_PARM_DESC(id, "ID string");
58module_param_array(enable, bool, NULL, 0444); 58module_param_array(enable, bool, NULL, 0444);
59MODULE_PARM_DESC(enable, "enable card"); 59MODULE_PARM_DESC(enable, "enable card");
60 60
61enum {
62 MODEL_CMEDIA_REF, /* C-Media's reference design */
63 MODEL_MERIDIAN, /* AuzenTech X-Meridian */
64};
65
61static struct pci_device_id oxygen_ids[] __devinitdata = { 66static struct pci_device_id oxygen_ids[] __devinitdata = {
62 { OXYGEN_PCI_SUBID(0x10b0, 0x0216) }, 67 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF },
63 { OXYGEN_PCI_SUBID(0x10b0, 0x0218) }, 68 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF },
64 { OXYGEN_PCI_SUBID(0x10b0, 0x0219) }, 69 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF },
65 { OXYGEN_PCI_SUBID(0x13f6, 0x0001) }, 70 { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF },
66 { OXYGEN_PCI_SUBID(0x13f6, 0x0010) }, 71 { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF },
67 { OXYGEN_PCI_SUBID(0x13f6, 0x8788) }, 72 { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF },
68 { OXYGEN_PCI_SUBID(0x147a, 0xa017) }, 73 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
69 { OXYGEN_PCI_SUBID(0x1a58, 0x0910) }, 74 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
70 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = 1 }, 75 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
71 { OXYGEN_PCI_SUBID(0x7284, 0x9761) }, 76 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CMEDIA_REF },
72 { } 77 { }
73}; 78};
74MODULE_DEVICE_TABLE(pci, oxygen_ids); 79MODULE_DEVICE_TABLE(pci, oxygen_ids);
@@ -199,6 +204,11 @@ static void generic_resume(struct oxygen *chip)
199 wm8785_registers_init(chip); 204 wm8785_registers_init(chip);
200} 205}
201 206
207static void meridian_resume(struct oxygen *chip)
208{
209 ak4396_registers_init(chip);
210}
211
202static void set_ak4396_params(struct oxygen *chip, 212static void set_ak4396_params(struct oxygen *chip,
203 struct snd_pcm_hw_params *params) 213 struct snd_pcm_hw_params *params)
204{ 214{
@@ -281,11 +291,28 @@ static void set_ak5385_params(struct oxygen *chip,
281 291
282static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 292static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
283 293
294static int generic_probe(struct oxygen *chip, unsigned long driver_data)
295{
296 if (driver_data == MODEL_MERIDIAN) {
297 chip->model.init = meridian_init;
298 chip->model.resume = meridian_resume;
299 chip->model.set_adc_params = set_ak5385_params;
300 chip->model.device_config = PLAYBACK_0_TO_I2S |
301 PLAYBACK_1_TO_SPDIF |
302 CAPTURE_0_FROM_I2S_2 |
303 CAPTURE_1_FROM_SPDIF;
304 chip->model.misc_flags = OXYGEN_MISC_MIDI;
305 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
306 }
307 return 0;
308}
309
284static const struct oxygen_model model_generic = { 310static const struct oxygen_model model_generic = {
285 .shortname = "C-Media CMI8788", 311 .shortname = "C-Media CMI8788",
286 .longname = "C-Media Oxygen HD Audio", 312 .longname = "C-Media Oxygen HD Audio",
287 .chip = "CMI8788", 313 .chip = "CMI8788",
288 .owner = THIS_MODULE, 314 .owner = THIS_MODULE,
315 .probe = generic_probe,
289 .init = generic_init, 316 .init = generic_init,
290 .cleanup = generic_cleanup, 317 .cleanup = generic_cleanup,
291 .resume = generic_resume, 318 .resume = generic_resume,
@@ -295,44 +322,15 @@ static const struct oxygen_model model_generic = {
295 .update_dac_mute = update_ak4396_mute, 322 .update_dac_mute = update_ak4396_mute,
296 .dac_tlv = ak4396_db_scale, 323 .dac_tlv = ak4396_db_scale,
297 .model_data_size = sizeof(struct generic_data), 324 .model_data_size = sizeof(struct generic_data),
298 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 325 .device_config = PLAYBACK_0_TO_I2S |
299 PLAYBACK_1_TO_SPDIF | 326 PLAYBACK_1_TO_SPDIF |
300 PLAYBACK_2_TO_AC97_1 | 327 PLAYBACK_2_TO_AC97_1 |
301 CAPTURE_0_FROM_I2S_1 | 328 CAPTURE_0_FROM_I2S_1 |
302 CAPTURE_1_FROM_SPDIF | 329 CAPTURE_1_FROM_SPDIF |
303 CAPTURE_2_FROM_AC97_1, 330 CAPTURE_2_FROM_AC97_1,
304 .dac_channels = 8,
305 .dac_volume_min = 0,
306 .dac_volume_max = 255,
307 .function_flags = OXYGEN_FUNCTION_SPI |
308 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
309 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
310 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
311};
312static const struct oxygen_model model_meridian = {
313 .shortname = "C-Media CMI8788",
314 .longname = "C-Media Oxygen HD Audio",
315 .chip = "CMI8788",
316 .owner = THIS_MODULE,
317 .init = meridian_init,
318 .cleanup = generic_cleanup,
319 .resume = ak4396_registers_init,
320 .set_dac_params = set_ak4396_params,
321 .set_adc_params = set_ak5385_params,
322 .update_dac_volume = update_ak4396_volume,
323 .update_dac_mute = update_ak4396_mute,
324 .dac_tlv = ak4396_db_scale,
325 .model_data_size = sizeof(struct generic_data),
326 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
327 PLAYBACK_1_TO_SPDIF |
328 PLAYBACK_2_TO_AC97_1 |
329 CAPTURE_0_FROM_I2S_2 |
330 CAPTURE_1_FROM_SPDIF |
331 CAPTURE_2_FROM_AC97_1,
332 .dac_channels = 8, 331 .dac_channels = 8,
333 .dac_volume_min = 0, 332 .dac_volume_min = 0,
334 .dac_volume_max = 255, 333 .dac_volume_max = 255,
335 .misc_flags = OXYGEN_MISC_MIDI,
336 .function_flags = OXYGEN_FUNCTION_SPI | 334 .function_flags = OXYGEN_FUNCTION_SPI |
337 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 335 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
338 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 336 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
@@ -343,7 +341,6 @@ static int __devinit generic_oxygen_probe(struct pci_dev *pci,
343 const struct pci_device_id *pci_id) 341 const struct pci_device_id *pci_id)
344{ 342{
345 static int dev; 343 static int dev;
346 int is_meridian;
347 int err; 344 int err;
348 345
349 if (dev >= SNDRV_CARDS) 346 if (dev >= SNDRV_CARDS)
@@ -352,9 +349,8 @@ static int __devinit generic_oxygen_probe(struct pci_dev *pci,
352 ++dev; 349 ++dev;
353 return -ENOENT; 350 return -ENOENT;
354 } 351 }
355 is_meridian = pci_id->driver_data;
356 err = oxygen_pci_probe(pci, index[dev], id[dev], 352 err = oxygen_pci_probe(pci, index[dev], id[dev],
357 is_meridian ? &model_meridian : &model_generic); 353 &model_generic, pci_id->driver_data);
358 if (err >= 0) 354 if (err >= 0)
359 ++dev; 355 ++dev;
360 return err; 356 return err;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index 74a644880074..19107c6307e5 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -19,14 +19,19 @@
19#define OXYGEN_IO_SIZE 0x100 19#define OXYGEN_IO_SIZE 0x100
20 20
21/* model-specific configuration of outputs/inputs */ 21/* model-specific configuration of outputs/inputs */
22#define PLAYBACK_0_TO_I2S 0x001 22#define PLAYBACK_0_TO_I2S 0x0001
23#define PLAYBACK_1_TO_SPDIF 0x004 23 /* PLAYBACK_0_TO_AC97_0 not implemented */
24#define PLAYBACK_2_TO_AC97_1 0x008 24#define PLAYBACK_1_TO_SPDIF 0x0004
25#define CAPTURE_0_FROM_I2S_1 0x010 25#define PLAYBACK_2_TO_AC97_1 0x0008
26#define CAPTURE_0_FROM_I2S_2 0x020 26#define CAPTURE_0_FROM_I2S_1 0x0010
27#define CAPTURE_1_FROM_SPDIF 0x080 27#define CAPTURE_0_FROM_I2S_2 0x0020
28#define CAPTURE_2_FROM_I2S_2 0x100 28 /* CAPTURE_0_FROM_AC97_0 not implemented */
29#define CAPTURE_2_FROM_AC97_1 0x200 29#define CAPTURE_1_FROM_SPDIF 0x0080
30#define CAPTURE_2_FROM_I2S_2 0x0100
31#define CAPTURE_2_FROM_AC97_1 0x0200
32 /* CAPTURE_3_FROM_I2S_3 not implemented */
33#define MIDI_OUTPUT 0x0800
34#define MIDI_INPUT 0x1000
30 35
31enum { 36enum {
32 CONTROL_SPDIF_PCM, 37 CONTROL_SPDIF_PCM,
@@ -51,7 +56,43 @@ struct snd_pcm_hardware;
51struct snd_pcm_hw_params; 56struct snd_pcm_hw_params;
52struct snd_kcontrol_new; 57struct snd_kcontrol_new;
53struct snd_rawmidi; 58struct snd_rawmidi;
54struct oxygen_model; 59struct oxygen;
60
61struct oxygen_model {
62 const char *shortname;
63 const char *longname;
64 const char *chip;
65 struct module *owner;
66 int (*probe)(struct oxygen *chip, unsigned long driver_data);
67 void (*init)(struct oxygen *chip);
68 int (*control_filter)(struct snd_kcontrol_new *template);
69 int (*mixer_init)(struct oxygen *chip);
70 void (*cleanup)(struct oxygen *chip);
71 void (*suspend)(struct oxygen *chip);
72 void (*resume)(struct oxygen *chip);
73 void (*pcm_hardware_filter)(unsigned int channel,
74 struct snd_pcm_hardware *hardware);
75 void (*set_dac_params)(struct oxygen *chip,
76 struct snd_pcm_hw_params *params);
77 void (*set_adc_params)(struct oxygen *chip,
78 struct snd_pcm_hw_params *params);
79 void (*update_dac_volume)(struct oxygen *chip);
80 void (*update_dac_mute)(struct oxygen *chip);
81 void (*gpio_changed)(struct oxygen *chip);
82 void (*uart_input)(struct oxygen *chip);
83 void (*ac97_switch)(struct oxygen *chip,
84 unsigned int reg, unsigned int mute);
85 const unsigned int *dac_tlv;
86 size_t model_data_size;
87 unsigned int device_config;
88 u8 dac_channels;
89 u8 dac_volume_min;
90 u8 dac_volume_max;
91 u8 misc_flags;
92 u8 function_flags;
93 u16 dac_i2s_format;
94 u16 adc_i2s_format;
95};
55 96
56struct oxygen { 97struct oxygen {
57 unsigned long addr; 98 unsigned long addr;
@@ -61,7 +102,6 @@ struct oxygen {
61 struct pci_dev *pci; 102 struct pci_dev *pci;
62 struct snd_rawmidi *midi; 103 struct snd_rawmidi *midi;
63 int irq; 104 int irq;
64 const struct oxygen_model *model;
65 void *model_data; 105 void *model_data;
66 unsigned int interrupt_mask; 106 unsigned int interrupt_mask;
67 u8 dac_volume[8]; 107 u8 dac_volume[8];
@@ -86,46 +126,16 @@ struct oxygen {
86 __le32 _32[OXYGEN_IO_SIZE / 4]; 126 __le32 _32[OXYGEN_IO_SIZE / 4];
87 } saved_registers; 127 } saved_registers;
88 u16 saved_ac97_registers[2][0x40]; 128 u16 saved_ac97_registers[2][0x40];
89}; 129 unsigned int uart_input_count;
90 130 u8 uart_input[32];
91struct oxygen_model { 131 struct oxygen_model model;
92 const char *shortname;
93 const char *longname;
94 const char *chip;
95 struct module *owner;
96 void (*init)(struct oxygen *chip);
97 int (*control_filter)(struct snd_kcontrol_new *template);
98 int (*mixer_init)(struct oxygen *chip);
99 void (*cleanup)(struct oxygen *chip);
100 void (*suspend)(struct oxygen *chip);
101 void (*resume)(struct oxygen *chip);
102 void (*pcm_hardware_filter)(unsigned int channel,
103 struct snd_pcm_hardware *hardware);
104 void (*set_dac_params)(struct oxygen *chip,
105 struct snd_pcm_hw_params *params);
106 void (*set_adc_params)(struct oxygen *chip,
107 struct snd_pcm_hw_params *params);
108 void (*update_dac_volume)(struct oxygen *chip);
109 void (*update_dac_mute)(struct oxygen *chip);
110 void (*gpio_changed)(struct oxygen *chip);
111 void (*ac97_switch)(struct oxygen *chip,
112 unsigned int reg, unsigned int mute);
113 const unsigned int *dac_tlv;
114 size_t model_data_size;
115 unsigned int pcm_dev_cfg;
116 u8 dac_channels;
117 u8 dac_volume_min;
118 u8 dac_volume_max;
119 u8 misc_flags;
120 u8 function_flags;
121 u16 dac_i2s_format;
122 u16 adc_i2s_format;
123}; 132};
124 133
125/* oxygen_lib.c */ 134/* oxygen_lib.c */
126 135
127int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 136int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
128 const struct oxygen_model *model); 137 const struct oxygen_model *model,
138 unsigned long driver_data);
129void oxygen_pci_remove(struct pci_dev *pci); 139void oxygen_pci_remove(struct pci_dev *pci);
130#ifdef CONFIG_PM 140#ifdef CONFIG_PM
131int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state); 141int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state);
@@ -167,6 +177,9 @@ void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
167void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data); 177void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data);
168void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data); 178void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
169 179
180void oxygen_reset_uart(struct oxygen *chip);
181void oxygen_write_uart(struct oxygen *chip, u8 data);
182
170static inline void oxygen_set_bits8(struct oxygen *chip, 183static inline void oxygen_set_bits8(struct oxygen *chip,
171 unsigned int reg, u8 value) 184 unsigned int reg, u8 value)
172{ 185{
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 83f135f80df4..3126c4b403dd 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -20,6 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <sound/core.h> 22#include <sound/core.h>
23#include <sound/mpu401.h>
23#include <asm/io.h> 24#include <asm/io.h>
24#include "oxygen.h" 25#include "oxygen.h"
25 26
@@ -232,3 +233,24 @@ void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data)
232 device | OXYGEN_2WIRE_DIR_WRITE); 233 device | OXYGEN_2WIRE_DIR_WRITE);
233} 234}
234EXPORT_SYMBOL(oxygen_write_i2c); 235EXPORT_SYMBOL(oxygen_write_i2c);
236
237static void _write_uart(struct oxygen *chip, unsigned int port, u8 data)
238{
239 if (oxygen_read8(chip, OXYGEN_MPU401 + 1) & MPU401_TX_FULL)
240 msleep(1);
241 oxygen_write8(chip, OXYGEN_MPU401 + port, data);
242}
243
244void oxygen_reset_uart(struct oxygen *chip)
245{
246 _write_uart(chip, 1, MPU401_RESET);
247 msleep(1); /* wait for ACK */
248 _write_uart(chip, 1, MPU401_ENTER_UART);
249}
250EXPORT_SYMBOL(oxygen_reset_uart);
251
252void oxygen_write_uart(struct oxygen *chip, u8 data)
253{
254 _write_uart(chip, 0, data);
255}
256EXPORT_SYMBOL(oxygen_write_uart);
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 22f37851045e..84f481d41efa 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -35,6 +35,30 @@ MODULE_DESCRIPTION("C-Media CMI8788 helper library");
35MODULE_LICENSE("GPL v2"); 35MODULE_LICENSE("GPL v2");
36 36
37 37
38static inline int oxygen_uart_input_ready(struct oxygen *chip)
39{
40 return !(oxygen_read8(chip, OXYGEN_MPU401 + 1) & MPU401_RX_EMPTY);
41}
42
43static void oxygen_read_uart(struct oxygen *chip)
44{
45 if (unlikely(!oxygen_uart_input_ready(chip))) {
46 /* no data, but read it anyway to clear the interrupt */
47 oxygen_read8(chip, OXYGEN_MPU401);
48 return;
49 }
50 do {
51 u8 data = oxygen_read8(chip, OXYGEN_MPU401);
52 if (data == MPU401_ACK)
53 continue;
54 if (chip->uart_input_count >= ARRAY_SIZE(chip->uart_input))
55 chip->uart_input_count = 0;
56 chip->uart_input[chip->uart_input_count++] = data;
57 } while (oxygen_uart_input_ready(chip));
58 if (chip->model.uart_input)
59 chip->model.uart_input(chip);
60}
61
38static irqreturn_t oxygen_interrupt(int dummy, void *dev_id) 62static irqreturn_t oxygen_interrupt(int dummy, void *dev_id)
39{ 63{
40 struct oxygen *chip = dev_id; 64 struct oxygen *chip = dev_id;
@@ -87,8 +111,12 @@ static irqreturn_t oxygen_interrupt(int dummy, void *dev_id)
87 if (status & OXYGEN_INT_GPIO) 111 if (status & OXYGEN_INT_GPIO)
88 schedule_work(&chip->gpio_work); 112 schedule_work(&chip->gpio_work);
89 113
90 if ((status & OXYGEN_INT_MIDI) && chip->midi) 114 if (status & OXYGEN_INT_MIDI) {
91 snd_mpu401_uart_interrupt(0, chip->midi->private_data); 115 if (chip->midi)
116 snd_mpu401_uart_interrupt(0, chip->midi->private_data);
117 else
118 oxygen_read_uart(chip);
119 }
92 120
93 if (status & OXYGEN_INT_AC97) 121 if (status & OXYGEN_INT_AC97)
94 wake_up(&chip->ac97_waitqueue); 122 wake_up(&chip->ac97_waitqueue);
@@ -161,8 +189,8 @@ static void oxygen_gpio_changed(struct work_struct *work)
161{ 189{
162 struct oxygen *chip = container_of(work, struct oxygen, gpio_work); 190 struct oxygen *chip = container_of(work, struct oxygen, gpio_work);
163 191
164 if (chip->model->gpio_changed) 192 if (chip->model.gpio_changed)
165 chip->model->gpio_changed(chip); 193 chip->model.gpio_changed(chip);
166} 194}
167 195
168#ifdef CONFIG_PROC_FS 196#ifdef CONFIG_PROC_FS
@@ -221,7 +249,7 @@ static void oxygen_init(struct oxygen *chip)
221 249
222 chip->dac_routing = 1; 250 chip->dac_routing = 1;
223 for (i = 0; i < 8; ++i) 251 for (i = 0; i < 8; ++i)
224 chip->dac_volume[i] = chip->model->dac_volume_min; 252 chip->dac_volume[i] = chip->model.dac_volume_min;
225 chip->dac_mute = 1; 253 chip->dac_mute = 1;
226 chip->spdif_playback_enable = 1; 254 chip->spdif_playback_enable = 1;
227 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL | 255 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL |
@@ -243,7 +271,7 @@ static void oxygen_init(struct oxygen *chip)
243 271
244 oxygen_write8_masked(chip, OXYGEN_FUNCTION, 272 oxygen_write8_masked(chip, OXYGEN_FUNCTION,
245 OXYGEN_FUNCTION_RESET_CODEC | 273 OXYGEN_FUNCTION_RESET_CODEC |
246 chip->model->function_flags, 274 chip->model.function_flags,
247 OXYGEN_FUNCTION_RESET_CODEC | 275 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK | 276 OXYGEN_FUNCTION_2WIRE_SPI_MASK |
249 OXYGEN_FUNCTION_ENABLE_SPI_4_5); 277 OXYGEN_FUNCTION_ENABLE_SPI_4_5);
@@ -255,7 +283,7 @@ static void oxygen_init(struct oxygen *chip)
255 OXYGEN_DMA_MULTICH_BURST_8); 283 OXYGEN_DMA_MULTICH_BURST_8);
256 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 284 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
257 oxygen_write8_masked(chip, OXYGEN_MISC, 285 oxygen_write8_masked(chip, OXYGEN_MISC,
258 chip->model->misc_flags, 286 chip->model.misc_flags,
259 OXYGEN_MISC_WRITE_PCI_SUBID | 287 OXYGEN_MISC_WRITE_PCI_SUBID |
260 OXYGEN_MISC_REC_C_FROM_SPDIF | 288 OXYGEN_MISC_REC_C_FROM_SPDIF |
261 OXYGEN_MISC_REC_B_FROM_AC97 | 289 OXYGEN_MISC_REC_B_FROM_AC97 |
@@ -270,21 +298,21 @@ static void oxygen_init(struct oxygen *chip)
270 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT)); 298 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT));
271 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2); 299 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2);
272 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT, 300 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT,
273 OXYGEN_RATE_48000 | chip->model->dac_i2s_format | 301 OXYGEN_RATE_48000 | chip->model.dac_i2s_format |
274 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 | 302 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
275 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 303 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
276 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1) 304 if (chip->model.device_config & CAPTURE_0_FROM_I2S_1)
277 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, 305 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
278 OXYGEN_RATE_48000 | chip->model->adc_i2s_format | 306 OXYGEN_RATE_48000 | chip->model.adc_i2s_format |
279 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 | 307 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 308 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
281 else 309 else
282 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, 310 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
283 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK); 311 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
284 if (chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_2 | 312 if (chip->model.device_config & (CAPTURE_0_FROM_I2S_2 |
285 CAPTURE_2_FROM_I2S_2)) 313 CAPTURE_2_FROM_I2S_2))
286 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT, 314 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
287 OXYGEN_RATE_48000 | chip->model->adc_i2s_format | 315 OXYGEN_RATE_48000 | chip->model.adc_i2s_format |
288 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 | 316 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
289 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 317 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
290 else 318 else
@@ -295,7 +323,7 @@ static void oxygen_init(struct oxygen *chip)
295 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, 323 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
296 OXYGEN_SPDIF_OUT_ENABLE | 324 OXYGEN_SPDIF_OUT_ENABLE |
297 OXYGEN_SPDIF_LOOPBACK); 325 OXYGEN_SPDIF_LOOPBACK);
298 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF) 326 if (chip->model.device_config & CAPTURE_1_FROM_SPDIF)
299 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL, 327 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL,
300 OXYGEN_SPDIF_SENSE_MASK | 328 OXYGEN_SPDIF_SENSE_MASK |
301 OXYGEN_SPDIF_LOCK_MASK | 329 OXYGEN_SPDIF_LOCK_MASK |
@@ -417,14 +445,15 @@ static void oxygen_card_free(struct snd_card *card)
417 if (chip->irq >= 0) 445 if (chip->irq >= 0)
418 free_irq(chip->irq, chip); 446 free_irq(chip->irq, chip);
419 flush_scheduled_work(); 447 flush_scheduled_work();
420 chip->model->cleanup(chip); 448 chip->model.cleanup(chip);
421 mutex_destroy(&chip->mutex); 449 mutex_destroy(&chip->mutex);
422 pci_release_regions(chip->pci); 450 pci_release_regions(chip->pci);
423 pci_disable_device(chip->pci); 451 pci_disable_device(chip->pci);
424} 452}
425 453
426int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 454int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
427 const struct oxygen_model *model) 455 const struct oxygen_model *model,
456 unsigned long driver_data)
428{ 457{
429 struct snd_card *card; 458 struct snd_card *card;
430 struct oxygen *chip; 459 struct oxygen *chip;
@@ -439,7 +468,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
439 chip->card = card; 468 chip->card = card;
440 chip->pci = pci; 469 chip->pci = pci;
441 chip->irq = -1; 470 chip->irq = -1;
442 chip->model = model; 471 chip->model = *model;
443 chip->model_data = chip + 1; 472 chip->model_data = chip + 1;
444 spin_lock_init(&chip->reg_lock); 473 spin_lock_init(&chip->reg_lock);
445 mutex_init(&chip->mutex); 474 mutex_init(&chip->mutex);
@@ -470,23 +499,28 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
470 snd_card_set_dev(card, &pci->dev); 499 snd_card_set_dev(card, &pci->dev);
471 card->private_free = oxygen_card_free; 500 card->private_free = oxygen_card_free;
472 501
502 if (chip->model.probe) {
503 err = chip->model.probe(chip, driver_data);
504 if (err < 0)
505 goto err_card;
506 }
473 oxygen_init(chip); 507 oxygen_init(chip);
474 model->init(chip); 508 chip->model.init(chip);
475 509
476 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED, 510 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED,
477 model->chip, chip); 511 chip->model.chip, chip);
478 if (err < 0) { 512 if (err < 0) {
479 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq); 513 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq);
480 goto err_card; 514 goto err_card;
481 } 515 }
482 chip->irq = pci->irq; 516 chip->irq = pci->irq;
483 517
484 strcpy(card->driver, model->chip); 518 strcpy(card->driver, chip->model.chip);
485 strcpy(card->shortname, model->shortname); 519 strcpy(card->shortname, chip->model.shortname);
486 sprintf(card->longname, "%s (rev %u) at %#lx, irq %i", 520 sprintf(card->longname, "%s (rev %u) at %#lx, irq %i",
487 model->longname, chip->revision, chip->addr, chip->irq); 521 chip->model.longname, chip->revision, chip->addr, chip->irq);
488 strcpy(card->mixername, model->chip); 522 strcpy(card->mixername, chip->model.chip);
489 snd_component_add(card, model->chip); 523 snd_component_add(card, chip->model.chip);
490 524
491 err = oxygen_pcm_init(chip); 525 err = oxygen_pcm_init(chip);
492 if (err < 0) 526 if (err < 0)
@@ -496,10 +530,15 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
496 if (err < 0) 530 if (err < 0)
497 goto err_card; 531 goto err_card;
498 532
499 if (model->misc_flags & OXYGEN_MISC_MIDI) { 533 if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) {
534 unsigned int info_flags = MPU401_INFO_INTEGRATED;
535 if (chip->model.device_config & MIDI_OUTPUT)
536 info_flags |= MPU401_INFO_OUTPUT;
537 if (chip->model.device_config & MIDI_INPUT)
538 info_flags |= MPU401_INFO_INPUT;
500 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 539 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
501 chip->addr + OXYGEN_MPU401, 540 chip->addr + OXYGEN_MPU401,
502 MPU401_INFO_INTEGRATED, 0, 0, 541 info_flags, 0, 0,
503 &chip->midi); 542 &chip->midi);
504 if (err < 0) 543 if (err < 0)
505 goto err_card; 544 goto err_card;
@@ -508,7 +547,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
508 oxygen_proc_init(chip); 547 oxygen_proc_init(chip);
509 548
510 spin_lock_irq(&chip->reg_lock); 549 spin_lock_irq(&chip->reg_lock);
511 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF) 550 if (chip->model.device_config & CAPTURE_1_FROM_SPDIF)
512 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT; 551 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT;
513 if (chip->has_ac97_0 | chip->has_ac97_1) 552 if (chip->has_ac97_0 | chip->has_ac97_1)
514 chip->interrupt_mask |= OXYGEN_INT_AC97; 553 chip->interrupt_mask |= OXYGEN_INT_AC97;
@@ -552,8 +591,8 @@ int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state)
552 if (chip->streams[i]) 591 if (chip->streams[i])
553 snd_pcm_suspend(chip->streams[i]); 592 snd_pcm_suspend(chip->streams[i]);
554 593
555 if (chip->model->suspend) 594 if (chip->model.suspend)
556 chip->model->suspend(chip); 595 chip->model.suspend(chip);
557 596
558 spin_lock_irq(&chip->reg_lock); 597 spin_lock_irq(&chip->reg_lock);
559 saved_interrupt_mask = chip->interrupt_mask; 598 saved_interrupt_mask = chip->interrupt_mask;
@@ -624,8 +663,8 @@ int oxygen_pci_resume(struct pci_dev *pci)
624 if (chip->has_ac97_1) 663 if (chip->has_ac97_1)
625 oxygen_restore_ac97(chip, 1); 664 oxygen_restore_ac97(chip, 1);
626 665
627 if (chip->model->resume) 666 if (chip->model.resume)
628 chip->model->resume(chip); 667 chip->model.resume(chip);
629 668
630 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); 669 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
631 670
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 05eb8994c141..304da169bfdc 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -31,9 +31,9 @@ static int dac_volume_info(struct snd_kcontrol *ctl,
31 struct oxygen *chip = ctl->private_data; 31 struct oxygen *chip = ctl->private_data;
32 32
33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
34 info->count = chip->model->dac_channels; 34 info->count = chip->model.dac_channels;
35 info->value.integer.min = chip->model->dac_volume_min; 35 info->value.integer.min = chip->model.dac_volume_min;
36 info->value.integer.max = chip->model->dac_volume_max; 36 info->value.integer.max = chip->model.dac_volume_max;
37 return 0; 37 return 0;
38} 38}
39 39
@@ -44,7 +44,7 @@ static int dac_volume_get(struct snd_kcontrol *ctl,
44 unsigned int i; 44 unsigned int i;
45 45
46 mutex_lock(&chip->mutex); 46 mutex_lock(&chip->mutex);
47 for (i = 0; i < chip->model->dac_channels; ++i) 47 for (i = 0; i < chip->model.dac_channels; ++i)
48 value->value.integer.value[i] = chip->dac_volume[i]; 48 value->value.integer.value[i] = chip->dac_volume[i];
49 mutex_unlock(&chip->mutex); 49 mutex_unlock(&chip->mutex);
50 return 0; 50 return 0;
@@ -59,13 +59,13 @@ static int dac_volume_put(struct snd_kcontrol *ctl,
59 59
60 changed = 0; 60 changed = 0;
61 mutex_lock(&chip->mutex); 61 mutex_lock(&chip->mutex);
62 for (i = 0; i < chip->model->dac_channels; ++i) 62 for (i = 0; i < chip->model.dac_channels; ++i)
63 if (value->value.integer.value[i] != chip->dac_volume[i]) { 63 if (value->value.integer.value[i] != chip->dac_volume[i]) {
64 chip->dac_volume[i] = value->value.integer.value[i]; 64 chip->dac_volume[i] = value->value.integer.value[i];
65 changed = 1; 65 changed = 1;
66 } 66 }
67 if (changed) 67 if (changed)
68 chip->model->update_dac_volume(chip); 68 chip->model.update_dac_volume(chip);
69 mutex_unlock(&chip->mutex); 69 mutex_unlock(&chip->mutex);
70 return changed; 70 return changed;
71} 71}
@@ -91,7 +91,7 @@ static int dac_mute_put(struct snd_kcontrol *ctl,
91 changed = !value->value.integer.value[0] != chip->dac_mute; 91 changed = !value->value.integer.value[0] != chip->dac_mute;
92 if (changed) { 92 if (changed) {
93 chip->dac_mute = !value->value.integer.value[0]; 93 chip->dac_mute = !value->value.integer.value[0];
94 chip->model->update_dac_mute(chip); 94 chip->model.update_dac_mute(chip);
95 } 95 }
96 mutex_unlock(&chip->mutex); 96 mutex_unlock(&chip->mutex);
97 return changed; 97 return changed;
@@ -103,7 +103,7 @@ static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
103 "Front", "Front+Surround", "Front+Surround+Back" 103 "Front", "Front+Surround", "Front+Surround+Back"
104 }; 104 };
105 struct oxygen *chip = ctl->private_data; 105 struct oxygen *chip = ctl->private_data;
106 unsigned int count = 2 + (chip->model->dac_channels == 8); 106 unsigned int count = 2 + (chip->model.dac_channels == 8);
107 107
108 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 108 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
109 info->count = 1; 109 info->count = 1;
@@ -172,7 +172,7 @@ void oxygen_update_dac_routing(struct oxygen *chip)
172static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 172static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
173{ 173{
174 struct oxygen *chip = ctl->private_data; 174 struct oxygen *chip = ctl->private_data;
175 unsigned int count = 2 + (chip->model->dac_channels == 8); 175 unsigned int count = 2 + (chip->model.dac_channels == 8);
176 int changed; 176 int changed;
177 177
178 mutex_lock(&chip->mutex); 178 mutex_lock(&chip->mutex);
@@ -211,13 +211,13 @@ static unsigned int oxygen_spdif_rate(unsigned int oxygen_rate)
211 case OXYGEN_RATE_64000: 211 case OXYGEN_RATE_64000:
212 return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT; 212 return 0xb << OXYGEN_SPDIF_CS_RATE_SHIFT;
213 case OXYGEN_RATE_88200: 213 case OXYGEN_RATE_88200:
214 return 0x8 << OXYGEN_SPDIF_CS_RATE_SHIFT; 214 return IEC958_AES3_CON_FS_88200 << OXYGEN_SPDIF_CS_RATE_SHIFT;
215 case OXYGEN_RATE_96000: 215 case OXYGEN_RATE_96000:
216 return 0xa << OXYGEN_SPDIF_CS_RATE_SHIFT; 216 return IEC958_AES3_CON_FS_96000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
217 case OXYGEN_RATE_176400: 217 case OXYGEN_RATE_176400:
218 return 0xc << OXYGEN_SPDIF_CS_RATE_SHIFT; 218 return IEC958_AES3_CON_FS_176400 << OXYGEN_SPDIF_CS_RATE_SHIFT;
219 case OXYGEN_RATE_192000: 219 case OXYGEN_RATE_192000:
220 return 0xe << OXYGEN_SPDIF_CS_RATE_SHIFT; 220 return IEC958_AES3_CON_FS_192000 << OXYGEN_SPDIF_CS_RATE_SHIFT;
221 } 221 }
222} 222}
223 223
@@ -521,8 +521,8 @@ static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
521 value = oxygen_read_ac97(chip, 0, priv_idx); 521 value = oxygen_read_ac97(chip, 0, priv_idx);
522 if (!(value & 0x8000)) { 522 if (!(value & 0x8000)) {
523 oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000); 523 oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000);
524 if (chip->model->ac97_switch) 524 if (chip->model.ac97_switch)
525 chip->model->ac97_switch(chip, priv_idx, 0x8000); 525 chip->model.ac97_switch(chip, priv_idx, 0x8000);
526 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 526 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
527 &chip->controls[control]->id); 527 &chip->controls[control]->id);
528 } 528 }
@@ -549,8 +549,8 @@ static int ac97_switch_put(struct snd_kcontrol *ctl,
549 change = newreg != oldreg; 549 change = newreg != oldreg;
550 if (change) { 550 if (change) {
551 oxygen_write_ac97(chip, codec, index, newreg); 551 oxygen_write_ac97(chip, codec, index, newreg);
552 if (codec == 0 && chip->model->ac97_switch) 552 if (codec == 0 && chip->model.ac97_switch)
553 chip->model->ac97_switch(chip, index, newreg & 0x8000); 553 chip->model.ac97_switch(chip, index, newreg & 0x8000);
554 if (index == AC97_LINE) { 554 if (index == AC97_LINE) {
555 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS, 555 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
556 newreg & 0x8000 ? 556 newreg & 0x8000 ?
@@ -939,16 +939,16 @@ static int add_controls(struct oxygen *chip,
939 939
940 for (i = 0; i < count; ++i) { 940 for (i = 0; i < count; ++i) {
941 template = controls[i]; 941 template = controls[i];
942 if (chip->model->control_filter) { 942 if (chip->model.control_filter) {
943 err = chip->model->control_filter(&template); 943 err = chip->model.control_filter(&template);
944 if (err < 0) 944 if (err < 0)
945 return err; 945 return err;
946 if (err == 1) 946 if (err == 1)
947 continue; 947 continue;
948 } 948 }
949 if (!strcmp(template.name, "Master Playback Volume") && 949 if (!strcmp(template.name, "Master Playback Volume") &&
950 chip->model->dac_tlv) { 950 chip->model.dac_tlv) {
951 template.tlv.p = chip->model->dac_tlv; 951 template.tlv.p = chip->model.dac_tlv;
952 template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; 952 template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
953 } 953 }
954 ctl = snd_ctl_new1(&template, chip); 954 ctl = snd_ctl_new1(&template, chip);
@@ -974,14 +974,14 @@ int oxygen_mixer_init(struct oxygen *chip)
974 err = add_controls(chip, controls, ARRAY_SIZE(controls)); 974 err = add_controls(chip, controls, ARRAY_SIZE(controls));
975 if (err < 0) 975 if (err < 0)
976 return err; 976 return err;
977 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF) { 977 if (chip->model.device_config & CAPTURE_1_FROM_SPDIF) {
978 err = add_controls(chip, spdif_input_controls, 978 err = add_controls(chip, spdif_input_controls,
979 ARRAY_SIZE(spdif_input_controls)); 979 ARRAY_SIZE(spdif_input_controls));
980 if (err < 0) 980 if (err < 0)
981 return err; 981 return err;
982 } 982 }
983 for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) { 983 for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) {
984 if (!(chip->model->pcm_dev_cfg & monitor_controls[i].pcm_dev)) 984 if (!(chip->model.device_config & monitor_controls[i].pcm_dev))
985 continue; 985 continue;
986 err = add_controls(chip, monitor_controls[i].controls, 986 err = add_controls(chip, monitor_controls[i].controls,
987 ARRAY_SIZE(monitor_controls[i].controls)); 987 ARRAY_SIZE(monitor_controls[i].controls));
@@ -1000,5 +1000,5 @@ int oxygen_mixer_init(struct oxygen *chip)
1000 if (err < 0) 1000 if (err < 0)
1001 return err; 1001 return err;
1002 } 1002 }
1003 return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0; 1003 return chip->model.mixer_init ? chip->model.mixer_init(chip) : 0;
1004} 1004}
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index c4ad65a3406f..c262049961e1 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -129,7 +129,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
129 129
130 runtime->private_data = (void *)(uintptr_t)channel; 130 runtime->private_data = (void *)(uintptr_t)channel;
131 if (channel == PCM_B && chip->has_ac97_1 && 131 if (channel == PCM_B && chip->has_ac97_1 &&
132 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1)) 132 (chip->model.device_config & CAPTURE_2_FROM_AC97_1))
133 runtime->hw = oxygen_ac97_hardware; 133 runtime->hw = oxygen_ac97_hardware;
134 else 134 else
135 runtime->hw = *oxygen_hardware[channel]; 135 runtime->hw = *oxygen_hardware[channel];
@@ -140,11 +140,11 @@ static int oxygen_open(struct snd_pcm_substream *substream,
140 runtime->hw.rate_min = 44100; 140 runtime->hw.rate_min = 44100;
141 break; 141 break;
142 case PCM_MULTICH: 142 case PCM_MULTICH:
143 runtime->hw.channels_max = chip->model->dac_channels; 143 runtime->hw.channels_max = chip->model.dac_channels;
144 break; 144 break;
145 } 145 }
146 if (chip->model->pcm_hardware_filter) 146 if (chip->model.pcm_hardware_filter)
147 chip->model->pcm_hardware_filter(channel, &runtime->hw); 147 chip->model.pcm_hardware_filter(channel, &runtime->hw);
148 err = snd_pcm_hw_constraint_step(runtime, 0, 148 err = snd_pcm_hw_constraint_step(runtime, 0,
149 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32); 149 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
150 if (err < 0) 150 if (err < 0)
@@ -355,7 +355,7 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
355 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, 355 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT,
356 oxygen_rate(hw_params) | 356 oxygen_rate(hw_params) |
357 oxygen_i2s_mclk(hw_params) | 357 oxygen_i2s_mclk(hw_params) |
358 chip->model->adc_i2s_format | 358 chip->model.adc_i2s_format |
359 oxygen_i2s_bits(hw_params), 359 oxygen_i2s_bits(hw_params),
360 OXYGEN_I2S_RATE_MASK | 360 OXYGEN_I2S_RATE_MASK |
361 OXYGEN_I2S_FORMAT_MASK | 361 OXYGEN_I2S_FORMAT_MASK |
@@ -364,7 +364,7 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
364 spin_unlock_irq(&chip->reg_lock); 364 spin_unlock_irq(&chip->reg_lock);
365 365
366 mutex_lock(&chip->mutex); 366 mutex_lock(&chip->mutex);
367 chip->model->set_adc_params(chip, hw_params); 367 chip->model.set_adc_params(chip, hw_params);
368 mutex_unlock(&chip->mutex); 368 mutex_unlock(&chip->mutex);
369 return 0; 369 return 0;
370} 370}
@@ -381,7 +381,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
381 return err; 381 return err;
382 382
383 is_ac97 = chip->has_ac97_1 && 383 is_ac97 = chip->has_ac97_1 &&
384 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1); 384 (chip->model.device_config & CAPTURE_2_FROM_AC97_1);
385 385
386 spin_lock_irq(&chip->reg_lock); 386 spin_lock_irq(&chip->reg_lock);
387 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, 387 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
@@ -391,7 +391,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
391 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, 391 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT,
392 oxygen_rate(hw_params) | 392 oxygen_rate(hw_params) |
393 oxygen_i2s_mclk(hw_params) | 393 oxygen_i2s_mclk(hw_params) |
394 chip->model->adc_i2s_format | 394 chip->model.adc_i2s_format |
395 oxygen_i2s_bits(hw_params), 395 oxygen_i2s_bits(hw_params),
396 OXYGEN_I2S_RATE_MASK | 396 OXYGEN_I2S_RATE_MASK |
397 OXYGEN_I2S_FORMAT_MASK | 397 OXYGEN_I2S_FORMAT_MASK |
@@ -401,7 +401,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
401 401
402 if (!is_ac97) { 402 if (!is_ac97) {
403 mutex_lock(&chip->mutex); 403 mutex_lock(&chip->mutex);
404 chip->model->set_adc_params(chip, hw_params); 404 chip->model.set_adc_params(chip, hw_params);
405 mutex_unlock(&chip->mutex); 405 mutex_unlock(&chip->mutex);
406 } 406 }
407 return 0; 407 return 0;
@@ -468,7 +468,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
468 OXYGEN_MULTICH_FORMAT_MASK); 468 OXYGEN_MULTICH_FORMAT_MASK);
469 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, 469 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
470 oxygen_rate(hw_params) | 470 oxygen_rate(hw_params) |
471 chip->model->dac_i2s_format | 471 chip->model.dac_i2s_format |
472 oxygen_i2s_bits(hw_params), 472 oxygen_i2s_bits(hw_params),
473 OXYGEN_I2S_RATE_MASK | 473 OXYGEN_I2S_RATE_MASK |
474 OXYGEN_I2S_FORMAT_MASK | 474 OXYGEN_I2S_FORMAT_MASK |
@@ -478,7 +478,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
478 spin_unlock_irq(&chip->reg_lock); 478 spin_unlock_irq(&chip->reg_lock);
479 479
480 mutex_lock(&chip->mutex); 480 mutex_lock(&chip->mutex);
481 chip->model->set_dac_params(chip, hw_params); 481 chip->model.set_dac_params(chip, hw_params);
482 mutex_unlock(&chip->mutex); 482 mutex_unlock(&chip->mutex);
483 return 0; 483 return 0;
484} 484}
@@ -657,25 +657,26 @@ int oxygen_pcm_init(struct oxygen *chip)
657 int outs, ins; 657 int outs, ins;
658 int err; 658 int err;
659 659
660 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S); 660 outs = !!(chip->model.device_config & PLAYBACK_0_TO_I2S);
661 ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 | 661 ins = !!(chip->model.device_config & (CAPTURE_0_FROM_I2S_1 |
662 CAPTURE_0_FROM_I2S_2)); 662 CAPTURE_0_FROM_I2S_2));
663 if (outs | ins) { 663 if (outs | ins) {
664 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm); 664 err = snd_pcm_new(chip->card, "Multichannel",
665 0, outs, ins, &pcm);
665 if (err < 0) 666 if (err < 0)
666 return err; 667 return err;
667 if (outs) 668 if (outs)
668 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 669 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
669 &oxygen_multich_ops); 670 &oxygen_multich_ops);
670 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1) 671 if (chip->model.device_config & CAPTURE_0_FROM_I2S_1)
671 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 672 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
672 &oxygen_rec_a_ops); 673 &oxygen_rec_a_ops);
673 else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2) 674 else if (chip->model.device_config & CAPTURE_0_FROM_I2S_2)
674 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 675 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
675 &oxygen_rec_b_ops); 676 &oxygen_rec_b_ops);
676 pcm->private_data = chip; 677 pcm->private_data = chip;
677 pcm->private_free = oxygen_pcm_free; 678 pcm->private_free = oxygen_pcm_free;
678 strcpy(pcm->name, "Analog"); 679 strcpy(pcm->name, "Multichannel");
679 if (outs) 680 if (outs)
680 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, 681 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
681 SNDRV_DMA_TYPE_DEV, 682 SNDRV_DMA_TYPE_DEV,
@@ -690,8 +691,8 @@ int oxygen_pcm_init(struct oxygen *chip)
690 BUFFER_BYTES_MAX); 691 BUFFER_BYTES_MAX);
691 } 692 }
692 693
693 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF); 694 outs = !!(chip->model.device_config & PLAYBACK_1_TO_SPDIF);
694 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF); 695 ins = !!(chip->model.device_config & CAPTURE_1_FROM_SPDIF);
695 if (outs | ins) { 696 if (outs | ins) {
696 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm); 697 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm);
697 if (err < 0) 698 if (err < 0)
@@ -712,11 +713,11 @@ int oxygen_pcm_init(struct oxygen *chip)
712 } 713 }
713 714
714 if (chip->has_ac97_1) { 715 if (chip->has_ac97_1) {
715 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1); 716 outs = !!(chip->model.device_config & PLAYBACK_2_TO_AC97_1);
716 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1); 717 ins = !!(chip->model.device_config & CAPTURE_2_FROM_AC97_1);
717 } else { 718 } else {
718 outs = 0; 719 outs = 0;
719 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2); 720 ins = !!(chip->model.device_config & CAPTURE_2_FROM_I2S_2);
720 } 721 }
721 if (outs | ins) { 722 if (outs | ins) {
722 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2", 723 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2",
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index 01d7b75f9182..98c6a8c65d81 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -62,14 +62,66 @@
62 * AD0 <- 0 62 * AD0 <- 0
63 */ 63 */
64 64
65/*
66 * Xonar HDAV1.3 (Deluxe)
67 * ----------------------
68 *
69 * CMI8788:
70 *
71 * I²C <-> PCM1796 (front)
72 *
73 * GPI 0 <- external power present
74 *
75 * GPIO 0 -> enable output to speakers
76 * GPIO 2 -> M0 of CS5381
77 * GPIO 3 -> M1 of CS5381
78 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
79 *
80 * TXD -> HDMI controller
81 * RXD <- HDMI controller
82 *
83 * PCM1796 front: AD1,0 <- 0,0
84 *
85 * no daughterboard
86 * ----------------
87 *
88 * GPIO 4 <- 1
89 *
90 * H6 daughterboard
91 * ----------------
92 *
93 * GPIO 4 <- 0
94 * GPIO 5 <- 0
95 *
96 * I²C <-> PCM1796 (surround)
97 * <-> PCM1796 (center/LFE)
98 * <-> PCM1796 (back)
99 *
100 * PCM1796 surround: AD1,0 <- 0,1
101 * PCM1796 center/LFE: AD1,0 <- 1,0
102 * PCM1796 back: AD1,0 <- 1,1
103 *
104 * unknown daughterboard
105 * ---------------------
106 *
107 * GPIO 4 <- 0
108 * GPIO 5 <- 1
109 *
110 * I²C <-> CS4362A (surround, center/LFE, back)
111 *
112 * CS4362A: AD0 <- 0
113 */
114
65#include <linux/pci.h> 115#include <linux/pci.h>
66#include <linux/delay.h> 116#include <linux/delay.h>
67#include <linux/mutex.h> 117#include <linux/mutex.h>
68#include <sound/ac97_codec.h> 118#include <sound/ac97_codec.h>
119#include <sound/asoundef.h>
69#include <sound/control.h> 120#include <sound/control.h>
70#include <sound/core.h> 121#include <sound/core.h>
71#include <sound/initval.h> 122#include <sound/initval.h>
72#include <sound/pcm.h> 123#include <sound/pcm.h>
124#include <sound/pcm_params.h>
73#include <sound/tlv.h> 125#include <sound/tlv.h>
74#include "oxygen.h" 126#include "oxygen.h"
75#include "cm9780.h" 127#include "cm9780.h"
@@ -98,12 +150,15 @@ enum {
98 MODEL_D2X, 150 MODEL_D2X,
99 MODEL_D1, 151 MODEL_D1,
100 MODEL_DX, 152 MODEL_DX,
153 MODEL_HDAV, /* without daughterboard */
154 MODEL_HDAV_H6, /* with H6 daughterboard */
101}; 155};
102 156
103static struct pci_device_id xonar_ids[] __devinitdata = { 157static struct pci_device_id xonar_ids[] __devinitdata = {
104 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 }, 158 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
105 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX }, 159 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
106 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X }, 160 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
161 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV },
107 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 }, 162 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 },
108 { } 163 { }
109}; 164};
@@ -124,11 +179,18 @@ MODULE_DEVICE_TABLE(pci, xonar_ids);
124#define GPIO_DX_FRONT_PANEL 0x0002 179#define GPIO_DX_FRONT_PANEL 0x0002
125#define GPIO_DX_INPUT_ROUTE 0x0100 180#define GPIO_DX_INPUT_ROUTE 0x0100
126 181
182#define GPIO_HDAV_DB_MASK 0x0030
183#define GPIO_HDAV_DB_H6 0x0000
184#define GPIO_HDAV_DB_XX 0x0020
185
186#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
127#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ 187#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
128#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ 188#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
129 189
130struct xonar_data { 190struct xonar_data {
191 unsigned int model;
131 unsigned int anti_pop_delay; 192 unsigned int anti_pop_delay;
193 unsigned int dacs;
132 u16 output_enable_bit; 194 u16 output_enable_bit;
133 u8 ext_power_reg; 195 u8 ext_power_reg;
134 u8 ext_power_int_reg; 196 u8 ext_power_int_reg;
@@ -137,10 +199,13 @@ struct xonar_data {
137 u8 pcm1796_oversampling; 199 u8 pcm1796_oversampling;
138 u8 cs4398_fm; 200 u8 cs4398_fm;
139 u8 cs4362a_fm; 201 u8 cs4362a_fm;
202 u8 hdmi_params[5];
140}; 203};
141 204
142static void pcm1796_write(struct oxygen *chip, unsigned int codec, 205static void xonar_gpio_changed(struct oxygen *chip);
143 u8 reg, u8 value) 206
207static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
208 u8 reg, u8 value)
144{ 209{
145 /* maps ALSA channel pair number to SPI output */ 210 /* maps ALSA channel pair number to SPI output */
146 static const u8 codec_map[4] = { 211 static const u8 codec_map[4] = {
@@ -154,6 +219,22 @@ static void pcm1796_write(struct oxygen *chip, unsigned int codec,
154 (reg << 8) | value); 219 (reg << 8) | value);
155} 220}
156 221
222static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
223 u8 reg, u8 value)
224{
225 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
226}
227
228static void pcm1796_write(struct oxygen *chip, unsigned int codec,
229 u8 reg, u8 value)
230{
231 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
232 OXYGEN_FUNCTION_SPI)
233 pcm1796_write_spi(chip, codec, reg, value);
234 else
235 pcm1796_write_i2c(chip, codec, reg, value);
236}
237
157static void cs4398_write(struct oxygen *chip, u8 reg, u8 value) 238static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
158{ 239{
159 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value); 240 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
@@ -164,6 +245,24 @@ static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
164 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value); 245 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
165} 246}
166 247
248static void hdmi_write_command(struct oxygen *chip, u8 command,
249 unsigned int count, const u8 *params)
250{
251 unsigned int i;
252 u8 checksum;
253
254 oxygen_write_uart(chip, 0xfb);
255 oxygen_write_uart(chip, 0xef);
256 oxygen_write_uart(chip, command);
257 oxygen_write_uart(chip, count);
258 for (i = 0; i < count; ++i)
259 oxygen_write_uart(chip, params[i]);
260 checksum = 0xfb + 0xef + command + count;
261 for (i = 0; i < count; ++i)
262 checksum += params[i];
263 oxygen_write_uart(chip, checksum);
264}
265
167static void xonar_enable_output(struct oxygen *chip) 266static void xonar_enable_output(struct oxygen *chip)
168{ 267{
169 struct xonar_data *data = chip->model_data; 268 struct xonar_data *data = chip->model_data;
@@ -180,6 +279,7 @@ static void xonar_common_init(struct oxygen *chip)
180 oxygen_set_bits8(chip, data->ext_power_int_reg, 279 oxygen_set_bits8(chip, data->ext_power_int_reg,
181 data->ext_power_bit); 280 data->ext_power_bit);
182 chip->interrupt_mask |= OXYGEN_INT_GPIO; 281 chip->interrupt_mask |= OXYGEN_INT_GPIO;
282 chip->model.gpio_changed = xonar_gpio_changed;
183 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg) 283 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
184 & data->ext_power_bit); 284 & data->ext_power_bit);
185 } 285 }
@@ -193,9 +293,10 @@ static void xonar_common_init(struct oxygen *chip)
193 293
194static void update_pcm1796_volume(struct oxygen *chip) 294static void update_pcm1796_volume(struct oxygen *chip)
195{ 295{
296 struct xonar_data *data = chip->model_data;
196 unsigned int i; 297 unsigned int i;
197 298
198 for (i = 0; i < 4; ++i) { 299 for (i = 0; i < data->dacs; ++i) {
199 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]); 300 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
200 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]); 301 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
201 } 302 }
@@ -203,13 +304,14 @@ static void update_pcm1796_volume(struct oxygen *chip)
203 304
204static void update_pcm1796_mute(struct oxygen *chip) 305static void update_pcm1796_mute(struct oxygen *chip)
205{ 306{
307 struct xonar_data *data = chip->model_data;
206 unsigned int i; 308 unsigned int i;
207 u8 value; 309 u8 value;
208 310
209 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; 311 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
210 if (chip->dac_mute) 312 if (chip->dac_mute)
211 value |= PCM1796_MUTE; 313 value |= PCM1796_MUTE;
212 for (i = 0; i < 4; ++i) 314 for (i = 0; i < data->dacs; ++i)
213 pcm1796_write(chip, i, 18, value); 315 pcm1796_write(chip, i, 18, value);
214} 316}
215 317
@@ -218,7 +320,7 @@ static void pcm1796_init(struct oxygen *chip)
218 struct xonar_data *data = chip->model_data; 320 struct xonar_data *data = chip->model_data;
219 unsigned int i; 321 unsigned int i;
220 322
221 for (i = 0; i < 4; ++i) { 323 for (i = 0; i < data->dacs; ++i) {
222 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); 324 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
223 pcm1796_write(chip, i, 20, data->pcm1796_oversampling); 325 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
224 pcm1796_write(chip, i, 21, 0); 326 pcm1796_write(chip, i, 21, 0);
@@ -234,6 +336,13 @@ static void xonar_d2_init(struct oxygen *chip)
234 data->anti_pop_delay = 300; 336 data->anti_pop_delay = 300;
235 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE; 337 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
236 data->pcm1796_oversampling = PCM1796_OS_64; 338 data->pcm1796_oversampling = PCM1796_OS_64;
339 if (data->model == MODEL_D2X) {
340 data->ext_power_reg = OXYGEN_GPIO_DATA;
341 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
342 data->ext_power_bit = GPIO_D2X_EXT_POWER;
343 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
344 GPIO_D2X_EXT_POWER);
345 }
237 346
238 pcm1796_init(chip); 347 pcm1796_init(chip);
239 348
@@ -246,17 +355,6 @@ static void xonar_d2_init(struct oxygen *chip)
246 snd_component_add(chip->card, "CS5381"); 355 snd_component_add(chip->card, "CS5381");
247} 356}
248 357
249static void xonar_d2x_init(struct oxygen *chip)
250{
251 struct xonar_data *data = chip->model_data;
252
253 data->ext_power_reg = OXYGEN_GPIO_DATA;
254 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
255 data->ext_power_bit = GPIO_D2X_EXT_POWER;
256 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
257 xonar_d2_init(chip);
258}
259
260static void update_cs4362a_volumes(struct oxygen *chip) 358static void update_cs4362a_volumes(struct oxygen *chip)
261{ 359{
262 u8 mute; 360 u8 mute;
@@ -324,6 +422,11 @@ static void xonar_d1_init(struct oxygen *chip)
324 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; 422 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
325 data->cs4362a_fm = CS4362A_FM_SINGLE | 423 data->cs4362a_fm = CS4362A_FM_SINGLE |
326 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; 424 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
425 if (data->model == MODEL_DX) {
426 data->ext_power_reg = OXYGEN_GPI_DATA;
427 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
428 data->ext_power_bit = GPI_DX_EXT_POWER;
429 }
327 430
328 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, 431 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
329 OXYGEN_2WIRE_LENGTH_8 | 432 OXYGEN_2WIRE_LENGTH_8 |
@@ -344,30 +447,86 @@ static void xonar_d1_init(struct oxygen *chip)
344 snd_component_add(chip->card, "CS5361"); 447 snd_component_add(chip->card, "CS5361");
345} 448}
346 449
347static void xonar_dx_init(struct oxygen *chip) 450static void xonar_hdav_init(struct oxygen *chip)
348{ 451{
349 struct xonar_data *data = chip->model_data; 452 struct xonar_data *data = chip->model_data;
453 u8 param;
350 454
455 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
456 OXYGEN_2WIRE_LENGTH_8 |
457 OXYGEN_2WIRE_INTERRUPT_MASK |
458 OXYGEN_2WIRE_SPEED_FAST);
459
460 data->anti_pop_delay = 100;
461 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
351 data->ext_power_reg = OXYGEN_GPI_DATA; 462 data->ext_power_reg = OXYGEN_GPI_DATA;
352 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; 463 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
353 data->ext_power_bit = GPI_DX_EXT_POWER; 464 data->ext_power_bit = GPI_DX_EXT_POWER;
354 xonar_d1_init(chip); 465 data->pcm1796_oversampling = PCM1796_OS_64;
466
467 pcm1796_init(chip);
468
469 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE);
470 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE);
471
472 oxygen_reset_uart(chip);
473 param = 0;
474 hdmi_write_command(chip, 0x61, 1, &param);
475 param = 1;
476 hdmi_write_command(chip, 0x74, 1, &param);
477 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
478 data->hdmi_params[4] = 1;
479 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
480
481 xonar_common_init(chip);
482
483 snd_component_add(chip->card, "PCM1796");
484 snd_component_add(chip->card, "CS5381");
355} 485}
356 486
357static void xonar_cleanup(struct oxygen *chip) 487static void xonar_disable_output(struct oxygen *chip)
358{ 488{
359 struct xonar_data *data = chip->model_data; 489 struct xonar_data *data = chip->model_data;
360 490
361 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); 491 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
362} 492}
363 493
494static void xonar_d2_cleanup(struct oxygen *chip)
495{
496 xonar_disable_output(chip);
497}
498
364static void xonar_d1_cleanup(struct oxygen *chip) 499static void xonar_d1_cleanup(struct oxygen *chip)
365{ 500{
366 xonar_cleanup(chip); 501 xonar_disable_output(chip);
367 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); 502 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
368 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); 503 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
369} 504}
370 505
506static void xonar_hdav_cleanup(struct oxygen *chip)
507{
508 u8 param = 0;
509
510 hdmi_write_command(chip, 0x74, 1, &param);
511 xonar_disable_output(chip);
512}
513
514static void xonar_d2_suspend(struct oxygen *chip)
515{
516 xonar_d2_cleanup(chip);
517}
518
519static void xonar_d1_suspend(struct oxygen *chip)
520{
521 xonar_d1_cleanup(chip);
522}
523
524static void xonar_hdav_suspend(struct oxygen *chip)
525{
526 xonar_hdav_cleanup(chip);
527 msleep(2);
528}
529
371static void xonar_d2_resume(struct oxygen *chip) 530static void xonar_d2_resume(struct oxygen *chip)
372{ 531{
373 pcm1796_init(chip); 532 pcm1796_init(chip);
@@ -380,6 +539,33 @@ static void xonar_d1_resume(struct oxygen *chip)
380 xonar_enable_output(chip); 539 xonar_enable_output(chip);
381} 540}
382 541
542static void xonar_hdav_resume(struct oxygen *chip)
543{
544 struct xonar_data *data = chip->model_data;
545 u8 param;
546
547 oxygen_reset_uart(chip);
548 param = 0;
549 hdmi_write_command(chip, 0x61, 1, &param);
550 param = 1;
551 hdmi_write_command(chip, 0x74, 1, &param);
552 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
553 pcm1796_init(chip);
554 xonar_enable_output(chip);
555}
556
557static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
558 struct snd_pcm_hardware *hardware)
559{
560 if (channel == PCM_MULTICH) {
561 hardware->rates = SNDRV_PCM_RATE_44100 |
562 SNDRV_PCM_RATE_48000 |
563 SNDRV_PCM_RATE_96000 |
564 SNDRV_PCM_RATE_192000;
565 hardware->rate_min = 44100;
566 }
567}
568
383static void set_pcm1796_params(struct oxygen *chip, 569static void set_pcm1796_params(struct oxygen *chip,
384 struct snd_pcm_hw_params *params) 570 struct snd_pcm_hw_params *params)
385{ 571{
@@ -388,7 +574,7 @@ static void set_pcm1796_params(struct oxygen *chip,
388 574
389 data->pcm1796_oversampling = 575 data->pcm1796_oversampling =
390 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; 576 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
391 for (i = 0; i < 4; ++i) 577 for (i = 0; i < data->dacs; ++i)
392 pcm1796_write(chip, i, 20, data->pcm1796_oversampling); 578 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
393} 579}
394 580
@@ -430,6 +616,42 @@ static void set_cs43xx_params(struct oxygen *chip,
430 cs4362a_write(chip, 0x0c, data->cs4362a_fm); 616 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
431} 617}
432 618
619static void set_hdmi_params(struct oxygen *chip,
620 struct snd_pcm_hw_params *params)
621{
622 struct xonar_data *data = chip->model_data;
623
624 data->hdmi_params[0] = 0; /* 1 = non-audio */
625 switch (params_rate(params)) {
626 case 44100:
627 data->hdmi_params[1] = IEC958_AES3_CON_FS_44100;
628 break;
629 case 48000:
630 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
631 break;
632 default: /* 96000 */
633 data->hdmi_params[1] = IEC958_AES3_CON_FS_96000;
634 break;
635 case 192000:
636 data->hdmi_params[1] = IEC958_AES3_CON_FS_192000;
637 break;
638 }
639 data->hdmi_params[2] = params_channels(params) / 2 - 1;
640 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
641 data->hdmi_params[3] = 0;
642 else
643 data->hdmi_params[3] = 0xc0;
644 data->hdmi_params[4] = 1; /* ? */
645 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
646}
647
648static void set_hdav_params(struct oxygen *chip,
649 struct snd_pcm_hw_params *params)
650{
651 set_pcm1796_params(chip, params);
652 set_hdmi_params(chip, params);
653}
654
433static void xonar_gpio_changed(struct oxygen *chip) 655static void xonar_gpio_changed(struct oxygen *chip)
434{ 656{
435 struct xonar_data *data = chip->model_data; 657 struct xonar_data *data = chip->model_data;
@@ -449,29 +671,43 @@ static void xonar_gpio_changed(struct oxygen *chip)
449 } 671 }
450} 672}
451 673
452static int alt_switch_get(struct snd_kcontrol *ctl, 674static void xonar_hdav_uart_input(struct oxygen *chip)
453 struct snd_ctl_elem_value *value) 675{
676 if (chip->uart_input_count >= 2 &&
677 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
678 chip->uart_input[chip->uart_input_count - 1] == 'K') {
679 printk(KERN_DEBUG "message from Xonar HDAV HDMI chip received:");
680 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
681 chip->uart_input, chip->uart_input_count);
682 chip->uart_input_count = 0;
683 }
684}
685
686static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
687 struct snd_ctl_elem_value *value)
454{ 688{
455 struct oxygen *chip = ctl->private_data; 689 struct oxygen *chip = ctl->private_data;
690 u16 bit = ctl->private_value;
456 691
457 value->value.integer.value[0] = 692 value->value.integer.value[0] =
458 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT); 693 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
459 return 0; 694 return 0;
460} 695}
461 696
462static int alt_switch_put(struct snd_kcontrol *ctl, 697static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
463 struct snd_ctl_elem_value *value) 698 struct snd_ctl_elem_value *value)
464{ 699{
465 struct oxygen *chip = ctl->private_data; 700 struct oxygen *chip = ctl->private_data;
701 u16 bit = ctl->private_value;
466 u16 old_bits, new_bits; 702 u16 old_bits, new_bits;
467 int changed; 703 int changed;
468 704
469 spin_lock_irq(&chip->reg_lock); 705 spin_lock_irq(&chip->reg_lock);
470 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 706 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
471 if (value->value.integer.value[0]) 707 if (value->value.integer.value[0])
472 new_bits = old_bits | GPIO_D2_ALT; 708 new_bits = old_bits | bit;
473 else 709 else
474 new_bits = old_bits & ~GPIO_D2_ALT; 710 new_bits = old_bits & ~bit;
475 changed = new_bits != old_bits; 711 changed = new_bits != old_bits;
476 if (changed) 712 if (changed)
477 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); 713 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
@@ -483,47 +719,22 @@ static const struct snd_kcontrol_new alt_switch = {
483 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
484 .name = "Analog Loopback Switch", 720 .name = "Analog Loopback Switch",
485 .info = snd_ctl_boolean_mono_info, 721 .info = snd_ctl_boolean_mono_info,
486 .get = alt_switch_get, 722 .get = gpio_bit_switch_get,
487 .put = alt_switch_put, 723 .put = gpio_bit_switch_put,
724 .private_value = GPIO_D2_ALT,
488}; 725};
489 726
490static int front_panel_get(struct snd_kcontrol *ctl,
491 struct snd_ctl_elem_value *value)
492{
493 struct oxygen *chip = ctl->private_data;
494
495 value->value.integer.value[0] =
496 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL);
497 return 0;
498}
499
500static int front_panel_put(struct snd_kcontrol *ctl,
501 struct snd_ctl_elem_value *value)
502{
503 struct oxygen *chip = ctl->private_data;
504 u16 old_reg, new_reg;
505
506 spin_lock_irq(&chip->reg_lock);
507 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
508 if (value->value.integer.value[0])
509 new_reg = old_reg | GPIO_DX_FRONT_PANEL;
510 else
511 new_reg = old_reg & ~GPIO_DX_FRONT_PANEL;
512 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
513 spin_unlock_irq(&chip->reg_lock);
514 return old_reg != new_reg;
515}
516
517static const struct snd_kcontrol_new front_panel_switch = { 727static const struct snd_kcontrol_new front_panel_switch = {
518 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
519 .name = "Front Panel Switch", 729 .name = "Front Panel Switch",
520 .info = snd_ctl_boolean_mono_info, 730 .info = snd_ctl_boolean_mono_info,
521 .get = front_panel_get, 731 .get = gpio_bit_switch_get,
522 .put = front_panel_put, 732 .put = gpio_bit_switch_put,
733 .private_value = GPIO_DX_FRONT_PANEL,
523}; 734};
524 735
525static void xonar_d1_ac97_switch(struct oxygen *chip, 736static void xonar_line_mic_ac97_switch(struct oxygen *chip,
526 unsigned int reg, unsigned int mute) 737 unsigned int reg, unsigned int mute)
527{ 738{
528 if (reg == AC97_LINE) { 739 if (reg == AC97_LINE) {
529 spin_lock_irq(&chip->reg_lock); 740 spin_lock_irq(&chip->reg_lock);
@@ -552,7 +763,7 @@ static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
552 return 0; 763 return 0;
553} 764}
554 765
555static int xonar_mixer_init(struct oxygen *chip) 766static int xonar_d2_mixer_init(struct oxygen *chip)
556{ 767{
557 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); 768 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
558} 769}
@@ -562,130 +773,147 @@ static int xonar_d1_mixer_init(struct oxygen *chip)
562 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); 773 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
563} 774}
564 775
565static const struct oxygen_model xonar_models[] = { 776static int xonar_model_probe(struct oxygen *chip, unsigned long driver_data)
566 [MODEL_D2] = { 777{
567 .shortname = "Xonar D2", 778 static const char *const names[] = {
568 .longname = "Asus Virtuoso 200", 779 [MODEL_D1] = "Xonar D1",
569 .chip = "AV200", 780 [MODEL_DX] = "Xonar DX",
570 .owner = THIS_MODULE, 781 [MODEL_D2] = "Xonar D2",
571 .init = xonar_d2_init, 782 [MODEL_D2X] = "Xonar D2X",
572 .control_filter = xonar_d2_control_filter, 783 [MODEL_HDAV] = "Xonar HDAV1.3",
573 .mixer_init = xonar_mixer_init, 784 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
574 .cleanup = xonar_cleanup, 785 };
575 .suspend = xonar_cleanup, 786 static const u8 dacs[] = {
576 .resume = xonar_d2_resume, 787 [MODEL_D1] = 2,
577 .set_dac_params = set_pcm1796_params, 788 [MODEL_DX] = 2,
578 .set_adc_params = set_cs53x1_params, 789 [MODEL_D2] = 4,
579 .update_dac_volume = update_pcm1796_volume, 790 [MODEL_D2X] = 4,
580 .update_dac_mute = update_pcm1796_mute, 791 [MODEL_HDAV] = 1,
581 .dac_tlv = pcm1796_db_scale, 792 [MODEL_HDAV_H6] = 4,
582 .model_data_size = sizeof(struct xonar_data), 793 };
583 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 794 struct xonar_data *data = chip->model_data;
584 PLAYBACK_1_TO_SPDIF | 795
585 CAPTURE_0_FROM_I2S_2 | 796 data->model = driver_data;
586 CAPTURE_1_FROM_SPDIF, 797 if (data->model == MODEL_HDAV) {
587 .dac_channels = 8, 798 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
588 .dac_volume_min = 0x0f, 799 GPIO_HDAV_DB_MASK);
589 .dac_volume_max = 0xff, 800 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) &
590 .misc_flags = OXYGEN_MISC_MIDI, 801 GPIO_HDAV_DB_MASK) {
591 .function_flags = OXYGEN_FUNCTION_SPI | 802 case GPIO_HDAV_DB_H6:
592 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 803 data->model = MODEL_HDAV_H6;
593 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 804 break;
594 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 805 case GPIO_HDAV_DB_XX:
595 }, 806 snd_printk(KERN_ERR "unknown daughterboard\n");
596 [MODEL_D2X] = { 807 return -ENODEV;
597 .shortname = "Xonar D2X", 808 }
598 .longname = "Asus Virtuoso 200", 809 }
599 .chip = "AV200", 810
600 .owner = THIS_MODULE, 811 data->dacs = dacs[data->model];
601 .init = xonar_d2x_init, 812 chip->model.shortname = names[data->model];
602 .control_filter = xonar_d2_control_filter, 813 return 0;
603 .mixer_init = xonar_mixer_init, 814}
604 .cleanup = xonar_cleanup, 815
605 .suspend = xonar_cleanup, 816static const struct oxygen_model model_xonar_d2 = {
606 .resume = xonar_d2_resume, 817 .longname = "Asus Virtuoso 200",
607 .set_dac_params = set_pcm1796_params, 818 .chip = "AV200",
608 .set_adc_params = set_cs53x1_params, 819 .owner = THIS_MODULE,
609 .update_dac_volume = update_pcm1796_volume, 820 .probe = xonar_model_probe,
610 .update_dac_mute = update_pcm1796_mute, 821 .init = xonar_d2_init,
611 .gpio_changed = xonar_gpio_changed, 822 .control_filter = xonar_d2_control_filter,
612 .dac_tlv = pcm1796_db_scale, 823 .mixer_init = xonar_d2_mixer_init,
613 .model_data_size = sizeof(struct xonar_data), 824 .cleanup = xonar_d2_cleanup,
614 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 825 .suspend = xonar_d2_suspend,
615 PLAYBACK_1_TO_SPDIF | 826 .resume = xonar_d2_resume,
616 CAPTURE_0_FROM_I2S_2 | 827 .set_dac_params = set_pcm1796_params,
617 CAPTURE_1_FROM_SPDIF, 828 .set_adc_params = set_cs53x1_params,
618 .dac_channels = 8, 829 .update_dac_volume = update_pcm1796_volume,
619 .dac_volume_min = 0x0f, 830 .update_dac_mute = update_pcm1796_mute,
620 .dac_volume_max = 0xff, 831 .dac_tlv = pcm1796_db_scale,
621 .misc_flags = OXYGEN_MISC_MIDI, 832 .model_data_size = sizeof(struct xonar_data),
622 .function_flags = OXYGEN_FUNCTION_SPI | 833 .device_config = PLAYBACK_0_TO_I2S |
623 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 834 PLAYBACK_1_TO_SPDIF |
624 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 835 CAPTURE_0_FROM_I2S_2 |
625 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 836 CAPTURE_1_FROM_SPDIF |
626 }, 837 MIDI_OUTPUT |
627 [MODEL_D1] = { 838 MIDI_INPUT,
628 .shortname = "Xonar D1", 839 .dac_channels = 8,
629 .longname = "Asus Virtuoso 100", 840 .dac_volume_min = 0x0f,
630 .chip = "AV200", 841 .dac_volume_max = 0xff,
631 .owner = THIS_MODULE, 842 .misc_flags = OXYGEN_MISC_MIDI,
632 .init = xonar_d1_init, 843 .function_flags = OXYGEN_FUNCTION_SPI |
633 .control_filter = xonar_d1_control_filter, 844 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
634 .mixer_init = xonar_d1_mixer_init, 845 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
635 .cleanup = xonar_d1_cleanup, 846 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
636 .suspend = xonar_d1_cleanup, 847};
637 .resume = xonar_d1_resume, 848
638 .set_dac_params = set_cs43xx_params, 849static const struct oxygen_model model_xonar_d1 = {
639 .set_adc_params = set_cs53x1_params, 850 .longname = "Asus Virtuoso 100",
640 .update_dac_volume = update_cs43xx_volume, 851 .chip = "AV200",
641 .update_dac_mute = update_cs43xx_mute, 852 .owner = THIS_MODULE,
642 .ac97_switch = xonar_d1_ac97_switch, 853 .probe = xonar_model_probe,
643 .dac_tlv = cs4362a_db_scale, 854 .init = xonar_d1_init,
644 .model_data_size = sizeof(struct xonar_data), 855 .control_filter = xonar_d1_control_filter,
645 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 856 .mixer_init = xonar_d1_mixer_init,
646 PLAYBACK_1_TO_SPDIF | 857 .cleanup = xonar_d1_cleanup,
647 CAPTURE_0_FROM_I2S_2, 858 .suspend = xonar_d1_suspend,
648 .dac_channels = 8, 859 .resume = xonar_d1_resume,
649 .dac_volume_min = 0, 860 .set_dac_params = set_cs43xx_params,
650 .dac_volume_max = 127, 861 .set_adc_params = set_cs53x1_params,
651 .function_flags = OXYGEN_FUNCTION_2WIRE, 862 .update_dac_volume = update_cs43xx_volume,
652 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 863 .update_dac_mute = update_cs43xx_mute,
653 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 864 .ac97_switch = xonar_line_mic_ac97_switch,
654 }, 865 .dac_tlv = cs4362a_db_scale,
655 [MODEL_DX] = { 866 .model_data_size = sizeof(struct xonar_data),
656 .shortname = "Xonar DX", 867 .device_config = PLAYBACK_0_TO_I2S |
657 .longname = "Asus Virtuoso 100", 868 PLAYBACK_1_TO_SPDIF |
658 .chip = "AV200", 869 CAPTURE_0_FROM_I2S_2,
659 .owner = THIS_MODULE, 870 .dac_channels = 8,
660 .init = xonar_dx_init, 871 .dac_volume_min = 0,
661 .control_filter = xonar_d1_control_filter, 872 .dac_volume_max = 127,
662 .mixer_init = xonar_d1_mixer_init, 873 .function_flags = OXYGEN_FUNCTION_2WIRE,
663 .cleanup = xonar_d1_cleanup, 874 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
664 .suspend = xonar_d1_cleanup, 875 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
665 .resume = xonar_d1_resume, 876};
666 .set_dac_params = set_cs43xx_params, 877
667 .set_adc_params = set_cs53x1_params, 878static const struct oxygen_model model_xonar_hdav = {
668 .update_dac_volume = update_cs43xx_volume, 879 .longname = "Asus Virtuoso 200",
669 .update_dac_mute = update_cs43xx_mute, 880 .chip = "AV200",
670 .gpio_changed = xonar_gpio_changed, 881 .owner = THIS_MODULE,
671 .ac97_switch = xonar_d1_ac97_switch, 882 .probe = xonar_model_probe,
672 .dac_tlv = cs4362a_db_scale, 883 .init = xonar_hdav_init,
673 .model_data_size = sizeof(struct xonar_data), 884 .cleanup = xonar_hdav_cleanup,
674 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 885 .suspend = xonar_hdav_suspend,
675 PLAYBACK_1_TO_SPDIF | 886 .resume = xonar_hdav_resume,
676 CAPTURE_0_FROM_I2S_2, 887 .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter,
677 .dac_channels = 8, 888 .set_dac_params = set_hdav_params,
678 .dac_volume_min = 0, 889 .set_adc_params = set_cs53x1_params,
679 .dac_volume_max = 127, 890 .update_dac_volume = update_pcm1796_volume,
680 .function_flags = OXYGEN_FUNCTION_2WIRE, 891 .update_dac_mute = update_pcm1796_mute,
681 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 892 .uart_input = xonar_hdav_uart_input,
682 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 893 .ac97_switch = xonar_line_mic_ac97_switch,
683 }, 894 .dac_tlv = pcm1796_db_scale,
895 .model_data_size = sizeof(struct xonar_data),
896 .device_config = PLAYBACK_0_TO_I2S |
897 PLAYBACK_1_TO_SPDIF |
898 CAPTURE_0_FROM_I2S_2,
899 .dac_channels = 8,
900 .dac_volume_min = 0x0f,
901 .dac_volume_max = 0xff,
902 .function_flags = OXYGEN_FUNCTION_2WIRE,
903 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
904 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
684}; 905};
685 906
686static int __devinit xonar_probe(struct pci_dev *pci, 907static int __devinit xonar_probe(struct pci_dev *pci,
687 const struct pci_device_id *pci_id) 908 const struct pci_device_id *pci_id)
688{ 909{
910 static const struct oxygen_model *const models[] = {
911 [MODEL_D1] = &model_xonar_d1,
912 [MODEL_DX] = &model_xonar_d1,
913 [MODEL_D2] = &model_xonar_d2,
914 [MODEL_D2X] = &model_xonar_d2,
915 [MODEL_HDAV] = &model_xonar_hdav,
916 };
689 static int dev; 917 static int dev;
690 int err; 918 int err;
691 919
@@ -695,8 +923,10 @@ static int __devinit xonar_probe(struct pci_dev *pci,
695 ++dev; 923 ++dev;
696 return -ENOENT; 924 return -ENOENT;
697 } 925 }
926 BUG_ON(pci_id->driver_data >= ARRAY_SIZE(models));
698 err = oxygen_pci_probe(pci, index[dev], id[dev], 927 err = oxygen_pci_probe(pci, index[dev], id[dev],
699 &xonar_models[pci_id->driver_data]); 928 models[pci_id->driver_data],
929 pci_id->driver_data);
700 if (err >= 0) 930 if (err >= 0)
701 ++dev; 931 ++dev;
702 return err; 932 return err;
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 2c7e25336795..0e06c6c9fcc0 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -464,7 +464,8 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS); 464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS);
465 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio, stream_num, 0); 465 pcxhr_set_pipe_cmd_params(&rmh, is_capture, stream->pipe->first_audio, stream_num, 0);
466 466
467 snd_assert(subs->runtime->dma_bytes < 0x200000); /* max buffer size is 2 MByte */ 467 /* max buffer size is 2 MByte */
468 snd_BUG_ON(subs->runtime->dma_bytes >= 0x200000);
468 rmh.cmd[1] = subs->runtime->dma_bytes * 8; /* size in bits */ 469 rmh.cmd[1] = subs->runtime->dma_bytes * 8; /* size in bits */
469 rmh.cmd[2] = subs->runtime->dma_addr >> 24; /* most significant byte */ 470 rmh.cmd[2] = subs->runtime->dma_addr >> 24; /* most significant byte */
470 rmh.cmd[2] |= 1<<19; /* this is a circular buffer */ 471 rmh.cmd[2] |= 1<<19; /* this is a circular buffer */
@@ -1228,7 +1229,8 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
1228 return -ENOMEM; 1229 return -ENOMEM;
1229 } 1230 }
1230 1231
1231 snd_assert(pci_id->driver_data < PCI_ID_LAST, return -ENODEV); 1232 if (snd_BUG_ON(pci_id->driver_data >= PCI_ID_LAST))
1233 return -ENODEV;
1232 card_name = pcxhr_board_params[pci_id->driver_data].board_name; 1234 card_name = pcxhr_board_params[pci_id->driver_data].board_name;
1233 mgr->playback_chips = pcxhr_board_params[pci_id->driver_data].playback_chips; 1235 mgr->playback_chips = pcxhr_board_params[pci_id->driver_data].playback_chips;
1234 mgr->capture_chips = pcxhr_board_params[pci_id->driver_data].capture_chips; 1236 mgr->capture_chips = pcxhr_board_params[pci_id->driver_data].capture_chips;
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index 000e6fed6e39..7143259cfe34 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -319,16 +319,20 @@ static int pcxhr_download_dsp(struct pcxhr_mgr *mgr, const struct firmware *dsp)
319 const unsigned char *data; 319 const unsigned char *data;
320 unsigned char dummy; 320 unsigned char dummy;
321 /* check the length of boot image */ 321 /* check the length of boot image */
322 snd_assert(dsp->size > 0, return -EINVAL); 322 if (dsp->size <= 0)
323 snd_assert(dsp->size % 3 == 0, return -EINVAL); 323 return -EINVAL;
324 snd_assert(dsp->data, return -EINVAL); 324 if (dsp->size % 3)
325 return -EINVAL;
326 if (snd_BUG_ON(!dsp->data))
327 return -EINVAL;
325 /* transfert data buffer from PC to DSP */ 328 /* transfert data buffer from PC to DSP */
326 for (i = 0; i < dsp->size; i += 3) { 329 for (i = 0; i < dsp->size; i += 3) {
327 data = dsp->data + i; 330 data = dsp->data + i;
328 if (i == 0) { 331 if (i == 0) {
329 /* test data header consistency */ 332 /* test data header consistency */
330 len = (unsigned int)((data[0]<<16) + (data[1]<<8) + data[2]); 333 len = (unsigned int)((data[0]<<16) + (data[1]<<8) + data[2]);
331 snd_assert((len==0) || (dsp->size == (len+2)*3), return -EINVAL); 334 if (len && dsp->size != (len + 2) * 3)
335 return -EINVAL;
332 } 336 }
333 /* wait DSP ready for new transfer */ 337 /* wait DSP ready for new transfer */
334 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_TRDY, 338 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, PCXHR_ISR_HI08_TRDY,
@@ -389,7 +393,8 @@ int pcxhr_load_boot_binary(struct pcxhr_mgr *mgr, const struct firmware *boot)
389 unsigned char dummy; 393 unsigned char dummy;
390 394
391 /* send the hostport address to the DSP (only the upper 24 bit !) */ 395 /* send the hostport address to the DSP (only the upper 24 bit !) */
392 snd_assert((physaddr & 0xff) == 0, return -EINVAL); 396 if (snd_BUG_ON(physaddr & 0xff))
397 return -EINVAL;
393 PCXHR_OUTPL(mgr, PCXHR_PLX_MBOX1, (physaddr >> 8)); 398 PCXHR_OUTPL(mgr, PCXHR_PLX_MBOX1, (physaddr >> 8));
394 399
395 err = pcxhr_send_it_dsp(mgr, PCXHR_IT_DOWNLOAD_BOOT, 0); 400 err = pcxhr_send_it_dsp(mgr, PCXHR_IT_DOWNLOAD_BOOT, 0);
@@ -570,7 +575,8 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
570 u32 data; 575 u32 data;
571 unsigned char reg; 576 unsigned char reg;
572 577
573 snd_assert(rmh->cmd_len<PCXHR_SIZE_MAX_CMD, return -EINVAL); 578 if (snd_BUG_ON(rmh->cmd_len >= PCXHR_SIZE_MAX_CMD))
579 return -EINVAL;
574 err = pcxhr_send_it_dsp(mgr, PCXHR_IT_MESSAGE, 1); 580 err = pcxhr_send_it_dsp(mgr, PCXHR_IT_MESSAGE, 1);
575 if (err) { 581 if (err) {
576 snd_printk(KERN_ERR "pcxhr_send_message : ED_DSP_CRASHED\n"); 582 snd_printk(KERN_ERR "pcxhr_send_message : ED_DSP_CRASHED\n");
@@ -677,7 +683,8 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
677 */ 683 */
678void pcxhr_init_rmh(struct pcxhr_rmh *rmh, int cmd) 684void pcxhr_init_rmh(struct pcxhr_rmh *rmh, int cmd)
679{ 685{
680 snd_assert(cmd < CMD_LAST_INDEX, return); 686 if (snd_BUG_ON(cmd >= CMD_LAST_INDEX))
687 return;
681 rmh->cmd[0] = pcxhr_dsp_cmds[cmd].opcode; 688 rmh->cmd[0] = pcxhr_dsp_cmds[cmd].opcode;
682 rmh->cmd_len = 1; 689 rmh->cmd_len = 1;
683 rmh->stat_len = pcxhr_dsp_cmds[cmd].st_length; 690 rmh->stat_len = pcxhr_dsp_cmds[cmd].st_length;
@@ -690,17 +697,17 @@ void pcxhr_set_pipe_cmd_params(struct pcxhr_rmh *rmh, int capture,
690 unsigned int param1, unsigned int param2, 697 unsigned int param1, unsigned int param2,
691 unsigned int param3) 698 unsigned int param3)
692{ 699{
693 snd_assert(param1 <= MASK_FIRST_FIELD); 700 snd_BUG_ON(param1 > MASK_FIRST_FIELD);
694 if (capture) 701 if (capture)
695 rmh->cmd[0] |= 0x800; /* COMMAND_RECORD_MASK */ 702 rmh->cmd[0] |= 0x800; /* COMMAND_RECORD_MASK */
696 if (param1) 703 if (param1)
697 rmh->cmd[0] |= (param1 << FIELD_SIZE); 704 rmh->cmd[0] |= (param1 << FIELD_SIZE);
698 if (param2) { 705 if (param2) {
699 snd_assert(param2 <= MASK_FIRST_FIELD); 706 snd_BUG_ON(param2 > MASK_FIRST_FIELD);
700 rmh->cmd[0] |= param2; 707 rmh->cmd[0] |= param2;
701 } 708 }
702 if(param3) { 709 if(param3) {
703 snd_assert(param3 <= MASK_DSP_WORD); 710 snd_BUG_ON(param3 > MASK_DSP_WORD);
704 rmh->cmd[1] = param3; 711 rmh->cmd[1] = param3;
705 rmh->cmd_len = 2; 712 rmh->cmd_len = 2;
706 } 713 }
diff --git a/sound/pci/pcxhr/pcxhr_hwdep.c b/sound/pci/pcxhr/pcxhr_hwdep.c
index d2f043278cf4..96640d9c227d 100644
--- a/sound/pci/pcxhr/pcxhr_hwdep.c
+++ b/sound/pci/pcxhr/pcxhr_hwdep.c
@@ -65,15 +65,18 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
65 if (err) 65 if (err)
66 return err; 66 return err;
67 /* test 8 or 12 phys out */ 67 /* test 8 or 12 phys out */
68 snd_assert((rmh.stat[0] & MASK_FIRST_FIELD) == mgr->playback_chips*2, 68 if ((rmh.stat[0] & MASK_FIRST_FIELD) != mgr->playback_chips * 2)
69 return -EINVAL); 69 return -EINVAL;
70 /* test 8 or 2 phys in */ 70 /* test 8 or 2 phys in */
71 snd_assert(((rmh.stat[0] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD) == 71 if (((rmh.stat[0] >> (2 * FIELD_SIZE)) & MASK_FIRST_FIELD) !=
72 mgr->capture_chips * 2, return -EINVAL); 72 mgr->capture_chips * 2)
73 return -EINVAL;
73 /* test max nb substream per board */ 74 /* test max nb substream per board */
74 snd_assert((rmh.stat[1] & 0x5F) >= card_streams, return -EINVAL); 75 if ((rmh.stat[1] & 0x5F) < card_streams)
76 return -EINVAL;
75 /* test max nb substream per pipe */ 77 /* test max nb substream per pipe */
76 snd_assert(((rmh.stat[1]>>7)&0x5F) >= PCXHR_PLAYBACK_STREAMS, return -EINVAL); 78 if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS)
79 return -EINVAL;
77 80
78 pcxhr_init_rmh(&rmh, CMD_VERSION); 81 pcxhr_init_rmh(&rmh, CMD_VERSION);
79 /* firmware num for DSP */ 82 /* firmware num for DSP */
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 6a3596247348..e9f0706ed3e4 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -865,7 +865,8 @@ static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm,
865 struct riptideport *hwport; 865 struct riptideport *hwport;
866 struct cmdport *cmdport = NULL; 866 struct cmdport *cmdport = NULL;
867 867
868 snd_assert(cif, return -EINVAL); 868 if (snd_BUG_ON(!cif))
869 return -EINVAL;
869 870
870 hwport = cif->hwport; 871 hwport = cif->hwport;
871 if (cif->errcnt > MAX_ERROR_COUNT) { 872 if (cif->errcnt > MAX_ERROR_COUNT) {
@@ -1482,7 +1483,6 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1482{ 1483{
1483 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1484 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1484 struct snd_pcm_runtime *runtime = substream->runtime; 1485 struct snd_pcm_runtime *runtime = substream->runtime;
1485 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
1486 struct pcmhw *data = get_pcmhwdev(substream); 1486 struct pcmhw *data = get_pcmhwdev(substream);
1487 struct cmdif *cif = chip->cif; 1487 struct cmdif *cif = chip->cif;
1488 unsigned char *lbuspath = NULL; 1488 unsigned char *lbuspath = NULL;
@@ -1490,7 +1490,8 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1490 int err = 0; 1490 int err = 0;
1491 snd_pcm_format_t format; 1491 snd_pcm_format_t format;
1492 1492
1493 snd_assert(cif && data, return -EINVAL); 1493 if (snd_BUG_ON(!cif || !data))
1494 return -EINVAL;
1494 1495
1495 snd_printdd("prepare id %d ch: %d f:0x%x r:%d\n", data->id, 1496 snd_printdd("prepare id %d ch: %d f:0x%x r:%d\n", data->id,
1496 runtime->channels, runtime->format, runtime->rate); 1497 runtime->channels, runtime->format, runtime->rate);
@@ -1513,9 +1514,9 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1513 lbuspath = data->paths.stereo; 1514 lbuspath = data->paths.stereo;
1514 break; 1515 break;
1515 } 1516 }
1516 snd_printdd("use sgdlist at 0x%p and buffer at 0x%p\n", 1517 snd_printdd("use sgdlist at 0x%p\n",
1517 data->sgdlist.area, sgbuf); 1518 data->sgdlist.area);
1518 if (data->sgdlist.area && sgbuf) { 1519 if (data->sgdlist.area) {
1519 unsigned int i, j, size, pages, f, pt, period; 1520 unsigned int i, j, size, pages, f, pt, period;
1520 struct sgd *c, *p = NULL; 1521 struct sgd *c, *p = NULL;
1521 1522
@@ -1533,6 +1534,7 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1533 pt = 0; 1534 pt = 0;
1534 j = 0; 1535 j = 0;
1535 for (i = 0; i < pages; i++) { 1536 for (i = 0; i < pages; i++) {
1537 unsigned int ofs, addr;
1536 c = &data->sgdbuf[i]; 1538 c = &data->sgdbuf[i];
1537 if (p) 1539 if (p)
1538 p->dwNextLink = cpu_to_le32(data->sgdlist.addr + 1540 p->dwNextLink = cpu_to_le32(data->sgdlist.addr +
@@ -1540,8 +1542,9 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1540 sizeof(struct 1542 sizeof(struct
1541 sgd))); 1543 sgd)));
1542 c->dwNextLink = cpu_to_le32(data->sgdlist.addr); 1544 c->dwNextLink = cpu_to_le32(data->sgdlist.addr);
1543 c->dwSegPtrPhys = 1545 ofs = j << PAGE_SHIFT;
1544 cpu_to_le32(sgbuf->table[j].addr + pt); 1546 addr = snd_pcm_sgbuf_get_addr(substream, ofs) + pt;
1547 c->dwSegPtrPhys = cpu_to_le32(addr);
1545 pt = (pt + f) % PAGE_SIZE; 1548 pt = (pt + f) % PAGE_SIZE;
1546 if (pt == 0) 1549 if (pt == 0)
1547 j++; 1550 j++;
@@ -1772,7 +1775,8 @@ snd_riptide_codec_write(struct snd_ac97 *ac97, unsigned short reg,
1772 union cmdret rptr = CMDRET_ZERO; 1775 union cmdret rptr = CMDRET_ZERO;
1773 int i = 0; 1776 int i = 0;
1774 1777
1775 snd_assert(cif, return); 1778 if (snd_BUG_ON(!cif))
1779 return;
1776 1780
1777 snd_printdd("Write AC97 reg 0x%x 0x%x\n", reg, val); 1781 snd_printdd("Write AC97 reg 0x%x 0x%x\n", reg, val);
1778 do { 1782 do {
@@ -1790,7 +1794,8 @@ static unsigned short snd_riptide_codec_read(struct snd_ac97 *ac97,
1790 struct cmdif *cif = chip->cif; 1794 struct cmdif *cif = chip->cif;
1791 union cmdret rptr = CMDRET_ZERO; 1795 union cmdret rptr = CMDRET_ZERO;
1792 1796
1793 snd_assert(cif, return 0); 1797 if (snd_BUG_ON(!cif))
1798 return 0;
1794 1799
1795 if (SEND_RACR(cif, reg, &rptr) != 0) 1800 if (SEND_RACR(cif, reg, &rptr) != 0)
1796 SEND_RACR(cif, reg, &rptr); 1801 SEND_RACR(cif, reg, &rptr);
@@ -1804,7 +1809,8 @@ static int snd_riptide_initialize(struct snd_riptide *chip)
1804 unsigned int device_id; 1809 unsigned int device_id;
1805 int err; 1810 int err;
1806 1811
1807 snd_assert(chip, return -EINVAL); 1812 if (snd_BUG_ON(!chip))
1813 return -EINVAL;
1808 1814
1809 cif = chip->cif; 1815 cif = chip->cif;
1810 if (!cif) { 1816 if (!cif) {
@@ -1836,7 +1842,8 @@ static int snd_riptide_free(struct snd_riptide *chip)
1836{ 1842{
1837 struct cmdif *cif; 1843 struct cmdif *cif;
1838 1844
1839 snd_assert(chip, return 0); 1845 if (!chip)
1846 return 0;
1840 1847
1841 if ((cif = chip->cif)) { 1848 if ((cif = chip->cif)) {
1842 SET_GRESET(cif->hwport); 1849 SET_GRESET(cif->hwport);
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 4d6fbb36ab8a..d723543beadd 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -1036,7 +1036,7 @@ static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1036 n = DDS_NUMERATOR; 1036 n = DDS_NUMERATOR;
1037 div64_32(&n, rate, &r); 1037 div64_32(&n, rate, &r);
1038 /* n should be less than 2^32 for being written to FREQ register */ 1038 /* n should be less than 2^32 for being written to FREQ register */
1039 snd_assert((n >> 32) == 0); 1039 snd_BUG_ON(n >> 32);
1040 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS 1040 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1041 value to write it after a reset */ 1041 value to write it after a reset */
1042 hdsp->dds_value = n; 1042 hdsp->dds_value = n;
@@ -3043,7 +3043,7 @@ static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct sn
3043 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 3043 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3044 3044
3045 offset = ucontrol->id.index - 1; 3045 offset = ucontrol->id.index - 1;
3046 snd_assert(offset >= 0); 3046 snd_BUG_ON(offset < 0);
3047 3047
3048 switch (hdsp->io_type) { 3048 switch (hdsp->io_type) {
3049 case Digiface: 3049 case Digiface:
@@ -3767,7 +3767,8 @@ static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3767{ 3767{
3768 int mapped_channel; 3768 int mapped_channel;
3769 3769
3770 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL); 3770 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3771 return NULL;
3771 3772
3772 if ((mapped_channel = hdsp->channel_map[channel]) < 0) 3773 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3773 return NULL; 3774 return NULL;
@@ -3784,10 +3785,12 @@ static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int chann
3784 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 3785 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3785 char *channel_buf; 3786 char *channel_buf;
3786 3787
3787 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL); 3788 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
3789 return -EINVAL;
3788 3790
3789 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel); 3791 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3790 snd_assert(channel_buf != NULL, return -EIO); 3792 if (snd_BUG_ON(!channel_buf))
3793 return -EIO;
3791 if (copy_from_user(channel_buf + pos * 4, src, count * 4)) 3794 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3792 return -EFAULT; 3795 return -EFAULT;
3793 return count; 3796 return count;
@@ -3799,10 +3802,12 @@ static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channe
3799 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 3802 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3800 char *channel_buf; 3803 char *channel_buf;
3801 3804
3802 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL); 3805 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
3806 return -EINVAL;
3803 3807
3804 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel); 3808 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3805 snd_assert(channel_buf != NULL, return -EIO); 3809 if (snd_BUG_ON(!channel_buf))
3810 return -EIO;
3806 if (copy_to_user(dst, channel_buf + pos * 4, count * 4)) 3811 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3807 return -EFAULT; 3812 return -EFAULT;
3808 return count; 3813 return count;
@@ -3815,7 +3820,8 @@ static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel,
3815 char *channel_buf; 3820 char *channel_buf;
3816 3821
3817 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel); 3822 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3818 snd_assert(channel_buf != NULL, return -EIO); 3823 if (snd_BUG_ON(!channel_buf))
3824 return -EIO;
3819 memset(channel_buf + pos * 4, 0, count * 4); 3825 memset(channel_buf + pos * 4, 0, count * 4);
3820 return count; 3826 return count;
3821} 3827}
@@ -3927,7 +3933,8 @@ static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,
3927 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 3933 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3928 int mapped_channel; 3934 int mapped_channel;
3929 3935
3930 snd_assert(info->channel < hdsp->max_channels, return -EINVAL); 3936 if (snd_BUG_ON(info->channel >= hdsp->max_channels))
3937 return -EINVAL;
3931 3938
3932 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) 3939 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3933 return -EINVAL; 3940 return -EINVAL;
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index ab423bc82342..98762f909d64 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -535,7 +535,8 @@ static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm);
535static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm); 535static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm);
536static int hdspm_autosync_ref(struct hdspm * hdspm); 536static int hdspm_autosync_ref(struct hdspm * hdspm);
537static int snd_hdspm_set_defaults(struct hdspm * hdspm); 537static int snd_hdspm_set_defaults(struct hdspm * hdspm);
538static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, 538static void hdspm_set_sgbuf(struct hdspm * hdspm,
539 struct snd_pcm_substream *substream,
539 unsigned int reg, int channels); 540 unsigned int reg, int channels);
540 541
541static inline int HDSPM_bit2freq(int n) 542static inline int HDSPM_bit2freq(int n)
@@ -845,7 +846,7 @@ static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
845 n = 110100480000000ULL; /* Value checked for AES32 and MADI */ 846 n = 110100480000000ULL; /* Value checked for AES32 and MADI */
846 div64_32(&n, rate, &r); 847 div64_32(&n, rate, &r);
847 /* n should be less than 2^32 for being written to FREQ register */ 848 /* n should be less than 2^32 for being written to FREQ register */
848 snd_assert((n >> 32) == 0); 849 snd_BUG_ON(n >> 32);
849 hdspm_write(hdspm, HDSPM_freqReg, (u32)n); 850 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
850} 851}
851 852
@@ -2617,8 +2618,8 @@ static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,
2617 2618
2618 channel = ucontrol->id.index - 1; 2619 channel = ucontrol->id.index - 1;
2619 2620
2620 snd_assert(channel >= 0 2621 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
2621 || channel < HDSPM_MAX_CHANNELS, return -EINVAL); 2622 return -EINVAL;
2622 2623
2623 mapped_channel = hdspm->channel_map[channel]; 2624 mapped_channel = hdspm->channel_map[channel];
2624 if (mapped_channel < 0) 2625 if (mapped_channel < 0)
@@ -2652,8 +2653,8 @@ static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
2652 2653
2653 channel = ucontrol->id.index - 1; 2654 channel = ucontrol->id.index - 1;
2654 2655
2655 snd_assert(channel >= 0 2656 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
2656 || channel < HDSPM_MAX_CHANNELS, return -EINVAL); 2657 return -EINVAL;
2657 2658
2658 mapped_channel = hdspm->channel_map[channel]; 2659 mapped_channel = hdspm->channel_map[channel];
2659 if (mapped_channel < 0) 2660 if (mapped_channel < 0)
@@ -3496,8 +3497,8 @@ static char *hdspm_channel_buffer_location(struct hdspm * hdspm,
3496{ 3497{
3497 int mapped_channel; 3498 int mapped_channel;
3498 3499
3499 snd_assert(channel >= 0 3500 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3500 || channel < HDSPM_MAX_CHANNELS, return NULL); 3501 return NULL;
3501 3502
3502 mapped_channel = hdspm->channel_map[channel]; 3503 mapped_channel = hdspm->channel_map[channel];
3503 if (mapped_channel < 0) 3504 if (mapped_channel < 0)
@@ -3520,14 +3521,15 @@ static int snd_hdspm_playback_copy(struct snd_pcm_substream *substream,
3520 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 3521 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3521 char *channel_buf; 3522 char *channel_buf;
3522 3523
3523 snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, 3524 if (snd_BUG_ON(pos + count > HDSPM_CHANNEL_BUFFER_BYTES / 4))
3524 return -EINVAL); 3525 return -EINVAL;
3525 3526
3526 channel_buf = 3527 channel_buf =
3527 hdspm_channel_buffer_location(hdspm, substream->pstr->stream, 3528 hdspm_channel_buffer_location(hdspm, substream->pstr->stream,
3528 channel); 3529 channel);
3529 3530
3530 snd_assert(channel_buf != NULL, return -EIO); 3531 if (snd_BUG_ON(!channel_buf))
3532 return -EIO;
3531 3533
3532 return copy_from_user(channel_buf + pos * 4, src, count * 4); 3534 return copy_from_user(channel_buf + pos * 4, src, count * 4);
3533} 3535}
@@ -3539,13 +3541,14 @@ static int snd_hdspm_capture_copy(struct snd_pcm_substream *substream,
3539 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 3541 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3540 char *channel_buf; 3542 char *channel_buf;
3541 3543
3542 snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, 3544 if (snd_BUG_ON(pos + count > HDSPM_CHANNEL_BUFFER_BYTES / 4))
3543 return -EINVAL); 3545 return -EINVAL;
3544 3546
3545 channel_buf = 3547 channel_buf =
3546 hdspm_channel_buffer_location(hdspm, substream->pstr->stream, 3548 hdspm_channel_buffer_location(hdspm, substream->pstr->stream,
3547 channel); 3549 channel);
3548 snd_assert(channel_buf != NULL, return -EIO); 3550 if (snd_BUG_ON(!channel_buf))
3551 return -EIO;
3549 return copy_to_user(dst, channel_buf + pos * 4, count * 4); 3552 return copy_to_user(dst, channel_buf + pos * 4, count * 4);
3550} 3553}
3551 3554
@@ -3559,7 +3562,8 @@ static int snd_hdspm_hw_silence(struct snd_pcm_substream *substream,
3559 channel_buf = 3562 channel_buf =
3560 hdspm_channel_buffer_location(hdspm, substream->pstr->stream, 3563 hdspm_channel_buffer_location(hdspm, substream->pstr->stream,
3561 channel); 3564 channel);
3562 snd_assert(channel_buf != NULL, return -EIO); 3565 if (snd_BUG_ON(!channel_buf))
3566 return -EIO;
3563 memset(channel_buf + pos * 4, 0, count * 4); 3567 memset(channel_buf + pos * 4, 0, count * 4);
3564 return 0; 3568 return 0;
3565} 3569}
@@ -3601,8 +3605,6 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3601 int i; 3605 int i;
3602 pid_t this_pid; 3606 pid_t this_pid;
3603 pid_t other_pid; 3607 pid_t other_pid;
3604 struct snd_sg_buf *sgbuf;
3605
3606 3608
3607 spin_lock_irq(&hdspm->lock); 3609 spin_lock_irq(&hdspm->lock);
3608 3610
@@ -3670,11 +3672,9 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3670 if (err < 0) 3672 if (err < 0)
3671 return err; 3673 return err;
3672 3674
3673 sgbuf = snd_pcm_substream_sgbuf(substream);
3674
3675 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 3675 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3676 3676
3677 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferOut, 3677 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
3678 params_channels(params)); 3678 params_channels(params));
3679 3679
3680 for (i = 0; i < params_channels(params); ++i) 3680 for (i = 0; i < params_channels(params); ++i)
@@ -3685,7 +3685,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3685 snd_printdd("Allocated sample buffer for playback at %p\n", 3685 snd_printdd("Allocated sample buffer for playback at %p\n",
3686 hdspm->playback_buffer); 3686 hdspm->playback_buffer);
3687 } else { 3687 } else {
3688 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferIn, 3688 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
3689 params_channels(params)); 3689 params_channels(params));
3690 3690
3691 for (i = 0; i < params_channels(params); ++i) 3691 for (i = 0; i < params_channels(params); ++i)
@@ -3700,7 +3700,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3700 snd_printdd("Allocated sample buffer for %s at 0x%08X\n", 3700 snd_printdd("Allocated sample buffer for %s at 0x%08X\n",
3701 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 3701 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
3702 "playback" : "capture", 3702 "playback" : "capture",
3703 snd_pcm_sgbuf_get_addr(sgbuf, 0)); 3703 snd_pcm_sgbuf_get_addr(substream, 0));
3704 */ 3704 */
3705 /* 3705 /*
3706 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", 3706 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n",
@@ -3744,7 +3744,8 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
3744 struct hdspm *hdspm = snd_pcm_substream_chip(substream); 3744 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3745 int mapped_channel; 3745 int mapped_channel;
3746 3746
3747 snd_assert(info->channel < HDSPM_MAX_CHANNELS, return -EINVAL); 3747 if (snd_BUG_ON(info->channel >= HDSPM_MAX_CHANNELS))
3748 return -EINVAL;
3748 3749
3749 mapped_channel = hdspm->channel_map[info->channel]; 3750 mapped_channel = hdspm->channel_map[info->channel];
3750 if (mapped_channel < 0) 3751 if (mapped_channel < 0)
@@ -4249,13 +4250,14 @@ static int __devinit snd_hdspm_preallocate_memory(struct hdspm * hdspm)
4249 return 0; 4250 return 0;
4250} 4251}
4251 4252
4252static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, 4253static void hdspm_set_sgbuf(struct hdspm * hdspm,
4254 struct snd_pcm_substream *substream,
4253 unsigned int reg, int channels) 4255 unsigned int reg, int channels)
4254{ 4256{
4255 int i; 4257 int i;
4256 for (i = 0; i < (channels * 16); i++) 4258 for (i = 0; i < (channels * 16); i++)
4257 hdspm_write(hdspm, reg + 4 * i, 4259 hdspm_write(hdspm, reg + 4 * i,
4258 snd_pcm_sgbuf_get_addr(sgbuf, (size_t) 4096 * i)); 4260 snd_pcm_sgbuf_get_addr(substream, 4096 * i));
4259} 4261}
4260 4262
4261/* ------------- ALSA Devices ---------------------------- */ 4263/* ------------- ALSA Devices ---------------------------- */
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index a123f0e6ba23..2570907134d7 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -595,8 +595,6 @@ static void rme9652_set_thru(struct snd_rme9652 *rme9652, int channel, int enabl
595 } else { 595 } else {
596 int mapped_channel; 596 int mapped_channel;
597 597
598 snd_assert(channel == RME9652_NCHANNELS, return);
599
600 mapped_channel = rme9652->channel_map[channel]; 598 mapped_channel = rme9652->channel_map[channel];
601 599
602 if (enable) { 600 if (enable) {
@@ -1893,7 +1891,8 @@ static char *rme9652_channel_buffer_location(struct snd_rme9652 *rme9652,
1893{ 1891{
1894 int mapped_channel; 1892 int mapped_channel;
1895 1893
1896 snd_assert(channel >= 0 || channel < RME9652_NCHANNELS, return NULL); 1894 if (snd_BUG_ON(channel < 0 || channel >= RME9652_NCHANNELS))
1895 return NULL;
1897 1896
1898 if ((mapped_channel = rme9652->channel_map[channel]) < 0) { 1897 if ((mapped_channel = rme9652->channel_map[channel]) < 0) {
1899 return NULL; 1898 return NULL;
@@ -1914,12 +1913,14 @@ static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream, int ch
1914 struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); 1913 struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
1915 char *channel_buf; 1914 char *channel_buf;
1916 1915
1917 snd_assert(pos + count <= RME9652_CHANNEL_BUFFER_BYTES / 4, return -EINVAL); 1916 if (snd_BUG_ON(pos + count > RME9652_CHANNEL_BUFFER_BYTES / 4))
1917 return -EINVAL;
1918 1918
1919 channel_buf = rme9652_channel_buffer_location (rme9652, 1919 channel_buf = rme9652_channel_buffer_location (rme9652,
1920 substream->pstr->stream, 1920 substream->pstr->stream,
1921 channel); 1921 channel);
1922 snd_assert(channel_buf != NULL, return -EIO); 1922 if (snd_BUG_ON(!channel_buf))
1923 return -EIO;
1923 if (copy_from_user(channel_buf + pos * 4, src, count * 4)) 1924 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
1924 return -EFAULT; 1925 return -EFAULT;
1925 return count; 1926 return count;
@@ -1931,12 +1932,14 @@ static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream, int cha
1931 struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); 1932 struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
1932 char *channel_buf; 1933 char *channel_buf;
1933 1934
1934 snd_assert(pos + count <= RME9652_CHANNEL_BUFFER_BYTES / 4, return -EINVAL); 1935 if (snd_BUG_ON(pos + count > RME9652_CHANNEL_BUFFER_BYTES / 4))
1936 return -EINVAL;
1935 1937
1936 channel_buf = rme9652_channel_buffer_location (rme9652, 1938 channel_buf = rme9652_channel_buffer_location (rme9652,
1937 substream->pstr->stream, 1939 substream->pstr->stream,
1938 channel); 1940 channel);
1939 snd_assert(channel_buf != NULL, return -EIO); 1941 if (snd_BUG_ON(!channel_buf))
1942 return -EIO;
1940 if (copy_to_user(dst, channel_buf + pos * 4, count * 4)) 1943 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
1941 return -EFAULT; 1944 return -EFAULT;
1942 return count; 1945 return count;
@@ -1951,7 +1954,8 @@ static int snd_rme9652_hw_silence(struct snd_pcm_substream *substream, int chann
1951 channel_buf = rme9652_channel_buffer_location (rme9652, 1954 channel_buf = rme9652_channel_buffer_location (rme9652,
1952 substream->pstr->stream, 1955 substream->pstr->stream,
1953 channel); 1956 channel);
1954 snd_assert(channel_buf != NULL, return -EIO); 1957 if (snd_BUG_ON(!channel_buf))
1958 return -EIO;
1955 memset(channel_buf + pos * 4, 0, count * 4); 1959 memset(channel_buf + pos * 4, 0, count * 4);
1956 return count; 1960 return count;
1957} 1961}
@@ -2053,7 +2057,8 @@ static int snd_rme9652_channel_info(struct snd_pcm_substream *substream,
2053 struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); 2057 struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
2054 int chn; 2058 int chn;
2055 2059
2056 snd_assert(info->channel < RME9652_NCHANNELS, return -EINVAL); 2060 if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS))
2061 return -EINVAL;
2057 2062
2058 if ((chn = rme9652->channel_map[info->channel]) < 0) { 2063 if ((chn = rme9652->channel_map[info->channel]) < 0) {
2059 return -EINVAL; 2064 return -EINVAL;
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 0d3d305b0a0b..cd408b86c839 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -534,8 +534,8 @@ static int snd_sonicvibes_hw_constraint_dac_rate(struct snd_pcm_hw_params *param
534 params->rate_den = 1; 534 params->rate_den = 1;
535 } else { 535 } else {
536 snd_sonicvibes_pll(rate, &r, &m, &n); 536 snd_sonicvibes_pll(rate, &r, &m, &n);
537 snd_assert((SV_REFFREQUENCY % 16) == 0, return -EINVAL); 537 snd_BUG_ON(SV_REFFREQUENCY % 16);
538 snd_assert((SV_ADCMULT % 512) == 0, return -EINVAL); 538 snd_BUG_ON(SV_ADCMULT % 512);
539 params->rate_num = (SV_REFFREQUENCY/16) * (n+2) * r; 539 params->rate_num = (SV_REFFREQUENCY/16) * (n+2) * r;
540 params->rate_den = (SV_ADCMULT/512) * (m+2); 540 params->rate_den = (SV_ADCMULT/512) * (m+2);
541 } 541 }
@@ -849,7 +849,8 @@ static int __devinit snd_sonicvibes_pcm(struct sonicvibes * sonic, int device, s
849 849
850 if ((err = snd_pcm_new(sonic->card, "s3_86c617", device, 1, 1, &pcm)) < 0) 850 if ((err = snd_pcm_new(sonic->card, "s3_86c617", device, 1, 1, &pcm)) < 0)
851 return err; 851 return err;
852 snd_assert(pcm != NULL, return -EINVAL); 852 if (snd_BUG_ON(!pcm))
853 return -EINVAL;
853 854
854 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sonicvibes_playback_ops); 855 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sonicvibes_playback_ops);
855 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sonicvibes_capture_ops); 856 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sonicvibes_capture_ops);
@@ -1089,7 +1090,8 @@ static int __devinit snd_sonicvibes_mixer(struct sonicvibes * sonic)
1089 unsigned int idx; 1090 unsigned int idx;
1090 int err; 1091 int err;
1091 1092
1092 snd_assert(sonic != NULL && sonic->card != NULL, return -EINVAL); 1093 if (snd_BUG_ON(!sonic || !sonic->card))
1094 return -EINVAL;
1093 card = sonic->card; 1095 card = sonic->card;
1094 strcpy(card->mixername, "S3 SonicVibes"); 1096 strcpy(card->mixername, "S3 SonicVibes");
1095 1097
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index a69b4206c69e..c612b435ca2b 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -2931,7 +2931,8 @@ static int snd_trident_pcm_mixer_build(struct snd_trident *trident,
2931{ 2931{
2932 struct snd_trident_pcm_mixer *tmix; 2932 struct snd_trident_pcm_mixer *tmix;
2933 2933
2934 snd_assert(trident != NULL && voice != NULL && substream != NULL, return -EINVAL); 2934 if (snd_BUG_ON(!trident || !voice || !substream))
2935 return -EINVAL;
2935 tmix = &trident->pcm_mixer[substream->number]; 2936 tmix = &trident->pcm_mixer[substream->number];
2936 tmix->voice = voice; 2937 tmix->voice = voice;
2937 tmix->vol = T4D_DEFAULT_PCM_VOL; 2938 tmix->vol = T4D_DEFAULT_PCM_VOL;
@@ -2946,7 +2947,8 @@ static int snd_trident_pcm_mixer_free(struct snd_trident *trident, struct snd_tr
2946{ 2947{
2947 struct snd_trident_pcm_mixer *tmix; 2948 struct snd_trident_pcm_mixer *tmix;
2948 2949
2949 snd_assert(trident != NULL && substream != NULL, return -EINVAL); 2950 if (snd_BUG_ON(!trident || !substream))
2951 return -EINVAL;
2950 tmix = &trident->pcm_mixer[substream->number]; 2952 tmix = &trident->pcm_mixer[substream->number];
2951 tmix->voice = NULL; 2953 tmix->voice = NULL;
2952 snd_trident_notify_pcm_change(trident, tmix, substream->number, 0); 2954 snd_trident_notify_pcm_change(trident, tmix, substream->number, 0);
@@ -3131,7 +3133,8 @@ static unsigned char snd_trident_gameport_read(struct gameport *gameport)
3131{ 3133{
3132 struct snd_trident *chip = gameport_get_port_data(gameport); 3134 struct snd_trident *chip = gameport_get_port_data(gameport);
3133 3135
3134 snd_assert(chip, return 0); 3136 if (snd_BUG_ON(!chip))
3137 return 0;
3135 return inb(TRID_REG(chip, GAMEPORT_LEGACY)); 3138 return inb(TRID_REG(chip, GAMEPORT_LEGACY));
3136} 3139}
3137 3140
@@ -3139,7 +3142,8 @@ static void snd_trident_gameport_trigger(struct gameport *gameport)
3139{ 3142{
3140 struct snd_trident *chip = gameport_get_port_data(gameport); 3143 struct snd_trident *chip = gameport_get_port_data(gameport);
3141 3144
3142 snd_assert(chip, return); 3145 if (snd_BUG_ON(!chip))
3146 return;
3143 outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY)); 3147 outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY));
3144} 3148}
3145 3149
@@ -3148,7 +3152,8 @@ static int snd_trident_gameport_cooked_read(struct gameport *gameport, int *axes
3148 struct snd_trident *chip = gameport_get_port_data(gameport); 3152 struct snd_trident *chip = gameport_get_port_data(gameport);
3149 int i; 3153 int i;
3150 3154
3151 snd_assert(chip, return 0); 3155 if (snd_BUG_ON(!chip))
3156 return 0;
3152 3157
3153 *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf; 3158 *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf;
3154 3159
@@ -3164,7 +3169,8 @@ static int snd_trident_gameport_open(struct gameport *gameport, int mode)
3164{ 3169{
3165 struct snd_trident *chip = gameport_get_port_data(gameport); 3170 struct snd_trident *chip = gameport_get_port_data(gameport);
3166 3171
3167 snd_assert(chip, return 0); 3172 if (snd_BUG_ON(!chip))
3173 return 0;
3168 3174
3169 switch (mode) { 3175 switch (mode) {
3170 case GAMEPORT_MODE_COOKED: 3176 case GAMEPORT_MODE_COOKED:
@@ -3891,8 +3897,8 @@ static void snd_trident_clear_voices(struct snd_trident * trident, unsigned shor
3891{ 3897{
3892 unsigned int i, val, mask[2] = { 0, 0 }; 3898 unsigned int i, val, mask[2] = { 0, 0 };
3893 3899
3894 snd_assert(v_min <= 63, return); 3900 if (snd_BUG_ON(v_min > 63 || v_max > 63))
3895 snd_assert(v_max <= 63, return); 3901 return;
3896 for (i = v_min; i <= v_max; i++) 3902 for (i = v_min; i <= v_max; i++)
3897 mask[i >> 5] |= 1 << (i & 0x1f); 3903 mask[i >> 5] |= 1 << (i & 0x1f);
3898 if (mask[0]) { 3904 if (mask[0]) {
diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c
index 3fd7f1b29b0f..f9779e23fe57 100644
--- a/sound/pci/trident/trident_memory.c
+++ b/sound/pci/trident/trident_memory.c
@@ -194,11 +194,14 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
194 struct snd_util_memblk *blk; 194 struct snd_util_memblk *blk;
195 struct snd_pcm_runtime *runtime = substream->runtime; 195 struct snd_pcm_runtime *runtime = substream->runtime;
196 int idx, page; 196 int idx, page;
197 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
198 197
199 snd_assert(runtime->dma_bytes > 0 && runtime->dma_bytes <= SNDRV_TRIDENT_MAX_PAGES * SNDRV_TRIDENT_PAGE_SIZE, return NULL); 198 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
199 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES *
200 SNDRV_TRIDENT_PAGE_SIZE))
201 return NULL;
200 hdr = trident->tlb.memhdr; 202 hdr = trident->tlb.memhdr;
201 snd_assert(hdr != NULL, return NULL); 203 if (snd_BUG_ON(!hdr))
204 return NULL;
202 205
203 206
204 207
@@ -208,18 +211,14 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
208 mutex_unlock(&hdr->block_mutex); 211 mutex_unlock(&hdr->block_mutex);
209 return NULL; 212 return NULL;
210 } 213 }
211 if (lastpg(blk) - firstpg(blk) >= sgbuf->pages) {
212 snd_printk(KERN_ERR "page calculation doesn't match: allocated pages = %d, trident = %d/%d\n", sgbuf->pages, firstpg(blk), lastpg(blk));
213 __snd_util_mem_free(hdr, blk);
214 mutex_unlock(&hdr->block_mutex);
215 return NULL;
216 }
217 214
218 /* set TLB entries */ 215 /* set TLB entries */
219 idx = 0; 216 idx = 0;
220 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) { 217 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) {
221 dma_addr_t addr = sgbuf->table[idx].addr; 218 unsigned long ofs = idx << PAGE_SHIFT;
222 unsigned long ptr = (unsigned long)sgbuf->table[idx].buf; 219 dma_addr_t addr = snd_pcm_sgbuf_get_addr(substream, ofs);
220 unsigned long ptr = (unsigned long)
221 snd_pcm_sgbuf_get_ptr(substream, ofs);
223 if (! is_valid_page(addr)) { 222 if (! is_valid_page(addr)) {
224 __snd_util_mem_free(hdr, blk); 223 __snd_util_mem_free(hdr, blk);
225 mutex_unlock(&hdr->block_mutex); 224 mutex_unlock(&hdr->block_mutex);
@@ -245,9 +244,13 @@ snd_trident_alloc_cont_pages(struct snd_trident *trident,
245 dma_addr_t addr; 244 dma_addr_t addr;
246 unsigned long ptr; 245 unsigned long ptr;
247 246
248 snd_assert(runtime->dma_bytes> 0 && runtime->dma_bytes <= SNDRV_TRIDENT_MAX_PAGES * SNDRV_TRIDENT_PAGE_SIZE, return NULL); 247 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
248 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES *
249 SNDRV_TRIDENT_PAGE_SIZE))
250 return NULL;
249 hdr = trident->tlb.memhdr; 251 hdr = trident->tlb.memhdr;
250 snd_assert(hdr != NULL, return NULL); 252 if (snd_BUG_ON(!hdr))
253 return NULL;
251 254
252 mutex_lock(&hdr->block_mutex); 255 mutex_lock(&hdr->block_mutex);
253 blk = search_empty(hdr, runtime->dma_bytes); 256 blk = search_empty(hdr, runtime->dma_bytes);
@@ -279,8 +282,8 @@ struct snd_util_memblk *
279snd_trident_alloc_pages(struct snd_trident *trident, 282snd_trident_alloc_pages(struct snd_trident *trident,
280 struct snd_pcm_substream *substream) 283 struct snd_pcm_substream *substream)
281{ 284{
282 snd_assert(trident != NULL, return NULL); 285 if (snd_BUG_ON(!trident || !substream))
283 snd_assert(substream != NULL, return NULL); 286 return NULL;
284 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_SG) 287 if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_SG)
285 return snd_trident_alloc_sg_pages(trident, substream); 288 return snd_trident_alloc_sg_pages(trident, substream);
286 else 289 else
@@ -297,8 +300,8 @@ int snd_trident_free_pages(struct snd_trident *trident,
297 struct snd_util_memhdr *hdr; 300 struct snd_util_memhdr *hdr;
298 int page; 301 int page;
299 302
300 snd_assert(trident != NULL, return -EINVAL); 303 if (snd_BUG_ON(!trident || !blk))
301 snd_assert(blk != NULL, return -EINVAL); 304 return -EINVAL;
302 305
303 hdr = trident->tlb.memhdr; 306 hdr = trident->tlb.memhdr;
304 mutex_lock(&hdr->block_mutex); 307 mutex_lock(&hdr->block_mutex);
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 6781be9e3078..1aafe956ee2b 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -313,6 +313,7 @@ struct snd_via_sg_table {
313} ; 313} ;
314 314
315#define VIA_TABLE_SIZE 255 315#define VIA_TABLE_SIZE 255
316#define VIA_MAX_BUFSIZE (1<<24)
316 317
317struct viadev { 318struct viadev {
318 unsigned int reg_offset; 319 unsigned int reg_offset;
@@ -420,7 +421,6 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
420{ 421{
421 unsigned int i, idx, ofs, rest; 422 unsigned int i, idx, ofs, rest;
422 struct via82xx *chip = snd_pcm_substream_chip(substream); 423 struct via82xx *chip = snd_pcm_substream_chip(substream);
423 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
424 424
425 if (dev->table.area == NULL) { 425 if (dev->table.area == NULL) {
426 /* the start of each lists must be aligned to 8 bytes, 426 /* the start of each lists must be aligned to 8 bytes,
@@ -449,15 +449,15 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
449 do { 449 do {
450 unsigned int r; 450 unsigned int r;
451 unsigned int flag; 451 unsigned int flag;
452 unsigned int addr;
452 453
453 if (idx >= VIA_TABLE_SIZE) { 454 if (idx >= VIA_TABLE_SIZE) {
454 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 455 snd_printk(KERN_ERR "via82xx: too much table size!\n");
455 return -EINVAL; 456 return -EINVAL;
456 } 457 }
457 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs)); 458 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
458 r = PAGE_SIZE - (ofs % PAGE_SIZE); 459 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32(addr);
459 if (rest < r) 460 r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest);
460 r = rest;
461 rest -= r; 461 rest -= r;
462 if (! rest) { 462 if (! rest) {
463 if (i == periods - 1) 463 if (i == periods - 1)
@@ -824,7 +824,8 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
824 struct viadev *viadev = substream->runtime->private_data; 824 struct viadev *viadev = substream->runtime->private_data;
825 unsigned int idx, ptr, count, res; 825 unsigned int idx, ptr, count, res;
826 826
827 snd_assert(viadev->tbl_entries, return 0); 827 if (snd_BUG_ON(!viadev->tbl_entries))
828 return 0;
828 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) 829 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
829 return 0; 830 return 0;
830 831
@@ -855,7 +856,8 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *subst
855 unsigned int idx, count, res; 856 unsigned int idx, count, res;
856 int status; 857 int status;
857 858
858 snd_assert(viadev->tbl_entries, return 0); 859 if (snd_BUG_ON(!viadev->tbl_entries))
860 return 0;
859 861
860 spin_lock(&chip->reg_lock); 862 spin_lock(&chip->reg_lock);
861 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); 863 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
@@ -1037,7 +1039,7 @@ static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream)
1037 else 1039 else
1038 rbits = (0x100000 / 48000) * runtime->rate + 1040 rbits = (0x100000 / 48000) * runtime->rate +
1039 ((0x100000 % 48000) * runtime->rate) / 48000; 1041 ((0x100000 % 48000) * runtime->rate) / 48000;
1040 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL); 1042 snd_BUG_ON(rbits & ~0xfffff);
1041 snd_via82xx_channel_reset(chip, viadev); 1043 snd_via82xx_channel_reset(chip, viadev);
1042 snd_via82xx_set_table_ptr(chip, viadev); 1044 snd_via82xx_set_table_ptr(chip, viadev);
1043 outb(chip->playback_volume[viadev->reg_offset / 0x10][0], 1045 outb(chip->playback_volume[viadev->reg_offset / 0x10][0],
@@ -1144,9 +1146,9 @@ static struct snd_pcm_hardware snd_via82xx_hw =
1144 .rate_max = 48000, 1146 .rate_max = 48000,
1145 .channels_min = 1, 1147 .channels_min = 1,
1146 .channels_max = 2, 1148 .channels_max = 2,
1147 .buffer_bytes_max = 128 * 1024, 1149 .buffer_bytes_max = VIA_MAX_BUFSIZE,
1148 .period_bytes_min = 32, 1150 .period_bytes_min = 32,
1149 .period_bytes_max = 128 * 1024, 1151 .period_bytes_max = VIA_MAX_BUFSIZE / 2,
1150 .periods_min = 2, 1152 .periods_min = 2,
1151 .periods_max = VIA_TABLE_SIZE / 2, 1153 .periods_max = VIA_TABLE_SIZE / 2,
1152 .fifo_size = 0, 1154 .fifo_size = 0,
@@ -1398,10 +1400,9 @@ static int __devinit snd_via8233_pcm_new(struct via82xx *chip)
1398 /* capture */ 1400 /* capture */
1399 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); 1401 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1400 1402
1401 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1403 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1402 snd_dma_pci_data(chip->pci), 1404 snd_dma_pci_data(chip->pci),
1403 64*1024, 128*1024)) < 0) 1405 64*1024, VIA_MAX_BUFSIZE);
1404 return err;
1405 1406
1406 /* PCM #1: multi-channel playback and 2nd capture */ 1407 /* PCM #1: multi-channel playback and 2nd capture */
1407 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm); 1408 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm);
@@ -1417,11 +1418,9 @@ static int __devinit snd_via8233_pcm_new(struct via82xx *chip)
1417 /* set up capture */ 1418 /* set up capture */
1418 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1); 1419 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
1419 1420
1420 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1421 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1421 snd_dma_pci_data(chip->pci), 1422 snd_dma_pci_data(chip->pci),
1422 64*1024, 128*1024)) < 0) 1423 64*1024, VIA_MAX_BUFSIZE);
1423 return err;
1424
1425 return 0; 1424 return 0;
1426} 1425}
1427 1426
@@ -1453,10 +1452,9 @@ static int __devinit snd_via8233a_pcm_new(struct via82xx *chip)
1453 /* capture */ 1452 /* capture */
1454 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); 1453 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1455 1454
1456 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1455 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1457 snd_dma_pci_data(chip->pci), 1456 snd_dma_pci_data(chip->pci),
1458 64*1024, 128*1024)) < 0) 1457 64*1024, VIA_MAX_BUFSIZE);
1459 return err;
1460 1458
1461 /* SPDIF supported? */ 1459 /* SPDIF supported? */
1462 if (! ac97_can_spdif(chip->ac97)) 1460 if (! ac97_can_spdif(chip->ac97))
@@ -1473,11 +1471,9 @@ static int __devinit snd_via8233a_pcm_new(struct via82xx *chip)
1473 /* set up playback */ 1471 /* set up playback */
1474 init_viadev(chip, chip->playback_devno, 0x30, 3, 0); 1472 init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
1475 1473
1476 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1474 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1477 snd_dma_pci_data(chip->pci), 1475 snd_dma_pci_data(chip->pci),
1478 64*1024, 128*1024)) < 0) 1476 64*1024, VIA_MAX_BUFSIZE);
1479 return err;
1480
1481 return 0; 1477 return 0;
1482} 1478}
1483 1479
@@ -1505,11 +1501,9 @@ static int __devinit snd_via686_pcm_new(struct via82xx *chip)
1505 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0); 1501 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
1506 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1); 1502 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
1507 1503
1508 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1504 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1509 snd_dma_pci_data(chip->pci), 1505 snd_dma_pci_data(chip->pci),
1510 64*1024, 128*1024)) < 0) 1506 64*1024, VIA_MAX_BUFSIZE);
1511 return err;
1512
1513 return 0; 1507 return 0;
1514} 1508}
1515 1509
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 31f64ee39882..5bd79d2a5a15 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -281,7 +281,6 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
281{ 281{
282 unsigned int i, idx, ofs, rest; 282 unsigned int i, idx, ofs, rest;
283 struct via82xx_modem *chip = snd_pcm_substream_chip(substream); 283 struct via82xx_modem *chip = snd_pcm_substream_chip(substream);
284 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
285 284
286 if (dev->table.area == NULL) { 285 if (dev->table.area == NULL) {
287 /* the start of each lists must be aligned to 8 bytes, 286 /* the start of each lists must be aligned to 8 bytes,
@@ -310,12 +309,14 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
310 do { 309 do {
311 unsigned int r; 310 unsigned int r;
312 unsigned int flag; 311 unsigned int flag;
312 unsigned int addr;
313 313
314 if (idx >= VIA_TABLE_SIZE) { 314 if (idx >= VIA_TABLE_SIZE) {
315 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 315 snd_printk(KERN_ERR "via82xx: too much table size!\n");
316 return -EINVAL; 316 return -EINVAL;
317 } 317 }
318 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs)); 318 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
319 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32(addr);
319 r = PAGE_SIZE - (ofs % PAGE_SIZE); 320 r = PAGE_SIZE - (ofs % PAGE_SIZE);
320 if (rest < r) 321 if (rest < r)
321 r = rest; 322 r = rest;
@@ -612,7 +613,8 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
612 struct viadev *viadev = substream->runtime->private_data; 613 struct viadev *viadev = substream->runtime->private_data;
613 unsigned int idx, ptr, count, res; 614 unsigned int idx, ptr, count, res;
614 615
615 snd_assert(viadev->tbl_entries, return 0); 616 if (snd_BUG_ON(!viadev->tbl_entries))
617 return 0;
616 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) 618 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
617 return 0; 619 return 0;
618 620
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index 631f3a639993..7e87f398ff0b 100644
--- a/sound/pci/vx222/vx222_ops.c
+++ b/sound/pci/vx222/vx222_ops.c
@@ -253,7 +253,8 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
253 int offset = pipe->hw_ptr; 253 int offset = pipe->hw_ptr;
254 u32 *addr = (u32 *)(runtime->dma_area + offset); 254 u32 *addr = (u32 *)(runtime->dma_area + offset);
255 255
256 snd_assert(count % 4 == 0, return); 256 if (snd_BUG_ON(count % 4))
257 return;
257 258
258 vx2_setup_pseudo_dma(chip, 1); 259 vx2_setup_pseudo_dma(chip, 1);
259 260
@@ -291,7 +292,8 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
291 u32 *addr = (u32 *)(runtime->dma_area + offset); 292 u32 *addr = (u32 *)(runtime->dma_area + offset);
292 unsigned long port = vx2_reg_addr(chip, VX_DMA); 293 unsigned long port = vx2_reg_addr(chip, VX_DMA);
293 294
294 snd_assert(count % 4 == 0, return); 295 if (snd_BUG_ON(count % 4))
296 return;
295 297
296 vx2_setup_pseudo_dma(chip, 0); 298 vx2_setup_pseudo_dma(chip, 0);
297 /* Transfer using pseudo-dma. 299 /* Transfer using pseudo-dma.
@@ -675,7 +677,8 @@ static void vx2_write_akm(struct vx_core *chip, int reg, unsigned int data)
675 a look up table, as there is no linear matching between the driver codec values 677 a look up table, as there is no linear matching between the driver codec values
676 and the real dBu value 678 and the real dBu value
677 */ 679 */
678 snd_assert(data < sizeof(vx2_akm_gains_lut), return); 680 if (snd_BUG_ON(data >= sizeof(vx2_akm_gains_lut)))
681 return;
679 682
680 switch (reg) { 683 switch (reg) {
681 case XX_CODEC_LEVEL_LEFT_REGISTER: 684 case XX_CODEC_LEVEL_LEFT_REGISTER:
@@ -823,7 +826,8 @@ static void vx2_set_input_level(struct snd_vx222 *chip)
823 preamp++; /* raise pre ampli + 18dB */ 826 preamp++; /* raise pre ampli + 18dB */
824 miclevel -= (18 * 2); /* lower level 18 dB (*2 because of 0.5 dB steps !) */ 827 miclevel -= (18 * 2); /* lower level 18 dB (*2 because of 0.5 dB steps !) */
825 } 828 }
826 snd_assert(preamp < 4, return); 829 if (snd_BUG_ON(preamp >= 4))
830 return;
827 831
828 /* set pre-amp level */ 832 /* set pre-amp level */
829 chip->regSELMIC &= ~MICRO_SELECT_PREAMPLI_MASK; 833 chip->regSELMIC &= ~MICRO_SELECT_PREAMPLI_MASK;
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 92d49aadf579..90d0d62bd0b4 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -259,8 +259,10 @@ static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip,
259 unsigned long flags; 259 unsigned long flags;
260 int result; 260 int result;
261 261
262 snd_assert(rvoice != NULL, return -EINVAL); 262 if (snd_BUG_ON(!rvoice))
263 snd_assert(!pair || type == YMFPCI_PCM, return -EINVAL); 263 return -EINVAL;
264 if (snd_BUG_ON(pair && type != YMFPCI_PCM))
265 return -EINVAL;
264 266
265 spin_lock_irqsave(&chip->voice_lock, flags); 267 spin_lock_irqsave(&chip->voice_lock, flags);
266 for (;;) { 268 for (;;) {
@@ -278,7 +280,8 @@ static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voic
278{ 280{
279 unsigned long flags; 281 unsigned long flags;
280 282
281 snd_assert(pvoice != NULL, return -EINVAL); 283 if (snd_BUG_ON(!pvoice))
284 return -EINVAL;
282 snd_ymfpci_hw_stop(chip); 285 snd_ymfpci_hw_stop(chip);
283 spin_lock_irqsave(&chip->voice_lock, flags); 286 spin_lock_irqsave(&chip->voice_lock, flags);
284 if (pvoice->number == chip->src441_used) { 287 if (pvoice->number == chip->src441_used) {
@@ -494,7 +497,8 @@ static void snd_ymfpci_pcm_init_voice(struct snd_ymfpci_pcm *ypcm, unsigned int
494 u8 use_left, use_right; 497 u8 use_left, use_right;
495 unsigned long flags; 498 unsigned long flags;
496 499
497 snd_assert(voice != NULL, return); 500 if (snd_BUG_ON(!voice))
501 return;
498 if (runtime->channels == 1) { 502 if (runtime->channels == 1) {
499 use_left = 1; 503 use_left = 1;
500 use_right = 1; 504 use_right = 1;
@@ -1813,7 +1817,8 @@ int __devinit snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch)
1813 } 1817 }
1814 1818
1815 /* add S/PDIF control */ 1819 /* add S/PDIF control */
1816 snd_assert(chip->pcm_spdif != NULL, return -EIO); 1820 if (snd_BUG_ON(!chip->pcm_spdif))
1821 return -ENXIO;
1817 if ((err = snd_ctl_add(chip->card, kctl = snd_ctl_new1(&snd_ymfpci_spdif_default, chip))) < 0) 1822 if ((err = snd_ctl_add(chip->card, kctl = snd_ctl_new1(&snd_ymfpci_spdif_default, chip))) < 0)
1818 return err; 1823 return err;
1819 kctl->id.device = chip->pcm_spdif->device; 1824 kctl->id.device = chip->pcm_spdif->device;
@@ -2133,7 +2138,8 @@ static int __devinit snd_ymfpci_memalloc(struct snd_ymfpci *chip)
2133 chip->work_base = ptr; 2138 chip->work_base = ptr;
2134 chip->work_base_addr = ptr_addr; 2139 chip->work_base_addr = ptr_addr;
2135 2140
2136 snd_assert(ptr + chip->work_size == chip->work_ptr.area + chip->work_ptr.bytes, ); 2141 snd_BUG_ON(ptr + chip->work_size !=
2142 chip->work_ptr.area + chip->work_ptr.bytes);
2137 2143
2138 snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, chip->bank_base_playback_addr); 2144 snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, chip->bank_base_playback_addr);
2139 snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, chip->bank_base_capture_addr); 2145 snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, chip->bank_base_capture_addr);
@@ -2168,7 +2174,8 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2168{ 2174{
2169 u16 ctrl; 2175 u16 ctrl;
2170 2176
2171 snd_assert(chip != NULL, return -EINVAL); 2177 if (snd_BUG_ON(!chip))
2178 return -EINVAL;
2172 2179
2173 if (chip->res_reg_area) { /* don't touch busy hardware */ 2180 if (chip->res_reg_area) { /* don't touch busy hardware */
2174 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0); 2181 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0);