aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/Kconfig2
-rw-r--r--sound/pci/ac97/ac97_codec.c18
-rw-r--r--sound/pci/ac97/ac97_id.h2
-rw-r--r--sound/pci/ac97/ac97_patch.c32
-rw-r--r--sound/pci/ac97/ac97_proc.c1
-rw-r--r--sound/pci/ad1889.c2
-rw-r--r--sound/pci/ali5451/ali5451.c2
-rw-r--r--sound/pci/als300.c2
-rw-r--r--sound/pci/als4000.c3
-rw-r--r--sound/pci/atiixp.c3
-rw-r--r--sound/pci/atiixp_modem.c2
-rw-r--r--sound/pci/au88x0/au8810.c2
-rw-r--r--sound/pci/au88x0/au8820.c2
-rw-r--r--sound/pci/au88x0/au8830.c2
-rw-r--r--sound/pci/aw2/aw2-alsa.c2
-rw-r--r--sound/pci/aw2/aw2-saa7146.c1
-rw-r--r--sound/pci/azt3328.c6
-rw-r--r--sound/pci/bt87x.c4
-rw-r--r--sound/pci/ca0106/ca0106_main.c2
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c5
-rw-r--r--sound/pci/ca0106/ca0106_proc.c7
-rw-r--r--sound/pci/cmipci.c22
-rw-r--r--sound/pci/cs4281.c2
-rw-r--r--sound/pci/cs46xx/cs46xx.c2
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c22
-rw-r--r--sound/pci/cs46xx/dsp_spos.c42
-rw-r--r--sound/pci/cs46xx/dsp_spos.h4
-rw-r--r--sound/pci/cs46xx/dsp_spos_scb_lib.c33
-rw-r--r--sound/pci/cs46xx/imgs/cwcdma.asp9
-rw-r--r--sound/pci/cs5530.c3
-rw-r--r--sound/pci/cs5535audio/Makefile2
-rw-r--r--sound/pci/cs5535audio/cs5535audio.c3
-rw-r--r--sound/pci/cs5535audio/cs5535audio.h4
-rw-r--r--sound/pci/cs5535audio/cs5535audio_olpc.c26
-rw-r--r--sound/pci/cs5535audio/cs5535audio_pcm.c1
-rw-r--r--sound/pci/cs5535audio/cs5535audio_pm.c1
-rw-r--r--sound/pci/ctxfi/ctatc.c41
-rw-r--r--sound/pci/ctxfi/ctatc.h2
-rw-r--r--sound/pci/ctxfi/ctpcm.c1
-rw-r--r--sound/pci/ctxfi/ctvmem.c38
-rw-r--r--sound/pci/ctxfi/ctvmem.h8
-rw-r--r--sound/pci/ctxfi/xfi.c7
-rw-r--r--sound/pci/echoaudio/darla20.c4
-rw-r--r--sound/pci/echoaudio/darla20_dsp.c12
-rw-r--r--sound/pci/echoaudio/darla24.c4
-rw-r--r--sound/pci/echoaudio/darla24_dsp.c12
-rw-r--r--sound/pci/echoaudio/echo3g.c4
-rw-r--r--sound/pci/echoaudio/echo3g_dsp.c28
-rw-r--r--sound/pci/echoaudio/echoaudio.c210
-rw-r--r--sound/pci/echoaudio/echoaudio.h11
-rw-r--r--sound/pci/echoaudio/echoaudio_3g.c5
-rw-r--r--sound/pci/echoaudio/echoaudio_dsp.c157
-rw-r--r--sound/pci/echoaudio/gina20.c4
-rw-r--r--sound/pci/echoaudio/gina20_dsp.c15
-rw-r--r--sound/pci/echoaudio/gina24.c4
-rw-r--r--sound/pci/echoaudio/gina24_dsp.c38
-rw-r--r--sound/pci/echoaudio/indigo.c4
-rw-r--r--sound/pci/echoaudio/indigo_dsp.c12
-rw-r--r--sound/pci/echoaudio/indigo_express_dsp.c1
-rw-r--r--sound/pci/echoaudio/indigodj.c4
-rw-r--r--sound/pci/echoaudio/indigodj_dsp.c12
-rw-r--r--sound/pci/echoaudio/indigodjx.c4
-rw-r--r--sound/pci/echoaudio/indigodjx_dsp.c13
-rw-r--r--sound/pci/echoaudio/indigoio.c4
-rw-r--r--sound/pci/echoaudio/indigoio_dsp.c12
-rw-r--r--sound/pci/echoaudio/indigoiox.c4
-rw-r--r--sound/pci/echoaudio/indigoiox_dsp.c13
-rw-r--r--sound/pci/echoaudio/layla20.c4
-rw-r--r--sound/pci/echoaudio/layla20_dsp.c20
-rw-r--r--sound/pci/echoaudio/layla24.c4
-rw-r--r--sound/pci/echoaudio/layla24_dsp.c37
-rw-r--r--sound/pci/echoaudio/mia.c4
-rw-r--r--sound/pci/echoaudio/mia_dsp.c12
-rw-r--r--sound/pci/echoaudio/mona.c4
-rw-r--r--sound/pci/echoaudio/mona_dsp.c61
-rw-r--r--sound/pci/emu10k1/emu10k1.c2
-rw-r--r--sound/pci/emu10k1/emu10k1x.c7
-rw-r--r--sound/pci/emu10k1/emumixer.c4
-rw-r--r--sound/pci/emu10k1/emuproc.c4
-rw-r--r--sound/pci/emu10k1/io.c2
-rw-r--r--sound/pci/emu10k1/memory.c1
-rw-r--r--sound/pci/ens1370.c2
-rw-r--r--sound/pci/es1938.c4
-rw-r--r--sound/pci/es1968.c2
-rw-r--r--sound/pci/fm801.c42
-rw-r--r--sound/pci/hda/Kconfig15
-rw-r--r--sound/pci/hda/Makefile4
-rw-r--r--sound/pci/hda/hda_beep.c121
-rw-r--r--sound/pci/hda/hda_beep.h10
-rw-r--r--sound/pci/hda/hda_codec.c745
-rw-r--r--sound/pci/hda/hda_codec.h22
-rw-r--r--sound/pci/hda/hda_eld.c27
-rw-r--r--sound/pci/hda/hda_generic.c18
-rw-r--r--sound/pci/hda/hda_hwdep.c105
-rw-r--r--sound/pci/hda/hda_intel.c185
-rw-r--r--sound/pci/hda/hda_local.h77
-rw-r--r--sound/pci/hda/hda_proc.c90
-rw-r--r--sound/pci/hda/patch_analog.c210
-rw-r--r--sound/pci/hda/patch_ca0110.c4
-rw-r--r--sound/pci/hda/patch_cirrus.c65
-rw-r--r--sound/pci/hda/patch_cmedia.c17
-rw-r--r--sound/pci/hda/patch_conexant.c775
-rw-r--r--sound/pci/hda/patch_hdmi.c849
-rw-r--r--sound/pci/hda/patch_intelhdmi.c637
-rw-r--r--sound/pci/hda/patch_nvhdmi.c278
-rw-r--r--sound/pci/hda/patch_realtek.c2185
-rw-r--r--sound/pci/hda/patch_si3054.c1
-rw-r--r--sound/pci/hda/patch_sigmatel.c493
-rw-r--r--sound/pci/hda/patch_via.c3638
-rw-r--r--sound/pci/ice1712/Makefile2
-rw-r--r--sound/pci/ice1712/ak4xxx.c1
-rw-r--r--sound/pci/ice1712/amp.c1
-rw-r--r--sound/pci/ice1712/aureon.c43
-rw-r--r--sound/pci/ice1712/ice1712.c23
-rw-r--r--sound/pci/ice1712/ice1712.h14
-rw-r--r--sound/pci/ice1712/ice1724.c105
-rw-r--r--sound/pci/ice1712/juli.c58
-rw-r--r--sound/pci/ice1712/maya44.c6
-rw-r--r--sound/pci/ice1712/quartet.c1130
-rw-r--r--sound/pci/ice1712/quartet.h10
-rw-r--r--sound/pci/ice1712/vt1720_mobo.c1
-rw-r--r--sound/pci/ice1712/wtm.c1
-rw-r--r--sound/pci/intel8x0.c8
-rw-r--r--sound/pci/intel8x0m.c2
-rw-r--r--sound/pci/korg1212/korg1212.c2
-rw-r--r--sound/pci/lx6464es/lx6464es.c3
-rw-r--r--sound/pci/maestro3.c11
-rw-r--r--sound/pci/mixart/mixart.c27
-rw-r--r--sound/pci/mixart/mixart_hwdep.c1
-rw-r--r--sound/pci/nm256/nm256.c2
-rw-r--r--sound/pci/oxygen/Makefile3
-rw-r--r--sound/pci/oxygen/cs2000.h83
-rw-r--r--sound/pci/oxygen/hifier.c63
-rw-r--r--sound/pci/oxygen/oxygen.c250
-rw-r--r--sound/pci/oxygen/oxygen.h5
-rw-r--r--sound/pci/oxygen/oxygen_lib.c30
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c52
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c19
-rw-r--r--sound/pci/oxygen/virtuoso.c1110
-rw-r--r--sound/pci/oxygen/wm8766.h73
-rw-r--r--sound/pci/oxygen/wm8776.h177
-rw-r--r--sound/pci/oxygen/xonar.h52
-rw-r--r--sound/pci/oxygen/xonar_cs43xx.c437
-rw-r--r--sound/pci/oxygen/xonar_hdmi.c128
-rw-r--r--sound/pci/oxygen/xonar_lib.c132
-rw-r--r--sound/pci/oxygen/xonar_pcm179x.c1115
-rw-r--r--sound/pci/oxygen/xonar_wm87x6.c1021
-rw-r--r--sound/pci/pcxhr/pcxhr.c2
-rw-r--r--sound/pci/riptide/riptide.c12
-rw-r--r--sound/pci/rme32.c4
-rw-r--r--sound/pci/rme96.c3
-rw-r--r--sound/pci/rme9652/hdsp.c3
-rw-r--r--sound/pci/rme9652/hdspm.c8
-rw-r--r--sound/pci/rme9652/rme9652.c3
-rw-r--r--sound/pci/sis7019.c3
-rw-r--r--sound/pci/sonicvibes.c2
-rw-r--r--sound/pci/trident/trident.c2
-rw-r--r--sound/pci/via82xx.c8
-rw-r--r--sound/pci/via82xx_modem.c2
-rw-r--r--sound/pci/vx222/vx222.c2
-rw-r--r--sound/pci/ymfpci/ymfpci.c2
161 files changed, 14164 insertions, 3846 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 75c602b5b132..1298c68d6bf0 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -570,6 +570,7 @@ config SND_ICE1712
570 tristate "ICEnsemble ICE1712 (Envy24)" 570 tristate "ICEnsemble ICE1712 (Envy24)"
571 select SND_MPU401_UART 571 select SND_MPU401_UART
572 select SND_AC97_CODEC 572 select SND_AC97_CODEC
573 select BITREVERSE
573 help 574 help
574 Say Y here to include support for soundcards based on the 575 Say Y here to include support for soundcards based on the
575 ICE1712 (Envy24) chip. 576 ICE1712 (Envy24) chip.
@@ -788,6 +789,7 @@ config SND_VIRTUOSO
788 Say Y here to include support for sound cards based on the 789 Say Y here to include support for sound cards based on the
789 Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X, 790 Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X,
790 Essence ST (Deluxe), and Essence STX. 791 Essence ST (Deluxe), and Essence STX.
792 Support for the DS is experimental.
791 Support for the HDAV1.3 (Deluxe) is very experimental. 793 Support for the HDAV1.3 (Deluxe) is very experimental.
792 794
793 To compile this driver as a module, choose M here: the module 795 To compile this driver as a module, choose M here: the module
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 78288dbfc17a..a7630e9edf8a 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -83,6 +83,7 @@ static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = {
83{ 0x4e534300, 0xffffff00, "National Semiconductor", NULL, NULL }, 83{ 0x4e534300, 0xffffff00, "National Semiconductor", NULL, NULL },
84{ 0x50534300, 0xffffff00, "Philips", NULL, NULL }, 84{ 0x50534300, 0xffffff00, "Philips", NULL, NULL },
85{ 0x53494c00, 0xffffff00, "Silicon Laboratory", NULL, NULL }, 85{ 0x53494c00, 0xffffff00, "Silicon Laboratory", NULL, NULL },
86{ 0x53544d00, 0xffffff00, "STMicroelectronics", NULL, NULL },
86{ 0x54524100, 0xffffff00, "TriTech", NULL, NULL }, 87{ 0x54524100, 0xffffff00, "TriTech", NULL, NULL },
87{ 0x54584e00, 0xffffff00, "Texas Instruments", NULL, NULL }, 88{ 0x54584e00, 0xffffff00, "Texas Instruments", NULL, NULL },
88{ 0x56494100, 0xffffff00, "VIA Technologies", NULL, NULL }, 89{ 0x56494100, 0xffffff00, "VIA Technologies", NULL, NULL },
@@ -161,6 +162,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
161{ 0x4e534350, 0xffffffff, "LM4550", patch_lm4550, NULL }, // volume wrap fix 162{ 0x4e534350, 0xffffffff, "LM4550", patch_lm4550, NULL }, // volume wrap fix
162{ 0x50534304, 0xffffffff, "UCB1400", patch_ucb1400, NULL }, 163{ 0x50534304, 0xffffffff, "UCB1400", patch_ucb1400, NULL },
163{ 0x53494c20, 0xffffffe0, "Si3036,8", mpatch_si3036, mpatch_si3036, AC97_MODEM_PATCH }, 164{ 0x53494c20, 0xffffffe0, "Si3036,8", mpatch_si3036, mpatch_si3036, AC97_MODEM_PATCH },
165{ 0x53544d02, 0xffffffff, "ST7597", NULL, NULL },
164{ 0x54524102, 0xffffffff, "TR28022", NULL, NULL }, 166{ 0x54524102, 0xffffffff, "TR28022", NULL, NULL },
165{ 0x54524103, 0xffffffff, "TR28023", NULL, NULL }, 167{ 0x54524103, 0xffffffff, "TR28023", NULL, NULL },
166{ 0x54524106, 0xffffffff, "TR28026", NULL, NULL }, 168{ 0x54524106, 0xffffffff, "TR28026", NULL, NULL },
@@ -213,6 +215,14 @@ static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg)
213{ 215{
214 /* filter some registers for buggy codecs */ 216 /* filter some registers for buggy codecs */
215 switch (ac97->id) { 217 switch (ac97->id) {
218 case AC97_ID_ST_AC97_ID4:
219 if (reg == 0x08)
220 return 0;
221 /* fall through */
222 case AC97_ID_ST7597:
223 if (reg == 0x22 || reg == 0x7a)
224 return 1;
225 /* fall through */
216 case AC97_ID_AK4540: 226 case AC97_ID_AK4540:
217 case AC97_ID_AK4542: 227 case AC97_ID_AK4542:
218 if (reg <= 0x1c || reg == 0x20 || reg == 0x26 || reg >= 0x7c) 228 if (reg <= 0x1c || reg == 0x20 || reg == 0x26 || reg >= 0x7c)
@@ -603,8 +613,8 @@ AC97_SINGLE("Tone Control - Treble", AC97_MASTER_TONE, 0, 15, 1)
603}; 613};
604 614
605static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = { 615static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = {
606AC97_SINGLE("PC Speaker Playback Switch", AC97_PC_BEEP, 15, 1, 1), 616AC97_SINGLE("Beep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
607AC97_SINGLE("PC Speaker Playback Volume", AC97_PC_BEEP, 1, 15, 1) 617AC97_SINGLE("Beep Playback Volume", AC97_PC_BEEP, 1, 15, 1)
608}; 618};
609 619
610static const struct snd_kcontrol_new snd_ac97_controls_mic_boost = 620static const struct snd_kcontrol_new snd_ac97_controls_mic_boost =
@@ -1393,7 +1403,7 @@ static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1393 } 1403 }
1394 } 1404 }
1395 1405
1396 /* build PC Speaker controls */ 1406 /* build Beep controls */
1397 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 1407 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1398 ((ac97->flags & AC97_HAS_PC_BEEP) || 1408 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1399 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) { 1409 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
@@ -2122,7 +2132,7 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2122 } 2132 }
2123 /* nothing should be in powerdown mode */ 2133 /* nothing should be in powerdown mode */
2124 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0); 2134 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
2125 end_time = jiffies + msecs_to_jiffies(120); 2135 end_time = jiffies + msecs_to_jiffies(5000);
2126 do { 2136 do {
2127 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f) 2137 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2128 goto __ready_ok; 2138 goto __ready_ok;
diff --git a/sound/pci/ac97/ac97_id.h b/sound/pci/ac97/ac97_id.h
index c129492c82b3..d603147c4a96 100644
--- a/sound/pci/ac97/ac97_id.h
+++ b/sound/pci/ac97/ac97_id.h
@@ -62,3 +62,5 @@
62#define AC97_ID_CM9761_78 0x434d4978 62#define AC97_ID_CM9761_78 0x434d4978
63#define AC97_ID_CM9761_82 0x434d4982 63#define AC97_ID_CM9761_82 0x434d4982
64#define AC97_ID_CM9761_83 0x434d4983 64#define AC97_ID_CM9761_83 0x434d4983
65#define AC97_ID_ST7597 0x53544d02
66#define AC97_ID_ST_AC97_ID4 0x53544d04
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 7337abdbe4e3..e68c98ef4041 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -544,25 +544,10 @@ static int patch_wolfson04(struct snd_ac97 * ac97)
544 return 0; 544 return 0;
545} 545}
546 546
547static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
548{
549 int err, i;
550 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
551 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
552 return err;
553 }
554 snd_ac97_write_cache(ac97, 0x72, 0x0808);
555 return 0;
556}
557
558static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
559 .build_specific = patch_wolfson_wm9705_specific,
560};
561
562static int patch_wolfson05(struct snd_ac97 * ac97) 547static int patch_wolfson05(struct snd_ac97 * ac97)
563{ 548{
564 /* WM9705, WM9710 */ 549 /* WM9705, WM9710 */
565 ac97->build_ops = &patch_wolfson_wm9705_ops; 550 ac97->build_ops = &patch_wolfson_wm9703_ops;
566#ifdef CONFIG_TOUCHSCREEN_WM9705 551#ifdef CONFIG_TOUCHSCREEN_WM9705
567 /* WM9705 touchscreen uses AUX and VIDEO for touch */ 552 /* WM9705 touchscreen uses AUX and VIDEO for touch */
568 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX; 553 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
@@ -800,12 +785,12 @@ AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
800AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 785AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
801AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 786AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
802 787
803AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 788AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
804AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 789AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
805AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1), 790AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
806AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1), 791AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
807AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1), 792AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
808AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1), 793AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
809 794
810AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 795AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
811AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 796AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
@@ -1867,11 +1852,14 @@ static unsigned int ad1981_jacks_blacklist[] = {
1867 0x10140523, /* Thinkpad R40 */ 1852 0x10140523, /* Thinkpad R40 */
1868 0x10140534, /* Thinkpad X31 */ 1853 0x10140534, /* Thinkpad X31 */
1869 0x10140537, /* Thinkpad T41p */ 1854 0x10140537, /* Thinkpad T41p */
1855 0x1014053e, /* Thinkpad R40e */
1870 0x10140554, /* Thinkpad T42p/R50p */ 1856 0x10140554, /* Thinkpad T42p/R50p */
1871 0x10140567, /* Thinkpad T43p 2668-G7U */ 1857 0x10140567, /* Thinkpad T43p 2668-G7U */
1872 0x10140581, /* Thinkpad X41-2527 */ 1858 0x10140581, /* Thinkpad X41-2527 */
1859 0x10280160, /* Dell Dimension 2400 */
1873 0x104380b0, /* Asus A7V8X-MX */ 1860 0x104380b0, /* Asus A7V8X-MX */
1874 0x11790241, /* Toshiba Satellite A-15 S127 */ 1861 0x11790241, /* Toshiba Satellite A-15 S127 */
1862 0x1179ff10, /* Toshiba P500 */
1875 0x144dc01a, /* Samsung NP-X20C004/SEG */ 1863 0x144dc01a, /* Samsung NP-X20C004/SEG */
1876 0 /* end */ 1864 0 /* end */
1877}; 1865};
diff --git a/sound/pci/ac97/ac97_proc.c b/sound/pci/ac97/ac97_proc.c
index 73b17d526c8b..6320bf084e47 100644
--- a/sound/pci/ac97/ac97_proc.c
+++ b/sound/pci/ac97/ac97_proc.c
@@ -22,7 +22,6 @@
22 * 22 *
23 */ 23 */
24 24
25#include <linux/slab.h>
26#include <linux/mutex.h> 25#include <linux/mutex.h>
27 26
28#include <sound/core.h> 27#include <sound/core.h>
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index 8f5098f92c37..4382d0fa6b9a 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -1048,7 +1048,7 @@ snd_ad1889_remove(struct pci_dev *pci)
1048 pci_set_drvdata(pci, NULL); 1048 pci_set_drvdata(pci, NULL);
1049} 1049}
1050 1050
1051static struct pci_device_id snd_ad1889_ids[] = { 1051static DEFINE_PCI_DEVICE_TABLE(snd_ad1889_ids) = {
1052 { PCI_DEVICE(PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS) }, 1052 { PCI_DEVICE(PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS) },
1053 { 0, }, 1053 { 0, },
1054}; 1054};
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index aaf4da68969c..5c6e322a48f0 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -275,7 +275,7 @@ struct snd_ali {
275#endif 275#endif
276}; 276};
277 277
278static struct pci_device_id snd_ali_ids[] = { 278static DEFINE_PCI_DEVICE_TABLE(snd_ali_ids) = {
279 {PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5451), 0, 0, 0}, 279 {PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5451), 0, 0, 0},
280 {0, } 280 {0, }
281}; 281};
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 3aa35af7ca91..d7653cb7ac60 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -145,7 +145,7 @@ struct snd_als300_substream_data {
145 int block_counter_register; 145 int block_counter_register;
146}; 146};
147 147
148static struct pci_device_id snd_als300_ids[] = { 148static DEFINE_PCI_DEVICE_TABLE(snd_als300_ids) = {
149 { 0x4005, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300 }, 149 { 0x4005, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300 },
150 { 0x4005, 0x0308, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300_PLUS }, 150 { 0x4005, 0x0308, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300_PLUS },
151 { 0, } 151 { 0, }
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index 3dbacde1a5af..6cf1de8042e8 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -68,7 +68,6 @@
68#include <asm/io.h> 68#include <asm/io.h>
69#include <linux/init.h> 69#include <linux/init.h>
70#include <linux/pci.h> 70#include <linux/pci.h>
71#include <linux/slab.h>
72#include <linux/gameport.h> 71#include <linux/gameport.h>
73#include <linux/moduleparam.h> 72#include <linux/moduleparam.h>
74#include <linux/dma-mapping.h> 73#include <linux/dma-mapping.h>
@@ -117,7 +116,7 @@ struct snd_card_als4000 {
117#endif 116#endif
118}; 117};
119 118
120static struct pci_device_id snd_als4000_ids[] = { 119static DEFINE_PCI_DEVICE_TABLE(snd_als4000_ids) = {
121 { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ALS4000 */ 120 { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ALS4000 */
122 { 0, } 121 { 0, }
123}; 122};
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index d6752dff2a44..49d572a7b235 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -286,7 +286,7 @@ struct atiixp {
286 286
287/* 287/*
288 */ 288 */
289static struct pci_device_id snd_atiixp_ids[] = { 289static DEFINE_PCI_DEVICE_TABLE(snd_atiixp_ids) = {
290 { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */ 290 { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */
291 { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */ 291 { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */
292 { PCI_VDEVICE(ATI, 0x4370), 0 }, /* SB400 */ 292 { PCI_VDEVICE(ATI, 0x4370), 0 }, /* SB400 */
@@ -297,6 +297,7 @@ static struct pci_device_id snd_atiixp_ids[] = {
297MODULE_DEVICE_TABLE(pci, snd_atiixp_ids); 297MODULE_DEVICE_TABLE(pci, snd_atiixp_ids);
298 298
299static struct snd_pci_quirk atiixp_quirks[] __devinitdata = { 299static struct snd_pci_quirk atiixp_quirks[] __devinitdata = {
300 SND_PCI_QUIRK(0x105b, 0x0c81, "Foxconn RC4107MA-RS2", 0),
300 SND_PCI_QUIRK(0x15bd, 0x3100, "DFI RS482", 0), 301 SND_PCI_QUIRK(0x15bd, 0x3100, "DFI RS482", 0),
301 { } /* terminator */ 302 { } /* terminator */
302}; 303};
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index e7e147bf8eb2..91d7036b6411 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -261,7 +261,7 @@ struct atiixp_modem {
261 261
262/* 262/*
263 */ 263 */
264static struct pci_device_id snd_atiixp_ids[] = { 264static DEFINE_PCI_DEVICE_TABLE(snd_atiixp_ids) = {
265 { PCI_VDEVICE(ATI, 0x434d), 0 }, /* SB200 */ 265 { PCI_VDEVICE(ATI, 0x434d), 0 }, /* SB200 */
266 { PCI_VDEVICE(ATI, 0x4378), 0 }, /* SB400 */ 266 { PCI_VDEVICE(ATI, 0x4378), 0 }, /* SB400 */
267 { 0, } 267 { 0, }
diff --git a/sound/pci/au88x0/au8810.c b/sound/pci/au88x0/au8810.c
index c0e8c6b295cb..aa51cc7771dd 100644
--- a/sound/pci/au88x0/au8810.c
+++ b/sound/pci/au88x0/au8810.c
@@ -1,6 +1,6 @@
1#include "au8810.h" 1#include "au8810.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static DEFINE_PCI_DEVICE_TABLE(snd_vortex_ids) = {
4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE), 1,}, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE), 1,},
5 {0,} 5 {0,}
6}; 6};
diff --git a/sound/pci/au88x0/au8820.c b/sound/pci/au88x0/au8820.c
index a6527330df58..2f321e7306cd 100644
--- a/sound/pci/au88x0/au8820.c
+++ b/sound/pci/au88x0/au8820.c
@@ -1,6 +1,6 @@
1#include "au8820.h" 1#include "au8820.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static DEFINE_PCI_DEVICE_TABLE(snd_vortex_ids) = {
4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_1), 0,}, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_1), 0,},
5 {0,} 5 {0,}
6}; 6};
diff --git a/sound/pci/au88x0/au8830.c b/sound/pci/au88x0/au8830.c
index 6c702ad4352a..279b78f06d22 100644
--- a/sound/pci/au88x0/au8830.c
+++ b/sound/pci/au88x0/au8830.c
@@ -1,6 +1,6 @@
1#include "au8830.h" 1#include "au8830.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static DEFINE_PCI_DEVICE_TABLE(snd_vortex_ids) = {
4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_2), 0,}, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_2), 0,},
5 {0,} 5 {0,}
6}; 6};
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
index 4d34bb0d99d3..67921f93a41e 100644
--- a/sound/pci/aw2/aw2-alsa.c
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -164,7 +164,7 @@ MODULE_PARM_DESC(id, "ID string for the Audiowerk2 soundcard.");
164module_param_array(enable, bool, NULL, 0444); 164module_param_array(enable, bool, NULL, 0444);
165MODULE_PARM_DESC(enable, "Enable Audiowerk2 soundcard."); 165MODULE_PARM_DESC(enable, "Enable Audiowerk2 soundcard.");
166 166
167static struct pci_device_id snd_aw2_ids[] = { 167static DEFINE_PCI_DEVICE_TABLE(snd_aw2_ids) = {
168 {PCI_VENDOR_ID_SAA7146, PCI_DEVICE_ID_SAA7146, 0, 0, 168 {PCI_VENDOR_ID_SAA7146, PCI_DEVICE_ID_SAA7146, 0, 0,
169 0, 0, 0}, 169 0, 0, 0},
170 {0} 170 {0}
diff --git a/sound/pci/aw2/aw2-saa7146.c b/sound/pci/aw2/aw2-saa7146.c
index 296123ab74f7..8afd8b5d1ac7 100644
--- a/sound/pci/aw2/aw2-saa7146.c
+++ b/sound/pci/aw2/aw2-saa7146.c
@@ -25,7 +25,6 @@
25 25
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h> 28#include <linux/interrupt.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <asm/system.h> 30#include <asm/system.h>
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 8451a0169f32..4679ed83a43b 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -350,7 +350,7 @@ struct snd_azf3328 {
350#endif 350#endif
351}; 351};
352 352
353static const struct pci_device_id snd_azf3328_ids[] = { 353static DEFINE_PCI_DEVICE_TABLE(snd_azf3328_ids) = {
354 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */ 354 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
355 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */ 355 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
356 { 0, } 356 { 0, }
@@ -830,8 +830,8 @@ static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
830 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0), 830 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
831 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1), 831 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
832 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1), 832 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
833 AZF3328_MIXER_SWITCH("PC Speaker Playback Switch", IDX_MIXER_PCBEEP, 15, 1), 833 AZF3328_MIXER_SWITCH("Beep Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
834 AZF3328_MIXER_VOL_SPECIAL("PC Speaker Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1), 834 AZF3328_MIXER_VOL_SPECIAL("Beep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
835 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1), 835 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
836 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1), 836 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
837 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1), 837 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 4e2b925a94cc..37e1b5df5ab8 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -795,7 +795,7 @@ fail:
795 .driver_data = SND_BT87X_BOARD_ ## id } 795 .driver_data = SND_BT87X_BOARD_ ## id }
796/* driver_data is the card id for that device */ 796/* driver_data is the card id for that device */
797 797
798static struct pci_device_id snd_bt87x_ids[] = { 798static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_ids) = {
799 /* Hauppauge WinTV series */ 799 /* Hauppauge WinTV series */
800 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0x13eb, GENERIC), 800 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0x13eb, GENERIC),
801 /* Hauppauge WinTV series */ 801 /* Hauppauge WinTV series */
@@ -964,7 +964,7 @@ static void __devexit snd_bt87x_remove(struct pci_dev *pci)
964 964
965/* default entries for all Bt87x cards - it's not exported */ 965/* default entries for all Bt87x cards - it's not exported */
966/* driver_data is set to 0 to call detection */ 966/* driver_data is set to 0 to call detection */
967static struct pci_device_id snd_bt87x_default_ids[] __devinitdata = { 967static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_default_ids) = {
968 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN), 968 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN),
969 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN), 969 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN),
970 { } 970 { }
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 15e4138bce17..0a3d3d6e77b4 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -1875,7 +1875,7 @@ static int snd_ca0106_resume(struct pci_dev *pci)
1875#endif 1875#endif
1876 1876
1877// PCI IDs 1877// PCI IDs
1878static struct pci_device_id snd_ca0106_ids[] = { 1878static DEFINE_PCI_DEVICE_TABLE(snd_ca0106_ids) = {
1879 { PCI_VDEVICE(CREATIVE, 0x0007), 0 }, /* Audigy LS or Live 24bit */ 1879 { PCI_VDEVICE(CREATIVE, 0x0007), 0 }, /* Audigy LS or Live 24bit */
1880 { 0, } 1880 { 0, }
1881}; 1881};
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index c8c6f437f5b3..85fd315d9999 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -63,7 +63,6 @@
63#include <linux/delay.h> 63#include <linux/delay.h>
64#include <linux/init.h> 64#include <linux/init.h>
65#include <linux/interrupt.h> 65#include <linux/interrupt.h>
66#include <linux/slab.h>
67#include <linux/moduleparam.h> 66#include <linux/moduleparam.h>
68#include <sound/core.h> 67#include <sound/core.h>
69#include <sound/initval.h> 68#include <sound/initval.h>
@@ -792,8 +791,8 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
792 "Phone Playback Volume", 791 "Phone Playback Volume",
793 "Video Playback Switch", 792 "Video Playback Switch",
794 "Video Playback Volume", 793 "Video Playback Volume",
795 "PC Speaker Playback Switch", 794 "Beep Playback Switch",
796 "PC Speaker Playback Volume", 795 "Beep Playback Volume",
797 "Mono Output Select", 796 "Mono Output Select",
798 "Capture Source", 797 "Capture Source",
799 "Capture Switch", 798 "Capture Switch",
diff --git a/sound/pci/ca0106/ca0106_proc.c b/sound/pci/ca0106/ca0106_proc.c
index c62b7d10ec61..ba96428c9f4c 100644
--- a/sound/pci/ca0106/ca0106_proc.c
+++ b/sound/pci/ca0106/ca0106_proc.c
@@ -63,7 +63,6 @@
63#include <linux/delay.h> 63#include <linux/delay.h>
64#include <linux/init.h> 64#include <linux/init.h>
65#include <linux/interrupt.h> 65#include <linux/interrupt.h>
66#include <linux/slab.h>
67#include <linux/moduleparam.h> 66#include <linux/moduleparam.h>
68#include <sound/core.h> 67#include <sound/core.h>
69#include <sound/initval.h> 68#include <sound/initval.h>
@@ -233,7 +232,7 @@ static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer *buffer, u32 val
233 snd_iprintf(buffer, "user-defined\n"); 232 snd_iprintf(buffer, "user-defined\n");
234 break; 233 break;
235 default: 234 default:
236 snd_iprintf(buffer, "unkown\n"); 235 snd_iprintf(buffer, "unknown\n");
237 break; 236 break;
238 } 237 }
239 snd_iprintf(buffer, "Sample Bits: "); 238 snd_iprintf(buffer, "Sample Bits: ");
@@ -304,7 +303,7 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
304 while (!snd_info_get_line(buffer, line, sizeof(line))) { 303 while (!snd_info_get_line(buffer, line, sizeof(line))) {
305 if (sscanf(line, "%x %x", &reg, &val) != 2) 304 if (sscanf(line, "%x %x", &reg, &val) != 2)
306 continue; 305 continue;
307 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) { 306 if (reg < 0x40 && val <= 0xffffffff) {
308 spin_lock_irqsave(&emu->emu_lock, flags); 307 spin_lock_irqsave(&emu->emu_lock, flags);
309 outl(val, emu->port + (reg & 0xfffffffc)); 308 outl(val, emu->port + (reg & 0xfffffffc));
310 spin_unlock_irqrestore(&emu->emu_lock, flags); 309 spin_unlock_irqrestore(&emu->emu_lock, flags);
@@ -405,7 +404,7 @@ static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,
405 while (!snd_info_get_line(buffer, line, sizeof(line))) { 404 while (!snd_info_get_line(buffer, line, sizeof(line))) {
406 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 405 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
407 continue; 406 continue;
408 if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) ) 407 if (reg < 0x80 && val <= 0xffffffff && channel_id <= 3)
409 snd_ca0106_ptr_write(emu, reg, channel_id, val); 408 snd_ca0106_ptr_write(emu, reg, channel_id, val);
410 } 409 }
411} 410}
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index ddcd4a9fd7e6..329968edca9b 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -941,13 +941,21 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci
941 struct snd_pcm_substream *substream) 941 struct snd_pcm_substream *substream)
942{ 942{
943 size_t ptr; 943 size_t ptr;
944 unsigned int reg; 944 unsigned int reg, rem, tries;
945
945 if (!rec->running) 946 if (!rec->running)
946 return 0; 947 return 0;
947#if 1 // this seems better.. 948#if 1 // this seems better..
948 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2; 949 reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
949 ptr = rec->dma_size - (snd_cmipci_read_w(cm, reg) + 1); 950 for (tries = 0; tries < 3; tries++) {
950 ptr >>= rec->shift; 951 rem = snd_cmipci_read_w(cm, reg);
952 if (rem < rec->dma_size)
953 goto ok;
954 }
955 printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem);
956 return SNDRV_PCM_POS_XRUN;
957ok:
958 ptr = (rec->dma_size - (rem + 1)) >> rec->shift;
951#else 959#else
952 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; 960 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1;
953 ptr = snd_cmipci_read(cm, reg) - rec->offset; 961 ptr = snd_cmipci_read(cm, reg) - rec->offset;
@@ -2302,7 +2310,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
2302 CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31), 2310 CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
2303 CMIPCI_SB_SW_MONO("Mic Playback Switch", 0), 2311 CMIPCI_SB_SW_MONO("Mic Playback Switch", 0),
2304 CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0), 2312 CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0),
2305 CMIPCI_SB_VOL_MONO("PC Speaker Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3), 2313 CMIPCI_SB_VOL_MONO("Beep Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
2306 CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15), 2314 CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15),
2307 CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0), 2315 CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0),
2308 CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0), 2316 CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0),
@@ -2310,7 +2318,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
2310 CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7), 2318 CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7),
2311 CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7), 2319 CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7),
2312 CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0), 2320 CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0),
2313 CMIPCI_DOUBLE("PC Speaker Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0), 2321 CMIPCI_DOUBLE("Beep Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0),
2314 CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0), 2322 CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0),
2315}; 2323};
2316 2324
@@ -2796,7 +2804,7 @@ static inline void snd_cmipci_proc_init(struct cmipci *cm) {}
2796#endif 2804#endif
2797 2805
2798 2806
2799static struct pci_device_id snd_cmipci_ids[] = { 2807static DEFINE_PCI_DEVICE_TABLE(snd_cmipci_ids) = {
2800 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0}, 2808 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0},
2801 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0}, 2809 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0},
2802 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738), 0}, 2810 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
@@ -3018,7 +3026,7 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
3018 int integrated_midi = 0; 3026 int integrated_midi = 0;
3019 char modelstr[16]; 3027 char modelstr[16];
3020 int pcm_index, pcm_spdif_index; 3028 int pcm_index, pcm_spdif_index;
3021 static struct pci_device_id intel_82437vx[] = { 3029 static DEFINE_PCI_DEVICE_TABLE(intel_82437vx) = {
3022 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) }, 3030 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
3023 { }, 3031 { },
3024 }; 3032 };
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index e2e0359bb056..9edc65059e3e 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -494,7 +494,7 @@ struct cs4281 {
494 494
495static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id); 495static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id);
496 496
497static struct pci_device_id snd_cs4281_ids[] = { 497static DEFINE_PCI_DEVICE_TABLE(snd_cs4281_ids) = {
498 { PCI_VDEVICE(CIRRUS, 0x6005), 0, }, /* CS4281 */ 498 { PCI_VDEVICE(CIRRUS, 0x6005), 0, }, /* CS4281 */
499 { 0, } 499 { 0, }
500}; 500};
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index 033aec430117..767fa7f06cd0 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -64,7 +64,7 @@ MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
64module_param_array(mmap_valid, bool, NULL, 0444); 64module_param_array(mmap_valid, bool, NULL, 0444);
65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap."); 65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
66 66
67static struct pci_device_id snd_cs46xx_ids[] = { 67static DEFINE_PCI_DEVICE_TABLE(snd_cs46xx_ids) = {
68 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */ 68 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
69 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */ 69 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
70 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */ 70 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 1be96ead4244..3f99a5e8528c 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -2238,11 +2238,11 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97)
2238 2238
2239 /* set the desired CODEC mode */ 2239 /* set the desired CODEC mode */
2240 if (ac97->num == CS46XX_PRIMARY_CODEC_INDEX) { 2240 if (ac97->num == CS46XX_PRIMARY_CODEC_INDEX) {
2241 snd_printdd("cs46xx: CODOEC1 mode %04x\n",0x0); 2241 snd_printdd("cs46xx: CODEC1 mode %04x\n", 0x0);
2242 snd_cs46xx_ac97_write(ac97,AC97_CSR_ACMODE,0x0); 2242 snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x0);
2243 } else if (ac97->num == CS46XX_SECONDARY_CODEC_INDEX) { 2243 } else if (ac97->num == CS46XX_SECONDARY_CODEC_INDEX) {
2244 snd_printdd("cs46xx: CODOEC2 mode %04x\n",0x3); 2244 snd_printdd("cs46xx: CODEC2 mode %04x\n", 0x3);
2245 snd_cs46xx_ac97_write(ac97,AC97_CSR_ACMODE,0x3); 2245 snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x3);
2246 } else { 2246 } else {
2247 snd_BUG(); /* should never happen ... */ 2247 snd_BUG(); /* should never happen ... */
2248 } 2248 }
@@ -2266,7 +2266,7 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97)
2266 return; 2266 return;
2267 2267
2268 /* test if we can write to the record gain volume register */ 2268 /* test if we can write to the record gain volume register */
2269 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05); 2269 snd_ac97_write(ac97, AC97_REC_GAIN, 0x8a05);
2270 if ((err = snd_ac97_read(ac97, AC97_REC_GAIN)) == 0x8a05) 2270 if ((err = snd_ac97_read(ac97, AC97_REC_GAIN)) == 0x8a05)
2271 return; 2271 return;
2272 2272
@@ -3597,7 +3597,7 @@ static struct cs_card_type __devinitdata cards[] = {
3597#ifdef CONFIG_PM 3597#ifdef CONFIG_PM
3598static unsigned int saved_regs[] = { 3598static unsigned int saved_regs[] = {
3599 BA0_ACOSV, 3599 BA0_ACOSV,
3600 BA0_ASER_FADDR, 3600 /*BA0_ASER_FADDR,*/
3601 BA0_ASER_MASTER, 3601 BA0_ASER_MASTER,
3602 BA1_PVOL, 3602 BA1_PVOL,
3603 BA1_CVOL, 3603 BA1_CVOL,
@@ -3644,6 +3644,7 @@ int snd_cs46xx_resume(struct pci_dev *pci)
3644#ifdef CONFIG_SND_CS46XX_NEW_DSP 3644#ifdef CONFIG_SND_CS46XX_NEW_DSP
3645 int i; 3645 int i;
3646#endif 3646#endif
3647 unsigned int tmp;
3647 3648
3648 pci_set_power_state(pci, PCI_D0); 3649 pci_set_power_state(pci, PCI_D0);
3649 pci_restore_state(pci); 3650 pci_restore_state(pci);
@@ -3685,6 +3686,15 @@ int snd_cs46xx_resume(struct pci_dev *pci)
3685 snd_ac97_resume(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]); 3686 snd_ac97_resume(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]);
3686 snd_ac97_resume(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]); 3687 snd_ac97_resume(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]);
3687 3688
3689 /*
3690 * Stop capture DMA.
3691 */
3692 tmp = snd_cs46xx_peek(chip, BA1_CCTL);
3693 chip->capt.ctl = tmp & 0x0000ffff;
3694 snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000);
3695
3696 mdelay(5);
3697
3688 /* reset playback/capture */ 3698 /* reset playback/capture */
3689 snd_cs46xx_set_play_sample_rate(chip, 8000); 3699 snd_cs46xx_set_play_sample_rate(chip, 8000);
3690 snd_cs46xx_set_capture_sample_rate(chip, 8000); 3700 snd_cs46xx_set_capture_sample_rate(chip, 8000);
diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
index f4f0c8f5dad7..3e5ca8fb519f 100644
--- a/sound/pci/cs46xx/dsp_spos.c
+++ b/sound/pci/cs46xx/dsp_spos.c
@@ -298,6 +298,9 @@ void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip)
298 if (ins->scbs[i].deleted) continue; 298 if (ins->scbs[i].deleted) continue;
299 299
300 cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); 300 cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
301#ifdef CONFIG_PM
302 kfree(ins->scbs[i].data);
303#endif
301 } 304 }
302 305
303 kfree(ins->code.data); 306 kfree(ins->code.data);
@@ -974,13 +977,11 @@ static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * nam
974 977
975 index = find_free_scb_index (ins); 978 index = find_free_scb_index (ins);
976 979
980 memset(&ins->scbs[index], 0, sizeof(ins->scbs[index]));
977 strcpy(ins->scbs[index].scb_name, name); 981 strcpy(ins->scbs[index].scb_name, name);
978 ins->scbs[index].address = dest; 982 ins->scbs[index].address = dest;
979 ins->scbs[index].index = index; 983 ins->scbs[index].index = index;
980 ins->scbs[index].proc_info = NULL;
981 ins->scbs[index].ref_count = 1; 984 ins->scbs[index].ref_count = 1;
982 ins->scbs[index].deleted = 0;
983 spin_lock_init(&ins->scbs[index].lock);
984 985
985 desc = (ins->scbs + index); 986 desc = (ins->scbs + index);
986 ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER); 987 ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER);
@@ -1022,17 +1023,29 @@ _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
1022 return desc; 1023 return desc;
1023} 1024}
1024 1025
1026#define SCB_BYTES (0x10 * 4)
1027
1025struct dsp_scb_descriptor * 1028struct dsp_scb_descriptor *
1026cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest) 1029cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest)
1027{ 1030{
1028 struct dsp_scb_descriptor * desc; 1031 struct dsp_scb_descriptor * desc;
1029 1032
1033#ifdef CONFIG_PM
1034 /* copy the data for resume */
1035 scb_data = kmemdup(scb_data, SCB_BYTES, GFP_KERNEL);
1036 if (!scb_data)
1037 return NULL;
1038#endif
1039
1030 desc = _map_scb (chip,name,dest); 1040 desc = _map_scb (chip,name,dest);
1031 if (desc) { 1041 if (desc) {
1032 desc->data = scb_data; 1042 desc->data = scb_data;
1033 _dsp_create_scb(chip,scb_data,dest); 1043 _dsp_create_scb(chip,scb_data,dest);
1034 } else { 1044 } else {
1035 snd_printk(KERN_ERR "dsp_spos: failed to map SCB\n"); 1045 snd_printk(KERN_ERR "dsp_spos: failed to map SCB\n");
1046#ifdef CONFIG_PM
1047 kfree(scb_data);
1048#endif
1036 } 1049 }
1037 1050
1038 return desc; 1051 return desc;
@@ -1988,7 +2001,28 @@ int cs46xx_dsp_resume(struct snd_cs46xx * chip)
1988 continue; 2001 continue;
1989 _dsp_create_scb(chip, s->data, s->address); 2002 _dsp_create_scb(chip, s->data, s->address);
1990 } 2003 }
1991 2004 for (i = 0; i < ins->nscb; i++) {
2005 struct dsp_scb_descriptor *s = &ins->scbs[i];
2006 if (s->deleted)
2007 continue;
2008 if (s->updated)
2009 cs46xx_dsp_spos_update_scb(chip, s);
2010 if (s->volume_set)
2011 cs46xx_dsp_scb_set_volume(chip, s,
2012 s->volume[0], s->volume[1]);
2013 }
2014 if (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) {
2015 cs46xx_dsp_enable_spdif_hw(chip);
2016 snd_cs46xx_poke(chip, (ins->ref_snoop_scb->address + 2) << 2,
2017 (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10);
2018 if (ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN)
2019 cs46xx_poke_via_dsp(chip, SP_SPDOUT_CSUV,
2020 ins->spdif_csuv_stream);
2021 }
2022 if (chip->dsp_spos_instance->spdif_status_in) {
2023 cs46xx_poke_via_dsp(chip, SP_ASER_COUNTDOWN, 0x80000005);
2024 cs46xx_poke_via_dsp(chip, SP_SPDIN_CONTROL, 0x800003ff);
2025 }
1992 return 0; 2026 return 0;
1993} 2027}
1994#endif 2028#endif
diff --git a/sound/pci/cs46xx/dsp_spos.h b/sound/pci/cs46xx/dsp_spos.h
index f9e169d33c03..ca47a8114c7f 100644
--- a/sound/pci/cs46xx/dsp_spos.h
+++ b/sound/pci/cs46xx/dsp_spos.h
@@ -212,6 +212,7 @@ static inline void cs46xx_dsp_spos_update_scb (struct snd_cs46xx * chip,
212 (scb->address + SCBsubListPtr) << 2, 212 (scb->address + SCBsubListPtr) << 2,
213 (scb->sub_list_ptr->address << 0x10) | 213 (scb->sub_list_ptr->address << 0x10) |
214 (scb->next_scb_ptr->address)); 214 (scb->next_scb_ptr->address));
215 scb->updated = 1;
215} 216}
216 217
217static inline void cs46xx_dsp_scb_set_volume (struct snd_cs46xx * chip, 218static inline void cs46xx_dsp_scb_set_volume (struct snd_cs46xx * chip,
@@ -222,6 +223,9 @@ static inline void cs46xx_dsp_scb_set_volume (struct snd_cs46xx * chip,
222 223
223 snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl) << 2, val); 224 snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl) << 2, val);
224 snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl + 1) << 2, val); 225 snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl + 1) << 2, val);
226 scb->volume_set = 1;
227 scb->volume[0] = left;
228 scb->volume[1] = right;
225} 229}
226#endif /* __DSP_SPOS_H__ */ 230#endif /* __DSP_SPOS_H__ */
227#endif /* CONFIG_SND_CS46XX_NEW_DSP */ 231#endif /* CONFIG_SND_CS46XX_NEW_DSP */
diff --git a/sound/pci/cs46xx/dsp_spos_scb_lib.c b/sound/pci/cs46xx/dsp_spos_scb_lib.c
index dd7c41b037b4..00b148a10239 100644
--- a/sound/pci/cs46xx/dsp_spos_scb_lib.c
+++ b/sound/pci/cs46xx/dsp_spos_scb_lib.c
@@ -115,7 +115,6 @@ static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry,
115static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb) 115static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
116{ 116{
117 struct dsp_spos_instance * ins = chip->dsp_spos_instance; 117 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
118 unsigned long flags;
119 118
120 if ( scb->parent_scb_ptr ) { 119 if ( scb->parent_scb_ptr ) {
121 /* unlink parent SCB */ 120 /* unlink parent SCB */
@@ -153,8 +152,6 @@ static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor
153 scb->next_scb_ptr = ins->the_null_scb; 152 scb->next_scb_ptr = ins->the_null_scb;
154 } 153 }
155 154
156 spin_lock_irqsave(&chip->reg_lock, flags);
157
158 /* update parent first entry in DSP RAM */ 155 /* update parent first entry in DSP RAM */
159 cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr); 156 cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr);
160 157
@@ -162,7 +159,6 @@ static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor
162 cs46xx_dsp_spos_update_scb(chip,scb); 159 cs46xx_dsp_spos_update_scb(chip,scb);
163 160
164 scb->parent_scb_ptr = NULL; 161 scb->parent_scb_ptr = NULL;
165 spin_unlock_irqrestore(&chip->reg_lock, flags);
166 } 162 }
167} 163}
168 164
@@ -197,9 +193,9 @@ void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor *
197 goto _end; 193 goto _end;
198#endif 194#endif
199 195
200 spin_lock_irqsave(&scb->lock, flags); 196 spin_lock_irqsave(&chip->reg_lock, flags);
201 _dsp_unlink_scb (chip,scb); 197 _dsp_unlink_scb (chip,scb);
202 spin_unlock_irqrestore(&scb->lock, flags); 198 spin_unlock_irqrestore(&chip->reg_lock, flags);
203 199
204 cs46xx_dsp_proc_free_scb_desc(scb); 200 cs46xx_dsp_proc_free_scb_desc(scb);
205 if (snd_BUG_ON(!scb->scb_symbol)) 201 if (snd_BUG_ON(!scb->scb_symbol))
@@ -207,6 +203,10 @@ void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor *
207 remove_symbol (chip,scb->scb_symbol); 203 remove_symbol (chip,scb->scb_symbol);
208 204
209 ins->scbs[scb->index].deleted = 1; 205 ins->scbs[scb->index].deleted = 1;
206#ifdef CONFIG_PM
207 kfree(ins->scbs[scb->index].data);
208 ins->scbs[scb->index].data = NULL;
209#endif
210 210
211 if (scb->index < ins->scb_highest_frag_index) 211 if (scb->index < ins->scb_highest_frag_index)
212 ins->scb_highest_frag_index = scb->index; 212 ins->scb_highest_frag_index = scb->index;
@@ -1508,20 +1508,17 @@ int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
1508 chip->dsp_spos_instance->npcm_channels <= 0)) 1508 chip->dsp_spos_instance->npcm_channels <= 0))
1509 return -EIO; 1509 return -EIO;
1510 1510
1511 spin_lock(&pcm_channel->src_scb->lock); 1511 spin_lock_irqsave(&chip->reg_lock, flags);
1512
1513 if (pcm_channel->unlinked) { 1512 if (pcm_channel->unlinked) {
1514 spin_unlock(&pcm_channel->src_scb->lock); 1513 spin_unlock_irqrestore(&chip->reg_lock, flags);
1515 return -EIO; 1514 return -EIO;
1516 } 1515 }
1517 1516
1518 spin_lock_irqsave(&chip->reg_lock, flags);
1519 pcm_channel->unlinked = 1; 1517 pcm_channel->unlinked = 1;
1520 spin_unlock_irqrestore(&chip->reg_lock, flags);
1521 1518
1522 _dsp_unlink_scb (chip,pcm_channel->pcm_reader_scb); 1519 _dsp_unlink_scb (chip,pcm_channel->pcm_reader_scb);
1520 spin_unlock_irqrestore(&chip->reg_lock, flags);
1523 1521
1524 spin_unlock(&pcm_channel->src_scb->lock);
1525 return 0; 1522 return 0;
1526} 1523}
1527 1524
@@ -1533,10 +1530,10 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
1533 struct dsp_scb_descriptor * src_scb = pcm_channel->src_scb; 1530 struct dsp_scb_descriptor * src_scb = pcm_channel->src_scb;
1534 unsigned long flags; 1531 unsigned long flags;
1535 1532
1536 spin_lock(&pcm_channel->src_scb->lock); 1533 spin_lock_irqsave(&chip->reg_lock, flags);
1537 1534
1538 if (pcm_channel->unlinked == 0) { 1535 if (pcm_channel->unlinked == 0) {
1539 spin_unlock(&pcm_channel->src_scb->lock); 1536 spin_unlock_irqrestore(&chip->reg_lock, flags);
1540 return -EIO; 1537 return -EIO;
1541 } 1538 }
1542 1539
@@ -1552,8 +1549,6 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
1552 snd_BUG_ON(pcm_channel->pcm_reader_scb->parent_scb_ptr); 1549 snd_BUG_ON(pcm_channel->pcm_reader_scb->parent_scb_ptr);
1553 pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb; 1550 pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb;
1554 1551
1555 spin_lock_irqsave(&chip->reg_lock, flags);
1556
1557 /* update SCB entry in DSP RAM */ 1552 /* update SCB entry in DSP RAM */
1558 cs46xx_dsp_spos_update_scb(chip,pcm_channel->pcm_reader_scb); 1553 cs46xx_dsp_spos_update_scb(chip,pcm_channel->pcm_reader_scb);
1559 1554
@@ -1562,8 +1557,6 @@ int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
1562 1557
1563 pcm_channel->unlinked = 0; 1558 pcm_channel->unlinked = 0;
1564 spin_unlock_irqrestore(&chip->reg_lock, flags); 1559 spin_unlock_irqrestore(&chip->reg_lock, flags);
1565
1566 spin_unlock(&pcm_channel->src_scb->lock);
1567 return 0; 1560 return 0;
1568} 1561}
1569 1562
@@ -1596,13 +1589,17 @@ cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * s
1596 1589
1597int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src) 1590int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
1598{ 1591{
1592 unsigned long flags;
1593
1599 if (snd_BUG_ON(!src->parent_scb_ptr)) 1594 if (snd_BUG_ON(!src->parent_scb_ptr))
1600 return -EINVAL; 1595 return -EINVAL;
1601 1596
1602 /* mute SCB */ 1597 /* mute SCB */
1603 cs46xx_dsp_scb_set_volume (chip,src,0,0); 1598 cs46xx_dsp_scb_set_volume (chip,src,0,0);
1604 1599
1600 spin_lock_irqsave(&chip->reg_lock, flags);
1605 _dsp_unlink_scb (chip,src); 1601 _dsp_unlink_scb (chip,src);
1602 spin_unlock_irqrestore(&chip->reg_lock, flags);
1606 1603
1607 return 0; 1604 return 0;
1608} 1605}
diff --git a/sound/pci/cs46xx/imgs/cwcdma.asp b/sound/pci/cs46xx/imgs/cwcdma.asp
index 09d24c76f034..a65e1193c89a 100644
--- a/sound/pci/cs46xx/imgs/cwcdma.asp
+++ b/sound/pci/cs46xx/imgs/cwcdma.asp
@@ -26,10 +26,11 @@
26// 26//
27// 27//
28// The purpose of this code is very simple: make it possible to tranfser 28// The purpose of this code is very simple: make it possible to tranfser
29// the samples 'as they are' with no alteration from a PCMreader SCB (DMA from host) 29// the samples 'as they are' with no alteration from a PCMreader
30// to any other SCB. This is useful for AC3 throug SPDIF. SRC (source rate converters) 30// SCB (DMA from host) to any other SCB. This is useful for AC3 through SPDIF.
31// task always alters the samples in some how, however it's from 48khz -> 48khz. The 31// SRC (source rate converters) task always alters the samples in somehow,
32// alterations are not audible, but AC3 wont work. 32// however it's from 48khz -> 48khz.
33// The alterations are not audible, but AC3 wont work.
33// 34//
34// ... 35// ...
35// | 36// |
diff --git a/sound/pci/cs5530.c b/sound/pci/cs5530.c
index dc464321d0f3..bc07e275d4d4 100644
--- a/sound/pci/cs5530.c
+++ b/sound/pci/cs5530.c
@@ -39,6 +39,7 @@
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/moduleparam.h> 40#include <linux/moduleparam.h>
41#include <linux/pci.h> 41#include <linux/pci.h>
42#include <linux/slab.h>
42#include <sound/core.h> 43#include <sound/core.h>
43#include <sound/sb.h> 44#include <sound/sb.h>
44#include <sound/initval.h> 45#include <sound/initval.h>
@@ -58,7 +59,7 @@ struct snd_cs5530 {
58 unsigned long pci_base; 59 unsigned long pci_base;
59}; 60};
60 61
61static struct pci_device_id snd_cs5530_ids[] = { 62static DEFINE_PCI_DEVICE_TABLE(snd_cs5530_ids) = {
62 {PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID, 63 {PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID,
63 PCI_ANY_ID, 0, 0}, 64 PCI_ANY_ID, 0, 0},
64 {0,} 65 {0,}
diff --git a/sound/pci/cs5535audio/Makefile b/sound/pci/cs5535audio/Makefile
index fda7a94c992f..ccc642269b9e 100644
--- a/sound/pci/cs5535audio/Makefile
+++ b/sound/pci/cs5535audio/Makefile
@@ -4,9 +4,7 @@
4 4
5snd-cs5535audio-y := cs5535audio.o cs5535audio_pcm.o 5snd-cs5535audio-y := cs5535audio.o cs5535audio_pcm.o
6snd-cs5535audio-$(CONFIG_PM) += cs5535audio_pm.o 6snd-cs5535audio-$(CONFIG_PM) += cs5535audio_pm.o
7ifdef CONFIG_MGEODE_LX
8snd-cs5535audio-$(CONFIG_OLPC) += cs5535audio_olpc.o 7snd-cs5535audio-$(CONFIG_OLPC) += cs5535audio_olpc.o
9endif
10 8
11# Toplevel Module Dependency 9# Toplevel Module Dependency
12obj-$(CONFIG_SND_CS5535AUDIO) += snd-cs5535audio.o 10obj-$(CONFIG_SND_CS5535AUDIO) += snd-cs5535audio.o
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index 05f56e04849b..afb803708416 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -66,7 +66,7 @@ MODULE_PARM_DESC(id, "ID string for " DRIVER_NAME);
66module_param_array(enable, bool, NULL, 0444); 66module_param_array(enable, bool, NULL, 0444);
67MODULE_PARM_DESC(enable, "Enable " DRIVER_NAME); 67MODULE_PARM_DESC(enable, "Enable " DRIVER_NAME);
68 68
69static struct pci_device_id snd_cs5535audio_ids[] = { 69static DEFINE_PCI_DEVICE_TABLE(snd_cs5535audio_ids) = {
70 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_AUDIO) }, 70 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_AUDIO) },
71 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_AUDIO) }, 71 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_AUDIO) },
72 {} 72 {}
@@ -389,6 +389,7 @@ probefail_out:
389 389
390static void __devexit snd_cs5535audio_remove(struct pci_dev *pci) 390static void __devexit snd_cs5535audio_remove(struct pci_dev *pci)
391{ 391{
392 olpc_quirks_cleanup();
392 snd_card_free(pci_get_drvdata(pci)); 393 snd_card_free(pci_get_drvdata(pci));
393 pci_set_drvdata(pci, NULL); 394 pci_set_drvdata(pci, NULL);
394} 395}
diff --git a/sound/pci/cs5535audio/cs5535audio.h b/sound/pci/cs5535audio/cs5535audio.h
index 7a298ac662e3..51966d782a3c 100644
--- a/sound/pci/cs5535audio/cs5535audio.h
+++ b/sound/pci/cs5535audio/cs5535audio.h
@@ -99,10 +99,11 @@ int snd_cs5535audio_suspend(struct pci_dev *pci, pm_message_t state);
99int snd_cs5535audio_resume(struct pci_dev *pci); 99int snd_cs5535audio_resume(struct pci_dev *pci);
100#endif 100#endif
101 101
102#if defined(CONFIG_OLPC) && defined(CONFIG_MGEODE_LX) 102#ifdef CONFIG_OLPC
103void __devinit olpc_prequirks(struct snd_card *card, 103void __devinit olpc_prequirks(struct snd_card *card,
104 struct snd_ac97_template *ac97); 104 struct snd_ac97_template *ac97);
105int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97); 105int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97);
106void __devexit olpc_quirks_cleanup(void);
106void olpc_analog_input(struct snd_ac97 *ac97, int on); 107void olpc_analog_input(struct snd_ac97 *ac97, int on);
107void olpc_mic_bias(struct snd_ac97 *ac97, int on); 108void olpc_mic_bias(struct snd_ac97 *ac97, int on);
108 109
@@ -128,6 +129,7 @@ static inline int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
128{ 129{
129 return 0; 130 return 0;
130} 131}
132static inline void olpc_quirks_cleanup(void) { }
131static inline void olpc_analog_input(struct snd_ac97 *ac97, int on) { } 133static inline void olpc_analog_input(struct snd_ac97 *ac97, int on) { }
132static inline void olpc_mic_bias(struct snd_ac97 *ac97, int on) { } 134static inline void olpc_mic_bias(struct snd_ac97 *ac97, int on) { }
133static inline void olpc_capture_open(struct snd_ac97 *ac97) { } 135static inline void olpc_capture_open(struct snd_ac97 *ac97) { }
diff --git a/sound/pci/cs5535audio/cs5535audio_olpc.c b/sound/pci/cs5535audio/cs5535audio_olpc.c
index 5c6814335cd7..50da49be9ae5 100644
--- a/sound/pci/cs5535audio/cs5535audio_olpc.c
+++ b/sound/pci/cs5535audio/cs5535audio_olpc.c
@@ -13,10 +13,13 @@
13#include <sound/info.h> 13#include <sound/info.h>
14#include <sound/control.h> 14#include <sound/control.h>
15#include <sound/ac97_codec.h> 15#include <sound/ac97_codec.h>
16#include <linux/gpio.h>
16 17
17#include <asm/olpc.h> 18#include <asm/olpc.h>
18#include "cs5535audio.h" 19#include "cs5535audio.h"
19 20
21#define DRV_NAME "cs5535audio-olpc"
22
20/* 23/*
21 * OLPC has an additional feature on top of the regular AD1888 codec features. 24 * OLPC has an additional feature on top of the regular AD1888 codec features.
22 * It has an Analog Input mode that is switched into (after disabling the 25 * It has an Analog Input mode that is switched into (after disabling the
@@ -38,10 +41,7 @@ void olpc_analog_input(struct snd_ac97 *ac97, int on)
38 } 41 }
39 42
40 /* set Analog Input through GPIO */ 43 /* set Analog Input through GPIO */
41 if (on) 44 gpio_set_value(OLPC_GPIO_MIC_AC, on);
42 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
43 else
44 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
45} 45}
46 46
47/* 47/*
@@ -73,8 +73,7 @@ static int olpc_dc_info(struct snd_kcontrol *kctl,
73 73
74static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) 74static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
75{ 75{
76 v->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC, 76 v->value.integer.value[0] = gpio_get_value(OLPC_GPIO_MIC_AC);
77 GPIO_OUTPUT_VAL);
78 return 0; 77 return 0;
79} 78}
80 79
@@ -153,6 +152,12 @@ int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
153 if (!machine_is_olpc()) 152 if (!machine_is_olpc())
154 return 0; 153 return 0;
155 154
155 if (gpio_request(OLPC_GPIO_MIC_AC, DRV_NAME)) {
156 printk(KERN_ERR DRV_NAME ": unable to allocate MIC GPIO\n");
157 return -EIO;
158 }
159 gpio_direction_output(OLPC_GPIO_MIC_AC, 0);
160
156 /* drop the original AD1888 HPF control */ 161 /* drop the original AD1888 HPF control */
157 memset(&elem, 0, sizeof(elem)); 162 memset(&elem, 0, sizeof(elem));
158 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 163 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
@@ -169,11 +174,18 @@ int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
169 for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) { 174 for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) {
170 err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i], 175 err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i],
171 ac97->private_data)); 176 ac97->private_data));
172 if (err < 0) 177 if (err < 0) {
178 gpio_free(OLPC_GPIO_MIC_AC);
173 return err; 179 return err;
180 }
174 } 181 }
175 182
176 /* turn off the mic by default */ 183 /* turn off the mic by default */
177 olpc_mic_bias(ac97, 0); 184 olpc_mic_bias(ac97, 0);
178 return 0; 185 return 0;
179} 186}
187
188void __devexit olpc_quirks_cleanup(void)
189{
190 gpio_free(OLPC_GPIO_MIC_AC);
191}
diff --git a/sound/pci/cs5535audio/cs5535audio_pcm.c b/sound/pci/cs5535audio/cs5535audio_pcm.c
index 0f48a871f17b..f16bc8aad6ed 100644
--- a/sound/pci/cs5535audio/cs5535audio_pcm.c
+++ b/sound/pci/cs5535audio/cs5535audio_pcm.c
@@ -23,7 +23,6 @@
23 */ 23 */
24 24
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/pci.h> 26#include <linux/pci.h>
28#include <sound/core.h> 27#include <sound/core.h>
29#include <sound/control.h> 28#include <sound/control.h>
diff --git a/sound/pci/cs5535audio/cs5535audio_pm.c b/sound/pci/cs5535audio/cs5535audio_pm.c
index 564c33b60953..a3301cc4ab82 100644
--- a/sound/pci/cs5535audio/cs5535audio_pm.c
+++ b/sound/pci/cs5535audio/cs5535audio_pm.c
@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/pci.h> 22#include <linux/pci.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <sound/core.h> 24#include <sound/core.h>
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index 75454648d50c..1bff80cde0a2 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -24,6 +24,7 @@
24#include "ctdaio.h" 24#include "ctdaio.h"
25#include "cttimer.h" 25#include "cttimer.h"
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h>
27#include <sound/pcm.h> 28#include <sound/pcm.h>
28#include <sound/control.h> 29#include <sound/control.h>
29#include <sound/asoundef.h> 30#include <sound/asoundef.h>
@@ -166,18 +167,7 @@ static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
166 167
167static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index) 168static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index)
168{ 169{
169 struct ct_vm *vm; 170 return atc->vm->get_ptp_phys(atc->vm, index);
170 void *kvirt_addr;
171 unsigned long phys_addr;
172
173 vm = atc->vm;
174 kvirt_addr = vm->get_ptp_virt(vm, index);
175 if (kvirt_addr == NULL)
176 phys_addr = (~0UL);
177 else
178 phys_addr = virt_to_phys(kvirt_addr);
179
180 return phys_addr;
181} 171}
182 172
183static unsigned int convert_format(snd_pcm_format_t snd_format) 173static unsigned int convert_format(snd_pcm_format_t snd_format)
@@ -240,7 +230,7 @@ static int select_rom(unsigned int pitch)
240 } else if (pitch == 0x02000000) { 230 } else if (pitch == 0x02000000) {
241 /* pitch == 2 */ 231 /* pitch == 2 */
242 return 3; 232 return 3;
243 } else if (pitch >= 0x0 && pitch <= 0x08000000) { 233 } else if (pitch <= 0x08000000) {
244 /* 0 <= pitch <= 8 */ 234 /* 0 <= pitch <= 8 */
245 return 0; 235 return 0;
246 } else { 236 } else {
@@ -1225,10 +1215,11 @@ static int atc_dev_free(struct snd_device *dev)
1225 return ct_atc_destroy(atc); 1215 return ct_atc_destroy(atc);
1226} 1216}
1227 1217
1228static int __devinit atc_identify_card(struct ct_atc *atc) 1218static int __devinit atc_identify_card(struct ct_atc *atc, unsigned int ssid)
1229{ 1219{
1230 const struct snd_pci_quirk *p; 1220 const struct snd_pci_quirk *p;
1231 const struct snd_pci_quirk *list; 1221 const struct snd_pci_quirk *list;
1222 u16 vendor_id, device_id;
1232 1223
1233 switch (atc->chip_type) { 1224 switch (atc->chip_type) {
1234 case ATC20K1: 1225 case ATC20K1:
@@ -1242,13 +1233,19 @@ static int __devinit atc_identify_card(struct ct_atc *atc)
1242 default: 1233 default:
1243 return -ENOENT; 1234 return -ENOENT;
1244 } 1235 }
1245 p = snd_pci_quirk_lookup(atc->pci, list); 1236 if (ssid) {
1237 vendor_id = ssid >> 16;
1238 device_id = ssid & 0xffff;
1239 } else {
1240 vendor_id = atc->pci->subsystem_vendor;
1241 device_id = atc->pci->subsystem_device;
1242 }
1243 p = snd_pci_quirk_lookup_id(vendor_id, device_id, list);
1246 if (p) { 1244 if (p) {
1247 if (p->value < 0) { 1245 if (p->value < 0) {
1248 printk(KERN_ERR "ctxfi: " 1246 printk(KERN_ERR "ctxfi: "
1249 "Device %04x:%04x is black-listed\n", 1247 "Device %04x:%04x is black-listed\n",
1250 atc->pci->subsystem_vendor, 1248 vendor_id, device_id);
1251 atc->pci->subsystem_device);
1252 return -ENOENT; 1249 return -ENOENT;
1253 } 1250 }
1254 atc->model = p->value; 1251 atc->model = p->value;
@@ -1261,8 +1258,7 @@ static int __devinit atc_identify_card(struct ct_atc *atc)
1261 atc->model_name = ct_subsys_name[atc->model]; 1258 atc->model_name = ct_subsys_name[atc->model];
1262 snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n", 1259 snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n",
1263 atc->chip_name, atc->model_name, 1260 atc->chip_name, atc->model_name,
1264 atc->pci->subsystem_vendor, 1261 vendor_id, device_id);
1265 atc->pci->subsystem_device);
1266 return 0; 1262 return 0;
1267} 1263}
1268 1264
@@ -1636,7 +1632,8 @@ static struct ct_atc atc_preset __devinitdata = {
1636 1632
1637int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci, 1633int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
1638 unsigned int rsr, unsigned int msr, 1634 unsigned int rsr, unsigned int msr,
1639 int chip_type, struct ct_atc **ratc) 1635 int chip_type, unsigned int ssid,
1636 struct ct_atc **ratc)
1640{ 1637{
1641 struct ct_atc *atc; 1638 struct ct_atc *atc;
1642 static struct snd_device_ops ops = { 1639 static struct snd_device_ops ops = {
@@ -1662,14 +1659,14 @@ int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
1662 mutex_init(&atc->atc_mutex); 1659 mutex_init(&atc->atc_mutex);
1663 1660
1664 /* Find card model */ 1661 /* Find card model */
1665 err = atc_identify_card(atc); 1662 err = atc_identify_card(atc, ssid);
1666 if (err < 0) { 1663 if (err < 0) {
1667 printk(KERN_ERR "ctatc: Card not recognised\n"); 1664 printk(KERN_ERR "ctatc: Card not recognised\n");
1668 goto error1; 1665 goto error1;
1669 } 1666 }
1670 1667
1671 /* Set up device virtual memory management object */ 1668 /* Set up device virtual memory management object */
1672 err = ct_vm_create(&atc->vm); 1669 err = ct_vm_create(&atc->vm, pci);
1673 if (err < 0) 1670 if (err < 0)
1674 goto error1; 1671 goto error1;
1675 1672
diff --git a/sound/pci/ctxfi/ctatc.h b/sound/pci/ctxfi/ctatc.h
index 9fd8a5708943..7167c0185d52 100644
--- a/sound/pci/ctxfi/ctatc.h
+++ b/sound/pci/ctxfi/ctatc.h
@@ -148,7 +148,7 @@ struct ct_atc {
148 148
149int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci, 149int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
150 unsigned int rsr, unsigned int msr, int chip_type, 150 unsigned int rsr, unsigned int msr, int chip_type,
151 struct ct_atc **ratc); 151 unsigned int subsysid, struct ct_atc **ratc);
152int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc); 152int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc);
153 153
154#endif /* CTATC_H */ 154#endif /* CTATC_H */
diff --git a/sound/pci/ctxfi/ctpcm.c b/sound/pci/ctxfi/ctpcm.c
index d0dc227fbdd3..85ab43e89212 100644
--- a/sound/pci/ctxfi/ctpcm.c
+++ b/sound/pci/ctxfi/ctpcm.c
@@ -17,6 +17,7 @@
17 17
18#include "ctpcm.h" 18#include "ctpcm.h"
19#include "cttimer.h" 19#include "cttimer.h"
20#include <linux/slab.h>
20#include <sound/pcm.h> 21#include <sound/pcm.h>
21 22
22/* Hardware descriptions for playback */ 23/* Hardware descriptions for playback */
diff --git a/sound/pci/ctxfi/ctvmem.c b/sound/pci/ctxfi/ctvmem.c
index 6b78752e9503..65da6e466f80 100644
--- a/sound/pci/ctxfi/ctvmem.c
+++ b/sound/pci/ctxfi/ctvmem.c
@@ -138,7 +138,7 @@ ct_vm_map(struct ct_vm *vm, struct snd_pcm_substream *substream, int size)
138 return NULL; 138 return NULL;
139 } 139 }
140 140
141 ptp = vm->ptp[0]; 141 ptp = (unsigned long *)vm->ptp[0].area;
142 pte_start = (block->addr >> CT_PAGE_SHIFT); 142 pte_start = (block->addr >> CT_PAGE_SHIFT);
143 pages = block->size >> CT_PAGE_SHIFT; 143 pages = block->size >> CT_PAGE_SHIFT;
144 for (i = 0; i < pages; i++) { 144 for (i = 0; i < pages; i++) {
@@ -158,25 +158,25 @@ static void ct_vm_unmap(struct ct_vm *vm, struct ct_vm_block *block)
158} 158}
159 159
160/* * 160/* *
161 * return the host (kmalloced) addr of the @index-th device 161 * return the host physical addr of the @index-th device
162 * page talbe page on success, or NULL on failure. 162 * page table page on success, or ~0UL on failure.
163 * The first returned NULL indicates the termination. 163 * The first returned ~0UL indicates the termination.
164 * */ 164 * */
165static void * 165static dma_addr_t
166ct_get_ptp_virt(struct ct_vm *vm, int index) 166ct_get_ptp_phys(struct ct_vm *vm, int index)
167{ 167{
168 void *addr; 168 dma_addr_t addr;
169 169
170 addr = (index >= CT_PTP_NUM) ? NULL : vm->ptp[index]; 170 addr = (index >= CT_PTP_NUM) ? ~0UL : vm->ptp[index].addr;
171 171
172 return addr; 172 return addr;
173} 173}
174 174
175int ct_vm_create(struct ct_vm **rvm) 175int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci)
176{ 176{
177 struct ct_vm *vm; 177 struct ct_vm *vm;
178 struct ct_vm_block *block; 178 struct ct_vm_block *block;
179 int i; 179 int i, err = 0;
180 180
181 *rvm = NULL; 181 *rvm = NULL;
182 182
@@ -188,23 +188,21 @@ int ct_vm_create(struct ct_vm **rvm)
188 188
189 /* Allocate page table pages */ 189 /* Allocate page table pages */
190 for (i = 0; i < CT_PTP_NUM; i++) { 190 for (i = 0; i < CT_PTP_NUM; i++) {
191 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL); 191 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
192 if (!vm->ptp[i]) 192 snd_dma_pci_data(pci),
193 PAGE_SIZE, &vm->ptp[i]);
194 if (err < 0)
193 break; 195 break;
194 } 196 }
195 if (!i) { 197 if (err < 0) {
196 /* no page table pages are allocated */ 198 /* no page table pages are allocated */
197 kfree(vm); 199 ct_vm_destroy(vm);
198 return -ENOMEM; 200 return -ENOMEM;
199 } 201 }
200 vm->size = CT_ADDRS_PER_PAGE * i; 202 vm->size = CT_ADDRS_PER_PAGE * i;
201 /* Initialise remaining ptps */
202 for (; i < CT_PTP_NUM; i++)
203 vm->ptp[i] = NULL;
204
205 vm->map = ct_vm_map; 203 vm->map = ct_vm_map;
206 vm->unmap = ct_vm_unmap; 204 vm->unmap = ct_vm_unmap;
207 vm->get_ptp_virt = ct_get_ptp_virt; 205 vm->get_ptp_phys = ct_get_ptp_phys;
208 INIT_LIST_HEAD(&vm->unused); 206 INIT_LIST_HEAD(&vm->unused);
209 INIT_LIST_HEAD(&vm->used); 207 INIT_LIST_HEAD(&vm->used);
210 block = kzalloc(sizeof(*block), GFP_KERNEL); 208 block = kzalloc(sizeof(*block), GFP_KERNEL);
@@ -242,7 +240,7 @@ void ct_vm_destroy(struct ct_vm *vm)
242 240
243 /* free allocated page table pages */ 241 /* free allocated page table pages */
244 for (i = 0; i < CT_PTP_NUM; i++) 242 for (i = 0; i < CT_PTP_NUM; i++)
245 kfree(vm->ptp[i]); 243 snd_dma_free_pages(&vm->ptp[i]);
246 244
247 vm->size = 0; 245 vm->size = 0;
248 246
diff --git a/sound/pci/ctxfi/ctvmem.h b/sound/pci/ctxfi/ctvmem.h
index 01e4fd0386a3..b23adfca4de6 100644
--- a/sound/pci/ctxfi/ctvmem.h
+++ b/sound/pci/ctxfi/ctvmem.h
@@ -22,6 +22,8 @@
22 22
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/pci.h>
26#include <sound/memalloc.h>
25 27
26/* The chip can handle the page table of 4k pages 28/* The chip can handle the page table of 4k pages
27 * (emu20k1 can handle even 8k pages, but we don't use it right now) 29 * (emu20k1 can handle even 8k pages, but we don't use it right now)
@@ -41,7 +43,7 @@ struct snd_pcm_substream;
41 43
42/* Virtual memory management object for card device */ 44/* Virtual memory management object for card device */
43struct ct_vm { 45struct ct_vm {
44 void *ptp[CT_PTP_NUM]; /* Device page table pages */ 46 struct snd_dma_buffer ptp[CT_PTP_NUM]; /* Device page table pages */
45 unsigned int size; /* Available addr space in bytes */ 47 unsigned int size; /* Available addr space in bytes */
46 struct list_head unused; /* List of unused blocks */ 48 struct list_head unused; /* List of unused blocks */
47 struct list_head used; /* List of used blocks */ 49 struct list_head used; /* List of used blocks */
@@ -52,10 +54,10 @@ struct ct_vm {
52 int size); 54 int size);
53 /* Unmap device logical addr area. */ 55 /* Unmap device logical addr area. */
54 void (*unmap)(struct ct_vm *, struct ct_vm_block *block); 56 void (*unmap)(struct ct_vm *, struct ct_vm_block *block);
55 void *(*get_ptp_virt)(struct ct_vm *vm, int index); 57 dma_addr_t (*get_ptp_phys)(struct ct_vm *vm, int index);
56}; 58};
57 59
58int ct_vm_create(struct ct_vm **rvm); 60int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci);
59void ct_vm_destroy(struct ct_vm *vm); 61void ct_vm_destroy(struct ct_vm *vm);
60 62
61#endif /* CTVMEM_H */ 63#endif /* CTVMEM_H */
diff --git a/sound/pci/ctxfi/xfi.c b/sound/pci/ctxfi/xfi.c
index 76541748e7bc..f42e7e1a1074 100644
--- a/sound/pci/ctxfi/xfi.c
+++ b/sound/pci/ctxfi/xfi.c
@@ -32,6 +32,7 @@ module_param(multiple, uint, S_IRUGO);
32static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 32static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
33static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 33static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
34static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 34static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
35static unsigned int subsystem[SNDRV_CARDS];
35 36
36module_param_array(index, int, NULL, 0444); 37module_param_array(index, int, NULL, 0444);
37MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver"); 38MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
@@ -39,8 +40,10 @@ module_param_array(id, charp, NULL, 0444);
39MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver"); 40MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
40module_param_array(enable, bool, NULL, 0444); 41module_param_array(enable, bool, NULL, 0444);
41MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver"); 42MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
43module_param_array(subsystem, int, NULL, 0444);
44MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
42 45
43static struct pci_device_id ct_pci_dev_ids[] = { 46static DEFINE_PCI_DEVICE_TABLE(ct_pci_dev_ids) = {
44 /* only X-Fi is supported, so... */ 47 /* only X-Fi is supported, so... */
45 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1), 48 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
46 .driver_data = ATC20K1, 49 .driver_data = ATC20K1,
@@ -85,7 +88,7 @@ ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
85 multiple = 2; 88 multiple = 2;
86 } 89 }
87 err = ct_atc_create(card, pci, reference_rate, multiple, 90 err = ct_atc_create(card, pci, reference_rate, multiple,
88 pci_id->driver_data, &atc); 91 pci_id->driver_data, subsystem[dev], &atc);
89 if (err < 0) 92 if (err < 0)
90 goto error; 93 goto error;
91 94
diff --git a/sound/pci/echoaudio/darla20.c b/sound/pci/echoaudio/darla20.c
index 8c6db3aa3c1a..fe7ad64dccd7 100644
--- a/sound/pci/echoaudio/darla20.c
+++ b/sound/pci/echoaudio/darla20.c
@@ -40,9 +40,9 @@
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/pci.h> 42#include <linux/pci.h>
43#include <linux/slab.h>
44#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
45#include <linux/firmware.h> 44#include <linux/firmware.h>
45#include <linux/slab.h>
46#include <sound/core.h> 46#include <sound/core.h>
47#include <sound/info.h> 47#include <sound/info.h>
48#include <sound/control.h> 48#include <sound/control.h>
@@ -63,7 +63,7 @@ static const struct firmware card_fw[] = {
63 {0, "darla20_dsp.fw"} 63 {0, "darla20_dsp.fw"}
64}; 64};
65 65
66static struct pci_device_id snd_echo_ids[] = { 66static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
67 {0x1057, 0x1801, 0xECC0, 0x0010, 0, 0, 0}, /* DSP 56301 Darla20 rev.0 */ 67 {0x1057, 0x1801, 0xECC0, 0x0010, 0, 0, 0}, /* DSP 56301 Darla20 rev.0 */
68 {0,} 68 {0,}
69}; 69};
diff --git a/sound/pci/echoaudio/darla20_dsp.c b/sound/pci/echoaudio/darla20_dsp.c
index 29043301ebb8..20c7cbc89bb3 100644
--- a/sound/pci/echoaudio/darla20_dsp.c
+++ b/sound/pci/echoaudio/darla20_dsp.c
@@ -45,7 +45,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
45 chip->device_id = device_id; 45 chip->device_id = device_id;
46 chip->subdevice_id = subdevice_id; 46 chip->subdevice_id = subdevice_id;
47 chip->bad_board = TRUE; 47 chip->bad_board = TRUE;
48 chip->dsp_code_to_load = &card_fw[FW_DARLA20_DSP]; 48 chip->dsp_code_to_load = FW_DARLA20_DSP;
49 chip->spdif_status = GD_SPDIF_STATUS_UNDEF; 49 chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
50 chip->clock_state = GD_CLOCK_UNDEF; 50 chip->clock_state = GD_CLOCK_UNDEF;
51 /* Since this card has no ASIC, mark it as loaded so everything 51 /* Since this card has no ASIC, mark it as loaded so everything
@@ -57,15 +57,19 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
57 return err; 57 return err;
58 chip->bad_board = FALSE; 58 chip->bad_board = FALSE;
59 59
60 if ((err = init_line_levels(chip)) < 0)
61 return err;
62
63 DE_INIT(("init_hw done\n")); 60 DE_INIT(("init_hw done\n"));
64 return err; 61 return err;
65} 62}
66 63
67 64
68 65
66static int set_mixer_defaults(struct echoaudio *chip)
67{
68 return init_line_levels(chip);
69}
70
71
72
69/* The Darla20 has no external clock sources */ 73/* The Darla20 has no external clock sources */
70static u32 detect_input_clocks(const struct echoaudio *chip) 74static u32 detect_input_clocks(const struct echoaudio *chip)
71{ 75{
diff --git a/sound/pci/echoaudio/darla24.c b/sound/pci/echoaudio/darla24.c
index 04cbf3eaf05a..d1fd34b1a8e3 100644
--- a/sound/pci/echoaudio/darla24.c
+++ b/sound/pci/echoaudio/darla24.c
@@ -44,9 +44,9 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/interrupt.h> 45#include <linux/interrupt.h>
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/slab.h>
48#include <linux/moduleparam.h> 47#include <linux/moduleparam.h>
49#include <linux/firmware.h> 48#include <linux/firmware.h>
49#include <linux/slab.h>
50#include <sound/core.h> 50#include <sound/core.h>
51#include <sound/info.h> 51#include <sound/info.h>
52#include <sound/control.h> 52#include <sound/control.h>
@@ -67,7 +67,7 @@ static const struct firmware card_fw[] = {
67 {0, "darla24_dsp.fw"} 67 {0, "darla24_dsp.fw"}
68}; 68};
69 69
70static struct pci_device_id snd_echo_ids[] = { 70static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
71 {0x1057, 0x1801, 0xECC0, 0x0040, 0, 0, 0}, /* DSP 56301 Darla24 rev.0 */ 71 {0x1057, 0x1801, 0xECC0, 0x0040, 0, 0, 0}, /* DSP 56301 Darla24 rev.0 */
72 {0x1057, 0x1801, 0xECC0, 0x0041, 0, 0, 0}, /* DSP 56301 Darla24 rev.1 */ 72 {0x1057, 0x1801, 0xECC0, 0x0041, 0, 0, 0}, /* DSP 56301 Darla24 rev.1 */
73 {0,} 73 {0,}
diff --git a/sound/pci/echoaudio/darla24_dsp.c b/sound/pci/echoaudio/darla24_dsp.c
index 60228731841f..6da6663e9176 100644
--- a/sound/pci/echoaudio/darla24_dsp.c
+++ b/sound/pci/echoaudio/darla24_dsp.c
@@ -45,7 +45,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
45 chip->device_id = device_id; 45 chip->device_id = device_id;
46 chip->subdevice_id = subdevice_id; 46 chip->subdevice_id = subdevice_id;
47 chip->bad_board = TRUE; 47 chip->bad_board = TRUE;
48 chip->dsp_code_to_load = &card_fw[FW_DARLA24_DSP]; 48 chip->dsp_code_to_load = FW_DARLA24_DSP;
49 /* Since this card has no ASIC, mark it as loaded so everything 49 /* Since this card has no ASIC, mark it as loaded so everything
50 works OK */ 50 works OK */
51 chip->asic_loaded = TRUE; 51 chip->asic_loaded = TRUE;
@@ -56,15 +56,19 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
56 return err; 56 return err;
57 chip->bad_board = FALSE; 57 chip->bad_board = FALSE;
58 58
59 if ((err = init_line_levels(chip)) < 0)
60 return err;
61
62 DE_INIT(("init_hw done\n")); 59 DE_INIT(("init_hw done\n"));
63 return err; 60 return err;
64} 61}
65 62
66 63
67 64
65static int set_mixer_defaults(struct echoaudio *chip)
66{
67 return init_line_levels(chip);
68}
69
70
71
68static u32 detect_input_clocks(const struct echoaudio *chip) 72static u32 detect_input_clocks(const struct echoaudio *chip)
69{ 73{
70 u32 clocks_from_dsp, clock_bits; 74 u32 clocks_from_dsp, clock_bits;
diff --git a/sound/pci/echoaudio/echo3g.c b/sound/pci/echoaudio/echo3g.c
index 4022e43a0053..1dffdc54416d 100644
--- a/sound/pci/echoaudio/echo3g.c
+++ b/sound/pci/echoaudio/echo3g.c
@@ -51,9 +51,9 @@
51#include <linux/init.h> 51#include <linux/init.h>
52#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53#include <linux/pci.h> 53#include <linux/pci.h>
54#include <linux/slab.h>
55#include <linux/moduleparam.h> 54#include <linux/moduleparam.h>
56#include <linux/firmware.h> 55#include <linux/firmware.h>
56#include <linux/slab.h>
57#include <sound/core.h> 57#include <sound/core.h>
58#include <sound/info.h> 58#include <sound/info.h>
59#include <sound/control.h> 59#include <sound/control.h>
@@ -81,7 +81,7 @@ static const struct firmware card_fw[] = {
81 {0, "3g_asic.fw"} 81 {0, "3g_asic.fw"}
82}; 82};
83 83
84static struct pci_device_id snd_echo_ids[] = { 84static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
85 {0x1057, 0x3410, 0xECC0, 0x0100, 0, 0, 0}, /* Echo 3G */ 85 {0x1057, 0x3410, 0xECC0, 0x0100, 0, 0, 0}, /* Echo 3G */
86 {0,} 86 {0,}
87}; 87};
diff --git a/sound/pci/echoaudio/echo3g_dsp.c b/sound/pci/echoaudio/echo3g_dsp.c
index 57967e580571..3cdc2ee2d1dd 100644
--- a/sound/pci/echoaudio/echo3g_dsp.c
+++ b/sound/pci/echoaudio/echo3g_dsp.c
@@ -61,7 +61,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
61 chip->subdevice_id = subdevice_id; 61 chip->subdevice_id = subdevice_id;
62 chip->bad_board = TRUE; 62 chip->bad_board = TRUE;
63 chip->has_midi = TRUE; 63 chip->has_midi = TRUE;
64 chip->dsp_code_to_load = &card_fw[FW_ECHO3G_DSP]; 64 chip->dsp_code_to_load = FW_ECHO3G_DSP;
65 65
66 /* Load the DSP code and the ASIC on the PCI card and get 66 /* Load the DSP code and the ASIC on the PCI card and get
67 what type of external box is attached */ 67 what type of external box is attached */
@@ -97,20 +97,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
97 chip->digital_modes = ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA | 97 chip->digital_modes = ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
98 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL | 98 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
99 ECHOCAPS_HAS_DIGITAL_MODE_ADAT; 99 ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
100 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
101 chip->professional_spdif = FALSE;
102 chip->non_audio_spdif = FALSE;
103 chip->bad_board = FALSE;
104
105 if ((err = init_line_levels(chip)) < 0)
106 return err;
107 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
108 if (err < 0)
109 return err;
110 err = set_phantom_power(chip, 0);
111 if (err < 0)
112 return err;
113 err = set_professional_spdif(chip, TRUE);
114 100
115 DE_INIT(("init_hw done\n")); 101 DE_INIT(("init_hw done\n"));
116 return err; 102 return err;
@@ -118,6 +104,18 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
118 104
119 105
120 106
107static int set_mixer_defaults(struct echoaudio *chip)
108{
109 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
110 chip->professional_spdif = FALSE;
111 chip->non_audio_spdif = FALSE;
112 chip->bad_board = FALSE;
113 chip->phantom_power = FALSE;
114 return init_line_levels(chip);
115}
116
117
118
121static int set_phantom_power(struct echoaudio *chip, char on) 119static int set_phantom_power(struct echoaudio *chip, char on)
122{ 120{
123 u32 control_reg = le32_to_cpu(chip->comm_page->control_register); 121 u32 control_reg = le32_to_cpu(chip->comm_page->control_register);
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 1305f7ca02c3..668a5ec04499 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -36,22 +36,61 @@ MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard.");
36static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999}; 36static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
37static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1); 37static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);
38 38
39
40
39static int get_firmware(const struct firmware **fw_entry, 41static int get_firmware(const struct firmware **fw_entry,
40 const struct firmware *frm, struct echoaudio *chip) 42 struct echoaudio *chip, const short fw_index)
41{ 43{
42 int err; 44 int err;
43 char name[30]; 45 char name[30];
44 DE_ACT(("firmware requested: %s\n", frm->data)); 46
45 snprintf(name, sizeof(name), "ea/%s", frm->data); 47#ifdef CONFIG_PM
46 if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0) 48 if (chip->fw_cache[fw_index]) {
49 DE_ACT(("firmware requested: %s is cached\n", card_fw[fw_index].data));
50 *fw_entry = chip->fw_cache[fw_index];
51 return 0;
52 }
53#endif
54
55 DE_ACT(("firmware requested: %s\n", card_fw[fw_index].data));
56 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
57 err = request_firmware(fw_entry, name, pci_device(chip));
58 if (err < 0)
47 snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err); 59 snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err);
60#ifdef CONFIG_PM
61 else
62 chip->fw_cache[fw_index] = *fw_entry;
63#endif
48 return err; 64 return err;
49} 65}
50 66
67
68
51static void free_firmware(const struct firmware *fw_entry) 69static void free_firmware(const struct firmware *fw_entry)
52{ 70{
71#ifdef CONFIG_PM
72 DE_ACT(("firmware not released (kept in cache)\n"));
73#else
53 release_firmware(fw_entry); 74 release_firmware(fw_entry);
54 DE_ACT(("firmware released\n")); 75 DE_ACT(("firmware released\n"));
76#endif
77}
78
79
80
81static void free_firmware_cache(struct echoaudio *chip)
82{
83#ifdef CONFIG_PM
84 int i;
85
86 for (i = 0; i < 8 ; i++)
87 if (chip->fw_cache[i]) {
88 release_firmware(chip->fw_cache[i]);
89 DE_ACT(("release_firmware(%d)\n", i));
90 }
91
92 DE_ACT(("firmware_cache released\n"));
93#endif
55} 94}
56 95
57 96
@@ -714,6 +753,8 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
714 753
715 spin_lock(&chip->lock); 754 spin_lock(&chip->lock);
716 switch (cmd) { 755 switch (cmd) {
756 case SNDRV_PCM_TRIGGER_RESUME:
757 DE_ACT(("pcm_trigger resume\n"));
717 case SNDRV_PCM_TRIGGER_START: 758 case SNDRV_PCM_TRIGGER_START:
718 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 759 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
719 DE_ACT(("pcm_trigger start\n")); 760 DE_ACT(("pcm_trigger start\n"));
@@ -737,6 +778,8 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
737 err = start_transport(chip, channelmask, 778 err = start_transport(chip, channelmask,
738 chip->pipe_cyclic_mask); 779 chip->pipe_cyclic_mask);
739 break; 780 break;
781 case SNDRV_PCM_TRIGGER_SUSPEND:
782 DE_ACT(("pcm_trigger suspend\n"));
740 case SNDRV_PCM_TRIGGER_STOP: 783 case SNDRV_PCM_TRIGGER_STOP:
741 DE_ACT(("pcm_trigger stop\n")); 784 DE_ACT(("pcm_trigger stop\n"));
742 for (i = 0; i < DSP_MAXPIPES; i++) { 785 for (i = 0; i < DSP_MAXPIPES; i++) {
@@ -1821,7 +1864,9 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1821 /* The hardware doesn't tell us which substream caused the irq, 1864 /* The hardware doesn't tell us which substream caused the irq,
1822 thus we have to check all running substreams. */ 1865 thus we have to check all running substreams. */
1823 for (ss = 0; ss < DSP_MAXPIPES; ss++) { 1866 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1824 if ((substream = chip->substream[ss])) { 1867 substream = chip->substream[ss];
1868 if (substream && ((struct audiopipe *)substream->runtime->
1869 private_data)->state == PIPE_STATE_STARTED) {
1825 period = pcm_pointer(substream) / 1870 period = pcm_pointer(substream) /
1826 substream->runtime->period_size; 1871 substream->runtime->period_size;
1827 if (period != chip->last_period[ss]) { 1872 if (period != chip->last_period[ss]) {
@@ -1874,6 +1919,7 @@ static int snd_echo_free(struct echoaudio *chip)
1874 pci_disable_device(chip->pci); 1919 pci_disable_device(chip->pci);
1875 1920
1876 /* release chip data */ 1921 /* release chip data */
1922 free_firmware_cache(chip);
1877 kfree(chip); 1923 kfree(chip);
1878 DE_INIT(("Chip freed.\n")); 1924 DE_INIT(("Chip freed.\n"));
1879 return 0; 1925 return 0;
@@ -1911,18 +1957,27 @@ static __devinit int snd_echo_create(struct snd_card *card,
1911 return err; 1957 return err;
1912 pci_set_master(pci); 1958 pci_set_master(pci);
1913 1959
1914 /* allocate a chip-specific data */ 1960 /* Allocate chip if needed */
1915 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1961 if (!*rchip) {
1916 if (!chip) { 1962 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1917 pci_disable_device(pci); 1963 if (!chip) {
1918 return -ENOMEM; 1964 pci_disable_device(pci);
1965 return -ENOMEM;
1966 }
1967 DE_INIT(("chip=%p\n", chip));
1968 spin_lock_init(&chip->lock);
1969 chip->card = card;
1970 chip->pci = pci;
1971 chip->irq = -1;
1972 atomic_set(&chip->opencount, 0);
1973 mutex_init(&chip->mode_mutex);
1974 chip->can_set_rate = 1;
1975 } else {
1976 /* If this was called from the resume function, chip is
1977 * already allocated and it contains current card settings.
1978 */
1979 chip = *rchip;
1919 } 1980 }
1920 DE_INIT(("chip=%p\n", chip));
1921
1922 spin_lock_init(&chip->lock);
1923 chip->card = card;
1924 chip->pci = pci;
1925 chip->irq = -1;
1926 1981
1927 /* PCI resource allocation */ 1982 /* PCI resource allocation */
1928 chip->dsp_registers_phys = pci_resource_start(pci, 0); 1983 chip->dsp_registers_phys = pci_resource_start(pci, 0);
@@ -1962,7 +2017,9 @@ static __devinit int snd_echo_create(struct snd_card *card,
1962 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; 2017 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1963 2018
1964 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); 2019 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1965 if (err) { 2020 if (err >= 0)
2021 err = set_mixer_defaults(chip);
2022 if (err < 0) {
1966 DE_INIT(("init_hw err=%d\n", err)); 2023 DE_INIT(("init_hw err=%d\n", err));
1967 snd_echo_free(chip); 2024 snd_echo_free(chip);
1968 return err; 2025 return err;
@@ -1973,9 +2030,6 @@ static __devinit int snd_echo_create(struct snd_card *card,
1973 snd_echo_free(chip); 2030 snd_echo_free(chip);
1974 return err; 2031 return err;
1975 } 2032 }
1976 atomic_set(&chip->opencount, 0);
1977 mutex_init(&chip->mode_mutex);
1978 chip->can_set_rate = 1;
1979 *rchip = chip; 2033 *rchip = chip;
1980 /* Init done ! */ 2034 /* Init done ! */
1981 return 0; 2035 return 0;
@@ -2008,6 +2062,7 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
2008 2062
2009 snd_card_set_dev(card, &pci->dev); 2063 snd_card_set_dev(card, &pci->dev);
2010 2064
2065 chip = NULL; /* Tells snd_echo_create to allocate chip */
2011 if ((err = snd_echo_create(card, pci, &chip)) < 0) { 2066 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2012 snd_card_free(card); 2067 snd_card_free(card);
2013 return err; 2068 return err;
@@ -2129,10 +2184,9 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
2129 goto ctl_error; 2184 goto ctl_error;
2130#endif 2185#endif
2131 2186
2132 if ((err = snd_card_register(card)) < 0) { 2187 err = snd_card_register(card);
2133 snd_card_free(card); 2188 if (err < 0)
2134 goto ctl_error; 2189 goto ctl_error;
2135 }
2136 snd_printk(KERN_INFO "Card registered: %s\n", card->longname); 2190 snd_printk(KERN_INFO "Card registered: %s\n", card->longname);
2137 2191
2138 pci_set_drvdata(pci, chip); 2192 pci_set_drvdata(pci, chip);
@@ -2147,6 +2201,112 @@ ctl_error:
2147 2201
2148 2202
2149 2203
2204#if defined(CONFIG_PM)
2205
2206static int snd_echo_suspend(struct pci_dev *pci, pm_message_t state)
2207{
2208 struct echoaudio *chip = pci_get_drvdata(pci);
2209
2210 DE_INIT(("suspend start\n"));
2211 snd_pcm_suspend_all(chip->analog_pcm);
2212 snd_pcm_suspend_all(chip->digital_pcm);
2213
2214#ifdef ECHOCARD_HAS_MIDI
2215 /* This call can sleep */
2216 if (chip->midi_out)
2217 snd_echo_midi_output_trigger(chip->midi_out, 0);
2218#endif
2219 spin_lock_irq(&chip->lock);
2220 if (wait_handshake(chip)) {
2221 spin_unlock_irq(&chip->lock);
2222 return -EIO;
2223 }
2224 clear_handshake(chip);
2225 if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) {
2226 spin_unlock_irq(&chip->lock);
2227 return -EIO;
2228 }
2229 spin_unlock_irq(&chip->lock);
2230
2231 chip->dsp_code = NULL;
2232 free_irq(chip->irq, chip);
2233 chip->irq = -1;
2234 pci_save_state(pci);
2235 pci_disable_device(pci);
2236
2237 DE_INIT(("suspend done\n"));
2238 return 0;
2239}
2240
2241
2242
2243static int snd_echo_resume(struct pci_dev *pci)
2244{
2245 struct echoaudio *chip = pci_get_drvdata(pci);
2246 struct comm_page *commpage, *commpage_bak;
2247 u32 pipe_alloc_mask;
2248 int err;
2249
2250 DE_INIT(("resume start\n"));
2251 pci_restore_state(pci);
2252 commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL);
2253 commpage = chip->comm_page;
2254 memcpy(commpage_bak, commpage, sizeof(struct comm_page));
2255
2256 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
2257 if (err < 0) {
2258 kfree(commpage_bak);
2259 DE_INIT(("resume init_hw err=%d\n", err));
2260 snd_echo_free(chip);
2261 return err;
2262 }
2263 DE_INIT(("resume init OK\n"));
2264
2265 /* Temporarily set chip->pipe_alloc_mask=0 otherwise
2266 * restore_dsp_settings() fails.
2267 */
2268 pipe_alloc_mask = chip->pipe_alloc_mask;
2269 chip->pipe_alloc_mask = 0;
2270 err = restore_dsp_rettings(chip);
2271 chip->pipe_alloc_mask = pipe_alloc_mask;
2272 if (err < 0) {
2273 kfree(commpage_bak);
2274 return err;
2275 }
2276 DE_INIT(("resume restore OK\n"));
2277
2278 memcpy(&commpage->audio_format, &commpage_bak->audio_format,
2279 sizeof(commpage->audio_format));
2280 memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr,
2281 sizeof(commpage->sglist_addr));
2282 memcpy(&commpage->midi_output, &commpage_bak->midi_output,
2283 sizeof(commpage->midi_output));
2284 kfree(commpage_bak);
2285
2286 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2287 ECHOCARD_NAME, chip)) {
2288 snd_echo_free(chip);
2289 snd_printk(KERN_ERR "cannot grab irq\n");
2290 return -EBUSY;
2291 }
2292 chip->irq = pci->irq;
2293 DE_INIT(("resume irq=%d\n", chip->irq));
2294
2295#ifdef ECHOCARD_HAS_MIDI
2296 if (chip->midi_input_enabled)
2297 enable_midi_input(chip, TRUE);
2298 if (chip->midi_out)
2299 snd_echo_midi_output_trigger(chip->midi_out, 1);
2300#endif
2301
2302 DE_INIT(("resume done\n"));
2303 return 0;
2304}
2305
2306#endif /* CONFIG_PM */
2307
2308
2309
2150static void __devexit snd_echo_remove(struct pci_dev *pci) 2310static void __devexit snd_echo_remove(struct pci_dev *pci)
2151{ 2311{
2152 struct echoaudio *chip; 2312 struct echoaudio *chip;
@@ -2169,6 +2329,10 @@ static struct pci_driver driver = {
2169 .id_table = snd_echo_ids, 2329 .id_table = snd_echo_ids,
2170 .probe = snd_echo_probe, 2330 .probe = snd_echo_probe,
2171 .remove = __devexit_p(snd_echo_remove), 2331 .remove = __devexit_p(snd_echo_remove),
2332#ifdef CONFIG_PM
2333 .suspend = snd_echo_suspend,
2334 .resume = snd_echo_resume,
2335#endif /* CONFIG_PM */
2172}; 2336};
2173 2337
2174 2338
diff --git a/sound/pci/echoaudio/echoaudio.h b/sound/pci/echoaudio/echoaudio.h
index f9490ae36c2e..1df974dcb5f4 100644
--- a/sound/pci/echoaudio/echoaudio.h
+++ b/sound/pci/echoaudio/echoaudio.h
@@ -442,13 +442,16 @@ struct echoaudio {
442 u16 device_id, subdevice_id; 442 u16 device_id, subdevice_id;
443 u16 *dsp_code; /* Current DSP code loaded, 443 u16 *dsp_code; /* Current DSP code loaded,
444 * NULL if nothing loaded */ 444 * NULL if nothing loaded */
445 const struct firmware *dsp_code_to_load;/* DSP code to load */ 445 short dsp_code_to_load; /* DSP code to load */
446 const struct firmware *asic_code; /* Current ASIC code */ 446 short asic_code; /* Current ASIC code */
447 u32 comm_page_phys; /* Physical address of the 447 u32 comm_page_phys; /* Physical address of the
448 * memory seen by DSP */ 448 * memory seen by DSP */
449 volatile u32 __iomem *dsp_registers; /* DSP's register base */ 449 volatile u32 __iomem *dsp_registers; /* DSP's register base */
450 u32 active_mask; /* Chs. active mask or 450 u32 active_mask; /* Chs. active mask or
451 * punks out */ 451 * punks out */
452#ifdef CONFIG_PM
453 const struct firmware *fw_cache[8]; /* Cached firmwares */
454#endif
452 455
453#ifdef ECHOCARD_HAS_MIDI 456#ifdef ECHOCARD_HAS_MIDI
454 u16 mtc_state; /* State for MIDI input parsing state machine */ 457 u16 mtc_state; /* State for MIDI input parsing state machine */
@@ -464,11 +467,13 @@ static int load_firmware(struct echoaudio *chip);
464static int wait_handshake(struct echoaudio *chip); 467static int wait_handshake(struct echoaudio *chip);
465static int send_vector(struct echoaudio *chip, u32 command); 468static int send_vector(struct echoaudio *chip, u32 command);
466static int get_firmware(const struct firmware **fw_entry, 469static int get_firmware(const struct firmware **fw_entry,
467 const struct firmware *frm, struct echoaudio *chip); 470 struct echoaudio *chip, const short fw_index);
468static void free_firmware(const struct firmware *fw_entry); 471static void free_firmware(const struct firmware *fw_entry);
469 472
470#ifdef ECHOCARD_HAS_MIDI 473#ifdef ECHOCARD_HAS_MIDI
471static int enable_midi_input(struct echoaudio *chip, char enable); 474static int enable_midi_input(struct echoaudio *chip, char enable);
475static void snd_echo_midi_output_trigger(
476 struct snd_rawmidi_substream *substream, int up);
472static int midi_service_irq(struct echoaudio *chip); 477static int midi_service_irq(struct echoaudio *chip);
473static int __devinit snd_echo_midi_create(struct snd_card *card, 478static int __devinit snd_echo_midi_create(struct snd_card *card,
474 struct echoaudio *chip); 479 struct echoaudio *chip);
diff --git a/sound/pci/echoaudio/echoaudio_3g.c b/sound/pci/echoaudio/echoaudio_3g.c
index e32a74897921..658db44ef746 100644
--- a/sound/pci/echoaudio/echoaudio_3g.c
+++ b/sound/pci/echoaudio/echoaudio_3g.c
@@ -227,12 +227,11 @@ static int load_asic(struct echoaudio *chip)
227 /* Give the DSP a few milliseconds to settle down */ 227 /* Give the DSP a few milliseconds to settle down */
228 mdelay(2); 228 mdelay(2);
229 229
230 err = load_asic_generic(chip, DSP_FNC_LOAD_3G_ASIC, 230 err = load_asic_generic(chip, DSP_FNC_LOAD_3G_ASIC, FW_3G_ASIC);
231 &card_fw[FW_3G_ASIC]);
232 if (err < 0) 231 if (err < 0)
233 return err; 232 return err;
234 233
235 chip->asic_code = &card_fw[FW_3G_ASIC]; 234 chip->asic_code = FW_3G_ASIC;
236 235
237 /* Now give the new ASIC some time to set up */ 236 /* Now give the new ASIC some time to set up */
238 msleep(1000); 237 msleep(1000);
diff --git a/sound/pci/echoaudio/echoaudio_dsp.c b/sound/pci/echoaudio/echoaudio_dsp.c
index 4df51ef5e095..64417a733220 100644
--- a/sound/pci/echoaudio/echoaudio_dsp.c
+++ b/sound/pci/echoaudio/echoaudio_dsp.c
@@ -175,15 +175,15 @@ static inline int check_asic_status(struct echoaudio *chip)
175#ifdef ECHOCARD_HAS_ASIC 175#ifdef ECHOCARD_HAS_ASIC
176 176
177/* Load ASIC code - done after the DSP is loaded */ 177/* Load ASIC code - done after the DSP is loaded */
178static int load_asic_generic(struct echoaudio *chip, u32 cmd, 178static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic)
179 const struct firmware *asic)
180{ 179{
181 const struct firmware *fw; 180 const struct firmware *fw;
182 int err; 181 int err;
183 u32 i, size; 182 u32 i, size;
184 u8 *code; 183 u8 *code;
185 184
186 if ((err = get_firmware(&fw, asic, chip)) < 0) { 185 err = get_firmware(&fw, chip, asic);
186 if (err < 0) {
187 snd_printk(KERN_WARNING "Firmware not found !\n"); 187 snd_printk(KERN_WARNING "Firmware not found !\n");
188 return err; 188 return err;
189 } 189 }
@@ -245,7 +245,8 @@ static int install_resident_loader(struct echoaudio *chip)
245 return 0; 245 return 0;
246 } 246 }
247 247
248 if ((i = get_firmware(&fw, &card_fw[FW_361_LOADER], chip)) < 0) { 248 i = get_firmware(&fw, chip, FW_361_LOADER);
249 if (i < 0) {
249 snd_printk(KERN_WARNING "Firmware not found !\n"); 250 snd_printk(KERN_WARNING "Firmware not found !\n");
250 return i; 251 return i;
251 } 252 }
@@ -485,7 +486,8 @@ static int load_firmware(struct echoaudio *chip)
485 chip->dsp_code = NULL; 486 chip->dsp_code = NULL;
486 } 487 }
487 488
488 if ((err = get_firmware(&fw, chip->dsp_code_to_load, chip)) < 0) 489 err = get_firmware(&fw, chip, chip->dsp_code_to_load);
490 if (err < 0)
489 return err; 491 return err;
490 err = load_dsp(chip, (u16 *)fw->data); 492 err = load_dsp(chip, (u16 *)fw->data);
491 free_firmware(fw); 493 free_firmware(fw);
@@ -495,9 +497,6 @@ static int load_firmware(struct echoaudio *chip)
495 if ((box_type = load_asic(chip)) < 0) 497 if ((box_type = load_asic(chip)) < 0)
496 return box_type; /* error */ 498 return box_type; /* error */
497 499
498 if ((err = restore_dsp_rettings(chip)) < 0)
499 return err;
500
501 return box_type; 500 return box_type;
502} 501}
503 502
@@ -657,51 +656,106 @@ static void get_audio_meters(struct echoaudio *chip, long *meters)
657 656
658static int restore_dsp_rettings(struct echoaudio *chip) 657static int restore_dsp_rettings(struct echoaudio *chip)
659{ 658{
660 int err; 659 int i, o, err;
661 DE_INIT(("restore_dsp_settings\n")); 660 DE_INIT(("restore_dsp_settings\n"));
662 661
663 if ((err = check_asic_status(chip)) < 0) 662 if ((err = check_asic_status(chip)) < 0)
664 return err; 663 return err;
665 664
666 /* @ Gina20/Darla20 only. Should be harmless for other cards. */ 665 /* Gina20/Darla20 only. Should be harmless for other cards. */
667 chip->comm_page->gd_clock_state = GD_CLOCK_UNDEF; 666 chip->comm_page->gd_clock_state = GD_CLOCK_UNDEF;
668 chip->comm_page->gd_spdif_status = GD_SPDIF_STATUS_UNDEF; 667 chip->comm_page->gd_spdif_status = GD_SPDIF_STATUS_UNDEF;
669 chip->comm_page->handshake = 0xffffffff; 668 chip->comm_page->handshake = 0xffffffff;
670 669
671 if ((err = set_sample_rate(chip, chip->sample_rate)) < 0) 670 /* Restore output busses */
671 for (i = 0; i < num_busses_out(chip); i++) {
672 err = set_output_gain(chip, i, chip->output_gain[i]);
673 if (err < 0)
674 return err;
675 }
676
677#ifdef ECHOCARD_HAS_VMIXER
678 for (i = 0; i < num_pipes_out(chip); i++)
679 for (o = 0; o < num_busses_out(chip); o++) {
680 err = set_vmixer_gain(chip, o, i,
681 chip->vmixer_gain[o][i]);
682 if (err < 0)
683 return err;
684 }
685 if (update_vmixer_level(chip) < 0)
686 return -EIO;
687#endif /* ECHOCARD_HAS_VMIXER */
688
689#ifdef ECHOCARD_HAS_MONITOR
690 for (o = 0; o < num_busses_out(chip); o++)
691 for (i = 0; i < num_busses_in(chip); i++) {
692 err = set_monitor_gain(chip, o, i,
693 chip->monitor_gain[o][i]);
694 if (err < 0)
695 return err;
696 }
697#endif /* ECHOCARD_HAS_MONITOR */
698
699#ifdef ECHOCARD_HAS_INPUT_GAIN
700 for (i = 0; i < num_busses_in(chip); i++) {
701 err = set_input_gain(chip, i, chip->input_gain[i]);
702 if (err < 0)
703 return err;
704 }
705#endif /* ECHOCARD_HAS_INPUT_GAIN */
706
707 err = update_output_line_level(chip);
708 if (err < 0)
672 return err; 709 return err;
673 710
674 if (chip->meters_enabled) 711 err = update_input_line_level(chip);
675 if (send_vector(chip, DSP_VC_METERS_ON) < 0) 712 if (err < 0)
676 return -EIO; 713 return err;
677 714
678#ifdef ECHOCARD_HAS_EXTERNAL_CLOCK 715 err = set_sample_rate(chip, chip->sample_rate);
679 if (set_input_clock(chip, chip->input_clock) < 0) 716 if (err < 0)
717 return err;
718
719 if (chip->meters_enabled) {
720 err = send_vector(chip, DSP_VC_METERS_ON);
721 if (err < 0)
722 return err;
723 }
724
725#ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH
726 if (set_digital_mode(chip, chip->digital_mode) < 0)
680 return -EIO; 727 return -EIO;
681#endif 728#endif
682 729
683#ifdef ECHOCARD_HAS_OUTPUT_CLOCK_SWITCH 730#ifdef ECHOCARD_HAS_DIGITAL_IO
684 if (set_output_clock(chip, chip->output_clock) < 0) 731 if (set_professional_spdif(chip, chip->professional_spdif) < 0)
685 return -EIO; 732 return -EIO;
686#endif 733#endif
687 734
688 if (update_output_line_level(chip) < 0) 735#ifdef ECHOCARD_HAS_PHANTOM_POWER
736 if (set_phantom_power(chip, chip->phantom_power) < 0)
689 return -EIO; 737 return -EIO;
738#endif
690 739
691 if (update_input_line_level(chip) < 0) 740#ifdef ECHOCARD_HAS_EXTERNAL_CLOCK
741 /* set_input_clock() also restores automute setting */
742 if (set_input_clock(chip, chip->input_clock) < 0)
692 return -EIO; 743 return -EIO;
744#endif
693 745
694#ifdef ECHOCARD_HAS_VMIXER 746#ifdef ECHOCARD_HAS_OUTPUT_CLOCK_SWITCH
695 if (update_vmixer_level(chip) < 0) 747 if (set_output_clock(chip, chip->output_clock) < 0)
696 return -EIO; 748 return -EIO;
697#endif 749#endif
698 750
699 if (wait_handshake(chip) < 0) 751 if (wait_handshake(chip) < 0)
700 return -EIO; 752 return -EIO;
701 clear_handshake(chip); 753 clear_handshake(chip);
754 if (send_vector(chip, DSP_VC_UPDATE_FLAGS) < 0)
755 return -EIO;
702 756
703 DE_INIT(("restore_dsp_rettings done\n")); 757 DE_INIT(("restore_dsp_rettings done\n"));
704 return send_vector(chip, DSP_VC_UPDATE_FLAGS); 758 return 0;
705} 759}
706 760
707 761
@@ -918,9 +972,6 @@ static int init_dsp_comm_page(struct echoaudio *chip)
918 chip->card_name = ECHOCARD_NAME; 972 chip->card_name = ECHOCARD_NAME;
919 chip->bad_board = TRUE; /* Set TRUE until DSP loaded */ 973 chip->bad_board = TRUE; /* Set TRUE until DSP loaded */
920 chip->dsp_code = NULL; /* Current DSP code not loaded */ 974 chip->dsp_code = NULL; /* Current DSP code not loaded */
921 chip->digital_mode = DIGITAL_MODE_NONE;
922 chip->input_clock = ECHO_CLOCK_INTERNAL;
923 chip->output_clock = ECHO_CLOCK_WORD;
924 chip->asic_loaded = FALSE; 975 chip->asic_loaded = FALSE;
925 memset(chip->comm_page, 0, sizeof(struct comm_page)); 976 memset(chip->comm_page, 0, sizeof(struct comm_page));
926 977
@@ -931,7 +982,6 @@ static int init_dsp_comm_page(struct echoaudio *chip)
931 chip->comm_page->midi_out_free_count = 982 chip->comm_page->midi_out_free_count =
932 cpu_to_le32(DSP_MIDI_OUT_FIFO_SIZE); 983 cpu_to_le32(DSP_MIDI_OUT_FIFO_SIZE);
933 chip->comm_page->sample_rate = cpu_to_le32(44100); 984 chip->comm_page->sample_rate = cpu_to_le32(44100);
934 chip->sample_rate = 44100;
935 985
936 /* Set line levels so we don't blast any inputs on startup */ 986 /* Set line levels so we don't blast any inputs on startup */
937 memset(chip->comm_page->monitors, ECHOGAIN_MUTED, MONITOR_ARRAY_SIZE); 987 memset(chip->comm_page->monitors, ECHOGAIN_MUTED, MONITOR_ARRAY_SIZE);
@@ -942,50 +992,21 @@ static int init_dsp_comm_page(struct echoaudio *chip)
942 992
943 993
944 994
945/* This function initializes the several volume controls for busses and pipes. 995/* This function initializes the chip structure with default values, ie. all
946This MUST be called after the DSP is up and running ! */ 996 * muted and internal clock source. Then it copies the settings to the DSP.
997 * This MUST be called after the DSP is up and running !
998 */
947static int init_line_levels(struct echoaudio *chip) 999static int init_line_levels(struct echoaudio *chip)
948{ 1000{
949 int st, i, o;
950
951 DE_INIT(("init_line_levels\n")); 1001 DE_INIT(("init_line_levels\n"));
952 1002 memset(chip->output_gain, ECHOGAIN_MUTED, sizeof(chip->output_gain));
953 /* Mute output busses */ 1003 memset(chip->input_gain, ECHOGAIN_MUTED, sizeof(chip->input_gain));
954 for (i = 0; i < num_busses_out(chip); i++) 1004 memset(chip->monitor_gain, ECHOGAIN_MUTED, sizeof(chip->monitor_gain));
955 if ((st = set_output_gain(chip, i, ECHOGAIN_MUTED))) 1005 memset(chip->vmixer_gain, ECHOGAIN_MUTED, sizeof(chip->vmixer_gain));
956 return st; 1006 chip->input_clock = ECHO_CLOCK_INTERNAL;
957 if ((st = update_output_line_level(chip))) 1007 chip->output_clock = ECHO_CLOCK_WORD;
958 return st; 1008 chip->sample_rate = 44100;
959 1009 return restore_dsp_rettings(chip);
960#ifdef ECHOCARD_HAS_VMIXER
961 /* Mute the Vmixer */
962 for (i = 0; i < num_pipes_out(chip); i++)
963 for (o = 0; o < num_busses_out(chip); o++)
964 if ((st = set_vmixer_gain(chip, o, i, ECHOGAIN_MUTED)))
965 return st;
966 if ((st = update_vmixer_level(chip)))
967 return st;
968#endif /* ECHOCARD_HAS_VMIXER */
969
970#ifdef ECHOCARD_HAS_MONITOR
971 /* Mute the monitor mixer */
972 for (o = 0; o < num_busses_out(chip); o++)
973 for (i = 0; i < num_busses_in(chip); i++)
974 if ((st = set_monitor_gain(chip, o, i, ECHOGAIN_MUTED)))
975 return st;
976 if ((st = update_output_line_level(chip)))
977 return st;
978#endif /* ECHOCARD_HAS_MONITOR */
979
980#ifdef ECHOCARD_HAS_INPUT_GAIN
981 for (i = 0; i < num_busses_in(chip); i++)
982 if ((st = set_input_gain(chip, i, ECHOGAIN_MUTED)))
983 return st;
984 if ((st = update_input_line_level(chip)))
985 return st;
986#endif /* ECHOCARD_HAS_INPUT_GAIN */
987
988 return 0;
989} 1010}
990 1011
991 1012
diff --git a/sound/pci/echoaudio/gina20.c b/sound/pci/echoaudio/gina20.c
index c0e64b8f52a4..050e54aa693f 100644
--- a/sound/pci/echoaudio/gina20.c
+++ b/sound/pci/echoaudio/gina20.c
@@ -44,9 +44,9 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/interrupt.h> 45#include <linux/interrupt.h>
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/slab.h>
48#include <linux/moduleparam.h> 47#include <linux/moduleparam.h>
49#include <linux/firmware.h> 48#include <linux/firmware.h>
49#include <linux/slab.h>
50#include <sound/core.h> 50#include <sound/core.h>
51#include <sound/info.h> 51#include <sound/info.h>
52#include <sound/control.h> 52#include <sound/control.h>
@@ -67,7 +67,7 @@ static const struct firmware card_fw[] = {
67 {0, "gina20_dsp.fw"} 67 {0, "gina20_dsp.fw"}
68}; 68};
69 69
70static struct pci_device_id snd_echo_ids[] = { 70static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
71 {0x1057, 0x1801, 0xECC0, 0x0020, 0, 0, 0}, /* DSP 56301 Gina20 rev.0 */ 71 {0x1057, 0x1801, 0xECC0, 0x0020, 0, 0, 0}, /* DSP 56301 Gina20 rev.0 */
72 {0,} 72 {0,}
73}; 73};
diff --git a/sound/pci/echoaudio/gina20_dsp.c b/sound/pci/echoaudio/gina20_dsp.c
index 3f1e7475faea..d1615a0579d1 100644
--- a/sound/pci/echoaudio/gina20_dsp.c
+++ b/sound/pci/echoaudio/gina20_dsp.c
@@ -49,7 +49,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
49 chip->device_id = device_id; 49 chip->device_id = device_id;
50 chip->subdevice_id = subdevice_id; 50 chip->subdevice_id = subdevice_id;
51 chip->bad_board = TRUE; 51 chip->bad_board = TRUE;
52 chip->dsp_code_to_load = &card_fw[FW_GINA20_DSP]; 52 chip->dsp_code_to_load = FW_GINA20_DSP;
53 chip->spdif_status = GD_SPDIF_STATUS_UNDEF; 53 chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
54 chip->clock_state = GD_CLOCK_UNDEF; 54 chip->clock_state = GD_CLOCK_UNDEF;
55 /* Since this card has no ASIC, mark it as loaded so everything 55 /* Since this card has no ASIC, mark it as loaded so everything
@@ -62,17 +62,20 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
62 return err; 62 return err;
63 chip->bad_board = FALSE; 63 chip->bad_board = FALSE;
64 64
65 if ((err = init_line_levels(chip)) < 0)
66 return err;
67
68 err = set_professional_spdif(chip, TRUE);
69
70 DE_INIT(("init_hw done\n")); 65 DE_INIT(("init_hw done\n"));
71 return err; 66 return err;
72} 67}
73 68
74 69
75 70
71static int set_mixer_defaults(struct echoaudio *chip)
72{
73 chip->professional_spdif = FALSE;
74 return init_line_levels(chip);
75}
76
77
78
76static u32 detect_input_clocks(const struct echoaudio *chip) 79static u32 detect_input_clocks(const struct echoaudio *chip)
77{ 80{
78 u32 clocks_from_dsp, clock_bits; 81 u32 clocks_from_dsp, clock_bits;
diff --git a/sound/pci/echoaudio/gina24.c b/sound/pci/echoaudio/gina24.c
index c36a78dd0b5e..5748fc6d29d6 100644
--- a/sound/pci/echoaudio/gina24.c
+++ b/sound/pci/echoaudio/gina24.c
@@ -50,9 +50,9 @@
50#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/interrupt.h> 51#include <linux/interrupt.h>
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/slab.h>
54#include <linux/moduleparam.h> 53#include <linux/moduleparam.h>
55#include <linux/firmware.h> 54#include <linux/firmware.h>
55#include <linux/slab.h>
56#include <sound/core.h> 56#include <sound/core.h>
57#include <sound/info.h> 57#include <sound/info.h>
58#include <sound/control.h> 58#include <sound/control.h>
@@ -85,7 +85,7 @@ static const struct firmware card_fw[] = {
85 {0, "gina24_361_asic.fw"} 85 {0, "gina24_361_asic.fw"}
86}; 86};
87 87
88static struct pci_device_id snd_echo_ids[] = { 88static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
89 {0x1057, 0x1801, 0xECC0, 0x0050, 0, 0, 0}, /* DSP 56301 Gina24 rev.0 */ 89 {0x1057, 0x1801, 0xECC0, 0x0050, 0, 0, 0}, /* DSP 56301 Gina24 rev.0 */
90 {0x1057, 0x1801, 0xECC0, 0x0051, 0, 0, 0}, /* DSP 56301 Gina24 rev.1 */ 90 {0x1057, 0x1801, 0xECC0, 0x0051, 0, 0, 0}, /* DSP 56301 Gina24 rev.1 */
91 {0x1057, 0x3410, 0xECC0, 0x0050, 0, 0, 0}, /* DSP 56361 Gina24 rev.0 */ 91 {0x1057, 0x3410, 0xECC0, 0x0050, 0, 0, 0}, /* DSP 56361 Gina24 rev.0 */
diff --git a/sound/pci/echoaudio/gina24_dsp.c b/sound/pci/echoaudio/gina24_dsp.c
index 2fef37a2a5b9..98f7cfa81b5f 100644
--- a/sound/pci/echoaudio/gina24_dsp.c
+++ b/sound/pci/echoaudio/gina24_dsp.c
@@ -33,8 +33,7 @@ static int write_control_reg(struct echoaudio *chip, u32 value, char force);
33static int set_input_clock(struct echoaudio *chip, u16 clock); 33static int set_input_clock(struct echoaudio *chip, u16 clock);
34static int set_professional_spdif(struct echoaudio *chip, char prof); 34static int set_professional_spdif(struct echoaudio *chip, char prof);
35static int set_digital_mode(struct echoaudio *chip, u8 mode); 35static int set_digital_mode(struct echoaudio *chip, u8 mode);
36static int load_asic_generic(struct echoaudio *chip, u32 cmd, 36static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
37 const struct firmware *asic);
38static int check_asic_status(struct echoaudio *chip); 37static int check_asic_status(struct echoaudio *chip);
39 38
40 39
@@ -58,19 +57,16 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
58 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF | 57 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF |
59 ECHO_CLOCK_BIT_ESYNC | ECHO_CLOCK_BIT_ESYNC96 | 58 ECHO_CLOCK_BIT_ESYNC | ECHO_CLOCK_BIT_ESYNC96 |
60 ECHO_CLOCK_BIT_ADAT; 59 ECHO_CLOCK_BIT_ADAT;
61 chip->professional_spdif = FALSE;
62 chip->digital_in_automute = TRUE;
63 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
64 60
65 /* Gina24 comes in both '301 and '361 flavors */ 61 /* Gina24 comes in both '301 and '361 flavors */
66 if (chip->device_id == DEVICE_ID_56361) { 62 if (chip->device_id == DEVICE_ID_56361) {
67 chip->dsp_code_to_load = &card_fw[FW_GINA24_361_DSP]; 63 chip->dsp_code_to_load = FW_GINA24_361_DSP;
68 chip->digital_modes = 64 chip->digital_modes =
69 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA | 65 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
70 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL | 66 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
71 ECHOCAPS_HAS_DIGITAL_MODE_ADAT; 67 ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
72 } else { 68 } else {
73 chip->dsp_code_to_load = &card_fw[FW_GINA24_301_DSP]; 69 chip->dsp_code_to_load = FW_GINA24_301_DSP;
74 chip->digital_modes = 70 chip->digital_modes =
75 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA | 71 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
76 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL | 72 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
@@ -82,19 +78,22 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
82 return err; 78 return err;
83 chip->bad_board = FALSE; 79 chip->bad_board = FALSE;
84 80
85 if ((err = init_line_levels(chip)) < 0)
86 return err;
87 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
88 if (err < 0)
89 return err;
90 err = set_professional_spdif(chip, TRUE);
91
92 DE_INIT(("init_hw done\n")); 81 DE_INIT(("init_hw done\n"));
93 return err; 82 return err;
94} 83}
95 84
96 85
97 86
87static int set_mixer_defaults(struct echoaudio *chip)
88{
89 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
90 chip->professional_spdif = FALSE;
91 chip->digital_in_automute = TRUE;
92 return init_line_levels(chip);
93}
94
95
96
98static u32 detect_input_clocks(const struct echoaudio *chip) 97static u32 detect_input_clocks(const struct echoaudio *chip)
99{ 98{
100 u32 clocks_from_dsp, clock_bits; 99 u32 clocks_from_dsp, clock_bits;
@@ -125,7 +124,7 @@ static int load_asic(struct echoaudio *chip)
125{ 124{
126 u32 control_reg; 125 u32 control_reg;
127 int err; 126 int err;
128 const struct firmware *fw; 127 short asic;
129 128
130 if (chip->asic_loaded) 129 if (chip->asic_loaded)
131 return 1; 130 return 1;
@@ -135,14 +134,15 @@ static int load_asic(struct echoaudio *chip)
135 134
136 /* Pick the correct ASIC for '301 or '361 Gina24 */ 135 /* Pick the correct ASIC for '301 or '361 Gina24 */
137 if (chip->device_id == DEVICE_ID_56361) 136 if (chip->device_id == DEVICE_ID_56361)
138 fw = &card_fw[FW_GINA24_361_ASIC]; 137 asic = FW_GINA24_361_ASIC;
139 else 138 else
140 fw = &card_fw[FW_GINA24_301_ASIC]; 139 asic = FW_GINA24_301_ASIC;
141 140
142 if ((err = load_asic_generic(chip, DSP_FNC_LOAD_GINA24_ASIC, fw)) < 0) 141 err = load_asic_generic(chip, DSP_FNC_LOAD_GINA24_ASIC, asic);
142 if (err < 0)
143 return err; 143 return err;
144 144
145 chip->asic_code = fw; 145 chip->asic_code = asic;
146 146
147 /* Now give the new ASIC a little time to set up */ 147 /* Now give the new ASIC a little time to set up */
148 mdelay(10); 148 mdelay(10);
diff --git a/sound/pci/echoaudio/indigo.c b/sound/pci/echoaudio/indigo.c
index 0a58a7c1fd7c..4ae5e35cb5f1 100644
--- a/sound/pci/echoaudio/indigo.c
+++ b/sound/pci/echoaudio/indigo.c
@@ -42,9 +42,9 @@
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/slab.h>
46#include <linux/moduleparam.h> 45#include <linux/moduleparam.h>
47#include <linux/firmware.h> 46#include <linux/firmware.h>
47#include <linux/slab.h>
48#include <sound/core.h> 48#include <sound/core.h>
49#include <sound/info.h> 49#include <sound/info.h>
50#include <sound/control.h> 50#include <sound/control.h>
@@ -68,7 +68,7 @@ static const struct firmware card_fw[] = {
68 {0, "indigo_dsp.fw"} 68 {0, "indigo_dsp.fw"}
69}; 69};
70 70
71static struct pci_device_id snd_echo_ids[] = { 71static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
72 {0x1057, 0x3410, 0xECC0, 0x0090, 0, 0, 0}, /* Indigo */ 72 {0x1057, 0x3410, 0xECC0, 0x0090, 0, 0, 0}, /* Indigo */
73 {0,} 73 {0,}
74}; 74};
diff --git a/sound/pci/echoaudio/indigo_dsp.c b/sound/pci/echoaudio/indigo_dsp.c
index 0b2cd9c86277..5e85f14fe5a8 100644
--- a/sound/pci/echoaudio/indigo_dsp.c
+++ b/sound/pci/echoaudio/indigo_dsp.c
@@ -50,7 +50,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
50 chip->device_id = device_id; 50 chip->device_id = device_id;
51 chip->subdevice_id = subdevice_id; 51 chip->subdevice_id = subdevice_id;
52 chip->bad_board = TRUE; 52 chip->bad_board = TRUE;
53 chip->dsp_code_to_load = &card_fw[FW_INDIGO_DSP]; 53 chip->dsp_code_to_load = FW_INDIGO_DSP;
54 /* Since this card has no ASIC, mark it as loaded so everything 54 /* Since this card has no ASIC, mark it as loaded so everything
55 works OK */ 55 works OK */
56 chip->asic_loaded = TRUE; 56 chip->asic_loaded = TRUE;
@@ -60,15 +60,19 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
60 return err; 60 return err;
61 chip->bad_board = FALSE; 61 chip->bad_board = FALSE;
62 62
63 if ((err = init_line_levels(chip)) < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n")); 63 DE_INIT(("init_hw done\n"));
67 return err; 64 return err;
68} 65}
69 66
70 67
71 68
69static int set_mixer_defaults(struct echoaudio *chip)
70{
71 return init_line_levels(chip);
72}
73
74
75
72static u32 detect_input_clocks(const struct echoaudio *chip) 76static u32 detect_input_clocks(const struct echoaudio *chip)
73{ 77{
74 return ECHO_CLOCK_BIT_INTERNAL; 78 return ECHO_CLOCK_BIT_INTERNAL;
diff --git a/sound/pci/echoaudio/indigo_express_dsp.c b/sound/pci/echoaudio/indigo_express_dsp.c
index 9ab625e15652..2e4ab3e34a74 100644
--- a/sound/pci/echoaudio/indigo_express_dsp.c
+++ b/sound/pci/echoaudio/indigo_express_dsp.c
@@ -61,6 +61,7 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
61 61
62 control_reg |= clock; 62 control_reg |= clock;
63 if (control_reg != old_control_reg) { 63 if (control_reg != old_control_reg) {
64 DE_ACT(("set_sample_rate: %d clock %d\n", rate, clock));
64 chip->comm_page->control_register = cpu_to_le32(control_reg); 65 chip->comm_page->control_register = cpu_to_le32(control_reg);
65 chip->sample_rate = rate; 66 chip->sample_rate = rate;
66 clear_handshake(chip); 67 clear_handshake(chip);
diff --git a/sound/pci/echoaudio/indigodj.c b/sound/pci/echoaudio/indigodj.c
index 2db24d29332b..3550715bab1c 100644
--- a/sound/pci/echoaudio/indigodj.c
+++ b/sound/pci/echoaudio/indigodj.c
@@ -42,9 +42,9 @@
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/slab.h>
46#include <linux/moduleparam.h> 45#include <linux/moduleparam.h>
47#include <linux/firmware.h> 46#include <linux/firmware.h>
47#include <linux/slab.h>
48#include <sound/core.h> 48#include <sound/core.h>
49#include <sound/info.h> 49#include <sound/info.h>
50#include <sound/control.h> 50#include <sound/control.h>
@@ -68,7 +68,7 @@ static const struct firmware card_fw[] = {
68 {0, "indigo_dj_dsp.fw"} 68 {0, "indigo_dj_dsp.fw"}
69}; 69};
70 70
71static struct pci_device_id snd_echo_ids[] = { 71static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
72 {0x1057, 0x3410, 0xECC0, 0x00B0, 0, 0, 0}, /* Indigo DJ*/ 72 {0x1057, 0x3410, 0xECC0, 0x00B0, 0, 0, 0}, /* Indigo DJ*/
73 {0,} 73 {0,}
74}; 74};
diff --git a/sound/pci/echoaudio/indigodj_dsp.c b/sound/pci/echoaudio/indigodj_dsp.c
index 08392916691e..68f3c8ccc1bf 100644
--- a/sound/pci/echoaudio/indigodj_dsp.c
+++ b/sound/pci/echoaudio/indigodj_dsp.c
@@ -50,7 +50,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
50 chip->device_id = device_id; 50 chip->device_id = device_id;
51 chip->subdevice_id = subdevice_id; 51 chip->subdevice_id = subdevice_id;
52 chip->bad_board = TRUE; 52 chip->bad_board = TRUE;
53 chip->dsp_code_to_load = &card_fw[FW_INDIGO_DJ_DSP]; 53 chip->dsp_code_to_load = FW_INDIGO_DJ_DSP;
54 /* Since this card has no ASIC, mark it as loaded so everything 54 /* Since this card has no ASIC, mark it as loaded so everything
55 works OK */ 55 works OK */
56 chip->asic_loaded = TRUE; 56 chip->asic_loaded = TRUE;
@@ -60,15 +60,19 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
60 return err; 60 return err;
61 chip->bad_board = FALSE; 61 chip->bad_board = FALSE;
62 62
63 if ((err = init_line_levels(chip)) < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n")); 63 DE_INIT(("init_hw done\n"));
67 return err; 64 return err;
68} 65}
69 66
70 67
71 68
69static int set_mixer_defaults(struct echoaudio *chip)
70{
71 return init_line_levels(chip);
72}
73
74
75
72static u32 detect_input_clocks(const struct echoaudio *chip) 76static u32 detect_input_clocks(const struct echoaudio *chip)
73{ 77{
74 return ECHO_CLOCK_BIT_INTERNAL; 78 return ECHO_CLOCK_BIT_INTERNAL;
diff --git a/sound/pci/echoaudio/indigodjx.c b/sound/pci/echoaudio/indigodjx.c
index 2e44316530a2..19b191fd0120 100644
--- a/sound/pci/echoaudio/indigodjx.c
+++ b/sound/pci/echoaudio/indigodjx.c
@@ -42,10 +42,10 @@
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/slab.h>
46#include <linux/moduleparam.h> 45#include <linux/moduleparam.h>
47#include <linux/firmware.h> 46#include <linux/firmware.h>
48#include <linux/io.h> 47#include <linux/io.h>
48#include <linux/slab.h>
49#include <sound/core.h> 49#include <sound/core.h>
50#include <sound/info.h> 50#include <sound/info.h>
51#include <sound/control.h> 51#include <sound/control.h>
@@ -68,7 +68,7 @@ static const struct firmware card_fw[] = {
68 {0, "indigo_djx_dsp.fw"} 68 {0, "indigo_djx_dsp.fw"}
69}; 69};
70 70
71static struct pci_device_id snd_echo_ids[] = { 71static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
72 {0x1057, 0x3410, 0xECC0, 0x00E0, 0, 0, 0}, /* Indigo DJx*/ 72 {0x1057, 0x3410, 0xECC0, 0x00E0, 0, 0, 0}, /* Indigo DJx*/
73 {0,} 73 {0,}
74}; 74};
diff --git a/sound/pci/echoaudio/indigodjx_dsp.c b/sound/pci/echoaudio/indigodjx_dsp.c
index f591fc2ed960..bb9632c752a9 100644
--- a/sound/pci/echoaudio/indigodjx_dsp.c
+++ b/sound/pci/echoaudio/indigodjx_dsp.c
@@ -48,7 +48,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
48 chip->device_id = device_id; 48 chip->device_id = device_id;
49 chip->subdevice_id = subdevice_id; 49 chip->subdevice_id = subdevice_id;
50 chip->bad_board = TRUE; 50 chip->bad_board = TRUE;
51 chip->dsp_code_to_load = &card_fw[FW_INDIGO_DJX_DSP]; 51 chip->dsp_code_to_load = FW_INDIGO_DJX_DSP;
52 /* Since this card has no ASIC, mark it as loaded so everything 52 /* Since this card has no ASIC, mark it as loaded so everything
53 works OK */ 53 works OK */
54 chip->asic_loaded = TRUE; 54 chip->asic_loaded = TRUE;
@@ -59,10 +59,13 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
59 return err; 59 return err;
60 chip->bad_board = FALSE; 60 chip->bad_board = FALSE;
61 61
62 err = init_line_levels(chip);
63 if (err < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n")); 62 DE_INIT(("init_hw done\n"));
67 return err; 63 return err;
68} 64}
65
66
67
68static int set_mixer_defaults(struct echoaudio *chip)
69{
70 return init_line_levels(chip);
71}
diff --git a/sound/pci/echoaudio/indigoio.c b/sound/pci/echoaudio/indigoio.c
index a60c0a0a89b7..a9fcedf317a4 100644
--- a/sound/pci/echoaudio/indigoio.c
+++ b/sound/pci/echoaudio/indigoio.c
@@ -43,9 +43,9 @@
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/interrupt.h> 44#include <linux/interrupt.h>
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/slab.h>
47#include <linux/moduleparam.h> 46#include <linux/moduleparam.h>
48#include <linux/firmware.h> 47#include <linux/firmware.h>
48#include <linux/slab.h>
49#include <sound/core.h> 49#include <sound/core.h>
50#include <sound/info.h> 50#include <sound/info.h>
51#include <sound/control.h> 51#include <sound/control.h>
@@ -69,7 +69,7 @@ static const struct firmware card_fw[] = {
69 {0, "indigo_io_dsp.fw"} 69 {0, "indigo_io_dsp.fw"}
70}; 70};
71 71
72static struct pci_device_id snd_echo_ids[] = { 72static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
73 {0x1057, 0x3410, 0xECC0, 0x00A0, 0, 0, 0}, /* Indigo IO*/ 73 {0x1057, 0x3410, 0xECC0, 0x00A0, 0, 0, 0}, /* Indigo IO*/
74 {0,} 74 {0,}
75}; 75};
diff --git a/sound/pci/echoaudio/indigoio_dsp.c b/sound/pci/echoaudio/indigoio_dsp.c
index 0604c8a85223..beb9a5b69892 100644
--- a/sound/pci/echoaudio/indigoio_dsp.c
+++ b/sound/pci/echoaudio/indigoio_dsp.c
@@ -50,7 +50,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
50 chip->device_id = device_id; 50 chip->device_id = device_id;
51 chip->subdevice_id = subdevice_id; 51 chip->subdevice_id = subdevice_id;
52 chip->bad_board = TRUE; 52 chip->bad_board = TRUE;
53 chip->dsp_code_to_load = &card_fw[FW_INDIGO_IO_DSP]; 53 chip->dsp_code_to_load = FW_INDIGO_IO_DSP;
54 /* Since this card has no ASIC, mark it as loaded so everything 54 /* Since this card has no ASIC, mark it as loaded so everything
55 works OK */ 55 works OK */
56 chip->asic_loaded = TRUE; 56 chip->asic_loaded = TRUE;
@@ -60,15 +60,19 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
60 return err; 60 return err;
61 chip->bad_board = FALSE; 61 chip->bad_board = FALSE;
62 62
63 if ((err = init_line_levels(chip)) < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n")); 63 DE_INIT(("init_hw done\n"));
67 return err; 64 return err;
68} 65}
69 66
70 67
71 68
69static int set_mixer_defaults(struct echoaudio *chip)
70{
71 return init_line_levels(chip);
72}
73
74
75
72static u32 detect_input_clocks(const struct echoaudio *chip) 76static u32 detect_input_clocks(const struct echoaudio *chip)
73{ 77{
74 return ECHO_CLOCK_BIT_INTERNAL; 78 return ECHO_CLOCK_BIT_INTERNAL;
diff --git a/sound/pci/echoaudio/indigoiox.c b/sound/pci/echoaudio/indigoiox.c
index eb3819f9654a..bcdfac63212c 100644
--- a/sound/pci/echoaudio/indigoiox.c
+++ b/sound/pci/echoaudio/indigoiox.c
@@ -43,10 +43,10 @@
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/interrupt.h> 44#include <linux/interrupt.h>
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/slab.h>
47#include <linux/moduleparam.h> 46#include <linux/moduleparam.h>
48#include <linux/firmware.h> 47#include <linux/firmware.h>
49#include <linux/io.h> 48#include <linux/io.h>
49#include <linux/slab.h>
50#include <sound/core.h> 50#include <sound/core.h>
51#include <sound/info.h> 51#include <sound/info.h>
52#include <sound/control.h> 52#include <sound/control.h>
@@ -69,7 +69,7 @@ static const struct firmware card_fw[] = {
69 {0, "indigo_iox_dsp.fw"} 69 {0, "indigo_iox_dsp.fw"}
70}; 70};
71 71
72static struct pci_device_id snd_echo_ids[] = { 72static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
73 {0x1057, 0x3410, 0xECC0, 0x00D0, 0, 0, 0}, /* Indigo IOx */ 73 {0x1057, 0x3410, 0xECC0, 0x00D0, 0, 0, 0}, /* Indigo IOx */
74 {0,} 74 {0,}
75}; 75};
diff --git a/sound/pci/echoaudio/indigoiox_dsp.c b/sound/pci/echoaudio/indigoiox_dsp.c
index f357521c79e6..394c6e76bcbc 100644
--- a/sound/pci/echoaudio/indigoiox_dsp.c
+++ b/sound/pci/echoaudio/indigoiox_dsp.c
@@ -48,7 +48,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
48 chip->device_id = device_id; 48 chip->device_id = device_id;
49 chip->subdevice_id = subdevice_id; 49 chip->subdevice_id = subdevice_id;
50 chip->bad_board = TRUE; 50 chip->bad_board = TRUE;
51 chip->dsp_code_to_load = &card_fw[FW_INDIGO_IOX_DSP]; 51 chip->dsp_code_to_load = FW_INDIGO_IOX_DSP;
52 /* Since this card has no ASIC, mark it as loaded so everything 52 /* Since this card has no ASIC, mark it as loaded so everything
53 works OK */ 53 works OK */
54 chip->asic_loaded = TRUE; 54 chip->asic_loaded = TRUE;
@@ -59,10 +59,13 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
59 return err; 59 return err;
60 chip->bad_board = FALSE; 60 chip->bad_board = FALSE;
61 61
62 err = init_line_levels(chip);
63 if (err < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n")); 62 DE_INIT(("init_hw done\n"));
67 return err; 63 return err;
68} 64}
65
66
67
68static int set_mixer_defaults(struct echoaudio *chip)
69{
70 return init_line_levels(chip);
71}
diff --git a/sound/pci/echoaudio/layla20.c b/sound/pci/echoaudio/layla20.c
index 506194688995..d3a98c5dac86 100644
--- a/sound/pci/echoaudio/layla20.c
+++ b/sound/pci/echoaudio/layla20.c
@@ -49,9 +49,9 @@
49#include <linux/init.h> 49#include <linux/init.h>
50#include <linux/interrupt.h> 50#include <linux/interrupt.h>
51#include <linux/pci.h> 51#include <linux/pci.h>
52#include <linux/slab.h>
53#include <linux/moduleparam.h> 52#include <linux/moduleparam.h>
54#include <linux/firmware.h> 53#include <linux/firmware.h>
54#include <linux/slab.h>
55#include <sound/core.h> 55#include <sound/core.h>
56#include <sound/info.h> 56#include <sound/info.h>
57#include <sound/control.h> 57#include <sound/control.h>
@@ -76,7 +76,7 @@ static const struct firmware card_fw[] = {
76 {0, "layla20_asic.fw"} 76 {0, "layla20_asic.fw"}
77}; 77};
78 78
79static struct pci_device_id snd_echo_ids[] = { 79static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
80 {0x1057, 0x1801, 0xECC0, 0x0030, 0, 0, 0}, /* DSP 56301 Layla20 rev.0 */ 80 {0x1057, 0x1801, 0xECC0, 0x0030, 0, 0, 0}, /* DSP 56301 Layla20 rev.0 */
81 {0x1057, 0x1801, 0xECC0, 0x0031, 0, 0, 0}, /* DSP 56301 Layla20 rev.1 */ 81 {0x1057, 0x1801, 0xECC0, 0x0031, 0, 0, 0}, /* DSP 56301 Layla20 rev.1 */
82 {0,} 82 {0,}
diff --git a/sound/pci/echoaudio/layla20_dsp.c b/sound/pci/echoaudio/layla20_dsp.c
index 83750e9fd7b4..53ce94605044 100644
--- a/sound/pci/echoaudio/layla20_dsp.c
+++ b/sound/pci/echoaudio/layla20_dsp.c
@@ -31,8 +31,7 @@
31 31
32static int read_dsp(struct echoaudio *chip, u32 *data); 32static int read_dsp(struct echoaudio *chip, u32 *data);
33static int set_professional_spdif(struct echoaudio *chip, char prof); 33static int set_professional_spdif(struct echoaudio *chip, char prof);
34static int load_asic_generic(struct echoaudio *chip, u32 cmd, 34static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
35 const struct firmware *asic);
36static int check_asic_status(struct echoaudio *chip); 35static int check_asic_status(struct echoaudio *chip);
37static int update_flags(struct echoaudio *chip); 36static int update_flags(struct echoaudio *chip);
38 37
@@ -54,7 +53,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
54 chip->subdevice_id = subdevice_id; 53 chip->subdevice_id = subdevice_id;
55 chip->bad_board = TRUE; 54 chip->bad_board = TRUE;
56 chip->has_midi = TRUE; 55 chip->has_midi = TRUE;
57 chip->dsp_code_to_load = &card_fw[FW_LAYLA20_DSP]; 56 chip->dsp_code_to_load = FW_LAYLA20_DSP;
58 chip->input_clock_types = 57 chip->input_clock_types =
59 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF | 58 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF |
60 ECHO_CLOCK_BIT_WORD | ECHO_CLOCK_BIT_SUPER; 59 ECHO_CLOCK_BIT_WORD | ECHO_CLOCK_BIT_SUPER;
@@ -65,17 +64,20 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
65 return err; 64 return err;
66 chip->bad_board = FALSE; 65 chip->bad_board = FALSE;
67 66
68 if ((err = init_line_levels(chip)) < 0)
69 return err;
70
71 err = set_professional_spdif(chip, TRUE);
72
73 DE_INIT(("init_hw done\n")); 67 DE_INIT(("init_hw done\n"));
74 return err; 68 return err;
75} 69}
76 70
77 71
78 72
73static int set_mixer_defaults(struct echoaudio *chip)
74{
75 chip->professional_spdif = FALSE;
76 return init_line_levels(chip);
77}
78
79
80
79static u32 detect_input_clocks(const struct echoaudio *chip) 81static u32 detect_input_clocks(const struct echoaudio *chip)
80{ 82{
81 u32 clocks_from_dsp, clock_bits; 83 u32 clocks_from_dsp, clock_bits;
@@ -144,7 +146,7 @@ static int load_asic(struct echoaudio *chip)
144 return 0; 146 return 0;
145 147
146 err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA_ASIC, 148 err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA_ASIC,
147 &card_fw[FW_LAYLA20_ASIC]); 149 FW_LAYLA20_ASIC);
148 if (err < 0) 150 if (err < 0)
149 return err; 151 return err;
150 152
diff --git a/sound/pci/echoaudio/layla24.c b/sound/pci/echoaudio/layla24.c
index e09e3ea7781e..2a1dca6dce17 100644
--- a/sound/pci/echoaudio/layla24.c
+++ b/sound/pci/echoaudio/layla24.c
@@ -51,9 +51,9 @@
51#include <linux/init.h> 51#include <linux/init.h>
52#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53#include <linux/pci.h> 53#include <linux/pci.h>
54#include <linux/slab.h>
55#include <linux/moduleparam.h> 54#include <linux/moduleparam.h>
56#include <linux/firmware.h> 55#include <linux/firmware.h>
56#include <linux/slab.h>
57#include <sound/core.h> 57#include <sound/core.h>
58#include <sound/info.h> 58#include <sound/info.h>
59#include <sound/control.h> 59#include <sound/control.h>
@@ -87,7 +87,7 @@ static const struct firmware card_fw[] = {
87 {0, "layla24_2S_asic.fw"} 87 {0, "layla24_2S_asic.fw"}
88}; 88};
89 89
90static struct pci_device_id snd_echo_ids[] = { 90static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
91 {0x1057, 0x3410, 0xECC0, 0x0060, 0, 0, 0}, /* DSP 56361 Layla24 rev.0 */ 91 {0x1057, 0x3410, 0xECC0, 0x0060, 0, 0, 0}, /* DSP 56361 Layla24 rev.0 */
92 {0,} 92 {0,}
93}; 93};
diff --git a/sound/pci/echoaudio/layla24_dsp.c b/sound/pci/echoaudio/layla24_dsp.c
index d61b5cbcccad..8c041647f285 100644
--- a/sound/pci/echoaudio/layla24_dsp.c
+++ b/sound/pci/echoaudio/layla24_dsp.c
@@ -32,8 +32,7 @@ static int write_control_reg(struct echoaudio *chip, u32 value, char force);
32static int set_input_clock(struct echoaudio *chip, u16 clock); 32static int set_input_clock(struct echoaudio *chip, u16 clock);
33static int set_professional_spdif(struct echoaudio *chip, char prof); 33static int set_professional_spdif(struct echoaudio *chip, char prof);
34static int set_digital_mode(struct echoaudio *chip, u8 mode); 34static int set_digital_mode(struct echoaudio *chip, u8 mode);
35static int load_asic_generic(struct echoaudio *chip, u32 cmd, 35static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
36 const struct firmware *asic);
37static int check_asic_status(struct echoaudio *chip); 36static int check_asic_status(struct echoaudio *chip);
38 37
39 38
@@ -54,7 +53,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
54 chip->subdevice_id = subdevice_id; 53 chip->subdevice_id = subdevice_id;
55 chip->bad_board = TRUE; 54 chip->bad_board = TRUE;
56 chip->has_midi = TRUE; 55 chip->has_midi = TRUE;
57 chip->dsp_code_to_load = &card_fw[FW_LAYLA24_DSP]; 56 chip->dsp_code_to_load = FW_LAYLA24_DSP;
58 chip->input_clock_types = 57 chip->input_clock_types =
59 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF | 58 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF |
60 ECHO_CLOCK_BIT_WORD | ECHO_CLOCK_BIT_ADAT; 59 ECHO_CLOCK_BIT_WORD | ECHO_CLOCK_BIT_ADAT;
@@ -62,9 +61,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
62 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA | 61 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
63 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL | 62 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
64 ECHOCAPS_HAS_DIGITAL_MODE_ADAT; 63 ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
65 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
66 chip->professional_spdif = FALSE;
67 chip->digital_in_automute = TRUE;
68 64
69 if ((err = load_firmware(chip)) < 0) 65 if ((err = load_firmware(chip)) < 0)
70 return err; 66 return err;
@@ -73,17 +69,22 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
73 if ((err = init_line_levels(chip)) < 0) 69 if ((err = init_line_levels(chip)) < 0)
74 return err; 70 return err;
75 71
76 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
77 if (err < 0)
78 return err;
79 err = set_professional_spdif(chip, TRUE);
80
81 DE_INIT(("init_hw done\n")); 72 DE_INIT(("init_hw done\n"));
82 return err; 73 return err;
83} 74}
84 75
85 76
86 77
78static int set_mixer_defaults(struct echoaudio *chip)
79{
80 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
81 chip->professional_spdif = FALSE;
82 chip->digital_in_automute = TRUE;
83 return init_line_levels(chip);
84}
85
86
87
87static u32 detect_input_clocks(const struct echoaudio *chip) 88static u32 detect_input_clocks(const struct echoaudio *chip)
88{ 89{
89 u32 clocks_from_dsp, clock_bits; 90 u32 clocks_from_dsp, clock_bits;
@@ -123,18 +124,18 @@ static int load_asic(struct echoaudio *chip)
123 124
124 /* Load the ASIC for the PCI card */ 125 /* Load the ASIC for the PCI card */
125 err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA24_PCI_CARD_ASIC, 126 err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA24_PCI_CARD_ASIC,
126 &card_fw[FW_LAYLA24_1_ASIC]); 127 FW_LAYLA24_1_ASIC);
127 if (err < 0) 128 if (err < 0)
128 return err; 129 return err;
129 130
130 chip->asic_code = &card_fw[FW_LAYLA24_2S_ASIC]; 131 chip->asic_code = FW_LAYLA24_2S_ASIC;
131 132
132 /* Now give the new ASIC a little time to set up */ 133 /* Now give the new ASIC a little time to set up */
133 mdelay(10); 134 mdelay(10);
134 135
135 /* Do the external one */ 136 /* Do the external one */
136 err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA24_EXTERNAL_ASIC, 137 err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA24_EXTERNAL_ASIC,
137 &card_fw[FW_LAYLA24_2S_ASIC]); 138 FW_LAYLA24_2S_ASIC);
138 if (err < 0) 139 if (err < 0)
139 return FALSE; 140 return FALSE;
140 141
@@ -299,7 +300,7 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
299/* Depending on what digital mode you want, Layla24 needs different ASICs 300/* Depending on what digital mode you want, Layla24 needs different ASICs
300loaded. This function checks the ASIC needed for the new mode and sees 301loaded. This function checks the ASIC needed for the new mode and sees
301if it matches the one already loaded. */ 302if it matches the one already loaded. */
302static int switch_asic(struct echoaudio *chip, const struct firmware *asic) 303static int switch_asic(struct echoaudio *chip, short asic)
303{ 304{
304 s8 *monitors; 305 s8 *monitors;
305 306
@@ -335,7 +336,7 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
335{ 336{
336 u32 control_reg; 337 u32 control_reg;
337 int err, incompatible_clock; 338 int err, incompatible_clock;
338 const struct firmware *asic; 339 short asic;
339 340
340 /* Set clock to "internal" if it's not compatible with the new mode */ 341 /* Set clock to "internal" if it's not compatible with the new mode */
341 incompatible_clock = FALSE; 342 incompatible_clock = FALSE;
@@ -344,12 +345,12 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
344 case DIGITAL_MODE_SPDIF_RCA: 345 case DIGITAL_MODE_SPDIF_RCA:
345 if (chip->input_clock == ECHO_CLOCK_ADAT) 346 if (chip->input_clock == ECHO_CLOCK_ADAT)
346 incompatible_clock = TRUE; 347 incompatible_clock = TRUE;
347 asic = &card_fw[FW_LAYLA24_2S_ASIC]; 348 asic = FW_LAYLA24_2S_ASIC;
348 break; 349 break;
349 case DIGITAL_MODE_ADAT: 350 case DIGITAL_MODE_ADAT:
350 if (chip->input_clock == ECHO_CLOCK_SPDIF) 351 if (chip->input_clock == ECHO_CLOCK_SPDIF)
351 incompatible_clock = TRUE; 352 incompatible_clock = TRUE;
352 asic = &card_fw[FW_LAYLA24_2A_ASIC]; 353 asic = FW_LAYLA24_2A_ASIC;
353 break; 354 break;
354 default: 355 default:
355 DE_ACT(("Digital mode not supported: %d\n", mode)); 356 DE_ACT(("Digital mode not supported: %d\n", mode));
diff --git a/sound/pci/echoaudio/mia.c b/sound/pci/echoaudio/mia.c
index f05c8c097aa8..9cdf14cfdd74 100644
--- a/sound/pci/echoaudio/mia.c
+++ b/sound/pci/echoaudio/mia.c
@@ -50,9 +50,9 @@
50#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/interrupt.h> 51#include <linux/interrupt.h>
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/slab.h>
54#include <linux/moduleparam.h> 53#include <linux/moduleparam.h>
55#include <linux/firmware.h> 54#include <linux/firmware.h>
55#include <linux/slab.h>
56#include <sound/core.h> 56#include <sound/core.h>
57#include <sound/info.h> 57#include <sound/info.h>
58#include <sound/control.h> 58#include <sound/control.h>
@@ -77,7 +77,7 @@ static const struct firmware card_fw[] = {
77 {0, "mia_dsp.fw"} 77 {0, "mia_dsp.fw"}
78}; 78};
79 79
80static struct pci_device_id snd_echo_ids[] = { 80static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
81 {0x1057, 0x3410, 0xECC0, 0x0080, 0, 0, 0}, /* DSP 56361 Mia rev.0 */ 81 {0x1057, 0x3410, 0xECC0, 0x0080, 0, 0, 0}, /* DSP 56361 Mia rev.0 */
82 {0x1057, 0x3410, 0xECC0, 0x0081, 0, 0, 0}, /* DSP 56361 Mia rev.1 */ 82 {0x1057, 0x3410, 0xECC0, 0x0081, 0, 0, 0}, /* DSP 56361 Mia rev.1 */
83 {0,} 83 {0,}
diff --git a/sound/pci/echoaudio/mia_dsp.c b/sound/pci/echoaudio/mia_dsp.c
index 551405114cbc..6ebfa6e7ab9e 100644
--- a/sound/pci/echoaudio/mia_dsp.c
+++ b/sound/pci/echoaudio/mia_dsp.c
@@ -53,7 +53,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
53 chip->device_id = device_id; 53 chip->device_id = device_id;
54 chip->subdevice_id = subdevice_id; 54 chip->subdevice_id = subdevice_id;
55 chip->bad_board = TRUE; 55 chip->bad_board = TRUE;
56 chip->dsp_code_to_load = &card_fw[FW_MIA_DSP]; 56 chip->dsp_code_to_load = FW_MIA_DSP;
57 /* Since this card has no ASIC, mark it as loaded so everything 57 /* Since this card has no ASIC, mark it as loaded so everything
58 works OK */ 58 works OK */
59 chip->asic_loaded = TRUE; 59 chip->asic_loaded = TRUE;
@@ -66,15 +66,19 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
66 return err; 66 return err;
67 chip->bad_board = FALSE; 67 chip->bad_board = FALSE;
68 68
69 if ((err = init_line_levels(chip)))
70 return err;
71
72 DE_INIT(("init_hw done\n")); 69 DE_INIT(("init_hw done\n"));
73 return err; 70 return err;
74} 71}
75 72
76 73
77 74
75static int set_mixer_defaults(struct echoaudio *chip)
76{
77 return init_line_levels(chip);
78}
79
80
81
78static u32 detect_input_clocks(const struct echoaudio *chip) 82static u32 detect_input_clocks(const struct echoaudio *chip)
79{ 83{
80 u32 clocks_from_dsp, clock_bits; 84 u32 clocks_from_dsp, clock_bits;
diff --git a/sound/pci/echoaudio/mona.c b/sound/pci/echoaudio/mona.c
index b05bad944901..1047be405ebe 100644
--- a/sound/pci/echoaudio/mona.c
+++ b/sound/pci/echoaudio/mona.c
@@ -48,9 +48,9 @@
48#include <linux/init.h> 48#include <linux/init.h>
49#include <linux/interrupt.h> 49#include <linux/interrupt.h>
50#include <linux/pci.h> 50#include <linux/pci.h>
51#include <linux/slab.h>
52#include <linux/moduleparam.h> 51#include <linux/moduleparam.h>
53#include <linux/firmware.h> 52#include <linux/firmware.h>
53#include <linux/slab.h>
54#include <sound/core.h> 54#include <sound/core.h>
55#include <sound/info.h> 55#include <sound/info.h>
56#include <sound/control.h> 56#include <sound/control.h>
@@ -92,7 +92,7 @@ static const struct firmware card_fw[] = {
92 {0, "mona_2_asic.fw"} 92 {0, "mona_2_asic.fw"}
93}; 93};
94 94
95static struct pci_device_id snd_echo_ids[] = { 95static DEFINE_PCI_DEVICE_TABLE(snd_echo_ids) = {
96 {0x1057, 0x1801, 0xECC0, 0x0070, 0, 0, 0}, /* DSP 56301 Mona rev.0 */ 96 {0x1057, 0x1801, 0xECC0, 0x0070, 0, 0, 0}, /* DSP 56301 Mona rev.0 */
97 {0x1057, 0x1801, 0xECC0, 0x0071, 0, 0, 0}, /* DSP 56301 Mona rev.1 */ 97 {0x1057, 0x1801, 0xECC0, 0x0071, 0, 0, 0}, /* DSP 56301 Mona rev.1 */
98 {0x1057, 0x1801, 0xECC0, 0x0072, 0, 0, 0}, /* DSP 56301 Mona rev.2 */ 98 {0x1057, 0x1801, 0xECC0, 0x0072, 0, 0, 0}, /* DSP 56301 Mona rev.2 */
diff --git a/sound/pci/echoaudio/mona_dsp.c b/sound/pci/echoaudio/mona_dsp.c
index eaa619bd2a03..6e6a7eb555b8 100644
--- a/sound/pci/echoaudio/mona_dsp.c
+++ b/sound/pci/echoaudio/mona_dsp.c
@@ -33,8 +33,7 @@ static int write_control_reg(struct echoaudio *chip, u32 value, char force);
33static int set_input_clock(struct echoaudio *chip, u16 clock); 33static int set_input_clock(struct echoaudio *chip, u16 clock);
34static int set_professional_spdif(struct echoaudio *chip, char prof); 34static int set_professional_spdif(struct echoaudio *chip, char prof);
35static int set_digital_mode(struct echoaudio *chip, u8 mode); 35static int set_digital_mode(struct echoaudio *chip, u8 mode);
36static int load_asic_generic(struct echoaudio *chip, u32 cmd, 36static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
37 const struct firmware *asic);
38static int check_asic_status(struct echoaudio *chip); 37static int check_asic_status(struct echoaudio *chip);
39 38
40 39
@@ -64,32 +63,30 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
64 63
65 /* Mona comes in both '301 and '361 flavors */ 64 /* Mona comes in both '301 and '361 flavors */
66 if (chip->device_id == DEVICE_ID_56361) 65 if (chip->device_id == DEVICE_ID_56361)
67 chip->dsp_code_to_load = &card_fw[FW_MONA_361_DSP]; 66 chip->dsp_code_to_load = FW_MONA_361_DSP;
68 else 67 else
69 chip->dsp_code_to_load = &card_fw[FW_MONA_301_DSP]; 68 chip->dsp_code_to_load = FW_MONA_301_DSP;
70
71 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
72 chip->professional_spdif = FALSE;
73 chip->digital_in_automute = TRUE;
74 69
75 if ((err = load_firmware(chip)) < 0) 70 if ((err = load_firmware(chip)) < 0)
76 return err; 71 return err;
77 chip->bad_board = FALSE; 72 chip->bad_board = FALSE;
78 73
79 if ((err = init_line_levels(chip)) < 0)
80 return err;
81
82 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
83 if (err < 0)
84 return err;
85 err = set_professional_spdif(chip, TRUE);
86
87 DE_INIT(("init_hw done\n")); 74 DE_INIT(("init_hw done\n"));
88 return err; 75 return err;
89} 76}
90 77
91 78
92 79
80static int set_mixer_defaults(struct echoaudio *chip)
81{
82 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
83 chip->professional_spdif = FALSE;
84 chip->digital_in_automute = TRUE;
85 return init_line_levels(chip);
86}
87
88
89
93static u32 detect_input_clocks(const struct echoaudio *chip) 90static u32 detect_input_clocks(const struct echoaudio *chip)
94{ 91{
95 u32 clocks_from_dsp, clock_bits; 92 u32 clocks_from_dsp, clock_bits;
@@ -120,7 +117,7 @@ static int load_asic(struct echoaudio *chip)
120{ 117{
121 u32 control_reg; 118 u32 control_reg;
122 int err; 119 int err;
123 const struct firmware *asic; 120 short asic;
124 121
125 if (chip->asic_loaded) 122 if (chip->asic_loaded)
126 return 0; 123 return 0;
@@ -128,9 +125,9 @@ static int load_asic(struct echoaudio *chip)
128 mdelay(10); 125 mdelay(10);
129 126
130 if (chip->device_id == DEVICE_ID_56361) 127 if (chip->device_id == DEVICE_ID_56361)
131 asic = &card_fw[FW_MONA_361_1_ASIC48]; 128 asic = FW_MONA_361_1_ASIC48;
132 else 129 else
133 asic = &card_fw[FW_MONA_301_1_ASIC48]; 130 asic = FW_MONA_301_1_ASIC48;
134 131
135 err = load_asic_generic(chip, DSP_FNC_LOAD_MONA_PCI_CARD_ASIC, asic); 132 err = load_asic_generic(chip, DSP_FNC_LOAD_MONA_PCI_CARD_ASIC, asic);
136 if (err < 0) 133 if (err < 0)
@@ -141,7 +138,7 @@ static int load_asic(struct echoaudio *chip)
141 138
142 /* Do the external one */ 139 /* Do the external one */
143 err = load_asic_generic(chip, DSP_FNC_LOAD_MONA_EXTERNAL_ASIC, 140 err = load_asic_generic(chip, DSP_FNC_LOAD_MONA_EXTERNAL_ASIC,
144 &card_fw[FW_MONA_2_ASIC]); 141 FW_MONA_2_ASIC);
145 if (err < 0) 142 if (err < 0)
146 return err; 143 return err;
147 144
@@ -165,22 +162,22 @@ loaded. This function checks the ASIC needed for the new mode and sees
165if it matches the one already loaded. */ 162if it matches the one already loaded. */
166static int switch_asic(struct echoaudio *chip, char double_speed) 163static int switch_asic(struct echoaudio *chip, char double_speed)
167{ 164{
168 const struct firmware *asic;
169 int err; 165 int err;
166 short asic;
170 167
171 /* Check the clock detect bits to see if this is 168 /* Check the clock detect bits to see if this is
172 a single-speed clock or a double-speed clock; load 169 a single-speed clock or a double-speed clock; load
173 a new ASIC if necessary. */ 170 a new ASIC if necessary. */
174 if (chip->device_id == DEVICE_ID_56361) { 171 if (chip->device_id == DEVICE_ID_56361) {
175 if (double_speed) 172 if (double_speed)
176 asic = &card_fw[FW_MONA_361_1_ASIC96]; 173 asic = FW_MONA_361_1_ASIC96;
177 else 174 else
178 asic = &card_fw[FW_MONA_361_1_ASIC48]; 175 asic = FW_MONA_361_1_ASIC48;
179 } else { 176 } else {
180 if (double_speed) 177 if (double_speed)
181 asic = &card_fw[FW_MONA_301_1_ASIC96]; 178 asic = FW_MONA_301_1_ASIC96;
182 else 179 else
183 asic = &card_fw[FW_MONA_301_1_ASIC48]; 180 asic = FW_MONA_301_1_ASIC48;
184 } 181 }
185 182
186 if (asic != chip->asic_code) { 183 if (asic != chip->asic_code) {
@@ -200,7 +197,7 @@ static int switch_asic(struct echoaudio *chip, char double_speed)
200static int set_sample_rate(struct echoaudio *chip, u32 rate) 197static int set_sample_rate(struct echoaudio *chip, u32 rate)
201{ 198{
202 u32 control_reg, clock; 199 u32 control_reg, clock;
203 const struct firmware *asic; 200 short asic;
204 char force_write; 201 char force_write;
205 202
206 /* Only set the clock for internal mode. */ 203 /* Only set the clock for internal mode. */
@@ -218,14 +215,14 @@ static int set_sample_rate(struct echoaudio *chip, u32 rate)
218 if (chip->digital_mode == DIGITAL_MODE_ADAT) 215 if (chip->digital_mode == DIGITAL_MODE_ADAT)
219 return -EINVAL; 216 return -EINVAL;
220 if (chip->device_id == DEVICE_ID_56361) 217 if (chip->device_id == DEVICE_ID_56361)
221 asic = &card_fw[FW_MONA_361_1_ASIC96]; 218 asic = FW_MONA_361_1_ASIC96;
222 else 219 else
223 asic = &card_fw[FW_MONA_301_1_ASIC96]; 220 asic = FW_MONA_301_1_ASIC96;
224 } else { 221 } else {
225 if (chip->device_id == DEVICE_ID_56361) 222 if (chip->device_id == DEVICE_ID_56361)
226 asic = &card_fw[FW_MONA_361_1_ASIC48]; 223 asic = FW_MONA_361_1_ASIC48;
227 else 224 else
228 asic = &card_fw[FW_MONA_301_1_ASIC48]; 225 asic = FW_MONA_301_1_ASIC48;
229 } 226 }
230 227
231 force_write = 0; 228 force_write = 0;
@@ -410,8 +407,8 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
410 case DIGITAL_MODE_ADAT: 407 case DIGITAL_MODE_ADAT:
411 /* If the current ASIC is the 96KHz ASIC, switch the ASIC 408 /* If the current ASIC is the 96KHz ASIC, switch the ASIC
412 and set to 48 KHz */ 409 and set to 48 KHz */
413 if (chip->asic_code == &card_fw[FW_MONA_361_1_ASIC96] || 410 if (chip->asic_code == FW_MONA_361_1_ASIC96 ||
414 chip->asic_code == &card_fw[FW_MONA_301_1_ASIC96]) { 411 chip->asic_code == FW_MONA_301_1_ASIC96) {
415 set_sample_rate(chip, 48000); 412 set_sample_rate(chip, 48000);
416 } 413 }
417 control_reg |= GML_ADAT_MODE; 414 control_reg |= GML_ADAT_MODE;
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index 168af67d938e..4203782d7cb7 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -76,7 +76,7 @@ MODULE_PARM_DESC(subsystem, "Force card subsystem model.");
76/* 76/*
77 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400 77 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400
78 */ 78 */
79static struct pci_device_id snd_emu10k1_ids[] = { 79static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1_ids) = {
80 { PCI_VDEVICE(CREATIVE, 0x0002), 0 }, /* EMU10K1 */ 80 { PCI_VDEVICE(CREATIVE, 0x0002), 0 }, /* EMU10K1 */
81 { PCI_VDEVICE(CREATIVE, 0x0004), 1 }, /* Audigy */ 81 { PCI_VDEVICE(CREATIVE, 0x0004), 1 }, /* Audigy */
82 { PCI_VDEVICE(CREATIVE, 0x0008), 1 }, /* Audigy 2 Value SB0400 */ 82 { PCI_VDEVICE(CREATIVE, 0x0008), 1 }, /* Audigy 2 Value SB0400 */
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 36e08bd2b3cc..df47f738098d 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -184,7 +184,7 @@ MODULE_PARM_DESC(enable, "Enable the EMU10K1X soundcard.");
184 * The hardware has 3 channels for playback and 1 for capture. 184 * The hardware has 3 channels for playback and 1 for capture.
185 * - channel 0 is the front channel 185 * - channel 0 is the front channel
186 * - channel 1 is the rear channel 186 * - channel 1 is the rear channel
187 * - channel 2 is the center/lfe chanel 187 * - channel 2 is the center/lfe channel
188 * Volume is controlled by the AC97 for the front and rear channels by 188 * Volume is controlled by the AC97 for the front and rear channels by
189 * the PCM Playback Volume, Sigmatel Surround Playback Volume and 189 * the PCM Playback Volume, Sigmatel Surround Playback Volume and
190 * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects 190 * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects
@@ -1040,8 +1040,7 @@ static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
1040 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 1040 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
1041 continue; 1041 continue;
1042 1042
1043 if ((reg < 0x49) && (reg >= 0) && (val <= 0xffffffff) 1043 if (reg < 0x49 && val <= 0xffffffff && channel_id <= 2)
1044 && (channel_id >= 0) && (channel_id <= 2) )
1045 snd_emu10k1x_ptr_write(emu, reg, channel_id, val); 1044 snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
1046 } 1045 }
1047} 1046}
@@ -1606,7 +1605,7 @@ static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
1606} 1605}
1607 1606
1608// PCI IDs 1607// PCI IDs
1609static struct pci_device_id snd_emu10k1x_ids[] = { 1608static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1x_ids) = {
1610 { PCI_VDEVICE(CREATIVE, 0x0006), 0 }, /* Dell OEM version (EMU10K1) */ 1609 { PCI_VDEVICE(CREATIVE, 0x0006), 0 }, /* Dell OEM version (EMU10K1) */
1611 { 0, } 1610 { 0, }
1612}; 1611};
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index b0fb6c917c38..05afe06e353a 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -1818,8 +1818,8 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1818 "Master Playback Switch", "Master Capture Switch", 1818 "Master Playback Switch", "Master Capture Switch",
1819 "Master Playback Volume", "Master Capture Volume", 1819 "Master Playback Volume", "Master Capture Volume",
1820 "Wave Master Playback Volume", "Master Playback Volume", 1820 "Wave Master Playback Volume", "Master Playback Volume",
1821 "PC Speaker Playback Switch", "PC Speaker Capture Switch", 1821 "Beep Playback Switch", "Beep Capture Switch",
1822 "PC Speaker Playback Volume", "PC Speaker Capture Volume", 1822 "Beep Playback Volume", "Beep Capture Volume",
1823 "Phone Playback Switch", "Phone Capture Switch", 1823 "Phone Playback Switch", "Phone Capture Switch",
1824 "Phone Playback Volume", "Phone Capture Volume", 1824 "Phone Playback Volume", "Phone Capture Volume",
1825 "Mic Playback Switch", "Mic Capture Switch", 1825 "Mic Playback Switch", "Mic Capture Switch",
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index 216f9748aff5..baa7cd508cd8 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -451,7 +451,7 @@ static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
451 while (!snd_info_get_line(buffer, line, sizeof(line))) { 451 while (!snd_info_get_line(buffer, line, sizeof(line))) {
452 if (sscanf(line, "%x %x", &reg, &val) != 2) 452 if (sscanf(line, "%x %x", &reg, &val) != 2)
453 continue; 453 continue;
454 if ((reg < 0x40) && (reg >= 0) && (val <= 0xffffffff) ) { 454 if (reg < 0x40 && val <= 0xffffffff) {
455 spin_lock_irqsave(&emu->emu_lock, flags); 455 spin_lock_irqsave(&emu->emu_lock, flags);
456 outl(val, emu->port + (reg & 0xfffffffc)); 456 outl(val, emu->port + (reg & 0xfffffffc));
457 spin_unlock_irqrestore(&emu->emu_lock, flags); 457 spin_unlock_irqrestore(&emu->emu_lock, flags);
@@ -527,7 +527,7 @@ static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
527 while (!snd_info_get_line(buffer, line, sizeof(line))) { 527 while (!snd_info_get_line(buffer, line, sizeof(line))) {
528 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 528 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
529 continue; 529 continue;
530 if ((reg < 0xa0) && (reg >= 0) && (val <= 0xffffffff) && (channel_id >= 0) && (channel_id <= 3) ) 530 if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3)
531 snd_ptr_write(emu, iobase, reg, channel_id, val); 531 snd_ptr_write(emu, iobase, reg, channel_id, val);
532 } 532 }
533} 533}
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index c1a5aa15af8f..5ef7080e14d0 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -256,7 +256,7 @@ int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, u32 reg, u32 value)
256 if (reg > 0x3f) 256 if (reg > 0x3f)
257 return 1; 257 return 1;
258 reg += 0x40; /* 0x40 upwards are registers. */ 258 reg += 0x40; /* 0x40 upwards are registers. */
259 if (value < 0 || value > 0x3f) /* 0 to 0x3f are values */ 259 if (value > 0x3f) /* 0 to 0x3f are values */
260 return 1; 260 return 1;
261 spin_lock_irqsave(&emu->emu_lock, flags); 261 spin_lock_irqsave(&emu->emu_lock, flags);
262 outl(reg, emu->port + A_IOCFG); 262 outl(reg, emu->port + A_IOCFG);
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index 6a47672f930a..ffb1ddb8dc28 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/gfp.h>
25#include <linux/time.h> 26#include <linux/time.h>
26#include <linux/mutex.h> 27#include <linux/mutex.h>
27 28
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 2b82c5c723e1..c7fba5379813 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -443,7 +443,7 @@ struct ensoniq {
443 443
444static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id); 444static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id);
445 445
446static struct pci_device_id snd_audiopci_ids[] = { 446static DEFINE_PCI_DEVICE_TABLE(snd_audiopci_ids) = {
447#ifdef CHIP1370 447#ifdef CHIP1370
448 { PCI_VDEVICE(ENSONIQ, 0x5000), 0, }, /* ES1370 */ 448 { PCI_VDEVICE(ENSONIQ, 0x5000), 0, }, /* ES1370 */
449#endif 449#endif
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 820318ee62c1..553b75217259 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -243,7 +243,7 @@ struct es1938 {
243 243
244static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id); 244static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id);
245 245
246static struct pci_device_id snd_es1938_ids[] = { 246static DEFINE_PCI_DEVICE_TABLE(snd_es1938_ids) = {
247 { PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */ 247 { PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */
248 { 0, } 248 { 0, }
249}; 249};
@@ -1387,7 +1387,7 @@ ES1938_DOUBLE_TLV("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0,
1387 db_scale_line), 1387 db_scale_line),
1388ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0, 1388ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0,
1389 db_scale_capture), 1389 db_scale_capture),
1390ES1938_SINGLE("PC Speaker Volume", 0, 0x3c, 0, 7, 0), 1390ES1938_SINGLE("Beep Volume", 0, 0x3c, 0, 7, 0),
1391ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), 1391ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1392ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1392ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1393{ 1393{
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index a11f453a6b6d..ecaea9fb48ec 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -551,7 +551,7 @@ struct es1968 {
551 551
552static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id); 552static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id);
553 553
554static struct pci_device_id snd_es1968_ids[] = { 554static DEFINE_PCI_DEVICE_TABLE(snd_es1968_ids) = {
555 /* Maestro 1 */ 555 /* Maestro 1 */
556 { 0x1285, 0x0100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO }, 556 { 0x1285, 0x0100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO },
557 /* Maestro 2 */ 557 /* Maestro 2 */
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 60cdb9e0b68d..e1baad74ea4b 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -55,7 +55,7 @@ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card *
55 * 1 = MediaForte 256-PCS 55 * 1 = MediaForte 256-PCS
56 * 2 = MediaForte 256-PCPR 56 * 2 = MediaForte 256-PCPR
57 * 3 = MediaForte 64-PCR 57 * 3 = MediaForte 64-PCR
58 * 16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card 58 * 16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card
59 * High 16-bits are video (radio) device number + 1 59 * High 16-bits are video (radio) device number + 1
60 */ 60 */
61static int tea575x_tuner[SNDRV_CARDS]; 61static int tea575x_tuner[SNDRV_CARDS];
@@ -67,7 +67,10 @@ MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
67module_param_array(enable, bool, NULL, 0444); 67module_param_array(enable, bool, NULL, 0444);
68MODULE_PARM_DESC(enable, "Enable FM801 soundcard."); 68MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
69module_param_array(tea575x_tuner, int, NULL, 0444); 69module_param_array(tea575x_tuner, int, NULL, 0444);
70MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner."); 70MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (1 = SF256-PCS, 2=SF256-PCPR, 3=SF64-PCR, +16=tuner-only).");
71
72#define TUNER_ONLY (1<<4)
73#define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF)
71 74
72/* 75/*
73 * Direct registers 76 * Direct registers
@@ -160,7 +163,7 @@ struct fm801 {
160 unsigned int multichannel: 1, /* multichannel support */ 163 unsigned int multichannel: 1, /* multichannel support */
161 secondary: 1; /* secondary codec */ 164 secondary: 1; /* secondary codec */
162 unsigned char secondary_addr; /* address of the secondary codec */ 165 unsigned char secondary_addr; /* address of the secondary codec */
163 unsigned int tea575x_tuner; /* tuner flags */ 166 unsigned int tea575x_tuner; /* tuner access method & flags */
164 167
165 unsigned short ply_ctrl; /* playback control */ 168 unsigned short ply_ctrl; /* playback control */
166 unsigned short cap_ctrl; /* capture control */ 169 unsigned short cap_ctrl; /* capture control */
@@ -202,7 +205,7 @@ struct fm801 {
202#endif 205#endif
203}; 206};
204 207
205static struct pci_device_id snd_fm801_ids[] = { 208static DEFINE_PCI_DEVICE_TABLE(snd_fm801_ids) = {
206 { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* FM801 */ 209 { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* FM801 */
207 { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* Gallant Odyssey Sound 4 */ 210 { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* Gallant Odyssey Sound 4 */
208 { 0, } 211 { 0, }
@@ -1287,7 +1290,7 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1287{ 1290{
1288 unsigned short cmdw; 1291 unsigned short cmdw;
1289 1292
1290 if (chip->tea575x_tuner & 0x0010) 1293 if (chip->tea575x_tuner & TUNER_ONLY)
1291 goto __ac97_ok; 1294 goto __ac97_ok;
1292 1295
1293 /* codec cold reset + AC'97 warm reset */ 1296 /* codec cold reset + AC'97 warm reset */
@@ -1296,11 +1299,13 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1296 udelay(100); 1299 udelay(100);
1297 outw(0, FM801_REG(chip, CODEC_CTRL)); 1300 outw(0, FM801_REG(chip, CODEC_CTRL));
1298 1301
1299 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) { 1302 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0)
1300 snd_printk(KERN_ERR "Primary AC'97 codec not found\n"); 1303 if (!resume) {
1301 if (! resume) 1304 snd_printk(KERN_INFO "Primary AC'97 codec not found, "
1302 return -EIO; 1305 "assume SF64-PCR (tuner-only)\n");
1303 } 1306 chip->tea575x_tuner = 3 | TUNER_ONLY;
1307 goto __ac97_ok;
1308 }
1304 1309
1305 if (chip->multichannel) { 1310 if (chip->multichannel) {
1306 if (chip->secondary_addr) { 1311 if (chip->secondary_addr) {
@@ -1414,7 +1419,7 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1414 return err; 1419 return err;
1415 } 1420 }
1416 chip->port = pci_resource_start(pci, 0); 1421 chip->port = pci_resource_start(pci, 0);
1417 if ((tea575x_tuner & 0x0010) == 0) { 1422 if ((tea575x_tuner & TUNER_ONLY) == 0) {
1418 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED, 1423 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
1419 "FM801", chip)) { 1424 "FM801", chip)) {
1420 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq); 1425 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
@@ -1429,6 +1434,14 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1429 chip->multichannel = 1; 1434 chip->multichannel = 1;
1430 1435
1431 snd_fm801_chip_init(chip, 0); 1436 snd_fm801_chip_init(chip, 0);
1437 /* init might set tuner access method */
1438 tea575x_tuner = chip->tea575x_tuner;
1439
1440 if (chip->irq >= 0 && (tea575x_tuner & TUNER_ONLY)) {
1441 pci_clear_master(pci);
1442 free_irq(chip->irq, chip);
1443 chip->irq = -1;
1444 }
1432 1445
1433 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1446 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1434 snd_fm801_free(chip); 1447 snd_fm801_free(chip);
@@ -1438,12 +1451,13 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1438 snd_card_set_dev(card, &pci->dev); 1451 snd_card_set_dev(card, &pci->dev);
1439 1452
1440#ifdef TEA575X_RADIO 1453#ifdef TEA575X_RADIO
1441 if (tea575x_tuner > 0 && (tea575x_tuner & 0x000f) < 4) { 1454 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
1455 (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1442 chip->tea.dev_nr = tea575x_tuner >> 16; 1456 chip->tea.dev_nr = tea575x_tuner >> 16;
1443 chip->tea.card = card; 1457 chip->tea.card = card;
1444 chip->tea.freq_fixup = 10700; 1458 chip->tea.freq_fixup = 10700;
1445 chip->tea.private_data = chip; 1459 chip->tea.private_data = chip;
1446 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x000f) - 1]; 1460 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & TUNER_TYPE_MASK) - 1];
1447 snd_tea575x_init(&chip->tea); 1461 snd_tea575x_init(&chip->tea);
1448 } 1462 }
1449#endif 1463#endif
@@ -1483,7 +1497,7 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
1483 sprintf(card->longname, "%s at 0x%lx, irq %i", 1497 sprintf(card->longname, "%s at 0x%lx, irq %i",
1484 card->shortname, chip->port, chip->irq); 1498 card->shortname, chip->port, chip->irq);
1485 1499
1486 if (tea575x_tuner[dev] & 0x0010) 1500 if (chip->tea575x_tuner & TUNER_ONLY)
1487 goto __fm801_tuner_only; 1501 goto __fm801_tuner_only;
1488 1502
1489 if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) { 1503 if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) {
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 55545e0818b5..567348b05b5a 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -38,9 +38,20 @@ config SND_HDA_INPUT_BEEP
38 Say Y here to build a digital beep interface for HD-audio 38 Say Y here to build a digital beep interface for HD-audio
39 driver. This interface is used to generate digital beeps. 39 driver. This interface is used to generate digital beeps.
40 40
41config SND_HDA_INPUT_BEEP_MODE
42 int "Digital beep registration mode (0=off, 1=on, 2=mute sw on/off)"
43 depends on SND_HDA_INPUT_BEEP=y
44 default "1"
45 range 0 2
46 help
47 Set 0 to disable the digital beep interface for HD-audio by default.
48 Set 1 to always enable the digital beep interface for HD-audio by
49 default. Set 2 to control the beep device registration to input
50 layer using a "Beep Switch" in mixer applications.
51
41config SND_HDA_INPUT_JACK 52config SND_HDA_INPUT_JACK
42 bool "Support jack plugging notification via input layer" 53 bool "Support jack plugging notification via input layer"
43 depends on INPUT=y || INPUT=SND_HDA_INTEL 54 depends on INPUT=y || INPUT=SND
44 select SND_JACK 55 select SND_JACK
45 help 56 help
46 Say Y here to enable the jack plugging notification via 57 Say Y here to enable the jack plugging notification via
@@ -146,7 +157,7 @@ config SND_HDA_CODEC_INTELHDMI
146 157
147config SND_HDA_ELD 158config SND_HDA_ELD
148 def_bool y 159 def_bool y
149 depends on SND_HDA_CODEC_INTELHDMI 160 depends on SND_HDA_CODEC_INTELHDMI || SND_HDA_CODEC_NVHDMI
150 161
151config SND_HDA_CODEC_CIRRUS 162config SND_HDA_CODEC_CIRRUS
152 bool "Build Cirrus Logic codec support" 163 bool "Build Cirrus Logic codec support"
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 315a1c4f8998..24bc195b02da 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -3,7 +3,7 @@ snd-hda-intel-objs := hda_intel.o
3snd-hda-codec-y := hda_codec.o 3snd-hda-codec-y := hda_codec.o
4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
6# snd-hda-codec-$(CONFIG_SND_HDA_ELD) += hda_eld.o 6snd-hda-codec-$(CONFIG_SND_HDA_ELD) += hda_eld.o
7snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 7snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o 8snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
9 9
@@ -18,7 +18,7 @@ snd-hda-codec-ca0110-objs := patch_ca0110.o
18snd-hda-codec-conexant-objs := patch_conexant.o 18snd-hda-codec-conexant-objs := patch_conexant.o
19snd-hda-codec-via-objs := patch_via.o 19snd-hda-codec-via-objs := patch_via.o
20snd-hda-codec-nvhdmi-objs := patch_nvhdmi.o 20snd-hda-codec-nvhdmi-objs := patch_nvhdmi.o
21snd-hda-codec-intelhdmi-objs := patch_intelhdmi.o hda_eld.o 21snd-hda-codec-intelhdmi-objs := patch_intelhdmi.o
22 22
23# common driver 23# common driver
24obj-$(CONFIG_SND_HDA_INTEL) := snd-hda-codec.o 24obj-$(CONFIG_SND_HDA_INTEL) := snd-hda-codec.o
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 3f51a981e604..29714c818b53 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/input.h> 22#include <linux/input.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/slab.h>
24#include <linux/workqueue.h> 25#include <linux/workqueue.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include "hda_beep.h" 27#include "hda_beep.h"
@@ -42,7 +43,7 @@ static void snd_hda_generate_beep(struct work_struct *work)
42 return; 43 return;
43 44
44 /* generate tone */ 45 /* generate tone */
45 snd_hda_codec_write_cache(codec, beep->nid, 0, 46 snd_hda_codec_write(codec, beep->nid, 0,
46 AC_VERB_SET_BEEP_CONTROL, beep->tone); 47 AC_VERB_SET_BEEP_CONTROL, beep->tone);
47} 48}
48 49
@@ -113,23 +114,25 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
113 return 0; 114 return 0;
114} 115}
115 116
116int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) 117static void snd_hda_do_detach(struct hda_beep *beep)
118{
119 input_unregister_device(beep->dev);
120 beep->dev = NULL;
121 cancel_work_sync(&beep->beep_work);
122 /* turn off beep for sure */
123 snd_hda_codec_write(beep->codec, beep->nid, 0,
124 AC_VERB_SET_BEEP_CONTROL, 0);
125}
126
127static int snd_hda_do_attach(struct hda_beep *beep)
117{ 128{
118 struct input_dev *input_dev; 129 struct input_dev *input_dev;
119 struct hda_beep *beep; 130 struct hda_codec *codec = beep->codec;
120 int err; 131 int err;
121 132
122 if (!snd_hda_get_bool_hint(codec, "beep"))
123 return 0; /* disabled explicitly */
124
125 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
126 if (beep == NULL)
127 return -ENOMEM;
128 snprintf(beep->phys, sizeof(beep->phys),
129 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
130 input_dev = input_allocate_device(); 133 input_dev = input_allocate_device();
131 if (!input_dev) { 134 if (!input_dev) {
132 kfree(beep); 135 printk(KERN_INFO "hda_beep: unable to allocate input device\n");
133 return -ENOMEM; 136 return -ENOMEM;
134 } 137 }
135 138
@@ -151,21 +154,100 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
151 err = input_register_device(input_dev); 154 err = input_register_device(input_dev);
152 if (err < 0) { 155 if (err < 0) {
153 input_free_device(input_dev); 156 input_free_device(input_dev);
154 kfree(beep); 157 printk(KERN_INFO "hda_beep: unable to register input device\n");
155 return err; 158 return err;
156 } 159 }
160 beep->dev = input_dev;
161 return 0;
162}
163
164static void snd_hda_do_register(struct work_struct *work)
165{
166 struct hda_beep *beep =
167 container_of(work, struct hda_beep, register_work);
168
169 mutex_lock(&beep->mutex);
170 if (beep->enabled && !beep->dev)
171 snd_hda_do_attach(beep);
172 mutex_unlock(&beep->mutex);
173}
174
175static void snd_hda_do_unregister(struct work_struct *work)
176{
177 struct hda_beep *beep =
178 container_of(work, struct hda_beep, unregister_work.work);
179
180 mutex_lock(&beep->mutex);
181 if (!beep->enabled && beep->dev)
182 snd_hda_do_detach(beep);
183 mutex_unlock(&beep->mutex);
184}
157 185
186int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
187{
188 struct hda_beep *beep = codec->beep;
189 enable = !!enable;
190 if (beep == NULL)
191 return 0;
192 if (beep->enabled != enable) {
193 beep->enabled = enable;
194 if (!enable) {
195 /* turn off beep */
196 snd_hda_codec_write(beep->codec, beep->nid, 0,
197 AC_VERB_SET_BEEP_CONTROL, 0);
198 }
199 if (beep->mode == HDA_BEEP_MODE_SWREG) {
200 if (enable) {
201 cancel_delayed_work(&beep->unregister_work);
202 schedule_work(&beep->register_work);
203 } else {
204 schedule_delayed_work(&beep->unregister_work,
205 HZ);
206 }
207 }
208 return 1;
209 }
210 return 0;
211}
212EXPORT_SYMBOL_HDA(snd_hda_enable_beep_device);
213
214int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
215{
216 struct hda_beep *beep;
217
218 if (!snd_hda_get_bool_hint(codec, "beep"))
219 return 0; /* disabled explicitly by hints */
220 if (codec->beep_mode == HDA_BEEP_MODE_OFF)
221 return 0; /* disabled by module option */
222
223 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
224 if (beep == NULL)
225 return -ENOMEM;
226 snprintf(beep->phys, sizeof(beep->phys),
227 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
158 /* enable linear scale */ 228 /* enable linear scale */
159 snd_hda_codec_write(codec, nid, 0, 229 snd_hda_codec_write(codec, nid, 0,
160 AC_VERB_SET_DIGI_CONVERT_2, 0x01); 230 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
161 231
162 beep->nid = nid; 232 beep->nid = nid;
163 beep->dev = input_dev;
164 beep->codec = codec; 233 beep->codec = codec;
165 beep->enabled = 1; 234 beep->mode = codec->beep_mode;
166 codec->beep = beep; 235 codec->beep = beep;
167 236
237 INIT_WORK(&beep->register_work, &snd_hda_do_register);
238 INIT_DELAYED_WORK(&beep->unregister_work, &snd_hda_do_unregister);
168 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); 239 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
240 mutex_init(&beep->mutex);
241
242 if (beep->mode == HDA_BEEP_MODE_ON) {
243 int err = snd_hda_do_attach(beep);
244 if (err < 0) {
245 kfree(beep);
246 codec->beep = NULL;
247 return err;
248 }
249 }
250
169 return 0; 251 return 0;
170} 252}
171EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device); 253EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device);
@@ -174,11 +256,12 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
174{ 256{
175 struct hda_beep *beep = codec->beep; 257 struct hda_beep *beep = codec->beep;
176 if (beep) { 258 if (beep) {
177 cancel_work_sync(&beep->beep_work); 259 cancel_work_sync(&beep->register_work);
178 260 cancel_delayed_work(&beep->unregister_work);
179 input_unregister_device(beep->dev); 261 if (beep->dev)
180 kfree(beep); 262 snd_hda_do_detach(beep);
181 codec->beep = NULL; 263 codec->beep = NULL;
264 kfree(beep);
182 } 265 }
183} 266}
184EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device); 267EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device);
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index 0c3de787c717..f1de1bac042c 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -24,19 +24,29 @@
24 24
25#include "hda_codec.h" 25#include "hda_codec.h"
26 26
27#define HDA_BEEP_MODE_OFF 0
28#define HDA_BEEP_MODE_ON 1
29#define HDA_BEEP_MODE_SWREG 2
30
27/* beep information */ 31/* beep information */
28struct hda_beep { 32struct hda_beep {
29 struct input_dev *dev; 33 struct input_dev *dev;
30 struct hda_codec *codec; 34 struct hda_codec *codec;
35 unsigned int mode;
31 char phys[32]; 36 char phys[32];
32 int tone; 37 int tone;
33 hda_nid_t nid; 38 hda_nid_t nid;
34 unsigned int enabled:1; 39 unsigned int enabled:1;
40 unsigned int request_enable:1;
35 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */ 41 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
42 struct work_struct register_work; /* registration work */
43 struct delayed_work unregister_work; /* unregistration work */
36 struct work_struct beep_work; /* scheduled task for beep event */ 44 struct work_struct beep_work; /* scheduled task for beep event */
45 struct mutex mutex;
37}; 46};
38 47
39#ifdef CONFIG_SND_HDA_INPUT_BEEP 48#ifdef CONFIG_SND_HDA_INPUT_BEEP
49int snd_hda_enable_beep_device(struct hda_codec *codec, int enable);
40int snd_hda_attach_beep_device(struct hda_codec *codec, int nid); 50int snd_hda_attach_beep_device(struct hda_codec *codec, int nid);
41void snd_hda_detach_beep_device(struct hda_codec *codec); 51void snd_hda_detach_beep_device(struct hda_codec *codec);
42#else 52#else
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index af989f660cca..0e76ac2b2ace 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -30,6 +30,7 @@
30#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_beep.h"
33#include <sound/hda_hwdep.h> 34#include <sound/hda_hwdep.h>
34 35
35/* 36/*
@@ -93,6 +94,13 @@ static void hda_keep_power_on(struct hda_codec *codec);
93static inline void hda_keep_power_on(struct hda_codec *codec) {} 94static inline void hda_keep_power_on(struct hda_codec *codec) {}
94#endif 95#endif
95 96
97/**
98 * snd_hda_get_jack_location - Give a location string of the jack
99 * @cfg: pin default config value
100 *
101 * Parse the pin default config value and returns the string of the
102 * jack location, e.g. "Rear", "Front", etc.
103 */
96const char *snd_hda_get_jack_location(u32 cfg) 104const char *snd_hda_get_jack_location(u32 cfg)
97{ 105{
98 static char *bases[7] = { 106 static char *bases[7] = {
@@ -120,6 +128,13 @@ const char *snd_hda_get_jack_location(u32 cfg)
120} 128}
121EXPORT_SYMBOL_HDA(snd_hda_get_jack_location); 129EXPORT_SYMBOL_HDA(snd_hda_get_jack_location);
122 130
131/**
132 * snd_hda_get_jack_connectivity - Give a connectivity string of the jack
133 * @cfg: pin default config value
134 *
135 * Parse the pin default config value and returns the string of the
136 * jack connectivity, i.e. external or internal connection.
137 */
123const char *snd_hda_get_jack_connectivity(u32 cfg) 138const char *snd_hda_get_jack_connectivity(u32 cfg)
124{ 139{
125 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" }; 140 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
@@ -128,6 +143,13 @@ const char *snd_hda_get_jack_connectivity(u32 cfg)
128} 143}
129EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity); 144EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity);
130 145
146/**
147 * snd_hda_get_jack_type - Give a type string of the jack
148 * @cfg: pin default config value
149 *
150 * Parse the pin default config value and returns the string of the
151 * jack type, i.e. the purpose of the jack, such as Line-Out or CD.
152 */
131const char *snd_hda_get_jack_type(u32 cfg) 153const char *snd_hda_get_jack_type(u32 cfg)
132{ 154{
133 static char *jack_types[16] = { 155 static char *jack_types[16] = {
@@ -515,6 +537,7 @@ static int snd_hda_bus_dev_register(struct snd_device *device)
515 struct hda_codec *codec; 537 struct hda_codec *codec;
516 list_for_each_entry(codec, &bus->codec_list, list) { 538 list_for_each_entry(codec, &bus->codec_list, list) {
517 snd_hda_hwdep_add_sysfs(codec); 539 snd_hda_hwdep_add_sysfs(codec);
540 snd_hda_hwdep_add_power_sysfs(codec);
518 } 541 }
519 return 0; 542 return 0;
520} 543}
@@ -801,6 +824,9 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
801 struct hda_pincfg *pin; 824 struct hda_pincfg *pin;
802 unsigned int oldcfg; 825 unsigned int oldcfg;
803 826
827 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
828 return -EINVAL;
829
804 oldcfg = snd_hda_codec_get_pincfg(codec, nid); 830 oldcfg = snd_hda_codec_get_pincfg(codec, nid);
805 pin = look_up_pincfg(codec, list, nid); 831 pin = look_up_pincfg(codec, list, nid);
806 if (!pin) { 832 if (!pin) {
@@ -820,6 +846,16 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
820 return 0; 846 return 0;
821} 847}
822 848
849/**
850 * snd_hda_codec_set_pincfg - Override a pin default configuration
851 * @codec: the HDA codec
852 * @nid: NID to set the pin config
853 * @cfg: the pin default config value
854 *
855 * Override a pin default configuration value in the cache.
856 * This value can be read by snd_hda_codec_get_pincfg() in a higher
857 * priority than the real hardware value.
858 */
823int snd_hda_codec_set_pincfg(struct hda_codec *codec, 859int snd_hda_codec_set_pincfg(struct hda_codec *codec,
824 hda_nid_t nid, unsigned int cfg) 860 hda_nid_t nid, unsigned int cfg)
825{ 861{
@@ -827,7 +863,15 @@ int snd_hda_codec_set_pincfg(struct hda_codec *codec,
827} 863}
828EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg); 864EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
829 865
830/* get the current pin config value of the given pin NID */ 866/**
867 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
868 * @codec: the HDA codec
869 * @nid: NID to get the pin config
870 *
871 * Get the current pin config value of the given pin NID.
872 * If the pincfg value is cached or overridden via sysfs or driver,
873 * returns the cached value.
874 */
831unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) 875unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
832{ 876{
833 struct hda_pincfg *pin; 877 struct hda_pincfg *pin;
@@ -858,6 +902,25 @@ static void restore_pincfgs(struct hda_codec *codec)
858 } 902 }
859} 903}
860 904
905/**
906 * snd_hda_shutup_pins - Shut up all pins
907 * @codec: the HDA codec
908 *
909 * Clear all pin controls to shup up before suspend for avoiding click noise.
910 * The controls aren't cached so that they can be resumed properly.
911 */
912void snd_hda_shutup_pins(struct hda_codec *codec)
913{
914 int i;
915 for (i = 0; i < codec->init_pins.used; i++) {
916 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
917 /* use read here for syncing after issuing each verb */
918 snd_hda_codec_read(codec, pin->nid, 0,
919 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
920 }
921}
922EXPORT_SYMBOL_HDA(snd_hda_shutup_pins);
923
861static void init_hda_cache(struct hda_cache_rec *cache, 924static void init_hda_cache(struct hda_cache_rec *cache,
862 unsigned int record_size); 925 unsigned int record_size);
863static void free_hda_cache(struct hda_cache_rec *cache); 926static void free_hda_cache(struct hda_cache_rec *cache);
@@ -890,6 +953,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
890#endif 953#endif
891 list_del(&codec->list); 954 list_del(&codec->list);
892 snd_array_free(&codec->mixers); 955 snd_array_free(&codec->mixers);
956 snd_array_free(&codec->nids);
893 codec->bus->caddr_tbl[codec->addr] = NULL; 957 codec->bus->caddr_tbl[codec->addr] = NULL;
894 if (codec->patch_ops.free) 958 if (codec->patch_ops.free)
895 codec->patch_ops.free(codec); 959 codec->patch_ops.free(codec);
@@ -914,8 +978,9 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
914 * 978 *
915 * Returns 0 if successful, or a negative error code. 979 * Returns 0 if successful, or a negative error code.
916 */ 980 */
917int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 981int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
918 struct hda_codec **codecp) 982 unsigned int codec_addr,
983 struct hda_codec **codecp)
919{ 984{
920 struct hda_codec *codec; 985 struct hda_codec *codec;
921 char component[31]; 986 char component[31];
@@ -944,7 +1009,8 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
944 mutex_init(&codec->control_mutex); 1009 mutex_init(&codec->control_mutex);
945 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 1010 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
946 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 1011 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
947 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32); 1012 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
1013 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
948 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 1014 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
949 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 1015 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
950 if (codec->bus->modelname) { 1016 if (codec->bus->modelname) {
@@ -1026,6 +1092,15 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
1026} 1092}
1027EXPORT_SYMBOL_HDA(snd_hda_codec_new); 1093EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1028 1094
1095/**
1096 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1097 * @codec: the HDA codec
1098 *
1099 * Start parsing of the given codec tree and (re-)initialize the whole
1100 * patch instance.
1101 *
1102 * Returns 0 if successful or a negative error code.
1103 */
1029int snd_hda_codec_configure(struct hda_codec *codec) 1104int snd_hda_codec_configure(struct hda_codec *codec)
1030{ 1105{
1031 int err; 1106 int err;
@@ -1036,11 +1111,6 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1036 if (err < 0) 1111 if (err < 0)
1037 return err; 1112 return err;
1038 } 1113 }
1039 /* audio codec should override the mixer name */
1040 if (codec->afg || !*codec->bus->card->mixername)
1041 snprintf(codec->bus->card->mixername,
1042 sizeof(codec->bus->card->mixername),
1043 "%s %s", codec->vendor_name, codec->chip_name);
1044 1114
1045 if (is_generic_config(codec)) { 1115 if (is_generic_config(codec)) {
1046 err = snd_hda_parse_generic_codec(codec); 1116 err = snd_hda_parse_generic_codec(codec);
@@ -1059,6 +1129,11 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1059 patched: 1129 patched:
1060 if (!err && codec->patch_ops.unsol_event) 1130 if (!err && codec->patch_ops.unsol_event)
1061 err = init_unsol_queue(codec->bus); 1131 err = init_unsol_queue(codec->bus);
1132 /* audio codec should override the mixer name */
1133 if (!err && (codec->afg || !*codec->bus->card->mixername))
1134 snprintf(codec->bus->card->mixername,
1135 sizeof(codec->bus->card->mixername),
1136 "%s %s", codec->vendor_name, codec->chip_name);
1062 return err; 1137 return err;
1063} 1138}
1064EXPORT_SYMBOL_HDA(snd_hda_codec_configure); 1139EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
@@ -1088,6 +1163,11 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1088} 1163}
1089EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); 1164EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1090 1165
1166/**
1167 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1168 * @codec: the CODEC to clean up
1169 * @nid: the NID to clean up
1170 */
1091void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 1171void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1092{ 1172{
1093 if (!nid) 1173 if (!nid)
@@ -1107,7 +1187,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
1107 */ 1187 */
1108 1188
1109/* FIXME: more better hash key? */ 1189/* FIXME: more better hash key? */
1110#define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24)) 1190#define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1111#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24)) 1191#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
1112#define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24)) 1192#define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24))
1113#define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24)) 1193#define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24))
@@ -1163,8 +1243,17 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1163 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1243 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1164} 1244}
1165 1245
1166/* 1246/**
1167 * query AMP capabilities for the given widget and direction 1247 * query_amp_caps - query AMP capabilities
1248 * @codec: the HD-auio codec
1249 * @nid: the NID to query
1250 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1251 *
1252 * Query AMP capabilities for the given widget and direction.
1253 * Returns the obtained capability bits.
1254 *
1255 * When cap bits have been already read, this doesn't read again but
1256 * returns the cached value.
1168 */ 1257 */
1169u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1258u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1170{ 1259{
@@ -1187,6 +1276,19 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1187} 1276}
1188EXPORT_SYMBOL_HDA(query_amp_caps); 1277EXPORT_SYMBOL_HDA(query_amp_caps);
1189 1278
1279/**
1280 * snd_hda_override_amp_caps - Override the AMP capabilities
1281 * @codec: the CODEC to clean up
1282 * @nid: the NID to clean up
1283 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1284 * @caps: the capability bits to set
1285 *
1286 * Override the cached AMP caps bits value by the given one.
1287 * This function is useful if the driver needs to adjust the AMP ranges,
1288 * e.g. limit to 0dB, etc.
1289 *
1290 * Returns zero if successful or a negative error code.
1291 */
1190int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1292int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1191 unsigned int caps) 1293 unsigned int caps)
1192{ 1294{
@@ -1222,6 +1324,17 @@ static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1222 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 1324 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1223} 1325}
1224 1326
1327/**
1328 * snd_hda_query_pin_caps - Query PIN capabilities
1329 * @codec: the HD-auio codec
1330 * @nid: the NID to query
1331 *
1332 * Query PIN capabilities for the given widget.
1333 * Returns the obtained capability bits.
1334 *
1335 * When cap bits have been already read, this doesn't read again but
1336 * returns the cached value.
1337 */
1225u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1338u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1226{ 1339{
1227 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1340 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
@@ -1229,6 +1342,43 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1229} 1342}
1230EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1343EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1231 1344
1345/**
1346 * snd_hda_pin_sense - execute pin sense measurement
1347 * @codec: the CODEC to sense
1348 * @nid: the pin NID to sense
1349 *
1350 * Execute necessary pin sense measurement and return its Presence Detect,
1351 * Impedance, ELD Valid etc. status bits.
1352 */
1353u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1354{
1355 u32 pincap;
1356
1357 if (!codec->no_trigger_sense) {
1358 pincap = snd_hda_query_pin_caps(codec, nid);
1359 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1360 snd_hda_codec_read(codec, nid, 0,
1361 AC_VERB_SET_PIN_SENSE, 0);
1362 }
1363 return snd_hda_codec_read(codec, nid, 0,
1364 AC_VERB_GET_PIN_SENSE, 0);
1365}
1366EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1367
1368/**
1369 * snd_hda_jack_detect - query pin Presence Detect status
1370 * @codec: the CODEC to sense
1371 * @nid: the pin NID to sense
1372 *
1373 * Query and return the pin's Presence Detect status.
1374 */
1375int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1376{
1377 u32 sense = snd_hda_pin_sense(codec, nid);
1378 return !!(sense & AC_PINSENSE_PRESENCE);
1379}
1380EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1381
1232/* 1382/*
1233 * read the current volume to info 1383 * read the current volume to info
1234 * if the cache exists, read the cache value. 1384 * if the cache exists, read the cache value.
@@ -1269,8 +1419,15 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1269 info->vol[ch] = val; 1419 info->vol[ch] = val;
1270} 1420}
1271 1421
1272/* 1422/**
1273 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. 1423 * snd_hda_codec_amp_read - Read AMP value
1424 * @codec: HD-audio codec
1425 * @nid: NID to read the AMP value
1426 * @ch: channel (left=0 or right=1)
1427 * @direction: #HDA_INPUT or #HDA_OUTPUT
1428 * @index: the index value (only for input direction)
1429 *
1430 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1274 */ 1431 */
1275int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 1432int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1276 int direction, int index) 1433 int direction, int index)
@@ -1283,8 +1440,18 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1283} 1440}
1284EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1441EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1285 1442
1286/* 1443/**
1287 * update the AMP value, mask = bit mask to set, val = the value 1444 * snd_hda_codec_amp_update - update the AMP value
1445 * @codec: HD-audio codec
1446 * @nid: NID to read the AMP value
1447 * @ch: channel (left=0 or right=1)
1448 * @direction: #HDA_INPUT or #HDA_OUTPUT
1449 * @idx: the index value (only for input direction)
1450 * @mask: bit mask to set
1451 * @val: the bits value to set
1452 *
1453 * Update the AMP value with a bit mask.
1454 * Returns 0 if the value is unchanged, 1 if changed.
1288 */ 1455 */
1289int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1456int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1290 int direction, int idx, int mask, int val) 1457 int direction, int idx, int mask, int val)
@@ -1303,8 +1470,17 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1303} 1470}
1304EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); 1471EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1305 1472
1306/* 1473/**
1307 * update the AMP stereo with the same mask and value 1474 * snd_hda_codec_amp_stereo - update the AMP stereo values
1475 * @codec: HD-audio codec
1476 * @nid: NID to read the AMP value
1477 * @direction: #HDA_INPUT or #HDA_OUTPUT
1478 * @idx: the index value (only for input direction)
1479 * @mask: bit mask to set
1480 * @val: the bits value to set
1481 *
1482 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1483 * stereo widget with the same mask and value.
1308 */ 1484 */
1309int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 1485int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1310 int direction, int idx, int mask, int val) 1486 int direction, int idx, int mask, int val)
@@ -1318,7 +1494,12 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1318EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); 1494EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1319 1495
1320#ifdef SND_HDA_NEEDS_RESUME 1496#ifdef SND_HDA_NEEDS_RESUME
1321/* resume the all amp commands from the cache */ 1497/**
1498 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1499 * @codec: HD-audio codec
1500 *
1501 * Resume the all amp commands from the cache.
1502 */
1322void snd_hda_codec_resume_amp(struct hda_codec *codec) 1503void snd_hda_codec_resume_amp(struct hda_codec *codec)
1323{ 1504{
1324 struct hda_amp_info *buffer = codec->amp_cache.buf.list; 1505 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
@@ -1344,7 +1525,12 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
1344EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); 1525EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1345#endif /* SND_HDA_NEEDS_RESUME */ 1526#endif /* SND_HDA_NEEDS_RESUME */
1346 1527
1347/* volume */ 1528/**
1529 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1530 *
1531 * The control element is supposed to have the private_value field
1532 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1533 */
1348int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 1534int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_info *uinfo) 1535 struct snd_ctl_elem_info *uinfo)
1350{ 1536{
@@ -1400,6 +1586,12 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1400 HDA_AMP_VOLMASK, val); 1586 HDA_AMP_VOLMASK, val);
1401} 1587}
1402 1588
1589/**
1590 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1591 *
1592 * The control element is supposed to have the private_value field
1593 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1594 */
1403int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1595int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1404 struct snd_ctl_elem_value *ucontrol) 1596 struct snd_ctl_elem_value *ucontrol)
1405{ 1597{
@@ -1419,6 +1611,12 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1419} 1611}
1420EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); 1612EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1421 1613
1614/**
1615 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1616 *
1617 * The control element is supposed to have the private_value field
1618 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1619 */
1422int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1620int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol) 1621 struct snd_ctl_elem_value *ucontrol)
1424{ 1622{
@@ -1443,6 +1641,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1443} 1641}
1444EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put); 1642EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1445 1643
1644/**
1645 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1646 *
1647 * The control element is supposed to have the private_value field
1648 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1649 */
1446int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1650int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1447 unsigned int size, unsigned int __user *_tlv) 1651 unsigned int size, unsigned int __user *_tlv)
1448{ 1652{
@@ -1472,8 +1676,16 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1472} 1676}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv); 1677EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1474 1678
1475/* 1679/**
1476 * set (static) TLV for virtual master volume; recalculated as max 0dB 1680 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1681 * @codec: HD-audio codec
1682 * @nid: NID of a reference widget
1683 * @dir: #HDA_INPUT or #HDA_OUTPUT
1684 * @tlv: TLV data to be stored, at least 4 elements
1685 *
1686 * Set (static) TLV data for a virtual master volume using the AMP caps
1687 * obtained from the reference NID.
1688 * The volume range is recalculated as if the max volume is 0dB.
1477 */ 1689 */
1478void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 1690void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1479 unsigned int *tlv) 1691 unsigned int *tlv)
@@ -1507,6 +1719,13 @@ _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1507 return snd_ctl_find_id(codec->bus->card, &id); 1719 return snd_ctl_find_id(codec->bus->card, &id);
1508} 1720}
1509 1721
1722/**
1723 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1724 * @codec: HD-audio codec
1725 * @name: ctl id name string
1726 *
1727 * Get the control element with the given id string and IFACE_MIXER.
1728 */
1510struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1729struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1511 const char *name) 1730 const char *name)
1512{ 1731{
@@ -1514,31 +1733,97 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1514} 1733}
1515EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); 1734EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1516 1735
1517/* Add a control element and assign to the codec */ 1736/**
1518int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl) 1737 * snd_hda_ctl_add - Add a control element and assign to the codec
1738 * @codec: HD-audio codec
1739 * @nid: corresponding NID (optional)
1740 * @kctl: the control element to assign
1741 *
1742 * Add the given control element to an array inside the codec instance.
1743 * All control elements belonging to a codec are supposed to be added
1744 * by this function so that a proper clean-up works at the free or
1745 * reconfiguration time.
1746 *
1747 * If non-zero @nid is passed, the NID is assigned to the control element.
1748 * The assignment is shown in the codec proc file.
1749 *
1750 * snd_hda_ctl_add() checks the control subdev id field whether
1751 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1752 * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit
1753 * specifies if kctl->private_value is a HDA amplifier value.
1754 */
1755int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1756 struct snd_kcontrol *kctl)
1519{ 1757{
1520 int err; 1758 int err;
1521 struct snd_kcontrol **knewp; 1759 unsigned short flags = 0;
1760 struct hda_nid_item *item;
1522 1761
1762 if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) {
1763 flags |= HDA_NID_ITEM_AMP;
1764 if (nid == 0)
1765 nid = get_amp_nid_(kctl->private_value);
1766 }
1767 if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0)
1768 nid = kctl->id.subdevice & 0xffff;
1769 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
1770 kctl->id.subdevice = 0;
1523 err = snd_ctl_add(codec->bus->card, kctl); 1771 err = snd_ctl_add(codec->bus->card, kctl);
1524 if (err < 0) 1772 if (err < 0)
1525 return err; 1773 return err;
1526 knewp = snd_array_new(&codec->mixers); 1774 item = snd_array_new(&codec->mixers);
1527 if (!knewp) 1775 if (!item)
1528 return -ENOMEM; 1776 return -ENOMEM;
1529 *knewp = kctl; 1777 item->kctl = kctl;
1778 item->nid = nid;
1779 item->flags = flags;
1530 return 0; 1780 return 0;
1531} 1781}
1532EXPORT_SYMBOL_HDA(snd_hda_ctl_add); 1782EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1533 1783
1534/* Clear all controls assigned to the given codec */ 1784/**
1785 * snd_hda_add_nid - Assign a NID to a control element
1786 * @codec: HD-audio codec
1787 * @nid: corresponding NID (optional)
1788 * @kctl: the control element to assign
1789 * @index: index to kctl
1790 *
1791 * Add the given control element to an array inside the codec instance.
1792 * This function is used when #snd_hda_ctl_add cannot be used for 1:1
1793 * NID:KCTL mapping - for example "Capture Source" selector.
1794 */
1795int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1796 unsigned int index, hda_nid_t nid)
1797{
1798 struct hda_nid_item *item;
1799
1800 if (nid > 0) {
1801 item = snd_array_new(&codec->nids);
1802 if (!item)
1803 return -ENOMEM;
1804 item->kctl = kctl;
1805 item->index = index;
1806 item->nid = nid;
1807 return 0;
1808 }
1809 printk(KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n",
1810 kctl->id.name, kctl->id.index, index);
1811 return -EINVAL;
1812}
1813EXPORT_SYMBOL_HDA(snd_hda_add_nid);
1814
1815/**
1816 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1817 * @codec: HD-audio codec
1818 */
1535void snd_hda_ctls_clear(struct hda_codec *codec) 1819void snd_hda_ctls_clear(struct hda_codec *codec)
1536{ 1820{
1537 int i; 1821 int i;
1538 struct snd_kcontrol **kctls = codec->mixers.list; 1822 struct hda_nid_item *items = codec->mixers.list;
1539 for (i = 0; i < codec->mixers.used; i++) 1823 for (i = 0; i < codec->mixers.used; i++)
1540 snd_ctl_remove(codec->bus->card, kctls[i]); 1824 snd_ctl_remove(codec->bus->card, items[i].kctl);
1541 snd_array_free(&codec->mixers); 1825 snd_array_free(&codec->mixers);
1826 snd_array_free(&codec->nids);
1542} 1827}
1543 1828
1544/* pseudo device locking 1829/* pseudo device locking
@@ -1563,6 +1848,16 @@ static void hda_unlock_devices(struct snd_card *card)
1563 spin_unlock(&card->files_lock); 1848 spin_unlock(&card->files_lock);
1564} 1849}
1565 1850
1851/**
1852 * snd_hda_codec_reset - Clear all objects assigned to the codec
1853 * @codec: HD-audio codec
1854 *
1855 * This frees the all PCM and control elements assigned to the codec, and
1856 * clears the caches and restores the pin default configurations.
1857 *
1858 * When a device is being used, it returns -EBSY. If successfully freed,
1859 * returns zero.
1860 */
1566int snd_hda_codec_reset(struct hda_codec *codec) 1861int snd_hda_codec_reset(struct hda_codec *codec)
1567{ 1862{
1568 struct snd_card *card = codec->bus->card; 1863 struct snd_card *card = codec->bus->card;
@@ -1626,7 +1921,22 @@ int snd_hda_codec_reset(struct hda_codec *codec)
1626 return 0; 1921 return 0;
1627} 1922}
1628 1923
1629/* create a virtual master control and add slaves */ 1924/**
1925 * snd_hda_add_vmaster - create a virtual master control and add slaves
1926 * @codec: HD-audio codec
1927 * @name: vmaster control name
1928 * @tlv: TLV data (optional)
1929 * @slaves: slave control names (optional)
1930 *
1931 * Create a virtual master control with the given name. The TLV data
1932 * must be either NULL or a valid data.
1933 *
1934 * @slaves is a NULL-terminated array of strings, each of which is a
1935 * slave control name. All controls with these names are assigned to
1936 * the new virtual master control.
1937 *
1938 * This function returns zero if successful or a negative error code.
1939 */
1630int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1940int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1631 unsigned int *tlv, const char **slaves) 1941 unsigned int *tlv, const char **slaves)
1632{ 1942{
@@ -1643,10 +1953,10 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1643 kctl = snd_ctl_make_virtual_master(name, tlv); 1953 kctl = snd_ctl_make_virtual_master(name, tlv);
1644 if (!kctl) 1954 if (!kctl)
1645 return -ENOMEM; 1955 return -ENOMEM;
1646 err = snd_hda_ctl_add(codec, kctl); 1956 err = snd_hda_ctl_add(codec, 0, kctl);
1647 if (err < 0) 1957 if (err < 0)
1648 return err; 1958 return err;
1649 1959
1650 for (s = slaves; *s; s++) { 1960 for (s = slaves; *s; s++) {
1651 struct snd_kcontrol *sctl; 1961 struct snd_kcontrol *sctl;
1652 int i = 0; 1962 int i = 0;
@@ -1668,7 +1978,12 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1668} 1978}
1669EXPORT_SYMBOL_HDA(snd_hda_add_vmaster); 1979EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1670 1980
1671/* switch */ 1981/**
1982 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
1983 *
1984 * The control element is supposed to have the private_value field
1985 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1986 */
1672int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1987int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_info *uinfo) 1988 struct snd_ctl_elem_info *uinfo)
1674{ 1989{
@@ -1682,6 +1997,12 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1682} 1997}
1683EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info); 1998EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1684 1999
2000/**
2001 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
2002 *
2003 * The control element is supposed to have the private_value field
2004 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2005 */
1685int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 2006int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol) 2007 struct snd_ctl_elem_value *ucontrol)
1687{ 2008{
@@ -1702,6 +2023,12 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1702} 2023}
1703EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get); 2024EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1704 2025
2026/**
2027 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
2028 *
2029 * The control element is supposed to have the private_value field
2030 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2031 */
1705int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 2032int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol) 2033 struct snd_ctl_elem_value *ucontrol)
1707{ 2034{
@@ -1733,6 +2060,25 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1733} 2060}
1734EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put); 2061EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1735 2062
2063#ifdef CONFIG_SND_HDA_INPUT_BEEP
2064/**
2065 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
2066 *
2067 * This function calls snd_hda_enable_beep_device(), which behaves differently
2068 * depending on beep_mode option.
2069 */
2070int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2071 struct snd_ctl_elem_value *ucontrol)
2072{
2073 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2074 long *valp = ucontrol->value.integer.value;
2075
2076 snd_hda_enable_beep_device(codec, *valp);
2077 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2078}
2079EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2080#endif /* CONFIG_SND_HDA_INPUT_BEEP */
2081
1736/* 2082/*
1737 * bound volume controls 2083 * bound volume controls
1738 * 2084 *
@@ -1742,6 +2088,12 @@ EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1742#define AMP_VAL_IDX_SHIFT 19 2088#define AMP_VAL_IDX_SHIFT 19
1743#define AMP_VAL_IDX_MASK (0x0f<<19) 2089#define AMP_VAL_IDX_MASK (0x0f<<19)
1744 2090
2091/**
2092 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2093 *
2094 * The control element is supposed to have the private_value field
2095 * set up via HDA_BIND_MUTE*() macros.
2096 */
1745int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, 2097int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol) 2098 struct snd_ctl_elem_value *ucontrol)
1747{ 2099{
@@ -1759,6 +2111,12 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1759} 2111}
1760EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get); 2112EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1761 2113
2114/**
2115 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2116 *
2117 * The control element is supposed to have the private_value field
2118 * set up via HDA_BIND_MUTE*() macros.
2119 */
1762int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 2120int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol) 2121 struct snd_ctl_elem_value *ucontrol)
1764{ 2122{
@@ -1783,8 +2141,11 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1783} 2141}
1784EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put); 2142EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1785 2143
1786/* 2144/**
1787 * generic bound volume/swtich controls 2145 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2146 *
2147 * The control element is supposed to have the private_value field
2148 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
1788 */ 2149 */
1789int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, 2150int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_info *uinfo) 2151 struct snd_ctl_elem_info *uinfo)
@@ -1803,6 +2164,12 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1803} 2164}
1804EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info); 2165EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1805 2166
2167/**
2168 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2169 *
2170 * The control element is supposed to have the private_value field
2171 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2172 */
1806int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 2173int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1807 struct snd_ctl_elem_value *ucontrol) 2174 struct snd_ctl_elem_value *ucontrol)
1808{ 2175{
@@ -1820,6 +2187,12 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1820} 2187}
1821EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get); 2188EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1822 2189
2190/**
2191 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2192 *
2193 * The control element is supposed to have the private_value field
2194 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2195 */
1823int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 2196int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol) 2197 struct snd_ctl_elem_value *ucontrol)
1825{ 2198{
@@ -1843,6 +2216,12 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1843} 2216}
1844EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put); 2217EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1845 2218
2219/**
2220 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2221 *
2222 * The control element is supposed to have the private_value field
2223 * set up via HDA_BIND_VOL() macro.
2224 */
1846int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 2225int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1847 unsigned int size, unsigned int __user *tlv) 2226 unsigned int size, unsigned int __user *tlv)
1848{ 2227{
@@ -2064,27 +2443,27 @@ static struct snd_kcontrol_new dig_mixes[] = {
2064 { 2443 {
2065 .access = SNDRV_CTL_ELEM_ACCESS_READ, 2444 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2066 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2445 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2067 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 2446 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
2068 .info = snd_hda_spdif_mask_info, 2447 .info = snd_hda_spdif_mask_info,
2069 .get = snd_hda_spdif_cmask_get, 2448 .get = snd_hda_spdif_cmask_get,
2070 }, 2449 },
2071 { 2450 {
2072 .access = SNDRV_CTL_ELEM_ACCESS_READ, 2451 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2073 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2074 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), 2453 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
2075 .info = snd_hda_spdif_mask_info, 2454 .info = snd_hda_spdif_mask_info,
2076 .get = snd_hda_spdif_pmask_get, 2455 .get = snd_hda_spdif_pmask_get,
2077 }, 2456 },
2078 { 2457 {
2079 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2458 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2080 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 2459 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
2081 .info = snd_hda_spdif_mask_info, 2460 .info = snd_hda_spdif_mask_info,
2082 .get = snd_hda_spdif_default_get, 2461 .get = snd_hda_spdif_default_get,
2083 .put = snd_hda_spdif_default_put, 2462 .put = snd_hda_spdif_default_put,
2084 }, 2463 },
2085 { 2464 {
2086 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2465 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2087 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 2466 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
2088 .info = snd_hda_spdif_out_switch_info, 2467 .info = snd_hda_spdif_out_switch_info,
2089 .get = snd_hda_spdif_out_switch_get, 2468 .get = snd_hda_spdif_out_switch_get,
2090 .put = snd_hda_spdif_out_switch_put, 2469 .put = snd_hda_spdif_out_switch_put,
@@ -2126,7 +2505,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2126 return -ENOMEM; 2505 return -ENOMEM;
2127 kctl->id.index = idx; 2506 kctl->id.index = idx;
2128 kctl->private_value = nid; 2507 kctl->private_value = nid;
2129 err = snd_hda_ctl_add(codec, kctl); 2508 err = snd_hda_ctl_add(codec, nid, kctl);
2130 if (err < 0) 2509 if (err < 0)
2131 return err; 2510 return err;
2132 } 2511 }
@@ -2165,14 +2544,19 @@ static struct snd_kcontrol_new spdif_share_sw = {
2165 .put = spdif_share_sw_put, 2544 .put = spdif_share_sw_put,
2166}; 2545};
2167 2546
2547/**
2548 * snd_hda_create_spdif_share_sw - create Default PCM switch
2549 * @codec: the HDA codec
2550 * @mout: multi-out instance
2551 */
2168int snd_hda_create_spdif_share_sw(struct hda_codec *codec, 2552int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2169 struct hda_multi_out *mout) 2553 struct hda_multi_out *mout)
2170{ 2554{
2171 if (!mout->dig_out_nid) 2555 if (!mout->dig_out_nid)
2172 return 0; 2556 return 0;
2173 /* ATTENTION: here mout is passed as private_data, instead of codec */ 2557 /* ATTENTION: here mout is passed as private_data, instead of codec */
2174 return snd_hda_ctl_add(codec, 2558 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2175 snd_ctl_new1(&spdif_share_sw, mout)); 2559 snd_ctl_new1(&spdif_share_sw, mout));
2176} 2560}
2177EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw); 2561EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2178 2562
@@ -2230,7 +2614,7 @@ static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
2230static struct snd_kcontrol_new dig_in_ctls[] = { 2614static struct snd_kcontrol_new dig_in_ctls[] = {
2231 { 2615 {
2232 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2616 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2233 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 2617 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
2234 .info = snd_hda_spdif_in_switch_info, 2618 .info = snd_hda_spdif_in_switch_info,
2235 .get = snd_hda_spdif_in_switch_get, 2619 .get = snd_hda_spdif_in_switch_get,
2236 .put = snd_hda_spdif_in_switch_put, 2620 .put = snd_hda_spdif_in_switch_put,
@@ -2238,7 +2622,7 @@ static struct snd_kcontrol_new dig_in_ctls[] = {
2238 { 2622 {
2239 .access = SNDRV_CTL_ELEM_ACCESS_READ, 2623 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2240 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2241 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), 2625 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
2242 .info = snd_hda_spdif_mask_info, 2626 .info = snd_hda_spdif_mask_info,
2243 .get = snd_hda_spdif_in_status_get, 2627 .get = snd_hda_spdif_in_status_get,
2244 }, 2628 },
@@ -2276,7 +2660,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2276 if (!kctl) 2660 if (!kctl)
2277 return -ENOMEM; 2661 return -ENOMEM;
2278 kctl->private_value = nid; 2662 kctl->private_value = nid;
2279 err = snd_hda_ctl_add(codec, kctl); 2663 err = snd_hda_ctl_add(codec, nid, kctl);
2280 if (err < 0) 2664 if (err < 0)
2281 return err; 2665 return err;
2282 } 2666 }
@@ -2332,7 +2716,12 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2332} 2716}
2333EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); 2717EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2334 2718
2335/* resume the all commands from the cache */ 2719/**
2720 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2721 * @codec: HD-audio codec
2722 *
2723 * Execute all verbs recorded in the command caches to resume.
2724 */
2336void snd_hda_codec_resume_cache(struct hda_codec *codec) 2725void snd_hda_codec_resume_cache(struct hda_codec *codec)
2337{ 2726{
2338 struct hda_cache_head *buffer = codec->cmd_cache.buf.list; 2727 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
@@ -2382,7 +2771,8 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2382 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 2771 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
2383 power_state); 2772 power_state);
2384 /* partial workaround for "azx_get_response timeout" */ 2773 /* partial workaround for "azx_get_response timeout" */
2385 if (power_state == AC_PWRST_D0) 2774 if (power_state == AC_PWRST_D0 &&
2775 (codec->vendor_id & 0xffff0000) == 0x14f10000)
2386 msleep(10); 2776 msleep(10);
2387 2777
2388 nid = codec->start_nid; 2778 nid = codec->start_nid;
@@ -2416,7 +2806,6 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2416 if (power_state == AC_PWRST_D0) { 2806 if (power_state == AC_PWRST_D0) {
2417 unsigned long end_time; 2807 unsigned long end_time;
2418 int state; 2808 int state;
2419 msleep(10);
2420 /* wait until the codec reachs to D0 */ 2809 /* wait until the codec reachs to D0 */
2421 end_time = jiffies + msecs_to_jiffies(500); 2810 end_time = jiffies + msecs_to_jiffies(500);
2422 do { 2811 do {
@@ -2452,9 +2841,11 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
2452 codec->afg ? codec->afg : codec->mfg, 2841 codec->afg ? codec->afg : codec->mfg,
2453 AC_PWRST_D3); 2842 AC_PWRST_D3);
2454#ifdef CONFIG_SND_HDA_POWER_SAVE 2843#ifdef CONFIG_SND_HDA_POWER_SAVE
2844 snd_hda_update_power_acct(codec);
2455 cancel_delayed_work(&codec->power_work); 2845 cancel_delayed_work(&codec->power_work);
2456 codec->power_on = 0; 2846 codec->power_on = 0;
2457 codec->power_transition = 0; 2847 codec->power_transition = 0;
2848 codec->power_jiffies = jiffies;
2458#endif 2849#endif
2459} 2850}
2460 2851
@@ -2495,8 +2886,8 @@ int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
2495 list_for_each_entry(codec, &bus->codec_list, list) { 2886 list_for_each_entry(codec, &bus->codec_list, list) {
2496 int err = snd_hda_codec_build_controls(codec); 2887 int err = snd_hda_codec_build_controls(codec);
2497 if (err < 0) { 2888 if (err < 0) {
2498 printk(KERN_ERR "hda_codec: cannot build controls" 2889 printk(KERN_ERR "hda_codec: cannot build controls "
2499 "for #%d (error %d)\n", codec->addr, err); 2890 "for #%d (error %d)\n", codec->addr, err);
2500 err = snd_hda_codec_reset(codec); 2891 err = snd_hda_codec_reset(codec);
2501 if (err < 0) { 2892 if (err < 0) {
2502 printk(KERN_ERR 2893 printk(KERN_ERR
@@ -2592,8 +2983,12 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2592 val |= channels - 1; 2983 val |= channels - 1;
2593 2984
2594 switch (snd_pcm_format_width(format)) { 2985 switch (snd_pcm_format_width(format)) {
2595 case 8: val |= 0x00; break; 2986 case 8:
2596 case 16: val |= 0x10; break; 2987 val |= 0x00;
2988 break;
2989 case 16:
2990 val |= 0x10;
2991 break;
2597 case 20: 2992 case 20:
2598 case 24: 2993 case 24:
2599 case 32: 2994 case 32:
@@ -2756,8 +3151,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2756} 3151}
2757 3152
2758/** 3153/**
2759 * snd_hda_is_supported_format - check whether the given node supports 3154 * snd_hda_is_supported_format - Check the validity of the format
2760 * the format val 3155 * @codec: HD-audio codec
3156 * @nid: NID to check
3157 * @format: the HD-audio format value to check
3158 *
3159 * Check whether the given node supports the format value.
2761 * 3160 *
2762 * Returns 1 if supported, 0 if not. 3161 * Returns 1 if supported, 0 if not.
2763 */ 3162 */
@@ -2877,51 +3276,39 @@ static int set_pcm_default_values(struct hda_codec *codec,
2877 return 0; 3276 return 0;
2878} 3277}
2879 3278
3279/* global */
3280const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3281 "Audio", "SPDIF", "HDMI", "Modem"
3282};
3283
2880/* 3284/*
2881 * get the empty PCM device number to assign 3285 * get the empty PCM device number to assign
3286 *
3287 * note the max device number is limited by HDA_MAX_PCMS, currently 10
2882 */ 3288 */
2883static int get_empty_pcm_device(struct hda_bus *bus, int type) 3289static int get_empty_pcm_device(struct hda_bus *bus, int type)
2884{ 3290{
2885 static const char *dev_name[HDA_PCM_NTYPES] = { 3291 /* audio device indices; not linear to keep compatibility */
2886 "Audio", "SPDIF", "HDMI", "Modem" 3292 static int audio_idx[HDA_PCM_NTYPES][5] = {
3293 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
3294 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
3295 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
3296 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
2887 }; 3297 };
2888 /* starting device index for each PCM type */ 3298 int i;
2889 static int dev_idx[HDA_PCM_NTYPES] = { 3299
2890 [HDA_PCM_TYPE_AUDIO] = 0, 3300 if (type >= HDA_PCM_NTYPES) {
2891 [HDA_PCM_TYPE_SPDIF] = 1,
2892 [HDA_PCM_TYPE_HDMI] = 3,
2893 [HDA_PCM_TYPE_MODEM] = 6
2894 };
2895 /* normal audio device indices; not linear to keep compatibility */
2896 static int audio_idx[4] = { 0, 2, 4, 5 };
2897 int i, dev;
2898
2899 switch (type) {
2900 case HDA_PCM_TYPE_AUDIO:
2901 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
2902 dev = audio_idx[i];
2903 if (!test_bit(dev, bus->pcm_dev_bits))
2904 goto ok;
2905 }
2906 snd_printk(KERN_WARNING "Too many audio devices\n");
2907 return -EAGAIN;
2908 case HDA_PCM_TYPE_SPDIF:
2909 case HDA_PCM_TYPE_HDMI:
2910 case HDA_PCM_TYPE_MODEM:
2911 dev = dev_idx[type];
2912 if (test_bit(dev, bus->pcm_dev_bits)) {
2913 snd_printk(KERN_WARNING "%s already defined\n",
2914 dev_name[type]);
2915 return -EAGAIN;
2916 }
2917 break;
2918 default:
2919 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); 3301 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2920 return -EINVAL; 3302 return -EINVAL;
2921 } 3303 }
2922 ok: 3304
2923 set_bit(dev, bus->pcm_dev_bits); 3305 for (i = 0; audio_idx[type][i] >= 0 ; i++)
2924 return dev; 3306 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3307 return audio_idx[type][i];
3308
3309 snd_printk(KERN_WARNING "Too many %s devices\n",
3310 snd_hda_pcm_type_name[type]);
3311 return -EAGAIN;
2925} 3312}
2926 3313
2927/* 3314/*
@@ -2958,7 +3345,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
2958 err = codec->patch_ops.build_pcms(codec); 3345 err = codec->patch_ops.build_pcms(codec);
2959 if (err < 0) { 3346 if (err < 0) {
2960 printk(KERN_ERR "hda_codec: cannot build PCMs" 3347 printk(KERN_ERR "hda_codec: cannot build PCMs"
2961 "for #%d (error %d)\n", codec->addr, err); 3348 "for #%d (error %d)\n", codec->addr, err);
2962 err = snd_hda_codec_reset(codec); 3349 err = snd_hda_codec_reset(codec);
2963 if (err < 0) { 3350 if (err < 0) {
2964 printk(KERN_ERR 3351 printk(KERN_ERR
@@ -3088,8 +3475,8 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_config);
3088 3475
3089/** 3476/**
3090 * snd_hda_check_board_codec_sid_config - compare the current codec 3477 * snd_hda_check_board_codec_sid_config - compare the current codec
3091 subsystem ID with the 3478 subsystem ID with the
3092 config table 3479 config table
3093 3480
3094 This is important for Gateway notebooks with SB450 HDA Audio 3481 This is important for Gateway notebooks with SB450 HDA Audio
3095 where the vendor ID of the PCI device is: 3482 where the vendor ID of the PCI device is:
@@ -3159,14 +3546,16 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3159 */ 3546 */
3160int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew) 3547int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3161{ 3548{
3162 int err; 3549 int err;
3163 3550
3164 for (; knew->name; knew++) { 3551 for (; knew->name; knew++) {
3165 struct snd_kcontrol *kctl; 3552 struct snd_kcontrol *kctl;
3553 if (knew->iface == -1) /* skip this codec private value */
3554 continue;
3166 kctl = snd_ctl_new1(knew, codec); 3555 kctl = snd_ctl_new1(knew, codec);
3167 if (!kctl) 3556 if (!kctl)
3168 return -ENOMEM; 3557 return -ENOMEM;
3169 err = snd_hda_ctl_add(codec, kctl); 3558 err = snd_hda_ctl_add(codec, 0, kctl);
3170 if (err < 0) { 3559 if (err < 0) {
3171 if (!codec->addr) 3560 if (!codec->addr)
3172 return err; 3561 return err;
@@ -3174,7 +3563,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3174 if (!kctl) 3563 if (!kctl)
3175 return -ENOMEM; 3564 return -ENOMEM;
3176 kctl->id.device = codec->addr; 3565 kctl->id.device = codec->addr;
3177 err = snd_hda_ctl_add(codec, kctl); 3566 err = snd_hda_ctl_add(codec, 0, kctl);
3178 if (err < 0) 3567 if (err < 0)
3179 return err; 3568 return err;
3180 } 3569 }
@@ -3207,8 +3596,27 @@ static void hda_keep_power_on(struct hda_codec *codec)
3207{ 3596{
3208 codec->power_count++; 3597 codec->power_count++;
3209 codec->power_on = 1; 3598 codec->power_on = 1;
3599 codec->power_jiffies = jiffies;
3600}
3601
3602/* update the power on/off account with the current jiffies */
3603void snd_hda_update_power_acct(struct hda_codec *codec)
3604{
3605 unsigned long delta = jiffies - codec->power_jiffies;
3606 if (codec->power_on)
3607 codec->power_on_acct += delta;
3608 else
3609 codec->power_off_acct += delta;
3610 codec->power_jiffies += delta;
3210} 3611}
3211 3612
3613/**
3614 * snd_hda_power_up - Power-up the codec
3615 * @codec: HD-audio codec
3616 *
3617 * Increment the power-up counter and power up the hardware really when
3618 * not turned on yet.
3619 */
3212void snd_hda_power_up(struct hda_codec *codec) 3620void snd_hda_power_up(struct hda_codec *codec)
3213{ 3621{
3214 struct hda_bus *bus = codec->bus; 3622 struct hda_bus *bus = codec->bus;
@@ -3217,7 +3625,9 @@ void snd_hda_power_up(struct hda_codec *codec)
3217 if (codec->power_on || codec->power_transition) 3625 if (codec->power_on || codec->power_transition)
3218 return; 3626 return;
3219 3627
3628 snd_hda_update_power_acct(codec);
3220 codec->power_on = 1; 3629 codec->power_on = 1;
3630 codec->power_jiffies = jiffies;
3221 if (bus->ops.pm_notify) 3631 if (bus->ops.pm_notify)
3222 bus->ops.pm_notify(bus); 3632 bus->ops.pm_notify(bus);
3223 hda_call_codec_resume(codec); 3633 hda_call_codec_resume(codec);
@@ -3229,9 +3639,13 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up);
3229#define power_save(codec) \ 3639#define power_save(codec) \
3230 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3640 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3231 3641
3232#define power_save(codec) \ 3642/**
3233 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3643 * snd_hda_power_down - Power-down the codec
3234 3644 * @codec: HD-audio codec
3645 *
3646 * Decrement the power-up counter and schedules the power-off work if
3647 * the counter rearches to zero.
3648 */
3235void snd_hda_power_down(struct hda_codec *codec) 3649void snd_hda_power_down(struct hda_codec *codec)
3236{ 3650{
3237 --codec->power_count; 3651 --codec->power_count;
@@ -3245,6 +3659,19 @@ void snd_hda_power_down(struct hda_codec *codec)
3245} 3659}
3246EXPORT_SYMBOL_HDA(snd_hda_power_down); 3660EXPORT_SYMBOL_HDA(snd_hda_power_down);
3247 3661
3662/**
3663 * snd_hda_check_amp_list_power - Check the amp list and update the power
3664 * @codec: HD-audio codec
3665 * @check: the object containing an AMP list and the status
3666 * @nid: NID to check / update
3667 *
3668 * Check whether the given NID is in the amp list. If it's in the list,
3669 * check the current AMP status, and update the the power-status according
3670 * to the mute status.
3671 *
3672 * This function is supposed to be set or called from the check_power_status
3673 * patch ops.
3674 */
3248int snd_hda_check_amp_list_power(struct hda_codec *codec, 3675int snd_hda_check_amp_list_power(struct hda_codec *codec,
3249 struct hda_loopback_check *check, 3676 struct hda_loopback_check *check,
3250 hda_nid_t nid) 3677 hda_nid_t nid)
@@ -3286,6 +3713,10 @@ EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3286/* 3713/*
3287 * Channel mode helper 3714 * Channel mode helper
3288 */ 3715 */
3716
3717/**
3718 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3719 */
3289int snd_hda_ch_mode_info(struct hda_codec *codec, 3720int snd_hda_ch_mode_info(struct hda_codec *codec,
3290 struct snd_ctl_elem_info *uinfo, 3721 struct snd_ctl_elem_info *uinfo,
3291 const struct hda_channel_mode *chmode, 3722 const struct hda_channel_mode *chmode,
@@ -3302,6 +3733,9 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
3302} 3733}
3303EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info); 3734EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3304 3735
3736/**
3737 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3738 */
3305int snd_hda_ch_mode_get(struct hda_codec *codec, 3739int snd_hda_ch_mode_get(struct hda_codec *codec,
3306 struct snd_ctl_elem_value *ucontrol, 3740 struct snd_ctl_elem_value *ucontrol,
3307 const struct hda_channel_mode *chmode, 3741 const struct hda_channel_mode *chmode,
@@ -3320,6 +3754,9 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
3320} 3754}
3321EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get); 3755EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3322 3756
3757/**
3758 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3759 */
3323int snd_hda_ch_mode_put(struct hda_codec *codec, 3760int snd_hda_ch_mode_put(struct hda_codec *codec,
3324 struct snd_ctl_elem_value *ucontrol, 3761 struct snd_ctl_elem_value *ucontrol,
3325 const struct hda_channel_mode *chmode, 3762 const struct hda_channel_mode *chmode,
@@ -3344,6 +3781,10 @@ EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3344/* 3781/*
3345 * input MUX helper 3782 * input MUX helper
3346 */ 3783 */
3784
3785/**
3786 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3787 */
3347int snd_hda_input_mux_info(const struct hda_input_mux *imux, 3788int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3348 struct snd_ctl_elem_info *uinfo) 3789 struct snd_ctl_elem_info *uinfo)
3349{ 3790{
@@ -3362,6 +3803,9 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3362} 3803}
3363EXPORT_SYMBOL_HDA(snd_hda_input_mux_info); 3804EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3364 3805
3806/**
3807 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3808 */
3365int snd_hda_input_mux_put(struct hda_codec *codec, 3809int snd_hda_input_mux_put(struct hda_codec *codec,
3366 const struct hda_input_mux *imux, 3810 const struct hda_input_mux *imux,
3367 struct snd_ctl_elem_value *ucontrol, 3811 struct snd_ctl_elem_value *ucontrol,
@@ -3395,7 +3839,7 @@ static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3395{ 3839{
3396 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ 3840 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3397 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) 3841 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
3398 set_dig_out_convert(codec, nid, 3842 set_dig_out_convert(codec, nid,
3399 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff, 3843 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff,
3400 -1); 3844 -1);
3401 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); 3845 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
@@ -3421,8 +3865,29 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3421 } 3865 }
3422} 3866}
3423 3867
3424/* 3868/**
3425 * open the digital out in the exclusive mode 3869 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3870 * @bus: HD-audio bus
3871 */
3872void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3873{
3874 struct hda_codec *codec;
3875
3876 if (!bus)
3877 return;
3878 list_for_each_entry(codec, &bus->codec_list, list) {
3879#ifdef CONFIG_SND_HDA_POWER_SAVE
3880 if (!codec->power_on)
3881 continue;
3882#endif
3883 if (codec->patch_ops.reboot_notify)
3884 codec->patch_ops.reboot_notify(codec);
3885 }
3886}
3887EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3888
3889/**
3890 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3426 */ 3891 */
3427int snd_hda_multi_out_dig_open(struct hda_codec *codec, 3892int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3428 struct hda_multi_out *mout) 3893 struct hda_multi_out *mout)
@@ -3437,6 +3902,9 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3437} 3902}
3438EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open); 3903EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3439 3904
3905/**
3906 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3907 */
3440int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3908int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3441 struct hda_multi_out *mout, 3909 struct hda_multi_out *mout,
3442 unsigned int stream_tag, 3910 unsigned int stream_tag,
@@ -3450,6 +3918,9 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3450} 3918}
3451EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare); 3919EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3452 3920
3921/**
3922 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3923 */
3453int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, 3924int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3454 struct hda_multi_out *mout) 3925 struct hda_multi_out *mout)
3455{ 3926{
@@ -3460,8 +3931,8 @@ int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3460} 3931}
3461EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup); 3932EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
3462 3933
3463/* 3934/**
3464 * release the digital out 3935 * snd_hda_multi_out_dig_close - release the digital out stream
3465 */ 3936 */
3466int snd_hda_multi_out_dig_close(struct hda_codec *codec, 3937int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3467 struct hda_multi_out *mout) 3938 struct hda_multi_out *mout)
@@ -3473,8 +3944,12 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3473} 3944}
3474EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close); 3945EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
3475 3946
3476/* 3947/**
3477 * set up more restrictions for analog out 3948 * snd_hda_multi_out_analog_open - open analog outputs
3949 *
3950 * Open analog outputs and set up the hw-constraints.
3951 * If the digital outputs can be opened as slave, open the digital
3952 * outputs, too.
3478 */ 3953 */
3479int snd_hda_multi_out_analog_open(struct hda_codec *codec, 3954int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3480 struct hda_multi_out *mout, 3955 struct hda_multi_out *mout,
@@ -3519,9 +3994,11 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3519} 3994}
3520EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open); 3995EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
3521 3996
3522/* 3997/**
3523 * set up the i/o for analog out 3998 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
3524 * when the digital out is available, copy the front out to digital out, too. 3999 *
4000 * Set up the i/o for analog out.
4001 * When the digital out is available, copy the front out to digital out, too.
3525 */ 4002 */
3526int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 4003int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3527 struct hda_multi_out *mout, 4004 struct hda_multi_out *mout,
@@ -3578,8 +4055,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3578} 4055}
3579EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); 4056EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
3580 4057
3581/* 4058/**
3582 * clean up the setting for analog out 4059 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3583 */ 4060 */
3584int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, 4061int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3585 struct hda_multi_out *mout) 4062 struct hda_multi_out *mout)
@@ -3621,13 +4098,13 @@ static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
3621/* 4098/*
3622 * Sort an associated group of pins according to their sequence numbers. 4099 * Sort an associated group of pins according to their sequence numbers.
3623 */ 4100 */
3624static void sort_pins_by_sequence(hda_nid_t * pins, short * sequences, 4101static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
3625 int num_pins) 4102 int num_pins)
3626{ 4103{
3627 int i, j; 4104 int i, j;
3628 short seq; 4105 short seq;
3629 hda_nid_t nid; 4106 hda_nid_t nid;
3630 4107
3631 for (i = 0; i < num_pins; i++) { 4108 for (i = 0; i < num_pins; i++) {
3632 for (j = i + 1; j < num_pins; j++) { 4109 for (j = i + 1; j < num_pins; j++) {
3633 if (sequences[i] > sequences[j]) { 4110 if (sequences[i] > sequences[j]) {
@@ -3655,7 +4132,7 @@ static void sort_pins_by_sequence(hda_nid_t * pins, short * sequences,
3655 * is detected, one of speaker of HP pins is assigned as the primary 4132 * is detected, one of speaker of HP pins is assigned as the primary
3656 * output, i.e. to line_out_pins[0]. So, line_outs is always positive 4133 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
3657 * if any analog output exists. 4134 * if any analog output exists.
3658 * 4135 *
3659 * The analog input pins are assigned to input_pins array. 4136 * The analog input pins are assigned to input_pins array.
3660 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, 4137 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
3661 * respectively. 4138 * respectively.
@@ -3718,9 +4195,9 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3718 case AC_JACK_SPEAKER: 4195 case AC_JACK_SPEAKER:
3719 seq = get_defcfg_sequence(def_conf); 4196 seq = get_defcfg_sequence(def_conf);
3720 assoc = get_defcfg_association(def_conf); 4197 assoc = get_defcfg_association(def_conf);
3721 if (! assoc) 4198 if (!assoc)
3722 continue; 4199 continue;
3723 if (! assoc_speaker) 4200 if (!assoc_speaker)
3724 assoc_speaker = assoc; 4201 assoc_speaker = assoc;
3725 else if (assoc_speaker != assoc) 4202 else if (assoc_speaker != assoc)
3726 continue; 4203 continue;
@@ -3818,7 +4295,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3818 cfg->speaker_outs); 4295 cfg->speaker_outs);
3819 sort_pins_by_sequence(cfg->hp_pins, sequences_hp, 4296 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
3820 cfg->hp_outs); 4297 cfg->hp_outs);
3821 4298
3822 /* if we have only one mic, make it AUTO_PIN_MIC */ 4299 /* if we have only one mic, make it AUTO_PIN_MIC */
3823 if (!cfg->input_pins[AUTO_PIN_MIC] && 4300 if (!cfg->input_pins[AUTO_PIN_MIC] &&
3824 cfg->input_pins[AUTO_PIN_FRONT_MIC]) { 4301 cfg->input_pins[AUTO_PIN_FRONT_MIC]) {
@@ -3965,8 +4442,14 @@ EXPORT_SYMBOL_HDA(snd_hda_resume);
3965 * generic arrays 4442 * generic arrays
3966 */ 4443 */
3967 4444
3968/* get a new element from the given array 4445/**
3969 * if it exceeds the pre-allocated array size, re-allocate the array 4446 * snd_array_new - get a new element from the given array
4447 * @array: the array object
4448 *
4449 * Get a new element from the given array. If it exceeds the
4450 * pre-allocated array size, re-allocate the array.
4451 *
4452 * Returns NULL if allocation failed.
3970 */ 4453 */
3971void *snd_array_new(struct snd_array *array) 4454void *snd_array_new(struct snd_array *array)
3972{ 4455{
@@ -3990,7 +4473,10 @@ void *snd_array_new(struct snd_array *array)
3990} 4473}
3991EXPORT_SYMBOL_HDA(snd_array_new); 4474EXPORT_SYMBOL_HDA(snd_array_new);
3992 4475
3993/* free the given array elements */ 4476/**
4477 * snd_array_free - free the given array elements
4478 * @array: the array object
4479 */
3994void snd_array_free(struct snd_array *array) 4480void snd_array_free(struct snd_array *array)
3995{ 4481{
3996 kfree(array->list); 4482 kfree(array->list);
@@ -4000,7 +4486,12 @@ void snd_array_free(struct snd_array *array)
4000} 4486}
4001EXPORT_SYMBOL_HDA(snd_array_free); 4487EXPORT_SYMBOL_HDA(snd_array_free);
4002 4488
4003/* 4489/**
4490 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4491 * @pcm: PCM caps bits
4492 * @buf: the string buffer to write
4493 * @buflen: the max buffer length
4494 *
4004 * used by hda_proc.c and hda_eld.c 4495 * used by hda_proc.c and hda_eld.c
4005 */ 4496 */
4006void snd_print_pcm_rates(int pcm, char *buf, int buflen) 4497void snd_print_pcm_rates(int pcm, char *buf, int buflen)
@@ -4019,6 +4510,14 @@ void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4019} 4510}
4020EXPORT_SYMBOL_HDA(snd_print_pcm_rates); 4511EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4021 4512
4513/**
4514 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4515 * @pcm: PCM caps bits
4516 * @buf: the string buffer to write
4517 * @buflen: the max buffer length
4518 *
4519 * used by hda_proc.c and hda_eld.c
4520 */
4022void snd_print_pcm_bits(int pcm, char *buf, int buflen) 4521void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4023{ 4522{
4024 static unsigned int bits[] = { 8, 16, 20, 24, 32 }; 4523 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 99552fb5f756..b75da47571e6 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -255,9 +255,13 @@ enum {
255 * in HD-audio specification 255 * in HD-audio specification
256 */ 256 */
257#define AC_PINCAP_HDMI (1<<7) /* HDMI pin */ 257#define AC_PINCAP_HDMI (1<<7) /* HDMI pin */
258#define AC_PINCAP_DP (1<<24) /* DisplayPort pin, can
259 * coexist with AC_PINCAP_HDMI
260 */
258#define AC_PINCAP_VREF (0x37<<8) 261#define AC_PINCAP_VREF (0x37<<8)
259#define AC_PINCAP_VREF_SHIFT 8 262#define AC_PINCAP_VREF_SHIFT 8
260#define AC_PINCAP_EAPD (1<<16) /* EAPD capable */ 263#define AC_PINCAP_EAPD (1<<16) /* EAPD capable */
264#define AC_PINCAP_HBR (1<<27) /* High Bit Rate */
261/* Vref status (used in pin cap) */ 265/* Vref status (used in pin cap) */
262#define AC_PINCAP_VREF_HIZ (1<<0) /* Hi-Z */ 266#define AC_PINCAP_VREF_HIZ (1<<0) /* Hi-Z */
263#define AC_PINCAP_VREF_50 (1<<1) /* 50% */ 267#define AC_PINCAP_VREF_50 (1<<1) /* 50% */
@@ -286,6 +290,10 @@ enum {
286#define AC_PWRST_D1SUP (1<<1) 290#define AC_PWRST_D1SUP (1<<1)
287#define AC_PWRST_D2SUP (1<<2) 291#define AC_PWRST_D2SUP (1<<2)
288#define AC_PWRST_D3SUP (1<<3) 292#define AC_PWRST_D3SUP (1<<3)
293#define AC_PWRST_D3COLDSUP (1<<4)
294#define AC_PWRST_S3D3COLDSUP (1<<29)
295#define AC_PWRST_CLKSTOP (1<<30)
296#define AC_PWRST_EPSS (1U<<31)
289 297
290/* Power state values */ 298/* Power state values */
291#define AC_PWRST_SETTING (0xf<<0) 299#define AC_PWRST_SETTING (0xf<<0)
@@ -519,6 +527,9 @@ enum {
519/* max. codec address */ 527/* max. codec address */
520#define HDA_MAX_CODEC_ADDRESS 0x0f 528#define HDA_MAX_CODEC_ADDRESS 0x0f
521 529
530/* max number of PCM devics per card */
531#define HDA_MAX_PCMS 10
532
522/* 533/*
523 * generic arrays 534 * generic arrays
524 */ 535 */
@@ -631,6 +642,7 @@ struct hda_bus {
631 unsigned int rirb_error:1; /* error in codec communication */ 642 unsigned int rirb_error:1; /* error in codec communication */
632 unsigned int response_reset:1; /* controller was reset */ 643 unsigned int response_reset:1; /* controller was reset */
633 unsigned int in_reset:1; /* during reset operation */ 644 unsigned int in_reset:1; /* during reset operation */
645 unsigned int power_keep_link_on:1; /* don't power off HDA link */
634}; 646};
635 647
636/* 648/*
@@ -674,6 +686,7 @@ struct hda_codec_ops {
674#ifdef CONFIG_SND_HDA_POWER_SAVE 686#ifdef CONFIG_SND_HDA_POWER_SAVE
675 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); 687 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
676#endif 688#endif
689 void (*reboot_notify)(struct hda_codec *codec);
677}; 690};
678 691
679/* record for amp information cache */ 692/* record for amp information cache */
@@ -771,6 +784,7 @@ struct hda_codec {
771 784
772 /* beep device */ 785 /* beep device */
773 struct hda_beep *beep; 786 struct hda_beep *beep;
787 unsigned int beep_mode;
774 788
775 /* widget capabilities cache */ 789 /* widget capabilities cache */
776 unsigned int num_nodes; 790 unsigned int num_nodes;
@@ -778,6 +792,7 @@ struct hda_codec {
778 u32 *wcaps; 792 u32 *wcaps;
779 793
780 struct snd_array mixers; /* list of assigned mixer elements */ 794 struct snd_array mixers; /* list of assigned mixer elements */
795 struct snd_array nids; /* list of mapped mixer elements */
781 796
782 struct hda_cache_rec amp_cache; /* cache for amp access */ 797 struct hda_cache_rec amp_cache; /* cache for amp access */
783 struct hda_cache_rec cmd_cache; /* cache for other commands */ 798 struct hda_cache_rec cmd_cache; /* cache for other commands */
@@ -806,11 +821,15 @@ struct hda_codec {
806 unsigned int pin_amp_workaround:1; /* pin out-amp takes index 821 unsigned int pin_amp_workaround:1; /* pin out-amp takes index
807 * (e.g. Conexant codecs) 822 * (e.g. Conexant codecs)
808 */ 823 */
824 unsigned int no_trigger_sense:1; /* don't trigger at pin-sensing */
809#ifdef CONFIG_SND_HDA_POWER_SAVE 825#ifdef CONFIG_SND_HDA_POWER_SAVE
810 unsigned int power_on :1; /* current (global) power-state */ 826 unsigned int power_on :1; /* current (global) power-state */
811 unsigned int power_transition :1; /* power-state in transition */ 827 unsigned int power_transition :1; /* power-state in transition */
812 int power_count; /* current (global) power refcount */ 828 int power_count; /* current (global) power refcount */
813 struct delayed_work power_work; /* delayed task for powerdown */ 829 struct delayed_work power_work; /* delayed task for powerdown */
830 unsigned long power_on_acct;
831 unsigned long power_off_acct;
832 unsigned long power_jiffies;
814#endif 833#endif
815 834
816 /* codec-specific additional proc output */ 835 /* codec-specific additional proc output */
@@ -883,6 +902,7 @@ int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid,
883 unsigned int cfg); 902 unsigned int cfg);
884int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list, 903int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
885 hda_nid_t nid, unsigned int cfg); /* for hwdep */ 904 hda_nid_t nid, unsigned int cfg); /* for hwdep */
905void snd_hda_shutup_pins(struct hda_codec *codec);
886 906
887/* 907/*
888 * Mixer 908 * Mixer
@@ -910,6 +930,7 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
910 * Misc 930 * Misc
911 */ 931 */
912void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); 932void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
933void snd_hda_bus_reboot_notify(struct hda_bus *bus);
913 934
914/* 935/*
915 * power management 936 * power management
@@ -933,6 +954,7 @@ const char *snd_hda_get_jack_location(u32 cfg);
933void snd_hda_power_up(struct hda_codec *codec); 954void snd_hda_power_up(struct hda_codec *codec);
934void snd_hda_power_down(struct hda_codec *codec); 955void snd_hda_power_down(struct hda_codec *codec);
935#define snd_hda_codec_needs_resume(codec) codec->power_count 956#define snd_hda_codec_needs_resume(codec) codec->power_count
957void snd_hda_update_power_acct(struct hda_codec *codec);
936#else 958#else
937static inline void snd_hda_power_up(struct hda_codec *codec) {} 959static inline void snd_hda_power_up(struct hda_codec *codec) {}
938static inline void snd_hda_power_down(struct hda_codec *codec) {} 960static inline void snd_hda_power_down(struct hda_codec *codec) {}
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index 9446a5abea13..d8da18a9e98b 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include <asm/unaligned.h> 27#include <asm/unaligned.h>
27#include "hda_codec.h" 28#include "hda_codec.h"
@@ -309,17 +310,12 @@ out_fail:
309 return -EINVAL; 310 return -EINVAL;
310} 311}
311 312
312static int hdmi_present_sense(struct hda_codec *codec, hda_nid_t nid)
313{
314 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0);
315}
316
317static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid) 313static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid)
318{ 314{
319 int eldv; 315 int eldv;
320 int present; 316 int present;
321 317
322 present = hdmi_present_sense(codec, nid); 318 present = snd_hda_pin_sense(codec, nid);
323 eldv = (present & AC_PINSENSE_ELDV); 319 eldv = (present & AC_PINSENSE_ELDV);
324 present = (present & AC_PINSENSE_PRESENCE); 320 present = (present & AC_PINSENSE_PRESENCE);
325 321
@@ -336,6 +332,7 @@ int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid)
336 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE, 332 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE,
337 AC_DIPSIZE_ELD_BUF); 333 AC_DIPSIZE_ELD_BUF);
338} 334}
335EXPORT_SYMBOL_HDA(snd_hdmi_get_eld_size);
339 336
340int snd_hdmi_get_eld(struct hdmi_eld *eld, 337int snd_hdmi_get_eld(struct hdmi_eld *eld,
341 struct hda_codec *codec, hda_nid_t nid) 338 struct hda_codec *codec, hda_nid_t nid)
@@ -371,6 +368,7 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
371 kfree(buf); 368 kfree(buf);
372 return ret; 369 return ret;
373} 370}
371EXPORT_SYMBOL_HDA(snd_hdmi_get_eld);
374 372
375static void hdmi_show_short_audio_desc(struct cea_sad *a) 373static void hdmi_show_short_audio_desc(struct cea_sad *a)
376{ 374{
@@ -409,6 +407,7 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen)
409 } 407 }
410 buf[j] = '\0'; /* necessary when j == 0 */ 408 buf[j] = '\0'; /* necessary when j == 0 */
411} 409}
410EXPORT_SYMBOL_HDA(snd_print_channel_allocation);
412 411
413void snd_hdmi_show_eld(struct hdmi_eld *e) 412void snd_hdmi_show_eld(struct hdmi_eld *e)
414{ 413{
@@ -427,6 +426,7 @@ void snd_hdmi_show_eld(struct hdmi_eld *e)
427 for (i = 0; i < e->sad_count; i++) 426 for (i = 0; i < e->sad_count; i++)
428 hdmi_show_short_audio_desc(e->sad + i); 427 hdmi_show_short_audio_desc(e->sad + i);
429} 428}
429EXPORT_SYMBOL_HDA(snd_hdmi_show_eld);
430 430
431#ifdef CONFIG_PROC_FS 431#ifdef CONFIG_PROC_FS
432 432
@@ -477,6 +477,8 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
477 [4 ... 7] = "reserved" 477 [4 ... 7] = "reserved"
478 }; 478 };
479 479
480 snd_iprintf(buffer, "monitor_present\t\t%d\n", e->monitor_present);
481 snd_iprintf(buffer, "eld_valid\t\t%d\n", e->eld_valid);
480 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name); 482 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
481 snd_iprintf(buffer, "connection_type\t\t%s\n", 483 snd_iprintf(buffer, "connection_type\t\t%s\n",
482 eld_connection_type_names[e->conn_type]); 484 eld_connection_type_names[e->conn_type]);
@@ -518,7 +520,11 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
518 * monitor_name manufacture_id product_id 520 * monitor_name manufacture_id product_id
519 * eld_version edid_version 521 * eld_version edid_version
520 */ 522 */
521 if (!strcmp(name, "connection_type")) 523 if (!strcmp(name, "monitor_present"))
524 e->monitor_present = val;
525 else if (!strcmp(name, "eld_valid"))
526 e->eld_valid = val;
527 else if (!strcmp(name, "connection_type"))
522 e->conn_type = val; 528 e->conn_type = val;
523 else if (!strcmp(name, "port_id")) 529 else if (!strcmp(name, "port_id"))
524 e->port_id = val; 530 e->port_id = val;
@@ -560,13 +566,14 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
560} 566}
561 567
562 568
563int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld) 569int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
570 int index)
564{ 571{
565 char name[32]; 572 char name[32];
566 struct snd_info_entry *entry; 573 struct snd_info_entry *entry;
567 int err; 574 int err;
568 575
569 snprintf(name, sizeof(name), "eld#%d", codec->addr); 576 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
570 err = snd_card_proc_new(codec->bus->card, name, &entry); 577 err = snd_card_proc_new(codec->bus->card, name, &entry);
571 if (err < 0) 578 if (err < 0)
572 return err; 579 return err;
@@ -578,6 +585,7 @@ int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld)
578 585
579 return 0; 586 return 0;
580} 587}
588EXPORT_SYMBOL_HDA(snd_hda_eld_proc_new);
581 589
582void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld) 590void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld)
583{ 591{
@@ -586,5 +594,6 @@ void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld)
586 eld->proc_entry = NULL; 594 eld->proc_entry = NULL;
587 } 595 }
588} 596}
597EXPORT_SYMBOL_HDA(snd_hda_eld_proc_free);
589 598
590#endif /* CONFIG_PROC_FS */ 599#endif /* CONFIG_PROC_FS */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index b36f6c5a92df..5ea21285ee1f 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -727,7 +727,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
727 if (is_loopback) 727 if (is_loopback)
728 add_input_loopback(codec, node->nid, HDA_INPUT, index); 728 add_input_loopback(codec, node->nid, HDA_INPUT, index);
729 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 729 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
730 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 730 err = snd_hda_ctl_add(codec, node->nid,
731 snd_ctl_new1(&knew, codec));
731 if (err < 0) 732 if (err < 0)
732 return err; 733 return err;
733 created = 1; 734 created = 1;
@@ -737,7 +738,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
737 if (is_loopback) 738 if (is_loopback)
738 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0); 739 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0);
739 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 740 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
740 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 741 err = snd_hda_ctl_add(codec, node->nid,
742 snd_ctl_new1(&knew, codec));
741 if (err < 0) 743 if (err < 0)
742 return err; 744 return err;
743 created = 1; 745 created = 1;
@@ -751,7 +753,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
751 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) { 753 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
752 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT); 754 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
753 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); 755 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
754 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 756 err = snd_hda_ctl_add(codec, node->nid,
757 snd_ctl_new1(&knew, codec));
755 if (err < 0) 758 if (err < 0)
756 return err; 759 return err;
757 created = 1; 760 created = 1;
@@ -759,7 +762,8 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
759 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) { 762 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
760 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT); 763 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
761 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); 764 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
762 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 765 err = snd_hda_ctl_add(codec, node->nid,
766 snd_ctl_new1(&knew, codec));
763 if (err < 0) 767 if (err < 0)
764 return err; 768 return err;
765 created = 1; 769 created = 1;
@@ -857,7 +861,8 @@ static int build_input_controls(struct hda_codec *codec)
857 } 861 }
858 862
859 /* create input MUX if multiple sources are available */ 863 /* create input MUX if multiple sources are available */
860 err = snd_hda_ctl_add(codec, snd_ctl_new1(&cap_sel, codec)); 864 err = snd_hda_ctl_add(codec, spec->adc_node->nid,
865 snd_ctl_new1(&cap_sel, codec));
861 if (err < 0) 866 if (err < 0)
862 return err; 867 return err;
863 868
@@ -875,7 +880,8 @@ static int build_input_controls(struct hda_codec *codec)
875 HDA_CODEC_VOLUME(name, adc_node->nid, 880 HDA_CODEC_VOLUME(name, adc_node->nid,
876 spec->input_mux.items[i].index, 881 spec->input_mux.items[i].index,
877 HDA_INPUT); 882 HDA_INPUT);
878 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 883 err = snd_hda_ctl_add(codec, adc_node->nid,
884 snd_ctl_new1(&knew, codec));
879 if (err < 0) 885 if (err < 0)
880 return err; 886 return err;
881 } 887 }
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index cc24e6721d74..a1fc83753cc6 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -24,6 +24,7 @@
24#include <linux/compat.h> 24#include <linux/compat.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/ctype.h> 26#include <linux/ctype.h>
27#include <linux/string.h>
27#include <linux/firmware.h> 28#include <linux/firmware.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include "hda_codec.h" 30#include "hda_codec.h"
@@ -154,6 +155,44 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec)
154 return 0; 155 return 0;
155} 156}
156 157
158#ifdef CONFIG_SND_HDA_POWER_SAVE
159static ssize_t power_on_acct_show(struct device *dev,
160 struct device_attribute *attr,
161 char *buf)
162{
163 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
164 struct hda_codec *codec = hwdep->private_data;
165 snd_hda_update_power_acct(codec);
166 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
167}
168
169static ssize_t power_off_acct_show(struct device *dev,
170 struct device_attribute *attr,
171 char *buf)
172{
173 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
174 struct hda_codec *codec = hwdep->private_data;
175 snd_hda_update_power_acct(codec);
176 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
177}
178
179static struct device_attribute power_attrs[] = {
180 __ATTR_RO(power_on_acct),
181 __ATTR_RO(power_off_acct),
182};
183
184int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
185{
186 struct snd_hwdep *hwdep = codec->hwdep;
187 int i;
188
189 for (i = 0; i < ARRAY_SIZE(power_attrs); i++)
190 snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card,
191 hwdep->device, &power_attrs[i]);
192 return 0;
193}
194#endif /* CONFIG_SND_HDA_POWER_SAVE */
195
157#ifdef CONFIG_SND_HDA_RECONFIG 196#ifdef CONFIG_SND_HDA_RECONFIG
158 197
159/* 198/*
@@ -254,8 +293,11 @@ static ssize_t type##_store(struct device *dev, \
254{ \ 293{ \
255 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \ 294 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
256 struct hda_codec *codec = hwdep->private_data; \ 295 struct hda_codec *codec = hwdep->private_data; \
257 char *after; \ 296 unsigned long val; \
258 codec->type = simple_strtoul(buf, &after, 0); \ 297 int err = strict_strtoul(buf, 0, &val); \
298 if (err < 0) \
299 return err; \
300 codec->type = val; \
259 return count; \ 301 return count; \
260} 302}
261 303
@@ -390,8 +432,7 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
390 char *key, *val; 432 char *key, *val;
391 struct hda_hint *hint; 433 struct hda_hint *hint;
392 434
393 while (isspace(*buf)) 435 buf = skip_spaces(buf);
394 buf++;
395 if (!*buf || *buf == '#' || *buf == '\n') 436 if (!*buf || *buf == '#' || *buf == '\n')
396 return 0; 437 return 0;
397 if (*buf == '=') 438 if (*buf == '=')
@@ -406,8 +447,7 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
406 return -EINVAL; 447 return -EINVAL;
407 } 448 }
408 *val++ = 0; 449 *val++ = 0;
409 while (isspace(*val)) 450 val = skip_spaces(val);
410 val++;
411 remove_trail_spaces(key); 451 remove_trail_spaces(key);
412 remove_trail_spaces(val); 452 remove_trail_spaces(val);
413 hint = get_hint(codec, key); 453 hint = get_hint(codec, key);
@@ -585,6 +625,10 @@ enum {
585 LINE_MODE_PINCFG, 625 LINE_MODE_PINCFG,
586 LINE_MODE_VERB, 626 LINE_MODE_VERB,
587 LINE_MODE_HINT, 627 LINE_MODE_HINT,
628 LINE_MODE_VENDOR_ID,
629 LINE_MODE_SUBSYSTEM_ID,
630 LINE_MODE_REVISION_ID,
631 LINE_MODE_CHIP_NAME,
588 NUM_LINE_MODES, 632 NUM_LINE_MODES,
589}; 633};
590 634
@@ -614,53 +658,71 @@ static void parse_codec_mode(char *buf, struct hda_bus *bus,
614} 658}
615 659
616/* parse the contents after the other command tags, [pincfg], [verb], 660/* parse the contents after the other command tags, [pincfg], [verb],
617 * [hint] and [model] 661 * [vendor_id], [subsystem_id], [revision_id], [chip_name], [hint] and [model]
618 * just pass to the sysfs helper (only when any codec was specified) 662 * just pass to the sysfs helper (only when any codec was specified)
619 */ 663 */
620static void parse_pincfg_mode(char *buf, struct hda_bus *bus, 664static void parse_pincfg_mode(char *buf, struct hda_bus *bus,
621 struct hda_codec **codecp) 665 struct hda_codec **codecp)
622{ 666{
623 if (!*codecp)
624 return;
625 parse_user_pin_configs(*codecp, buf); 667 parse_user_pin_configs(*codecp, buf);
626} 668}
627 669
628static void parse_verb_mode(char *buf, struct hda_bus *bus, 670static void parse_verb_mode(char *buf, struct hda_bus *bus,
629 struct hda_codec **codecp) 671 struct hda_codec **codecp)
630{ 672{
631 if (!*codecp)
632 return;
633 parse_init_verbs(*codecp, buf); 673 parse_init_verbs(*codecp, buf);
634} 674}
635 675
636static void parse_hint_mode(char *buf, struct hda_bus *bus, 676static void parse_hint_mode(char *buf, struct hda_bus *bus,
637 struct hda_codec **codecp) 677 struct hda_codec **codecp)
638{ 678{
639 if (!*codecp)
640 return;
641 parse_hints(*codecp, buf); 679 parse_hints(*codecp, buf);
642} 680}
643 681
644static void parse_model_mode(char *buf, struct hda_bus *bus, 682static void parse_model_mode(char *buf, struct hda_bus *bus,
645 struct hda_codec **codecp) 683 struct hda_codec **codecp)
646{ 684{
647 if (!*codecp)
648 return;
649 kfree((*codecp)->modelname); 685 kfree((*codecp)->modelname);
650 (*codecp)->modelname = kstrdup(buf, GFP_KERNEL); 686 (*codecp)->modelname = kstrdup(buf, GFP_KERNEL);
651} 687}
652 688
689static void parse_chip_name_mode(char *buf, struct hda_bus *bus,
690 struct hda_codec **codecp)
691{
692 kfree((*codecp)->chip_name);
693 (*codecp)->chip_name = kstrdup(buf, GFP_KERNEL);
694}
695
696#define DEFINE_PARSE_ID_MODE(name) \
697static void parse_##name##_mode(char *buf, struct hda_bus *bus, \
698 struct hda_codec **codecp) \
699{ \
700 unsigned long val; \
701 if (!strict_strtoul(buf, 0, &val)) \
702 (*codecp)->name = val; \
703}
704
705DEFINE_PARSE_ID_MODE(vendor_id);
706DEFINE_PARSE_ID_MODE(subsystem_id);
707DEFINE_PARSE_ID_MODE(revision_id);
708
709
653struct hda_patch_item { 710struct hda_patch_item {
654 const char *tag; 711 const char *tag;
655 void (*parser)(char *buf, struct hda_bus *bus, struct hda_codec **retc); 712 void (*parser)(char *buf, struct hda_bus *bus, struct hda_codec **retc);
713 int need_codec;
656}; 714};
657 715
658static struct hda_patch_item patch_items[NUM_LINE_MODES] = { 716static struct hda_patch_item patch_items[NUM_LINE_MODES] = {
659 [LINE_MODE_CODEC] = { "[codec]", parse_codec_mode }, 717 [LINE_MODE_CODEC] = { "[codec]", parse_codec_mode, 0 },
660 [LINE_MODE_MODEL] = { "[model]", parse_model_mode }, 718 [LINE_MODE_MODEL] = { "[model]", parse_model_mode, 1 },
661 [LINE_MODE_VERB] = { "[verb]", parse_verb_mode }, 719 [LINE_MODE_VERB] = { "[verb]", parse_verb_mode, 1 },
662 [LINE_MODE_PINCFG] = { "[pincfg]", parse_pincfg_mode }, 720 [LINE_MODE_PINCFG] = { "[pincfg]", parse_pincfg_mode, 1 },
663 [LINE_MODE_HINT] = { "[hint]", parse_hint_mode }, 721 [LINE_MODE_HINT] = { "[hint]", parse_hint_mode, 1 },
722 [LINE_MODE_VENDOR_ID] = { "[vendor_id]", parse_vendor_id_mode, 1 },
723 [LINE_MODE_SUBSYSTEM_ID] = { "[subsystem_id]", parse_subsystem_id_mode, 1 },
724 [LINE_MODE_REVISION_ID] = { "[revision_id]", parse_revision_id_mode, 1 },
725 [LINE_MODE_CHIP_NAME] = { "[chip_name]", parse_chip_name_mode, 1 },
664}; 726};
665 727
666/* check the line starting with '[' -- change the parser mode accodingly */ 728/* check the line starting with '[' -- change the parser mode accodingly */
@@ -743,7 +805,8 @@ int snd_hda_load_patch(struct hda_bus *bus, const char *patch)
743 continue; 805 continue;
744 if (*buf == '[') 806 if (*buf == '[')
745 line_mode = parse_line_mode(buf, bus); 807 line_mode = parse_line_mode(buf, bus);
746 else if (patch_items[line_mode].parser) 808 else if (patch_items[line_mode].parser &&
809 (codec || !patch_items[line_mode].need_codec))
747 patch_items[line_mode].parser(buf, bus, &codec); 810 patch_items[line_mode].parser(buf, bus, &codec);
748 } 811 }
749 release_firmware(fw); 812 release_firmware(fw);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 6517f589d01d..cec68152dcb1 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -60,10 +60,14 @@ static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
60static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; 60static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
61static int probe_only[SNDRV_CARDS]; 61static int probe_only[SNDRV_CARDS];
62static int single_cmd; 62static int single_cmd;
63static int enable_msi; 63static int enable_msi = -1;
64#ifdef CONFIG_SND_HDA_PATCH_LOADER 64#ifdef CONFIG_SND_HDA_PATCH_LOADER
65static char *patch[SNDRV_CARDS]; 65static char *patch[SNDRV_CARDS];
66#endif 66#endif
67#ifdef CONFIG_SND_HDA_INPUT_BEEP
68static int beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
69 CONFIG_SND_HDA_INPUT_BEEP_MODE};
70#endif
67 71
68module_param_array(index, int, NULL, 0444); 72module_param_array(index, int, NULL, 0444);
69MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); 73MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
@@ -91,6 +95,11 @@ MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
91module_param_array(patch, charp, NULL, 0444); 95module_param_array(patch, charp, NULL, 0444);
92MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface."); 96MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface.");
93#endif 97#endif
98#ifdef CONFIG_SND_HDA_INPUT_BEEP
99module_param_array(beep_mode, int, NULL, 0444);
100MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
101 "(0=off, 1=on, 2=mute switch on/off) (default=1).");
102#endif
94 103
95#ifdef CONFIG_SND_HDA_POWER_SAVE 104#ifdef CONFIG_SND_HDA_POWER_SAVE
96static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; 105static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
@@ -116,6 +125,7 @@ MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
116 "{Intel, ICH9}," 125 "{Intel, ICH9},"
117 "{Intel, ICH10}," 126 "{Intel, ICH10},"
118 "{Intel, PCH}," 127 "{Intel, PCH},"
128 "{Intel, CPT},"
119 "{Intel, SCH}," 129 "{Intel, SCH},"
120 "{ATI, SB450}," 130 "{ATI, SB450},"
121 "{ATI, SB600}," 131 "{ATI, SB600},"
@@ -250,8 +260,6 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
250#define AZX_MAX_FRAG 32 260#define AZX_MAX_FRAG 32
251/* max buffer size - no h/w limit, you can increase as you like */ 261/* max buffer size - no h/w limit, you can increase as you like */
252#define AZX_MAX_BUF_SIZE (1024*1024*1024) 262#define AZX_MAX_BUF_SIZE (1024*1024*1024)
253/* max number of PCM devics per card */
254#define AZX_MAX_PCMS 8
255 263
256/* RIRB int mask: overrun[2], response[0] */ 264/* RIRB int mask: overrun[2], response[0] */
257#define RIRB_INT_RESPONSE 0x01 265#define RIRB_INT_RESPONSE 0x01
@@ -259,7 +267,8 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
259#define RIRB_INT_MASK 0x05 267#define RIRB_INT_MASK 0x05
260 268
261/* STATESTS int mask: S3,SD2,SD1,SD0 */ 269/* STATESTS int mask: S3,SD2,SD1,SD0 */
262#define AZX_MAX_CODECS 4 270#define AZX_MAX_CODECS 8
271#define AZX_DEFAULT_CODECS 4
263#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1) 272#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
264 273
265/* SD_CTL bits */ 274/* SD_CTL bits */
@@ -347,6 +356,7 @@ struct azx_dev {
347 */ 356 */
348 unsigned char stream_tag; /* assigned stream */ 357 unsigned char stream_tag; /* assigned stream */
349 unsigned char index; /* stream index */ 358 unsigned char index; /* stream index */
359 int device; /* last device number assigned to */
350 360
351 unsigned int opened :1; 361 unsigned int opened :1;
352 unsigned int running :1; 362 unsigned int running :1;
@@ -398,12 +408,13 @@ struct azx {
398 struct azx_dev *azx_dev; 408 struct azx_dev *azx_dev;
399 409
400 /* PCM */ 410 /* PCM */
401 struct snd_pcm *pcm[AZX_MAX_PCMS]; 411 struct snd_pcm *pcm[HDA_MAX_PCMS];
402 412
403 /* HD codec */ 413 /* HD codec */
404 unsigned short codec_mask; 414 unsigned short codec_mask;
405 int codec_probe_mask; /* copied from probe_mask option */ 415 int codec_probe_mask; /* copied from probe_mask option */
406 struct hda_bus *bus; 416 struct hda_bus *bus;
417 unsigned int beep_mode;
407 418
408 /* CORB/RIRB */ 419 /* CORB/RIRB */
409 struct azx_rb corb; 420 struct azx_rb corb;
@@ -415,6 +426,7 @@ struct azx {
415 426
416 /* flags */ 427 /* flags */
417 int position_fix; 428 int position_fix;
429 int poll_count;
418 unsigned int running :1; 430 unsigned int running :1;
419 unsigned int initialized :1; 431 unsigned int initialized :1;
420 unsigned int single_cmd :1; 432 unsigned int single_cmd :1;
@@ -437,6 +449,7 @@ struct azx {
437/* driver types */ 449/* driver types */
438enum { 450enum {
439 AZX_DRIVER_ICH, 451 AZX_DRIVER_ICH,
452 AZX_DRIVER_PCH,
440 AZX_DRIVER_SCH, 453 AZX_DRIVER_SCH,
441 AZX_DRIVER_ATI, 454 AZX_DRIVER_ATI,
442 AZX_DRIVER_ATIHDMI, 455 AZX_DRIVER_ATIHDMI,
@@ -451,6 +464,7 @@ enum {
451 464
452static char *driver_short_names[] __devinitdata = { 465static char *driver_short_names[] __devinitdata = {
453 [AZX_DRIVER_ICH] = "HDA Intel", 466 [AZX_DRIVER_ICH] = "HDA Intel",
467 [AZX_DRIVER_PCH] = "HDA Intel PCH",
454 [AZX_DRIVER_SCH] = "HDA Intel MID", 468 [AZX_DRIVER_SCH] = "HDA Intel MID",
455 [AZX_DRIVER_ATI] = "HDA ATI SB", 469 [AZX_DRIVER_ATI] = "HDA ATI SB",
456 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI", 470 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
@@ -495,7 +509,7 @@ static char *driver_short_names[] __devinitdata = {
495#define get_azx_dev(substream) (substream->runtime->private_data) 509#define get_azx_dev(substream) (substream->runtime->private_data)
496 510
497static int azx_acquire_irq(struct azx *chip, int do_disconnect); 511static int azx_acquire_irq(struct azx *chip, int do_disconnect);
498 512static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
499/* 513/*
500 * Interface for HD codec 514 * Interface for HD codec
501 */ 515 */
@@ -653,11 +667,12 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
653{ 667{
654 struct azx *chip = bus->private_data; 668 struct azx *chip = bus->private_data;
655 unsigned long timeout; 669 unsigned long timeout;
670 int do_poll = 0;
656 671
657 again: 672 again:
658 timeout = jiffies + msecs_to_jiffies(1000); 673 timeout = jiffies + msecs_to_jiffies(1000);
659 for (;;) { 674 for (;;) {
660 if (chip->polling_mode) { 675 if (chip->polling_mode || do_poll) {
661 spin_lock_irq(&chip->reg_lock); 676 spin_lock_irq(&chip->reg_lock);
662 azx_update_rirb(chip); 677 azx_update_rirb(chip);
663 spin_unlock_irq(&chip->reg_lock); 678 spin_unlock_irq(&chip->reg_lock);
@@ -665,6 +680,9 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
665 if (!chip->rirb.cmds[addr]) { 680 if (!chip->rirb.cmds[addr]) {
666 smp_rmb(); 681 smp_rmb();
667 bus->rirb_error = 0; 682 bus->rirb_error = 0;
683
684 if (!do_poll)
685 chip->poll_count = 0;
668 return chip->rirb.res[addr]; /* the last value */ 686 return chip->rirb.res[addr]; /* the last value */
669 } 687 }
670 if (time_after(jiffies, timeout)) 688 if (time_after(jiffies, timeout))
@@ -677,6 +695,24 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
677 } 695 }
678 } 696 }
679 697
698 if (!chip->polling_mode && chip->poll_count < 2) {
699 snd_printdd(SFX "azx_get_response timeout, "
700 "polling the codec once: last cmd=0x%08x\n",
701 chip->last_cmd[addr]);
702 do_poll = 1;
703 chip->poll_count++;
704 goto again;
705 }
706
707
708 if (!chip->polling_mode) {
709 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
710 "switching to polling mode: last cmd=0x%08x\n",
711 chip->last_cmd[addr]);
712 chip->polling_mode = 1;
713 goto again;
714 }
715
680 if (chip->msi) { 716 if (chip->msi) {
681 snd_printk(KERN_WARNING SFX "No response from codec, " 717 snd_printk(KERN_WARNING SFX "No response from codec, "
682 "disabling MSI: last cmd=0x%08x\n", 718 "disabling MSI: last cmd=0x%08x\n",
@@ -692,14 +728,6 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
692 goto again; 728 goto again;
693 } 729 }
694 730
695 if (!chip->polling_mode) {
696 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
697 "switching to polling mode: last cmd=0x%08x\n",
698 chip->last_cmd[addr]);
699 chip->polling_mode = 1;
700 goto again;
701 }
702
703 if (chip->probing) { 731 if (chip->probing) {
704 /* If this critical timeout happens during the codec probing 732 /* If this critical timeout happens during the codec probing
705 * phase, this is likely an access to a non-existing codec 733 * phase, this is likely an access to a non-existing codec
@@ -942,8 +970,8 @@ static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
942 azx_dev->insufficient = 1; 970 azx_dev->insufficient = 1;
943 971
944 /* enable SIE */ 972 /* enable SIE */
945 azx_writeb(chip, INTCTL, 973 azx_writel(chip, INTCTL,
946 azx_readb(chip, INTCTL) | (1 << azx_dev->index)); 974 azx_readl(chip, INTCTL) | (1 << azx_dev->index));
947 /* set DMA start and interrupt mask */ 975 /* set DMA start and interrupt mask */
948 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) | 976 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
949 SD_CTL_DMA_START | SD_INT_MASK); 977 SD_CTL_DMA_START | SD_INT_MASK);
@@ -962,8 +990,8 @@ static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
962{ 990{
963 azx_stream_clear(chip, azx_dev); 991 azx_stream_clear(chip, azx_dev);
964 /* disable SIE */ 992 /* disable SIE */
965 azx_writeb(chip, INTCTL, 993 azx_writel(chip, INTCTL,
966 azx_readb(chip, INTCTL) & ~(1 << azx_dev->index)); 994 azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
967} 995}
968 996
969 997
@@ -1039,6 +1067,7 @@ static void azx_init_pci(struct azx *chip)
1039 0x01, NVIDIA_HDA_ENABLE_COHBIT); 1067 0x01, NVIDIA_HDA_ENABLE_COHBIT);
1040 break; 1068 break;
1041 case AZX_DRIVER_SCH: 1069 case AZX_DRIVER_SCH:
1070 case AZX_DRIVER_PCH:
1042 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); 1071 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
1043 if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) { 1072 if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
1044 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, 1073 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,
@@ -1324,7 +1353,7 @@ static void azx_bus_reset(struct hda_bus *bus)
1324 if (chip->initialized) { 1353 if (chip->initialized) {
1325 int i; 1354 int i;
1326 1355
1327 for (i = 0; i < AZX_MAX_PCMS; i++) 1356 for (i = 0; i < HDA_MAX_PCMS; i++)
1328 snd_pcm_suspend_all(chip->pcm[i]); 1357 snd_pcm_suspend_all(chip->pcm[i]);
1329 snd_hda_suspend(chip->bus); 1358 snd_hda_suspend(chip->bus);
1330 snd_hda_resume(chip->bus); 1359 snd_hda_resume(chip->bus);
@@ -1339,6 +1368,7 @@ static void azx_bus_reset(struct hda_bus *bus)
1339 1368
1340/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ 1369/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
1341static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = { 1370static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1371 [AZX_DRIVER_NVIDIA] = 8,
1342 [AZX_DRIVER_TERA] = 1, 1372 [AZX_DRIVER_TERA] = 1,
1343}; 1373};
1344 1374
@@ -1371,7 +1401,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model)
1371 codecs = 0; 1401 codecs = 0;
1372 max_slots = azx_max_codecs[chip->driver_type]; 1402 max_slots = azx_max_codecs[chip->driver_type];
1373 if (!max_slots) 1403 if (!max_slots)
1374 max_slots = AZX_MAX_CODECS; 1404 max_slots = AZX_DEFAULT_CODECS;
1375 1405
1376 /* First try to probe all given codec slots */ 1406 /* First try to probe all given codec slots */
1377 for (c = 0; c < max_slots; c++) { 1407 for (c = 0; c < max_slots; c++) {
@@ -1386,7 +1416,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model)
1386 chip->codec_mask &= ~(1 << c); 1416 chip->codec_mask &= ~(1 << c);
1387 /* More badly, accessing to a non-existing 1417 /* More badly, accessing to a non-existing
1388 * codec often screws up the controller chip, 1418 * codec often screws up the controller chip,
1389 * and distrubs the further communications. 1419 * and disturbs the further communications.
1390 * Thus if an error occurs during probing, 1420 * Thus if an error occurs during probing,
1391 * better to reset the controller chip to 1421 * better to reset the controller chip to
1392 * get back to the sanity state. 1422 * get back to the sanity state.
@@ -1404,6 +1434,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model)
1404 err = snd_hda_codec_new(chip->bus, c, &codec); 1434 err = snd_hda_codec_new(chip->bus, c, &codec);
1405 if (err < 0) 1435 if (err < 0)
1406 continue; 1436 continue;
1437 codec->beep_mode = chip->beep_mode;
1407 codecs++; 1438 codecs++;
1408 } 1439 }
1409 } 1440 }
@@ -1430,10 +1461,13 @@ static int __devinit azx_codec_configure(struct azx *chip)
1430 */ 1461 */
1431 1462
1432/* assign a stream for the PCM */ 1463/* assign a stream for the PCM */
1433static inline struct azx_dev *azx_assign_device(struct azx *chip, int stream) 1464static inline struct azx_dev *
1465azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
1434{ 1466{
1435 int dev, i, nums; 1467 int dev, i, nums;
1436 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 1468 struct azx_dev *res = NULL;
1469
1470 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1437 dev = chip->playback_index_offset; 1471 dev = chip->playback_index_offset;
1438 nums = chip->playback_streams; 1472 nums = chip->playback_streams;
1439 } else { 1473 } else {
@@ -1442,10 +1476,15 @@ static inline struct azx_dev *azx_assign_device(struct azx *chip, int stream)
1442 } 1476 }
1443 for (i = 0; i < nums; i++, dev++) 1477 for (i = 0; i < nums; i++, dev++)
1444 if (!chip->azx_dev[dev].opened) { 1478 if (!chip->azx_dev[dev].opened) {
1445 chip->azx_dev[dev].opened = 1; 1479 res = &chip->azx_dev[dev];
1446 return &chip->azx_dev[dev]; 1480 if (res->device == substream->pcm->device)
1481 break;
1447 } 1482 }
1448 return NULL; 1483 if (res) {
1484 res->opened = 1;
1485 res->device = substream->pcm->device;
1486 }
1487 return res;
1449} 1488}
1450 1489
1451/* release the assigned stream */ 1490/* release the assigned stream */
@@ -1494,7 +1533,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1494 int err; 1533 int err;
1495 1534
1496 mutex_lock(&chip->open_mutex); 1535 mutex_lock(&chip->open_mutex);
1497 azx_dev = azx_assign_device(chip, substream->stream); 1536 azx_dev = azx_assign_device(chip, substream);
1498 if (azx_dev == NULL) { 1537 if (azx_dev == NULL) {
1499 mutex_unlock(&chip->open_mutex); 1538 mutex_unlock(&chip->open_mutex);
1500 return -EBUSY; 1539 return -EBUSY;
@@ -1858,6 +1897,9 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
1858 1897
1859 if (!bdl_pos_adj[chip->dev_index]) 1898 if (!bdl_pos_adj[chip->dev_index])
1860 return 1; /* no delayed ack */ 1899 return 1; /* no delayed ack */
1900 if (WARN_ONCE(!azx_dev->period_bytes,
1901 "hda-intel: zero azx_dev->period_bytes"))
1902 return 0; /* this shouldn't happen! */
1861 if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) 1903 if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
1862 return 0; /* NG - it's below the period boundary */ 1904 return 0; /* NG - it's below the period boundary */
1863 return 1; /* OK, it's fine */ 1905 return 1; /* OK, it's fine */
@@ -1945,7 +1987,7 @@ azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
1945 int pcm_dev = cpcm->device; 1987 int pcm_dev = cpcm->device;
1946 int s, err; 1988 int s, err;
1947 1989
1948 if (pcm_dev >= AZX_MAX_PCMS) { 1990 if (pcm_dev >= HDA_MAX_PCMS) {
1949 snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n", 1991 snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
1950 pcm_dev); 1992 pcm_dev);
1951 return -EINVAL; 1993 return -EINVAL;
@@ -2023,7 +2065,7 @@ static int azx_acquire_irq(struct azx *chip, int do_disconnect)
2023{ 2065{
2024 if (request_irq(chip->pci->irq, azx_interrupt, 2066 if (request_irq(chip->pci->irq, azx_interrupt,
2025 chip->msi ? 0 : IRQF_SHARED, 2067 chip->msi ? 0 : IRQF_SHARED,
2026 "HDA Intel", chip)) { 2068 "hda_intel", chip)) {
2027 printk(KERN_ERR "hda-intel: unable to grab IRQ %d, " 2069 printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
2028 "disabling device\n", chip->pci->irq); 2070 "disabling device\n", chip->pci->irq);
2029 if (do_disconnect) 2071 if (do_disconnect)
@@ -2071,7 +2113,8 @@ static void azx_power_notify(struct hda_bus *bus)
2071 } 2113 }
2072 if (power_on) 2114 if (power_on)
2073 azx_init_chip(chip); 2115 azx_init_chip(chip);
2074 else if (chip->running && power_save_controller) 2116 else if (chip->running && power_save_controller &&
2117 !bus->power_keep_link_on)
2075 azx_stop_chip(chip); 2118 azx_stop_chip(chip);
2076} 2119}
2077#endif /* CONFIG_SND_HDA_POWER_SAVE */ 2120#endif /* CONFIG_SND_HDA_POWER_SAVE */
@@ -2100,7 +2143,7 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
2100 2143
2101 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2144 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2102 azx_clear_irq_pending(chip); 2145 azx_clear_irq_pending(chip);
2103 for (i = 0; i < AZX_MAX_PCMS; i++) 2146 for (i = 0; i < HDA_MAX_PCMS; i++)
2104 snd_pcm_suspend_all(chip->pcm[i]); 2147 snd_pcm_suspend_all(chip->pcm[i]);
2105 if (chip->initialized) 2148 if (chip->initialized)
2106 snd_hda_suspend(chip->bus); 2149 snd_hda_suspend(chip->bus);
@@ -2154,6 +2197,7 @@ static int azx_resume(struct pci_dev *pci)
2154static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) 2197static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
2155{ 2198{
2156 struct azx *chip = container_of(nb, struct azx, reboot_notifier); 2199 struct azx *chip = container_of(nb, struct azx, reboot_notifier);
2200 snd_hda_bus_reboot_notify(chip->bus);
2157 azx_stop_chip(chip); 2201 azx_stop_chip(chip);
2158 return NOTIFY_OK; 2202 return NOTIFY_OK;
2159} 2203}
@@ -2221,7 +2265,16 @@ static int azx_dev_free(struct snd_device *device)
2221static struct snd_pci_quirk position_fix_list[] __devinitdata = { 2265static struct snd_pci_quirk position_fix_list[] __devinitdata = {
2222 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), 2266 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
2223 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), 2267 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
2268 SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
2269 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
2270 SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),
2224 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), 2271 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
2272 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
2273 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
2274 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),
2275 SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
2276 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
2277 SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),
2225 {} 2278 {}
2226}; 2279};
2227 2280
@@ -2304,11 +2357,14 @@ static void __devinit check_probe_mask(struct azx *chip, int dev)
2304} 2357}
2305 2358
2306/* 2359/*
2307 * white-list for enable_msi 2360 * white/black-list for enable_msi
2308 */ 2361 */
2309static struct snd_pci_quirk msi_white_list[] __devinitdata = { 2362static struct snd_pci_quirk msi_black_list[] __devinitdata = {
2310 SND_PCI_QUIRK(0x103c, 0x30f7, "HP Pavilion dv4t-1300", 1), 2363 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
2311 SND_PCI_QUIRK(0x103c, 0x3607, "HP Compa CQ40", 1), 2364 SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
2365 SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
2366 SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
2367 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
2312 {} 2368 {}
2313}; 2369};
2314 2370
@@ -2316,15 +2372,24 @@ static void __devinit check_msi(struct azx *chip)
2316{ 2372{
2317 const struct snd_pci_quirk *q; 2373 const struct snd_pci_quirk *q;
2318 2374
2319 chip->msi = enable_msi; 2375 if (enable_msi >= 0) {
2320 if (chip->msi) 2376 chip->msi = !!enable_msi;
2321 return; 2377 return;
2322 q = snd_pci_quirk_lookup(chip->pci, msi_white_list); 2378 }
2379 chip->msi = 1; /* enable MSI as default */
2380 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
2323 if (q) { 2381 if (q) {
2324 printk(KERN_INFO 2382 printk(KERN_INFO
2325 "hda_intel: msi for device %04x:%04x set to %d\n", 2383 "hda_intel: msi for device %04x:%04x set to %d\n",
2326 q->subvendor, q->subdevice, q->value); 2384 q->subvendor, q->subdevice, q->value);
2327 chip->msi = q->value; 2385 chip->msi = q->value;
2386 return;
2387 }
2388
2389 /* NVidia chipsets seem to cause troubles with MSI */
2390 if (chip->driver_type == AZX_DRIVER_NVIDIA) {
2391 printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");
2392 chip->msi = 0;
2328 } 2393 }
2329} 2394}
2330 2395
@@ -2374,6 +2439,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2374 if (bdl_pos_adj[dev] < 0) { 2439 if (bdl_pos_adj[dev] < 0) {
2375 switch (chip->driver_type) { 2440 switch (chip->driver_type) {
2376 case AZX_DRIVER_ICH: 2441 case AZX_DRIVER_ICH:
2442 case AZX_DRIVER_PCH:
2377 bdl_pos_adj[dev] = 1; 2443 bdl_pos_adj[dev] = 1;
2378 break; 2444 break;
2379 default: 2445 default:
@@ -2436,6 +2502,11 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2436 } 2502 }
2437 } 2503 }
2438 2504
2505 /* disable 64bit DMA address for Teradici */
2506 /* it does not work with device 6549:1200 subsys e4a2:040b */
2507 if (chip->driver_type == AZX_DRIVER_TERA)
2508 gcap &= ~ICH6_GCAP_64OK;
2509
2439 /* allow 64bit DMA address if supported by H/W */ 2510 /* allow 64bit DMA address if supported by H/W */
2440 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 2511 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
2441 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); 2512 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
@@ -2578,6 +2649,10 @@ static int __devinit azx_probe(struct pci_dev *pci,
2578 goto out_free; 2649 goto out_free;
2579 card->private_data = chip; 2650 card->private_data = chip;
2580 2651
2652#ifdef CONFIG_SND_HDA_INPUT_BEEP
2653 chip->beep_mode = beep_mode[dev];
2654#endif
2655
2581 /* create codec instances */ 2656 /* create codec instances */
2582 err = azx_codec_create(chip, model[dev]); 2657 err = azx_codec_create(chip, model[dev]);
2583 if (err < 0) 2658 if (err < 0)
@@ -2630,7 +2705,7 @@ static void __devexit azx_remove(struct pci_dev *pci)
2630} 2705}
2631 2706
2632/* PCI IDs */ 2707/* PCI IDs */
2633static struct pci_device_id azx_ids[] = { 2708static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
2634 /* ICH 6..10 */ 2709 /* ICH 6..10 */
2635 { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH }, 2710 { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH },
2636 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH }, 2711 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
@@ -2643,6 +2718,9 @@ static struct pci_device_id azx_ids[] = {
2643 { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH }, 2718 { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH },
2644 /* PCH */ 2719 /* PCH */
2645 { PCI_DEVICE(0x8086, 0x3b56), .driver_data = AZX_DRIVER_ICH }, 2720 { PCI_DEVICE(0x8086, 0x3b56), .driver_data = AZX_DRIVER_ICH },
2721 { PCI_DEVICE(0x8086, 0x3b57), .driver_data = AZX_DRIVER_ICH },
2722 /* CPT */
2723 { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH },
2646 /* SCH */ 2724 /* SCH */
2647 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH }, 2725 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
2648 /* ATI SB 450/600 */ 2726 /* ATI SB 450/600 */
@@ -2670,29 +2748,10 @@ static struct pci_device_id azx_ids[] = {
2670 /* ULI M5461 */ 2748 /* ULI M5461 */
2671 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI }, 2749 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2672 /* NVIDIA MCP */ 2750 /* NVIDIA MCP */
2673 { PCI_DEVICE(0x10de, 0x026c), .driver_data = AZX_DRIVER_NVIDIA }, 2751 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
2674 { PCI_DEVICE(0x10de, 0x0371), .driver_data = AZX_DRIVER_NVIDIA }, 2752 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2675 { PCI_DEVICE(0x10de, 0x03e4), .driver_data = AZX_DRIVER_NVIDIA }, 2753 .class_mask = 0xffffff,
2676 { PCI_DEVICE(0x10de, 0x03f0), .driver_data = AZX_DRIVER_NVIDIA }, 2754 .driver_data = AZX_DRIVER_NVIDIA },
2677 { PCI_DEVICE(0x10de, 0x044a), .driver_data = AZX_DRIVER_NVIDIA },
2678 { PCI_DEVICE(0x10de, 0x044b), .driver_data = AZX_DRIVER_NVIDIA },
2679 { PCI_DEVICE(0x10de, 0x055c), .driver_data = AZX_DRIVER_NVIDIA },
2680 { PCI_DEVICE(0x10de, 0x055d), .driver_data = AZX_DRIVER_NVIDIA },
2681 { PCI_DEVICE(0x10de, 0x0590), .driver_data = AZX_DRIVER_NVIDIA },
2682 { PCI_DEVICE(0x10de, 0x0774), .driver_data = AZX_DRIVER_NVIDIA },
2683 { PCI_DEVICE(0x10de, 0x0775), .driver_data = AZX_DRIVER_NVIDIA },
2684 { PCI_DEVICE(0x10de, 0x0776), .driver_data = AZX_DRIVER_NVIDIA },
2685 { PCI_DEVICE(0x10de, 0x0777), .driver_data = AZX_DRIVER_NVIDIA },
2686 { PCI_DEVICE(0x10de, 0x07fc), .driver_data = AZX_DRIVER_NVIDIA },
2687 { PCI_DEVICE(0x10de, 0x07fd), .driver_data = AZX_DRIVER_NVIDIA },
2688 { PCI_DEVICE(0x10de, 0x0ac0), .driver_data = AZX_DRIVER_NVIDIA },
2689 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
2690 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
2691 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
2692 { PCI_DEVICE(0x10de, 0x0d94), .driver_data = AZX_DRIVER_NVIDIA },
2693 { PCI_DEVICE(0x10de, 0x0d95), .driver_data = AZX_DRIVER_NVIDIA },
2694 { PCI_DEVICE(0x10de, 0x0d96), .driver_data = AZX_DRIVER_NVIDIA },
2695 { PCI_DEVICE(0x10de, 0x0d97), .driver_data = AZX_DRIVER_NVIDIA },
2696 /* Teradici */ 2755 /* Teradici */
2697 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, 2756 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
2698 /* Creative X-Fi (CA0110-IBG) */ 2757 /* Creative X-Fi (CA0110-IBG) */
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 5f1dcc59002b..7cee364976ff 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -23,6 +23,16 @@
23#ifndef __SOUND_HDA_LOCAL_H 23#ifndef __SOUND_HDA_LOCAL_H
24#define __SOUND_HDA_LOCAL_H 24#define __SOUND_HDA_LOCAL_H
25 25
26/* We abuse kcontrol_new.subdev field to pass the NID corresponding to
27 * the given new control. If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
28 * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
29 *
30 * Note that the subdevice field is cleared again before the real registration
31 * in snd_hda_ctl_add(), so that this value won't appear in the outside.
32 */
33#define HDA_SUBDEV_NID_FLAG (1U << 31)
34#define HDA_SUBDEV_AMP_FLAG (1U << 30)
35
26/* 36/*
27 * for mixer controls 37 * for mixer controls
28 */ 38 */
@@ -33,6 +43,7 @@
33/* mono volume with index (index=0,1,...) (channel=1,2) */ 43/* mono volume with index (index=0,1,...) (channel=1,2) */
34#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 44#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
35 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 45 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
46 .subdevice = HDA_SUBDEV_AMP_FLAG, \
36 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 47 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
37 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 48 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
38 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ 49 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
@@ -53,6 +64,7 @@
53/* mono mute switch with index (index=0,1,...) (channel=1,2) */ 64/* mono mute switch with index (index=0,1,...) (channel=1,2) */
54#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 65#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
55 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 66 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
67 .subdevice = HDA_SUBDEV_AMP_FLAG, \
56 .info = snd_hda_mixer_amp_switch_info, \ 68 .info = snd_hda_mixer_amp_switch_info, \
57 .get = snd_hda_mixer_amp_switch_get, \ 69 .get = snd_hda_mixer_amp_switch_get, \
58 .put = snd_hda_mixer_amp_switch_put, \ 70 .put = snd_hda_mixer_amp_switch_put, \
@@ -66,6 +78,28 @@
66/* stereo mute switch */ 78/* stereo mute switch */
67#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \ 79#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
68 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction) 80 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
81#ifdef CONFIG_SND_HDA_INPUT_BEEP
82/* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
83#define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
84 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
85 .subdevice = HDA_SUBDEV_AMP_FLAG, \
86 .info = snd_hda_mixer_amp_switch_info, \
87 .get = snd_hda_mixer_amp_switch_get, \
88 .put = snd_hda_mixer_amp_switch_put_beep, \
89 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
90#else
91/* no digital beep - just the standard one */
92#define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
93 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
94#endif /* CONFIG_SND_HDA_INPUT_BEEP */
95/* special beep mono mute switch */
96#define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
97 HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
98/* special beep stereo mute switch */
99#define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
100 HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
101
102extern const char *snd_hda_pcm_type_name[];
69 103
70int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 104int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
71 struct snd_ctl_elem_info *uinfo); 105 struct snd_ctl_elem_info *uinfo);
@@ -81,6 +115,10 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
81 struct snd_ctl_elem_value *ucontrol); 115 struct snd_ctl_elem_value *ucontrol);
82int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 116int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_value *ucontrol); 117 struct snd_ctl_elem_value *ucontrol);
118#ifdef CONFIG_SND_HDA_INPUT_BEEP
119int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
120 struct snd_ctl_elem_value *ucontrol);
121#endif
84/* lowlevel accessor with caching; use carefully */ 122/* lowlevel accessor with caching; use carefully */
85int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 123int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
86 int direction, int index); 124 int direction, int index);
@@ -424,8 +462,23 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
424int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 462int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
425 unsigned int caps); 463 unsigned int caps);
426u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); 464u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
465u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
466int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
427 467
428int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl); 468/* flags for hda_nid_item */
469#define HDA_NID_ITEM_AMP (1<<0)
470
471struct hda_nid_item {
472 struct snd_kcontrol *kctl;
473 unsigned int index;
474 hda_nid_t nid;
475 unsigned short flags;
476};
477
478int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
479 struct snd_kcontrol *kctl);
480int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
481 unsigned int index, hda_nid_t nid);
429void snd_hda_ctls_clear(struct hda_codec *codec); 482void snd_hda_ctls_clear(struct hda_codec *codec);
430 483
431/* 484/*
@@ -437,6 +490,15 @@ int snd_hda_create_hwdep(struct hda_codec *codec);
437static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; } 490static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
438#endif 491#endif
439 492
493#if defined(CONFIG_SND_HDA_POWER_SAVE) && defined(CONFIG_SND_HDA_HWDEP)
494int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
495#else
496static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
497{
498 return 0;
499}
500#endif
501
440#ifdef CONFIG_SND_HDA_RECONFIG 502#ifdef CONFIG_SND_HDA_RECONFIG
441int snd_hda_hwdep_add_sysfs(struct hda_codec *codec); 503int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
442#else 504#else
@@ -490,7 +552,8 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
490 * AMP control callbacks 552 * AMP control callbacks
491 */ 553 */
492/* retrieve parameters from private_value */ 554/* retrieve parameters from private_value */
493#define get_amp_nid(kc) ((kc)->private_value & 0xffff) 555#define get_amp_nid_(pv) ((pv) & 0xffff)
556#define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
494#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3) 557#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
495#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1) 558#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
496#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 559#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
@@ -516,9 +579,11 @@ struct cea_sad {
516 * ELD: EDID Like Data 579 * ELD: EDID Like Data
517 */ 580 */
518struct hdmi_eld { 581struct hdmi_eld {
582 bool monitor_present;
583 bool eld_valid;
519 int eld_size; 584 int eld_size;
520 int baseline_len; 585 int baseline_len;
521 int eld_ver; /* (eld_ver == 0) indicates invalid ELD */ 586 int eld_ver;
522 int cea_edid_ver; 587 int cea_edid_ver;
523 char monitor_name[ELD_MAX_MNL + 1]; 588 char monitor_name[ELD_MAX_MNL + 1];
524 int manufacture_id; 589 int manufacture_id;
@@ -541,11 +606,13 @@ int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
541void snd_hdmi_show_eld(struct hdmi_eld *eld); 606void snd_hdmi_show_eld(struct hdmi_eld *eld);
542 607
543#ifdef CONFIG_PROC_FS 608#ifdef CONFIG_PROC_FS
544int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld); 609int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
610 int index);
545void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld); 611void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
546#else 612#else
547static inline int snd_hda_eld_proc_new(struct hda_codec *codec, 613static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
548 struct hdmi_eld *eld) 614 struct hdmi_eld *eld,
615 int index)
549{ 616{
550 return 0; 617 return 0;
551} 618}
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 95f24e4729f8..f97d35de66c4 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -26,6 +26,21 @@
26#include "hda_codec.h" 26#include "hda_codec.h"
27#include "hda_local.h" 27#include "hda_local.h"
28 28
29static char *bits_names(unsigned int bits, char *names[], int size)
30{
31 int i, n;
32 static char buf[128];
33
34 for (i = 0, n = 0; i < size; i++) {
35 if (bits & (1U<<i) && names[i])
36 n += snprintf(buf + n, sizeof(buf) - n, " %s",
37 names[i]);
38 }
39 buf[n] = '\0';
40
41 return buf;
42}
43
29static const char *get_wid_type_name(unsigned int wid_value) 44static const char *get_wid_type_name(unsigned int wid_value)
30{ 45{
31 static char *names[16] = { 46 static char *names[16] = {
@@ -46,6 +61,52 @@ static const char *get_wid_type_name(unsigned int wid_value)
46 return "UNKNOWN Widget"; 61 return "UNKNOWN Widget";
47} 62}
48 63
64static void print_nid_array(struct snd_info_buffer *buffer,
65 struct hda_codec *codec, hda_nid_t nid,
66 struct snd_array *array)
67{
68 int i;
69 struct hda_nid_item *items = array->list, *item;
70 struct snd_kcontrol *kctl;
71 for (i = 0; i < array->used; i++) {
72 item = &items[i];
73 if (item->nid == nid) {
74 kctl = item->kctl;
75 snd_iprintf(buffer,
76 " Control: name=\"%s\", index=%i, device=%i\n",
77 kctl->id.name, kctl->id.index + item->index,
78 kctl->id.device);
79 if (item->flags & HDA_NID_ITEM_AMP)
80 snd_iprintf(buffer,
81 " ControlAmp: chs=%lu, dir=%s, "
82 "idx=%lu, ofs=%lu\n",
83 get_amp_channels(kctl),
84 get_amp_direction(kctl) ? "Out" : "In",
85 get_amp_index(kctl),
86 get_amp_offset(kctl));
87 }
88 }
89}
90
91static void print_nid_pcms(struct snd_info_buffer *buffer,
92 struct hda_codec *codec, hda_nid_t nid)
93{
94 int pcm, type;
95 struct hda_pcm *cpcm;
96 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
97 cpcm = &codec->pcm_info[pcm];
98 for (type = 0; type < 2; type++) {
99 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
100 continue;
101 snd_iprintf(buffer, " Device: name=\"%s\", "
102 "type=\"%s\", device=%i\n",
103 cpcm->name,
104 snd_hda_pcm_type_name[cpcm->pcm_type],
105 cpcm->pcm->device);
106 }
107 }
108}
109
49static void print_amp_caps(struct snd_info_buffer *buffer, 110static void print_amp_caps(struct snd_info_buffer *buffer,
50 struct hda_codec *codec, hda_nid_t nid, int dir) 111 struct hda_codec *codec, hda_nid_t nid, int dir)
51{ 112{
@@ -190,9 +251,14 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
190 /* Realtek uses this bit as a different meaning */ 251 /* Realtek uses this bit as a different meaning */
191 if ((codec->vendor_id >> 16) == 0x10ec) 252 if ((codec->vendor_id >> 16) == 0x10ec)
192 snd_iprintf(buffer, " R/L"); 253 snd_iprintf(buffer, " R/L");
193 else 254 else {
255 if (caps & AC_PINCAP_HBR)
256 snd_iprintf(buffer, " HBR");
194 snd_iprintf(buffer, " HDMI"); 257 snd_iprintf(buffer, " HDMI");
258 }
195 } 259 }
260 if (caps & AC_PINCAP_DP)
261 snd_iprintf(buffer, " DP");
196 if (caps & AC_PINCAP_TRIG_REQ) 262 if (caps & AC_PINCAP_TRIG_REQ)
197 snd_iprintf(buffer, " Trigger"); 263 snd_iprintf(buffer, " Trigger");
198 if (caps & AC_PINCAP_IMP_SENSE) 264 if (caps & AC_PINCAP_IMP_SENSE)
@@ -363,8 +429,24 @@ static const char *get_pwr_state(u32 state)
363static void print_power_state(struct snd_info_buffer *buffer, 429static void print_power_state(struct snd_info_buffer *buffer,
364 struct hda_codec *codec, hda_nid_t nid) 430 struct hda_codec *codec, hda_nid_t nid)
365{ 431{
432 static char *names[] = {
433 [ilog2(AC_PWRST_D0SUP)] = "D0",
434 [ilog2(AC_PWRST_D1SUP)] = "D1",
435 [ilog2(AC_PWRST_D2SUP)] = "D2",
436 [ilog2(AC_PWRST_D3SUP)] = "D3",
437 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
438 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
439 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
440 [ilog2(AC_PWRST_EPSS)] = "EPSS",
441 };
442
443 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
366 int pwr = snd_hda_codec_read(codec, nid, 0, 444 int pwr = snd_hda_codec_read(codec, nid, 0,
367 AC_VERB_GET_POWER_STATE, 0); 445 AC_VERB_GET_POWER_STATE, 0);
446 if (sup)
447 snd_iprintf(buffer, " Power states: %s\n",
448 bits_names(sup, names, ARRAY_SIZE(names)));
449
368 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n", 450 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n",
369 get_pwr_state(pwr & AC_PWRST_SETTING), 451 get_pwr_state(pwr & AC_PWRST_SETTING),
370 get_pwr_state((pwr & AC_PWRST_ACTUAL) >> 452 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
@@ -457,6 +539,8 @@ static void print_gpio(struct snd_info_buffer *buffer,
457 (data & (1<<i)) ? 1 : 0, 539 (data & (1<<i)) ? 1 : 0,
458 (unsol & (1<<i)) ? 1 : 0); 540 (unsol & (1<<i)) ? 1 : 0);
459 /* FIXME: add GPO and GPI pin information */ 541 /* FIXME: add GPO and GPI pin information */
542 print_nid_array(buffer, codec, nid, &codec->mixers);
543 print_nid_array(buffer, codec, nid, &codec->nids);
460} 544}
461 545
462static void print_codec_info(struct snd_info_entry *entry, 546static void print_codec_info(struct snd_info_entry *entry,
@@ -536,6 +620,10 @@ static void print_codec_info(struct snd_info_entry *entry,
536 snd_iprintf(buffer, " CP"); 620 snd_iprintf(buffer, " CP");
537 snd_iprintf(buffer, "\n"); 621 snd_iprintf(buffer, "\n");
538 622
623 print_nid_array(buffer, codec, nid, &codec->mixers);
624 print_nid_array(buffer, codec, nid, &codec->nids);
625 print_nid_pcms(buffer, codec, nid);
626
539 /* volume knob is a special widget that always have connection 627 /* volume knob is a special widget that always have connection
540 * list 628 * list
541 */ 629 */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 2d603f6aba63..e9fdfc4b1c57 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -72,7 +72,8 @@ struct ad198x_spec {
72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
73 73
74 unsigned int jack_present :1; 74 unsigned int jack_present :1;
75 unsigned int inv_jack_detect:1; 75 unsigned int inv_jack_detect:1; /* inverted jack-detection */
76 unsigned int inv_eapd:1; /* inverted EAPD implementation */
76 77
77#ifdef CONFIG_SND_HDA_POWER_SAVE 78#ifdef CONFIG_SND_HDA_POWER_SAVE
78 struct hda_loopback_check loopback; 79 struct hda_loopback_check loopback;
@@ -156,19 +157,24 @@ static const char *ad_slave_sws[] = {
156 157
157static void ad198x_free_kctls(struct hda_codec *codec); 158static void ad198x_free_kctls(struct hda_codec *codec);
158 159
160#ifdef CONFIG_SND_HDA_INPUT_BEEP
159/* additional beep mixers; the actual parameters are overwritten at build */ 161/* additional beep mixers; the actual parameters are overwritten at build */
160static struct snd_kcontrol_new ad_beep_mixer[] = { 162static struct snd_kcontrol_new ad_beep_mixer[] = {
161 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT), 163 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
162 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_OUTPUT), 164 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
163 { } /* end */ 165 { } /* end */
164}; 166};
165 167
166#define set_beep_amp(spec, nid, idx, dir) \ 168#define set_beep_amp(spec, nid, idx, dir) \
167 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */ 169 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
170#else
171#define set_beep_amp(spec, nid, idx, dir) /* NOP */
172#endif
168 173
169static int ad198x_build_controls(struct hda_codec *codec) 174static int ad198x_build_controls(struct hda_codec *codec)
170{ 175{
171 struct ad198x_spec *spec = codec->spec; 176 struct ad198x_spec *spec = codec->spec;
177 struct snd_kcontrol *kctl;
172 unsigned int i; 178 unsigned int i;
173 int err; 179 int err;
174 180
@@ -194,6 +200,7 @@ static int ad198x_build_controls(struct hda_codec *codec)
194 } 200 }
195 201
196 /* create beep controls if needed */ 202 /* create beep controls if needed */
203#ifdef CONFIG_SND_HDA_INPUT_BEEP
197 if (spec->beep_amp) { 204 if (spec->beep_amp) {
198 struct snd_kcontrol_new *knew; 205 struct snd_kcontrol_new *knew;
199 for (knew = ad_beep_mixer; knew->name; knew++) { 206 for (knew = ad_beep_mixer; knew->name; knew++) {
@@ -202,11 +209,12 @@ static int ad198x_build_controls(struct hda_codec *codec)
202 if (!kctl) 209 if (!kctl)
203 return -ENOMEM; 210 return -ENOMEM;
204 kctl->private_value = spec->beep_amp; 211 kctl->private_value = spec->beep_amp;
205 err = snd_hda_ctl_add(codec, kctl); 212 err = snd_hda_ctl_add(codec, 0, kctl);
206 if (err < 0) 213 if (err < 0)
207 return err; 214 return err;
208 } 215 }
209 } 216 }
217#endif
210 218
211 /* if we have no master control, let's create it */ 219 /* if we have no master control, let's create it */
212 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 220 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
@@ -230,6 +238,27 @@ static int ad198x_build_controls(struct hda_codec *codec)
230 } 238 }
231 239
232 ad198x_free_kctls(codec); /* no longer needed */ 240 ad198x_free_kctls(codec); /* no longer needed */
241
242 /* assign Capture Source enums to NID */
243 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
244 if (!kctl)
245 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
246 for (i = 0; kctl && i < kctl->count; i++) {
247 err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
248 if (err < 0)
249 return err;
250 }
251
252 /* assign IEC958 enums to NID */
253 kctl = snd_hda_find_mixer_ctl(codec,
254 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
255 if (kctl) {
256 err = snd_hda_add_nid(codec, kctl, 0,
257 spec->multiout.dig_out_nid);
258 if (err < 0)
259 return err;
260 }
261
233 return 0; 262 return 0;
234} 263}
235 264
@@ -412,6 +441,11 @@ static int ad198x_build_pcms(struct hda_codec *codec)
412 return 0; 441 return 0;
413} 442}
414 443
444static inline void ad198x_shutup(struct hda_codec *codec)
445{
446 snd_hda_shutup_pins(codec);
447}
448
415static void ad198x_free_kctls(struct hda_codec *codec) 449static void ad198x_free_kctls(struct hda_codec *codec)
416{ 450{
417 struct ad198x_spec *spec = codec->spec; 451 struct ad198x_spec *spec = codec->spec;
@@ -425,6 +459,46 @@ static void ad198x_free_kctls(struct hda_codec *codec)
425 snd_array_free(&spec->kctls); 459 snd_array_free(&spec->kctls);
426} 460}
427 461
462static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
463 hda_nid_t hp)
464{
465 struct ad198x_spec *spec = codec->spec;
466 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
467 !spec->inv_eapd ? 0x00 : 0x02);
468 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
469 !spec->inv_eapd ? 0x00 : 0x02);
470}
471
472static void ad198x_power_eapd(struct hda_codec *codec)
473{
474 /* We currently only handle front, HP */
475 switch (codec->vendor_id) {
476 case 0x11d41882:
477 case 0x11d4882a:
478 case 0x11d41884:
479 case 0x11d41984:
480 case 0x11d41883:
481 case 0x11d4184a:
482 case 0x11d4194a:
483 case 0x11d4194b:
484 ad198x_power_eapd_write(codec, 0x12, 0x11);
485 break;
486 case 0x11d41981:
487 case 0x11d41983:
488 ad198x_power_eapd_write(codec, 0x05, 0x06);
489 break;
490 case 0x11d41986:
491 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
492 break;
493 case 0x11d41988:
494 case 0x11d4198b:
495 case 0x11d4989a:
496 case 0x11d4989b:
497 ad198x_power_eapd_write(codec, 0x29, 0x22);
498 break;
499 }
500}
501
428static void ad198x_free(struct hda_codec *codec) 502static void ad198x_free(struct hda_codec *codec)
429{ 503{
430 struct ad198x_spec *spec = codec->spec; 504 struct ad198x_spec *spec = codec->spec;
@@ -432,11 +506,21 @@ static void ad198x_free(struct hda_codec *codec)
432 if (!spec) 506 if (!spec)
433 return; 507 return;
434 508
509 ad198x_shutup(codec);
435 ad198x_free_kctls(codec); 510 ad198x_free_kctls(codec);
436 kfree(spec); 511 kfree(spec);
437 snd_hda_detach_beep_device(codec); 512 snd_hda_detach_beep_device(codec);
438} 513}
439 514
515#ifdef SND_HDA_NEEDS_RESUME
516static int ad198x_suspend(struct hda_codec *codec, pm_message_t state)
517{
518 ad198x_shutup(codec);
519 ad198x_power_eapd(codec);
520 return 0;
521}
522#endif
523
440static struct hda_codec_ops ad198x_patch_ops = { 524static struct hda_codec_ops ad198x_patch_ops = {
441 .build_controls = ad198x_build_controls, 525 .build_controls = ad198x_build_controls,
442 .build_pcms = ad198x_build_pcms, 526 .build_pcms = ad198x_build_pcms,
@@ -445,12 +529,16 @@ static struct hda_codec_ops ad198x_patch_ops = {
445#ifdef CONFIG_SND_HDA_POWER_SAVE 529#ifdef CONFIG_SND_HDA_POWER_SAVE
446 .check_power_status = ad198x_check_power_status, 530 .check_power_status = ad198x_check_power_status,
447#endif 531#endif
532#ifdef SND_HDA_NEEDS_RESUME
533 .suspend = ad198x_suspend,
534#endif
535 .reboot_notify = ad198x_shutup,
448}; 536};
449 537
450 538
451/* 539/*
452 * EAPD control 540 * EAPD control
453 * the private value = nid | (invert << 8) 541 * the private value = nid
454 */ 542 */
455#define ad198x_eapd_info snd_ctl_boolean_mono_info 543#define ad198x_eapd_info snd_ctl_boolean_mono_info
456 544
@@ -459,8 +547,7 @@ static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
459{ 547{
460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 548 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
461 struct ad198x_spec *spec = codec->spec; 549 struct ad198x_spec *spec = codec->spec;
462 int invert = (kcontrol->private_value >> 8) & 1; 550 if (spec->inv_eapd)
463 if (invert)
464 ucontrol->value.integer.value[0] = ! spec->cur_eapd; 551 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
465 else 552 else
466 ucontrol->value.integer.value[0] = spec->cur_eapd; 553 ucontrol->value.integer.value[0] = spec->cur_eapd;
@@ -472,11 +559,10 @@ static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
472{ 559{
473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474 struct ad198x_spec *spec = codec->spec; 561 struct ad198x_spec *spec = codec->spec;
475 int invert = (kcontrol->private_value >> 8) & 1;
476 hda_nid_t nid = kcontrol->private_value & 0xff; 562 hda_nid_t nid = kcontrol->private_value & 0xff;
477 unsigned int eapd; 563 unsigned int eapd;
478 eapd = !!ucontrol->value.integer.value[0]; 564 eapd = !!ucontrol->value.integer.value[0];
479 if (invert) 565 if (spec->inv_eapd)
480 eapd = !eapd; 566 eapd = !eapd;
481 if (eapd == spec->cur_eapd) 567 if (eapd == spec->cur_eapd)
482 return 0; 568 return 0;
@@ -694,10 +780,11 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
694 { 780 {
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "External Amplifier", 782 .name = "External Amplifier",
783 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
697 .info = ad198x_eapd_info, 784 .info = ad198x_eapd_info,
698 .get = ad198x_eapd_get, 785 .get = ad198x_eapd_get,
699 .put = ad198x_eapd_put, 786 .put = ad198x_eapd_put,
700 .private_value = 0x1b | (1 << 8), /* port-D, inversed */ 787 .private_value = 0x1b, /* port-D */
701 }, 788 },
702 { } /* end */ 789 { } /* end */
703}; 790};
@@ -712,10 +799,10 @@ static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
712static void ad1986a_automic(struct hda_codec *codec) 799static void ad1986a_automic(struct hda_codec *codec)
713{ 800{
714 unsigned int present; 801 unsigned int present;
715 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0); 802 present = snd_hda_jack_detect(codec, 0x1f);
716 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */ 803 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
717 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL, 804 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
718 (present & AC_PINSENSE_PRESENCE) ? 0 : 2); 805 present ? 0 : 2);
719} 806}
720 807
721#define AD1986A_MIC_EVENT 0x36 808#define AD1986A_MIC_EVENT 0x36
@@ -754,10 +841,8 @@ static void ad1986a_update_hp(struct hda_codec *codec)
754static void ad1986a_hp_automute(struct hda_codec *codec) 841static void ad1986a_hp_automute(struct hda_codec *codec)
755{ 842{
756 struct ad198x_spec *spec = codec->spec; 843 struct ad198x_spec *spec = codec->spec;
757 unsigned int present;
758 844
759 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0); 845 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
760 spec->jack_present = !!(present & 0x80000000);
761 if (spec->inv_jack_detect) 846 if (spec->inv_jack_detect)
762 spec->jack_present = !spec->jack_present; 847 spec->jack_present = !spec->jack_present;
763 ad1986a_update_hp(codec); 848 ad1986a_update_hp(codec);
@@ -803,6 +888,7 @@ static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
803 { 888 {
804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 889 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805 .name = "Master Playback Switch", 890 .name = "Master Playback Switch",
891 .subdevice = HDA_SUBDEV_AMP_FLAG,
806 .info = snd_hda_mixer_amp_switch_info, 892 .info = snd_hda_mixer_amp_switch_info,
807 .get = snd_hda_mixer_amp_switch_get, 893 .get = snd_hda_mixer_amp_switch_get,
808 .put = ad1986a_hp_master_sw_put, 894 .put = ad1986a_hp_master_sw_put,
@@ -1003,7 +1089,7 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1003 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK), 1089 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1004 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK), 1090 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
1005 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK), 1091 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
1006 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD), 1092 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
1007 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK), 1093 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1008 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP), 1094 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1009 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50), 1095 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
@@ -1068,6 +1154,7 @@ static int patch_ad1986a(struct hda_codec *codec)
1068 spec->loopback.amplist = ad1986a_loopbacks; 1154 spec->loopback.amplist = ad1986a_loopbacks;
1069#endif 1155#endif
1070 spec->vmaster_nid = 0x1b; 1156 spec->vmaster_nid = 0x1b;
1157 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
1071 1158
1072 codec->patch_ops = ad198x_patch_ops; 1159 codec->patch_ops = ad198x_patch_ops;
1073 1160
@@ -1180,6 +1267,8 @@ static int patch_ad1986a(struct hda_codec *codec)
1180 */ 1267 */
1181 spec->multiout.no_share_stream = 1; 1268 spec->multiout.no_share_stream = 1;
1182 1269
1270 codec->no_trigger_sense = 1;
1271
1183 return 0; 1272 return 0;
1184} 1273}
1185 1274
@@ -1365,6 +1454,8 @@ static int patch_ad1983(struct hda_codec *codec)
1365 1454
1366 codec->patch_ops = ad198x_patch_ops; 1455 codec->patch_ops = ad198x_patch_ops;
1367 1456
1457 codec->no_trigger_sense = 1;
1458
1368 return 0; 1459 return 0;
1369} 1460}
1370 1461
@@ -1547,8 +1638,7 @@ static void ad1981_hp_automute(struct hda_codec *codec)
1547{ 1638{
1548 unsigned int present; 1639 unsigned int present;
1549 1640
1550 present = snd_hda_codec_read(codec, 0x06, 0, 1641 present = snd_hda_jack_detect(codec, 0x06);
1551 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1552 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0, 1642 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1553 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 1643 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1554} 1644}
@@ -1568,8 +1658,7 @@ static void ad1981_hp_automic(struct hda_codec *codec)
1568 }; 1658 };
1569 unsigned int present; 1659 unsigned int present;
1570 1660
1571 present = snd_hda_codec_read(codec, 0x08, 0, 1661 present = snd_hda_jack_detect(codec, 0x08);
1572 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1573 if (present) 1662 if (present)
1574 snd_hda_sequence_write(codec, mic_jack_on); 1663 snd_hda_sequence_write(codec, mic_jack_on);
1575 else 1664 else
@@ -1604,6 +1693,7 @@ static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1604 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol), 1693 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1605 { 1694 {
1606 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1696 .subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
1607 .name = "Master Playback Switch", 1697 .name = "Master Playback Switch",
1608 .info = ad198x_eapd_info, 1698 .info = ad198x_eapd_info,
1609 .get = ad198x_eapd_get, 1699 .get = ad198x_eapd_get,
@@ -1785,10 +1875,26 @@ static int patch_ad1981(struct hda_codec *codec)
1785 1875
1786 codec->patch_ops.init = ad1981_hp_init; 1876 codec->patch_ops.init = ad1981_hp_init;
1787 codec->patch_ops.unsol_event = ad1981_hp_unsol_event; 1877 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1878 /* set the upper-limit for mixer amp to 0dB for avoiding the
1879 * possible damage by overloading
1880 */
1881 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1882 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1883 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1884 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1885 (1 << AC_AMPCAP_MUTE_SHIFT));
1788 break; 1886 break;
1789 case AD1981_THINKPAD: 1887 case AD1981_THINKPAD:
1790 spec->mixers[0] = ad1981_thinkpad_mixers; 1888 spec->mixers[0] = ad1981_thinkpad_mixers;
1791 spec->input_mux = &ad1981_thinkpad_capture_source; 1889 spec->input_mux = &ad1981_thinkpad_capture_source;
1890 /* set the upper-limit for mixer amp to 0dB for avoiding the
1891 * possible damage by overloading
1892 */
1893 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1894 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1895 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1896 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1897 (1 << AC_AMPCAP_MUTE_SHIFT));
1792 break; 1898 break;
1793 case AD1981_TOSHIBA: 1899 case AD1981_TOSHIBA:
1794 spec->mixers[0] = ad1981_hp_mixers; 1900 spec->mixers[0] = ad1981_hp_mixers;
@@ -1801,6 +1907,9 @@ static int patch_ad1981(struct hda_codec *codec)
1801 codec->patch_ops.unsol_event = ad1981_hp_unsol_event; 1907 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1802 break; 1908 break;
1803 } 1909 }
1910
1911 codec->no_trigger_sense = 1;
1912
1804 return 0; 1913 return 0;
1805} 1914}
1806 1915
@@ -2117,10 +2226,11 @@ static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2117 { 2226 {
2118 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2227 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2119 .name = "External Amplifier", 2228 .name = "External Amplifier",
2229 .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
2120 .info = ad198x_eapd_info, 2230 .info = ad198x_eapd_info,
2121 .get = ad198x_eapd_get, 2231 .get = ad198x_eapd_get,
2122 .put = ad198x_eapd_put, 2232 .put = ad198x_eapd_put,
2123 .private_value = 0x12 | (1 << 8), /* port-D, inversed */ 2233 .private_value = 0x12, /* port-D */
2124 }, 2234 },
2125 2235
2126 { } /* end */ 2236 { } /* end */
@@ -2238,6 +2348,7 @@ static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2238 { 2348 {
2239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2240 .name = "IEC958 Playback Source", 2350 .name = "IEC958 Playback Source",
2351 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
2241 .info = ad1988_spdif_playback_source_info, 2352 .info = ad1988_spdif_playback_source_info,
2242 .get = ad1988_spdif_playback_source_get, 2353 .get = ad1988_spdif_playback_source_get,
2243 .put = ad1988_spdif_playback_source_put, 2354 .put = ad1988_spdif_playback_source_put,
@@ -2353,6 +2464,12 @@ static struct hda_verb ad1988_spdif_init_verbs[] = {
2353 { } 2464 { }
2354}; 2465};
2355 2466
2467static struct hda_verb ad1988_spdif_in_init_verbs[] = {
2468 /* unmute SPDIF input pin */
2469 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2470 { }
2471};
2472
2356/* AD1989 has no ADC -> SPDIF route */ 2473/* AD1989 has no ADC -> SPDIF route */
2357static struct hda_verb ad1989_spdif_init_verbs[] = { 2474static struct hda_verb ad1989_spdif_init_verbs[] = {
2358 /* SPDIF-1 out pin */ 2475 /* SPDIF-1 out pin */
@@ -2524,7 +2641,7 @@ static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2524{ 2641{
2525 if ((res >> 26) != AD1988_HP_EVENT) 2642 if ((res >> 26) != AD1988_HP_EVENT)
2526 return; 2643 return;
2527 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31)) 2644 if (snd_hda_jack_detect(codec, 0x11))
2528 snd_hda_sequence_write(codec, ad1988_laptop_hp_on); 2645 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2529 else 2646 else
2530 snd_hda_sequence_write(codec, ad1988_laptop_hp_off); 2647 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
@@ -2569,6 +2686,8 @@ static int add_control(struct ad198x_spec *spec, int type, const char *name,
2569 knew->name = kstrdup(name, GFP_KERNEL); 2686 knew->name = kstrdup(name, GFP_KERNEL);
2570 if (! knew->name) 2687 if (! knew->name)
2571 return -ENOMEM; 2688 return -ENOMEM;
2689 if (get_amp_nid_(val))
2690 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
2572 knew->private_value = val; 2691 knew->private_value = val;
2573 return 0; 2692 return 0;
2574} 2693}
@@ -3059,6 +3178,7 @@ static int patch_ad1988(struct hda_codec *codec)
3059 spec->input_mux = &ad1988_laptop_capture_source; 3178 spec->input_mux = &ad1988_laptop_capture_source;
3060 spec->num_mixers = 1; 3179 spec->num_mixers = 1;
3061 spec->mixers[0] = ad1988_laptop_mixers; 3180 spec->mixers[0] = ad1988_laptop_mixers;
3181 spec->inv_eapd = 1; /* inverted EAPD */
3062 spec->num_init_verbs = 1; 3182 spec->num_init_verbs = 1;
3063 spec->init_verbs[0] = ad1988_laptop_init_verbs; 3183 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3064 if (board_config == AD1988_LAPTOP_DIG) 3184 if (board_config == AD1988_LAPTOP_DIG)
@@ -3085,8 +3205,11 @@ static int patch_ad1988(struct hda_codec *codec)
3085 ad1988_spdif_init_verbs; 3205 ad1988_spdif_init_verbs;
3086 } 3206 }
3087 } 3207 }
3088 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) 3208 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
3089 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers; 3209 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3210 spec->init_verbs[spec->num_init_verbs++] =
3211 ad1988_spdif_in_init_verbs;
3212 }
3090 3213
3091 codec->patch_ops = ad198x_patch_ops; 3214 codec->patch_ops = ad198x_patch_ops;
3092 switch (board_config) { 3215 switch (board_config) {
@@ -3103,6 +3226,8 @@ static int patch_ad1988(struct hda_codec *codec)
3103#endif 3226#endif
3104 spec->vmaster_nid = 0x04; 3227 spec->vmaster_nid = 0x04;
3105 3228
3229 codec->no_trigger_sense = 1;
3230
3106 return 0; 3231 return 0;
3107} 3232}
3108 3233
@@ -3315,6 +3440,8 @@ static int patch_ad1884(struct hda_codec *codec)
3315 3440
3316 codec->patch_ops = ad198x_patch_ops; 3441 codec->patch_ops = ad198x_patch_ops;
3317 3442
3443 codec->no_trigger_sense = 1;
3444
3318 return 0; 3445 return 0;
3319} 3446}
3320 3447
@@ -3721,6 +3848,7 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3721 { 3848 {
3722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3723 .name = "Master Playback Switch", 3850 .name = "Master Playback Switch",
3851 .subdevice = HDA_SUBDEV_AMP_FLAG,
3724 .info = snd_hda_mixer_amp_switch_info, 3852 .info = snd_hda_mixer_amp_switch_info,
3725 .get = snd_hda_mixer_amp_switch_get, 3853 .get = snd_hda_mixer_amp_switch_get,
3726 .put = ad1884a_mobile_master_sw_put, 3854 .put = ad1884a_mobile_master_sw_put,
@@ -3749,6 +3877,7 @@ static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3749 { 3877 {
3750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3751 .name = "Master Playback Switch", 3879 .name = "Master Playback Switch",
3880 .subdevice = HDA_SUBDEV_AMP_FLAG,
3752 .info = snd_hda_mixer_amp_switch_info, 3881 .info = snd_hda_mixer_amp_switch_info,
3753 .get = snd_hda_mixer_amp_switch_get, 3882 .get = snd_hda_mixer_amp_switch_get,
3754 .put = ad1884a_mobile_master_sw_put, 3883 .put = ad1884a_mobile_master_sw_put,
@@ -3768,8 +3897,7 @@ static void ad1884a_hp_automute(struct hda_codec *codec)
3768{ 3897{
3769 unsigned int present; 3898 unsigned int present;
3770 3899
3771 present = snd_hda_codec_read(codec, 0x11, 0, 3900 present = snd_hda_jack_detect(codec, 0x11);
3772 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3773 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 3901 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3774 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 3902 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3775 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE, 3903 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
@@ -3781,8 +3909,7 @@ static void ad1884a_hp_automic(struct hda_codec *codec)
3781{ 3909{
3782 unsigned int present; 3910 unsigned int present;
3783 3911
3784 present = snd_hda_codec_read(codec, 0x14, 0, 3912 present = snd_hda_jack_detect(codec, 0x14);
3785 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3786 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, 3913 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3787 present ? 0 : 1); 3914 present ? 0 : 1);
3788} 3915}
@@ -3817,13 +3944,9 @@ static void ad1884a_laptop_automute(struct hda_codec *codec)
3817{ 3944{
3818 unsigned int present; 3945 unsigned int present;
3819 3946
3820 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0); 3947 present = snd_hda_jack_detect(codec, 0x11);
3821 present &= AC_PINSENSE_PRESENCE; 3948 if (!present)
3822 if (!present) { 3949 present = snd_hda_jack_detect(codec, 0x12);
3823 present = snd_hda_codec_read(codec, 0x12, 0,
3824 AC_VERB_GET_PIN_SENSE, 0);
3825 present &= AC_PINSENSE_PRESENCE;
3826 }
3827 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 3950 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3828 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 3951 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3829 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE, 3952 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
@@ -3835,11 +3958,9 @@ static void ad1884a_laptop_automic(struct hda_codec *codec)
3835{ 3958{
3836 unsigned int idx; 3959 unsigned int idx;
3837 3960
3838 if (snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0) & 3961 if (snd_hda_jack_detect(codec, 0x14))
3839 AC_PINSENSE_PRESENCE)
3840 idx = 0; 3962 idx = 0;
3841 else if (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 3963 else if (snd_hda_jack_detect(codec, 0x1c))
3842 AC_PINSENSE_PRESENCE)
3843 idx = 4; 3964 idx = 4;
3844 else 3965 else
3845 idx = 1; 3966 idx = 1;
@@ -4008,8 +4129,7 @@ static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4008{ 4129{
4009 unsigned int present; 4130 unsigned int present;
4010 4131
4011 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) 4132 present = snd_hda_jack_detect(codec, 0x11);
4012 & AC_PINSENSE_PRESENCE;
4013 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0, 4133 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4014 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 4134 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4015} 4135}
@@ -4099,6 +4219,7 @@ static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4099/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/ 4219/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4100 { 4220 {
4101 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4222 .subdevice = HDA_SUBDEV_AMP_FLAG,
4102 .name = "Master Playback Switch", 4223 .name = "Master Playback Switch",
4103 .info = snd_hda_mixer_amp_switch_info, 4224 .info = snd_hda_mixer_amp_switch_info,
4104 .get = snd_hda_mixer_amp_switch_get, 4225 .get = snd_hda_mixer_amp_switch_get,
@@ -4117,14 +4238,12 @@ static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4117/* switch to external mic if plugged */ 4238/* switch to external mic if plugged */
4118static void ad1984a_touchsmart_automic(struct hda_codec *codec) 4239static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4119{ 4240{
4120 if (snd_hda_codec_read(codec, 0x1c, 0, 4241 if (snd_hda_jack_detect(codec, 0x1c))
4121 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000) {
4122 snd_hda_codec_write(codec, 0x0c, 0, 4242 snd_hda_codec_write(codec, 0x0c, 0,
4123 AC_VERB_SET_CONNECT_SEL, 0x4); 4243 AC_VERB_SET_CONNECT_SEL, 0x4);
4124 } else { 4244 else
4125 snd_hda_codec_write(codec, 0x0c, 0, 4245 snd_hda_codec_write(codec, 0x0c, 0,
4126 AC_VERB_SET_CONNECT_SEL, 0x5); 4246 AC_VERB_SET_CONNECT_SEL, 0x5);
4127 }
4128} 4247}
4129 4248
4130 4249
@@ -4283,6 +4402,8 @@ static int patch_ad1884a(struct hda_codec *codec)
4283 break; 4402 break;
4284 } 4403 }
4285 4404
4405 codec->no_trigger_sense = 1;
4406
4286 return 0; 4407 return 0;
4287} 4408}
4288 4409
@@ -4619,6 +4740,9 @@ static int patch_ad1882(struct hda_codec *codec)
4619 spec->mixers[2] = ad1882_6stack_mixers; 4740 spec->mixers[2] = ad1882_6stack_mixers;
4620 break; 4741 break;
4621 } 4742 }
4743
4744 codec->no_trigger_sense = 1;
4745
4622 return 0; 4746 return 0;
4623} 4747}
4624 4748
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index d08353d3bb7f..af478019088e 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -144,7 +144,7 @@ static int _add_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
144 struct snd_kcontrol_new knew = 144 struct snd_kcontrol_new knew =
145 HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type); 145 HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type);
146 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]); 146 sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]);
147 return snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 147 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
148} 148}
149 149
150static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx, 150static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
@@ -155,7 +155,7 @@ static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx,
155 struct snd_kcontrol_new knew = 155 struct snd_kcontrol_new knew =
156 HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type); 156 HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type);
157 sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]); 157 sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]);
158 return snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 158 return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec));
159} 159}
160 160
161#define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0) 161#define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0)
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 8ba306856d38..350ee8ac4153 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -66,6 +66,7 @@ struct cs_spec {
66/* available models */ 66/* available models */
67enum { 67enum {
68 CS420X_MBP55, 68 CS420X_MBP55,
69 CS420X_IMAC27,
69 CS420X_AUTO, 70 CS420X_AUTO,
70 CS420X_MODELS 71 CS420X_MODELS
71}; 72};
@@ -500,7 +501,8 @@ static int add_mute(struct hda_codec *codec, const char *name, int index,
500 knew.private_value = pval; 501 knew.private_value = pval;
501 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]); 502 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
502 *kctlp = snd_ctl_new1(&knew, codec); 503 *kctlp = snd_ctl_new1(&knew, codec);
503 return snd_hda_ctl_add(codec, *kctlp); 504 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
505 return snd_hda_ctl_add(codec, 0, *kctlp);
504} 506}
505 507
506static int add_volume(struct hda_codec *codec, const char *name, 508static int add_volume(struct hda_codec *codec, const char *name,
@@ -513,7 +515,8 @@ static int add_volume(struct hda_codec *codec, const char *name,
513 knew.private_value = pval; 515 knew.private_value = pval;
514 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]); 516 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
515 *kctlp = snd_ctl_new1(&knew, codec); 517 *kctlp = snd_ctl_new1(&knew, codec);
516 return snd_hda_ctl_add(codec, *kctlp); 518 (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
519 return snd_hda_ctl_add(codec, 0, *kctlp);
517} 520}
518 521
519static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) 522static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
@@ -536,14 +539,14 @@ static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
536 539
537 spec->vmaster_sw = 540 spec->vmaster_sw =
538 snd_ctl_make_virtual_master("Master Playback Switch", NULL); 541 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
539 err = snd_hda_ctl_add(codec, spec->vmaster_sw); 542 err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
540 if (err < 0) 543 if (err < 0)
541 return err; 544 return err;
542 545
543 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv); 546 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
544 spec->vmaster_vol = 547 spec->vmaster_vol =
545 snd_ctl_make_virtual_master("Master Playback Volume", tlv); 548 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
546 err = snd_hda_ctl_add(codec, spec->vmaster_vol); 549 err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
547 if (err < 0) 550 if (err < 0)
548 return err; 551 return err;
549 return 0; 552 return 0;
@@ -750,19 +753,27 @@ static int build_input(struct hda_codec *codec)
750 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol); 753 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
751 for (i = 0; i < 2; i++) { 754 for (i = 0; i < 2; i++) {
752 struct snd_kcontrol *kctl; 755 struct snd_kcontrol *kctl;
756 int n;
753 if (!spec->capture_bind[i]) 757 if (!spec->capture_bind[i])
754 return -ENOMEM; 758 return -ENOMEM;
755 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec); 759 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
756 if (!kctl) 760 if (!kctl)
757 return -ENOMEM; 761 return -ENOMEM;
758 kctl->private_value = (long)spec->capture_bind[i]; 762 kctl->private_value = (long)spec->capture_bind[i];
759 err = snd_hda_ctl_add(codec, kctl); 763 err = snd_hda_ctl_add(codec, 0, kctl);
760 if (err < 0) 764 if (err < 0)
761 return err; 765 return err;
766 for (n = 0; n < AUTO_PIN_LAST; n++) {
767 if (!spec->adc_nid[n])
768 continue;
769 err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
770 if (err < 0)
771 return err;
772 }
762 } 773 }
763 774
764 if (spec->num_inputs > 1 && !spec->mic_detect) { 775 if (spec->num_inputs > 1 && !spec->mic_detect) {
765 err = snd_hda_ctl_add(codec, 776 err = snd_hda_ctl_add(codec, 0,
766 snd_ctl_new1(&cs_capture_source, codec)); 777 snd_ctl_new1(&cs_capture_source, codec));
767 if (err < 0) 778 if (err < 0)
768 return err; 779 return err;
@@ -807,7 +818,7 @@ static void cs_automute(struct hda_codec *codec)
807{ 818{
808 struct cs_spec *spec = codec->spec; 819 struct cs_spec *spec = codec->spec;
809 struct auto_pin_cfg *cfg = &spec->autocfg; 820 struct auto_pin_cfg *cfg = &spec->autocfg;
810 unsigned int caps, present, hp_present; 821 unsigned int caps, hp_present;
811 hda_nid_t nid; 822 hda_nid_t nid;
812 int i; 823 int i;
813 824
@@ -817,12 +828,7 @@ static void cs_automute(struct hda_codec *codec)
817 caps = snd_hda_query_pin_caps(codec, nid); 828 caps = snd_hda_query_pin_caps(codec, nid);
818 if (!(caps & AC_PINCAP_PRES_DETECT)) 829 if (!(caps & AC_PINCAP_PRES_DETECT))
819 continue; 830 continue;
820 if (caps & AC_PINCAP_TRIG_REQ) 831 hp_present = snd_hda_jack_detect(codec, nid);
821 snd_hda_codec_read(codec, nid, 0,
822 AC_VERB_SET_PIN_SENSE, 0);
823 present = snd_hda_codec_read(codec, nid, 0,
824 AC_VERB_GET_PIN_SENSE, 0);
825 hp_present |= (present & AC_PINSENSE_PRESENCE) != 0;
826 if (hp_present) 832 if (hp_present)
827 break; 833 break;
828 } 834 }
@@ -832,7 +838,8 @@ static void cs_automute(struct hda_codec *codec)
832 AC_VERB_SET_PIN_WIDGET_CONTROL, 838 AC_VERB_SET_PIN_WIDGET_CONTROL,
833 hp_present ? 0 : PIN_OUT); 839 hp_present ? 0 : PIN_OUT);
834 } 840 }
835 if (spec->board_config == CS420X_MBP55) { 841 if (spec->board_config == CS420X_MBP55 ||
842 spec->board_config == CS420X_IMAC27) {
836 unsigned int gpio = hp_present ? 0x02 : 0x08; 843 unsigned int gpio = hp_present ? 0x02 : 0x08;
837 snd_hda_codec_write(codec, 0x01, 0, 844 snd_hda_codec_write(codec, 0x01, 0,
838 AC_VERB_SET_GPIO_DATA, gpio); 845 AC_VERB_SET_GPIO_DATA, gpio);
@@ -844,15 +851,11 @@ static void cs_automic(struct hda_codec *codec)
844 struct cs_spec *spec = codec->spec; 851 struct cs_spec *spec = codec->spec;
845 struct auto_pin_cfg *cfg = &spec->autocfg; 852 struct auto_pin_cfg *cfg = &spec->autocfg;
846 hda_nid_t nid; 853 hda_nid_t nid;
847 unsigned int caps, present; 854 unsigned int present;
848 855
849 nid = cfg->input_pins[spec->automic_idx]; 856 nid = cfg->input_pins[spec->automic_idx];
850 caps = snd_hda_query_pin_caps(codec, nid); 857 present = snd_hda_jack_detect(codec, nid);
851 if (caps & AC_PINCAP_TRIG_REQ) 858 if (present)
852 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
853 present = snd_hda_codec_read(codec, nid, 0,
854 AC_VERB_GET_PIN_SENSE, 0);
855 if (present & AC_PINSENSE_PRESENCE)
856 change_cur_input(codec, spec->automic_idx, 0); 859 change_cur_input(codec, spec->automic_idx, 0);
857 else { 860 else {
858 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ? 861 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
@@ -947,7 +950,7 @@ static void init_input(struct hda_codec *codec)
947 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */ 950 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */
948 if (is_active_pin(codec, CS_DMIC1_PIN_NID)) 951 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
949 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0 952 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0
950 * No effect if SPDIF_OUT2 is slected in 953 * No effect if SPDIF_OUT2 is selected in
951 * IDX_SPDIF_CTL. 954 * IDX_SPDIF_CTL.
952 */ 955 */
953 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef); 956 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef);
@@ -1078,12 +1081,14 @@ static int cs_parse_auto_config(struct hda_codec *codec)
1078 1081
1079static const char *cs420x_models[CS420X_MODELS] = { 1082static const char *cs420x_models[CS420X_MODELS] = {
1080 [CS420X_MBP55] = "mbp55", 1083 [CS420X_MBP55] = "mbp55",
1084 [CS420X_IMAC27] = "imac27",
1081 [CS420X_AUTO] = "auto", 1085 [CS420X_AUTO] = "auto",
1082}; 1086};
1083 1087
1084 1088
1085static struct snd_pci_quirk cs420x_cfg_tbl[] = { 1089static struct snd_pci_quirk cs420x_cfg_tbl[] = {
1086 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55), 1090 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
1091 SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),
1087 {} /* terminator */ 1092 {} /* terminator */
1088}; 1093};
1089 1094
@@ -1106,8 +1111,23 @@ static struct cs_pincfg mbp55_pincfgs[] = {
1106 {} /* terminator */ 1111 {} /* terminator */
1107}; 1112};
1108 1113
1114static struct cs_pincfg imac27_pincfgs[] = {
1115 { 0x09, 0x012b4050 },
1116 { 0x0a, 0x90100140 },
1117 { 0x0b, 0x90100142 },
1118 { 0x0c, 0x018b3020 },
1119 { 0x0d, 0x90a00110 },
1120 { 0x0e, 0x400000f0 },
1121 { 0x0f, 0x01cbe030 },
1122 { 0x10, 0x014be060 },
1123 { 0x12, 0x01ab9070 },
1124 { 0x15, 0x400000f0 },
1125 {} /* terminator */
1126};
1127
1109static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = { 1128static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = {
1110 [CS420X_MBP55] = mbp55_pincfgs, 1129 [CS420X_MBP55] = mbp55_pincfgs,
1130 [CS420X_IMAC27] = imac27_pincfgs,
1111}; 1131};
1112 1132
1113static void fix_pincfg(struct hda_codec *codec, int model) 1133static void fix_pincfg(struct hda_codec *codec, int model)
@@ -1137,6 +1157,7 @@ static int patch_cs420x(struct hda_codec *codec)
1137 fix_pincfg(codec, spec->board_config); 1157 fix_pincfg(codec, spec->board_config);
1138 1158
1139 switch (spec->board_config) { 1159 switch (spec->board_config) {
1160 case CS420X_IMAC27:
1140 case CS420X_MBP55: 1161 case CS420X_MBP55:
1141 /* GPIO1 = headphones */ 1162 /* GPIO1 = headphones */
1142 /* GPIO3 = speakers */ 1163 /* GPIO3 = speakers */
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 780e1a72114a..ff60908f4554 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -66,7 +66,7 @@ struct cmi_spec {
66 66
67 struct hda_pcm pcm_rec[2]; /* PCM information */ 67 struct hda_pcm pcm_rec[2]; /* PCM information */
68 68
69 /* pin deafault configuration */ 69 /* pin default configuration */
70 hda_nid_t pin_nid[NUM_PINS]; 70 hda_nid_t pin_nid[NUM_PINS];
71 unsigned int def_conf[NUM_PINS]; 71 unsigned int def_conf[NUM_PINS];
72 unsigned int pin_def_confs; 72 unsigned int pin_def_confs;
@@ -197,8 +197,8 @@ static struct snd_kcontrol_new cmi9880_basic_mixer[] = {
197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT), 197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
198 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT), 198 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
199 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT), 199 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
200 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT), 200 HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT),
201 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT), 201 HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT),
202 { } /* end */ 202 { } /* end */
203}; 203};
204 204
@@ -315,7 +315,8 @@ static struct hda_verb cmi9880_allout_init[] = {
315static int cmi9880_build_controls(struct hda_codec *codec) 315static int cmi9880_build_controls(struct hda_codec *codec)
316{ 316{
317 struct cmi_spec *spec = codec->spec; 317 struct cmi_spec *spec = codec->spec;
318 int err; 318 struct snd_kcontrol *kctl;
319 int i, err;
319 320
320 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer); 321 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
321 if (err < 0) 322 if (err < 0)
@@ -340,6 +341,14 @@ static int cmi9880_build_controls(struct hda_codec *codec)
340 if (err < 0) 341 if (err < 0)
341 return err; 342 return err;
342 } 343 }
344
345 /* assign Capture Source enums to NID */
346 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
347 for (i = 0; kctl && i < kctl->count; i++) {
348 err = snd_hda_add_nid(codec, kctl, i, spec->adc_nids[i]);
349 if (err < 0)
350 return err;
351 }
343 return 0; 352 return 0;
344} 353}
345 354
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 905859d4f4df..feabb44c7ca4 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -29,6 +29,7 @@
29 29
30#include "hda_codec.h" 30#include "hda_codec.h"
31#include "hda_local.h" 31#include "hda_local.h"
32#include "hda_beep.h"
32 33
33#define CXT_PIN_DIR_IN 0x00 34#define CXT_PIN_DIR_IN 0x00
34#define CXT_PIN_DIR_OUT 0x01 35#define CXT_PIN_DIR_OUT 0x01
@@ -41,10 +42,12 @@
41 42
42/* Conexant 5051 specific */ 43/* Conexant 5051 specific */
43 44
44#define CXT5051_SPDIF_OUT 0x1C 45#define CXT5051_SPDIF_OUT 0x12
45#define CXT5051_PORTB_EVENT 0x38 46#define CXT5051_PORTB_EVENT 0x38
46#define CXT5051_PORTC_EVENT 0x39 47#define CXT5051_PORTC_EVENT 0x39
47 48
49#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
48 51
49struct conexant_jack { 52struct conexant_jack {
50 53
@@ -73,7 +76,7 @@ struct conexant_spec {
73 */ 76 */
74 unsigned int cur_eapd; 77 unsigned int cur_eapd;
75 unsigned int hp_present; 78 unsigned int hp_present;
76 unsigned int no_auto_mic; 79 unsigned int auto_mic;
77 unsigned int need_dac_fix; 80 unsigned int need_dac_fix;
78 81
79 /* capture */ 82 /* capture */
@@ -110,7 +113,23 @@ struct conexant_spec {
110 113
111 unsigned int dell_automute; 114 unsigned int dell_automute;
112 unsigned int port_d_mode; 115 unsigned int port_d_mode;
113 unsigned char ext_mic_bias; 116 unsigned int dell_vostro:1;
117 unsigned int ideapad:1;
118
119 unsigned int ext_mic_present;
120 unsigned int recording;
121 void (*capture_prepare)(struct hda_codec *codec);
122 void (*capture_cleanup)(struct hda_codec *codec);
123
124 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
125 * through the microphone jack.
126 * When the user enables this through a mixer switch, both internal and
127 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
128 * we also allow the bias to be configured through a separate mixer
129 * control. */
130 unsigned int dc_enable;
131 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
132 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
114}; 133};
115 134
116static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 135static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
@@ -183,6 +202,8 @@ static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
183 struct snd_pcm_substream *substream) 202 struct snd_pcm_substream *substream)
184{ 203{
185 struct conexant_spec *spec = codec->spec; 204 struct conexant_spec *spec = codec->spec;
205 if (spec->capture_prepare)
206 spec->capture_prepare(codec);
186 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 207 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
187 stream_tag, 0, format); 208 stream_tag, 0, format);
188 return 0; 209 return 0;
@@ -194,6 +215,8 @@ static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
194{ 215{
195 struct conexant_spec *spec = codec->spec; 216 struct conexant_spec *spec = codec->spec;
196 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 217 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
218 if (spec->capture_cleanup)
219 spec->capture_cleanup(codec);
197 return 0; 220 return 0;
198} 221}
199 222
@@ -397,9 +420,7 @@ static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
397 for (i = 0; i < spec->jacks.used; i++) { 420 for (i = 0; i < spec->jacks.used; i++) {
398 if (jacks->nid == nid) { 421 if (jacks->nid == nid) {
399 unsigned int present; 422 unsigned int present;
400 present = snd_hda_codec_read(codec, nid, 0, 423 present = snd_hda_jack_detect(codec, nid);
401 AC_VERB_GET_PIN_SENSE, 0) &
402 AC_PINSENSE_PRESENCE;
403 424
404 present = (present) ? jacks->type : 0 ; 425 present = (present) ? jacks->type : 0 ;
405 426
@@ -478,6 +499,7 @@ static void conexant_free(struct hda_codec *codec)
478 snd_array_free(&spec->jacks); 499 snd_array_free(&spec->jacks);
479 } 500 }
480#endif 501#endif
502 snd_hda_detach_beep_device(codec);
481 kfree(codec->spec); 503 kfree(codec->spec);
482} 504}
483 505
@@ -750,8 +772,7 @@ static void cxt5045_hp_automic(struct hda_codec *codec)
750 }; 772 };
751 unsigned int present; 773 unsigned int present;
752 774
753 present = snd_hda_codec_read(codec, 0x12, 0, 775 present = snd_hda_jack_detect(codec, 0x12);
754 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
755 if (present) 776 if (present)
756 snd_hda_sequence_write(codec, mic_jack_on); 777 snd_hda_sequence_write(codec, mic_jack_on);
757 else 778 else
@@ -765,8 +786,7 @@ static void cxt5045_hp_automute(struct hda_codec *codec)
765 struct conexant_spec *spec = codec->spec; 786 struct conexant_spec *spec = codec->spec;
766 unsigned int bits; 787 unsigned int bits;
767 788
768 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, 789 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
769 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
770 790
771 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 791 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
772 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 792 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
@@ -1175,9 +1195,12 @@ static int patch_cxt5045(struct hda_codec *codec)
1175 1195
1176 switch (codec->subsystem_id >> 16) { 1196 switch (codec->subsystem_id >> 16) {
1177 case 0x103c: 1197 case 0x103c:
1178 /* HP laptop has a really bad sound over 0dB on NID 0x17. 1198 case 0x1631:
1179 * Fix max PCM level to 0 dB 1199 case 0x1734:
1180 * (originall it has 0x2b steps with 0dB offset 0x14) 1200 case 0x17aa:
1201 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1202 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1203 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1181 */ 1204 */
1182 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 1205 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1183 (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 1206 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
@@ -1243,8 +1266,7 @@ static void cxt5047_hp_automute(struct hda_codec *codec)
1243 struct conexant_spec *spec = codec->spec; 1266 struct conexant_spec *spec = codec->spec;
1244 unsigned int bits; 1267 unsigned int bits;
1245 1268
1246 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1269 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1247 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1248 1270
1249 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 1271 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1250 /* See the note in cxt5047_hp_master_sw_put */ 1272 /* See the note in cxt5047_hp_master_sw_put */
@@ -1267,8 +1289,7 @@ static void cxt5047_hp_automic(struct hda_codec *codec)
1267 }; 1289 };
1268 unsigned int present; 1290 unsigned int present;
1269 1291
1270 present = snd_hda_codec_read(codec, 0x15, 0, 1292 present = snd_hda_jack_detect(codec, 0x15);
1271 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1272 if (present) 1293 if (present)
1273 snd_hda_sequence_write(codec, mic_jack_on); 1294 snd_hda_sequence_write(codec, mic_jack_on);
1274 else 1295 else
@@ -1415,16 +1436,7 @@ static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1415 .get = conexant_mux_enum_get, 1436 .get = conexant_mux_enum_get,
1416 .put = conexant_mux_enum_put, 1437 .put = conexant_mux_enum_put,
1417 }, 1438 },
1418 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1439 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1420 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1421 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1422 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1423 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1425 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1427 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1428 1440
1429 { } /* end */ 1441 { } /* end */
1430}; 1442};
@@ -1581,6 +1593,21 @@ static int patch_cxt5047(struct hda_codec *codec)
1581#endif 1593#endif
1582 } 1594 }
1583 spec->vmaster_nid = 0x13; 1595 spec->vmaster_nid = 0x13;
1596
1597 switch (codec->subsystem_id >> 16) {
1598 case 0x103c:
1599 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1600 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1601 * with 0 dB offset 0x17)
1602 */
1603 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1604 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1605 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1606 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1607 (1 << AC_AMPCAP_MUTE_SHIFT));
1608 break;
1609 }
1610
1584 return 0; 1611 return 0;
1585} 1612}
1586 1613
@@ -1596,6 +1623,11 @@ static void cxt5051_update_speaker(struct hda_codec *codec)
1596{ 1623{
1597 struct conexant_spec *spec = codec->spec; 1624 struct conexant_spec *spec = codec->spec;
1598 unsigned int pinctl; 1625 unsigned int pinctl;
1626 /* headphone pin */
1627 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1628 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1629 pinctl);
1630 /* speaker pin */
1599 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1631 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1600 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1632 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1601 pinctl); 1633 pinctl);
@@ -1619,11 +1651,9 @@ static void cxt5051_portb_automic(struct hda_codec *codec)
1619 struct conexant_spec *spec = codec->spec; 1651 struct conexant_spec *spec = codec->spec;
1620 unsigned int present; 1652 unsigned int present;
1621 1653
1622 if (spec->no_auto_mic) 1654 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1623 return; 1655 return;
1624 present = snd_hda_codec_read(codec, 0x17, 0, 1656 present = snd_hda_jack_detect(codec, 0x17);
1625 AC_VERB_GET_PIN_SENSE, 0) &
1626 AC_PINSENSE_PRESENCE;
1627 snd_hda_codec_write(codec, 0x14, 0, 1657 snd_hda_codec_write(codec, 0x14, 0,
1628 AC_VERB_SET_CONNECT_SEL, 1658 AC_VERB_SET_CONNECT_SEL,
1629 present ? 0x01 : 0x00); 1659 present ? 0x01 : 0x00);
@@ -1636,11 +1666,9 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1636 unsigned int present; 1666 unsigned int present;
1637 hda_nid_t new_adc; 1667 hda_nid_t new_adc;
1638 1668
1639 if (spec->no_auto_mic) 1669 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1640 return; 1670 return;
1641 present = snd_hda_codec_read(codec, 0x18, 0, 1671 present = snd_hda_jack_detect(codec, 0x18);
1642 AC_VERB_GET_PIN_SENSE, 0) &
1643 AC_PINSENSE_PRESENCE;
1644 if (present) 1672 if (present)
1645 spec->cur_adc_idx = 1; 1673 spec->cur_adc_idx = 1;
1646 else 1674 else
@@ -1661,9 +1689,7 @@ static void cxt5051_hp_automute(struct hda_codec *codec)
1661{ 1689{
1662 struct conexant_spec *spec = codec->spec; 1690 struct conexant_spec *spec = codec->spec;
1663 1691
1664 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, 1692 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1665 AC_VERB_GET_PIN_SENSE, 0) &
1666 AC_PINSENSE_PRESENCE;
1667 cxt5051_update_speaker(codec); 1693 cxt5051_update_speaker(codec);
1668} 1694}
1669 1695
@@ -1686,13 +1712,7 @@ static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1686 conexant_report_jack(codec, nid); 1712 conexant_report_jack(codec, nid);
1687} 1713}
1688 1714
1689static struct snd_kcontrol_new cxt5051_mixers[] = { 1715static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1690 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1691 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1692 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1693 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1694 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1695 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1696 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1716 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1697 { 1717 {
1698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1702,7 +1722,16 @@ static struct snd_kcontrol_new cxt5051_mixers[] = {
1702 .put = cxt5051_hp_master_sw_put, 1722 .put = cxt5051_hp_master_sw_put,
1703 .private_value = 0x1a, 1723 .private_value = 0x1a,
1704 }, 1724 },
1725 {}
1726};
1705 1727
1728static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1729 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1730 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1731 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1732 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1733 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1734 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1706 {} 1735 {}
1707}; 1736};
1708 1737
@@ -1711,32 +1740,26 @@ static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1711 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1740 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1712 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1741 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1713 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1742 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1714 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1715 {
1716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1717 .name = "Master Playback Switch",
1718 .info = cxt_eapd_info,
1719 .get = cxt_eapd_get,
1720 .put = cxt5051_hp_master_sw_put,
1721 .private_value = 0x1a,
1722 },
1723
1724 {} 1743 {}
1725}; 1744};
1726 1745
1727static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 1746static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1728 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT), 1747 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1729 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT), 1748 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1730 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1749 {}
1731 { 1750};
1732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1733 .name = "Master Playback Switch",
1734 .info = cxt_eapd_info,
1735 .get = cxt_eapd_get,
1736 .put = cxt5051_hp_master_sw_put,
1737 .private_value = 0x1a,
1738 },
1739 1751
1752static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1753 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1754 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1755 {}
1756};
1757
1758static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1759 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1760 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1761 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1762 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1740 {} 1763 {}
1741}; 1764};
1742 1765
@@ -1765,8 +1788,6 @@ static struct hda_verb cxt5051_init_verbs[] = {
1765 /* EAPD */ 1788 /* EAPD */
1766 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1789 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1767 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1790 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1768 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1769 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1770 { } /* end */ 1791 { } /* end */
1771}; 1792};
1772 1793
@@ -1792,7 +1813,6 @@ static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1792 /* EAPD */ 1813 /* EAPD */
1793 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1814 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1794 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1815 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1795 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1796 { } /* end */ 1816 { } /* end */
1797}; 1817};
1798 1818
@@ -1824,17 +1844,60 @@ static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1824 /* EAPD */ 1844 /* EAPD */
1825 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1845 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1826 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1846 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1827 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1828 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1829 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1847 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1830 { } /* end */ 1848 { } /* end */
1831}; 1849};
1832 1850
1851static struct hda_verb cxt5051_f700_init_verbs[] = {
1852 /* Line in, Mic */
1853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1854 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1856 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1857 /* SPK */
1858 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1859 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1860 /* HP, Amp */
1861 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1862 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1863 /* DAC1 */
1864 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1865 /* Record selector: Int mic */
1866 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1867 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1868 /* SPDIF route: PCM */
1869 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1870 /* EAPD */
1871 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1872 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1873 { } /* end */
1874};
1875
1876static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1877 unsigned int event)
1878{
1879 snd_hda_codec_write(codec, nid, 0,
1880 AC_VERB_SET_UNSOLICITED_ENABLE,
1881 AC_USRSP_EN | event);
1882#ifdef CONFIG_SND_HDA_INPUT_JACK
1883 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1884 conexant_report_jack(codec, nid);
1885#endif
1886}
1887
1833/* initialize jack-sensing, too */ 1888/* initialize jack-sensing, too */
1834static int cxt5051_init(struct hda_codec *codec) 1889static int cxt5051_init(struct hda_codec *codec)
1835{ 1890{
1891 struct conexant_spec *spec = codec->spec;
1892
1836 conexant_init(codec); 1893 conexant_init(codec);
1837 conexant_init_jacks(codec); 1894 conexant_init_jacks(codec);
1895
1896 if (spec->auto_mic & AUTO_MIC_PORTB)
1897 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1898 if (spec->auto_mic & AUTO_MIC_PORTC)
1899 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1900
1838 if (codec->patch_ops.unsol_event) { 1901 if (codec->patch_ops.unsol_event) {
1839 cxt5051_hp_automute(codec); 1902 cxt5051_hp_automute(codec);
1840 cxt5051_portb_automic(codec); 1903 cxt5051_portb_automic(codec);
@@ -1849,6 +1912,8 @@ enum {
1849 CXT5051_HP, /* no docking */ 1912 CXT5051_HP, /* no docking */
1850 CXT5051_HP_DV6736, /* HP without mic switch */ 1913 CXT5051_HP_DV6736, /* HP without mic switch */
1851 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */ 1914 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1915 CXT5051_F700, /* HP Compaq Presario F700 */
1916 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1852 CXT5051_MODELS 1917 CXT5051_MODELS
1853}; 1918};
1854 1919
@@ -1857,11 +1922,15 @@ static const char *cxt5051_models[CXT5051_MODELS] = {
1857 [CXT5051_HP] = "hp", 1922 [CXT5051_HP] = "hp",
1858 [CXT5051_HP_DV6736] = "hp-dv6736", 1923 [CXT5051_HP_DV6736] = "hp-dv6736",
1859 [CXT5051_LENOVO_X200] = "lenovo-x200", 1924 [CXT5051_LENOVO_X200] = "lenovo-x200",
1925 [CXT5051_F700] = "hp-700",
1926 [CXT5051_TOSHIBA] = "toshiba",
1860}; 1927};
1861 1928
1862static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 1929static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1863 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 1930 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1864 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 1931 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1932 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1933 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1865 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1934 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1866 CXT5051_LAPTOP), 1935 CXT5051_LAPTOP),
1867 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1936 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
@@ -1889,8 +1958,9 @@ static int patch_cxt5051(struct hda_codec *codec)
1889 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1958 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1890 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1959 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1891 spec->adc_nids = cxt5051_adc_nids; 1960 spec->adc_nids = cxt5051_adc_nids;
1892 spec->num_mixers = 1; 1961 spec->num_mixers = 2;
1893 spec->mixers[0] = cxt5051_mixers; 1962 spec->mixers[0] = cxt5051_capture_mixers;
1963 spec->mixers[1] = cxt5051_playback_mixers;
1894 spec->num_init_verbs = 1; 1964 spec->num_init_verbs = 1;
1895 spec->init_verbs[0] = cxt5051_init_verbs; 1965 spec->init_verbs[0] = cxt5051_init_verbs;
1896 spec->spdif_route = 0; 1966 spec->spdif_route = 0;
@@ -1904,6 +1974,7 @@ static int patch_cxt5051(struct hda_codec *codec)
1904 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1974 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1905 cxt5051_models, 1975 cxt5051_models,
1906 cxt5051_cfg_tbl); 1976 cxt5051_cfg_tbl);
1977 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1907 switch (board_config) { 1978 switch (board_config) {
1908 case CXT5051_HP: 1979 case CXT5051_HP:
1909 spec->mixers[0] = cxt5051_hp_mixers; 1980 spec->mixers[0] = cxt5051_hp_mixers;
@@ -1911,11 +1982,20 @@ static int patch_cxt5051(struct hda_codec *codec)
1911 case CXT5051_HP_DV6736: 1982 case CXT5051_HP_DV6736:
1912 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 1983 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1913 spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1984 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1914 spec->no_auto_mic = 1; 1985 spec->auto_mic = 0;
1915 break; 1986 break;
1916 case CXT5051_LENOVO_X200: 1987 case CXT5051_LENOVO_X200:
1917 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 1988 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1918 break; 1989 break;
1990 case CXT5051_F700:
1991 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1992 spec->mixers[0] = cxt5051_f700_mixers;
1993 spec->auto_mic = 0;
1994 break;
1995 case CXT5051_TOSHIBA:
1996 spec->mixers[0] = cxt5051_toshiba_mixers;
1997 spec->auto_mic = AUTO_MIC_PORTB;
1998 break;
1919 } 1999 }
1920 2000
1921 return 0; 2001 return 0;
@@ -1983,36 +2063,147 @@ static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1983 return 1; 2063 return 1;
1984} 2064}
1985 2065
2066static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2067 .num_items = 3,
2068 .items = {
2069 { "Off", PIN_IN },
2070 { "50%", PIN_VREF50 },
2071 { "80%", PIN_VREF80 },
2072 },
2073};
2074
2075static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2076{
2077 struct conexant_spec *spec = codec->spec;
2078 /* Even though port F is the DC input, the bias is controlled on port B.
2079 * we also leave that port as an active input (but unselected) in DC mode
2080 * just in case that is necessary to make the bias setting take effect. */
2081 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2082 AC_VERB_SET_PIN_WIDGET_CONTROL,
2083 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2084}
2085
2086/* OLPC defers mic widget control until when capture is started because the
2087 * microphone LED comes on as soon as these settings are put in place. if we
2088 * did this before recording, it would give the false indication that recording
2089 * is happening when it is not. */
2090static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2091{
2092 struct conexant_spec *spec = codec->spec;
2093 if (!spec->recording)
2094 return;
2095
2096 if (spec->dc_enable) {
2097 /* in DC mode we ignore presence detection and just use the jack
2098 * through our special DC port */
2099 const struct hda_verb enable_dc_mode[] = {
2100 /* disble internal mic, port C */
2101 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2102
2103 /* enable DC capture, port F */
2104 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2105 {},
2106 };
2107
2108 snd_hda_sequence_write(codec, enable_dc_mode);
2109 /* port B input disabled (and bias set) through the following call */
2110 cxt5066_set_olpc_dc_bias(codec);
2111 return;
2112 }
2113
2114 /* disable DC (port F) */
2115 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2116
2117 /* external mic, port B */
2118 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2119 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2120
2121 /* internal mic, port C */
2122 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2123 spec->ext_mic_present ? 0 : PIN_VREF80);
2124}
2125
1986/* toggle input of built-in and mic jack appropriately */ 2126/* toggle input of built-in and mic jack appropriately */
1987static void cxt5066_automic(struct hda_codec *codec) 2127static void cxt5066_olpc_automic(struct hda_codec *codec)
1988{ 2128{
1989 struct conexant_spec *spec = codec->spec; 2129 struct conexant_spec *spec = codec->spec;
2130 unsigned int present;
2131
2132 if (spec->dc_enable) /* don't do presence detection in DC mode */
2133 return;
2134
2135 present = snd_hda_codec_read(codec, 0x1a, 0,
2136 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2137 if (present)
2138 snd_printdd("CXT5066: external microphone detected\n");
2139 else
2140 snd_printdd("CXT5066: external microphone absent\n");
2141
2142 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2143 present ? 0 : 1);
2144 spec->ext_mic_present = !!present;
2145
2146 cxt5066_olpc_select_mic(codec);
2147}
2148
2149/* toggle input of built-in digital mic and mic jack appropriately */
2150static void cxt5066_vostro_automic(struct hda_codec *codec)
2151{
2152 unsigned int present;
2153
1990 struct hda_verb ext_mic_present[] = { 2154 struct hda_verb ext_mic_present[] = {
1991 /* enable external mic, port B */ 2155 /* enable external mic, port B */
1992 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias}, 2156 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1993 2157
1994 /* switch to external mic input */ 2158 /* switch to external mic input */
1995 {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 2159 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2160 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
1996 2161
1997 /* disable internal mic, port C */ 2162 /* disable internal digital mic */
1998 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2163 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1999 {} 2164 {}
2000 }; 2165 };
2001 static struct hda_verb ext_mic_absent[] = { 2166 static struct hda_verb ext_mic_absent[] = {
2002 /* enable internal mic, port C */ 2167 /* enable internal mic, port C */
2003 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2168 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2004 2169
2005 /* switch to internal mic input */ 2170 /* switch to internal mic input */
2006 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 2171 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2007 2172
2008 /* disable external mic, port B */ 2173 /* disable external mic, port B */
2009 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2174 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2010 {} 2175 {}
2011 }; 2176 };
2177
2178 present = snd_hda_jack_detect(codec, 0x1a);
2179 if (present) {
2180 snd_printdd("CXT5066: external microphone detected\n");
2181 snd_hda_sequence_write(codec, ext_mic_present);
2182 } else {
2183 snd_printdd("CXT5066: external microphone absent\n");
2184 snd_hda_sequence_write(codec, ext_mic_absent);
2185 }
2186}
2187
2188/* toggle input of built-in digital mic and mic jack appropriately */
2189static void cxt5066_ideapad_automic(struct hda_codec *codec)
2190{
2012 unsigned int present; 2191 unsigned int present;
2013 2192
2014 present = snd_hda_codec_read(codec, 0x1a, 0, 2193 struct hda_verb ext_mic_present[] = {
2015 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 2194 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2195 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2196 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2197 {}
2198 };
2199 static struct hda_verb ext_mic_absent[] = {
2200 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2201 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2202 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2203 {}
2204 };
2205
2206 present = snd_hda_jack_detect(codec, 0x1b);
2016 if (present) { 2207 if (present) {
2017 snd_printdd("CXT5066: external microphone detected\n"); 2208 snd_printdd("CXT5066: external microphone detected\n");
2018 snd_hda_sequence_write(codec, ext_mic_present); 2209 snd_hda_sequence_write(codec, ext_mic_present);
@@ -2029,12 +2220,10 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
2029 unsigned int portA, portD; 2220 unsigned int portA, portD;
2030 2221
2031 /* Port A */ 2222 /* Port A */
2032 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0) 2223 portA = snd_hda_jack_detect(codec, 0x19);
2033 & AC_PINSENSE_PRESENCE;
2034 2224
2035 /* Port D */ 2225 /* Port D */
2036 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) 2226 portD = snd_hda_jack_detect(codec, 0x1c);
2037 & AC_PINSENSE_PRESENCE) << 1;
2038 2227
2039 spec->hp_present = !!(portA | portD); 2228 spec->hp_present = !!(portA | portD);
2040 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2229 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
@@ -2043,15 +2232,46 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
2043} 2232}
2044 2233
2045/* unsolicited event for jack sensing */ 2234/* unsolicited event for jack sensing */
2046static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 2235static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2047{ 2236{
2237 struct conexant_spec *spec = codec->spec;
2048 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 2238 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2049 switch (res >> 26) { 2239 switch (res >> 26) {
2050 case CONEXANT_HP_EVENT: 2240 case CONEXANT_HP_EVENT:
2051 cxt5066_hp_automute(codec); 2241 cxt5066_hp_automute(codec);
2052 break; 2242 break;
2053 case CONEXANT_MIC_EVENT: 2243 case CONEXANT_MIC_EVENT:
2054 cxt5066_automic(codec); 2244 /* ignore mic events in DC mode; we're always using the jack */
2245 if (!spec->dc_enable)
2246 cxt5066_olpc_automic(codec);
2247 break;
2248 }
2249}
2250
2251/* unsolicited event for jack sensing */
2252static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2253{
2254 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2255 switch (res >> 26) {
2256 case CONEXANT_HP_EVENT:
2257 cxt5066_hp_automute(codec);
2258 break;
2259 case CONEXANT_MIC_EVENT:
2260 cxt5066_vostro_automic(codec);
2261 break;
2262 }
2263}
2264
2265/* unsolicited event for jack sensing */
2266static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2267{
2268 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2269 switch (res >> 26) {
2270 case CONEXANT_HP_EVENT:
2271 cxt5066_hp_automute(codec);
2272 break;
2273 case CONEXANT_MIC_EVENT:
2274 cxt5066_ideapad_automic(codec);
2055 break; 2275 break;
2056 } 2276 }
2057} 2277}
@@ -2067,6 +2287,23 @@ static const struct hda_input_mux cxt5066_analog_mic_boost = {
2067 }, 2287 },
2068}; 2288};
2069 2289
2290static void cxt5066_set_mic_boost(struct hda_codec *codec)
2291{
2292 struct conexant_spec *spec = codec->spec;
2293 snd_hda_codec_write_cache(codec, 0x17, 0,
2294 AC_VERB_SET_AMP_GAIN_MUTE,
2295 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2296 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2297 if (spec->ideapad) {
2298 /* adjust the internal mic as well...it is not through 0x17 */
2299 snd_hda_codec_write_cache(codec, 0x23, 0,
2300 AC_VERB_SET_AMP_GAIN_MUTE,
2301 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2302 cxt5066_analog_mic_boost.
2303 items[spec->mic_boost].index);
2304 }
2305}
2306
2070static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 2307static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2071 struct snd_ctl_elem_info *uinfo) 2308 struct snd_ctl_elem_info *uinfo)
2072{ 2309{
@@ -2077,12 +2314,8 @@ static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2077 struct snd_ctl_elem_value *ucontrol) 2314 struct snd_ctl_elem_value *ucontrol)
2078{ 2315{
2079 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2316 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2080 int val; 2317 struct conexant_spec *spec = codec->spec;
2081 2318 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2082 val = snd_hda_codec_read(codec, 0x17, 0,
2083 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2084
2085 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2086 return 0; 2319 return 0;
2087} 2320}
2088 2321
@@ -2090,23 +2323,132 @@ static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2090 struct snd_ctl_elem_value *ucontrol) 2323 struct snd_ctl_elem_value *ucontrol)
2091{ 2324{
2092 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2326 struct conexant_spec *spec = codec->spec;
2093 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2327 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2094 unsigned int idx; 2328 unsigned int idx;
2329 idx = ucontrol->value.enumerated.item[0];
2330 if (idx >= imux->num_items)
2331 idx = imux->num_items - 1;
2095 2332
2096 if (!imux->num_items) 2333 spec->mic_boost = idx;
2334 if (!spec->dc_enable)
2335 cxt5066_set_mic_boost(codec);
2336 return 1;
2337}
2338
2339static void cxt5066_enable_dc(struct hda_codec *codec)
2340{
2341 const struct hda_verb enable_dc_mode[] = {
2342 /* disable gain */
2343 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2344
2345 /* switch to DC input */
2346 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2347 {}
2348 };
2349
2350 /* configure as input source */
2351 snd_hda_sequence_write(codec, enable_dc_mode);
2352 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2353}
2354
2355static void cxt5066_disable_dc(struct hda_codec *codec)
2356{
2357 /* reconfigure input source */
2358 cxt5066_set_mic_boost(codec);
2359 /* automic also selects the right mic if we're recording */
2360 cxt5066_olpc_automic(codec);
2361}
2362
2363static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2364 struct snd_ctl_elem_value *ucontrol)
2365{
2366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2367 struct conexant_spec *spec = codec->spec;
2368 ucontrol->value.integer.value[0] = spec->dc_enable;
2369 return 0;
2370}
2371
2372static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2373 struct snd_ctl_elem_value *ucontrol)
2374{
2375 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2376 struct conexant_spec *spec = codec->spec;
2377 int dc_enable = !!ucontrol->value.integer.value[0];
2378
2379 if (dc_enable == spec->dc_enable)
2097 return 0; 2380 return 0;
2381
2382 spec->dc_enable = dc_enable;
2383 if (dc_enable)
2384 cxt5066_enable_dc(codec);
2385 else
2386 cxt5066_disable_dc(codec);
2387
2388 return 1;
2389}
2390
2391static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_info *uinfo)
2393{
2394 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2395}
2396
2397static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2398 struct snd_ctl_elem_value *ucontrol)
2399{
2400 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2401 struct conexant_spec *spec = codec->spec;
2402 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2403 return 0;
2404}
2405
2406static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2407 struct snd_ctl_elem_value *ucontrol)
2408{
2409 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2410 struct conexant_spec *spec = codec->spec;
2411 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2412 unsigned int idx;
2413
2098 idx = ucontrol->value.enumerated.item[0]; 2414 idx = ucontrol->value.enumerated.item[0];
2099 if (idx >= imux->num_items) 2415 if (idx >= imux->num_items)
2100 idx = imux->num_items - 1; 2416 idx = imux->num_items - 1;
2101 2417
2102 snd_hda_codec_write_cache(codec, 0x17, 0, 2418 spec->dc_input_bias = idx;
2103 AC_VERB_SET_AMP_GAIN_MUTE, 2419 if (spec->dc_enable)
2104 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2420 cxt5066_set_olpc_dc_bias(codec);
2105 imux->items[idx].index);
2106
2107 return 1; 2421 return 1;
2108} 2422}
2109 2423
2424static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2425{
2426 struct conexant_spec *spec = codec->spec;
2427 /* mark as recording and configure the microphone widget so that the
2428 * recording LED comes on. */
2429 spec->recording = 1;
2430 cxt5066_olpc_select_mic(codec);
2431}
2432
2433static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2434{
2435 struct conexant_spec *spec = codec->spec;
2436 const struct hda_verb disable_mics[] = {
2437 /* disable external mic, port B */
2438 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2439
2440 /* disble internal mic, port C */
2441 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2442
2443 /* disable DC capture, port F */
2444 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2445 {},
2446 };
2447
2448 snd_hda_sequence_write(codec, disable_mics);
2449 spec->recording = 0;
2450}
2451
2110static struct hda_input_mux cxt5066_capture_source = { 2452static struct hda_input_mux cxt5066_capture_source = {
2111 .num_items = 4, 2453 .num_items = 4,
2112 .items = { 2454 .items = {
@@ -2147,6 +2489,7 @@ static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2147 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 2489 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2148 SNDRV_CTL_ELEM_ACCESS_TLV_READ | 2490 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2149 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 2491 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2492 .subdevice = HDA_SUBDEV_AMP_FLAG,
2150 .info = snd_hda_mixer_amp_volume_info, 2493 .info = snd_hda_mixer_amp_volume_info,
2151 .get = snd_hda_mixer_amp_volume_get, 2494 .get = snd_hda_mixer_amp_volume_get,
2152 .put = snd_hda_mixer_amp_volume_put, 2495 .put = snd_hda_mixer_amp_volume_put,
@@ -2158,6 +2501,24 @@ static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2158 {} 2501 {}
2159}; 2502};
2160 2503
2504static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2505 {
2506 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2507 .name = "DC Mode Enable Switch",
2508 .info = snd_ctl_boolean_mono_info,
2509 .get = cxt5066_olpc_dc_get,
2510 .put = cxt5066_olpc_dc_put,
2511 },
2512 {
2513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2514 .name = "DC Input Bias Enum",
2515 .info = cxt5066_olpc_dc_bias_enum_info,
2516 .get = cxt5066_olpc_dc_bias_enum_get,
2517 .put = cxt5066_olpc_dc_bias_enum_put,
2518 },
2519 {}
2520};
2521
2161static struct snd_kcontrol_new cxt5066_mixers[] = { 2522static struct snd_kcontrol_new cxt5066_mixers[] = {
2162 { 2523 {
2163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -2181,6 +2542,19 @@ static struct snd_kcontrol_new cxt5066_mixers[] = {
2181 {} 2542 {}
2182}; 2543};
2183 2544
2545static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2546 {
2547 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2548 .name = "Int Mic Boost Capture Enum",
2549 .info = cxt5066_mic_boost_mux_enum_info,
2550 .get = cxt5066_mic_boost_mux_enum_get,
2551 .put = cxt5066_mic_boost_mux_enum_put,
2552 .private_value = 0x23 | 0x100,
2553 },
2554 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2555 {}
2556};
2557
2184static struct hda_verb cxt5066_init_verbs[] = { 2558static struct hda_verb cxt5066_init_verbs[] = {
2185 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2559 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2186 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2560 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
@@ -2242,10 +2616,10 @@ static struct hda_verb cxt5066_init_verbs_olpc[] = {
2242 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2616 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2243 2617
2244 /* Port B: external microphone */ 2618 /* Port B: external microphone */
2245 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS}, 2619 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2246 2620
2247 /* Port C: internal microphone */ 2621 /* Port C: internal microphone */
2248 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2622 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2249 2623
2250 /* Port D: unused */ 2624 /* Port D: unused */
2251 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2625 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
@@ -2254,7 +2628,7 @@ static struct hda_verb cxt5066_init_verbs_olpc[] = {
2254 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2628 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2255 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2629 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2256 2630
2257 /* Port F: unused */ 2631 /* Port F: external DC input through microphone port */
2258 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2632 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2259 2633
2260 /* Port G: internal speakers */ 2634 /* Port G: internal speakers */
@@ -2297,6 +2671,117 @@ static struct hda_verb cxt5066_init_verbs_olpc[] = {
2297 { } /* end */ 2671 { } /* end */
2298}; 2672};
2299 2673
2674static struct hda_verb cxt5066_init_verbs_vostro[] = {
2675 /* Port A: headphones */
2676 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2677 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2678
2679 /* Port B: external microphone */
2680 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2681
2682 /* Port C: unused */
2683 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2684
2685 /* Port D: unused */
2686 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2687
2688 /* Port E: unused, but has primary EAPD */
2689 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2690 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2691
2692 /* Port F: unused */
2693 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2694
2695 /* Port G: internal speakers */
2696 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2697 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2698
2699 /* DAC1 */
2700 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2701
2702 /* DAC2: unused */
2703 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2704
2705 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2706 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2707 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2708 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2709 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2710 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2711 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2712 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2713 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2714 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2715 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2716 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2717
2718 /* Digital microphone port */
2719 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2720
2721 /* Audio input selectors */
2722 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2723 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2724
2725 /* Disable SPDIF */
2726 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2728
2729 /* enable unsolicited events for Port A and B */
2730 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2731 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2732 { } /* end */
2733};
2734
2735static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2736 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2737 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2738 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2739 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2740
2741 /* Speakers */
2742 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2743 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2744
2745 /* HP, Amp */
2746 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2747 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2748
2749 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2750 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2751
2752 /* DAC1 */
2753 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2754
2755 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2759 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2761 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2762
2763 /* Audio input selector */
2764 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2765 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2766
2767 /* SPDIF route: PCM */
2768 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2769 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2770
2771 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2772 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2773
2774 /* internal microphone */
2775 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2776
2777 /* EAPD */
2778 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2779
2780 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2781 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2782 { } /* end */
2783};
2784
2300static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 2785static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2301 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2786 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2302 { } /* end */ 2787 { } /* end */
@@ -2305,11 +2790,32 @@ static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2305/* initialize jack-sensing, too */ 2790/* initialize jack-sensing, too */
2306static int cxt5066_init(struct hda_codec *codec) 2791static int cxt5066_init(struct hda_codec *codec)
2307{ 2792{
2793 struct conexant_spec *spec = codec->spec;
2794
2308 snd_printdd("CXT5066: init\n"); 2795 snd_printdd("CXT5066: init\n");
2309 conexant_init(codec); 2796 conexant_init(codec);
2310 if (codec->patch_ops.unsol_event) { 2797 if (codec->patch_ops.unsol_event) {
2311 cxt5066_hp_automute(codec); 2798 cxt5066_hp_automute(codec);
2312 cxt5066_automic(codec); 2799 if (spec->dell_vostro)
2800 cxt5066_vostro_automic(codec);
2801 else if (spec->ideapad)
2802 cxt5066_ideapad_automic(codec);
2803 }
2804 cxt5066_set_mic_boost(codec);
2805 return 0;
2806}
2807
2808static int cxt5066_olpc_init(struct hda_codec *codec)
2809{
2810 struct conexant_spec *spec = codec->spec;
2811 snd_printdd("CXT5066: init\n");
2812 conexant_init(codec);
2813 cxt5066_hp_automute(codec);
2814 if (!spec->dc_enable) {
2815 cxt5066_set_mic_boost(codec);
2816 cxt5066_olpc_automic(codec);
2817 } else {
2818 cxt5066_enable_dc(codec);
2313 } 2819 }
2314 return 0; 2820 return 0;
2315} 2821}
@@ -2318,6 +2824,8 @@ enum {
2318 CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 2824 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2319 CXT5066_DELL_LAPTOP, /* Dell Laptop */ 2825 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2320 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 2826 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2827 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
2828 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
2321 CXT5066_MODELS 2829 CXT5066_MODELS
2322}; 2830};
2323 2831
@@ -2325,6 +2833,8 @@ static const char *cxt5066_models[CXT5066_MODELS] = {
2325 [CXT5066_LAPTOP] = "laptop", 2833 [CXT5066_LAPTOP] = "laptop",
2326 [CXT5066_DELL_LAPTOP] = "dell-laptop", 2834 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2327 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 2835 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2836 [CXT5066_DELL_VOSTO] = "dell-vostro",
2837 [CXT5066_IDEAPAD] = "ideapad",
2328}; 2838};
2329 2839
2330static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 2840static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
@@ -2333,6 +2843,12 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2333 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 2843 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2334 CXT5066_DELL_LAPTOP), 2844 CXT5066_DELL_LAPTOP),
2335 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 2845 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2846 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
2847 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2848 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2849 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
2850 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
2851 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
2336 {} 2852 {}
2337}; 2853};
2338 2854
@@ -2347,7 +2863,7 @@ static int patch_cxt5066(struct hda_codec *codec)
2347 codec->spec = spec; 2863 codec->spec = spec;
2348 2864
2349 codec->patch_ops = conexant_patch_ops; 2865 codec->patch_ops = conexant_patch_ops;
2350 codec->patch_ops.init = cxt5066_init; 2866 codec->patch_ops.init = conexant_init;
2351 2867
2352 spec->dell_automute = 0; 2868 spec->dell_automute = 0;
2353 spec->multiout.max_channels = 2; 2869 spec->multiout.max_channels = 2;
@@ -2360,7 +2876,6 @@ static int patch_cxt5066(struct hda_codec *codec)
2360 spec->input_mux = &cxt5066_capture_source; 2876 spec->input_mux = &cxt5066_capture_source;
2361 2877
2362 spec->port_d_mode = PIN_HP; 2878 spec->port_d_mode = PIN_HP;
2363 spec->ext_mic_bias = PIN_VREF80;
2364 2879
2365 spec->num_init_verbs = 1; 2880 spec->num_init_verbs = 1;
2366 spec->init_verbs[0] = cxt5066_init_verbs; 2881 spec->init_verbs[0] = cxt5066_init_verbs;
@@ -2387,12 +2902,53 @@ static int patch_cxt5066(struct hda_codec *codec)
2387 spec->dell_automute = 1; 2902 spec->dell_automute = 1;
2388 break; 2903 break;
2389 case CXT5066_OLPC_XO_1_5: 2904 case CXT5066_OLPC_XO_1_5:
2390 codec->patch_ops.unsol_event = cxt5066_unsol_event; 2905 codec->patch_ops.init = cxt5066_olpc_init;
2906 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
2391 spec->init_verbs[0] = cxt5066_init_verbs_olpc; 2907 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2392 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 2908 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2909 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
2910 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2911 spec->port_d_mode = 0;
2912 spec->mic_boost = 3; /* default 30dB gain */
2913
2914 /* no S/PDIF out */
2915 spec->multiout.dig_out_nid = 0;
2916
2917 /* input source automatically selected */
2918 spec->input_mux = NULL;
2919
2920 /* our capture hooks which allow us to turn on the microphone LED
2921 * at the right time */
2922 spec->capture_prepare = cxt5066_olpc_capture_prepare;
2923 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
2924 break;
2925 case CXT5066_DELL_VOSTO:
2926 codec->patch_ops.init = cxt5066_init;
2927 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2928 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2929 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2393 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2930 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2931 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
2394 spec->port_d_mode = 0; 2932 spec->port_d_mode = 0;
2395 spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS; 2933 spec->dell_vostro = 1;
2934 spec->mic_boost = 3; /* default 30dB gain */
2935 snd_hda_attach_beep_device(codec, 0x13);
2936
2937 /* no S/PDIF out */
2938 spec->multiout.dig_out_nid = 0;
2939
2940 /* input source automatically selected */
2941 spec->input_mux = NULL;
2942 break;
2943 case CXT5066_IDEAPAD:
2944 codec->patch_ops.init = cxt5066_init;
2945 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
2946 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2947 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2948 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
2949 spec->port_d_mode = 0;
2950 spec->ideapad = 1;
2951 spec->mic_boost = 2; /* default 20dB gain */
2396 2952
2397 /* no S/PDIF out */ 2953 /* no S/PDIF out */
2398 spec->multiout.dig_out_nid = 0; 2954 spec->multiout.dig_out_nid = 0;
@@ -2417,6 +2973,8 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
2417 .patch = patch_cxt5051 }, 2973 .patch = patch_cxt5051 },
2418 { .id = 0x14f15066, .name = "CX20582 (Pebble)", 2974 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2419 .patch = patch_cxt5066 }, 2975 .patch = patch_cxt5066 },
2976 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2977 .patch = patch_cxt5066 },
2420 {} /* terminator */ 2978 {} /* terminator */
2421}; 2979};
2422 2980
@@ -2424,6 +2982,7 @@ MODULE_ALIAS("snd-hda-codec-id:14f15045");
2424MODULE_ALIAS("snd-hda-codec-id:14f15047"); 2982MODULE_ALIAS("snd-hda-codec-id:14f15047");
2425MODULE_ALIAS("snd-hda-codec-id:14f15051"); 2983MODULE_ALIAS("snd-hda-codec-id:14f15051");
2426MODULE_ALIAS("snd-hda-codec-id:14f15066"); 2984MODULE_ALIAS("snd-hda-codec-id:14f15066");
2985MODULE_ALIAS("snd-hda-codec-id:14f15067");
2427 2986
2428MODULE_LICENSE("GPL"); 2987MODULE_LICENSE("GPL");
2429MODULE_DESCRIPTION("Conexant HD-audio codec"); 2988MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
new file mode 100644
index 000000000000..2c2bafbf0258
--- /dev/null
+++ b/sound/pci/hda/patch_hdmi.c
@@ -0,0 +1,849 @@
1/*
2 *
3 * patch_hdmi.c - routines for HDMI/DisplayPort codecs
4 *
5 * Copyright(c) 2008-2010 Intel Corporation. All rights reserved.
6 *
7 * Authors:
8 * Wu Fengguang <wfg@linux.intel.com>
9 *
10 * Maintained by:
11 * Wu Fengguang <wfg@linux.intel.com>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */
27
28
29struct hdmi_spec {
30 int num_cvts;
31 int num_pins;
32 hda_nid_t cvt[MAX_HDMI_CVTS+1]; /* audio sources */
33 hda_nid_t pin[MAX_HDMI_PINS+1]; /* audio sinks */
34
35 /*
36 * source connection for each pin
37 */
38 hda_nid_t pin_cvt[MAX_HDMI_PINS+1];
39
40 /*
41 * HDMI sink attached to each pin
42 */
43 struct hdmi_eld sink_eld[MAX_HDMI_PINS];
44
45 /*
46 * export one pcm per pipe
47 */
48 struct hda_pcm pcm_rec[MAX_HDMI_CVTS];
49
50 /*
51 * nvhdmi specific
52 */
53 struct hda_multi_out multiout;
54 unsigned int codec_type;
55};
56
57
58struct hdmi_audio_infoframe {
59 u8 type; /* 0x84 */
60 u8 ver; /* 0x01 */
61 u8 len; /* 0x0a */
62
63 u8 checksum; /* PB0 */
64 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
65 u8 SS01_SF24;
66 u8 CXT04;
67 u8 CA;
68 u8 LFEPBL01_LSV36_DM_INH7;
69 u8 reserved[5]; /* PB6 - PB10 */
70};
71
72/*
73 * CEA speaker placement:
74 *
75 * FLH FCH FRH
76 * FLW FL FLC FC FRC FR FRW
77 *
78 * LFE
79 * TC
80 *
81 * RL RLC RC RRC RR
82 *
83 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
84 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
85 */
86enum cea_speaker_placement {
87 FL = (1 << 0), /* Front Left */
88 FC = (1 << 1), /* Front Center */
89 FR = (1 << 2), /* Front Right */
90 FLC = (1 << 3), /* Front Left Center */
91 FRC = (1 << 4), /* Front Right Center */
92 RL = (1 << 5), /* Rear Left */
93 RC = (1 << 6), /* Rear Center */
94 RR = (1 << 7), /* Rear Right */
95 RLC = (1 << 8), /* Rear Left Center */
96 RRC = (1 << 9), /* Rear Right Center */
97 LFE = (1 << 10), /* Low Frequency Effect */
98 FLW = (1 << 11), /* Front Left Wide */
99 FRW = (1 << 12), /* Front Right Wide */
100 FLH = (1 << 13), /* Front Left High */
101 FCH = (1 << 14), /* Front Center High */
102 FRH = (1 << 15), /* Front Right High */
103 TC = (1 << 16), /* Top Center */
104};
105
106/*
107 * ELD SA bits in the CEA Speaker Allocation data block
108 */
109static int eld_speaker_allocation_bits[] = {
110 [0] = FL | FR,
111 [1] = LFE,
112 [2] = FC,
113 [3] = RL | RR,
114 [4] = RC,
115 [5] = FLC | FRC,
116 [6] = RLC | RRC,
117 /* the following are not defined in ELD yet */
118 [7] = FLW | FRW,
119 [8] = FLH | FRH,
120 [9] = TC,
121 [10] = FCH,
122};
123
124struct cea_channel_speaker_allocation {
125 int ca_index;
126 int speakers[8];
127
128 /* derived values, just for convenience */
129 int channels;
130 int spk_mask;
131};
132
133/*
134 * ALSA sequence is:
135 *
136 * surround40 surround41 surround50 surround51 surround71
137 * ch0 front left = = = =
138 * ch1 front right = = = =
139 * ch2 rear left = = = =
140 * ch3 rear right = = = =
141 * ch4 LFE center center center
142 * ch5 LFE LFE
143 * ch6 side left
144 * ch7 side right
145 *
146 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
147 */
148static int hdmi_channel_mapping[0x32][8] = {
149 /* stereo */
150 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
151 /* 2.1 */
152 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
153 /* Dolby Surround */
154 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
155 /* surround40 */
156 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
157 /* 4ch */
158 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
159 /* surround41 */
160 [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 },
161 /* surround50 */
162 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
163 /* surround51 */
164 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
165 /* 7.1 */
166 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
167};
168
169/*
170 * This is an ordered list!
171 *
172 * The preceding ones have better chances to be selected by
173 * hdmi_setup_channel_allocation().
174 */
175static struct cea_channel_speaker_allocation channel_allocations[] = {
176/* channel: 7 6 5 4 3 2 1 0 */
177{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
178 /* 2.1 */
179{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
180 /* Dolby Surround */
181{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
182 /* surround40 */
183{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
184 /* surround41 */
185{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
186 /* surround50 */
187{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
188 /* surround51 */
189{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
190 /* 6.1 */
191{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
192 /* surround71 */
193{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
194
195{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
196{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
197{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
198{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
199{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
200{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
201{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
202{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
203{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
204{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
205{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
206{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
207{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
208{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
209{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
210{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
211{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
212{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
213{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
214{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
215{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
216{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
217{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
218{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
219{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
220{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
221{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
222{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
223{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
224{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
225{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
226{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
227{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
228{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
229{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
230{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
231{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
232{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
233{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
234{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
235{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
236};
237
238
239/*
240 * HDMI routines
241 */
242
243static int hda_node_index(hda_nid_t *nids, hda_nid_t nid)
244{
245 int i;
246
247 for (i = 0; nids[i]; i++)
248 if (nids[i] == nid)
249 return i;
250
251 snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid);
252 return -EINVAL;
253}
254
255static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid,
256 struct hdmi_eld *eld)
257{
258 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
259 snd_hdmi_show_eld(eld);
260}
261
262#ifdef BE_PARANOID
263static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
264 int *packet_index, int *byte_index)
265{
266 int val;
267
268 val = snd_hda_codec_read(codec, pin_nid, 0,
269 AC_VERB_GET_HDMI_DIP_INDEX, 0);
270
271 *packet_index = val >> 5;
272 *byte_index = val & 0x1f;
273}
274#endif
275
276static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
277 int packet_index, int byte_index)
278{
279 int val;
280
281 val = (packet_index << 5) | (byte_index & 0x1f);
282
283 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
284}
285
286static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
287 unsigned char val)
288{
289 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
290}
291
292static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid)
293{
294 /* Unmute */
295 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
296 snd_hda_codec_write(codec, pin_nid, 0,
297 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
298 /* Enable pin out */
299 snd_hda_codec_write(codec, pin_nid, 0,
300 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
301}
302
303static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid)
304{
305 return 1 + snd_hda_codec_read(codec, nid, 0,
306 AC_VERB_GET_CVT_CHAN_COUNT, 0);
307}
308
309static void hdmi_set_channel_count(struct hda_codec *codec,
310 hda_nid_t nid, int chs)
311{
312 if (chs != hdmi_get_channel_count(codec, nid))
313 snd_hda_codec_write(codec, nid, 0,
314 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
315}
316
317
318/*
319 * Channel mapping routines
320 */
321
322/*
323 * Compute derived values in channel_allocations[].
324 */
325static void init_channel_allocations(void)
326{
327 int i, j;
328 struct cea_channel_speaker_allocation *p;
329
330 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
331 p = channel_allocations + i;
332 p->channels = 0;
333 p->spk_mask = 0;
334 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
335 if (p->speakers[j]) {
336 p->channels++;
337 p->spk_mask |= p->speakers[j];
338 }
339 }
340}
341
342/*
343 * The transformation takes two steps:
344 *
345 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
346 * spk_mask => (channel_allocations[]) => ai->CA
347 *
348 * TODO: it could select the wrong CA from multiple candidates.
349*/
350static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid,
351 struct hdmi_audio_infoframe *ai)
352{
353 struct hdmi_spec *spec = codec->spec;
354 struct hdmi_eld *eld;
355 int i;
356 int spk_mask = 0;
357 int channels = 1 + (ai->CC02_CT47 & 0x7);
358 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
359
360 /*
361 * CA defaults to 0 for basic stereo audio
362 */
363 if (channels <= 2)
364 return 0;
365
366 i = hda_node_index(spec->pin_cvt, nid);
367 if (i < 0)
368 return 0;
369 eld = &spec->sink_eld[i];
370
371 /*
372 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
373 * in console or for audio devices. Assume the highest speakers
374 * configuration, to _not_ prohibit multi-channel audio playback.
375 */
376 if (!eld->spk_alloc)
377 eld->spk_alloc = 0xffff;
378
379 /*
380 * expand ELD's speaker allocation mask
381 *
382 * ELD tells the speaker mask in a compact(paired) form,
383 * expand ELD's notions to match the ones used by Audio InfoFrame.
384 */
385 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
386 if (eld->spk_alloc & (1 << i))
387 spk_mask |= eld_speaker_allocation_bits[i];
388 }
389
390 /* search for the first working match in the CA table */
391 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
392 if (channels == channel_allocations[i].channels &&
393 (spk_mask & channel_allocations[i].spk_mask) ==
394 channel_allocations[i].spk_mask) {
395 ai->CA = channel_allocations[i].ca_index;
396 break;
397 }
398 }
399
400 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
401 snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
402 ai->CA, channels, buf);
403
404 return ai->CA;
405}
406
407static void hdmi_debug_channel_mapping(struct hda_codec *codec,
408 hda_nid_t pin_nid)
409{
410#ifdef CONFIG_SND_DEBUG_VERBOSE
411 int i;
412 int slot;
413
414 for (i = 0; i < 8; i++) {
415 slot = snd_hda_codec_read(codec, pin_nid, 0,
416 AC_VERB_GET_HDMI_CHAN_SLOT, i);
417 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
418 slot >> 4, slot & 0xf);
419 }
420#endif
421}
422
423
424static void hdmi_setup_channel_mapping(struct hda_codec *codec,
425 hda_nid_t pin_nid,
426 struct hdmi_audio_infoframe *ai)
427{
428 int i;
429 int ca = ai->CA;
430 int err;
431
432 if (hdmi_channel_mapping[ca][1] == 0) {
433 for (i = 0; i < channel_allocations[ca].channels; i++)
434 hdmi_channel_mapping[ca][i] = i | (i << 4);
435 for (; i < 8; i++)
436 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
437 }
438
439 for (i = 0; i < 8; i++) {
440 err = snd_hda_codec_write(codec, pin_nid, 0,
441 AC_VERB_SET_HDMI_CHAN_SLOT,
442 hdmi_channel_mapping[ca][i]);
443 if (err) {
444 snd_printdd(KERN_NOTICE
445 "HDMI: channel mapping failed\n");
446 break;
447 }
448 }
449
450 hdmi_debug_channel_mapping(codec, pin_nid);
451}
452
453
454/*
455 * Audio InfoFrame routines
456 */
457
458/*
459 * Enable Audio InfoFrame Transmission
460 */
461static void hdmi_start_infoframe_trans(struct hda_codec *codec,
462 hda_nid_t pin_nid)
463{
464 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
465 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
466 AC_DIPXMIT_BEST);
467}
468
469/*
470 * Disable Audio InfoFrame Transmission
471 */
472static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
473 hda_nid_t pin_nid)
474{
475 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
476 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
477 AC_DIPXMIT_DISABLE);
478}
479
480static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
481{
482#ifdef CONFIG_SND_DEBUG_VERBOSE
483 int i;
484 int size;
485
486 size = snd_hdmi_get_eld_size(codec, pin_nid);
487 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
488
489 for (i = 0; i < 8; i++) {
490 size = snd_hda_codec_read(codec, pin_nid, 0,
491 AC_VERB_GET_HDMI_DIP_SIZE, i);
492 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
493 }
494#endif
495}
496
497static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
498{
499#ifdef BE_PARANOID
500 int i, j;
501 int size;
502 int pi, bi;
503 for (i = 0; i < 8; i++) {
504 size = snd_hda_codec_read(codec, pin_nid, 0,
505 AC_VERB_GET_HDMI_DIP_SIZE, i);
506 if (size == 0)
507 continue;
508
509 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
510 for (j = 1; j < 1000; j++) {
511 hdmi_write_dip_byte(codec, pin_nid, 0x0);
512 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
513 if (pi != i)
514 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
515 bi, pi, i);
516 if (bi == 0) /* byte index wrapped around */
517 break;
518 }
519 snd_printd(KERN_INFO
520 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
521 i, size, j);
522 }
523#endif
524}
525
526static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai)
527{
528 u8 *bytes = (u8 *)ai;
529 u8 sum = 0;
530 int i;
531
532 ai->checksum = 0;
533
534 for (i = 0; i < sizeof(*ai); i++)
535 sum += bytes[i];
536
537 ai->checksum = -sum;
538}
539
540static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
541 hda_nid_t pin_nid,
542 struct hdmi_audio_infoframe *ai)
543{
544 u8 *bytes = (u8 *)ai;
545 int i;
546
547 hdmi_debug_dip_size(codec, pin_nid);
548 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
549
550 hdmi_checksum_audio_infoframe(ai);
551
552 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
553 for (i = 0; i < sizeof(*ai); i++)
554 hdmi_write_dip_byte(codec, pin_nid, bytes[i]);
555}
556
557static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
558 struct hdmi_audio_infoframe *ai)
559{
560 u8 *bytes = (u8 *)ai;
561 u8 val;
562 int i;
563
564 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
565 != AC_DIPXMIT_BEST)
566 return false;
567
568 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
569 for (i = 0; i < sizeof(*ai); i++) {
570 val = snd_hda_codec_read(codec, pin_nid, 0,
571 AC_VERB_GET_HDMI_DIP_DATA, 0);
572 if (val != bytes[i])
573 return false;
574 }
575
576 return true;
577}
578
579static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid,
580 struct snd_pcm_substream *substream)
581{
582 struct hdmi_spec *spec = codec->spec;
583 hda_nid_t pin_nid;
584 int i;
585 struct hdmi_audio_infoframe ai = {
586 .type = 0x84,
587 .ver = 0x01,
588 .len = 0x0a,
589 .CC02_CT47 = substream->runtime->channels - 1,
590 };
591
592 hdmi_setup_channel_allocation(codec, nid, &ai);
593
594 for (i = 0; i < spec->num_pins; i++) {
595 if (spec->pin_cvt[i] != nid)
596 continue;
597 if (!spec->sink_eld[i].monitor_present)
598 continue;
599
600 pin_nid = spec->pin[i];
601 if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) {
602 snd_printdd("hdmi_setup_audio_infoframe: "
603 "cvt=%d pin=%d channels=%d\n",
604 nid, pin_nid,
605 substream->runtime->channels);
606 hdmi_setup_channel_mapping(codec, pin_nid, &ai);
607 hdmi_stop_infoframe_trans(codec, pin_nid);
608 hdmi_fill_audio_infoframe(codec, pin_nid, &ai);
609 hdmi_start_infoframe_trans(codec, pin_nid);
610 }
611 }
612}
613
614
615/*
616 * Unsolicited events
617 */
618
619static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
620{
621 struct hdmi_spec *spec = codec->spec;
622 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
623 int pind = !!(res & AC_UNSOL_RES_PD);
624 int eldv = !!(res & AC_UNSOL_RES_ELDV);
625 int index;
626
627 printk(KERN_INFO
628 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
629 tag, pind, eldv);
630
631 index = hda_node_index(spec->pin, tag);
632 if (index < 0)
633 return;
634
635 spec->sink_eld[index].monitor_present = pind;
636 spec->sink_eld[index].eld_valid = eldv;
637
638 if (pind && eldv) {
639 hdmi_get_show_eld(codec, spec->pin[index],
640 &spec->sink_eld[index]);
641 /* TODO: do real things about ELD */
642 }
643}
644
645static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
646{
647 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
648 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
649 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
650 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
651
652 printk(KERN_INFO
653 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
654 tag,
655 subtag,
656 cp_state,
657 cp_ready);
658
659 /* TODO */
660 if (cp_state)
661 ;
662 if (cp_ready)
663 ;
664}
665
666
667static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
668{
669 struct hdmi_spec *spec = codec->spec;
670 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
671 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
672
673 if (hda_node_index(spec->pin, tag) < 0) {
674 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
675 return;
676 }
677
678 if (subtag == 0)
679 hdmi_intrinsic_event(codec, res);
680 else
681 hdmi_non_intrinsic_event(codec, res);
682}
683
684/*
685 * Callbacks
686 */
687
688static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid,
689 u32 stream_tag, int format)
690{
691 int tag;
692 int fmt;
693
694 tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4;
695 fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0);
696
697 snd_printdd("hdmi_setup_stream: "
698 "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
699 nid,
700 tag == stream_tag ? "" : "new-",
701 stream_tag,
702 fmt == format ? "" : "new-",
703 format);
704
705 if (tag != stream_tag)
706 snd_hda_codec_write(codec, nid, 0,
707 AC_VERB_SET_CHANNEL_STREAMID,
708 stream_tag << 4);
709 if (fmt != format)
710 snd_hda_codec_write(codec, nid, 0,
711 AC_VERB_SET_STREAM_FORMAT, format);
712}
713
714/*
715 * HDA/HDMI auto parsing
716 */
717
718static int hdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid)
719{
720 struct hdmi_spec *spec = codec->spec;
721 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
722 int conn_len, curr;
723 int index;
724
725 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
726 snd_printk(KERN_WARNING
727 "HDMI: pin %d wcaps %#x "
728 "does not support connection list\n",
729 pin_nid, get_wcaps(codec, pin_nid));
730 return -EINVAL;
731 }
732
733 conn_len = snd_hda_get_connections(codec, pin_nid, conn_list,
734 HDA_MAX_CONNECTIONS);
735 if (conn_len > 1)
736 curr = snd_hda_codec_read(codec, pin_nid, 0,
737 AC_VERB_GET_CONNECT_SEL, 0);
738 else
739 curr = 0;
740
741 index = hda_node_index(spec->pin, pin_nid);
742 if (index < 0)
743 return -EINVAL;
744
745 spec->pin_cvt[index] = conn_list[curr];
746
747 return 0;
748}
749
750static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
751 struct hdmi_eld *eld)
752{
753 int present = snd_hda_pin_sense(codec, pin_nid);
754
755 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
756 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
757
758 if (present & AC_PINSENSE_ELDV)
759 hdmi_get_show_eld(codec, pin_nid, eld);
760}
761
762static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
763{
764 struct hdmi_spec *spec = codec->spec;
765
766 if (spec->num_pins >= MAX_HDMI_PINS) {
767 snd_printk(KERN_WARNING
768 "HDMI: no space for pin %d\n", pin_nid);
769 return -EINVAL;
770 }
771
772 hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]);
773
774 spec->pin[spec->num_pins] = pin_nid;
775 spec->num_pins++;
776
777 /*
778 * It is assumed that converter nodes come first in the node list and
779 * hence have been registered and usable now.
780 */
781 return hdmi_read_pin_conn(codec, pin_nid);
782}
783
784static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid)
785{
786 struct hdmi_spec *spec = codec->spec;
787
788 if (spec->num_cvts >= MAX_HDMI_CVTS) {
789 snd_printk(KERN_WARNING
790 "HDMI: no space for converter %d\n", nid);
791 return -EINVAL;
792 }
793
794 spec->cvt[spec->num_cvts] = nid;
795 spec->num_cvts++;
796
797 return 0;
798}
799
800static int hdmi_parse_codec(struct hda_codec *codec)
801{
802 hda_nid_t nid;
803 int i, nodes;
804
805 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
806 if (!nid || nodes < 0) {
807 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
808 return -EINVAL;
809 }
810
811 for (i = 0; i < nodes; i++, nid++) {
812 unsigned int caps;
813 unsigned int type;
814
815 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
816 type = get_wcaps_type(caps);
817
818 if (!(caps & AC_WCAP_DIGITAL))
819 continue;
820
821 switch (type) {
822 case AC_WID_AUD_OUT:
823 if (hdmi_add_cvt(codec, nid) < 0)
824 return -EINVAL;
825 break;
826 case AC_WID_PIN:
827 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
828 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
829 continue;
830 if (hdmi_add_pin(codec, nid) < 0)
831 return -EINVAL;
832 break;
833 }
834 }
835
836 /*
837 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
838 * can be lost and presence sense verb will become inaccurate if the
839 * HDA link is powered off at hot plug or hw initialization time.
840 */
841#ifdef CONFIG_SND_HDA_POWER_SAVE
842 if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
843 AC_PWRST_EPSS))
844 codec->bus->power_keep_link_on = 1;
845#endif
846
847 return 0;
848}
849
diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
index 01a18ed475ac..88d035104cc5 100644
--- a/sound/pci/hda/patch_intelhdmi.c
+++ b/sound/pci/hda/patch_intelhdmi.c
@@ -33,605 +33,121 @@
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35 35
36static hda_nid_t cvt_nid; /* audio converter */
37static hda_nid_t pin_nid; /* HDMI output pin */
38
39#define INTEL_HDMI_EVENT_TAG 0x08
40
41struct intel_hdmi_spec {
42 struct hda_multi_out multiout;
43 struct hda_pcm pcm_rec;
44 struct hdmi_eld sink_eld;
45};
46
47struct hdmi_audio_infoframe {
48 u8 type; /* 0x84 */
49 u8 ver; /* 0x01 */
50 u8 len; /* 0x0a */
51
52 u8 checksum; /* PB0 */
53 u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
54 u8 SS01_SF24;
55 u8 CXT04;
56 u8 CA;
57 u8 LFEPBL01_LSV36_DM_INH7;
58 u8 reserved[5]; /* PB6 - PB10 */
59};
60
61/* 36/*
62 * CEA speaker placement: 37 * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
38 * could support two independent pipes, each of them can be connected to one or
39 * more ports (DVI, HDMI or DisplayPort).
63 * 40 *
64 * FLH FCH FRH 41 * The HDA correspondence of pipes/ports are converter/pin nodes.
65 * FLW FL FLC FC FRC FR FRW
66 *
67 * LFE
68 * TC
69 *
70 * RL RLC RC RRC RR
71 *
72 * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
73 * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
74 */
75enum cea_speaker_placement {
76 FL = (1 << 0), /* Front Left */
77 FC = (1 << 1), /* Front Center */
78 FR = (1 << 2), /* Front Right */
79 FLC = (1 << 3), /* Front Left Center */
80 FRC = (1 << 4), /* Front Right Center */
81 RL = (1 << 5), /* Rear Left */
82 RC = (1 << 6), /* Rear Center */
83 RR = (1 << 7), /* Rear Right */
84 RLC = (1 << 8), /* Rear Left Center */
85 RRC = (1 << 9), /* Rear Right Center */
86 LFE = (1 << 10), /* Low Frequency Effect */
87 FLW = (1 << 11), /* Front Left Wide */
88 FRW = (1 << 12), /* Front Right Wide */
89 FLH = (1 << 13), /* Front Left High */
90 FCH = (1 << 14), /* Front Center High */
91 FRH = (1 << 15), /* Front Right High */
92 TC = (1 << 16), /* Top Center */
93};
94
95/*
96 * ELD SA bits in the CEA Speaker Allocation data block
97 */ 42 */
98static int eld_speaker_allocation_bits[] = { 43#define MAX_HDMI_CVTS 2
99 [0] = FL | FR, 44#define MAX_HDMI_PINS 3
100 [1] = LFE,
101 [2] = FC,
102 [3] = RL | RR,
103 [4] = RC,
104 [5] = FLC | FRC,
105 [6] = RLC | RRC,
106 /* the following are not defined in ELD yet */
107 [7] = FLW | FRW,
108 [8] = FLH | FRH,
109 [9] = TC,
110 [10] = FCH,
111};
112 45
113struct cea_channel_speaker_allocation { 46#include "patch_hdmi.c"
114 int ca_index;
115 int speakers[8];
116 47
117 /* derived values, just for convenience */ 48static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = {
118 int channels; 49 "INTEL HDMI 0",
119 int spk_mask; 50 "INTEL HDMI 1",
120}; 51};
121 52
122/* 53/*
123 * This is an ordered list! 54 * HDMI callbacks
124 *
125 * The preceding ones have better chances to be selected by
126 * hdmi_setup_channel_allocation().
127 */
128static struct cea_channel_speaker_allocation channel_allocations[] = {
129/* channel: 8 7 6 5 4 3 2 1 */
130{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
131 /* 2.1 */
132{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
133 /* Dolby Surround */
134{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
135{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
136{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
137{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
138{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
139{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
140{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
141{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
142{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
143 /* 5.1 */
144{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
145{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
146{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
147{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
148 /* 6.1 */
149{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
150{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
151{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
152{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
153 /* 7.1 */
154{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
155{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
156{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
157{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
158{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
159{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
160{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
161{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
162{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
163{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
164{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
165{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
166{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
167{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
168{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
169{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
170{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
171{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
172{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
173{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
174{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
175{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
176{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
177{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
178{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
179{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
180{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
181{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
182{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
183{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
184{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
185};
186
187/*
188 * HDMI routines
189 */
190
191#ifdef BE_PARANOID
192static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t nid,
193 int *packet_index, int *byte_index)
194{
195 int val;
196
197 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_INDEX, 0);
198
199 *packet_index = val >> 5;
200 *byte_index = val & 0x1f;
201}
202#endif
203
204static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t nid,
205 int packet_index, int byte_index)
206{
207 int val;
208
209 val = (packet_index << 5) | (byte_index & 0x1f);
210
211 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
212}
213
214static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid,
215 unsigned char val)
216{
217 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
218}
219
220static void hdmi_enable_output(struct hda_codec *codec)
221{
222 /* Unmute */
223 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
224 snd_hda_codec_write(codec, pin_nid, 0,
225 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
226 /* Enable pin out */
227 snd_hda_codec_write(codec, pin_nid, 0,
228 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
229}
230
231/*
232 * Enable Audio InfoFrame Transmission
233 */
234static void hdmi_start_infoframe_trans(struct hda_codec *codec)
235{
236 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
237 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
238 AC_DIPXMIT_BEST);
239}
240
241/*
242 * Disable Audio InfoFrame Transmission
243 */
244static void hdmi_stop_infoframe_trans(struct hda_codec *codec)
245{
246 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
247 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
248 AC_DIPXMIT_DISABLE);
249}
250
251static int hdmi_get_channel_count(struct hda_codec *codec)
252{
253 return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
254 AC_VERB_GET_CVT_CHAN_COUNT, 0);
255}
256
257static void hdmi_set_channel_count(struct hda_codec *codec, int chs)
258{
259 snd_hda_codec_write(codec, cvt_nid, 0,
260 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
261
262 if (chs != hdmi_get_channel_count(codec))
263 snd_printd(KERN_INFO "HDMI channel count: expect %d, get %d\n",
264 chs, hdmi_get_channel_count(codec));
265}
266
267static void hdmi_debug_channel_mapping(struct hda_codec *codec)
268{
269#ifdef CONFIG_SND_DEBUG_VERBOSE
270 int i;
271 int slot;
272
273 for (i = 0; i < 8; i++) {
274 slot = snd_hda_codec_read(codec, cvt_nid, 0,
275 AC_VERB_GET_HDMI_CHAN_SLOT, i);
276 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
277 slot >> 4, slot & 0x7);
278 }
279#endif
280}
281
282static void hdmi_parse_eld(struct hda_codec *codec)
283{
284 struct intel_hdmi_spec *spec = codec->spec;
285 struct hdmi_eld *eld = &spec->sink_eld;
286
287 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
288 snd_hdmi_show_eld(eld);
289}
290
291
292/*
293 * Audio InfoFrame routines
294 */
295
296static void hdmi_debug_dip_size(struct hda_codec *codec)
297{
298#ifdef CONFIG_SND_DEBUG_VERBOSE
299 int i;
300 int size;
301
302 size = snd_hdmi_get_eld_size(codec, pin_nid);
303 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
304
305 for (i = 0; i < 8; i++) {
306 size = snd_hda_codec_read(codec, pin_nid, 0,
307 AC_VERB_GET_HDMI_DIP_SIZE, i);
308 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
309 }
310#endif
311}
312
313static void hdmi_clear_dip_buffers(struct hda_codec *codec)
314{
315#ifdef BE_PARANOID
316 int i, j;
317 int size;
318 int pi, bi;
319 for (i = 0; i < 8; i++) {
320 size = snd_hda_codec_read(codec, pin_nid, 0,
321 AC_VERB_GET_HDMI_DIP_SIZE, i);
322 if (size == 0)
323 continue;
324
325 hdmi_set_dip_index(codec, pin_nid, i, 0x0);
326 for (j = 1; j < 1000; j++) {
327 hdmi_write_dip_byte(codec, pin_nid, 0x0);
328 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
329 if (pi != i)
330 snd_printd(KERN_INFO "dip index %d: %d != %d\n",
331 bi, pi, i);
332 if (bi == 0) /* byte index wrapped around */
333 break;
334 }
335 snd_printd(KERN_INFO
336 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
337 i, size, j);
338 }
339#endif
340}
341
342static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
343 struct hdmi_audio_infoframe *ai)
344{
345 u8 *params = (u8 *)ai;
346 u8 sum = 0;
347 int i;
348
349 hdmi_debug_dip_size(codec);
350 hdmi_clear_dip_buffers(codec); /* be paranoid */
351
352 for (i = 0; i < sizeof(ai); i++)
353 sum += params[i];
354 ai->checksum = - sum;
355
356 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
357 for (i = 0; i < sizeof(ai); i++)
358 hdmi_write_dip_byte(codec, pin_nid, params[i]);
359}
360
361/*
362 * Compute derived values in channel_allocations[].
363 */
364static void init_channel_allocations(void)
365{
366 int i, j;
367 struct cea_channel_speaker_allocation *p;
368
369 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
370 p = channel_allocations + i;
371 p->channels = 0;
372 p->spk_mask = 0;
373 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
374 if (p->speakers[j]) {
375 p->channels++;
376 p->spk_mask |= p->speakers[j];
377 }
378 }
379}
380
381/*
382 * The transformation takes two steps:
383 *
384 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
385 * spk_mask => (channel_allocations[]) => ai->CA
386 *
387 * TODO: it could select the wrong CA from multiple candidates.
388*/
389static int hdmi_setup_channel_allocation(struct hda_codec *codec,
390 struct hdmi_audio_infoframe *ai)
391{
392 struct intel_hdmi_spec *spec = codec->spec;
393 struct hdmi_eld *eld = &spec->sink_eld;
394 int i;
395 int spk_mask = 0;
396 int channels = 1 + (ai->CC02_CT47 & 0x7);
397 char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
398
399 /*
400 * CA defaults to 0 for basic stereo audio
401 */
402 if (channels <= 2)
403 return 0;
404
405 /*
406 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
407 * in console or for audio devices. Assume the highest speakers
408 * configuration, to _not_ prohibit multi-channel audio playback.
409 */
410 if (!eld->spk_alloc)
411 eld->spk_alloc = 0xffff;
412
413 /*
414 * expand ELD's speaker allocation mask
415 *
416 * ELD tells the speaker mask in a compact(paired) form,
417 * expand ELD's notions to match the ones used by Audio InfoFrame.
418 */
419 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
420 if (eld->spk_alloc & (1 << i))
421 spk_mask |= eld_speaker_allocation_bits[i];
422 }
423
424 /* search for the first working match in the CA table */
425 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
426 if (channels == channel_allocations[i].channels &&
427 (spk_mask & channel_allocations[i].spk_mask) ==
428 channel_allocations[i].spk_mask) {
429 ai->CA = channel_allocations[i].ca_index;
430 break;
431 }
432 }
433
434 snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
435 snd_printdd(KERN_INFO
436 "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
437 ai->CA, channels, buf);
438
439 return ai->CA;
440}
441
442static void hdmi_setup_channel_mapping(struct hda_codec *codec,
443 struct hdmi_audio_infoframe *ai)
444{
445 int i;
446
447 if (!ai->CA)
448 return;
449
450 /*
451 * TODO: adjust channel mapping if necessary
452 * ALSA sequence is front/surr/clfe/side?
453 */
454
455 for (i = 0; i < 8; i++)
456 snd_hda_codec_write(codec, cvt_nid, 0,
457 AC_VERB_SET_HDMI_CHAN_SLOT,
458 (i << 4) | i);
459
460 hdmi_debug_channel_mapping(codec);
461}
462
463
464static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
465 struct snd_pcm_substream *substream)
466{
467 struct hdmi_audio_infoframe ai = {
468 .type = 0x84,
469 .ver = 0x01,
470 .len = 0x0a,
471 .CC02_CT47 = substream->runtime->channels - 1,
472 };
473
474 hdmi_setup_channel_allocation(codec, &ai);
475 hdmi_setup_channel_mapping(codec, &ai);
476
477 hdmi_fill_audio_infoframe(codec, &ai);
478 hdmi_start_infoframe_trans(codec);
479}
480
481
482/*
483 * Unsolicited events
484 */
485
486static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
487{
488 int pind = !!(res & AC_UNSOL_RES_PD);
489 int eldv = !!(res & AC_UNSOL_RES_ELDV);
490
491 printk(KERN_INFO
492 "HDMI hot plug event: Presence_Detect=%d ELD_Valid=%d\n",
493 pind, eldv);
494
495 if (pind && eldv) {
496 hdmi_parse_eld(codec);
497 /* TODO: do real things about ELD */
498 }
499}
500
501static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
502{
503 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
504 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
505 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
506
507 printk(KERN_INFO
508 "HDMI content protection event: SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
509 subtag,
510 cp_state,
511 cp_ready);
512
513 /* TODO */
514 if (cp_state)
515 ;
516 if (cp_ready)
517 ;
518}
519
520
521static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
522{
523 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
524 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
525
526 if (tag != INTEL_HDMI_EVENT_TAG) {
527 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
528 return;
529 }
530
531 if (subtag == 0)
532 hdmi_intrinsic_event(codec, res);
533 else
534 hdmi_non_intrinsic_event(codec, res);
535}
536
537/*
538 * Callbacks
539 */ 55 */
540 56
541static int intel_hdmi_playback_pcm_open(struct hda_pcm_stream *hinfo,
542 struct hda_codec *codec,
543 struct snd_pcm_substream *substream)
544{
545 struct intel_hdmi_spec *spec = codec->spec;
546
547 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
548}
549
550static int intel_hdmi_playback_pcm_close(struct hda_pcm_stream *hinfo,
551 struct hda_codec *codec,
552 struct snd_pcm_substream *substream)
553{
554 struct intel_hdmi_spec *spec = codec->spec;
555
556 hdmi_stop_infoframe_trans(codec);
557
558 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
559}
560
561static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 57static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
562 struct hda_codec *codec, 58 struct hda_codec *codec,
563 unsigned int stream_tag, 59 unsigned int stream_tag,
564 unsigned int format, 60 unsigned int format,
565 struct snd_pcm_substream *substream) 61 struct snd_pcm_substream *substream)
566{ 62{
567 struct intel_hdmi_spec *spec = codec->spec; 63 hdmi_set_channel_count(codec, hinfo->nid,
64 substream->runtime->channels);
568 65
569 snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, 66 hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
570 format, substream);
571 67
572 hdmi_set_channel_count(codec, substream->runtime->channels); 68 hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
573 69 return 0;
574 hdmi_setup_audio_infoframe(codec, substream); 70}
575 71
72static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
73 struct hda_codec *codec,
74 struct snd_pcm_substream *substream)
75{
576 return 0; 76 return 0;
577} 77}
578 78
579static struct hda_pcm_stream intel_hdmi_pcm_playback = { 79static struct hda_pcm_stream intel_hdmi_pcm_playback = {
580 .substreams = 1, 80 .substreams = 1,
581 .channels_min = 2, 81 .channels_min = 2,
582 .channels_max = 8,
583 .ops = { 82 .ops = {
584 .open = intel_hdmi_playback_pcm_open, 83 .prepare = intel_hdmi_playback_pcm_prepare,
585 .close = intel_hdmi_playback_pcm_close, 84 .cleanup = intel_hdmi_playback_pcm_cleanup,
586 .prepare = intel_hdmi_playback_pcm_prepare
587 }, 85 },
588}; 86};
589 87
590static int intel_hdmi_build_pcms(struct hda_codec *codec) 88static int intel_hdmi_build_pcms(struct hda_codec *codec)
591{ 89{
592 struct intel_hdmi_spec *spec = codec->spec; 90 struct hdmi_spec *spec = codec->spec;
593 struct hda_pcm *info = &spec->pcm_rec; 91 struct hda_pcm *info = spec->pcm_rec;
92 int i;
594 93
595 codec->num_pcms = 1; 94 codec->num_pcms = spec->num_cvts;
596 codec->pcm_info = info; 95 codec->pcm_info = info;
597 96
598 /* NID to query formats and rates and setup streams */ 97 for (i = 0; i < codec->num_pcms; i++, info++) {
599 intel_hdmi_pcm_playback.nid = cvt_nid; 98 unsigned int chans;
99
100 chans = get_wcaps(codec, spec->cvt[i]);
101 chans = get_wcaps_channels(chans);
600 102
601 info->name = "INTEL HDMI"; 103 info->name = intel_hdmi_pcm_names[i];
602 info->pcm_type = HDA_PCM_TYPE_HDMI; 104 info->pcm_type = HDA_PCM_TYPE_HDMI;
603 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback; 105 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
106 intel_hdmi_pcm_playback;
107 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
108 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
109 }
604 110
605 return 0; 111 return 0;
606} 112}
607 113
608static int intel_hdmi_build_controls(struct hda_codec *codec) 114static int intel_hdmi_build_controls(struct hda_codec *codec)
609{ 115{
610 struct intel_hdmi_spec *spec = codec->spec; 116 struct hdmi_spec *spec = codec->spec;
611 int err; 117 int err;
118 int i;
612 119
613 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 120 for (i = 0; i < codec->num_pcms; i++) {
614 if (err < 0) 121 err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
615 return err; 122 if (err < 0)
123 return err;
124 }
616 125
617 return 0; 126 return 0;
618} 127}
619 128
620static int intel_hdmi_init(struct hda_codec *codec) 129static int intel_hdmi_init(struct hda_codec *codec)
621{ 130{
622 hdmi_enable_output(codec); 131 struct hdmi_spec *spec = codec->spec;
132 int i;
623 133
624 snd_hda_codec_write(codec, pin_nid, 0, 134 for (i = 0; spec->pin[i]; i++) {
625 AC_VERB_SET_UNSOLICITED_ENABLE, 135 hdmi_enable_output(codec, spec->pin[i]);
626 AC_USRSP_EN | INTEL_HDMI_EVENT_TAG); 136 snd_hda_codec_write(codec, spec->pin[i], 0,
137 AC_VERB_SET_UNSOLICITED_ENABLE,
138 AC_USRSP_EN | spec->pin[i]);
139 }
627 return 0; 140 return 0;
628} 141}
629 142
630static void intel_hdmi_free(struct hda_codec *codec) 143static void intel_hdmi_free(struct hda_codec *codec)
631{ 144{
632 struct intel_hdmi_spec *spec = codec->spec; 145 struct hdmi_spec *spec = codec->spec;
146 int i;
147
148 for (i = 0; i < spec->num_pins; i++)
149 snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
633 150
634 snd_hda_eld_proc_free(codec, &spec->sink_eld);
635 kfree(spec); 151 kfree(spec);
636} 152}
637 153
@@ -640,52 +156,41 @@ static struct hda_codec_ops intel_hdmi_patch_ops = {
640 .free = intel_hdmi_free, 156 .free = intel_hdmi_free,
641 .build_pcms = intel_hdmi_build_pcms, 157 .build_pcms = intel_hdmi_build_pcms,
642 .build_controls = intel_hdmi_build_controls, 158 .build_controls = intel_hdmi_build_controls,
643 .unsol_event = intel_hdmi_unsol_event, 159 .unsol_event = hdmi_unsol_event,
644}; 160};
645 161
646static int do_patch_intel_hdmi(struct hda_codec *codec) 162static int patch_intel_hdmi(struct hda_codec *codec)
647{ 163{
648 struct intel_hdmi_spec *spec; 164 struct hdmi_spec *spec;
165 int i;
649 166
650 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 167 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
651 if (spec == NULL) 168 if (spec == NULL)
652 return -ENOMEM; 169 return -ENOMEM;
653 170
654 spec->multiout.num_dacs = 0; /* no analog */
655 spec->multiout.max_channels = 8;
656 spec->multiout.dig_out_nid = cvt_nid;
657
658 codec->spec = spec; 171 codec->spec = spec;
172 if (hdmi_parse_codec(codec) < 0) {
173 codec->spec = NULL;
174 kfree(spec);
175 return -EINVAL;
176 }
659 codec->patch_ops = intel_hdmi_patch_ops; 177 codec->patch_ops = intel_hdmi_patch_ops;
660 178
661 snd_hda_eld_proc_new(codec, &spec->sink_eld); 179 for (i = 0; i < spec->num_pins; i++)
180 snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
662 181
663 init_channel_allocations(); 182 init_channel_allocations();
664 183
665 return 0; 184 return 0;
666} 185}
667 186
668static int patch_intel_hdmi(struct hda_codec *codec)
669{
670 cvt_nid = 0x02;
671 pin_nid = 0x03;
672 return do_patch_intel_hdmi(codec);
673}
674
675static int patch_intel_hdmi_ibexpeak(struct hda_codec *codec)
676{
677 cvt_nid = 0x02;
678 pin_nid = 0x04;
679 return do_patch_intel_hdmi(codec);
680}
681
682static struct hda_codec_preset snd_hda_preset_intelhdmi[] = { 187static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
683 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi }, 188 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi },
684 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi }, 189 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
685 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi }, 190 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
686 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi }, 191 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
687 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi }, 192 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi },
688 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi_ibexpeak }, 193 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi },
689 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi }, 194 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
690 {} /* terminator */ 195 {} /* terminator */
691}; 196};
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
index 6afdab09bab7..3c10c0b149f4 100644
--- a/sound/pci/hda/patch_nvhdmi.c
+++ b/sound/pci/hda/patch_nvhdmi.c
@@ -29,13 +29,23 @@
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31 31
32#define MAX_HDMI_CVTS 1
33#define MAX_HDMI_PINS 1
34
35#include "patch_hdmi.c"
36
37static char *nvhdmi_pcm_names[MAX_HDMI_CVTS] = {
38 "NVIDIA HDMI",
39};
40
32/* define below to restrict the supported rates and formats */ 41/* define below to restrict the supported rates and formats */
33/* #define LIMITED_RATE_FMT_SUPPORT */ 42/* #define LIMITED_RATE_FMT_SUPPORT */
34 43
35struct nvhdmi_spec { 44enum HDACodec {
36 struct hda_multi_out multiout; 45 HDA_CODEC_NVIDIA_MCP7X,
37 46 HDA_CODEC_NVIDIA_MCP89,
38 struct hda_pcm pcm_rec; 47 HDA_CODEC_NVIDIA_GT21X,
48 HDA_CODEC_INVALID
39}; 49};
40 50
41#define Nv_VERB_SET_Channel_Allocation 0xF79 51#define Nv_VERB_SET_Channel_Allocation 0xF79
@@ -43,15 +53,18 @@ struct nvhdmi_spec {
43#define Nv_VERB_SET_Audio_Protection_On 0xF98 53#define Nv_VERB_SET_Audio_Protection_On 0xF98
44#define Nv_VERB_SET_Audio_Protection_Off 0xF99 54#define Nv_VERB_SET_Audio_Protection_Off 0xF99
45 55
46#define Nv_Master_Convert_nid 0x04 56#define nvhdmi_master_con_nid_7x 0x04
47#define Nv_Master_Pin_nid 0x05 57#define nvhdmi_master_pin_nid_7x 0x05
48 58
49static hda_nid_t nvhdmi_convert_nids[4] = { 59#define nvhdmi_master_con_nid_89 0x04
60#define nvhdmi_master_pin_nid_89 0x05
61
62static hda_nid_t nvhdmi_con_nids_7x[4] = {
50 /*front, rear, clfe, rear_surr */ 63 /*front, rear, clfe, rear_surr */
51 0x6, 0x8, 0xa, 0xc, 64 0x6, 0x8, 0xa, 0xc,
52}; 65};
53 66
54static struct hda_verb nvhdmi_basic_init[] = { 67static struct hda_verb nvhdmi_basic_init_7x[] = {
55 /* set audio protect on */ 68 /* set audio protect on */
56 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, 69 { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
57 /* enable digital output on pin widget */ 70 /* enable digital output on pin widget */
@@ -84,22 +97,60 @@ static struct hda_verb nvhdmi_basic_init[] = {
84 */ 97 */
85static int nvhdmi_build_controls(struct hda_codec *codec) 98static int nvhdmi_build_controls(struct hda_codec *codec)
86{ 99{
87 struct nvhdmi_spec *spec = codec->spec; 100 struct hdmi_spec *spec = codec->spec;
88 int err; 101 int err;
102 int i;
89 103
90 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 104 if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
91 if (err < 0) 105 || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X)) {
92 return err; 106 for (i = 0; i < codec->num_pcms; i++) {
107 err = snd_hda_create_spdif_out_ctls(codec,
108 spec->cvt[i]);
109 if (err < 0)
110 return err;
111 }
112 } else {
113 err = snd_hda_create_spdif_out_ctls(codec,
114 spec->multiout.dig_out_nid);
115 if (err < 0)
116 return err;
117 }
93 118
94 return 0; 119 return 0;
95} 120}
96 121
97static int nvhdmi_init(struct hda_codec *codec) 122static int nvhdmi_init(struct hda_codec *codec)
98{ 123{
99 snd_hda_sequence_write(codec, nvhdmi_basic_init); 124 struct hdmi_spec *spec = codec->spec;
125 int i;
126 if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
127 || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X)) {
128 for (i = 0; spec->pin[i]; i++) {
129 hdmi_enable_output(codec, spec->pin[i]);
130 snd_hda_codec_write(codec, spec->pin[i], 0,
131 AC_VERB_SET_UNSOLICITED_ENABLE,
132 AC_USRSP_EN | spec->pin[i]);
133 }
134 } else {
135 snd_hda_sequence_write(codec, nvhdmi_basic_init_7x);
136 }
100 return 0; 137 return 0;
101} 138}
102 139
140static void nvhdmi_free(struct hda_codec *codec)
141{
142 struct hdmi_spec *spec = codec->spec;
143 int i;
144
145 if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
146 || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X)) {
147 for (i = 0; i < spec->num_pins; i++)
148 snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
149 }
150
151 kfree(spec);
152}
153
103/* 154/*
104 * Digital out 155 * Digital out
105 */ 156 */
@@ -107,25 +158,25 @@ static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
107 struct hda_codec *codec, 158 struct hda_codec *codec,
108 struct snd_pcm_substream *substream) 159 struct snd_pcm_substream *substream)
109{ 160{
110 struct nvhdmi_spec *spec = codec->spec; 161 struct hdmi_spec *spec = codec->spec;
111 return snd_hda_multi_out_dig_open(codec, &spec->multiout); 162 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
112} 163}
113 164
114static int nvhdmi_dig_playback_pcm_close_8ch(struct hda_pcm_stream *hinfo, 165static int nvhdmi_dig_playback_pcm_close_8ch_7x(struct hda_pcm_stream *hinfo,
115 struct hda_codec *codec, 166 struct hda_codec *codec,
116 struct snd_pcm_substream *substream) 167 struct snd_pcm_substream *substream)
117{ 168{
118 struct nvhdmi_spec *spec = codec->spec; 169 struct hdmi_spec *spec = codec->spec;
119 int i; 170 int i;
120 171
121 snd_hda_codec_write(codec, Nv_Master_Convert_nid, 172 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
122 0, AC_VERB_SET_CHANNEL_STREAMID, 0); 173 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
123 for (i = 0; i < 4; i++) { 174 for (i = 0; i < 4; i++) {
124 /* set the stream id */ 175 /* set the stream id */
125 snd_hda_codec_write(codec, nvhdmi_convert_nids[i], 0, 176 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
126 AC_VERB_SET_CHANNEL_STREAMID, 0); 177 AC_VERB_SET_CHANNEL_STREAMID, 0);
127 /* set the stream format */ 178 /* set the stream format */
128 snd_hda_codec_write(codec, nvhdmi_convert_nids[i], 0, 179 snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
129 AC_VERB_SET_STREAM_FORMAT, 0); 180 AC_VERB_SET_STREAM_FORMAT, 0);
130 } 181 }
131 182
@@ -136,10 +187,25 @@ static int nvhdmi_dig_playback_pcm_close_2ch(struct hda_pcm_stream *hinfo,
136 struct hda_codec *codec, 187 struct hda_codec *codec,
137 struct snd_pcm_substream *substream) 188 struct snd_pcm_substream *substream)
138{ 189{
139 struct nvhdmi_spec *spec = codec->spec; 190 struct hdmi_spec *spec = codec->spec;
140 return snd_hda_multi_out_dig_close(codec, &spec->multiout); 191 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
141} 192}
142 193
194static int nvhdmi_dig_playback_pcm_prepare_8ch_89(struct hda_pcm_stream *hinfo,
195 struct hda_codec *codec,
196 unsigned int stream_tag,
197 unsigned int format,
198 struct snd_pcm_substream *substream)
199{
200 hdmi_set_channel_count(codec, hinfo->nid,
201 substream->runtime->channels);
202
203 hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
204
205 hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
206 return 0;
207}
208
143static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo, 209static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo,
144 struct hda_codec *codec, 210 struct hda_codec *codec,
145 unsigned int stream_tag, 211 unsigned int stream_tag,
@@ -181,29 +247,29 @@ static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo,
181 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ 247 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
182 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) 248 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
183 snd_hda_codec_write(codec, 249 snd_hda_codec_write(codec,
184 Nv_Master_Convert_nid, 250 nvhdmi_master_con_nid_7x,
185 0, 251 0,
186 AC_VERB_SET_DIGI_CONVERT_1, 252 AC_VERB_SET_DIGI_CONVERT_1,
187 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff); 253 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
188 254
189 /* set the stream id */ 255 /* set the stream id */
190 snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, 256 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
191 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0); 257 AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
192 258
193 /* set the stream format */ 259 /* set the stream format */
194 snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, 260 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
195 AC_VERB_SET_STREAM_FORMAT, format); 261 AC_VERB_SET_STREAM_FORMAT, format);
196 262
197 /* turn on again (if needed) */ 263 /* turn on again (if needed) */
198 /* enable and set the channel status audio/data flag */ 264 /* enable and set the channel status audio/data flag */
199 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) { 265 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) {
200 snd_hda_codec_write(codec, 266 snd_hda_codec_write(codec,
201 Nv_Master_Convert_nid, 267 nvhdmi_master_con_nid_7x,
202 0, 268 0,
203 AC_VERB_SET_DIGI_CONVERT_1, 269 AC_VERB_SET_DIGI_CONVERT_1,
204 codec->spdif_ctls & 0xff); 270 codec->spdif_ctls & 0xff);
205 snd_hda_codec_write(codec, 271 snd_hda_codec_write(codec,
206 Nv_Master_Convert_nid, 272 nvhdmi_master_con_nid_7x,
207 0, 273 0,
208 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); 274 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
209 } 275 }
@@ -220,19 +286,19 @@ static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo,
220 if (codec->spdif_status_reset && 286 if (codec->spdif_status_reset &&
221 (codec->spdif_ctls & AC_DIG1_ENABLE)) 287 (codec->spdif_ctls & AC_DIG1_ENABLE))
222 snd_hda_codec_write(codec, 288 snd_hda_codec_write(codec,
223 nvhdmi_convert_nids[i], 289 nvhdmi_con_nids_7x[i],
224 0, 290 0,
225 AC_VERB_SET_DIGI_CONVERT_1, 291 AC_VERB_SET_DIGI_CONVERT_1,
226 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff); 292 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
227 /* set the stream id */ 293 /* set the stream id */
228 snd_hda_codec_write(codec, 294 snd_hda_codec_write(codec,
229 nvhdmi_convert_nids[i], 295 nvhdmi_con_nids_7x[i],
230 0, 296 0,
231 AC_VERB_SET_CHANNEL_STREAMID, 297 AC_VERB_SET_CHANNEL_STREAMID,
232 (stream_tag << 4) | channel_id); 298 (stream_tag << 4) | channel_id);
233 /* set the stream format */ 299 /* set the stream format */
234 snd_hda_codec_write(codec, 300 snd_hda_codec_write(codec,
235 nvhdmi_convert_nids[i], 301 nvhdmi_con_nids_7x[i],
236 0, 302 0,
237 AC_VERB_SET_STREAM_FORMAT, 303 AC_VERB_SET_STREAM_FORMAT,
238 format); 304 format);
@@ -241,12 +307,12 @@ static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo,
241 if (codec->spdif_status_reset && 307 if (codec->spdif_status_reset &&
242 (codec->spdif_ctls & AC_DIG1_ENABLE)) { 308 (codec->spdif_ctls & AC_DIG1_ENABLE)) {
243 snd_hda_codec_write(codec, 309 snd_hda_codec_write(codec,
244 nvhdmi_convert_nids[i], 310 nvhdmi_con_nids_7x[i],
245 0, 311 0,
246 AC_VERB_SET_DIGI_CONVERT_1, 312 AC_VERB_SET_DIGI_CONVERT_1,
247 codec->spdif_ctls & 0xff); 313 codec->spdif_ctls & 0xff);
248 snd_hda_codec_write(codec, 314 snd_hda_codec_write(codec,
249 nvhdmi_convert_nids[i], 315 nvhdmi_con_nids_7x[i],
250 0, 316 0,
251 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); 317 AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
252 } 318 }
@@ -261,28 +327,47 @@ static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo,
261 return 0; 327 return 0;
262} 328}
263 329
330static int nvhdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
331 struct hda_codec *codec,
332 struct snd_pcm_substream *substream)
333{
334 return 0;
335}
336
264static int nvhdmi_dig_playback_pcm_prepare_2ch(struct hda_pcm_stream *hinfo, 337static int nvhdmi_dig_playback_pcm_prepare_2ch(struct hda_pcm_stream *hinfo,
265 struct hda_codec *codec, 338 struct hda_codec *codec,
266 unsigned int stream_tag, 339 unsigned int stream_tag,
267 unsigned int format, 340 unsigned int format,
268 struct snd_pcm_substream *substream) 341 struct snd_pcm_substream *substream)
269{ 342{
270 struct nvhdmi_spec *spec = codec->spec; 343 struct hdmi_spec *spec = codec->spec;
271 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, 344 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
272 format, substream); 345 format, substream);
273} 346}
274 347
275static struct hda_pcm_stream nvhdmi_pcm_digital_playback_8ch = { 348static struct hda_pcm_stream nvhdmi_pcm_digital_playback_8ch_89 = {
349 .substreams = 1,
350 .channels_min = 2,
351 .rates = SUPPORTED_RATES,
352 .maxbps = SUPPORTED_MAXBPS,
353 .formats = SUPPORTED_FORMATS,
354 .ops = {
355 .prepare = nvhdmi_dig_playback_pcm_prepare_8ch_89,
356 .cleanup = nvhdmi_playback_pcm_cleanup,
357 },
358};
359
360static struct hda_pcm_stream nvhdmi_pcm_digital_playback_8ch_7x = {
276 .substreams = 1, 361 .substreams = 1,
277 .channels_min = 2, 362 .channels_min = 2,
278 .channels_max = 8, 363 .channels_max = 8,
279 .nid = Nv_Master_Convert_nid, 364 .nid = nvhdmi_master_con_nid_7x,
280 .rates = SUPPORTED_RATES, 365 .rates = SUPPORTED_RATES,
281 .maxbps = SUPPORTED_MAXBPS, 366 .maxbps = SUPPORTED_MAXBPS,
282 .formats = SUPPORTED_FORMATS, 367 .formats = SUPPORTED_FORMATS,
283 .ops = { 368 .ops = {
284 .open = nvhdmi_dig_playback_pcm_open, 369 .open = nvhdmi_dig_playback_pcm_open,
285 .close = nvhdmi_dig_playback_pcm_close_8ch, 370 .close = nvhdmi_dig_playback_pcm_close_8ch_7x,
286 .prepare = nvhdmi_dig_playback_pcm_prepare_8ch 371 .prepare = nvhdmi_dig_playback_pcm_prepare_8ch
287 }, 372 },
288}; 373};
@@ -291,7 +376,7 @@ static struct hda_pcm_stream nvhdmi_pcm_digital_playback_2ch = {
291 .substreams = 1, 376 .substreams = 1,
292 .channels_min = 2, 377 .channels_min = 2,
293 .channels_max = 2, 378 .channels_max = 2,
294 .nid = Nv_Master_Convert_nid, 379 .nid = nvhdmi_master_con_nid_7x,
295 .rates = SUPPORTED_RATES, 380 .rates = SUPPORTED_RATES,
296 .maxbps = SUPPORTED_MAXBPS, 381 .maxbps = SUPPORTED_MAXBPS,
297 .formats = SUPPORTED_FORMATS, 382 .formats = SUPPORTED_FORMATS,
@@ -302,10 +387,36 @@ static struct hda_pcm_stream nvhdmi_pcm_digital_playback_2ch = {
302 }, 387 },
303}; 388};
304 389
305static int nvhdmi_build_pcms_8ch(struct hda_codec *codec) 390static int nvhdmi_build_pcms_8ch_89(struct hda_codec *codec)
391{
392 struct hdmi_spec *spec = codec->spec;
393 struct hda_pcm *info = spec->pcm_rec;
394 int i;
395
396 codec->num_pcms = spec->num_cvts;
397 codec->pcm_info = info;
398
399 for (i = 0; i < codec->num_pcms; i++, info++) {
400 unsigned int chans;
401
402 chans = get_wcaps(codec, spec->cvt[i]);
403 chans = get_wcaps_channels(chans);
404
405 info->name = nvhdmi_pcm_names[i];
406 info->pcm_type = HDA_PCM_TYPE_HDMI;
407 info->stream[SNDRV_PCM_STREAM_PLAYBACK]
408 = nvhdmi_pcm_digital_playback_8ch_89;
409 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
410 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
411 }
412
413 return 0;
414}
415
416static int nvhdmi_build_pcms_8ch_7x(struct hda_codec *codec)
306{ 417{
307 struct nvhdmi_spec *spec = codec->spec; 418 struct hdmi_spec *spec = codec->spec;
308 struct hda_pcm *info = &spec->pcm_rec; 419 struct hda_pcm *info = spec->pcm_rec;
309 420
310 codec->num_pcms = 1; 421 codec->num_pcms = 1;
311 codec->pcm_info = info; 422 codec->pcm_info = info;
@@ -313,15 +424,15 @@ static int nvhdmi_build_pcms_8ch(struct hda_codec *codec)
313 info->name = "NVIDIA HDMI"; 424 info->name = "NVIDIA HDMI";
314 info->pcm_type = HDA_PCM_TYPE_HDMI; 425 info->pcm_type = HDA_PCM_TYPE_HDMI;
315 info->stream[SNDRV_PCM_STREAM_PLAYBACK] 426 info->stream[SNDRV_PCM_STREAM_PLAYBACK]
316 = nvhdmi_pcm_digital_playback_8ch; 427 = nvhdmi_pcm_digital_playback_8ch_7x;
317 428
318 return 0; 429 return 0;
319} 430}
320 431
321static int nvhdmi_build_pcms_2ch(struct hda_codec *codec) 432static int nvhdmi_build_pcms_2ch(struct hda_codec *codec)
322{ 433{
323 struct nvhdmi_spec *spec = codec->spec; 434 struct hdmi_spec *spec = codec->spec;
324 struct hda_pcm *info = &spec->pcm_rec; 435 struct hda_pcm *info = spec->pcm_rec;
325 436
326 codec->num_pcms = 1; 437 codec->num_pcms = 1;
327 codec->pcm_info = info; 438 codec->pcm_info = info;
@@ -334,14 +445,17 @@ static int nvhdmi_build_pcms_2ch(struct hda_codec *codec)
334 return 0; 445 return 0;
335} 446}
336 447
337static void nvhdmi_free(struct hda_codec *codec) 448static struct hda_codec_ops nvhdmi_patch_ops_8ch_89 = {
338{ 449 .build_controls = nvhdmi_build_controls,
339 kfree(codec->spec); 450 .build_pcms = nvhdmi_build_pcms_8ch_89,
340} 451 .init = nvhdmi_init,
452 .free = nvhdmi_free,
453 .unsol_event = hdmi_unsol_event,
454};
341 455
342static struct hda_codec_ops nvhdmi_patch_ops_8ch = { 456static struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
343 .build_controls = nvhdmi_build_controls, 457 .build_controls = nvhdmi_build_controls,
344 .build_pcms = nvhdmi_build_pcms_8ch, 458 .build_pcms = nvhdmi_build_pcms_8ch_7x,
345 .init = nvhdmi_init, 459 .init = nvhdmi_init,
346 .free = nvhdmi_free, 460 .free = nvhdmi_free,
347}; 461};
@@ -353,9 +467,36 @@ static struct hda_codec_ops nvhdmi_patch_ops_2ch = {
353 .free = nvhdmi_free, 467 .free = nvhdmi_free,
354}; 468};
355 469
356static int patch_nvhdmi_8ch(struct hda_codec *codec) 470static int patch_nvhdmi_8ch_89(struct hda_codec *codec)
471{
472 struct hdmi_spec *spec;
473 int i;
474
475 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
476 if (spec == NULL)
477 return -ENOMEM;
478
479 codec->spec = spec;
480 spec->codec_type = HDA_CODEC_NVIDIA_MCP89;
481
482 if (hdmi_parse_codec(codec) < 0) {
483 codec->spec = NULL;
484 kfree(spec);
485 return -EINVAL;
486 }
487 codec->patch_ops = nvhdmi_patch_ops_8ch_89;
488
489 for (i = 0; i < spec->num_pins; i++)
490 snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
491
492 init_channel_allocations();
493
494 return 0;
495}
496
497static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
357{ 498{
358 struct nvhdmi_spec *spec; 499 struct hdmi_spec *spec;
359 500
360 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 501 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
361 if (spec == NULL) 502 if (spec == NULL)
@@ -365,16 +506,17 @@ static int patch_nvhdmi_8ch(struct hda_codec *codec)
365 506
366 spec->multiout.num_dacs = 0; /* no analog */ 507 spec->multiout.num_dacs = 0; /* no analog */
367 spec->multiout.max_channels = 8; 508 spec->multiout.max_channels = 8;
368 spec->multiout.dig_out_nid = Nv_Master_Convert_nid; 509 spec->multiout.dig_out_nid = nvhdmi_master_con_nid_7x;
510 spec->codec_type = HDA_CODEC_NVIDIA_MCP7X;
369 511
370 codec->patch_ops = nvhdmi_patch_ops_8ch; 512 codec->patch_ops = nvhdmi_patch_ops_8ch_7x;
371 513
372 return 0; 514 return 0;
373} 515}
374 516
375static int patch_nvhdmi_2ch(struct hda_codec *codec) 517static int patch_nvhdmi_2ch(struct hda_codec *codec)
376{ 518{
377 struct nvhdmi_spec *spec; 519 struct hdmi_spec *spec;
378 520
379 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 521 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
380 if (spec == NULL) 522 if (spec == NULL)
@@ -384,7 +526,8 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
384 526
385 spec->multiout.num_dacs = 0; /* no analog */ 527 spec->multiout.num_dacs = 0; /* no analog */
386 spec->multiout.max_channels = 2; 528 spec->multiout.max_channels = 2;
387 spec->multiout.dig_out_nid = Nv_Master_Convert_nid; 529 spec->multiout.dig_out_nid = nvhdmi_master_con_nid_7x;
530 spec->codec_type = HDA_CODEC_NVIDIA_MCP7X;
388 531
389 codec->patch_ops = nvhdmi_patch_ops_2ch; 532 codec->patch_ops = nvhdmi_patch_ops_2ch;
390 533
@@ -395,11 +538,24 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
395 * patch entries 538 * patch entries
396 */ 539 */
397static struct hda_codec_preset snd_hda_preset_nvhdmi[] = { 540static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
398 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 541 { .id = 0x10de0002, .name = "MCP77/78 HDMI",
399 { .id = 0x10de0003, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 542 .patch = patch_nvhdmi_8ch_7x },
400 { .id = 0x10de0005, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 543 { .id = 0x10de0003, .name = "MCP77/78 HDMI",
401 { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 544 .patch = patch_nvhdmi_8ch_7x },
402 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi_8ch }, 545 { .id = 0x10de0005, .name = "MCP77/78 HDMI",
546 .patch = patch_nvhdmi_8ch_7x },
547 { .id = 0x10de0006, .name = "MCP77/78 HDMI",
548 .patch = patch_nvhdmi_8ch_7x },
549 { .id = 0x10de0007, .name = "MCP79/7A HDMI",
550 .patch = patch_nvhdmi_8ch_7x },
551 { .id = 0x10de000a, .name = "GT220 HDMI",
552 .patch = patch_nvhdmi_8ch_89 },
553 { .id = 0x10de000b, .name = "GT21x HDMI",
554 .patch = patch_nvhdmi_8ch_89 },
555 { .id = 0x10de000c, .name = "MCP89 HDMI",
556 .patch = patch_nvhdmi_8ch_89 },
557 { .id = 0x10de000d, .name = "GT240 HDMI",
558 .patch = patch_nvhdmi_8ch_89 },
403 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, 559 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
404 { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, 560 { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
405 {} /* terminator */ 561 {} /* terminator */
@@ -410,11 +566,15 @@ MODULE_ALIAS("snd-hda-codec-id:10de0003");
410MODULE_ALIAS("snd-hda-codec-id:10de0005"); 566MODULE_ALIAS("snd-hda-codec-id:10de0005");
411MODULE_ALIAS("snd-hda-codec-id:10de0006"); 567MODULE_ALIAS("snd-hda-codec-id:10de0006");
412MODULE_ALIAS("snd-hda-codec-id:10de0007"); 568MODULE_ALIAS("snd-hda-codec-id:10de0007");
569MODULE_ALIAS("snd-hda-codec-id:10de000a");
570MODULE_ALIAS("snd-hda-codec-id:10de000b");
571MODULE_ALIAS("snd-hda-codec-id:10de000c");
572MODULE_ALIAS("snd-hda-codec-id:10de000d");
413MODULE_ALIAS("snd-hda-codec-id:10de0067"); 573MODULE_ALIAS("snd-hda-codec-id:10de0067");
414MODULE_ALIAS("snd-hda-codec-id:10de8001"); 574MODULE_ALIAS("snd-hda-codec-id:10de8001");
415 575
416MODULE_LICENSE("GPL"); 576MODULE_LICENSE("GPL");
417MODULE_DESCRIPTION("Nvidia HDMI HD-audio codec"); 577MODULE_DESCRIPTION("NVIDIA HDMI HD-audio codec");
418 578
419static struct hda_codec_preset_list nvhdmi_list = { 579static struct hda_codec_preset_list nvhdmi_list = {
420 .preset = snd_hda_preset_nvhdmi, 580 .preset = snd_hda_preset_nvhdmi,
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 70583719282b..886d8e46bb37 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -131,8 +131,10 @@ enum {
131enum { 131enum {
132 ALC269_BASIC, 132 ALC269_BASIC,
133 ALC269_QUANTA_FL1, 133 ALC269_QUANTA_FL1,
134 ALC269_ASUS_EEEPC_P703, 134 ALC269_AMIC,
135 ALC269_ASUS_EEEPC_P901, 135 ALC269_DMIC,
136 ALC269VB_AMIC,
137 ALC269VB_DMIC,
136 ALC269_FUJITSU, 138 ALC269_FUJITSU,
137 ALC269_LIFEBOOK, 139 ALC269_LIFEBOOK,
138 ALC269_AUTO, 140 ALC269_AUTO,
@@ -188,6 +190,8 @@ enum {
188 ALC663_ASUS_MODE4, 190 ALC663_ASUS_MODE4,
189 ALC663_ASUS_MODE5, 191 ALC663_ASUS_MODE5,
190 ALC663_ASUS_MODE6, 192 ALC663_ASUS_MODE6,
193 ALC663_ASUS_MODE7,
194 ALC663_ASUS_MODE8,
191 ALC272_DELL, 195 ALC272_DELL,
192 ALC272_DELL_ZM1, 196 ALC272_DELL_ZM1,
193 ALC272_SAMSUNG_NC10, 197 ALC272_SAMSUNG_NC10,
@@ -205,9 +209,12 @@ enum {
205 ALC882_ASUS_A7J, 209 ALC882_ASUS_A7J,
206 ALC882_ASUS_A7M, 210 ALC882_ASUS_A7M,
207 ALC885_MACPRO, 211 ALC885_MACPRO,
212 ALC885_MBA21,
208 ALC885_MBP3, 213 ALC885_MBP3,
209 ALC885_MB5, 214 ALC885_MB5,
215 ALC885_MACMINI3,
210 ALC885_IMAC24, 216 ALC885_IMAC24,
217 ALC885_IMAC91,
211 ALC883_3ST_2ch_DIG, 218 ALC883_3ST_2ch_DIG,
212 ALC883_3ST_6ch_DIG, 219 ALC883_3ST_6ch_DIG,
213 ALC883_3ST_6ch, 220 ALC883_3ST_6ch,
@@ -223,6 +230,7 @@ enum {
223 ALC888_ACER_ASPIRE_7730G, 230 ALC888_ACER_ASPIRE_7730G,
224 ALC883_MEDION, 231 ALC883_MEDION,
225 ALC883_MEDION_MD2, 232 ALC883_MEDION_MD2,
233 ALC883_MEDION_WIM2160,
226 ALC883_LAPTOP_EAPD, 234 ALC883_LAPTOP_EAPD,
227 ALC883_LENOVO_101E_2ch, 235 ALC883_LENOVO_101E_2ch,
228 ALC883_LENOVO_NB0763, 236 ALC883_LENOVO_NB0763,
@@ -334,6 +342,9 @@ struct alc_spec {
334 /* hooks */ 342 /* hooks */
335 void (*init_hook)(struct hda_codec *codec); 343 void (*init_hook)(struct hda_codec *codec);
336 void (*unsol_event)(struct hda_codec *codec, unsigned int res); 344 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
345#ifdef CONFIG_SND_HDA_POWER_SAVE
346 void (*power_hook)(struct hda_codec *codec);
347#endif
337 348
338 /* for pin sensing */ 349 /* for pin sensing */
339 unsigned int sense_updated: 1; 350 unsigned int sense_updated: 1;
@@ -385,6 +396,7 @@ struct alc_config_preset {
385 void (*init_hook)(struct hda_codec *); 396 void (*init_hook)(struct hda_codec *);
386#ifdef CONFIG_SND_HDA_POWER_SAVE 397#ifdef CONFIG_SND_HDA_POWER_SAVE
387 struct hda_amp_list *loopbacks; 398 struct hda_amp_list *loopbacks;
399 void (*power_hook)(struct hda_codec *codec);
388#endif 400#endif
389}; 401};
390 402
@@ -400,6 +412,8 @@ static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
400 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); 412 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
401 if (mux_idx >= spec->num_mux_defs) 413 if (mux_idx >= spec->num_mux_defs)
402 mux_idx = 0; 414 mux_idx = 0;
415 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
416 mux_idx = 0;
403 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); 417 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
404} 418}
405 419
@@ -428,6 +442,8 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
428 442
429 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 443 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
430 imux = &spec->input_mux[mux_idx]; 444 imux = &spec->input_mux[mux_idx];
445 if (!imux->num_items && mux_idx > 0)
446 imux = &spec->input_mux[0];
431 447
432 type = get_wcaps_type(get_wcaps(codec, nid)); 448 type = get_wcaps_type(get_wcaps(codec, nid));
433 if (type == AC_WID_AUD_MIX) { 449 if (type == AC_WID_AUD_MIX) {
@@ -626,6 +642,7 @@ static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
626 642
627#define ALC_PIN_MODE(xname, nid, dir) \ 643#define ALC_PIN_MODE(xname, nid, dir) \
628 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 644 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
645 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
629 .info = alc_pin_mode_info, \ 646 .info = alc_pin_mode_info, \
630 .get = alc_pin_mode_get, \ 647 .get = alc_pin_mode_get, \
631 .put = alc_pin_mode_put, \ 648 .put = alc_pin_mode_put, \
@@ -677,6 +694,7 @@ static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
677} 694}
678#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \ 695#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
679 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 696 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
697 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
680 .info = alc_gpio_data_info, \ 698 .info = alc_gpio_data_info, \
681 .get = alc_gpio_data_get, \ 699 .get = alc_gpio_data_get, \
682 .put = alc_gpio_data_put, \ 700 .put = alc_gpio_data_put, \
@@ -731,6 +749,7 @@ static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
731} 749}
732#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \ 750#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
733 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 751 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
752 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
734 .info = alc_spdif_ctrl_info, \ 753 .info = alc_spdif_ctrl_info, \
735 .get = alc_spdif_ctrl_get, \ 754 .get = alc_spdif_ctrl_get, \
736 .put = alc_spdif_ctrl_put, \ 755 .put = alc_spdif_ctrl_put, \
@@ -784,6 +803,7 @@ static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
784 803
785#define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \ 804#define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
786 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 805 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
806 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
787 .info = alc_eapd_ctrl_info, \ 807 .info = alc_eapd_ctrl_info, \
788 .get = alc_eapd_ctrl_get, \ 808 .get = alc_eapd_ctrl_get, \
789 .put = alc_eapd_ctrl_put, \ 809 .put = alc_eapd_ctrl_put, \
@@ -830,27 +850,6 @@ static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
830 spec->init_verbs[spec->num_init_verbs++] = verb; 850 spec->init_verbs[spec->num_init_verbs++] = verb;
831} 851}
832 852
833#ifdef CONFIG_PROC_FS
834/*
835 * hook for proc
836 */
837static void print_realtek_coef(struct snd_info_buffer *buffer,
838 struct hda_codec *codec, hda_nid_t nid)
839{
840 int coeff;
841
842 if (nid != 0x20)
843 return;
844 coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
845 snd_iprintf(buffer, " Processing Coefficient: 0x%02x\n", coeff);
846 coeff = snd_hda_codec_read(codec, nid, 0,
847 AC_VERB_GET_COEF_INDEX, 0);
848 snd_iprintf(buffer, " Coefficient Index: 0x%02x\n", coeff);
849}
850#else
851#define print_realtek_coef NULL
852#endif
853
854/* 853/*
855 * set up from the preset table 854 * set up from the preset table
856 */ 855 */
@@ -897,6 +896,7 @@ static void setup_preset(struct hda_codec *codec,
897 spec->unsol_event = preset->unsol_event; 896 spec->unsol_event = preset->unsol_event;
898 spec->init_hook = preset->init_hook; 897 spec->init_hook = preset->init_hook;
899#ifdef CONFIG_SND_HDA_POWER_SAVE 898#ifdef CONFIG_SND_HDA_POWER_SAVE
899 spec->power_hook = preset->power_hook;
900 spec->loopback.amplist = preset->loopbacks; 900 spec->loopback.amplist = preset->loopbacks;
901#endif 901#endif
902 902
@@ -961,18 +961,12 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
961static void alc_automute_pin(struct hda_codec *codec) 961static void alc_automute_pin(struct hda_codec *codec)
962{ 962{
963 struct alc_spec *spec = codec->spec; 963 struct alc_spec *spec = codec->spec;
964 unsigned int present, pincap;
965 unsigned int nid = spec->autocfg.hp_pins[0]; 964 unsigned int nid = spec->autocfg.hp_pins[0];
966 int i; 965 int i;
967 966
968 if (!nid) 967 if (!nid)
969 return; 968 return;
970 pincap = snd_hda_query_pin_caps(codec, nid); 969 spec->jack_present = snd_hda_jack_detect(codec, nid);
971 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
972 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
973 present = snd_hda_codec_read(codec, nid, 0,
974 AC_VERB_GET_PIN_SENSE, 0);
975 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
976 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) { 970 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977 nid = spec->autocfg.speaker_pins[i]; 971 nid = spec->autocfg.speaker_pins[i];
978 if (!nid) 972 if (!nid)
@@ -1012,9 +1006,7 @@ static void alc_mic_automute(struct hda_codec *codec)
1012 1006
1013 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0]; 1007 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014 1008
1015 present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0, 1009 present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1016 AC_VERB_GET_PIN_SENSE, 0);
1017 present &= AC_PINSENSE_PRESENCE;
1018 if (present) { 1010 if (present) {
1019 alive = &spec->ext_mic; 1011 alive = &spec->ext_mic;
1020 dead = &spec->int_mic; 1012 dead = &spec->int_mic;
@@ -1093,6 +1085,16 @@ static void alc889_coef_init(struct hda_codec *codec)
1093 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010); 1085 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1094} 1086}
1095 1087
1088/* turn on/off EAPD control (only if available) */
1089static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
1090{
1091 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
1092 return;
1093 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
1094 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1095 on ? 2 : 0);
1096}
1097
1096static void alc_auto_init_amp(struct hda_codec *codec, int type) 1098static void alc_auto_init_amp(struct hda_codec *codec, int type)
1097{ 1099{
1098 unsigned int tmp; 1100 unsigned int tmp;
@@ -1110,25 +1112,22 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
1110 case ALC_INIT_DEFAULT: 1112 case ALC_INIT_DEFAULT:
1111 switch (codec->vendor_id) { 1113 switch (codec->vendor_id) {
1112 case 0x10ec0260: 1114 case 0x10ec0260:
1113 snd_hda_codec_write(codec, 0x0f, 0, 1115 set_eapd(codec, 0x0f, 1);
1114 AC_VERB_SET_EAPD_BTLENABLE, 2); 1116 set_eapd(codec, 0x10, 1);
1115 snd_hda_codec_write(codec, 0x10, 0,
1116 AC_VERB_SET_EAPD_BTLENABLE, 2);
1117 break; 1117 break;
1118 case 0x10ec0262: 1118 case 0x10ec0262:
1119 case 0x10ec0267: 1119 case 0x10ec0267:
1120 case 0x10ec0268: 1120 case 0x10ec0268:
1121 case 0x10ec0269: 1121 case 0x10ec0269:
1122 case 0x10ec0270:
1122 case 0x10ec0272: 1123 case 0x10ec0272:
1123 case 0x10ec0660: 1124 case 0x10ec0660:
1124 case 0x10ec0662: 1125 case 0x10ec0662:
1125 case 0x10ec0663: 1126 case 0x10ec0663:
1126 case 0x10ec0862: 1127 case 0x10ec0862:
1127 case 0x10ec0889: 1128 case 0x10ec0889:
1128 snd_hda_codec_write(codec, 0x14, 0, 1129 set_eapd(codec, 0x14, 1);
1129 AC_VERB_SET_EAPD_BTLENABLE, 2); 1130 set_eapd(codec, 0x15, 1);
1130 snd_hda_codec_write(codec, 0x15, 0,
1131 AC_VERB_SET_EAPD_BTLENABLE, 2);
1132 break; 1131 break;
1133 } 1132 }
1134 switch (codec->vendor_id) { 1133 switch (codec->vendor_id) {
@@ -1155,6 +1154,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
1155 case 0x10ec0888: 1154 case 0x10ec0888:
1156 alc888_coef_init(codec); 1155 alc888_coef_init(codec);
1157 break; 1156 break;
1157#if 0 /* XXX: This may cause the silent output on speaker on some machines */
1158 case 0x10ec0267: 1158 case 0x10ec0267:
1159 case 0x10ec0268: 1159 case 0x10ec0268:
1160 snd_hda_codec_write(codec, 0x20, 0, 1160 snd_hda_codec_write(codec, 0x20, 0,
@@ -1167,6 +1167,7 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
1167 AC_VERB_SET_PROC_COEF, 1167 AC_VERB_SET_PROC_COEF,
1168 tmp | 0x3000); 1168 tmp | 0x3000);
1169 break; 1169 break;
1170#endif /* XXX */
1170 } 1171 }
1171 break; 1172 break;
1172 } 1173 }
@@ -1230,6 +1231,8 @@ static void alc_init_auto_mic(struct hda_codec *codec)
1230 return; /* invalid entry */ 1231 return; /* invalid entry */
1231 } 1232 }
1232 } 1233 }
1234 if (!ext || !fixed)
1235 return;
1233 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP)) 1236 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1234 return; /* no unsol support */ 1237 return; /* no unsol support */
1235 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n", 1238 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
@@ -1256,7 +1259,7 @@ static void alc_init_auto_mic(struct hda_codec *codec)
1256 */ 1259 */
1257static int alc_subsystem_id(struct hda_codec *codec, 1260static int alc_subsystem_id(struct hda_codec *codec,
1258 hda_nid_t porta, hda_nid_t porte, 1261 hda_nid_t porta, hda_nid_t porte,
1259 hda_nid_t portd) 1262 hda_nid_t portd, hda_nid_t porti)
1260{ 1263{
1261 unsigned int ass, tmp, i; 1264 unsigned int ass, tmp, i;
1262 unsigned nid; 1265 unsigned nid;
@@ -1282,7 +1285,7 @@ static int alc_subsystem_id(struct hda_codec *codec,
1282 snd_printd("realtek: No valid SSID, " 1285 snd_printd("realtek: No valid SSID, "
1283 "checking pincfg 0x%08x for NID 0x%x\n", 1286 "checking pincfg 0x%08x for NID 0x%x\n",
1284 ass, nid); 1287 ass, nid);
1285 if (!(ass & 1) && !(ass & 0x100000)) 1288 if (!(ass & 1))
1286 return 0; 1289 return 0;
1287 if ((ass >> 30) != 1) /* no physical connection */ 1290 if ((ass >> 30) != 1) /* no physical connection */
1288 return 0; 1291 return 0;
@@ -1342,6 +1345,8 @@ do_sku:
1342 nid = porte; 1345 nid = porte;
1343 else if (tmp == 2) 1346 else if (tmp == 2)
1344 nid = portd; 1347 nid = portd;
1348 else if (tmp == 3)
1349 nid = porti;
1345 else 1350 else
1346 return 1; 1351 return 1;
1347 for (i = 0; i < spec->autocfg.line_outs; i++) 1352 for (i = 0; i < spec->autocfg.line_outs; i++)
@@ -1356,9 +1361,10 @@ do_sku:
1356} 1361}
1357 1362
1358static void alc_ssid_check(struct hda_codec *codec, 1363static void alc_ssid_check(struct hda_codec *codec,
1359 hda_nid_t porta, hda_nid_t porte, hda_nid_t portd) 1364 hda_nid_t porta, hda_nid_t porte,
1365 hda_nid_t portd, hda_nid_t porti)
1360{ 1366{
1361 if (!alc_subsystem_id(codec, porta, porte, portd)) { 1367 if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1362 struct alc_spec *spec = codec->spec; 1368 struct alc_spec *spec = codec->spec;
1363 snd_printd("realtek: " 1369 snd_printd("realtek: "
1364 "Enable default setup for auto mode as fallback\n"); 1370 "Enable default setup for auto mode as fallback\n");
@@ -1384,22 +1390,42 @@ struct alc_fixup {
1384 1390
1385static void alc_pick_fixup(struct hda_codec *codec, 1391static void alc_pick_fixup(struct hda_codec *codec,
1386 const struct snd_pci_quirk *quirk, 1392 const struct snd_pci_quirk *quirk,
1387 const struct alc_fixup *fix) 1393 const struct alc_fixup *fix,
1394 int pre_init)
1388{ 1395{
1389 const struct alc_pincfg *cfg; 1396 const struct alc_pincfg *cfg;
1390 1397
1391 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 1398 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1392 if (!quirk) 1399 if (!quirk)
1393 return; 1400 return;
1394
1395 fix += quirk->value; 1401 fix += quirk->value;
1396 cfg = fix->pins; 1402 cfg = fix->pins;
1397 if (cfg) { 1403 if (pre_init && cfg) {
1404#ifdef CONFIG_SND_DEBUG_VERBOSE
1405 snd_printdd(KERN_INFO "hda_codec: %s: Apply pincfg for %s\n",
1406 codec->chip_name, quirk->name);
1407#endif
1398 for (; cfg->nid; cfg++) 1408 for (; cfg->nid; cfg++)
1399 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 1409 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1400 } 1410 }
1401 if (fix->verbs) 1411 if (!pre_init && fix->verbs) {
1412#ifdef CONFIG_SND_DEBUG_VERBOSE
1413 snd_printdd(KERN_INFO "hda_codec: %s: Apply fix-verbs for %s\n",
1414 codec->chip_name, quirk->name);
1415#endif
1402 add_verb(codec->spec, fix->verbs); 1416 add_verb(codec->spec, fix->verbs);
1417 }
1418}
1419
1420static int alc_read_coef_idx(struct hda_codec *codec,
1421 unsigned int coef_idx)
1422{
1423 unsigned int val;
1424 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1425 coef_idx);
1426 val = snd_hda_codec_read(codec, 0x20, 0,
1427 AC_VERB_GET_PROC_COEF, 0);
1428 return val;
1403} 1429}
1404 1430
1405/* 1431/*
@@ -1513,7 +1539,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1513static void alc_automute_amp(struct hda_codec *codec) 1539static void alc_automute_amp(struct hda_codec *codec)
1514{ 1540{
1515 struct alc_spec *spec = codec->spec; 1541 struct alc_spec *spec = codec->spec;
1516 unsigned int val, mute, pincap; 1542 unsigned int mute;
1517 hda_nid_t nid; 1543 hda_nid_t nid;
1518 int i; 1544 int i;
1519 1545
@@ -1522,13 +1548,7 @@ static void alc_automute_amp(struct hda_codec *codec)
1522 nid = spec->autocfg.hp_pins[i]; 1548 nid = spec->autocfg.hp_pins[i];
1523 if (!nid) 1549 if (!nid)
1524 break; 1550 break;
1525 pincap = snd_hda_query_pin_caps(codec, nid); 1551 if (snd_hda_jack_detect(codec, nid)) {
1526 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1527 snd_hda_codec_read(codec, nid, 0,
1528 AC_VERB_SET_PIN_SENSE, 0);
1529 val = snd_hda_codec_read(codec, nid, 0,
1530 AC_VERB_GET_PIN_SENSE, 0);
1531 if (val & AC_PINSENSE_PRESENCE) {
1532 spec->jack_present = 1; 1552 spec->jack_present = 1;
1533 break; 1553 break;
1534 } 1554 }
@@ -1611,6 +1631,11 @@ static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1611 */ 1631 */
1612 1632
1613static struct hda_verb alc888_acer_aspire_6530g_verbs[] = { 1633static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1634/* Route to built-in subwoofer as well as speakers */
1635 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1636 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1637 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1638 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1614/* Bias voltage on for external mic port */ 1639/* Bias voltage on for external mic port */
1615 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80}, 1640 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1616/* Front Mic: set to PIN_IN (empty by default) */ 1641/* Front Mic: set to PIN_IN (empty by default) */
@@ -1622,10 +1647,12 @@ static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1622/* Enable speaker output */ 1647/* Enable speaker output */
1623 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1648 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1649 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1650 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
1625/* Enable headphone output */ 1651/* Enable headphone output */
1626 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP}, 1652 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1627 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1653 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1628 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 1654 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1655 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
1629 { } 1656 { }
1630}; 1657};
1631 1658
@@ -1665,9 +1692,6 @@ static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1665/* some bit here disables the other DACs. Init=0x4900 */ 1692/* some bit here disables the other DACs. Init=0x4900 */
1666 {0x20, AC_VERB_SET_COEF_INDEX, 0x08}, 1693 {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1667 {0x20, AC_VERB_SET_PROC_COEF, 0x0000}, 1694 {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1668/* Enable amplifiers */
1669 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1670 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1671/* DMIC fix 1695/* DMIC fix
1672 * This laptop has a stereo digital microphone. The mics are only 1cm apart 1696 * This laptop has a stereo digital microphone. The mics are only 1cm apart
1673 * which makes the stereo useless. However, either the mic or the ALC889 1697 * which makes the stereo useless. However, either the mic or the ALC889
@@ -1780,12 +1804,33 @@ static struct snd_kcontrol_new alc888_base_mixer[] = {
1780 { } /* end */ 1804 { } /* end */
1781}; 1805};
1782 1806
1807static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
1808 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1809 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1810 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1811 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1812 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1813 HDA_OUTPUT),
1814 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1815 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1816 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1817 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1818 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1819 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1820 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1821 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1822 { } /* end */
1823};
1824
1825
1783static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec) 1826static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1784{ 1827{
1785 struct alc_spec *spec = codec->spec; 1828 struct alc_spec *spec = codec->spec;
1786 1829
1787 spec->autocfg.hp_pins[0] = 0x15; 1830 spec->autocfg.hp_pins[0] = 0x15;
1788 spec->autocfg.speaker_pins[0] = 0x14; 1831 spec->autocfg.speaker_pins[0] = 0x14;
1832 spec->autocfg.speaker_pins[1] = 0x16;
1833 spec->autocfg.speaker_pins[2] = 0x17;
1789} 1834}
1790 1835
1791static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec) 1836static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
@@ -2401,6 +2446,8 @@ static const char *alc_slave_sws[] = {
2401 "Speaker Playback Switch", 2446 "Speaker Playback Switch",
2402 "Mono Playback Switch", 2447 "Mono Playback Switch",
2403 "IEC958 Playback Switch", 2448 "IEC958 Playback Switch",
2449 "Line-Out Playback Switch",
2450 "PCM Playback Switch",
2404 NULL, 2451 NULL,
2405}; 2452};
2406 2453
@@ -2408,20 +2455,34 @@ static const char *alc_slave_sws[] = {
2408 * build control elements 2455 * build control elements
2409 */ 2456 */
2410 2457
2458#define NID_MAPPING (-1)
2459
2460#define SUBDEV_SPEAKER_ (0 << 6)
2461#define SUBDEV_HP_ (1 << 6)
2462#define SUBDEV_LINE_ (2 << 6)
2463#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
2464#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
2465#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
2466
2411static void alc_free_kctls(struct hda_codec *codec); 2467static void alc_free_kctls(struct hda_codec *codec);
2412 2468
2469#ifdef CONFIG_SND_HDA_INPUT_BEEP
2413/* additional beep mixers; the actual parameters are overwritten at build */ 2470/* additional beep mixers; the actual parameters are overwritten at build */
2414static struct snd_kcontrol_new alc_beep_mixer[] = { 2471static struct snd_kcontrol_new alc_beep_mixer[] = {
2415 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), 2472 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2416 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT), 2473 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2417 { } /* end */ 2474 { } /* end */
2418}; 2475};
2476#endif
2419 2477
2420static int alc_build_controls(struct hda_codec *codec) 2478static int alc_build_controls(struct hda_codec *codec)
2421{ 2479{
2422 struct alc_spec *spec = codec->spec; 2480 struct alc_spec *spec = codec->spec;
2423 int err; 2481 struct snd_kcontrol *kctl;
2424 int i; 2482 struct snd_kcontrol_new *knew;
2483 int i, j, err;
2484 unsigned int u;
2485 hda_nid_t nid;
2425 2486
2426 for (i = 0; i < spec->num_mixers; i++) { 2487 for (i = 0; i < spec->num_mixers; i++) {
2427 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 2488 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -2452,6 +2513,7 @@ static int alc_build_controls(struct hda_codec *codec)
2452 return err; 2513 return err;
2453 } 2514 }
2454 2515
2516#ifdef CONFIG_SND_HDA_INPUT_BEEP
2455 /* create beep controls if needed */ 2517 /* create beep controls if needed */
2456 if (spec->beep_amp) { 2518 if (spec->beep_amp) {
2457 struct snd_kcontrol_new *knew; 2519 struct snd_kcontrol_new *knew;
@@ -2461,11 +2523,12 @@ static int alc_build_controls(struct hda_codec *codec)
2461 if (!kctl) 2523 if (!kctl)
2462 return -ENOMEM; 2524 return -ENOMEM;
2463 kctl->private_value = spec->beep_amp; 2525 kctl->private_value = spec->beep_amp;
2464 err = snd_hda_ctl_add(codec, kctl); 2526 err = snd_hda_ctl_add(codec, 0, kctl);
2465 if (err < 0) 2527 if (err < 0)
2466 return err; 2528 return err;
2467 } 2529 }
2468 } 2530 }
2531#endif
2469 2532
2470 /* if we have no master control, let's create it */ 2533 /* if we have no master control, let's create it */
2471 if (!spec->no_analog && 2534 if (!spec->no_analog &&
@@ -2486,7 +2549,77 @@ static int alc_build_controls(struct hda_codec *codec)
2486 return err; 2549 return err;
2487 } 2550 }
2488 2551
2552 /* assign Capture Source enums to NID */
2553 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2554 if (!kctl)
2555 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2556 for (i = 0; kctl && i < kctl->count; i++) {
2557 hda_nid_t *nids = spec->capsrc_nids;
2558 if (!nids)
2559 nids = spec->adc_nids;
2560 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
2561 if (err < 0)
2562 return err;
2563 }
2564 if (spec->cap_mixer) {
2565 const char *kname = kctl ? kctl->id.name : NULL;
2566 for (knew = spec->cap_mixer; knew->name; knew++) {
2567 if (kname && strcmp(knew->name, kname) == 0)
2568 continue;
2569 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2570 for (i = 0; kctl && i < kctl->count; i++) {
2571 err = snd_hda_add_nid(codec, kctl, i,
2572 spec->adc_nids[i]);
2573 if (err < 0)
2574 return err;
2575 }
2576 }
2577 }
2578
2579 /* other nid->control mapping */
2580 for (i = 0; i < spec->num_mixers; i++) {
2581 for (knew = spec->mixers[i]; knew->name; knew++) {
2582 if (knew->iface != NID_MAPPING)
2583 continue;
2584 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2585 if (kctl == NULL)
2586 continue;
2587 u = knew->subdevice;
2588 for (j = 0; j < 4; j++, u >>= 8) {
2589 nid = u & 0x3f;
2590 if (nid == 0)
2591 continue;
2592 switch (u & 0xc0) {
2593 case SUBDEV_SPEAKER_:
2594 nid = spec->autocfg.speaker_pins[nid];
2595 break;
2596 case SUBDEV_LINE_:
2597 nid = spec->autocfg.line_out_pins[nid];
2598 break;
2599 case SUBDEV_HP_:
2600 nid = spec->autocfg.hp_pins[nid];
2601 break;
2602 default:
2603 continue;
2604 }
2605 err = snd_hda_add_nid(codec, kctl, 0, nid);
2606 if (err < 0)
2607 return err;
2608 }
2609 u = knew->private_value;
2610 for (j = 0; j < 4; j++, u >>= 8) {
2611 nid = u & 0xff;
2612 if (nid == 0)
2613 continue;
2614 err = snd_hda_add_nid(codec, kctl, 0, nid);
2615 if (err < 0)
2616 return err;
2617 }
2618 }
2619 }
2620
2489 alc_free_kctls(codec); /* no longer needed */ 2621 alc_free_kctls(codec); /* no longer needed */
2622
2490 return 0; 2623 return 0;
2491} 2624}
2492 2625
@@ -2779,8 +2912,7 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2779 unsigned int present; 2912 unsigned int present;
2780 unsigned char bits; 2913 unsigned char bits;
2781 2914
2782 present = snd_hda_codec_read(codec, 0x18, 0, 2915 present = snd_hda_jack_detect(codec, 0x18);
2783 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2784 bits = present ? HDA_AMP_MUTE : 0; 2916 bits = present ? HDA_AMP_MUTE : 0;
2785 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 2917 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2786} 2918}
@@ -3480,7 +3612,7 @@ static int alc_build_pcms(struct hda_codec *codec)
3480 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), 3612 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3481 "%s Analog", codec->chip_name); 3613 "%s Analog", codec->chip_name);
3482 info->name = spec->stream_name_analog; 3614 info->name = spec->stream_name_analog;
3483 3615
3484 if (spec->stream_analog_playback) { 3616 if (spec->stream_analog_playback) {
3485 if (snd_BUG_ON(!spec->multiout.dac_nids)) 3617 if (snd_BUG_ON(!spec->multiout.dac_nids))
3486 return -EINVAL; 3618 return -EINVAL;
@@ -3570,6 +3702,11 @@ static int alc_build_pcms(struct hda_codec *codec)
3570 return 0; 3702 return 0;
3571} 3703}
3572 3704
3705static inline void alc_shutup(struct hda_codec *codec)
3706{
3707 snd_hda_shutup_pins(codec);
3708}
3709
3573static void alc_free_kctls(struct hda_codec *codec) 3710static void alc_free_kctls(struct hda_codec *codec)
3574{ 3711{
3575 struct alc_spec *spec = codec->spec; 3712 struct alc_spec *spec = codec->spec;
@@ -3590,11 +3727,48 @@ static void alc_free(struct hda_codec *codec)
3590 if (!spec) 3727 if (!spec)
3591 return; 3728 return;
3592 3729
3730 alc_shutup(codec);
3593 alc_free_kctls(codec); 3731 alc_free_kctls(codec);
3594 kfree(spec); 3732 kfree(spec);
3595 snd_hda_detach_beep_device(codec); 3733 snd_hda_detach_beep_device(codec);
3596} 3734}
3597 3735
3736#ifdef CONFIG_SND_HDA_POWER_SAVE
3737static void alc_power_eapd(struct hda_codec *codec)
3738{
3739 /* We currently only handle front, HP */
3740 switch (codec->vendor_id) {
3741 case 0x10ec0260:
3742 set_eapd(codec, 0x0f, 0);
3743 set_eapd(codec, 0x10, 0);
3744 break;
3745 case 0x10ec0262:
3746 case 0x10ec0267:
3747 case 0x10ec0268:
3748 case 0x10ec0269:
3749 case 0x10ec0270:
3750 case 0x10ec0272:
3751 case 0x10ec0660:
3752 case 0x10ec0662:
3753 case 0x10ec0663:
3754 case 0x10ec0862:
3755 case 0x10ec0889:
3756 set_eapd(codec, 0x14, 0);
3757 set_eapd(codec, 0x15, 0);
3758 break;
3759 }
3760}
3761
3762static int alc_suspend(struct hda_codec *codec, pm_message_t state)
3763{
3764 struct alc_spec *spec = codec->spec;
3765 alc_shutup(codec);
3766 if (spec && spec->power_hook)
3767 spec->power_hook(codec);
3768 return 0;
3769}
3770#endif
3771
3598#ifdef SND_HDA_NEEDS_RESUME 3772#ifdef SND_HDA_NEEDS_RESUME
3599static int alc_resume(struct hda_codec *codec) 3773static int alc_resume(struct hda_codec *codec)
3600{ 3774{
@@ -3617,8 +3791,10 @@ static struct hda_codec_ops alc_patch_ops = {
3617 .resume = alc_resume, 3791 .resume = alc_resume,
3618#endif 3792#endif
3619#ifdef CONFIG_SND_HDA_POWER_SAVE 3793#ifdef CONFIG_SND_HDA_POWER_SAVE
3794 .suspend = alc_suspend,
3620 .check_power_status = alc_check_power_status, 3795 .check_power_status = alc_check_power_status,
3621#endif 3796#endif
3797 .reboot_notify = alc_shutup,
3622}; 3798};
3623 3799
3624 3800
@@ -3775,6 +3951,7 @@ static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3775#define PIN_CTL_TEST(xname,nid) { \ 3951#define PIN_CTL_TEST(xname,nid) { \
3776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 3952 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3777 .name = xname, \ 3953 .name = xname, \
3954 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
3778 .info = alc_test_pin_ctl_info, \ 3955 .info = alc_test_pin_ctl_info, \
3779 .get = alc_test_pin_ctl_get, \ 3956 .get = alc_test_pin_ctl_get, \
3780 .put = alc_test_pin_ctl_put, \ 3957 .put = alc_test_pin_ctl_put, \
@@ -3784,6 +3961,7 @@ static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3784#define PIN_SRC_TEST(xname,nid) { \ 3961#define PIN_SRC_TEST(xname,nid) { \
3785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 3962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3786 .name = xname, \ 3963 .name = xname, \
3964 .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
3787 .info = alc_test_pin_src_info, \ 3965 .info = alc_test_pin_src_info, \
3788 .get = alc_test_pin_src_get, \ 3966 .get = alc_test_pin_src_get, \
3789 .put = alc_test_pin_src_put, \ 3967 .put = alc_test_pin_src_put, \
@@ -3965,7 +4143,7 @@ static struct snd_pci_quirk alc880_cfg_tbl[] = {
3965 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG), 4143 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3966 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734), 4144 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3967 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU), 4145 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3968 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL), 4146 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_F1734),
3969 SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU), 4147 SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3970 SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW), 4148 SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3971 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG), 4149 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
@@ -4322,10 +4500,26 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
4322 knew->name = kstrdup(name, GFP_KERNEL); 4500 knew->name = kstrdup(name, GFP_KERNEL);
4323 if (!knew->name) 4501 if (!knew->name)
4324 return -ENOMEM; 4502 return -ENOMEM;
4503 if (get_amp_nid_(val))
4504 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
4325 knew->private_value = val; 4505 knew->private_value = val;
4326 return 0; 4506 return 0;
4327} 4507}
4328 4508
4509static int add_control_with_pfx(struct alc_spec *spec, int type,
4510 const char *pfx, const char *dir,
4511 const char *sfx, unsigned long val)
4512{
4513 char name[32];
4514 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4515 return add_control(spec, type, name, val);
4516}
4517
4518#define add_pb_vol_ctrl(spec, type, pfx, val) \
4519 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4520#define add_pb_sw_ctrl(spec, type, pfx, val) \
4521 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4522
4329#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17) 4523#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
4330#define alc880_fixed_pin_idx(nid) ((nid) - 0x14) 4524#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
4331#define alc880_is_multi_pin(nid) ((nid) >= 0x18) 4525#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
@@ -4379,7 +4573,6 @@ static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4379static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, 4573static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4380 const struct auto_pin_cfg *cfg) 4574 const struct auto_pin_cfg *cfg)
4381{ 4575{
4382 char name[32];
4383 static const char *chname[4] = { 4576 static const char *chname[4] = {
4384 "Front", "Surround", NULL /*CLFE*/, "Side" 4577 "Front", "Surround", NULL /*CLFE*/, "Side"
4385 }; 4578 };
@@ -4392,26 +4585,26 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4392 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i])); 4585 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4393 if (i == 2) { 4586 if (i == 2) {
4394 /* Center/LFE */ 4587 /* Center/LFE */
4395 err = add_control(spec, ALC_CTL_WIDGET_VOL, 4588 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4396 "Center Playback Volume", 4589 "Center",
4397 HDA_COMPOSE_AMP_VAL(nid, 1, 0, 4590 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4398 HDA_OUTPUT)); 4591 HDA_OUTPUT));
4399 if (err < 0) 4592 if (err < 0)
4400 return err; 4593 return err;
4401 err = add_control(spec, ALC_CTL_WIDGET_VOL, 4594 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4402 "LFE Playback Volume", 4595 "LFE",
4403 HDA_COMPOSE_AMP_VAL(nid, 2, 0, 4596 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4404 HDA_OUTPUT)); 4597 HDA_OUTPUT));
4405 if (err < 0) 4598 if (err < 0)
4406 return err; 4599 return err;
4407 err = add_control(spec, ALC_CTL_BIND_MUTE, 4600 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4408 "Center Playback Switch", 4601 "Center",
4409 HDA_COMPOSE_AMP_VAL(nid, 1, 2, 4602 HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4410 HDA_INPUT)); 4603 HDA_INPUT));
4411 if (err < 0) 4604 if (err < 0)
4412 return err; 4605 return err;
4413 err = add_control(spec, ALC_CTL_BIND_MUTE, 4606 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4414 "LFE Playback Switch", 4607 "LFE",
4415 HDA_COMPOSE_AMP_VAL(nid, 2, 2, 4608 HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4416 HDA_INPUT)); 4609 HDA_INPUT));
4417 if (err < 0) 4610 if (err < 0)
@@ -4423,14 +4616,12 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4423 pfx = "Speaker"; 4616 pfx = "Speaker";
4424 else 4617 else
4425 pfx = chname[i]; 4618 pfx = chname[i];
4426 sprintf(name, "%s Playback Volume", pfx); 4619 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4427 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4428 HDA_COMPOSE_AMP_VAL(nid, 3, 0, 4620 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4429 HDA_OUTPUT)); 4621 HDA_OUTPUT));
4430 if (err < 0) 4622 if (err < 0)
4431 return err; 4623 return err;
4432 sprintf(name, "%s Playback Switch", pfx); 4624 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4433 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4434 HDA_COMPOSE_AMP_VAL(nid, 3, 2, 4625 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4435 HDA_INPUT)); 4626 HDA_INPUT));
4436 if (err < 0) 4627 if (err < 0)
@@ -4446,7 +4637,6 @@ static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4446{ 4637{
4447 hda_nid_t nid; 4638 hda_nid_t nid;
4448 int err; 4639 int err;
4449 char name[32];
4450 4640
4451 if (!pin) 4641 if (!pin)
4452 return 0; 4642 return 0;
@@ -4460,21 +4650,18 @@ static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4460 spec->multiout.extra_out_nid[0] = nid; 4650 spec->multiout.extra_out_nid[0] = nid;
4461 /* control HP volume/switch on the output mixer amp */ 4651 /* control HP volume/switch on the output mixer amp */
4462 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin)); 4652 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4463 sprintf(name, "%s Playback Volume", pfx); 4653 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4464 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4465 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT)); 4654 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4466 if (err < 0) 4655 if (err < 0)
4467 return err; 4656 return err;
4468 sprintf(name, "%s Playback Switch", pfx); 4657 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4469 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4470 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT)); 4658 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4471 if (err < 0) 4659 if (err < 0)
4472 return err; 4660 return err;
4473 } else if (alc880_is_multi_pin(pin)) { 4661 } else if (alc880_is_multi_pin(pin)) {
4474 /* set manual connection */ 4662 /* set manual connection */
4475 /* we have only a switch on HP-out PIN */ 4663 /* we have only a switch on HP-out PIN */
4476 sprintf(name, "%s Playback Switch", pfx); 4664 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4477 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4478 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 4665 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4479 if (err < 0) 4666 if (err < 0)
4480 return err; 4667 return err;
@@ -4487,16 +4674,13 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4487 const char *ctlname, 4674 const char *ctlname,
4488 int idx, hda_nid_t mix_nid) 4675 int idx, hda_nid_t mix_nid)
4489{ 4676{
4490 char name[32];
4491 int err; 4677 int err;
4492 4678
4493 sprintf(name, "%s Playback Volume", ctlname); 4679 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4494 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4495 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 4680 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4496 if (err < 0) 4681 if (err < 0)
4497 return err; 4682 return err;
4498 sprintf(name, "%s Playback Switch", ctlname); 4683 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4499 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4500 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 4684 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4501 if (err < 0) 4685 if (err < 0)
4502 return err; 4686 return err;
@@ -4634,6 +4818,25 @@ static void alc880_auto_init_analog_input(struct hda_codec *codec)
4634 } 4818 }
4635} 4819}
4636 4820
4821static void alc880_auto_init_input_src(struct hda_codec *codec)
4822{
4823 struct alc_spec *spec = codec->spec;
4824 int c;
4825
4826 for (c = 0; c < spec->num_adc_nids; c++) {
4827 unsigned int mux_idx;
4828 const struct hda_input_mux *imux;
4829 mux_idx = c >= spec->num_mux_defs ? 0 : c;
4830 imux = &spec->input_mux[mux_idx];
4831 if (!imux->num_items && mux_idx > 0)
4832 imux = &spec->input_mux[0];
4833 if (imux)
4834 snd_hda_codec_write(codec, spec->adc_nids[c], 0,
4835 AC_VERB_SET_CONNECT_SEL,
4836 imux->items[0].index);
4837 }
4838}
4839
4637/* parse the BIOS configuration and set up the alc_spec */ 4840/* parse the BIOS configuration and set up the alc_spec */
4638/* return 1 if successful, 0 if the proper config is not found, 4841/* return 1 if successful, 0 if the proper config is not found,
4639 * or a negative error code 4842 * or a negative error code
@@ -4700,7 +4903,7 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
4700 spec->num_mux_defs = 1; 4903 spec->num_mux_defs = 1;
4701 spec->input_mux = &spec->private_imux[0]; 4904 spec->input_mux = &spec->private_imux[0];
4702 4905
4703 alc_ssid_check(codec, 0x15, 0x1b, 0x14); 4906 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
4704 4907
4705 return 1; 4908 return 1;
4706} 4909}
@@ -4712,6 +4915,7 @@ static void alc880_auto_init(struct hda_codec *codec)
4712 alc880_auto_init_multi_out(codec); 4915 alc880_auto_init_multi_out(codec);
4713 alc880_auto_init_extra_out(codec); 4916 alc880_auto_init_extra_out(codec);
4714 alc880_auto_init_analog_input(codec); 4917 alc880_auto_init_analog_input(codec);
4918 alc880_auto_init_input_src(codec);
4715 if (spec->unsol_event) 4919 if (spec->unsol_event)
4716 alc_inithook(codec); 4920 alc_inithook(codec);
4717} 4921}
@@ -4749,6 +4953,49 @@ static void fixup_automic_adc(struct hda_codec *codec)
4749 spec->auto_mic = 0; /* disable auto-mic to be sure */ 4953 spec->auto_mic = 0; /* disable auto-mic to be sure */
4750} 4954}
4751 4955
4956/* choose the ADC/MUX containing the input pin and initialize the setup */
4957static void fixup_single_adc(struct hda_codec *codec)
4958{
4959 struct alc_spec *spec = codec->spec;
4960 hda_nid_t pin = 0;
4961 int i;
4962
4963 /* search for the input pin; there must be only one */
4964 for (i = 0; i < AUTO_PIN_LAST; i++) {
4965 if (spec->autocfg.input_pins[i]) {
4966 pin = spec->autocfg.input_pins[i];
4967 break;
4968 }
4969 }
4970 if (!pin)
4971 return;
4972
4973 /* set the default connection to that pin */
4974 for (i = 0; i < spec->num_adc_nids; i++) {
4975 hda_nid_t cap = spec->capsrc_nids ?
4976 spec->capsrc_nids[i] : spec->adc_nids[i];
4977 int idx;
4978
4979 idx = get_connection_index(codec, cap, pin);
4980 if (idx < 0)
4981 continue;
4982 /* use only this ADC */
4983 if (spec->capsrc_nids)
4984 spec->capsrc_nids += i;
4985 spec->adc_nids += i;
4986 spec->num_adc_nids = 1;
4987 /* select or unmute this route */
4988 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4989 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4990 HDA_AMP_MUTE, 0);
4991 } else {
4992 snd_hda_codec_write_cache(codec, cap, 0,
4993 AC_VERB_SET_CONNECT_SEL, idx);
4994 }
4995 return;
4996 }
4997}
4998
4752static void set_capture_mixer(struct hda_codec *codec) 4999static void set_capture_mixer(struct hda_codec *codec)
4753{ 5000{
4754 struct alc_spec *spec = codec->spec; 5001 struct alc_spec *spec = codec->spec;
@@ -4761,20 +5008,89 @@ static void set_capture_mixer(struct hda_codec *codec)
4761 alc_capture_mixer3 }, 5008 alc_capture_mixer3 },
4762 }; 5009 };
4763 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) { 5010 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4764 int mux; 5011 int mux = 0;
4765 if (spec->auto_mic) { 5012 if (spec->auto_mic)
4766 mux = 0;
4767 fixup_automic_adc(codec); 5013 fixup_automic_adc(codec);
4768 } else if (spec->input_mux && spec->input_mux->num_items > 1) 5014 else if (spec->input_mux) {
4769 mux = 1; 5015 if (spec->input_mux->num_items > 1)
4770 else 5016 mux = 1;
4771 mux = 0; 5017 else if (spec->input_mux->num_items == 1)
5018 fixup_single_adc(codec);
5019 }
4772 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1]; 5020 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4773 } 5021 }
4774} 5022}
4775 5023
5024/* fill adc_nids (and capsrc_nids) containing all active input pins */
5025static void fillup_priv_adc_nids(struct hda_codec *codec, hda_nid_t *nids,
5026 int num_nids)
5027{
5028 struct alc_spec *spec = codec->spec;
5029 int n;
5030 hda_nid_t fallback_adc = 0, fallback_cap = 0;
5031
5032 for (n = 0; n < num_nids; n++) {
5033 hda_nid_t adc, cap;
5034 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
5035 int nconns, i, j;
5036
5037 adc = nids[n];
5038 if (get_wcaps_type(get_wcaps(codec, adc)) != AC_WID_AUD_IN)
5039 continue;
5040 cap = adc;
5041 nconns = snd_hda_get_connections(codec, cap, conn,
5042 ARRAY_SIZE(conn));
5043 if (nconns == 1) {
5044 cap = conn[0];
5045 nconns = snd_hda_get_connections(codec, cap, conn,
5046 ARRAY_SIZE(conn));
5047 }
5048 if (nconns <= 0)
5049 continue;
5050 if (!fallback_adc) {
5051 fallback_adc = adc;
5052 fallback_cap = cap;
5053 }
5054 for (i = 0; i < AUTO_PIN_LAST; i++) {
5055 hda_nid_t nid = spec->autocfg.input_pins[i];
5056 if (!nid)
5057 continue;
5058 for (j = 0; j < nconns; j++) {
5059 if (conn[j] == nid)
5060 break;
5061 }
5062 if (j >= nconns)
5063 break;
5064 }
5065 if (i >= AUTO_PIN_LAST) {
5066 int num_adcs = spec->num_adc_nids;
5067 spec->private_adc_nids[num_adcs] = adc;
5068 spec->private_capsrc_nids[num_adcs] = cap;
5069 spec->num_adc_nids++;
5070 spec->adc_nids = spec->private_adc_nids;
5071 if (adc != cap)
5072 spec->capsrc_nids = spec->private_capsrc_nids;
5073 }
5074 }
5075 if (!spec->num_adc_nids) {
5076 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
5077 " using fallback 0x%x\n",
5078 codec->chip_name, fallback_adc);
5079 spec->private_adc_nids[0] = fallback_adc;
5080 spec->adc_nids = spec->private_adc_nids;
5081 if (fallback_adc != fallback_cap) {
5082 spec->private_capsrc_nids[0] = fallback_cap;
5083 spec->capsrc_nids = spec->private_adc_nids;
5084 }
5085 }
5086}
5087
5088#ifdef CONFIG_SND_HDA_INPUT_BEEP
4776#define set_beep_amp(spec, nid, idx, dir) \ 5089#define set_beep_amp(spec, nid, idx, dir) \
4777 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) 5090 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
5091#else
5092#define set_beep_amp(spec, nid, idx, dir) /* NOP */
5093#endif
4778 5094
4779/* 5095/*
4780 * OK, here we have finally the patch for ALC880 5096 * OK, here we have finally the patch for ALC880
@@ -4856,7 +5172,6 @@ static int patch_alc880(struct hda_codec *codec)
4856 if (!spec->loopback.amplist) 5172 if (!spec->loopback.amplist)
4857 spec->loopback.amplist = alc880_loopbacks; 5173 spec->loopback.amplist = alc880_loopbacks;
4858#endif 5174#endif
4859 codec->proc_widget_hook = print_realtek_coef;
4860 5175
4861 return 0; 5176 return 0;
4862} 5177}
@@ -5064,6 +5379,7 @@ static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5064 { 5379 {
5065 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5380 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5066 .name = "Master Playback Switch", 5381 .name = "Master Playback Switch",
5382 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5067 .info = snd_ctl_boolean_mono_info, 5383 .info = snd_ctl_boolean_mono_info,
5068 .get = alc260_hp_master_sw_get, 5384 .get = alc260_hp_master_sw_get,
5069 .put = alc260_hp_master_sw_put, 5385 .put = alc260_hp_master_sw_put,
@@ -5087,11 +5403,8 @@ static struct hda_verb alc260_hp_unsol_verbs[] = {
5087static void alc260_hp_automute(struct hda_codec *codec) 5403static void alc260_hp_automute(struct hda_codec *codec)
5088{ 5404{
5089 struct alc_spec *spec = codec->spec; 5405 struct alc_spec *spec = codec->spec;
5090 unsigned int present;
5091 5406
5092 present = snd_hda_codec_read(codec, 0x10, 0, 5407 spec->jack_present = snd_hda_jack_detect(codec, 0x10);
5093 AC_VERB_GET_PIN_SENSE, 0);
5094 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5095 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11); 5408 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5096} 5409}
5097 5410
@@ -5105,6 +5418,7 @@ static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5105 { 5418 {
5106 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 5419 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5107 .name = "Master Playback Switch", 5420 .name = "Master Playback Switch",
5421 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5108 .info = snd_ctl_boolean_mono_info, 5422 .info = snd_ctl_boolean_mono_info,
5109 .get = alc260_hp_master_sw_get, 5423 .get = alc260_hp_master_sw_get,
5110 .put = alc260_hp_master_sw_put, 5424 .put = alc260_hp_master_sw_put,
@@ -5156,11 +5470,8 @@ static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5156static void alc260_hp_3013_automute(struct hda_codec *codec) 5470static void alc260_hp_3013_automute(struct hda_codec *codec)
5157{ 5471{
5158 struct alc_spec *spec = codec->spec; 5472 struct alc_spec *spec = codec->spec;
5159 unsigned int present;
5160 5473
5161 present = snd_hda_codec_read(codec, 0x15, 0, 5474 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
5162 AC_VERB_GET_PIN_SENSE, 0);
5163 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5164 alc260_hp_master_update(codec, 0x15, 0x10, 0x11); 5475 alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5165} 5476}
5166 5477
@@ -5173,12 +5484,8 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5173 5484
5174static void alc260_hp_3012_automute(struct hda_codec *codec) 5485static void alc260_hp_3012_automute(struct hda_codec *codec)
5175{ 5486{
5176 unsigned int present, bits; 5487 unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
5177 5488
5178 present = snd_hda_codec_read(codec, 0x10, 0,
5179 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5180
5181 bits = present ? 0 : PIN_OUT;
5182 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5489 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5183 bits); 5490 bits);
5184 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5491 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
@@ -5748,8 +6055,7 @@ static void alc260_replacer_672v_automute(struct hda_codec *codec)
5748 unsigned int present; 6055 unsigned int present;
5749 6056
5750 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */ 6057 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5751 present = snd_hda_codec_read(codec, 0x0f, 0, 6058 present = snd_hda_jack_detect(codec, 0x0f);
5752 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5753 if (present) { 6059 if (present) {
5754 snd_hda_codec_write_cache(codec, 0x01, 0, 6060 snd_hda_codec_write_cache(codec, 0x01, 0,
5755 AC_VERB_SET_GPIO_DATA, 1); 6061 AC_VERB_SET_GPIO_DATA, 1);
@@ -5989,7 +6295,6 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5989{ 6295{
5990 hda_nid_t nid_vol; 6296 hda_nid_t nid_vol;
5991 unsigned long vol_val, sw_val; 6297 unsigned long vol_val, sw_val;
5992 char name[32];
5993 int err; 6298 int err;
5994 6299
5995 if (nid >= 0x0f && nid < 0x11) { 6300 if (nid >= 0x0f && nid < 0x11) {
@@ -6009,14 +6314,12 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6009 6314
6010 if (!(*vol_bits & (1 << nid_vol))) { 6315 if (!(*vol_bits & (1 << nid_vol))) {
6011 /* first control for the volume widget */ 6316 /* first control for the volume widget */
6012 snprintf(name, sizeof(name), "%s Playback Volume", pfx); 6317 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6013 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
6014 if (err < 0) 6318 if (err < 0)
6015 return err; 6319 return err;
6016 *vol_bits |= (1 << nid_vol); 6320 *vol_bits |= (1 << nid_vol);
6017 } 6321 }
6018 snprintf(name, sizeof(name), "%s Playback Switch", pfx); 6322 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6019 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
6020 if (err < 0) 6323 if (err < 0)
6021 return err; 6324 return err;
6022 return 1; 6325 return 1;
@@ -6124,6 +6427,8 @@ static void alc260_auto_init_analog_input(struct hda_codec *codec)
6124 } 6427 }
6125} 6428}
6126 6429
6430#define alc260_auto_init_input_src alc880_auto_init_input_src
6431
6127/* 6432/*
6128 * generic initialization of ADC, input mixers and output mixers 6433 * generic initialization of ADC, input mixers and output mixers
6129 */ 6434 */
@@ -6199,7 +6504,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
6199 spec->num_mux_defs = 1; 6504 spec->num_mux_defs = 1;
6200 spec->input_mux = &spec->private_imux[0]; 6505 spec->input_mux = &spec->private_imux[0];
6201 6506
6202 alc_ssid_check(codec, 0x10, 0x15, 0x0f); 6507 alc_ssid_check(codec, 0x10, 0x15, 0x0f, 0);
6203 6508
6204 return 1; 6509 return 1;
6205} 6510}
@@ -6210,6 +6515,7 @@ static void alc260_auto_init(struct hda_codec *codec)
6210 struct alc_spec *spec = codec->spec; 6515 struct alc_spec *spec = codec->spec;
6211 alc260_auto_init_multi_out(codec); 6516 alc260_auto_init_multi_out(codec);
6212 alc260_auto_init_analog_input(codec); 6517 alc260_auto_init_analog_input(codec);
6518 alc260_auto_init_input_src(codec);
6213 if (spec->unsol_event) 6519 if (spec->unsol_event)
6214 alc_inithook(codec); 6520 alc_inithook(codec);
6215} 6521}
@@ -6246,6 +6552,7 @@ static const char *alc260_models[ALC260_MODEL_LAST] = {
6246 6552
6247static struct snd_pci_quirk alc260_cfg_tbl[] = { 6553static struct snd_pci_quirk alc260_cfg_tbl[] = {
6248 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER), 6554 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6555 SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
6249 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER), 6556 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6250 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100), 6557 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6251 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013), 6558 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
@@ -6275,7 +6582,7 @@ static struct alc_config_preset alc260_presets[] = {
6275 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 6582 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6276 .dac_nids = alc260_dac_nids, 6583 .dac_nids = alc260_dac_nids,
6277 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids), 6584 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6278 .adc_nids = alc260_adc_nids, 6585 .adc_nids = alc260_dual_adc_nids,
6279 .num_channel_mode = ARRAY_SIZE(alc260_modes), 6586 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6280 .channel_mode = alc260_modes, 6587 .channel_mode = alc260_modes,
6281 .input_mux = &alc260_capture_source, 6588 .input_mux = &alc260_capture_source,
@@ -6477,7 +6784,6 @@ static int patch_alc260(struct hda_codec *codec)
6477 if (!spec->loopback.amplist) 6784 if (!spec->loopback.amplist)
6478 spec->loopback.amplist = alc260_loopbacks; 6785 spec->loopback.amplist = alc260_loopbacks;
6479#endif 6786#endif
6480 codec->proc_widget_hook = print_realtek_coef;
6481 6787
6482 return 0; 6788 return 0;
6483} 6789}
@@ -6559,6 +6865,14 @@ static struct hda_input_mux mb5_capture_source = {
6559 }, 6865 },
6560}; 6866};
6561 6867
6868static struct hda_input_mux macmini3_capture_source = {
6869 .num_items = 2,
6870 .items = {
6871 { "Line", 0x2 },
6872 { "CD", 0x4 },
6873 },
6874};
6875
6562static struct hda_input_mux alc883_3stack_6ch_intel = { 6876static struct hda_input_mux alc883_3stack_6ch_intel = {
6563 .num_items = 4, 6877 .num_items = 4,
6564 .items = { 6878 .items = {
@@ -6619,7 +6933,7 @@ static struct hda_input_mux alc889A_mb31_capture_source = {
6619 /* Front Mic (0x01) unused */ 6933 /* Front Mic (0x01) unused */
6620 { "Line", 0x2 }, 6934 { "Line", 0x2 },
6621 /* Line 2 (0x03) unused */ 6935 /* Line 2 (0x03) unused */
6622 /* CD (0x04) unsused? */ 6936 /* CD (0x04) unused? */
6623 }, 6937 },
6624}; 6938};
6625 6939
@@ -6747,6 +7061,13 @@ static struct hda_channel_mode alc882_sixstack_modes[2] = {
6747 { 8, alc882_sixstack_ch8_init }, 7061 { 8, alc882_sixstack_ch8_init },
6748}; 7062};
6749 7063
7064
7065/* Macbook Air 2,1 */
7066
7067static struct hda_channel_mode alc885_mba21_ch_modes[1] = {
7068 { 2, NULL },
7069};
7070
6750/* 7071/*
6751 * macbook pro ALC885 can switch LineIn to LineOut without losing Mic 7072 * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6752 */ 7073 */
@@ -6807,6 +7128,7 @@ static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6807 { 6, alc885_mb5_ch6_init }, 7128 { 6, alc885_mb5_ch6_init },
6808}; 7129};
6809 7130
7131#define alc885_macmini3_6ch_modes alc885_mb5_6ch_modes
6810 7132
6811/* 7133/*
6812 * 2ch mode 7134 * 2ch mode
@@ -7018,6 +7340,15 @@ static struct snd_kcontrol_new alc882_base_mixer[] = {
7018 { } /* end */ 7340 { } /* end */
7019}; 7341};
7020 7342
7343/* Macbook Air 2,1 same control for HP and internal Speaker */
7344
7345static struct snd_kcontrol_new alc885_mba21_mixer[] = {
7346 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7347 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 0x02, HDA_OUTPUT),
7348 { }
7349};
7350
7351
7021static struct snd_kcontrol_new alc885_mbp3_mixer[] = { 7352static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7022 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT), 7353 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7023 HDA_BIND_MUTE ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT), 7354 HDA_BIND_MUTE ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
@@ -7040,8 +7371,8 @@ static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7040 HDA_BIND_MUTE ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT), 7371 HDA_BIND_MUTE ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7041 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT), 7372 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7042 HDA_BIND_MUTE ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT), 7373 HDA_BIND_MUTE ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7043 HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT), 7374 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7044 HDA_BIND_MUTE ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT), 7375 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
7045 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 7376 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7046 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 7377 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7047 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 7378 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
@@ -7051,6 +7382,35 @@ static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7051 { } /* end */ 7382 { } /* end */
7052}; 7383};
7053 7384
7385static struct snd_kcontrol_new alc885_macmini3_mixer[] = {
7386 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7387 HDA_BIND_MUTE ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7388 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7389 HDA_BIND_MUTE ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7390 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7391 HDA_BIND_MUTE ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7392 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7393 HDA_BIND_MUTE ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
7394 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
7395 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
7396 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7397 { } /* end */
7398};
7399
7400static struct snd_kcontrol_new alc885_imac91_mixer[] = {
7401 HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7402 HDA_BIND_MUTE ("Line-Out Playback Switch", 0x0c, 0x02, HDA_INPUT),
7403 HDA_CODEC_MUTE ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
7404 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7405 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7406 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7407 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7408 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7409 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7410 { } /* end */
7411};
7412
7413
7054static struct snd_kcontrol_new alc882_w2jc_mixer[] = { 7414static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7055 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7415 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7056 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7416 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -7128,29 +7488,18 @@ static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7128 7488
7129static struct hda_verb alc882_base_init_verbs[] = { 7489static struct hda_verb alc882_base_init_verbs[] = {
7130 /* Front mixer: unmute input/output amp left and right (volume = 0) */ 7490 /* Front mixer: unmute input/output amp left and right (volume = 0) */
7131 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7132 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7491 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7133 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7492 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7134 /* Rear mixer */ 7493 /* Rear mixer */
7135 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7136 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7494 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7137 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7495 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7138 /* CLFE mixer */ 7496 /* CLFE mixer */
7139 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7140 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7497 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7141 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7498 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7142 /* Side mixer */ 7499 /* Side mixer */
7143 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7144 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7500 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7145 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7501 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7146 7502
7147 /* mute analog input loopbacks */
7148 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7149 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7150 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7151 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7152 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7153
7154 /* Front Pin: output 0 (0x0c) */ 7503 /* Front Pin: output 0 (0x0c) */
7155 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7504 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7156 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 7505 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -7187,14 +7536,8 @@ static struct hda_verb alc882_base_init_verbs[] = {
7187 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 7536 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7188 /* Input mixer2 */ 7537 /* Input mixer2 */
7189 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7538 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7190 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7191 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7192 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7193 /* Input mixer3 */ 7539 /* Input mixer3 */
7194 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7540 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7195 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7196 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7197 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7198 /* ADC2: mute amp left and right */ 7541 /* ADC2: mute amp left and right */
7199 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7542 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7200 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, 7543 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -7238,26 +7581,17 @@ static struct hda_verb alc_hp15_unsol_verbs[] = {
7238 7581
7239static struct hda_verb alc885_init_verbs[] = { 7582static struct hda_verb alc885_init_verbs[] = {
7240 /* Front mixer: unmute input/output amp left and right (volume = 0) */ 7583 /* Front mixer: unmute input/output amp left and right (volume = 0) */
7241 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7584 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7242 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7585 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7243 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7244 /* Rear mixer */ 7586 /* Rear mixer */
7245 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7587 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7246 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7588 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7247 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7248 /* CLFE mixer */ 7589 /* CLFE mixer */
7249 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7590 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7250 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7591 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7251 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7252 /* Side mixer */ 7592 /* Side mixer */
7253 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 7593 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7254 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7594 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7255 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7256
7257 /* mute analog input loopbacks */
7258 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7259 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7260 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7261 7595
7262 /* Front HP Pin: output 0 (0x0c) */ 7596 /* Front HP Pin: output 0 (0x0c) */
7263 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 7597 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
@@ -7291,17 +7625,11 @@ static struct hda_verb alc885_init_verbs[] = {
7291 7625
7292 /* Mixer elements: 0x18, , 0x1a, 0x1b */ 7626 /* Mixer elements: 0x18, , 0x1a, 0x1b */
7293 /* Input mixer1 */ 7627 /* Input mixer1 */
7294 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, 7628 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7295 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7296 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7297 /* Input mixer2 */ 7629 /* Input mixer2 */
7298 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7630 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7299 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7300 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7301 /* Input mixer3 */ 7631 /* Input mixer3 */
7302 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, 7632 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7303 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7304 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7305 /* ADC2: mute amp left and right */ 7633 /* ADC2: mute amp left and right */
7306 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7634 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7307 /* ADC3: mute amp left and right */ 7635 /* ADC3: mute amp left and right */
@@ -7336,8 +7664,8 @@ static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7336 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT), 7664 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7337 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 7665 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7338 /* FIXME: this looks suspicious... 7666 /* FIXME: this looks suspicious...
7339 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT), 7667 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7340 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT), 7668 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7341 */ 7669 */
7342 { } /* end */ 7670 { } /* end */
7343}; 7671};
@@ -7428,6 +7756,7 @@ static struct hda_verb alc885_mb5_init_verbs[] = {
7428 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7756 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7429 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 7757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7430 {0x14, AC_VERB_SET_CONNECT_SEL, 0x03}, 7758 {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7759 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7431 /* Front Mic pin: input vref at 80% */ 7760 /* Front Mic pin: input vref at 80% */
7432 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 7761 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7433 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 7762 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
@@ -7442,6 +7771,76 @@ static struct hda_verb alc885_mb5_init_verbs[] = {
7442 { } 7771 { }
7443}; 7772};
7444 7773
7774/* Macmini 3,1 */
7775static struct hda_verb alc885_macmini3_init_verbs[] = {
7776 /* DACs */
7777 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7778 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7779 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7780 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7781 /* Front mixer */
7782 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7783 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7784 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7785 /* Surround mixer */
7786 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7787 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7788 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7789 /* LFE mixer */
7790 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7791 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7792 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7793 /* HP mixer */
7794 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7795 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7796 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7797 /* Front Pin (0x0c) */
7798 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7799 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7800 {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7801 /* LFE Pin (0x0e) */
7802 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7803 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7804 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7805 /* HP Pin (0x0f) */
7806 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7808 {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7809 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7810 /* Line In pin */
7811 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7812 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7813
7814 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7815 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7816 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7817 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7818 { }
7819};
7820
7821
7822static struct hda_verb alc885_mba21_init_verbs[] = {
7823 /*Internal and HP Speaker Mixer*/
7824 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7825 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7826 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7827 /*Internal Speaker Pin (0x0c)*/
7828 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
7829 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7830 {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7831 /* HP Pin: output 0 (0x0e) */
7832 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7834 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7835 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, (ALC880_HP_EVENT | AC_USRSP_EN)},
7836 /* Line in (is hp when jack connected)*/
7837 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_VREF_50},
7838 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7839
7840 { }
7841 };
7842
7843
7445/* Macbook Pro rev3 */ 7844/* Macbook Pro rev3 */
7446static struct hda_verb alc885_mbp3_init_verbs[] = { 7845static struct hda_verb alc885_mbp3_init_verbs[] = {
7447 /* Front mixer: unmute input/output amp left and right (volume = 0) */ 7846 /* Front mixer: unmute input/output amp left and right (volume = 0) */
@@ -7506,6 +7905,66 @@ static struct hda_verb alc885_mbp3_init_verbs[] = {
7506 { } 7905 { }
7507}; 7906};
7508 7907
7908/* iMac 9,1 */
7909static struct hda_verb alc885_imac91_init_verbs[] = {
7910 /* Line-Out mixer: unmute input/output amp left and right (volume = 0) */
7911 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7912 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7913 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7914 /* Rear mixer */
7915 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7916 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7917 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7918 /* HP Pin: output 0 (0x0c) */
7919 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7920 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7921 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7922 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7923 /* Internal Speakers: output 0 (0x0d) */
7924 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7925 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7926 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7927 /* Mic (rear) pin: input vref at 80% */
7928 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7929 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7930 /* Front Mic pin: input vref at 80% */
7931 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7932 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7933 /* Line In pin: use output 1 when in LineOut mode */
7934 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7935 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7936 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7937
7938 /* FIXME: use matrix-type input source selection */
7939 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7940 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7941 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7942 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7943 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7944 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7945 /* Input mixer2 */
7946 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7947 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7948 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7949 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7950 /* Input mixer3 */
7951 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7952 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7953 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7954 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7955 /* ADC1: mute amp left and right */
7956 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7957 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7958 /* ADC2: mute amp left and right */
7959 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7960 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7961 /* ADC3: mute amp left and right */
7962 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7963 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7964
7965 { }
7966};
7967
7509/* iMac 24 mixer. */ 7968/* iMac 24 mixer. */
7510static struct snd_kcontrol_new alc885_imac24_mixer[] = { 7969static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7511 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT), 7970 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
@@ -7544,6 +8003,20 @@ static void alc885_imac24_setup(struct hda_codec *codec)
7544 spec->autocfg.speaker_pins[1] = 0x1a; 8003 spec->autocfg.speaker_pins[1] = 0x1a;
7545} 8004}
7546 8005
8006#define alc885_mb5_setup alc885_imac24_setup
8007#define alc885_macmini3_setup alc885_imac24_setup
8008
8009/* Macbook Air 2,1 */
8010static void alc885_mba21_setup(struct hda_codec *codec)
8011{
8012 struct alc_spec *spec = codec->spec;
8013
8014 spec->autocfg.hp_pins[0] = 0x14;
8015 spec->autocfg.speaker_pins[0] = 0x18;
8016}
8017
8018
8019
7547static void alc885_mbp3_setup(struct hda_codec *codec) 8020static void alc885_mbp3_setup(struct hda_codec *codec)
7548{ 8021{
7549 struct alc_spec *spec = codec->spec; 8022 struct alc_spec *spec = codec->spec;
@@ -7552,6 +8025,14 @@ static void alc885_mbp3_setup(struct hda_codec *codec)
7552 spec->autocfg.speaker_pins[0] = 0x14; 8025 spec->autocfg.speaker_pins[0] = 0x14;
7553} 8026}
7554 8027
8028static void alc885_imac91_setup(struct hda_codec *codec)
8029{
8030 struct alc_spec *spec = codec->spec;
8031
8032 spec->autocfg.hp_pins[0] = 0x14;
8033 spec->autocfg.speaker_pins[0] = 0x15;
8034 spec->autocfg.speaker_pins[1] = 0x1a;
8035}
7555 8036
7556static struct hda_verb alc882_targa_verbs[] = { 8037static struct hda_verb alc882_targa_verbs[] = {
7557 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 8038 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -7685,18 +8166,6 @@ static struct hda_verb alc883_auto_init_verbs[] = {
7685 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00}, 8166 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7686 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 8167 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7687 8168
7688 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7689 * mixer widget
7690 * Note: PASD motherboards uses the Line In 2 as the input for
7691 * front panel mic (mic 2)
7692 */
7693 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7694 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7695 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7696 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7697 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7698 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7699
7700 /* 8169 /*
7701 * Set up output mixers (0x0c - 0x0f) 8170 * Set up output mixers (0x0c - 0x0f)
7702 */ 8171 */
@@ -7721,16 +8190,9 @@ static struct hda_verb alc883_auto_init_verbs[] = {
7721 /* FIXME: use matrix-type input source selection */ 8190 /* FIXME: use matrix-type input source selection */
7722 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 8191 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7723 /* Input mixer2 */ 8192 /* Input mixer2 */
7724 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 8193 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7725 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7726 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7727 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7728 /* Input mixer3 */ 8194 /* Input mixer3 */
7729 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 8195 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7730 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7731 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7732 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7733
7734 { } 8196 { }
7735}; 8197};
7736 8198
@@ -8026,6 +8488,42 @@ static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8026 { } /* end */ 8488 { } /* end */
8027}; 8489};
8028 8490
8491static struct snd_kcontrol_new alc883_medion_wim2160_mixer[] = {
8492 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8493 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8494 HDA_CODEC_MUTE("Speaker Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8495 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
8496 HDA_CODEC_VOLUME("Line Playback Volume", 0x08, 0x0, HDA_INPUT),
8497 HDA_CODEC_MUTE("Line Playback Switch", 0x08, 0x0, HDA_INPUT),
8498 { } /* end */
8499};
8500
8501static struct hda_verb alc883_medion_wim2160_verbs[] = {
8502 /* Unmute front mixer */
8503 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8504 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8505
8506 /* Set speaker pin to front mixer */
8507 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8508
8509 /* Init headphone pin */
8510 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8511 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8512 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8513 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8514
8515 { } /* end */
8516};
8517
8518/* toggle speaker-output according to the hp-jack state */
8519static void alc883_medion_wim2160_setup(struct hda_codec *codec)
8520{
8521 struct alc_spec *spec = codec->spec;
8522
8523 spec->autocfg.hp_pins[0] = 0x1a;
8524 spec->autocfg.speaker_pins[0] = 0x15;
8525}
8526
8029static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = { 8527static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8030 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 8528 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8031 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 8529 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -8040,9 +8538,7 @@ static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8040 8538
8041static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = { 8539static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8042 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 8540 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8043 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8044 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 8541 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8045 HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8046 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 8542 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8047 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 8543 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8048 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 8544 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
@@ -8184,12 +8680,8 @@ static void alc883_mitac_setup(struct hda_codec *codec)
8184/* 8680/*
8185static void alc883_mitac_mic_automute(struct hda_codec *codec) 8681static void alc883_mitac_mic_automute(struct hda_codec *codec)
8186{ 8682{
8187 unsigned int present; 8683 unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
8188 unsigned char bits;
8189 8684
8190 present = snd_hda_codec_read(codec, 0x18, 0,
8191 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8192 bits = present ? HDA_AMP_MUTE : 0;
8193 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 8685 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8194} 8686}
8195*/ 8687*/
@@ -8411,10 +8903,8 @@ static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8411/* toggle front-jack and RCA according to the hp-jack state */ 8903/* toggle front-jack and RCA according to the hp-jack state */
8412static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec) 8904static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8413{ 8905{
8414 unsigned int present; 8906 unsigned int present = snd_hda_jack_detect(codec, 0x1b);
8415 8907
8416 present = snd_hda_codec_read(codec, 0x1b, 0,
8417 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8418 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8908 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8419 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8909 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8420 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8910 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -8424,10 +8914,8 @@ static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8424/* toggle RCA according to the front-jack state */ 8914/* toggle RCA according to the front-jack state */
8425static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec) 8915static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8426{ 8916{
8427 unsigned int present; 8917 unsigned int present = snd_hda_jack_detect(codec, 0x14);
8428 8918
8429 present = snd_hda_codec_read(codec, 0x14, 0,
8430 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8431 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8919 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8432 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8920 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8433} 8921}
@@ -8468,8 +8956,7 @@ static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8468{ 8956{
8469 unsigned int present; 8957 unsigned int present;
8470 8958
8471 present = snd_hda_codec_read(codec, 0x18, 0, 8959 present = snd_hda_jack_detect(codec, 0x18);
8472 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8473 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, 8960 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8474 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8961 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8475} 8962}
@@ -8520,24 +9007,16 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
8520 9007
8521static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 9008static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8522{ 9009{
8523 unsigned int present; 9010 int bits = snd_hda_jack_detect(codec, 0x14) ? HDA_AMP_MUTE : 0;
8524 unsigned char bits;
8525 9011
8526 present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8527 & AC_PINSENSE_PRESENCE;
8528 bits = present ? HDA_AMP_MUTE : 0;
8529 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 9012 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8530 HDA_AMP_MUTE, bits); 9013 HDA_AMP_MUTE, bits);
8531} 9014}
8532 9015
8533static void alc883_lenovo_101e_all_automute(struct hda_codec *codec) 9016static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8534{ 9017{
8535 unsigned int present; 9018 int bits = snd_hda_jack_detect(codec, 0x1b) ? HDA_AMP_MUTE : 0;
8536 unsigned char bits;
8537 9019
8538 present = snd_hda_codec_read(codec, 0x1b, 0,
8539 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8540 bits = present ? HDA_AMP_MUTE : 0;
8541 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 9020 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8542 HDA_AMP_MUTE, bits); 9021 HDA_AMP_MUTE, bits);
8543 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 9022 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -8688,8 +9167,7 @@ static void alc889A_mb31_automute(struct hda_codec *codec)
8688 /* Mute only in 2ch or 4ch mode */ 9167 /* Mute only in 2ch or 4ch mode */
8689 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0) 9168 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8690 == 0x00) { 9169 == 0x00) {
8691 present = snd_hda_codec_read(codec, 0x15, 0, 9170 present = snd_hda_jack_detect(codec, 0x15);
8692 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8693 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 9171 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8694 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 9172 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8695 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 9173 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
@@ -8735,8 +9213,11 @@ static const char *alc882_models[ALC882_MODEL_LAST] = {
8735 [ALC882_ASUS_A7M] = "asus-a7m", 9213 [ALC882_ASUS_A7M] = "asus-a7m",
8736 [ALC885_MACPRO] = "macpro", 9214 [ALC885_MACPRO] = "macpro",
8737 [ALC885_MB5] = "mb5", 9215 [ALC885_MB5] = "mb5",
9216 [ALC885_MACMINI3] = "macmini3",
9217 [ALC885_MBA21] = "mba21",
8738 [ALC885_MBP3] = "mbp3", 9218 [ALC885_MBP3] = "mbp3",
8739 [ALC885_IMAC24] = "imac24", 9219 [ALC885_IMAC24] = "imac24",
9220 [ALC885_IMAC91] = "imac91",
8740 [ALC883_3ST_2ch_DIG] = "3stack-2ch-dig", 9221 [ALC883_3ST_2ch_DIG] = "3stack-2ch-dig",
8741 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig", 9222 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig",
8742 [ALC883_3ST_6ch] = "3stack-6ch", 9223 [ALC883_3ST_6ch] = "3stack-6ch",
@@ -8752,6 +9233,7 @@ static const char *alc882_models[ALC882_MODEL_LAST] = {
8752 [ALC888_ACER_ASPIRE_7730G] = "acer-aspire-7730g", 9233 [ALC888_ACER_ASPIRE_7730G] = "acer-aspire-7730g",
8753 [ALC883_MEDION] = "medion", 9234 [ALC883_MEDION] = "medion",
8754 [ALC883_MEDION_MD2] = "medion-md2", 9235 [ALC883_MEDION_MD2] = "medion-md2",
9236 [ALC883_MEDION_WIM2160] = "medion-wim2160",
8755 [ALC883_LAPTOP_EAPD] = "laptop-eapd", 9237 [ALC883_LAPTOP_EAPD] = "laptop-eapd",
8756 [ALC883_LENOVO_101E_2ch] = "lenovo-101e", 9238 [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8757 [ALC883_LENOVO_NB0763] = "lenovo-nb0763", 9239 [ALC883_LENOVO_NB0763] = "lenovo-nb0763",
@@ -8839,7 +9321,7 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
8839 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 9321 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8840 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG), 9322 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8841 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */ 9323 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */
8842 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG), 9324 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC882_AUTO),
8843 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG), 9325 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8844 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 9326 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8845 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG), 9327 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
@@ -8853,6 +9335,7 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
8853 SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG), 9335 SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8854 SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG), 9336 SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8855 SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG), 9337 SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
9338 SND_PCI_QUIRK(0x1462, 0x4570, "MSI Wind Top AE2220", ALC883_TARGA_DIG),
8856 SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG), 9339 SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8857 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG), 9340 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8858 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG), 9341 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
@@ -8862,10 +9345,12 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
8862 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG), 9345 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8863 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 9346 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8864 SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG), 9347 SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
9348 SND_PCI_QUIRK(0x1462, 0x7437, "MSI NetOn AP1900", ALC883_TARGA_DIG),
8865 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG), 9349 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8866 SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG), 9350 SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8867 9351
8868 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 9352 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9353 SND_PCI_QUIRK(0x1558, 0x0571, "Clevo laptop M570U", ALC883_3ST_6ch_DIG),
8869 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720), 9354 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8870 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720), 9355 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8871 SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R), 9356 SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
@@ -8893,7 +9378,7 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
8893 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL), 9378 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8894 SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL), 9379 SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8895 SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL), 9380 SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8896 SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch), 9381 SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC882_6ST_DIG),
8897 9382
8898 {} 9383 {}
8899}; 9384};
@@ -8910,12 +9395,14 @@ static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8910 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31), 9395 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8911 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3), 9396 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8912 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24), 9397 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
9398 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC885_IMAC91),
8913 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5), 9399 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8914 /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2, 9400 /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
8915 * so apparently no perfect solution yet 9401 * so apparently no perfect solution yet
8916 */ 9402 */
8917 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5), 9403 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8918 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5), 9404 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
9405 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC885_MACMINI3),
8919 {} /* terminator */ 9406 {} /* terminator */
8920}; 9407};
8921 9408
@@ -8967,6 +9454,18 @@ static struct alc_config_preset alc882_presets[] = {
8967 .input_mux = &alc882_capture_source, 9454 .input_mux = &alc882_capture_source,
8968 .dig_out_nid = ALC882_DIGOUT_NID, 9455 .dig_out_nid = ALC882_DIGOUT_NID,
8969 }, 9456 },
9457 [ALC885_MBA21] = {
9458 .mixers = { alc885_mba21_mixer },
9459 .init_verbs = { alc885_mba21_init_verbs, alc880_gpio1_init_verbs },
9460 .num_dacs = 2,
9461 .dac_nids = alc882_dac_nids,
9462 .channel_mode = alc885_mba21_ch_modes,
9463 .num_channel_mode = ARRAY_SIZE(alc885_mba21_ch_modes),
9464 .input_mux = &alc882_capture_source,
9465 .unsol_event = alc_automute_amp_unsol_event,
9466 .setup = alc885_mba21_setup,
9467 .init_hook = alc_automute_amp,
9468 },
8970 [ALC885_MBP3] = { 9469 [ALC885_MBP3] = {
8971 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer }, 9470 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8972 .init_verbs = { alc885_mbp3_init_verbs, 9471 .init_verbs = { alc885_mbp3_init_verbs,
@@ -8994,6 +9493,24 @@ static struct alc_config_preset alc882_presets[] = {
8994 .input_mux = &mb5_capture_source, 9493 .input_mux = &mb5_capture_source,
8995 .dig_out_nid = ALC882_DIGOUT_NID, 9494 .dig_out_nid = ALC882_DIGOUT_NID,
8996 .dig_in_nid = ALC882_DIGIN_NID, 9495 .dig_in_nid = ALC882_DIGIN_NID,
9496 .unsol_event = alc_automute_amp_unsol_event,
9497 .setup = alc885_mb5_setup,
9498 .init_hook = alc_automute_amp,
9499 },
9500 [ALC885_MACMINI3] = {
9501 .mixers = { alc885_macmini3_mixer, alc882_chmode_mixer },
9502 .init_verbs = { alc885_macmini3_init_verbs,
9503 alc880_gpio1_init_verbs },
9504 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9505 .dac_nids = alc882_dac_nids,
9506 .channel_mode = alc885_macmini3_6ch_modes,
9507 .num_channel_mode = ARRAY_SIZE(alc885_macmini3_6ch_modes),
9508 .input_mux = &macmini3_capture_source,
9509 .dig_out_nid = ALC882_DIGOUT_NID,
9510 .dig_in_nid = ALC882_DIGIN_NID,
9511 .unsol_event = alc_automute_amp_unsol_event,
9512 .setup = alc885_macmini3_setup,
9513 .init_hook = alc_automute_amp,
8997 }, 9514 },
8998 [ALC885_MACPRO] = { 9515 [ALC885_MACPRO] = {
8999 .mixers = { alc882_macpro_mixer }, 9516 .mixers = { alc882_macpro_mixer },
@@ -9021,6 +9538,21 @@ static struct alc_config_preset alc882_presets[] = {
9021 .setup = alc885_imac24_setup, 9538 .setup = alc885_imac24_setup,
9022 .init_hook = alc885_imac24_init_hook, 9539 .init_hook = alc885_imac24_init_hook,
9023 }, 9540 },
9541 [ALC885_IMAC91] = {
9542 .mixers = { alc885_imac91_mixer, alc882_chmode_mixer },
9543 .init_verbs = { alc885_imac91_init_verbs,
9544 alc880_gpio1_init_verbs },
9545 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9546 .dac_nids = alc882_dac_nids,
9547 .channel_mode = alc885_mbp_4ch_modes,
9548 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
9549 .input_mux = &alc882_capture_source,
9550 .dig_out_nid = ALC882_DIGOUT_NID,
9551 .dig_in_nid = ALC882_DIGIN_NID,
9552 .unsol_event = alc_automute_amp_unsol_event,
9553 .setup = alc885_imac91_setup,
9554 .init_hook = alc_automute_amp,
9555 },
9024 [ALC882_TARGA] = { 9556 [ALC882_TARGA] = {
9025 .mixers = { alc882_targa_mixer, alc882_chmode_mixer }, 9557 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9026 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs, 9558 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
@@ -9187,6 +9719,7 @@ static struct alc_config_preset alc882_presets[] = {
9187 .dac_nids = alc883_dac_nids, 9719 .dac_nids = alc883_dac_nids,
9188 .adc_nids = alc883_adc_nids_alt, 9720 .adc_nids = alc883_adc_nids_alt,
9189 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt), 9721 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9722 .capsrc_nids = alc883_capsrc_nids,
9190 .dig_out_nid = ALC883_DIGOUT_NID, 9723 .dig_out_nid = ALC883_DIGOUT_NID,
9191 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 9724 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9192 .channel_mode = alc883_3ST_2ch_modes, 9725 .channel_mode = alc883_3ST_2ch_modes,
@@ -9256,6 +9789,7 @@ static struct alc_config_preset alc882_presets[] = {
9256 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 9789 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9257 .channel_mode = alc883_3ST_6ch_modes, 9790 .channel_mode = alc883_3ST_6ch_modes,
9258 .need_dac_fix = 1, 9791 .need_dac_fix = 1,
9792 .const_channel_count = 6,
9259 .num_mux_defs = 9793 .num_mux_defs =
9260 ARRAY_SIZE(alc888_2_capture_sources), 9794 ARRAY_SIZE(alc888_2_capture_sources),
9261 .input_mux = alc888_2_capture_sources, 9795 .input_mux = alc888_2_capture_sources,
@@ -9283,10 +9817,11 @@ static struct alc_config_preset alc882_presets[] = {
9283 .init_hook = alc_automute_amp, 9817 .init_hook = alc_automute_amp,
9284 }, 9818 },
9285 [ALC888_ACER_ASPIRE_8930G] = { 9819 [ALC888_ACER_ASPIRE_8930G] = {
9286 .mixers = { alc888_base_mixer, 9820 .mixers = { alc889_acer_aspire_8930g_mixer,
9287 alc883_chmode_mixer }, 9821 alc883_chmode_mixer },
9288 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs, 9822 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9289 alc889_acer_aspire_8930g_verbs }, 9823 alc889_acer_aspire_8930g_verbs,
9824 alc889_eapd_verbs},
9290 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9825 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9291 .dac_nids = alc883_dac_nids, 9826 .dac_nids = alc883_dac_nids,
9292 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids), 9827 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
@@ -9303,6 +9838,9 @@ static struct alc_config_preset alc882_presets[] = {
9303 .unsol_event = alc_automute_amp_unsol_event, 9838 .unsol_event = alc_automute_amp_unsol_event,
9304 .setup = alc889_acer_aspire_8930g_setup, 9839 .setup = alc889_acer_aspire_8930g_setup,
9305 .init_hook = alc_automute_amp, 9840 .init_hook = alc_automute_amp,
9841#ifdef CONFIG_SND_HDA_POWER_SAVE
9842 .power_hook = alc_power_eapd,
9843#endif
9306 }, 9844 },
9307 [ALC888_ACER_ASPIRE_7730G] = { 9845 [ALC888_ACER_ASPIRE_7730G] = {
9308 .mixers = { alc883_3ST_6ch_mixer, 9846 .mixers = { alc883_3ST_6ch_mixer,
@@ -9333,6 +9871,7 @@ static struct alc_config_preset alc882_presets[] = {
9333 .dac_nids = alc883_dac_nids, 9871 .dac_nids = alc883_dac_nids,
9334 .adc_nids = alc883_adc_nids_alt, 9872 .adc_nids = alc883_adc_nids_alt,
9335 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt), 9873 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9874 .capsrc_nids = alc883_capsrc_nids,
9336 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 9875 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9337 .channel_mode = alc883_sixstack_modes, 9876 .channel_mode = alc883_sixstack_modes,
9338 .input_mux = &alc883_capture_source, 9877 .input_mux = &alc883_capture_source,
@@ -9350,6 +9889,21 @@ static struct alc_config_preset alc882_presets[] = {
9350 .setup = alc883_medion_md2_setup, 9889 .setup = alc883_medion_md2_setup,
9351 .init_hook = alc_automute_amp, 9890 .init_hook = alc_automute_amp,
9352 }, 9891 },
9892 [ALC883_MEDION_WIM2160] = {
9893 .mixers = { alc883_medion_wim2160_mixer },
9894 .init_verbs = { alc883_init_verbs, alc883_medion_wim2160_verbs },
9895 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9896 .dac_nids = alc883_dac_nids,
9897 .dig_out_nid = ALC883_DIGOUT_NID,
9898 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9899 .adc_nids = alc883_adc_nids,
9900 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9901 .channel_mode = alc883_3ST_2ch_modes,
9902 .input_mux = &alc883_capture_source,
9903 .unsol_event = alc_automute_amp_unsol_event,
9904 .setup = alc883_medion_wim2160_setup,
9905 .init_hook = alc_automute_amp,
9906 },
9353 [ALC883_LAPTOP_EAPD] = { 9907 [ALC883_LAPTOP_EAPD] = {
9354 .mixers = { alc883_base_mixer }, 9908 .mixers = { alc883_base_mixer },
9355 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs }, 9909 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
@@ -9394,6 +9948,7 @@ static struct alc_config_preset alc882_presets[] = {
9394 .dac_nids = alc883_dac_nids, 9948 .dac_nids = alc883_dac_nids,
9395 .adc_nids = alc883_adc_nids_alt, 9949 .adc_nids = alc883_adc_nids_alt,
9396 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt), 9950 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9951 .capsrc_nids = alc883_capsrc_nids,
9397 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 9952 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9398 .channel_mode = alc883_3ST_2ch_modes, 9953 .channel_mode = alc883_3ST_2ch_modes,
9399 .input_mux = &alc883_lenovo_101e_capture_source, 9954 .input_mux = &alc883_lenovo_101e_capture_source,
@@ -9573,6 +10128,7 @@ static struct alc_config_preset alc882_presets[] = {
9573 alc880_gpio1_init_verbs }, 10128 alc880_gpio1_init_verbs },
9574 .adc_nids = alc883_adc_nids, 10129 .adc_nids = alc883_adc_nids,
9575 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids), 10130 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
10131 .capsrc_nids = alc883_capsrc_nids,
9576 .dac_nids = alc883_dac_nids, 10132 .dac_nids = alc883_dac_nids,
9577 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 10133 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9578 .channel_mode = alc889A_mb31_6ch_modes, 10134 .channel_mode = alc889A_mb31_6ch_modes,
@@ -9640,6 +10196,8 @@ static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9640 int idx; 10196 int idx;
9641 10197
9642 alc_set_pin_output(codec, nid, pin_type); 10198 alc_set_pin_output(codec, nid, pin_type);
10199 if (dac_idx >= spec->multiout.num_dacs)
10200 return;
9643 if (spec->multiout.dac_nids[dac_idx] == 0x25) 10201 if (spec->multiout.dac_nids[dac_idx] == 0x25)
9644 idx = 4; 10202 idx = 4;
9645 else 10203 else
@@ -9711,6 +10269,8 @@ static void alc882_auto_init_input_src(struct hda_codec *codec)
9711 continue; 10269 continue;
9712 mux_idx = c >= spec->num_mux_defs ? 0 : c; 10270 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9713 imux = &spec->input_mux[mux_idx]; 10271 imux = &spec->input_mux[mux_idx];
10272 if (!imux->num_items && mux_idx > 0)
10273 imux = &spec->input_mux[0];
9714 for (idx = 0; idx < conns; idx++) { 10274 for (idx = 0; idx < conns; idx++) {
9715 /* if the current connection is the selected one, 10275 /* if the current connection is the selected one,
9716 * unmute it as default - otherwise mute it 10276 * unmute it as default - otherwise mute it
@@ -9833,7 +10393,7 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
9833 spec->num_mux_defs = 1; 10393 spec->num_mux_defs = 1;
9834 spec->input_mux = &spec->private_imux[0]; 10394 spec->input_mux = &spec->private_imux[0];
9835 10395
9836 alc_ssid_check(codec, 0x15, 0x1b, 0x14); 10396 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
9837 10397
9838 err = alc_auto_add_mic_boost(codec); 10398 err = alc_auto_add_mic_boost(codec);
9839 if (err < 0) 10399 if (err < 0)
@@ -9889,7 +10449,8 @@ static int patch_alc882(struct hda_codec *codec)
9889 board_config = ALC882_AUTO; 10449 board_config = ALC882_AUTO;
9890 } 10450 }
9891 10451
9892 alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups); 10452 if (board_config == ALC882_AUTO)
10453 alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups, 1);
9893 10454
9894 if (board_config == ALC882_AUTO) { 10455 if (board_config == ALC882_AUTO) {
9895 /* automatic parse from the BIOS config */ 10456 /* automatic parse from the BIOS config */
@@ -9927,10 +10488,12 @@ static int patch_alc882(struct hda_codec *codec)
9927 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */ 10488 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9928 10489
9929 if (!spec->adc_nids && spec->input_mux) { 10490 if (!spec->adc_nids && spec->input_mux) {
9930 int i; 10491 int i, j;
9931 spec->num_adc_nids = 0; 10492 spec->num_adc_nids = 0;
9932 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) { 10493 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
10494 const struct hda_input_mux *imux = spec->input_mux;
9933 hda_nid_t cap; 10495 hda_nid_t cap;
10496 hda_nid_t items[16];
9934 hda_nid_t nid = alc882_adc_nids[i]; 10497 hda_nid_t nid = alc882_adc_nids[i];
9935 unsigned int wcap = get_wcaps(codec, nid); 10498 unsigned int wcap = get_wcaps(codec, nid);
9936 /* get type */ 10499 /* get type */
@@ -9941,6 +10504,15 @@ static int patch_alc882(struct hda_codec *codec)
9941 err = snd_hda_get_connections(codec, nid, &cap, 1); 10504 err = snd_hda_get_connections(codec, nid, &cap, 1);
9942 if (err < 0) 10505 if (err < 0)
9943 continue; 10506 continue;
10507 err = snd_hda_get_connections(codec, cap, items,
10508 ARRAY_SIZE(items));
10509 if (err < 0)
10510 continue;
10511 for (j = 0; j < imux->num_items; j++)
10512 if (imux->items[j].index >= err)
10513 break;
10514 if (j < imux->num_items)
10515 continue;
9944 spec->private_capsrc_nids[spec->num_adc_nids] = cap; 10516 spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9945 spec->num_adc_nids++; 10517 spec->num_adc_nids++;
9946 } 10518 }
@@ -9951,6 +10523,9 @@ static int patch_alc882(struct hda_codec *codec)
9951 set_capture_mixer(codec); 10523 set_capture_mixer(codec);
9952 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 10524 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9953 10525
10526 if (board_config == ALC882_AUTO)
10527 alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups, 0);
10528
9954 spec->vmaster_nid = 0x0c; 10529 spec->vmaster_nid = 0x0c;
9955 10530
9956 codec->patch_ops = alc_patch_ops; 10531 codec->patch_ops = alc_patch_ops;
@@ -9960,7 +10535,6 @@ static int patch_alc882(struct hda_codec *codec)
9960 if (!spec->loopback.amplist) 10535 if (!spec->loopback.amplist)
9961 spec->loopback.amplist = alc882_loopbacks; 10536 spec->loopback.amplist = alc882_loopbacks;
9962#endif 10537#endif
9963 codec->proc_widget_hook = print_realtek_coef;
9964 10538
9965 return 0; 10539 return 0;
9966} 10540}
@@ -10032,10 +10606,8 @@ static void alc262_hp_master_update(struct hda_codec *codec)
10032static void alc262_hp_bpc_automute(struct hda_codec *codec) 10606static void alc262_hp_bpc_automute(struct hda_codec *codec)
10033{ 10607{
10034 struct alc_spec *spec = codec->spec; 10608 struct alc_spec *spec = codec->spec;
10035 unsigned int presence; 10609
10036 presence = snd_hda_codec_read(codec, 0x1b, 0, 10610 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10037 AC_VERB_GET_PIN_SENSE, 0);
10038 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10039 alc262_hp_master_update(codec); 10611 alc262_hp_master_update(codec);
10040} 10612}
10041 10613
@@ -10049,10 +10621,8 @@ static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10049static void alc262_hp_wildwest_automute(struct hda_codec *codec) 10621static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10050{ 10622{
10051 struct alc_spec *spec = codec->spec; 10623 struct alc_spec *spec = codec->spec;
10052 unsigned int presence; 10624
10053 presence = snd_hda_codec_read(codec, 0x15, 0, 10625 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10054 AC_VERB_GET_PIN_SENSE, 0);
10055 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10056 alc262_hp_master_update(codec); 10626 alc262_hp_master_update(codec);
10057} 10627}
10058 10628
@@ -10087,8 +10657,14 @@ static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10087 .info = snd_ctl_boolean_mono_info, \ 10657 .info = snd_ctl_boolean_mono_info, \
10088 .get = alc262_hp_master_sw_get, \ 10658 .get = alc262_hp_master_sw_get, \
10089 .put = alc262_hp_master_sw_put, \ 10659 .put = alc262_hp_master_sw_put, \
10660 }, \
10661 { \
10662 .iface = NID_MAPPING, \
10663 .name = "Master Playback Switch", \
10664 .private_value = 0x15 | (0x16 << 8) | (0x1b << 16), \
10090 } 10665 }
10091 10666
10667
10092static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = { 10668static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10093 ALC262_HP_MASTER_SWITCH, 10669 ALC262_HP_MASTER_SWITCH,
10094 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 10670 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -10146,7 +10722,7 @@ static void alc262_hp_t5735_setup(struct hda_codec *codec)
10146 struct alc_spec *spec = codec->spec; 10722 struct alc_spec *spec = codec->spec;
10147 10723
10148 spec->autocfg.hp_pins[0] = 0x15; 10724 spec->autocfg.hp_pins[0] = 0x15;
10149 spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */ 10725 spec->autocfg.speaker_pins[0] = 0x14;
10150} 10726}
10151 10727
10152static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = { 10728static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
@@ -10246,6 +10822,12 @@ static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10246 .info = snd_ctl_boolean_mono_info, \ 10822 .info = snd_ctl_boolean_mono_info, \
10247 .get = alc262_hippo_master_sw_get, \ 10823 .get = alc262_hippo_master_sw_get, \
10248 .put = alc262_hippo_master_sw_put, \ 10824 .put = alc262_hippo_master_sw_put, \
10825 }, \
10826 { \
10827 .iface = NID_MAPPING, \
10828 .name = "Master Playback Switch", \
10829 .subdevice = SUBDEV_HP(0) | (SUBDEV_LINE(0) << 8) | \
10830 (SUBDEV_SPEAKER(0) << 16), \
10249 } 10831 }
10250 10832
10251static struct snd_kcontrol_new alc262_hippo_mixer[] = { 10833static struct snd_kcontrol_new alc262_hippo_mixer[] = {
@@ -10286,13 +10868,8 @@ static void alc262_hippo_automute(struct hda_codec *codec)
10286{ 10868{
10287 struct alc_spec *spec = codec->spec; 10869 struct alc_spec *spec = codec->spec;
10288 hda_nid_t hp_nid = spec->autocfg.hp_pins[0]; 10870 hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10289 unsigned int present;
10290 10871
10291 /* need to execute and sync at first */ 10872 spec->jack_present = snd_hda_jack_detect(codec, hp_nid);
10292 snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10293 present = snd_hda_codec_read(codec, hp_nid, 0,
10294 AC_VERB_GET_PIN_SENSE, 0);
10295 spec->jack_present = (present & 0x80000000) != 0;
10296 alc262_hippo_master_update(codec); 10873 alc262_hippo_master_update(codec);
10297} 10874}
10298 10875
@@ -10581,6 +11158,13 @@ static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10581 {} 11158 {}
10582}; 11159};
10583 11160
11161static struct hda_verb alc262_lenovo_3000_init_verbs[] = {
11162 /* Front Mic pin: input vref at 50% */
11163 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11164 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11165 {}
11166};
11167
10584static struct hda_input_mux alc262_fujitsu_capture_source = { 11168static struct hda_input_mux alc262_fujitsu_capture_source = {
10585 .num_items = 3, 11169 .num_items = 3,
10586 .items = { 11170 .items = {
@@ -10618,21 +11202,8 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10618 unsigned int mute; 11202 unsigned int mute;
10619 11203
10620 if (force || !spec->sense_updated) { 11204 if (force || !spec->sense_updated) {
10621 unsigned int present; 11205 spec->jack_present = snd_hda_jack_detect(codec, 0x14) ||
10622 /* need to execute and sync at first */ 11206 snd_hda_jack_detect(codec, 0x1b);
10623 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10624 /* check laptop HP jack */
10625 present = snd_hda_codec_read(codec, 0x14, 0,
10626 AC_VERB_GET_PIN_SENSE, 0);
10627 /* need to execute and sync at first */
10628 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10629 /* check docking HP jack */
10630 present |= snd_hda_codec_read(codec, 0x1b, 0,
10631 AC_VERB_GET_PIN_SENSE, 0);
10632 if (present & AC_PINSENSE_PRESENCE)
10633 spec->jack_present = 1;
10634 else
10635 spec->jack_present = 0;
10636 spec->sense_updated = 1; 11207 spec->sense_updated = 1;
10637 } 11208 }
10638 /* unmute internal speaker only if both HPs are unplugged and 11209 /* unmute internal speaker only if both HPs are unplugged and
@@ -10677,12 +11248,7 @@ static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10677 unsigned int mute; 11248 unsigned int mute;
10678 11249
10679 if (force || !spec->sense_updated) { 11250 if (force || !spec->sense_updated) {
10680 unsigned int present_int_hp; 11251 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10681 /* need to execute and sync at first */
10682 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10683 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10684 AC_VERB_GET_PIN_SENSE, 0);
10685 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10686 spec->sense_updated = 1; 11252 spec->sense_updated = 1;
10687 } 11253 }
10688 if (spec->jack_present) { 11254 if (spec->jack_present) {
@@ -10742,11 +11308,17 @@ static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10742 { 11308 {
10743 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 11309 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10744 .name = "Master Playback Switch", 11310 .name = "Master Playback Switch",
11311 .subdevice = HDA_SUBDEV_AMP_FLAG,
10745 .info = snd_hda_mixer_amp_switch_info, 11312 .info = snd_hda_mixer_amp_switch_info,
10746 .get = snd_hda_mixer_amp_switch_get, 11313 .get = snd_hda_mixer_amp_switch_get,
10747 .put = alc262_fujitsu_master_sw_put, 11314 .put = alc262_fujitsu_master_sw_put,
10748 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT), 11315 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10749 }, 11316 },
11317 {
11318 .iface = NID_MAPPING,
11319 .name = "Master Playback Switch",
11320 .private_value = 0x1b,
11321 },
10750 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 11322 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10751 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 11323 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10752 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 11324 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
@@ -10777,6 +11349,7 @@ static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10777 { 11349 {
10778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 11350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10779 .name = "Master Playback Switch", 11351 .name = "Master Playback Switch",
11352 .subdevice = HDA_SUBDEV_AMP_FLAG,
10780 .info = snd_hda_mixer_amp_switch_info, 11353 .info = snd_hda_mixer_amp_switch_info,
10781 .get = snd_hda_mixer_amp_switch_get, 11354 .get = snd_hda_mixer_amp_switch_get,
10782 .put = alc262_lenovo_3000_master_sw_put, 11355 .put = alc262_lenovo_3000_master_sw_put,
@@ -10874,12 +11447,7 @@ static void alc262_ultra_automute(struct hda_codec *codec)
10874 mute = 0; 11447 mute = 0;
10875 /* auto-mute only when HP is used as HP */ 11448 /* auto-mute only when HP is used as HP */
10876 if (!spec->cur_mux[0]) { 11449 if (!spec->cur_mux[0]) {
10877 unsigned int present; 11450 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10878 /* need to execute and sync at first */
10879 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10880 present = snd_hda_codec_read(codec, 0x15, 0,
10881 AC_VERB_GET_PIN_SENSE, 0);
10882 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10883 if (spec->jack_present) 11451 if (spec->jack_present)
10884 mute = HDA_AMP_MUTE; 11452 mute = HDA_AMP_MUTE;
10885 } 11453 }
@@ -10936,6 +11504,11 @@ static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10936 .get = alc_mux_enum_get, 11504 .get = alc_mux_enum_get,
10937 .put = alc262_ultra_mux_enum_put, 11505 .put = alc262_ultra_mux_enum_put,
10938 }, 11506 },
11507 {
11508 .iface = NID_MAPPING,
11509 .name = "Capture Source",
11510 .private_value = 0x15,
11511 },
10939 { } /* end */ 11512 { } /* end */
10940}; 11513};
10941 11514
@@ -10956,7 +11529,6 @@ static int alc262_check_volbit(hda_nid_t nid)
10956static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid, 11529static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10957 const char *pfx, int *vbits) 11530 const char *pfx, int *vbits)
10958{ 11531{
10959 char name[32];
10960 unsigned long val; 11532 unsigned long val;
10961 int vbit; 11533 int vbit;
10962 11534
@@ -10966,28 +11538,25 @@ static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10966 if (*vbits & vbit) /* a volume control for this mixer already there */ 11538 if (*vbits & vbit) /* a volume control for this mixer already there */
10967 return 0; 11539 return 0;
10968 *vbits |= vbit; 11540 *vbits |= vbit;
10969 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
10970 if (vbit == 2) 11541 if (vbit == 2)
10971 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT); 11542 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10972 else 11543 else
10973 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT); 11544 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10974 return add_control(spec, ALC_CTL_WIDGET_VOL, name, val); 11545 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10975} 11546}
10976 11547
10977static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid, 11548static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10978 const char *pfx) 11549 const char *pfx)
10979{ 11550{
10980 char name[32];
10981 unsigned long val; 11551 unsigned long val;
10982 11552
10983 if (!nid) 11553 if (!nid)
10984 return 0; 11554 return 0;
10985 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
10986 if (nid == 0x16) 11555 if (nid == 0x16)
10987 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT); 11556 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10988 else 11557 else
10989 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); 11558 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10990 return add_control(spec, ALC_CTL_WIDGET_MUTE, name, val); 11559 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10991} 11560}
10992 11561
10993/* add playback controls from the parsed DAC table */ 11562/* add playback controls from the parsed DAC table */
@@ -11043,7 +11612,7 @@ static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
11043} 11612}
11044 11613
11045#define alc262_auto_create_input_ctls \ 11614#define alc262_auto_create_input_ctls \
11046 alc880_auto_create_input_ctls 11615 alc882_auto_create_input_ctls
11047 11616
11048/* 11617/*
11049 * generic initialization of ADC, input mixers and output mixers 11618 * generic initialization of ADC, input mixers and output mixers
@@ -11386,7 +11955,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
11386 if (err < 0) 11955 if (err < 0)
11387 return err; 11956 return err;
11388 11957
11389 alc_ssid_check(codec, 0x15, 0x14, 0x1b); 11958 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
11390 11959
11391 return 1; 11960 return 1;
11392} 11961}
@@ -11463,8 +12032,10 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
11463 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06), 12032 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11464 SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO), 12033 SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11465 SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO), 12034 SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
12035#if 0 /* disable the quirk since model=auto works better in recent versions */
11466 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO", 12036 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11467 ALC262_SONY_ASSAMD), 12037 ALC262_SONY_ASSAMD),
12038#endif
11468 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 12039 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11469 ALC262_TOSHIBA_RX1), 12040 ALC262_TOSHIBA_RX1),
11470 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06), 12041 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
@@ -11580,9 +12151,9 @@ static struct alc_config_preset alc262_presets[] = {
11580 .num_channel_mode = ARRAY_SIZE(alc262_modes), 12151 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11581 .channel_mode = alc262_modes, 12152 .channel_mode = alc262_modes,
11582 .input_mux = &alc262_capture_source, 12153 .input_mux = &alc262_capture_source,
11583 .unsol_event = alc_automute_amp_unsol_event, 12154 .unsol_event = alc_sku_unsol_event,
11584 .setup = alc262_hp_t5735_setup, 12155 .setup = alc262_hp_t5735_setup,
11585 .init_hook = alc_automute_amp, 12156 .init_hook = alc_inithook,
11586 }, 12157 },
11587 [ALC262_HP_RP5700] = { 12158 [ALC262_HP_RP5700] = {
11588 .mixers = { alc262_hp_rp5700_mixer }, 12159 .mixers = { alc262_hp_rp5700_mixer },
@@ -11648,7 +12219,8 @@ static struct alc_config_preset alc262_presets[] = {
11648 [ALC262_LENOVO_3000] = { 12219 [ALC262_LENOVO_3000] = {
11649 .mixers = { alc262_lenovo_3000_mixer }, 12220 .mixers = { alc262_lenovo_3000_mixer },
11650 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs, 12221 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11651 alc262_lenovo_3000_unsol_verbs }, 12222 alc262_lenovo_3000_unsol_verbs,
12223 alc262_lenovo_3000_init_verbs },
11652 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 12224 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11653 .dac_nids = alc262_dac_nids, 12225 .dac_nids = alc262_dac_nids,
11654 .hp_nid = 0x03, 12226 .hp_nid = 0x03,
@@ -11826,7 +12398,6 @@ static int patch_alc262(struct hda_codec *codec)
11826 if (!spec->loopback.amplist) 12398 if (!spec->loopback.amplist)
11827 spec->loopback.amplist = alc262_loopbacks; 12399 spec->loopback.amplist = alc262_loopbacks;
11828#endif 12400#endif
11829 codec->proc_widget_hook = print_realtek_coef;
11830 12401
11831 return 0; 12402 return 0;
11832} 12403}
@@ -11923,10 +12494,7 @@ static void alc268_acer_automute(struct hda_codec *codec, int force)
11923 unsigned int mute; 12494 unsigned int mute;
11924 12495
11925 if (force || !spec->sense_updated) { 12496 if (force || !spec->sense_updated) {
11926 unsigned int present; 12497 spec->jack_present = snd_hda_jack_detect(codec, 0x14);
11927 present = snd_hda_codec_read(codec, 0x14, 0,
11928 AC_VERB_GET_PIN_SENSE, 0);
11929 spec->jack_present = (present & 0x80000000) != 0;
11930 spec->sense_updated = 1; 12498 spec->sense_updated = 1;
11931 } 12499 }
11932 if (spec->jack_present) 12500 if (spec->jack_present)
@@ -11958,6 +12526,7 @@ static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11958 { 12526 {
11959 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11960 .name = "Master Playback Switch", 12528 .name = "Master Playback Switch",
12529 .subdevice = HDA_SUBDEV_AMP_FLAG,
11961 .info = snd_hda_mixer_amp_switch_info, 12530 .info = snd_hda_mixer_amp_switch_info,
11962 .get = snd_hda_mixer_amp_switch_get, 12531 .get = snd_hda_mixer_amp_switch_get,
11963 .put = alc268_acer_master_sw_put, 12532 .put = alc268_acer_master_sw_put,
@@ -11973,6 +12542,7 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
11973 { 12542 {
11974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12543 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11975 .name = "Master Playback Switch", 12544 .name = "Master Playback Switch",
12545 .subdevice = HDA_SUBDEV_AMP_FLAG,
11976 .info = snd_hda_mixer_amp_switch_info, 12546 .info = snd_hda_mixer_amp_switch_info,
11977 .get = snd_hda_mixer_amp_switch_get, 12547 .get = snd_hda_mixer_amp_switch_get,
11978 .put = alc268_acer_master_sw_put, 12548 .put = alc268_acer_master_sw_put,
@@ -11990,6 +12560,7 @@ static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11990 { 12560 {
11991 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12561 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11992 .name = "Master Playback Switch", 12562 .name = "Master Playback Switch",
12563 .subdevice = HDA_SUBDEV_AMP_FLAG,
11993 .info = snd_hda_mixer_amp_switch_info, 12564 .info = snd_hda_mixer_amp_switch_info,
11994 .get = snd_hda_mixer_amp_switch_get, 12565 .get = snd_hda_mixer_amp_switch_get,
11995 .put = alc268_acer_master_sw_put, 12566 .put = alc268_acer_master_sw_put,
@@ -12045,13 +12616,12 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12045 unsigned int present; 12616 unsigned int present;
12046 unsigned char bits; 12617 unsigned char bits;
12047 12618
12048 present = snd_hda_codec_read(codec, 0x15, 0, 12619 present = snd_hda_jack_detect(codec, 0x15);
12049 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 12620 bits = present ? HDA_AMP_MUTE : 0;
12050 bits = present ? AMP_IN_MUTE(0) : 0;
12051 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0, 12621 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12052 AMP_IN_MUTE(0), bits); 12622 HDA_AMP_MUTE, bits);
12053 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1, 12623 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12054 AMP_IN_MUTE(0), bits); 12624 HDA_AMP_MUTE, bits);
12055} 12625}
12056 12626
12057static void alc268_acer_lc_unsol_event(struct hda_codec *codec, 12627static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
@@ -12327,17 +12897,16 @@ static struct snd_kcontrol_new alc268_test_mixer[] = {
12327static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid, 12897static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12328 const char *ctlname, int idx) 12898 const char *ctlname, int idx)
12329{ 12899{
12330 char name[32];
12331 hda_nid_t dac; 12900 hda_nid_t dac;
12332 int err; 12901 int err;
12333 12902
12334 sprintf(name, "%s Playback Volume", ctlname);
12335 switch (nid) { 12903 switch (nid) {
12336 case 0x14: 12904 case 0x14:
12337 case 0x16: 12905 case 0x16:
12338 dac = 0x02; 12906 dac = 0x02;
12339 break; 12907 break;
12340 case 0x15: 12908 case 0x15:
12909 case 0x21: /* ALC269vb has this pin, too */
12341 dac = 0x03; 12910 dac = 0x03;
12342 break; 12911 break;
12343 default: 12912 default:
@@ -12345,7 +12914,7 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12345 } 12914 }
12346 if (spec->multiout.dac_nids[0] != dac && 12915 if (spec->multiout.dac_nids[0] != dac &&
12347 spec->multiout.dac_nids[1] != dac) { 12916 spec->multiout.dac_nids[1] != dac) {
12348 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12917 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12349 HDA_COMPOSE_AMP_VAL(dac, 3, idx, 12918 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12350 HDA_OUTPUT)); 12919 HDA_OUTPUT));
12351 if (err < 0) 12920 if (err < 0)
@@ -12353,12 +12922,11 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12353 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac; 12922 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12354 } 12923 }
12355 12924
12356 sprintf(name, "%s Playback Switch", ctlname);
12357 if (nid != 0x16) 12925 if (nid != 0x16)
12358 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12926 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12359 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT)); 12927 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12360 else /* mono */ 12928 else /* mono */
12361 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12929 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12362 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT)); 12930 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12363 if (err < 0) 12931 if (err < 0)
12364 return err; 12932 return err;
@@ -12388,8 +12956,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12388 12956
12389 nid = cfg->speaker_pins[0]; 12957 nid = cfg->speaker_pins[0];
12390 if (nid == 0x1d) { 12958 if (nid == 0x1d) {
12391 err = add_control(spec, ALC_CTL_WIDGET_VOL, 12959 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12392 "Speaker Playback Volume",
12393 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 12960 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12394 if (err < 0) 12961 if (err < 0)
12395 return err; 12962 return err;
@@ -12407,8 +12974,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12407 12974
12408 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2]; 12975 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12409 if (nid == 0x16) { 12976 if (nid == 0x16) {
12410 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 12977 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12411 "Mono Playback Switch",
12412 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT)); 12978 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12413 if (err < 0) 12979 if (err < 0)
12414 return err; 12980 return err;
@@ -12561,7 +13127,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12561 if (err < 0) 13127 if (err < 0)
12562 return err; 13128 return err;
12563 13129
12564 alc_ssid_check(codec, 0x15, 0x1b, 0x14); 13130 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
12565 13131
12566 return 1; 13132 return 1;
12567} 13133}
@@ -12794,7 +13360,7 @@ static int patch_alc268(struct hda_codec *codec)
12794 int board_config; 13360 int board_config;
12795 int i, has_beep, err; 13361 int i, has_beep, err;
12796 13362
12797 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 13363 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12798 if (spec == NULL) 13364 if (spec == NULL)
12799 return -ENOMEM; 13365 return -ENOMEM;
12800 13366
@@ -12806,7 +13372,7 @@ static int patch_alc268(struct hda_codec *codec)
12806 13372
12807 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) 13373 if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12808 board_config = snd_hda_check_board_codec_sid_config(codec, 13374 board_config = snd_hda_check_board_codec_sid_config(codec,
12809 ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl); 13375 ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12810 13376
12811 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) { 13377 if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12812 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 13378 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
@@ -12898,8 +13464,6 @@ static int patch_alc268(struct hda_codec *codec)
12898 if (board_config == ALC268_AUTO) 13464 if (board_config == ALC268_AUTO)
12899 spec->init_hook = alc268_auto_init; 13465 spec->init_hook = alc268_auto_init;
12900 13466
12901 codec->proc_widget_hook = print_realtek_coef;
12902
12903 return 0; 13467 return 0;
12904} 13468}
12905 13469
@@ -12919,9 +13483,18 @@ static hda_nid_t alc269_capsrc_nids[1] = {
12919 0x23, 13483 0x23,
12920}; 13484};
12921 13485
12922/* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24), 13486static hda_nid_t alc269vb_adc_nids[1] = {
12923 * not a mux! 13487 /* ADC1 */
12924 */ 13488 0x09,
13489};
13490
13491static hda_nid_t alc269vb_capsrc_nids[1] = {
13492 0x22,
13493};
13494
13495static hda_nid_t alc269_adc_candidates[] = {
13496 0x08, 0x09, 0x07,
13497};
12925 13498
12926#define alc269_modes alc260_modes 13499#define alc269_modes alc260_modes
12927#define alc269_capture_source alc880_lg_lw_capture_source 13500#define alc269_capture_source alc880_lg_lw_capture_source
@@ -12948,6 +13521,7 @@ static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12948 { 13521 {
12949 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 13522 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12950 .name = "Master Playback Switch", 13523 .name = "Master Playback Switch",
13524 .subdevice = HDA_SUBDEV_AMP_FLAG,
12951 .info = snd_hda_mixer_amp_switch_info, 13525 .info = snd_hda_mixer_amp_switch_info,
12952 .get = snd_hda_mixer_amp_switch_get, 13526 .get = snd_hda_mixer_amp_switch_get,
12953 .put = alc268_acer_master_sw_put, 13527 .put = alc268_acer_master_sw_put,
@@ -12968,6 +13542,7 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12968 { 13542 {
12969 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 13543 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12970 .name = "Master Playback Switch", 13544 .name = "Master Playback Switch",
13545 .subdevice = HDA_SUBDEV_AMP_FLAG,
12971 .info = snd_hda_mixer_amp_switch_info, 13546 .info = snd_hda_mixer_amp_switch_info,
12972 .get = snd_hda_mixer_amp_switch_get, 13547 .get = snd_hda_mixer_amp_switch_get,
12973 .put = alc268_acer_master_sw_put, 13548 .put = alc268_acer_master_sw_put,
@@ -12985,7 +13560,7 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12985 { } 13560 { }
12986}; 13561};
12987 13562
12988static struct snd_kcontrol_new alc269_eeepc_mixer[] = { 13563static struct snd_kcontrol_new alc269_laptop_mixer[] = {
12989 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 13564 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12990 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13565 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12991 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 13566 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
@@ -12993,16 +13568,47 @@ static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12993 { } /* end */ 13568 { } /* end */
12994}; 13569};
12995 13570
13571static struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
13572 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13573 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13574 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13575 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13576 { } /* end */
13577};
13578
12996/* capture mixer elements */ 13579/* capture mixer elements */
12997static struct snd_kcontrol_new alc269_epc_capture_mixer[] = { 13580static struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
12998 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 13581 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12999 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 13582 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13000 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 13583 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13584 HDA_CODEC_VOLUME("IntMic Boost", 0x19, 0, HDA_INPUT),
13585 { } /* end */
13586};
13587
13588static struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
13589 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13590 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13591 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13592 { } /* end */
13593};
13594
13595static struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
13596 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13597 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13598 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13599 HDA_CODEC_VOLUME("IntMic Boost", 0x19, 0, HDA_INPUT),
13600 { } /* end */
13601};
13602
13603static struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
13604 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13605 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13606 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13001 { } /* end */ 13607 { } /* end */
13002}; 13608};
13003 13609
13004/* FSC amilo */ 13610/* FSC amilo */
13005#define alc269_fujitsu_mixer alc269_eeepc_mixer 13611#define alc269_fujitsu_mixer alc269_laptop_mixer
13006 13612
13007static struct hda_verb alc269_quanta_fl1_verbs[] = { 13613static struct hda_verb alc269_quanta_fl1_verbs[] = {
13008 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 13614 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -13034,13 +13640,12 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13034 unsigned int present; 13640 unsigned int present;
13035 unsigned char bits; 13641 unsigned char bits;
13036 13642
13037 present = snd_hda_codec_read(codec, 0x15, 0, 13643 present = snd_hda_jack_detect(codec, 0x15);
13038 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 13644 bits = present ? HDA_AMP_MUTE : 0;
13039 bits = present ? AMP_IN_MUTE(0) : 0;
13040 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13645 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13041 AMP_IN_MUTE(0), bits); 13646 HDA_AMP_MUTE, bits);
13042 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 13647 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13043 AMP_IN_MUTE(0), bits); 13648 HDA_AMP_MUTE, bits);
13044 13649
13045 snd_hda_codec_write(codec, 0x20, 0, 13650 snd_hda_codec_write(codec, 0x20, 0,
13046 AC_VERB_SET_COEF_INDEX, 0x0c); 13651 AC_VERB_SET_COEF_INDEX, 0x0c);
@@ -13060,18 +13665,16 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13060 unsigned char bits; 13665 unsigned char bits;
13061 13666
13062 /* Check laptop headphone socket */ 13667 /* Check laptop headphone socket */
13063 present = snd_hda_codec_read(codec, 0x15, 0, 13668 present = snd_hda_jack_detect(codec, 0x15);
13064 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13065 13669
13066 /* Check port replicator headphone socket */ 13670 /* Check port replicator headphone socket */
13067 present |= snd_hda_codec_read(codec, 0x1a, 0, 13671 present |= snd_hda_jack_detect(codec, 0x1a);
13068 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13069 13672
13070 bits = present ? AMP_IN_MUTE(0) : 0; 13673 bits = present ? HDA_AMP_MUTE : 0;
13071 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13674 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13072 AMP_IN_MUTE(0), bits); 13675 HDA_AMP_MUTE, bits);
13073 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 13676 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13074 AMP_IN_MUTE(0), bits); 13677 HDA_AMP_MUTE, bits);
13075 13678
13076 snd_hda_codec_write(codec, 0x20, 0, 13679 snd_hda_codec_write(codec, 0x20, 0,
13077 AC_VERB_SET_COEF_INDEX, 0x0c); 13680 AC_VERB_SET_COEF_INDEX, 0x0c);
@@ -13089,11 +13692,8 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13089 unsigned int present_laptop; 13692 unsigned int present_laptop;
13090 unsigned int present_dock; 13693 unsigned int present_dock;
13091 13694
13092 present_laptop = snd_hda_codec_read(codec, 0x18, 0, 13695 present_laptop = snd_hda_jack_detect(codec, 0x18);
13093 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 13696 present_dock = snd_hda_jack_detect(codec, 0x1b);
13094
13095 present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13096 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13097 13697
13098 /* Laptop mic port overrides dock mic port, design decision */ 13698 /* Laptop mic port overrides dock mic port, design decision */
13099 if (present_dock) 13699 if (present_dock)
@@ -13132,6 +13732,8 @@ static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13132static void alc269_quanta_fl1_setup(struct hda_codec *codec) 13732static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13133{ 13733{
13134 struct alc_spec *spec = codec->spec; 13734 struct alc_spec *spec = codec->spec;
13735 spec->autocfg.hp_pins[0] = 0x15;
13736 spec->autocfg.speaker_pins[0] = 0x14;
13135 spec->ext_mic.pin = 0x18; 13737 spec->ext_mic.pin = 0x18;
13136 spec->ext_mic.mux_idx = 0; 13738 spec->ext_mic.mux_idx = 0;
13137 spec->int_mic.pin = 0x19; 13739 spec->int_mic.pin = 0x19;
@@ -13151,7 +13753,7 @@ static void alc269_lifebook_init_hook(struct hda_codec *codec)
13151 alc269_lifebook_mic_autoswitch(codec); 13753 alc269_lifebook_mic_autoswitch(codec);
13152} 13754}
13153 13755
13154static struct hda_verb alc269_eeepc_dmic_init_verbs[] = { 13756static struct hda_verb alc269_laptop_dmic_init_verbs[] = {
13155 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 13757 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13156 {0x23, AC_VERB_SET_CONNECT_SEL, 0x05}, 13758 {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13157 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 }, 13759 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
@@ -13162,7 +13764,7 @@ static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13162 {} 13764 {}
13163}; 13765};
13164 13766
13165static struct hda_verb alc269_eeepc_amic_init_verbs[] = { 13767static struct hda_verb alc269_laptop_amic_init_verbs[] = {
13166 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 13768 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13167 {0x23, AC_VERB_SET_CONNECT_SEL, 0x01}, 13769 {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13168 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 }, 13770 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
@@ -13172,23 +13774,46 @@ static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13172 {} 13774 {}
13173}; 13775};
13174 13776
13777static struct hda_verb alc269vb_laptop_dmic_init_verbs[] = {
13778 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
13779 {0x22, AC_VERB_SET_CONNECT_SEL, 0x06},
13780 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13781 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13782 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13783 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13784 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13785 {}
13786};
13787
13788static struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
13789 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
13790 {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
13791 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13792 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13793 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13794 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13795 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13796 {}
13797};
13798
13175/* toggle speaker-output according to the hp-jack state */ 13799/* toggle speaker-output according to the hp-jack state */
13176static void alc269_speaker_automute(struct hda_codec *codec) 13800static void alc269_speaker_automute(struct hda_codec *codec)
13177{ 13801{
13802 struct alc_spec *spec = codec->spec;
13803 unsigned int nid = spec->autocfg.hp_pins[0];
13178 unsigned int present; 13804 unsigned int present;
13179 unsigned char bits; 13805 unsigned char bits;
13180 13806
13181 present = snd_hda_codec_read(codec, 0x15, 0, 13807 present = snd_hda_jack_detect(codec, nid);
13182 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 13808 bits = present ? HDA_AMP_MUTE : 0;
13183 bits = present ? AMP_IN_MUTE(0) : 0;
13184 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13809 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13185 AMP_IN_MUTE(0), bits); 13810 HDA_AMP_MUTE, bits);
13186 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 13811 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13187 AMP_IN_MUTE(0), bits); 13812 HDA_AMP_MUTE, bits);
13188} 13813}
13189 13814
13190/* unsolicited event for HP jack sensing */ 13815/* unsolicited event for HP jack sensing */
13191static void alc269_eeepc_unsol_event(struct hda_codec *codec, 13816static void alc269_laptop_unsol_event(struct hda_codec *codec,
13192 unsigned int res) 13817 unsigned int res)
13193{ 13818{
13194 switch (res >> 26) { 13819 switch (res >> 26) {
@@ -13201,9 +13826,23 @@ static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13201 } 13826 }
13202} 13827}
13203 13828
13204static void alc269_eeepc_dmic_setup(struct hda_codec *codec) 13829static void alc269_laptop_amic_setup(struct hda_codec *codec)
13205{ 13830{
13206 struct alc_spec *spec = codec->spec; 13831 struct alc_spec *spec = codec->spec;
13832 spec->autocfg.hp_pins[0] = 0x15;
13833 spec->autocfg.speaker_pins[0] = 0x14;
13834 spec->ext_mic.pin = 0x18;
13835 spec->ext_mic.mux_idx = 0;
13836 spec->int_mic.pin = 0x19;
13837 spec->int_mic.mux_idx = 1;
13838 spec->auto_mic = 1;
13839}
13840
13841static void alc269_laptop_dmic_setup(struct hda_codec *codec)
13842{
13843 struct alc_spec *spec = codec->spec;
13844 spec->autocfg.hp_pins[0] = 0x15;
13845 spec->autocfg.speaker_pins[0] = 0x14;
13207 spec->ext_mic.pin = 0x18; 13846 spec->ext_mic.pin = 0x18;
13208 spec->ext_mic.mux_idx = 0; 13847 spec->ext_mic.mux_idx = 0;
13209 spec->int_mic.pin = 0x12; 13848 spec->int_mic.pin = 0x12;
@@ -13211,9 +13850,11 @@ static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13211 spec->auto_mic = 1; 13850 spec->auto_mic = 1;
13212} 13851}
13213 13852
13214static void alc269_eeepc_amic_setup(struct hda_codec *codec) 13853static void alc269vb_laptop_amic_setup(struct hda_codec *codec)
13215{ 13854{
13216 struct alc_spec *spec = codec->spec; 13855 struct alc_spec *spec = codec->spec;
13856 spec->autocfg.hp_pins[0] = 0x21;
13857 spec->autocfg.speaker_pins[0] = 0x14;
13217 spec->ext_mic.pin = 0x18; 13858 spec->ext_mic.pin = 0x18;
13218 spec->ext_mic.mux_idx = 0; 13859 spec->ext_mic.mux_idx = 0;
13219 spec->int_mic.pin = 0x19; 13860 spec->int_mic.pin = 0x19;
@@ -13221,7 +13862,19 @@ static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13221 spec->auto_mic = 1; 13862 spec->auto_mic = 1;
13222} 13863}
13223 13864
13224static void alc269_eeepc_inithook(struct hda_codec *codec) 13865static void alc269vb_laptop_dmic_setup(struct hda_codec *codec)
13866{
13867 struct alc_spec *spec = codec->spec;
13868 spec->autocfg.hp_pins[0] = 0x21;
13869 spec->autocfg.speaker_pins[0] = 0x14;
13870 spec->ext_mic.pin = 0x18;
13871 spec->ext_mic.mux_idx = 0;
13872 spec->int_mic.pin = 0x12;
13873 spec->int_mic.mux_idx = 6;
13874 spec->auto_mic = 1;
13875}
13876
13877static void alc269_laptop_inithook(struct hda_codec *codec)
13225{ 13878{
13226 alc269_speaker_automute(codec); 13879 alc269_speaker_automute(codec);
13227 alc_mic_automute(codec); 13880 alc_mic_automute(codec);
@@ -13234,22 +13887,10 @@ static struct hda_verb alc269_init_verbs[] = {
13234 /* 13887 /*
13235 * Unmute ADC0 and set the default input to mic-in 13888 * Unmute ADC0 and set the default input to mic-in
13236 */ 13889 */
13237 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 13890 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13238
13239 /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13240 * analog-loopback mixer widget
13241 * Note: PASD motherboards uses the Line In 2 as the input for
13242 * front panel mic (mic 2)
13243 */
13244 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13245 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13246 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13247 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13248 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13249 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13250 13891
13251 /* 13892 /*
13252 * Set up output mixers (0x0c - 0x0e) 13893 * Set up output mixers (0x02 - 0x03)
13253 */ 13894 */
13254 /* set vol=0 to output mixers */ 13895 /* set vol=0 to output mixers */
13255 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 13896 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
@@ -13274,26 +13915,57 @@ static struct hda_verb alc269_init_verbs[] = {
13274 13915
13275 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 13916 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13276 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 13917 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13277 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13278 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13279 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13280 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13281 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13282 13918
13283 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, 13919 /* FIXME: use Mux-type input source selection */
13284 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, 13920 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13921 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13922 {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
13285 13923
13286 /* FIXME: use matrix-type input source selection */ 13924 /* set EAPD */
13925 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13926 { }
13927};
13928
13929static struct hda_verb alc269vb_init_verbs[] = {
13930 /*
13931 * Unmute ADC0 and set the default input to mic-in
13932 */
13933 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13934
13935 /*
13936 * Set up output mixers (0x02 - 0x03)
13937 */
13938 /* set vol=0 to output mixers */
13939 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13940 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13941
13942 /* set up input amps for analog loopback */
13943 /* Amp Indices: DAC = 0, mixer = 1 */
13944 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13945 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13946 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13947 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13948 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13949 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13950
13951 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13952 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13953 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13954 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13955 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13956 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13957 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13958
13959 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13960 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13961
13962 /* FIXME: use Mux-type input source selection */
13287 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */ 13963 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13288 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */ 13964 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13289 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 13965 {0x22, AC_VERB_SET_CONNECT_SEL, 0x00},
13290 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13291 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13292 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13293 13966
13294 /* set EAPD */ 13967 /* set EAPD */
13295 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, 13968 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13296 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13297 { } 13969 { }
13298}; 13970};
13299 13971
@@ -13362,11 +14034,21 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13362 if (spec->kctls.list) 14034 if (spec->kctls.list)
13363 add_mixer(spec, spec->kctls.list); 14035 add_mixer(spec, spec->kctls.list);
13364 14036
13365 add_verb(spec, alc269_init_verbs); 14037 if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010) {
14038 add_verb(spec, alc269vb_init_verbs);
14039 alc_ssid_check(codec, 0, 0x1b, 0x14, 0x21);
14040 } else {
14041 add_verb(spec, alc269_init_verbs);
14042 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
14043 }
14044
13366 spec->num_mux_defs = 1; 14045 spec->num_mux_defs = 1;
13367 spec->input_mux = &spec->private_imux[0]; 14046 spec->input_mux = &spec->private_imux[0];
14047 fillup_priv_adc_nids(codec, alc269_adc_candidates,
14048 sizeof(alc269_adc_candidates));
14049
13368 /* set default input source */ 14050 /* set default input source */
13369 snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0], 14051 snd_hda_codec_write_cache(codec, spec->capsrc_nids[0],
13370 0, AC_VERB_SET_CONNECT_SEL, 14052 0, AC_VERB_SET_CONNECT_SEL,
13371 spec->input_mux->items[0].index); 14053 spec->input_mux->items[0].index);
13372 14054
@@ -13377,8 +14059,6 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13377 if (!spec->cap_mixer && !spec->no_analog) 14059 if (!spec->cap_mixer && !spec->no_analog)
13378 set_capture_mixer(codec); 14060 set_capture_mixer(codec);
13379 14061
13380 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13381
13382 return 1; 14062 return 1;
13383} 14063}
13384 14064
@@ -13398,14 +14078,35 @@ static void alc269_auto_init(struct hda_codec *codec)
13398 alc_inithook(codec); 14078 alc_inithook(codec);
13399} 14079}
13400 14080
14081enum {
14082 ALC269_FIXUP_SONY_VAIO,
14083};
14084
14085const static struct hda_verb alc269_sony_vaio_fixup_verbs[] = {
14086 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
14087 {}
14088};
14089
14090static const struct alc_fixup alc269_fixups[] = {
14091 [ALC269_FIXUP_SONY_VAIO] = {
14092 .verbs = alc269_sony_vaio_fixup_verbs
14093 },
14094};
14095
14096static struct snd_pci_quirk alc269_fixup_tbl[] = {
14097 SND_PCI_QUIRK(0x104d, 0x9071, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
14098 {}
14099};
14100
14101
13401/* 14102/*
13402 * configuration and preset 14103 * configuration and preset
13403 */ 14104 */
13404static const char *alc269_models[ALC269_MODEL_LAST] = { 14105static const char *alc269_models[ALC269_MODEL_LAST] = {
13405 [ALC269_BASIC] = "basic", 14106 [ALC269_BASIC] = "basic",
13406 [ALC269_QUANTA_FL1] = "quanta", 14107 [ALC269_QUANTA_FL1] = "quanta",
13407 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703", 14108 [ALC269_AMIC] = "laptop-amic",
13408 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901", 14109 [ALC269_DMIC] = "laptop-dmic",
13409 [ALC269_FUJITSU] = "fujitsu", 14110 [ALC269_FUJITSU] = "fujitsu",
13410 [ALC269_LIFEBOOK] = "lifebook", 14111 [ALC269_LIFEBOOK] = "lifebook",
13411 [ALC269_AUTO] = "auto", 14112 [ALC269_AUTO] = "auto",
@@ -13414,20 +14115,57 @@ static const char *alc269_models[ALC269_MODEL_LAST] = {
13414static struct snd_pci_quirk alc269_cfg_tbl[] = { 14115static struct snd_pci_quirk alc269_cfg_tbl[] = {
13415 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1), 14116 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13416 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", 14117 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13417 ALC269_ASUS_EEEPC_P703), 14118 ALC269_AMIC),
13418 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703), 14119 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
13419 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703), 14120 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269VB_AMIC),
13420 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703), 14121 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269VB_AMIC),
13421 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703), 14122 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_AMIC),
13422 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703), 14123 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269VB_AMIC),
13423 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703), 14124 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269VB_AMIC),
14125 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269VB_AMIC),
14126 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269VB_AMIC),
14127 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_AMIC),
14128 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82Jv", ALC269_AMIC),
14129 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_AMIC),
14130 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_AMIC),
14131 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_AMIC),
14132 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_AMIC),
14133 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_AMIC),
14134 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_AMIC),
14135 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_AMIC),
14136 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_AMIC),
14137 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_AMIC),
14138 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_AMIC),
14139 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_AMIC),
14140 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_AMIC),
14141 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_AMIC),
14142 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_AMIC),
14143 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_AMIC),
14144 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_AMIC),
14145 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_AMIC),
14146 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_AMIC),
14147 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_AMIC),
14148 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_AMIC),
14149 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_AMIC),
14150 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_DMIC),
14151 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_AMIC),
14152 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_AMIC),
14153 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_AMIC),
14154 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_AMIC),
13424 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901", 14155 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13425 ALC269_ASUS_EEEPC_P901), 14156 ALC269_DMIC),
13426 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101", 14157 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13427 ALC269_ASUS_EEEPC_P901), 14158 ALC269_DMIC),
13428 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901), 14159 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005HA", ALC269_DMIC),
13429 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU), 14160 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005HA", ALC269_DMIC),
14161 SND_PCI_QUIRK(0x104d, 0x9071, "Sony VAIO", ALC269_AUTO),
13430 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK), 14162 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
14163 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_DMIC),
14164 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
14165 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_AMIC),
14166 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_AMIC),
14167 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_DMIC),
14168 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_DMIC),
13431 {} 14169 {}
13432}; 14170};
13433 14171
@@ -13455,47 +14193,75 @@ static struct alc_config_preset alc269_presets[] = {
13455 .setup = alc269_quanta_fl1_setup, 14193 .setup = alc269_quanta_fl1_setup,
13456 .init_hook = alc269_quanta_fl1_init_hook, 14194 .init_hook = alc269_quanta_fl1_init_hook,
13457 }, 14195 },
13458 [ALC269_ASUS_EEEPC_P703] = { 14196 [ALC269_AMIC] = {
13459 .mixers = { alc269_eeepc_mixer }, 14197 .mixers = { alc269_laptop_mixer },
13460 .cap_mixer = alc269_epc_capture_mixer, 14198 .cap_mixer = alc269_laptop_analog_capture_mixer,
13461 .init_verbs = { alc269_init_verbs, 14199 .init_verbs = { alc269_init_verbs,
13462 alc269_eeepc_amic_init_verbs }, 14200 alc269_laptop_amic_init_verbs },
13463 .num_dacs = ARRAY_SIZE(alc269_dac_nids), 14201 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13464 .dac_nids = alc269_dac_nids, 14202 .dac_nids = alc269_dac_nids,
13465 .hp_nid = 0x03, 14203 .hp_nid = 0x03,
13466 .num_channel_mode = ARRAY_SIZE(alc269_modes), 14204 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13467 .channel_mode = alc269_modes, 14205 .channel_mode = alc269_modes,
13468 .unsol_event = alc269_eeepc_unsol_event, 14206 .unsol_event = alc269_laptop_unsol_event,
13469 .setup = alc269_eeepc_amic_setup, 14207 .setup = alc269_laptop_amic_setup,
13470 .init_hook = alc269_eeepc_inithook, 14208 .init_hook = alc269_laptop_inithook,
13471 }, 14209 },
13472 [ALC269_ASUS_EEEPC_P901] = { 14210 [ALC269_DMIC] = {
13473 .mixers = { alc269_eeepc_mixer }, 14211 .mixers = { alc269_laptop_mixer },
13474 .cap_mixer = alc269_epc_capture_mixer, 14212 .cap_mixer = alc269_laptop_digital_capture_mixer,
13475 .init_verbs = { alc269_init_verbs, 14213 .init_verbs = { alc269_init_verbs,
13476 alc269_eeepc_dmic_init_verbs }, 14214 alc269_laptop_dmic_init_verbs },
13477 .num_dacs = ARRAY_SIZE(alc269_dac_nids), 14215 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13478 .dac_nids = alc269_dac_nids, 14216 .dac_nids = alc269_dac_nids,
13479 .hp_nid = 0x03, 14217 .hp_nid = 0x03,
13480 .num_channel_mode = ARRAY_SIZE(alc269_modes), 14218 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13481 .channel_mode = alc269_modes, 14219 .channel_mode = alc269_modes,
13482 .unsol_event = alc269_eeepc_unsol_event, 14220 .unsol_event = alc269_laptop_unsol_event,
13483 .setup = alc269_eeepc_dmic_setup, 14221 .setup = alc269_laptop_dmic_setup,
13484 .init_hook = alc269_eeepc_inithook, 14222 .init_hook = alc269_laptop_inithook,
14223 },
14224 [ALC269VB_AMIC] = {
14225 .mixers = { alc269vb_laptop_mixer },
14226 .cap_mixer = alc269vb_laptop_analog_capture_mixer,
14227 .init_verbs = { alc269vb_init_verbs,
14228 alc269vb_laptop_amic_init_verbs },
14229 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14230 .dac_nids = alc269_dac_nids,
14231 .hp_nid = 0x03,
14232 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14233 .channel_mode = alc269_modes,
14234 .unsol_event = alc269_laptop_unsol_event,
14235 .setup = alc269vb_laptop_amic_setup,
14236 .init_hook = alc269_laptop_inithook,
14237 },
14238 [ALC269VB_DMIC] = {
14239 .mixers = { alc269vb_laptop_mixer },
14240 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
14241 .init_verbs = { alc269vb_init_verbs,
14242 alc269vb_laptop_dmic_init_verbs },
14243 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14244 .dac_nids = alc269_dac_nids,
14245 .hp_nid = 0x03,
14246 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14247 .channel_mode = alc269_modes,
14248 .unsol_event = alc269_laptop_unsol_event,
14249 .setup = alc269vb_laptop_dmic_setup,
14250 .init_hook = alc269_laptop_inithook,
13485 }, 14251 },
13486 [ALC269_FUJITSU] = { 14252 [ALC269_FUJITSU] = {
13487 .mixers = { alc269_fujitsu_mixer }, 14253 .mixers = { alc269_fujitsu_mixer },
13488 .cap_mixer = alc269_epc_capture_mixer, 14254 .cap_mixer = alc269_laptop_digital_capture_mixer,
13489 .init_verbs = { alc269_init_verbs, 14255 .init_verbs = { alc269_init_verbs,
13490 alc269_eeepc_dmic_init_verbs }, 14256 alc269_laptop_dmic_init_verbs },
13491 .num_dacs = ARRAY_SIZE(alc269_dac_nids), 14257 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13492 .dac_nids = alc269_dac_nids, 14258 .dac_nids = alc269_dac_nids,
13493 .hp_nid = 0x03, 14259 .hp_nid = 0x03,
13494 .num_channel_mode = ARRAY_SIZE(alc269_modes), 14260 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13495 .channel_mode = alc269_modes, 14261 .channel_mode = alc269_modes,
13496 .unsol_event = alc269_eeepc_unsol_event, 14262 .unsol_event = alc269_laptop_unsol_event,
13497 .setup = alc269_eeepc_dmic_setup, 14263 .setup = alc269_laptop_dmic_setup,
13498 .init_hook = alc269_eeepc_inithook, 14264 .init_hook = alc269_laptop_inithook,
13499 }, 14265 },
13500 [ALC269_LIFEBOOK] = { 14266 [ALC269_LIFEBOOK] = {
13501 .mixers = { alc269_lifebook_mixer }, 14267 .mixers = { alc269_lifebook_mixer },
@@ -13516,6 +14282,7 @@ static int patch_alc269(struct hda_codec *codec)
13516 struct alc_spec *spec; 14282 struct alc_spec *spec;
13517 int board_config; 14283 int board_config;
13518 int err; 14284 int err;
14285 int is_alc269vb = 0;
13519 14286
13520 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 14287 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13521 if (spec == NULL) 14288 if (spec == NULL)
@@ -13525,6 +14292,16 @@ static int patch_alc269(struct hda_codec *codec)
13525 14292
13526 alc_fix_pll_init(codec, 0x20, 0x04, 15); 14293 alc_fix_pll_init(codec, 0x20, 0x04, 15);
13527 14294
14295 if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010){
14296 kfree(codec->chip_name);
14297 codec->chip_name = kstrdup("ALC259", GFP_KERNEL);
14298 if (!codec->chip_name) {
14299 alc_free(codec);
14300 return -ENOMEM;
14301 }
14302 is_alc269vb = 1;
14303 }
14304
13528 board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST, 14305 board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13529 alc269_models, 14306 alc269_models,
13530 alc269_cfg_tbl); 14307 alc269_cfg_tbl);
@@ -13535,6 +14312,9 @@ static int patch_alc269(struct hda_codec *codec)
13535 board_config = ALC269_AUTO; 14312 board_config = ALC269_AUTO;
13536 } 14313 }
13537 14314
14315 if (board_config == ALC269_AUTO)
14316 alc_pick_fixup(codec, alc269_fixup_tbl, alc269_fixups, 1);
14317
13538 if (board_config == ALC269_AUTO) { 14318 if (board_config == ALC269_AUTO) {
13539 /* automatic parse from the BIOS config */ 14319 /* automatic parse from the BIOS config */
13540 err = alc269_parse_auto_config(codec); 14320 err = alc269_parse_auto_config(codec);
@@ -13558,7 +14338,7 @@ static int patch_alc269(struct hda_codec *codec)
13558 if (board_config != ALC269_AUTO) 14338 if (board_config != ALC269_AUTO)
13559 setup_preset(codec, &alc269_presets[board_config]); 14339 setup_preset(codec, &alc269_presets[board_config]);
13560 14340
13561 if (codec->subsystem_id == 0x17aa3bf8) { 14341 if (board_config == ALC269_QUANTA_FL1) {
13562 /* Due to a hardware problem on Lenovo Ideadpad, we need to 14342 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13563 * fix the sample rate of analog I/O to 44.1kHz 14343 * fix the sample rate of analog I/O to 44.1kHz
13564 */ 14344 */
@@ -13571,13 +14351,25 @@ static int patch_alc269(struct hda_codec *codec)
13571 spec->stream_digital_playback = &alc269_pcm_digital_playback; 14351 spec->stream_digital_playback = &alc269_pcm_digital_playback;
13572 spec->stream_digital_capture = &alc269_pcm_digital_capture; 14352 spec->stream_digital_capture = &alc269_pcm_digital_capture;
13573 14353
13574 spec->adc_nids = alc269_adc_nids; 14354 if (!spec->adc_nids) { /* wasn't filled automatically? use default */
13575 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); 14355 if (!is_alc269vb) {
13576 spec->capsrc_nids = alc269_capsrc_nids; 14356 spec->adc_nids = alc269_adc_nids;
14357 spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
14358 spec->capsrc_nids = alc269_capsrc_nids;
14359 } else {
14360 spec->adc_nids = alc269vb_adc_nids;
14361 spec->num_adc_nids = ARRAY_SIZE(alc269vb_adc_nids);
14362 spec->capsrc_nids = alc269vb_capsrc_nids;
14363 }
14364 }
14365
13577 if (!spec->cap_mixer) 14366 if (!spec->cap_mixer)
13578 set_capture_mixer(codec); 14367 set_capture_mixer(codec);
13579 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 14368 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13580 14369
14370 if (board_config == ALC269_AUTO)
14371 alc_pick_fixup(codec, alc269_fixup_tbl, alc269_fixups, 0);
14372
13581 spec->vmaster_nid = 0x02; 14373 spec->vmaster_nid = 0x02;
13582 14374
13583 codec->patch_ops = alc_patch_ops; 14375 codec->patch_ops = alc_patch_ops;
@@ -13587,7 +14379,6 @@ static int patch_alc269(struct hda_codec *codec)
13587 if (!spec->loopback.amplist) 14379 if (!spec->loopback.amplist)
13588 spec->loopback.amplist = alc269_loopbacks; 14380 spec->loopback.amplist = alc269_loopbacks;
13589#endif 14381#endif
13590 codec->proc_widget_hook = print_realtek_coef;
13591 14382
13592 return 0; 14383 return 0;
13593} 14384}
@@ -14157,10 +14948,8 @@ static struct hda_verb alc861_toshiba_init_verbs[] = {
14157/* toggle speaker-output according to the hp-jack state */ 14948/* toggle speaker-output according to the hp-jack state */
14158static void alc861_toshiba_automute(struct hda_codec *codec) 14949static void alc861_toshiba_automute(struct hda_codec *codec)
14159{ 14950{
14160 unsigned int present; 14951 unsigned int present = snd_hda_jack_detect(codec, 0x0f);
14161 14952
14162 present = snd_hda_codec_read(codec, 0x0f, 0,
14163 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14164 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0, 14953 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14165 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 14954 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14166 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3, 14955 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
@@ -14260,9 +15049,7 @@ static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14260static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx, 15049static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14261 hda_nid_t nid, unsigned int chs) 15050 hda_nid_t nid, unsigned int chs)
14262{ 15051{
14263 char name[32]; 15052 return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14264 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
14265 return add_control(codec->spec, ALC_CTL_WIDGET_MUTE, name,
14266 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 15053 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14267} 15054}
14268 15055
@@ -14454,7 +15241,7 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
14454 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids); 15241 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14455 set_capture_mixer(codec); 15242 set_capture_mixer(codec);
14456 15243
14457 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b); 15244 alc_ssid_check(codec, 0x0e, 0x0f, 0x0b, 0);
14458 15245
14459 return 1; 15246 return 1;
14460} 15247}
@@ -14627,6 +15414,27 @@ static struct alc_config_preset alc861_presets[] = {
14627 }, 15414 },
14628}; 15415};
14629 15416
15417/* Pin config fixes */
15418enum {
15419 PINFIX_FSC_AMILO_PI1505,
15420};
15421
15422static struct alc_pincfg alc861_fsc_amilo_pi1505_pinfix[] = {
15423 { 0x0b, 0x0221101f }, /* HP */
15424 { 0x0f, 0x90170310 }, /* speaker */
15425 { }
15426};
15427
15428static const struct alc_fixup alc861_fixups[] = {
15429 [PINFIX_FSC_AMILO_PI1505] = {
15430 .pins = alc861_fsc_amilo_pi1505_pinfix
15431 },
15432};
15433
15434static struct snd_pci_quirk alc861_fixup_tbl[] = {
15435 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
15436 {}
15437};
14630 15438
14631static int patch_alc861(struct hda_codec *codec) 15439static int patch_alc861(struct hda_codec *codec)
14632{ 15440{
@@ -14650,6 +15458,9 @@ static int patch_alc861(struct hda_codec *codec)
14650 board_config = ALC861_AUTO; 15458 board_config = ALC861_AUTO;
14651 } 15459 }
14652 15460
15461 if (board_config == ALC861_AUTO)
15462 alc_pick_fixup(codec, alc861_fixup_tbl, alc861_fixups, 1);
15463
14653 if (board_config == ALC861_AUTO) { 15464 if (board_config == ALC861_AUTO) {
14654 /* automatic parse from the BIOS config */ 15465 /* automatic parse from the BIOS config */
14655 err = alc861_parse_auto_config(codec); 15466 err = alc861_parse_auto_config(codec);
@@ -14679,18 +15490,26 @@ static int patch_alc861(struct hda_codec *codec)
14679 spec->stream_digital_playback = &alc861_pcm_digital_playback; 15490 spec->stream_digital_playback = &alc861_pcm_digital_playback;
14680 spec->stream_digital_capture = &alc861_pcm_digital_capture; 15491 spec->stream_digital_capture = &alc861_pcm_digital_capture;
14681 15492
15493 if (!spec->cap_mixer)
15494 set_capture_mixer(codec);
14682 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); 15495 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14683 15496
14684 spec->vmaster_nid = 0x03; 15497 spec->vmaster_nid = 0x03;
14685 15498
14686 codec->patch_ops = alc_patch_ops;
14687 if (board_config == ALC861_AUTO) 15499 if (board_config == ALC861_AUTO)
15500 alc_pick_fixup(codec, alc861_fixup_tbl, alc861_fixups, 0);
15501
15502 codec->patch_ops = alc_patch_ops;
15503 if (board_config == ALC861_AUTO) {
14688 spec->init_hook = alc861_auto_init; 15504 spec->init_hook = alc861_auto_init;
14689#ifdef CONFIG_SND_HDA_POWER_SAVE 15505#ifdef CONFIG_SND_HDA_POWER_SAVE
15506 spec->power_hook = alc_power_eapd;
15507#endif
15508 }
15509#ifdef CONFIG_SND_HDA_POWER_SAVE
14690 if (!spec->loopback.amplist) 15510 if (!spec->loopback.amplist)
14691 spec->loopback.amplist = alc861_loopbacks; 15511 spec->loopback.amplist = alc861_loopbacks;
14692#endif 15512#endif
14693 codec->proc_widget_hook = print_realtek_coef;
14694 15513
14695 return 0; 15514 return 0;
14696} 15515}
@@ -15067,9 +15886,9 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15067 unsigned int present; 15886 unsigned int present;
15068 unsigned char bits; 15887 unsigned char bits;
15069 15888
15070 present = snd_hda_codec_read(codec, 0x18, 0, 15889 present = snd_hda_jack_detect(codec, 0x18);
15071 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15072 bits = present ? HDA_AMP_MUTE : 0; 15890 bits = present ? HDA_AMP_MUTE : 0;
15891
15073 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, 15892 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15074 HDA_AMP_MUTE, bits); 15893 HDA_AMP_MUTE, bits);
15075} 15894}
@@ -15386,7 +16205,6 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15386static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec, 16205static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15387 const struct auto_pin_cfg *cfg) 16206 const struct auto_pin_cfg *cfg)
15388{ 16207{
15389 char name[32];
15390 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"}; 16208 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15391 hda_nid_t nid_v, nid_s; 16209 hda_nid_t nid_v, nid_s;
15392 int i, err; 16210 int i, err;
@@ -15403,26 +16221,26 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15403 16221
15404 if (i == 2) { 16222 if (i == 2) {
15405 /* Center/LFE */ 16223 /* Center/LFE */
15406 err = add_control(spec, ALC_CTL_WIDGET_VOL, 16224 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15407 "Center Playback Volume", 16225 "Center",
15408 HDA_COMPOSE_AMP_VAL(nid_v, 1, 0, 16226 HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15409 HDA_OUTPUT)); 16227 HDA_OUTPUT));
15410 if (err < 0) 16228 if (err < 0)
15411 return err; 16229 return err;
15412 err = add_control(spec, ALC_CTL_WIDGET_VOL, 16230 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15413 "LFE Playback Volume", 16231 "LFE",
15414 HDA_COMPOSE_AMP_VAL(nid_v, 2, 0, 16232 HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15415 HDA_OUTPUT)); 16233 HDA_OUTPUT));
15416 if (err < 0) 16234 if (err < 0)
15417 return err; 16235 return err;
15418 err = add_control(spec, ALC_CTL_BIND_MUTE, 16236 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15419 "Center Playback Switch", 16237 "Center",
15420 HDA_COMPOSE_AMP_VAL(nid_s, 1, 2, 16238 HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15421 HDA_INPUT)); 16239 HDA_INPUT));
15422 if (err < 0) 16240 if (err < 0)
15423 return err; 16241 return err;
15424 err = add_control(spec, ALC_CTL_BIND_MUTE, 16242 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15425 "LFE Playback Switch", 16243 "LFE",
15426 HDA_COMPOSE_AMP_VAL(nid_s, 2, 2, 16244 HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15427 HDA_INPUT)); 16245 HDA_INPUT));
15428 if (err < 0) 16246 if (err < 0)
@@ -15437,8 +16255,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15437 pfx = "PCM"; 16255 pfx = "PCM";
15438 } else 16256 } else
15439 pfx = chname[i]; 16257 pfx = chname[i];
15440 sprintf(name, "%s Playback Volume", pfx); 16258 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15441 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15442 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, 16259 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15443 HDA_OUTPUT)); 16260 HDA_OUTPUT));
15444 if (err < 0) 16261 if (err < 0)
@@ -15446,8 +16263,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15446 if (cfg->line_outs == 1 && 16263 if (cfg->line_outs == 1 &&
15447 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) 16264 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15448 pfx = "Speaker"; 16265 pfx = "Speaker";
15449 sprintf(name, "%s Playback Switch", pfx); 16266 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15450 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15451 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, 16267 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15452 HDA_INPUT)); 16268 HDA_INPUT));
15453 if (err < 0) 16269 if (err < 0)
@@ -15465,7 +16281,6 @@ static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15465{ 16281{
15466 hda_nid_t nid_v, nid_s; 16282 hda_nid_t nid_v, nid_s;
15467 int err; 16283 int err;
15468 char name[32];
15469 16284
15470 if (!pin) 16285 if (!pin)
15471 return 0; 16286 return 0;
@@ -15483,21 +16298,18 @@ static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15483 nid_s = alc861vd_idx_to_mixer_switch( 16298 nid_s = alc861vd_idx_to_mixer_switch(
15484 alc880_fixed_pin_idx(pin)); 16299 alc880_fixed_pin_idx(pin));
15485 16300
15486 sprintf(name, "%s Playback Volume", pfx); 16301 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15487 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15488 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT)); 16302 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15489 if (err < 0) 16303 if (err < 0)
15490 return err; 16304 return err;
15491 sprintf(name, "%s Playback Switch", pfx); 16305 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15492 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15493 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT)); 16306 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15494 if (err < 0) 16307 if (err < 0)
15495 return err; 16308 return err;
15496 } else if (alc880_is_multi_pin(pin)) { 16309 } else if (alc880_is_multi_pin(pin)) {
15497 /* set manual connection */ 16310 /* set manual connection */
15498 /* we have only a switch on HP-out PIN */ 16311 /* we have only a switch on HP-out PIN */
15499 sprintf(name, "%s Playback Switch", pfx); 16312 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15500 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15501 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 16313 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15502 if (err < 0) 16314 if (err < 0)
15503 return err; 16315 return err;
@@ -15560,7 +16372,7 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
15560 if (err < 0) 16372 if (err < 0)
15561 return err; 16373 return err;
15562 16374
15563 alc_ssid_check(codec, 0x15, 0x1b, 0x14); 16375 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
15564 16376
15565 return 1; 16377 return 1;
15566} 16378}
@@ -15621,7 +16433,8 @@ static int patch_alc861vd(struct hda_codec *codec)
15621 board_config = ALC861VD_AUTO; 16433 board_config = ALC861VD_AUTO;
15622 } 16434 }
15623 16435
15624 alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups); 16436 if (board_config == ALC861VD_AUTO)
16437 alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups, 1);
15625 16438
15626 if (board_config == ALC861VD_AUTO) { 16439 if (board_config == ALC861VD_AUTO) {
15627 /* automatic parse from the BIOS config */ 16440 /* automatic parse from the BIOS config */
@@ -15669,6 +16482,9 @@ static int patch_alc861vd(struct hda_codec *codec)
15669 16482
15670 spec->vmaster_nid = 0x02; 16483 spec->vmaster_nid = 0x02;
15671 16484
16485 if (board_config == ALC861VD_AUTO)
16486 alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups, 0);
16487
15672 codec->patch_ops = alc_patch_ops; 16488 codec->patch_ops = alc_patch_ops;
15673 16489
15674 if (board_config == ALC861VD_AUTO) 16490 if (board_config == ALC861VD_AUTO)
@@ -15677,7 +16493,6 @@ static int patch_alc861vd(struct hda_codec *codec)
15677 if (!spec->loopback.amplist) 16493 if (!spec->loopback.amplist)
15678 spec->loopback.amplist = alc861vd_loopbacks; 16494 spec->loopback.amplist = alc861vd_loopbacks;
15679#endif 16495#endif
15680 codec->proc_widget_hook = print_realtek_coef;
15681 16496
15682 return 0; 16497 return 0;
15683} 16498}
@@ -16083,6 +16898,52 @@ static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16083 { } /* end */ 16898 { } /* end */
16084}; 16899};
16085 16900
16901static struct hda_bind_ctls alc663_asus_mode7_8_all_bind_switch = {
16902 .ops = &snd_hda_bind_sw,
16903 .values = {
16904 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16905 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
16906 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
16907 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
16908 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
16909 0
16910 },
16911};
16912
16913static struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
16914 .ops = &snd_hda_bind_sw,
16915 .values = {
16916 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16917 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
16918 0
16919 },
16920};
16921
16922static struct snd_kcontrol_new alc663_mode7_mixer[] = {
16923 HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
16924 HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
16925 HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
16926 HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16927 HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16928 HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16929 HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16930 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16931 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16932 { } /* end */
16933};
16934
16935static struct snd_kcontrol_new alc663_mode8_mixer[] = {
16936 HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
16937 HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
16938 HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
16939 HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16940 HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16941 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16942 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16943 { } /* end */
16944};
16945
16946
16086static struct snd_kcontrol_new alc662_chmode_mixer[] = { 16947static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16087 { 16948 {
16088 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 16949 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -16098,13 +16959,6 @@ static struct hda_verb alc662_init_verbs[] = {
16098 /* ADC: mute amp left and right */ 16959 /* ADC: mute amp left and right */
16099 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 16960 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16100 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00}, 16961 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16101 /* Front mixer: unmute input/output amp left and right (volume = 0) */
16102
16103 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16104 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16105 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16106 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16107 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16108 16962
16109 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 16963 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16110 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 16964 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -16154,6 +17008,28 @@ static struct hda_verb alc662_init_verbs[] = {
16154 { } 17008 { }
16155}; 17009};
16156 17010
17011static struct hda_verb alc663_init_verbs[] = {
17012 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17014 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17015 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17016 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17017 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17018 { }
17019};
17020
17021static struct hda_verb alc272_init_verbs[] = {
17022 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17023 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17024 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17025 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17026 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17027 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17028 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17029 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17030 { }
17031};
17032
16157static struct hda_verb alc662_sue_init_verbs[] = { 17033static struct hda_verb alc662_sue_init_verbs[] = {
16158 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT}, 17034 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16159 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT}, 17035 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
@@ -16173,61 +17049,6 @@ static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16173 {} 17049 {}
16174}; 17050};
16175 17051
16176/*
16177 * generic initialization of ADC, input mixers and output mixers
16178 */
16179static struct hda_verb alc662_auto_init_verbs[] = {
16180 /*
16181 * Unmute ADC and set the default input to mic-in
16182 */
16183 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16184 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16185
16186 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16187 * mixer widget
16188 * Note: PASD motherboards uses the Line In 2 as the input for front
16189 * panel mic (mic 2)
16190 */
16191 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16192 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16193 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16194 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16195 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16196 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16197
16198 /*
16199 * Set up output mixers (0x0c - 0x0f)
16200 */
16201 /* set vol=0 to output mixers */
16202 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16203 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16204 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16205
16206 /* set up input amps for analog loopback */
16207 /* Amp Indices: DAC = 0, mixer = 1 */
16208 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16209 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16210 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16211 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16212 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16213 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16214
16215
16216 /* FIXME: use matrix-type input source selection */
16217 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16218 /* Input mixer */
16219 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16220 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16221 { }
16222};
16223
16224/* additional verbs for ALC663 */
16225static struct hda_verb alc663_auto_init_verbs[] = {
16226 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16227 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16228 { }
16229};
16230
16231static struct hda_verb alc663_m51va_init_verbs[] = { 17052static struct hda_verb alc663_m51va_init_verbs[] = {
16232 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 17053 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16233 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 17054 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
@@ -16370,6 +17191,45 @@ static struct hda_verb alc272_dell_init_verbs[] = {
16370 {} 17191 {}
16371}; 17192};
16372 17193
17194static struct hda_verb alc663_mode7_init_verbs[] = {
17195 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17196 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17197 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17199 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17200 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17201 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
17202 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17203 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17204 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
17205 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17206 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17207 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17208 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17209 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17210 {}
17211};
17212
17213static struct hda_verb alc663_mode8_init_verbs[] = {
17214 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17215 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17216 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17217 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
17218 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17219 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17220 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17221 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17222 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17223 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17224 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
17225 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17226 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17227 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17228 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17229 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17230 {}
17231};
17232
16373static struct snd_kcontrol_new alc662_auto_capture_mixer[] = { 17233static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16374 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 17234 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16375 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT), 17235 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
@@ -16387,9 +17247,9 @@ static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16387 unsigned int present; 17247 unsigned int present;
16388 unsigned char bits; 17248 unsigned char bits;
16389 17249
16390 present = snd_hda_codec_read(codec, 0x14, 0, 17250 present = snd_hda_jack_detect(codec, 0x14);
16391 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16392 bits = present ? HDA_AMP_MUTE : 0; 17251 bits = present ? HDA_AMP_MUTE : 0;
17252
16393 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 17253 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16394 HDA_AMP_MUTE, bits); 17254 HDA_AMP_MUTE, bits);
16395} 17255}
@@ -16399,9 +17259,9 @@ static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16399 unsigned int present; 17259 unsigned int present;
16400 unsigned char bits; 17260 unsigned char bits;
16401 17261
16402 present = snd_hda_codec_read(codec, 0x1b, 0, 17262 present = snd_hda_jack_detect(codec, 0x1b);
16403 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16404 bits = present ? HDA_AMP_MUTE : 0; 17263 bits = present ? HDA_AMP_MUTE : 0;
17264
16405 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 17265 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16406 HDA_AMP_MUTE, bits); 17266 HDA_AMP_MUTE, bits);
16407 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 17267 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -16460,14 +17320,12 @@ static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16460 unsigned int present; 17320 unsigned int present;
16461 unsigned char bits; 17321 unsigned char bits;
16462 17322
16463 present = snd_hda_codec_read(codec, 0x21, 0, 17323 present = snd_hda_jack_detect(codec, 0x21);
16464 AC_VERB_GET_PIN_SENSE, 0)
16465 & AC_PINSENSE_PRESENCE;
16466 bits = present ? HDA_AMP_MUTE : 0; 17324 bits = present ? HDA_AMP_MUTE : 0;
16467 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 17325 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16468 AMP_IN_MUTE(0), bits); 17326 HDA_AMP_MUTE, bits);
16469 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 17327 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16470 AMP_IN_MUTE(0), bits); 17328 HDA_AMP_MUTE, bits);
16471} 17329}
16472 17330
16473static void alc663_21jd_two_speaker_automute(struct hda_codec *codec) 17331static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
@@ -16475,18 +17333,16 @@ static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16475 unsigned int present; 17333 unsigned int present;
16476 unsigned char bits; 17334 unsigned char bits;
16477 17335
16478 present = snd_hda_codec_read(codec, 0x21, 0, 17336 present = snd_hda_jack_detect(codec, 0x21);
16479 AC_VERB_GET_PIN_SENSE, 0)
16480 & AC_PINSENSE_PRESENCE;
16481 bits = present ? HDA_AMP_MUTE : 0; 17337 bits = present ? HDA_AMP_MUTE : 0;
16482 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 17338 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16483 AMP_IN_MUTE(0), bits); 17339 HDA_AMP_MUTE, bits);
16484 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 17340 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16485 AMP_IN_MUTE(0), bits); 17341 HDA_AMP_MUTE, bits);
16486 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0, 17342 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16487 AMP_IN_MUTE(0), bits); 17343 HDA_AMP_MUTE, bits);
16488 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1, 17344 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16489 AMP_IN_MUTE(0), bits); 17345 HDA_AMP_MUTE, bits);
16490} 17346}
16491 17347
16492static void alc663_15jd_two_speaker_automute(struct hda_codec *codec) 17348static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
@@ -16494,18 +17350,16 @@ static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16494 unsigned int present; 17350 unsigned int present;
16495 unsigned char bits; 17351 unsigned char bits;
16496 17352
16497 present = snd_hda_codec_read(codec, 0x15, 0, 17353 present = snd_hda_jack_detect(codec, 0x15);
16498 AC_VERB_GET_PIN_SENSE, 0)
16499 & AC_PINSENSE_PRESENCE;
16500 bits = present ? HDA_AMP_MUTE : 0; 17354 bits = present ? HDA_AMP_MUTE : 0;
16501 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 17355 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16502 AMP_IN_MUTE(0), bits); 17356 HDA_AMP_MUTE, bits);
16503 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 17357 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16504 AMP_IN_MUTE(0), bits); 17358 HDA_AMP_MUTE, bits);
16505 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0, 17359 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16506 AMP_IN_MUTE(0), bits); 17360 HDA_AMP_MUTE, bits);
16507 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1, 17361 snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16508 AMP_IN_MUTE(0), bits); 17362 HDA_AMP_MUTE, bits);
16509} 17363}
16510 17364
16511static void alc662_f5z_speaker_automute(struct hda_codec *codec) 17365static void alc662_f5z_speaker_automute(struct hda_codec *codec)
@@ -16513,9 +17367,7 @@ static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16513 unsigned int present; 17367 unsigned int present;
16514 unsigned char bits; 17368 unsigned char bits;
16515 17369
16516 present = snd_hda_codec_read(codec, 0x1b, 0, 17370 present = snd_hda_jack_detect(codec, 0x1b);
16517 AC_VERB_GET_PIN_SENSE, 0)
16518 & AC_PINSENSE_PRESENCE;
16519 bits = present ? 0 : PIN_OUT; 17371 bits = present ? 0 : PIN_OUT;
16520 snd_hda_codec_write(codec, 0x14, 0, 17372 snd_hda_codec_write(codec, 0x14, 0,
16521 AC_VERB_SET_PIN_WIDGET_CONTROL, bits); 17373 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
@@ -16525,12 +17377,8 @@ static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16525{ 17377{
16526 unsigned int present1, present2; 17378 unsigned int present1, present2;
16527 17379
16528 present1 = snd_hda_codec_read(codec, 0x21, 0, 17380 present1 = snd_hda_jack_detect(codec, 0x21);
16529 AC_VERB_GET_PIN_SENSE, 0) 17381 present2 = snd_hda_jack_detect(codec, 0x15);
16530 & AC_PINSENSE_PRESENCE;
16531 present2 = snd_hda_codec_read(codec, 0x15, 0,
16532 AC_VERB_GET_PIN_SENSE, 0)
16533 & AC_PINSENSE_PRESENCE;
16534 17382
16535 if (present1 || present2) { 17383 if (present1 || present2) {
16536 snd_hda_codec_write_cache(codec, 0x14, 0, 17384 snd_hda_codec_write_cache(codec, 0x14, 0,
@@ -16545,23 +17393,67 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16545{ 17393{
16546 unsigned int present1, present2; 17394 unsigned int present1, present2;
16547 17395
16548 present1 = snd_hda_codec_read(codec, 0x1b, 0, 17396 present1 = snd_hda_jack_detect(codec, 0x1b);
16549 AC_VERB_GET_PIN_SENSE, 0) 17397 present2 = snd_hda_jack_detect(codec, 0x15);
16550 & AC_PINSENSE_PRESENCE;
16551 present2 = snd_hda_codec_read(codec, 0x15, 0,
16552 AC_VERB_GET_PIN_SENSE, 0)
16553 & AC_PINSENSE_PRESENCE;
16554 17398
16555 if (present1 || present2) { 17399 if (present1 || present2) {
16556 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 17400 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16557 AMP_IN_MUTE(0), AMP_IN_MUTE(0)); 17401 HDA_AMP_MUTE, HDA_AMP_MUTE);
16558 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 17402 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16559 AMP_IN_MUTE(0), AMP_IN_MUTE(0)); 17403 HDA_AMP_MUTE, HDA_AMP_MUTE);
16560 } else { 17404 } else {
16561 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 17405 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16562 AMP_IN_MUTE(0), 0); 17406 HDA_AMP_MUTE, 0);
16563 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 17407 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16564 AMP_IN_MUTE(0), 0); 17408 HDA_AMP_MUTE, 0);
17409 }
17410}
17411
17412static void alc663_two_hp_m7_speaker_automute(struct hda_codec *codec)
17413{
17414 unsigned int present1, present2;
17415
17416 present1 = snd_hda_codec_read(codec, 0x1b, 0,
17417 AC_VERB_GET_PIN_SENSE, 0)
17418 & AC_PINSENSE_PRESENCE;
17419 present2 = snd_hda_codec_read(codec, 0x21, 0,
17420 AC_VERB_GET_PIN_SENSE, 0)
17421 & AC_PINSENSE_PRESENCE;
17422
17423 if (present1 || present2) {
17424 snd_hda_codec_write_cache(codec, 0x14, 0,
17425 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
17426 snd_hda_codec_write_cache(codec, 0x17, 0,
17427 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
17428 } else {
17429 snd_hda_codec_write_cache(codec, 0x14, 0,
17430 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
17431 snd_hda_codec_write_cache(codec, 0x17, 0,
17432 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
17433 }
17434}
17435
17436static void alc663_two_hp_m8_speaker_automute(struct hda_codec *codec)
17437{
17438 unsigned int present1, present2;
17439
17440 present1 = snd_hda_codec_read(codec, 0x21, 0,
17441 AC_VERB_GET_PIN_SENSE, 0)
17442 & AC_PINSENSE_PRESENCE;
17443 present2 = snd_hda_codec_read(codec, 0x15, 0,
17444 AC_VERB_GET_PIN_SENSE, 0)
17445 & AC_PINSENSE_PRESENCE;
17446
17447 if (present1 || present2) {
17448 snd_hda_codec_write_cache(codec, 0x14, 0,
17449 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
17450 snd_hda_codec_write_cache(codec, 0x17, 0,
17451 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
17452 } else {
17453 snd_hda_codec_write_cache(codec, 0x14, 0,
17454 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
17455 snd_hda_codec_write_cache(codec, 0x17, 0,
17456 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16565 } 17457 }
16566} 17458}
16567 17459
@@ -16584,7 +17476,7 @@ static void alc663_m51va_setup(struct hda_codec *codec)
16584 spec->ext_mic.pin = 0x18; 17476 spec->ext_mic.pin = 0x18;
16585 spec->ext_mic.mux_idx = 0; 17477 spec->ext_mic.mux_idx = 0;
16586 spec->int_mic.pin = 0x12; 17478 spec->int_mic.pin = 0x12;
16587 spec->int_mic.mux_idx = 1; 17479 spec->int_mic.mux_idx = 9;
16588 spec->auto_mic = 1; 17480 spec->auto_mic = 1;
16589} 17481}
16590 17482
@@ -16596,7 +17488,17 @@ static void alc663_m51va_inithook(struct hda_codec *codec)
16596 17488
16597/* ***************** Mode1 ******************************/ 17489/* ***************** Mode1 ******************************/
16598#define alc663_mode1_unsol_event alc663_m51va_unsol_event 17490#define alc663_mode1_unsol_event alc663_m51va_unsol_event
16599#define alc663_mode1_setup alc663_m51va_setup 17491
17492static void alc663_mode1_setup(struct hda_codec *codec)
17493{
17494 struct alc_spec *spec = codec->spec;
17495 spec->ext_mic.pin = 0x18;
17496 spec->ext_mic.mux_idx = 0;
17497 spec->int_mic.pin = 0x19;
17498 spec->int_mic.mux_idx = 1;
17499 spec->auto_mic = 1;
17500}
17501
16600#define alc663_mode1_inithook alc663_m51va_inithook 17502#define alc663_mode1_inithook alc663_m51va_inithook
16601 17503
16602/* ***************** Mode2 ******************************/ 17504/* ***************** Mode2 ******************************/
@@ -16613,7 +17515,7 @@ static void alc662_mode2_unsol_event(struct hda_codec *codec,
16613 } 17515 }
16614} 17516}
16615 17517
16616#define alc662_mode2_setup alc663_m51va_setup 17518#define alc662_mode2_setup alc663_mode1_setup
16617 17519
16618static void alc662_mode2_inithook(struct hda_codec *codec) 17520static void alc662_mode2_inithook(struct hda_codec *codec)
16619{ 17521{
@@ -16634,7 +17536,7 @@ static void alc663_mode3_unsol_event(struct hda_codec *codec,
16634 } 17536 }
16635} 17537}
16636 17538
16637#define alc663_mode3_setup alc663_m51va_setup 17539#define alc663_mode3_setup alc663_mode1_setup
16638 17540
16639static void alc663_mode3_inithook(struct hda_codec *codec) 17541static void alc663_mode3_inithook(struct hda_codec *codec)
16640{ 17542{
@@ -16655,7 +17557,7 @@ static void alc663_mode4_unsol_event(struct hda_codec *codec,
16655 } 17557 }
16656} 17558}
16657 17559
16658#define alc663_mode4_setup alc663_m51va_setup 17560#define alc663_mode4_setup alc663_mode1_setup
16659 17561
16660static void alc663_mode4_inithook(struct hda_codec *codec) 17562static void alc663_mode4_inithook(struct hda_codec *codec)
16661{ 17563{
@@ -16676,7 +17578,7 @@ static void alc663_mode5_unsol_event(struct hda_codec *codec,
16676 } 17578 }
16677} 17579}
16678 17580
16679#define alc663_mode5_setup alc663_m51va_setup 17581#define alc663_mode5_setup alc663_mode1_setup
16680 17582
16681static void alc663_mode5_inithook(struct hda_codec *codec) 17583static void alc663_mode5_inithook(struct hda_codec *codec)
16682{ 17584{
@@ -16697,7 +17599,7 @@ static void alc663_mode6_unsol_event(struct hda_codec *codec,
16697 } 17599 }
16698} 17600}
16699 17601
16700#define alc663_mode6_setup alc663_m51va_setup 17602#define alc663_mode6_setup alc663_mode1_setup
16701 17603
16702static void alc663_mode6_inithook(struct hda_codec *codec) 17604static void alc663_mode6_inithook(struct hda_codec *codec)
16703{ 17605{
@@ -16705,14 +17607,56 @@ static void alc663_mode6_inithook(struct hda_codec *codec)
16705 alc_mic_automute(codec); 17607 alc_mic_automute(codec);
16706} 17608}
16707 17609
17610/* ***************** Mode7 ******************************/
17611static void alc663_mode7_unsol_event(struct hda_codec *codec,
17612 unsigned int res)
17613{
17614 switch (res >> 26) {
17615 case ALC880_HP_EVENT:
17616 alc663_two_hp_m7_speaker_automute(codec);
17617 break;
17618 case ALC880_MIC_EVENT:
17619 alc_mic_automute(codec);
17620 break;
17621 }
17622}
17623
17624#define alc663_mode7_setup alc663_mode1_setup
17625
17626static void alc663_mode7_inithook(struct hda_codec *codec)
17627{
17628 alc663_two_hp_m7_speaker_automute(codec);
17629 alc_mic_automute(codec);
17630}
17631
17632/* ***************** Mode8 ******************************/
17633static void alc663_mode8_unsol_event(struct hda_codec *codec,
17634 unsigned int res)
17635{
17636 switch (res >> 26) {
17637 case ALC880_HP_EVENT:
17638 alc663_two_hp_m8_speaker_automute(codec);
17639 break;
17640 case ALC880_MIC_EVENT:
17641 alc_mic_automute(codec);
17642 break;
17643 }
17644}
17645
17646#define alc663_mode8_setup alc663_m51va_setup
17647
17648static void alc663_mode8_inithook(struct hda_codec *codec)
17649{
17650 alc663_two_hp_m8_speaker_automute(codec);
17651 alc_mic_automute(codec);
17652}
17653
16708static void alc663_g71v_hp_automute(struct hda_codec *codec) 17654static void alc663_g71v_hp_automute(struct hda_codec *codec)
16709{ 17655{
16710 unsigned int present; 17656 unsigned int present;
16711 unsigned char bits; 17657 unsigned char bits;
16712 17658
16713 present = snd_hda_codec_read(codec, 0x21, 0, 17659 present = snd_hda_jack_detect(codec, 0x21);
16714 AC_VERB_GET_PIN_SENSE, 0)
16715 & AC_PINSENSE_PRESENCE;
16716 bits = present ? HDA_AMP_MUTE : 0; 17660 bits = present ? HDA_AMP_MUTE : 0;
16717 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 17661 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16718 HDA_AMP_MUTE, bits); 17662 HDA_AMP_MUTE, bits);
@@ -16725,9 +17669,7 @@ static void alc663_g71v_front_automute(struct hda_codec *codec)
16725 unsigned int present; 17669 unsigned int present;
16726 unsigned char bits; 17670 unsigned char bits;
16727 17671
16728 present = snd_hda_codec_read(codec, 0x15, 0, 17672 present = snd_hda_jack_detect(codec, 0x15);
16729 AC_VERB_GET_PIN_SENSE, 0)
16730 & AC_PINSENSE_PRESENCE;
16731 bits = present ? HDA_AMP_MUTE : 0; 17673 bits = present ? HDA_AMP_MUTE : 0;
16732 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 17674 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16733 HDA_AMP_MUTE, bits); 17675 HDA_AMP_MUTE, bits);
@@ -16843,6 +17785,8 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
16843 [ALC663_ASUS_MODE4] = "asus-mode4", 17785 [ALC663_ASUS_MODE4] = "asus-mode4",
16844 [ALC663_ASUS_MODE5] = "asus-mode5", 17786 [ALC663_ASUS_MODE5] = "asus-mode5",
16845 [ALC663_ASUS_MODE6] = "asus-mode6", 17787 [ALC663_ASUS_MODE6] = "asus-mode6",
17788 [ALC663_ASUS_MODE7] = "asus-mode7",
17789 [ALC663_ASUS_MODE8] = "asus-mode8",
16846 [ALC272_DELL] = "dell", 17790 [ALC272_DELL] = "dell",
16847 [ALC272_DELL_ZM1] = "dell-zm1", 17791 [ALC272_DELL_ZM1] = "dell-zm1",
16848 [ALC272_SAMSUNG_NC10] = "samsung-nc10", 17792 [ALC272_SAMSUNG_NC10] = "samsung-nc10",
@@ -16855,16 +17799,27 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16855 SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1), 17799 SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16856 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1), 17800 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16857 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3), 17801 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
17802 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC663_ASUS_MODE1),
16858 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3), 17803 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16859 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1), 17804 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16860 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2), 17805 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16861 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1), 17806 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
17807 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
17808 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
16862 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2), 17809 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
17810 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
17811 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
17812 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
17813 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
17814 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
16863 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2), 17815 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
17816 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
17817 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
16864 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2), 17818 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16865 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6), 17819 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16866 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6), 17820 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16867 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2), 17821 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
17822 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
16868 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3), 17823 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16869 SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA), 17824 SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16870 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2), 17825 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
@@ -16880,6 +17835,7 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16880 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3), 17835 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16881 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3), 17836 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16882 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1), 17837 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
17838 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC663_ASUS_MODE1),
16883 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1), 17839 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16884 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1), 17840 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16885 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1), 17841 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
@@ -16903,10 +17859,11 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16903 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS), 17859 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16904 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K", 17860 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16905 ALC662_3ST_6ch_DIG), 17861 ALC662_3ST_6ch_DIG),
16906 SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4), 17862 SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB20x", ALC662_AUTO),
16907 SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10), 17863 SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16908 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L", 17864 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16909 ALC662_3ST_6ch_DIG), 17865 ALC662_3ST_6ch_DIG),
17866 SND_PCI_QUIRK(0x152d, 0x2304, "Quanta WH1", ALC663_ASUS_H13),
16910 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG), 17867 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16911 SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA), 17868 SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16912 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E), 17869 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
@@ -17147,6 +18104,36 @@ static struct alc_config_preset alc662_presets[] = {
17147 .setup = alc663_mode6_setup, 18104 .setup = alc663_mode6_setup,
17148 .init_hook = alc663_mode6_inithook, 18105 .init_hook = alc663_mode6_inithook,
17149 }, 18106 },
18107 [ALC663_ASUS_MODE7] = {
18108 .mixers = { alc663_mode7_mixer },
18109 .cap_mixer = alc662_auto_capture_mixer,
18110 .init_verbs = { alc662_init_verbs,
18111 alc663_mode7_init_verbs },
18112 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18113 .hp_nid = 0x03,
18114 .dac_nids = alc662_dac_nids,
18115 .dig_out_nid = ALC662_DIGOUT_NID,
18116 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18117 .channel_mode = alc662_3ST_2ch_modes,
18118 .unsol_event = alc663_mode7_unsol_event,
18119 .setup = alc663_mode7_setup,
18120 .init_hook = alc663_mode7_inithook,
18121 },
18122 [ALC663_ASUS_MODE8] = {
18123 .mixers = { alc663_mode8_mixer },
18124 .cap_mixer = alc662_auto_capture_mixer,
18125 .init_verbs = { alc662_init_verbs,
18126 alc663_mode8_init_verbs },
18127 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18128 .hp_nid = 0x03,
18129 .dac_nids = alc662_dac_nids,
18130 .dig_out_nid = ALC662_DIGOUT_NID,
18131 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18132 .channel_mode = alc662_3ST_2ch_modes,
18133 .unsol_event = alc663_mode8_unsol_event,
18134 .setup = alc663_mode8_setup,
18135 .init_hook = alc663_mode8_inithook,
18136 },
17150 [ALC272_DELL] = { 18137 [ALC272_DELL] = {
17151 .mixers = { alc663_m51va_mixer }, 18138 .mixers = { alc663_m51va_mixer },
17152 .cap_mixer = alc272_auto_capture_mixer, 18139 .cap_mixer = alc272_auto_capture_mixer,
@@ -17264,21 +18251,17 @@ static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17264 return 0; 18251 return 0;
17265} 18252}
17266 18253
17267static int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx, 18254static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17268 hda_nid_t nid, unsigned int chs) 18255 hda_nid_t nid, unsigned int chs)
17269{ 18256{
17270 char name[32]; 18257 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17271 sprintf(name, "%s Playback Volume", pfx);
17272 return add_control(spec, ALC_CTL_WIDGET_VOL, name,
17273 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 18258 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17274} 18259}
17275 18260
17276static int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx, 18261static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17277 hda_nid_t nid, unsigned int chs) 18262 hda_nid_t nid, unsigned int chs)
17278{ 18263{
17279 char name[32]; 18264 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17280 sprintf(name, "%s Playback Switch", pfx);
17281 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17282 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT)); 18265 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17283} 18266}
17284 18267
@@ -17356,13 +18339,11 @@ static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17356 return 0; 18339 return 0;
17357 nid = alc662_look_for_dac(codec, pin); 18340 nid = alc662_look_for_dac(codec, pin);
17358 if (!nid) { 18341 if (!nid) {
17359 char name[32];
17360 /* the corresponding DAC is already occupied */ 18342 /* the corresponding DAC is already occupied */
17361 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) 18343 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17362 return 0; /* no way */ 18344 return 0; /* no way */
17363 /* create a switch only */ 18345 /* create a switch only */
17364 sprintf(name, "%s Playback Switch", pfx); 18346 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17365 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17366 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 18347 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17367 } 18348 }
17368 18349
@@ -17500,15 +18481,23 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
17500 spec->num_mux_defs = 1; 18481 spec->num_mux_defs = 1;
17501 spec->input_mux = &spec->private_imux[0]; 18482 spec->input_mux = &spec->private_imux[0];
17502 18483
17503 add_verb(spec, alc662_auto_init_verbs); 18484 add_verb(spec, alc662_init_verbs);
17504 if (codec->vendor_id == 0x10ec0663) 18485 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
17505 add_verb(spec, alc663_auto_init_verbs); 18486 codec->vendor_id == 0x10ec0665)
18487 add_verb(spec, alc663_init_verbs);
18488
18489 if (codec->vendor_id == 0x10ec0272)
18490 add_verb(spec, alc272_init_verbs);
17506 18491
17507 err = alc_auto_add_mic_boost(codec); 18492 err = alc_auto_add_mic_boost(codec);
17508 if (err < 0) 18493 if (err < 0)
17509 return err; 18494 return err;
17510 18495
17511 alc_ssid_check(codec, 0x15, 0x1b, 0x14); 18496 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
18497 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
18498 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0x21);
18499 else
18500 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
17512 18501
17513 return 1; 18502 return 1;
17514} 18503}
@@ -17538,6 +18527,15 @@ static int patch_alc662(struct hda_codec *codec)
17538 18527
17539 alc_fix_pll_init(codec, 0x20, 0x04, 15); 18528 alc_fix_pll_init(codec, 0x20, 0x04, 15);
17540 18529
18530 if (alc_read_coef_idx(codec, 0)==0x8020){
18531 kfree(codec->chip_name);
18532 codec->chip_name = kstrdup("ALC661", GFP_KERNEL);
18533 if (!codec->chip_name) {
18534 alc_free(codec);
18535 return -ENOMEM;
18536 }
18537 }
18538
17541 board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST, 18539 board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17542 alc662_models, 18540 alc662_models,
17543 alc662_cfg_tbl); 18541 alc662_cfg_tbl);
@@ -17585,11 +18583,20 @@ static int patch_alc662(struct hda_codec *codec)
17585 18583
17586 if (!spec->cap_mixer) 18584 if (!spec->cap_mixer)
17587 set_capture_mixer(codec); 18585 set_capture_mixer(codec);
17588 if (codec->vendor_id == 0x10ec0662) 18586
18587 switch (codec->vendor_id) {
18588 case 0x10ec0662:
17589 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 18589 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17590 else 18590 break;
18591 case 0x10ec0272:
18592 case 0x10ec0663:
18593 case 0x10ec0665:
17591 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 18594 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17592 18595 break;
18596 case 0x10ec0273:
18597 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
18598 break;
18599 }
17593 spec->vmaster_nid = 0x02; 18600 spec->vmaster_nid = 0x02;
17594 18601
17595 codec->patch_ops = alc_patch_ops; 18602 codec->patch_ops = alc_patch_ops;
@@ -17599,11 +18606,24 @@ static int patch_alc662(struct hda_codec *codec)
17599 if (!spec->loopback.amplist) 18606 if (!spec->loopback.amplist)
17600 spec->loopback.amplist = alc662_loopbacks; 18607 spec->loopback.amplist = alc662_loopbacks;
17601#endif 18608#endif
17602 codec->proc_widget_hook = print_realtek_coef;
17603 18609
17604 return 0; 18610 return 0;
17605} 18611}
17606 18612
18613static int patch_alc888(struct hda_codec *codec)
18614{
18615 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
18616 kfree(codec->chip_name);
18617 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
18618 if (!codec->chip_name) {
18619 alc_free(codec);
18620 return -ENOMEM;
18621 }
18622 return patch_alc662(codec);
18623 }
18624 return patch_alc882(codec);
18625}
18626
17607/* 18627/*
17608 * patch entries 18628 * patch entries
17609 */ 18629 */
@@ -17613,7 +18633,9 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17613 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, 18633 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17614 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, 18634 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17615 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, 18635 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
18636 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
17616 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, 18637 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
18638 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
17617 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", 18639 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17618 .patch = patch_alc861 }, 18640 .patch = patch_alc861 },
17619 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, 18641 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
@@ -17624,6 +18646,8 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17624 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", 18646 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17625 .patch = patch_alc662 }, 18647 .patch = patch_alc662 },
17626 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, 18648 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
18649 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
18650 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
17627 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 18651 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17628 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 18652 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17629 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 }, 18653 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
@@ -17635,8 +18659,9 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17635 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, 18659 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17636 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 18660 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17637 .patch = patch_alc882 }, 18661 .patch = patch_alc882 },
17638 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, 18662 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
17639 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, 18663 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
18664 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
17640 {} /* terminator */ 18665 {} /* terminator */
17641}; 18666};
17642 18667
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index 43b436c5d01b..f419ee8d75f0 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -122,6 +122,7 @@ static int si3054_switch_put(struct snd_kcontrol *kcontrol,
122#define SI3054_KCONTROL(kname,reg,mask) { \ 122#define SI3054_KCONTROL(kname,reg,mask) { \
123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
124 .name = kname, \ 124 .name = kname, \
125 .subdevice = HDA_SUBDEV_NID_FLAG | reg, \
125 .info = si3054_switch_info, \ 126 .info = si3054_switch_info, \
126 .get = si3054_switch_get, \ 127 .get = si3054_switch_get, \
127 .put = si3054_switch_put, \ 128 .put = si3054_switch_put, \
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 86de305fc9f2..a0e06d82da1f 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -93,6 +93,7 @@ enum {
93 STAC_92HD83XXX_REF, 93 STAC_92HD83XXX_REF,
94 STAC_92HD83XXX_PWR_REF, 94 STAC_92HD83XXX_PWR_REF,
95 STAC_DELL_S14, 95 STAC_DELL_S14,
96 STAC_92HD83XXX_HP,
96 STAC_92HD83XXX_MODELS 97 STAC_92HD83XXX_MODELS
97}; 98};
98 99
@@ -103,6 +104,7 @@ enum {
103 STAC_DELL_M4_2, 104 STAC_DELL_M4_2,
104 STAC_DELL_M4_3, 105 STAC_DELL_M4_3,
105 STAC_HP_M4, 106 STAC_HP_M4,
107 STAC_HP_DV4,
106 STAC_HP_DV5, 108 STAC_HP_DV5,
107 STAC_HP_HDX, 109 STAC_HP_HDX,
108 STAC_HP_DV4_1222NR, 110 STAC_HP_DV4_1222NR,
@@ -208,6 +210,7 @@ struct sigmatel_spec {
208 unsigned int gpio_data; 210 unsigned int gpio_data;
209 unsigned int gpio_mute; 211 unsigned int gpio_mute;
210 unsigned int gpio_led; 212 unsigned int gpio_led;
213 unsigned int gpio_led_polarity;
211 214
212 /* stream */ 215 /* stream */
213 unsigned int stream_delay; 216 unsigned int stream_delay;
@@ -566,6 +569,11 @@ static hda_nid_t stac92hd83xxx_pin_nids[10] = {
566 0x0f, 0x10, 0x11, 0x1f, 0x20, 569 0x0f, 0x10, 0x11, 0x1f, 0x20,
567}; 570};
568 571
572static hda_nid_t stac92hd88xxx_pin_nids[10] = {
573 0x0a, 0x0b, 0x0c, 0x0d,
574 0x0f, 0x11, 0x1f, 0x20,
575};
576
569#define STAC92HD71BXX_NUM_PINS 13 577#define STAC92HD71BXX_NUM_PINS 13
570static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = { 578static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
571 0x0a, 0x0b, 0x0c, 0x0d, 0x00, 579 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
@@ -1085,7 +1093,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1085 if (!spec->auto_mic && spec->num_dmuxes > 0 && 1093 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1086 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) { 1094 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1087 stac_dmux_mixer.count = spec->num_dmuxes; 1095 stac_dmux_mixer.count = spec->num_dmuxes;
1088 err = snd_hda_ctl_add(codec, 1096 err = snd_hda_ctl_add(codec, 0,
1089 snd_ctl_new1(&stac_dmux_mixer, codec)); 1097 snd_ctl_new1(&stac_dmux_mixer, codec));
1090 if (err < 0) 1098 if (err < 0)
1091 return err; 1099 return err;
@@ -1101,7 +1109,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1101 spec->spdif_mute = 1; 1109 spec->spdif_mute = 1;
1102 } 1110 }
1103 stac_smux_mixer.count = spec->num_smuxes; 1111 stac_smux_mixer.count = spec->num_smuxes;
1104 err = snd_hda_ctl_add(codec, 1112 err = snd_hda_ctl_add(codec, 0,
1105 snd_ctl_new1(&stac_smux_mixer, codec)); 1113 snd_ctl_new1(&stac_smux_mixer, codec));
1106 if (err < 0) 1114 if (err < 0)
1107 return err; 1115 return err;
@@ -1537,6 +1545,11 @@ static unsigned int alienware_m17x_pin_configs[13] = {
1537 0x904601b0, 1545 0x904601b0,
1538}; 1546};
1539 1547
1548static unsigned int intel_dg45id_pin_configs[13] = {
1549 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1550 0x01A19250, 0x01011212, 0x01016211
1551};
1552
1540static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1553static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1541 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1554 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1542 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs, 1555 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
@@ -1544,6 +1557,7 @@ static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1544 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs, 1557 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1545 [STAC_DELL_EQ] = dell_m6_pin_configs, 1558 [STAC_DELL_EQ] = dell_m6_pin_configs,
1546 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs, 1559 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1560 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
1547}; 1561};
1548 1562
1549static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1563static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
@@ -1592,6 +1606,10 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1592 "Dell Studio 1555", STAC_DELL_M6_DMIC), 1606 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd, 1607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1594 "Dell Studio 1557", STAC_DELL_M6_DMIC), 1608 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1610 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
1611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1612 "Dell Studio 1558", STAC_DELL_M6_BOTH),
1595 {} /* terminator */ 1613 {} /* terminator */
1596}; 1614};
1597 1615
@@ -1624,6 +1642,7 @@ static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1624 [STAC_92HD83XXX_REF] = "ref", 1642 [STAC_92HD83XXX_REF] = "ref",
1625 [STAC_92HD83XXX_PWR_REF] = "mic-ref", 1643 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1626 [STAC_DELL_S14] = "dell-s14", 1644 [STAC_DELL_S14] = "dell-s14",
1645 [STAC_92HD83XXX_HP] = "hp",
1627}; 1646};
1628 1647
1629static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { 1648static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
@@ -1634,6 +1653,8 @@ static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1634 "DFI LanParty", STAC_92HD83XXX_REF), 1653 "DFI LanParty", STAC_92HD83XXX_REF),
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba, 1654 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1636 "unknown Dell", STAC_DELL_S14), 1655 "unknown Dell", STAC_DELL_S14),
1656 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1657 "HP", STAC_92HD83XXX_HP),
1637 {} /* terminator */ 1658 {} /* terminator */
1638}; 1659};
1639 1660
@@ -1671,6 +1692,7 @@ static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1671 [STAC_DELL_M4_2] = dell_m4_2_pin_configs, 1692 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1672 [STAC_DELL_M4_3] = dell_m4_3_pin_configs, 1693 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1673 [STAC_HP_M4] = NULL, 1694 [STAC_HP_M4] = NULL,
1695 [STAC_HP_DV4] = NULL,
1674 [STAC_HP_DV5] = NULL, 1696 [STAC_HP_DV5] = NULL,
1675 [STAC_HP_HDX] = NULL, 1697 [STAC_HP_HDX] = NULL,
1676 [STAC_HP_DV4_1222NR] = NULL, 1698 [STAC_HP_DV4_1222NR] = NULL,
@@ -1683,6 +1705,7 @@ static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1683 [STAC_DELL_M4_2] = "dell-m4-2", 1705 [STAC_DELL_M4_2] = "dell-m4-2",
1684 [STAC_DELL_M4_3] = "dell-m4-3", 1706 [STAC_DELL_M4_3] = "dell-m4-3",
1685 [STAC_HP_M4] = "hp-m4", 1707 [STAC_HP_M4] = "hp-m4",
1708 [STAC_HP_DV4] = "hp-dv4",
1686 [STAC_HP_DV5] = "hp-dv5", 1709 [STAC_HP_DV5] = "hp-dv5",
1687 [STAC_HP_HDX] = "hp-hdx", 1710 [STAC_HP_HDX] = "hp-hdx",
1688 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr", 1711 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
@@ -1701,7 +1724,7 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1701 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080, 1724 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1702 "HP", STAC_HP_DV5), 1725 "HP", STAC_HP_DV5),
1703 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0, 1726 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1704 "HP dv4-7", STAC_HP_DV5), 1727 "HP dv4-7", STAC_HP_DV4),
1705 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600, 1728 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1706 "HP dv4-7", STAC_HP_DV5), 1729 "HP dv4-7", STAC_HP_DV5),
1707 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610, 1730 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
@@ -1712,6 +1735,8 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1712 "HP HDX", STAC_HP_HDX), /* HDX16 */ 1735 "HP HDX", STAC_HP_HDX), /* HDX16 */
1713 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620, 1736 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1714 "HP dv6", STAC_HP_DV5), 1737 "HP dv6", STAC_HP_DV5),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1739 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
1715 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010, 1740 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1716 "HP", STAC_HP_DV5), 1741 "HP", STAC_HP_DV5),
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233, 1742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
@@ -2091,6 +2116,7 @@ static unsigned int ref9205_pin_configs[12] = {
2091 10280204 2116 10280204
2092 1028021F 2117 1028021F
2093 10280228 (Dell Vostro 1500) 2118 10280228 (Dell Vostro 1500)
2119 10280229 (Dell Vostro 1700)
2094*/ 2120*/
2095static unsigned int dell_9205_m42_pin_configs[12] = { 2121static unsigned int dell_9205_m42_pin_configs[12] = {
2096 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310, 2122 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
@@ -2176,6 +2202,8 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2176 "Dell Inspiron", STAC_9205_DELL_M44), 2202 "Dell Inspiron", STAC_9205_DELL_M44),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228, 2203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2178 "Dell Vostro 1500", STAC_9205_DELL_M42), 2204 "Dell Vostro 1500", STAC_9205_DELL_M42),
2205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2206 "Dell Vostro 1700", STAC_9205_DELL_M42),
2179 /* Gateway */ 2207 /* Gateway */
2180 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD), 2208 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2181 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD), 2209 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
@@ -2648,6 +2676,7 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2648enum { 2676enum {
2649 STAC_CTL_WIDGET_VOL, 2677 STAC_CTL_WIDGET_VOL,
2650 STAC_CTL_WIDGET_MUTE, 2678 STAC_CTL_WIDGET_MUTE,
2679 STAC_CTL_WIDGET_MUTE_BEEP,
2651 STAC_CTL_WIDGET_MONO_MUX, 2680 STAC_CTL_WIDGET_MONO_MUX,
2652 STAC_CTL_WIDGET_HP_SWITCH, 2681 STAC_CTL_WIDGET_HP_SWITCH,
2653 STAC_CTL_WIDGET_IO_SWITCH, 2682 STAC_CTL_WIDGET_IO_SWITCH,
@@ -2658,6 +2687,7 @@ enum {
2658static struct snd_kcontrol_new stac92xx_control_templates[] = { 2687static struct snd_kcontrol_new stac92xx_control_templates[] = {
2659 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2688 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2660 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2689 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2690 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2661 STAC_MONO_MUX, 2691 STAC_MONO_MUX,
2662 STAC_CODEC_HP_SWITCH(NULL), 2692 STAC_CODEC_HP_SWITCH(NULL),
2663 STAC_CODEC_IO_SWITCH(NULL, 0), 2693 STAC_CODEC_IO_SWITCH(NULL, 0),
@@ -2669,7 +2699,8 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2669static struct snd_kcontrol_new * 2699static struct snd_kcontrol_new *
2670stac_control_new(struct sigmatel_spec *spec, 2700stac_control_new(struct sigmatel_spec *spec,
2671 struct snd_kcontrol_new *ktemp, 2701 struct snd_kcontrol_new *ktemp,
2672 const char *name) 2702 const char *name,
2703 unsigned int subdev)
2673{ 2704{
2674 struct snd_kcontrol_new *knew; 2705 struct snd_kcontrol_new *knew;
2675 2706
@@ -2685,6 +2716,7 @@ stac_control_new(struct sigmatel_spec *spec,
2685 spec->kctls.alloced--; 2716 spec->kctls.alloced--;
2686 return NULL; 2717 return NULL;
2687 } 2718 }
2719 knew->subdevice = subdev;
2688 return knew; 2720 return knew;
2689} 2721}
2690 2722
@@ -2693,7 +2725,8 @@ static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2693 int idx, const char *name, 2725 int idx, const char *name,
2694 unsigned long val) 2726 unsigned long val)
2695{ 2727{
2696 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name); 2728 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2729 HDA_SUBDEV_AMP_FLAG);
2697 if (!knew) 2730 if (!knew)
2698 return -ENOMEM; 2731 return -ENOMEM;
2699 knew->index = idx; 2732 knew->index = idx;
@@ -2764,7 +2797,7 @@ static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2764 if (!spec->num_adcs || imux->num_items <= 1) 2797 if (!spec->num_adcs || imux->num_items <= 1)
2765 return 0; /* no need for input source control */ 2798 return 0; /* no need for input source control */
2766 knew = stac_control_new(spec, &stac_input_src_temp, 2799 knew = stac_control_new(spec, &stac_input_src_temp,
2767 stac_input_src_temp.name); 2800 stac_input_src_temp.name, 0);
2768 if (!knew) 2801 if (!knew)
2769 return -ENOMEM; 2802 return -ENOMEM;
2770 knew->count = spec->num_adcs; 2803 knew->count = spec->num_adcs;
@@ -2852,6 +2885,13 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2852 2885
2853 conn_len = snd_hda_get_connections(codec, nid, conn, 2886 conn_len = snd_hda_get_connections(codec, nid, conn,
2854 HDA_MAX_CONNECTIONS); 2887 HDA_MAX_CONNECTIONS);
2888 /* 92HD88: trace back up the link of nids to find the DAC */
2889 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2890 != AC_WID_AUD_OUT)) {
2891 nid = conn[0];
2892 conn_len = snd_hda_get_connections(codec, nid, conn,
2893 HDA_MAX_CONNECTIONS);
2894 }
2855 for (j = 0; j < conn_len; j++) { 2895 for (j = 0; j < conn_len; j++) {
2856 wcaps = get_wcaps(codec, conn[j]); 2896 wcaps = get_wcaps(codec, conn[j]);
2857 wtype = get_wcaps_type(wcaps); 2897 wtype = get_wcaps_type(wcaps);
@@ -3221,12 +3261,15 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3221{ 3261{
3222 struct sigmatel_spec *spec = codec->spec; 3262 struct sigmatel_spec *spec = codec->spec;
3223 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT); 3263 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3224 int err; 3264 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3265
3266 if (spec->anabeep_nid == nid)
3267 type = STAC_CTL_WIDGET_MUTE;
3225 3268
3226 /* check for mute support for the the amp */ 3269 /* check for mute support for the the amp */
3227 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) { 3270 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3228 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, 3271 err = stac92xx_add_control(spec, type,
3229 "PC Beep Playback Switch", 3272 "Beep Playback Switch",
3230 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3273 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3231 if (err < 0) 3274 if (err < 0)
3232 return err; 3275 return err;
@@ -3235,7 +3278,7 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3235 /* check to see if there is volume support for the amp */ 3278 /* check to see if there is volume support for the amp */
3236 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) { 3279 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3237 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, 3280 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3238 "PC Beep Playback Volume", 3281 "Beep Playback Volume",
3239 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3282 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3240 if (err < 0) 3283 if (err < 0)
3241 return err; 3284 return err;
@@ -3258,12 +3301,7 @@ static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3258 struct snd_ctl_elem_value *ucontrol) 3301 struct snd_ctl_elem_value *ucontrol)
3259{ 3302{
3260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3261 int enabled = !!ucontrol->value.integer.value[0]; 3304 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3262 if (codec->beep->enabled != enabled) {
3263 codec->beep->enabled = enabled;
3264 return 1;
3265 }
3266 return 0;
3267} 3305}
3268 3306
3269static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = { 3307static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
@@ -3276,7 +3314,7 @@ static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3276static int stac92xx_beep_switch_ctl(struct hda_codec *codec) 3314static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3277{ 3315{
3278 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl, 3316 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3279 0, "PC Beep Playback Switch", 0); 3317 0, "Beep Playback Switch", 0);
3280} 3318}
3281#endif 3319#endif
3282 3320
@@ -3631,6 +3669,26 @@ static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3631 } 3669 }
3632} 3670}
3633 3671
3672static int is_dual_headphones(struct hda_codec *codec)
3673{
3674 struct sigmatel_spec *spec = codec->spec;
3675 int i, valid_hps;
3676
3677 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3678 spec->autocfg.hp_outs <= 1)
3679 return 0;
3680 valid_hps = 0;
3681 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3682 hda_nid_t nid = spec->autocfg.hp_pins[i];
3683 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3684 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3685 continue;
3686 valid_hps++;
3687 }
3688 return (valid_hps > 1);
3689}
3690
3691
3634static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) 3692static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3635{ 3693{
3636 struct sigmatel_spec *spec = codec->spec; 3694 struct sigmatel_spec *spec = codec->spec;
@@ -3647,8 +3705,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3647 /* If we have no real line-out pin and multiple hp-outs, HPs should 3705 /* If we have no real line-out pin and multiple hp-outs, HPs should
3648 * be set up as multi-channel outputs. 3706 * be set up as multi-channel outputs.
3649 */ 3707 */
3650 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && 3708 if (is_dual_headphones(codec)) {
3651 spec->autocfg.hp_outs > 1) {
3652 /* Copy hp_outs to line_outs, backup line_outs in 3709 /* Copy hp_outs to line_outs, backup line_outs in
3653 * speaker_outs so that the following routines can handle 3710 * speaker_outs so that the following routines can handle
3654 * HP pins as primary outputs. 3711 * HP pins as primary outputs.
@@ -3743,15 +3800,16 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3743 err = snd_hda_attach_beep_device(codec, nid); 3800 err = snd_hda_attach_beep_device(codec, nid);
3744 if (err < 0) 3801 if (err < 0)
3745 return err; 3802 return err;
3746 /* IDT/STAC codecs have linear beep tone parameter */ 3803 if (codec->beep) {
3747 codec->beep->linear_tone = 1; 3804 /* IDT/STAC codecs have linear beep tone parameter */
3748 /* if no beep switch is available, make its own one */ 3805 codec->beep->linear_tone = 1;
3749 caps = query_amp_caps(codec, nid, HDA_OUTPUT); 3806 /* if no beep switch is available, make its own one */
3750 if (codec->beep && 3807 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3751 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) { 3808 if (!(caps & AC_AMPCAP_MUTE)) {
3752 err = stac92xx_beep_switch_ctl(codec); 3809 err = stac92xx_beep_switch_ctl(codec);
3753 if (err < 0) 3810 if (err < 0)
3754 return err; 3811 return err;
3812 }
3755 } 3813 }
3756 } 3814 }
3757#endif 3815#endif
@@ -4120,34 +4178,52 @@ static void stac92xx_power_down(struct hda_codec *codec)
4120static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid, 4178static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4121 int enable); 4179 int enable);
4122 4180
4181static inline int get_int_hint(struct hda_codec *codec, const char *key,
4182 int *valp)
4183{
4184 const char *p;
4185 p = snd_hda_get_hint(codec, key);
4186 if (p) {
4187 unsigned long val;
4188 if (!strict_strtoul(p, 0, &val)) {
4189 *valp = val;
4190 return 1;
4191 }
4192 }
4193 return 0;
4194}
4195
4123/* override some hints from the hwdep entry */ 4196/* override some hints from the hwdep entry */
4124static void stac_store_hints(struct hda_codec *codec) 4197static void stac_store_hints(struct hda_codec *codec)
4125{ 4198{
4126 struct sigmatel_spec *spec = codec->spec; 4199 struct sigmatel_spec *spec = codec->spec;
4127 const char *p;
4128 int val; 4200 int val;
4129 4201
4130 val = snd_hda_get_bool_hint(codec, "hp_detect"); 4202 val = snd_hda_get_bool_hint(codec, "hp_detect");
4131 if (val >= 0) 4203 if (val >= 0)
4132 spec->hp_detect = val; 4204 spec->hp_detect = val;
4133 p = snd_hda_get_hint(codec, "gpio_mask"); 4205 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
4134 if (p) {
4135 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4136 spec->eapd_mask = spec->gpio_dir = spec->gpio_data = 4206 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4137 spec->gpio_mask; 4207 spec->gpio_mask;
4138 } 4208 }
4139 p = snd_hda_get_hint(codec, "gpio_dir"); 4209 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4140 if (p) 4210 spec->gpio_mask &= spec->gpio_mask;
4141 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask; 4211 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4142 p = snd_hda_get_hint(codec, "gpio_data"); 4212 spec->gpio_dir &= spec->gpio_mask;
4143 if (p) 4213 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4144 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask; 4214 spec->eapd_mask &= spec->gpio_mask;
4145 p = snd_hda_get_hint(codec, "eapd_mask"); 4215 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4146 if (p) 4216 spec->gpio_mute &= spec->gpio_mask;
4147 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4148 val = snd_hda_get_bool_hint(codec, "eapd_switch"); 4217 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4149 if (val >= 0) 4218 if (val >= 0)
4150 spec->eapd_switch = val; 4219 spec->eapd_switch = val;
4220 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4221 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
4222 spec->gpio_mask |= spec->gpio_led;
4223 spec->gpio_dir |= spec->gpio_led;
4224 if (spec->gpio_led_polarity)
4225 spec->gpio_data |= spec->gpio_led;
4226 }
4151} 4227}
4152 4228
4153static int stac92xx_init(struct hda_codec *codec) 4229static int stac92xx_init(struct hda_codec *codec)
@@ -4294,6 +4370,12 @@ static int stac92xx_init(struct hda_codec *codec)
4294 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) 4370 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4295 stac_issue_unsol_event(codec, nid); 4371 stac_issue_unsol_event(codec, nid);
4296 } 4372 }
4373
4374#ifdef CONFIG_SND_HDA_POWER_SAVE
4375 /* sync mute LED */
4376 if (spec->gpio_led && codec->patch_ops.check_power_status)
4377 codec->patch_ops.check_power_status(codec, 0x01);
4378#endif
4297 if (spec->dac_list) 4379 if (spec->dac_list)
4298 stac92xx_power_down(codec); 4380 stac92xx_power_down(codec);
4299 return 0; 4381 return 0;
@@ -4329,6 +4411,18 @@ static void stac92xx_free_kctls(struct hda_codec *codec)
4329 snd_array_free(&spec->kctls); 4411 snd_array_free(&spec->kctls);
4330} 4412}
4331 4413
4414static void stac92xx_shutup(struct hda_codec *codec)
4415{
4416 struct sigmatel_spec *spec = codec->spec;
4417
4418 snd_hda_shutup_pins(codec);
4419
4420 if (spec->eapd_mask)
4421 stac_gpio_set(codec, spec->gpio_mask,
4422 spec->gpio_dir, spec->gpio_data &
4423 ~spec->eapd_mask);
4424}
4425
4332static void stac92xx_free(struct hda_codec *codec) 4426static void stac92xx_free(struct hda_codec *codec)
4333{ 4427{
4334 struct sigmatel_spec *spec = codec->spec; 4428 struct sigmatel_spec *spec = codec->spec;
@@ -4336,6 +4430,7 @@ static void stac92xx_free(struct hda_codec *codec)
4336 if (! spec) 4430 if (! spec)
4337 return; 4431 return;
4338 4432
4433 stac92xx_shutup(codec);
4339 stac92xx_free_jacks(codec); 4434 stac92xx_free_jacks(codec);
4340 snd_array_free(&spec->events); 4435 snd_array_free(&spec->events);
4341 4436
@@ -4386,14 +4481,11 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4386 pin_ctl & ~flag); 4481 pin_ctl & ~flag);
4387} 4482}
4388 4483
4389static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) 4484static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4390{ 4485{
4391 if (!nid) 4486 if (!nid)
4392 return 0; 4487 return 0;
4393 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00) 4488 return snd_hda_jack_detect(codec, nid);
4394 & (1 << 31))
4395 return 1;
4396 return 0;
4397} 4489}
4398 4490
4399static void stac92xx_line_out_detect(struct hda_codec *codec, 4491static void stac92xx_line_out_detect(struct hda_codec *codec,
@@ -4670,13 +4762,86 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4670 } 4762 }
4671} 4763}
4672 4764
4673static int hp_bseries_system(u32 subsystem_id) 4765static int hp_blike_system(u32 subsystem_id);
4766
4767static void set_hp_led_gpio(struct hda_codec *codec)
4768{
4769 struct sigmatel_spec *spec = codec->spec;
4770 unsigned int gpio;
4771
4772 if (spec->gpio_led)
4773 return;
4774
4775 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4776 gpio &= AC_GPIO_IO_COUNT;
4777 if (gpio > 3)
4778 spec->gpio_led = 0x08; /* GPIO 3 */
4779 else
4780 spec->gpio_led = 0x01; /* GPIO 0 */
4781}
4782
4783/*
4784 * This method searches for the mute LED GPIO configuration
4785 * provided as OEM string in SMBIOS. The format of that string
4786 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4787 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4788 * that corresponds to the NOT muted state of the master volume
4789 * and G is the index of the GPIO to use as the mute LED control (0..9)
4790 * If _G portion is missing it is assigned based on the codec ID
4791 *
4792 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4793 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4794 *
4795 *
4796 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4797 * SMBIOS - at least the ones I have seen do not have them - which include
4798 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4799 * HP Pavilion dv9500t CTO.
4800 * Need more information on whether it is true across the entire series.
4801 * -- kunal
4802 */
4803static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
4804{
4805 struct sigmatel_spec *spec = codec->spec;
4806 const struct dmi_device *dev = NULL;
4807
4808 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4809 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4810 NULL, dev))) {
4811 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4812 &spec->gpio_led_polarity,
4813 &spec->gpio_led) == 2) {
4814 spec->gpio_led = 1 << spec->gpio_led;
4815 return 1;
4816 }
4817 if (sscanf(dev->name, "HP_Mute_LED_%d",
4818 &spec->gpio_led_polarity) == 1) {
4819 set_hp_led_gpio(codec);
4820 return 1;
4821 }
4822 }
4823
4824 /*
4825 * Fallback case - if we don't find the DMI strings,
4826 * we statically set the GPIO - if not a B-series system.
4827 */
4828 if (!hp_blike_system(codec->subsystem_id)) {
4829 set_hp_led_gpio(codec);
4830 spec->gpio_led_polarity = default_polarity;
4831 return 1;
4832 }
4833 }
4834 return 0;
4835}
4836
4837static int hp_blike_system(u32 subsystem_id)
4674{ 4838{
4675 switch (subsystem_id) { 4839 switch (subsystem_id) {
4676 case 0x103c307e: 4840 case 0x103c1520:
4677 case 0x103c307f: 4841 case 0x103c1521:
4678 case 0x103c3080: 4842 case 0x103c1523:
4679 case 0x103c3081: 4843 case 0x103c1524:
4844 case 0x103c1525:
4680 case 0x103c1722: 4845 case 0x103c1722:
4681 case 0x103c1723: 4846 case 0x103c1723:
4682 case 0x103c1724: 4847 case 0x103c1724:
@@ -4685,6 +4850,14 @@ static int hp_bseries_system(u32 subsystem_id)
4685 case 0x103c1727: 4850 case 0x103c1727:
4686 case 0x103c1728: 4851 case 0x103c1728:
4687 case 0x103c1729: 4852 case 0x103c1729:
4853 case 0x103c172a:
4854 case 0x103c172b:
4855 case 0x103c307e:
4856 case 0x103c307f:
4857 case 0x103c3080:
4858 case 0x103c3081:
4859 case 0x103c7007:
4860 case 0x103c7008:
4688 return 1; 4861 return 1;
4689 } 4862 }
4690 return 0; 4863 return 0;
@@ -4752,6 +4925,11 @@ static int stac92xx_resume(struct hda_codec *codec)
4752 stac_issue_unsol_event(codec, 4925 stac_issue_unsol_event(codec,
4753 spec->autocfg.line_out_pins[0]); 4926 spec->autocfg.line_out_pins[0]);
4754 } 4927 }
4928#ifdef CONFIG_SND_HDA_POWER_SAVE
4929 /* sync mute LED */
4930 if (spec->gpio_led && codec->patch_ops.check_power_status)
4931 codec->patch_ops.check_power_status(codec, 0x01);
4932#endif
4755 return 0; 4933 return 0;
4756} 4934}
4757 4935
@@ -4771,48 +4949,34 @@ static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4771 hda_nid_t nid) 4949 hda_nid_t nid)
4772{ 4950{
4773 struct sigmatel_spec *spec = codec->spec; 4951 struct sigmatel_spec *spec = codec->spec;
4952 int i, muted = 1;
4774 4953
4775 if (nid == 0x10) { 4954 for (i = 0; i < spec->multiout.num_dacs; i++) {
4776 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) & 4955 nid = spec->multiout.dac_nids[i];
4777 HDA_AMP_MUTE) 4956 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4778 spec->gpio_data &= ~spec->gpio_led; /* orange */ 4957 HDA_AMP_MUTE)) {
4779 else 4958 muted = 0; /* something heard */
4780 spec->gpio_data |= spec->gpio_led; /* white */ 4959 break;
4781
4782 if (hp_bseries_system(codec->subsystem_id)) {
4783 /* LED state is inverted on these systems */
4784 spec->gpio_data ^= spec->gpio_led;
4785 } 4960 }
4961 }
4962 if (muted)
4963 spec->gpio_data &= ~spec->gpio_led; /* orange */
4964 else
4965 spec->gpio_data |= spec->gpio_led; /* white */
4786 4966
4787 stac_gpio_set(codec, spec->gpio_mask, 4967 if (!spec->gpio_led_polarity) {
4788 spec->gpio_dir, 4968 /* LED state is inverted on these systems */
4789 spec->gpio_data); 4969 spec->gpio_data ^= spec->gpio_led;
4790 } 4970 }
4791 4971
4972 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4792 return 0; 4973 return 0;
4793} 4974}
4794#endif 4975#endif
4795 4976
4796static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) 4977static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4797{ 4978{
4798 struct sigmatel_spec *spec = codec->spec; 4979 stac92xx_shutup(codec);
4799 int i;
4800 hda_nid_t nid;
4801
4802 /* reset each pin before powering down DAC/ADC to avoid click noise */
4803 nid = codec->start_nid;
4804 for (i = 0; i < codec->num_nodes; i++, nid++) {
4805 unsigned int wcaps = get_wcaps(codec, nid);
4806 unsigned int wid_type = get_wcaps_type(wcaps);
4807 if (wid_type == AC_WID_PIN)
4808 snd_hda_codec_read(codec, nid, 0,
4809 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4810 }
4811
4812 if (spec->eapd_mask)
4813 stac_gpio_set(codec, spec->gpio_mask,
4814 spec->gpio_dir, spec->gpio_data &
4815 ~spec->eapd_mask);
4816 return 0; 4980 return 0;
4817} 4981}
4818#endif 4982#endif
@@ -4827,6 +4991,7 @@ static struct hda_codec_ops stac92xx_patch_ops = {
4827 .suspend = stac92xx_suspend, 4991 .suspend = stac92xx_suspend,
4828 .resume = stac92xx_resume, 4992 .resume = stac92xx_resume,
4829#endif 4993#endif
4994 .reboot_notify = stac92xx_shutup,
4830}; 4995};
4831 4996
4832static int patch_stac9200(struct hda_codec *codec) 4997static int patch_stac9200(struct hda_codec *codec)
@@ -4838,6 +5003,7 @@ static int patch_stac9200(struct hda_codec *codec)
4838 if (spec == NULL) 5003 if (spec == NULL)
4839 return -ENOMEM; 5004 return -ENOMEM;
4840 5005
5006 codec->no_trigger_sense = 1;
4841 codec->spec = spec; 5007 codec->spec = spec;
4842 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids); 5008 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
4843 spec->pin_nids = stac9200_pin_nids; 5009 spec->pin_nids = stac9200_pin_nids;
@@ -4900,6 +5066,7 @@ static int patch_stac925x(struct hda_codec *codec)
4900 if (spec == NULL) 5066 if (spec == NULL)
4901 return -ENOMEM; 5067 return -ENOMEM;
4902 5068
5069 codec->no_trigger_sense = 1;
4903 codec->spec = spec; 5070 codec->spec = spec;
4904 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids); 5071 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
4905 spec->pin_nids = stac925x_pin_nids; 5072 spec->pin_nids = stac925x_pin_nids;
@@ -4984,6 +5151,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4984 if (spec == NULL) 5151 if (spec == NULL)
4985 return -ENOMEM; 5152 return -ENOMEM;
4986 5153
5154 codec->no_trigger_sense = 1;
4987 codec->spec = spec; 5155 codec->spec = spec;
4988 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs; 5156 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
4989 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids); 5157 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
@@ -5125,12 +5293,12 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
5125 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1]; 5293 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5126 int err; 5294 int err;
5127 int num_dacs; 5295 int num_dacs;
5128 hda_nid_t nid;
5129 5296
5130 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5297 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5131 if (spec == NULL) 5298 if (spec == NULL)
5132 return -ENOMEM; 5299 return -ENOMEM;
5133 5300
5301 codec->no_trigger_sense = 1;
5134 codec->spec = spec; 5302 codec->spec = spec;
5135 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs; 5303 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5136 spec->digbeep_nid = 0x21; 5304 spec->digbeep_nid = 0x21;
@@ -5163,7 +5331,18 @@ again:
5163 stac92hd83xxx_brd_tbl[spec->board_config]); 5331 stac92hd83xxx_brd_tbl[spec->board_config]);
5164 5332
5165 switch (codec->vendor_id) { 5333 switch (codec->vendor_id) {
5334 case 0x111d7666:
5335 case 0x111d7667:
5336 case 0x111d7668:
5337 case 0x111d7669:
5338 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5339 spec->pin_nids = stac92hd88xxx_pin_nids;
5340 spec->mono_nid = 0;
5341 spec->digbeep_nid = 0;
5342 spec->num_pwrs = 0;
5343 break;
5166 case 0x111d7604: 5344 case 0x111d7604:
5345 case 0x111d76d4:
5167 case 0x111d7605: 5346 case 0x111d7605:
5168 case 0x111d76d5: 5347 case 0x111d76d5:
5169 if (spec->board_config == STAC_92HD83XXX_PWR_REF) 5348 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
@@ -5172,6 +5351,24 @@ again:
5172 break; 5351 break;
5173 } 5352 }
5174 5353
5354 codec->patch_ops = stac92xx_patch_ops;
5355
5356 if (find_mute_led_gpio(codec, 0))
5357 snd_printd("mute LED gpio %d polarity %d\n",
5358 spec->gpio_led,
5359 spec->gpio_led_polarity);
5360
5361#ifdef CONFIG_SND_HDA_POWER_SAVE
5362 if (spec->gpio_led) {
5363 spec->gpio_mask |= spec->gpio_led;
5364 spec->gpio_dir |= spec->gpio_led;
5365 spec->gpio_data |= spec->gpio_led;
5366 /* register check_power_status callback. */
5367 codec->patch_ops.check_power_status =
5368 stac92xx_hp_check_power_status;
5369 }
5370#endif
5371
5175 err = stac92xx_parse_auto_config(codec, 0x1d, 0); 5372 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5176 if (!err) { 5373 if (!err) {
5177 if (spec->board_config < 0) { 5374 if (spec->board_config < 0) {
@@ -5188,26 +5385,21 @@ again:
5188 return err; 5385 return err;
5189 } 5386 }
5190 5387
5191 switch (spec->board_config) { 5388 /* docking output support */
5192 case STAC_DELL_S14: 5389 num_dacs = snd_hda_get_connections(codec, 0xF,
5193 nid = 0xf;
5194 break;
5195 default:
5196 nid = 0xe;
5197 break;
5198 }
5199
5200 num_dacs = snd_hda_get_connections(codec, nid,
5201 conn, STAC92HD83_DAC_COUNT + 1) - 1; 5390 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5202 if (num_dacs < 0) 5391 /* skip non-DAC connections */
5203 num_dacs = STAC92HD83_DAC_COUNT; 5392 while (num_dacs >= 0 &&
5204 5393 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5205 /* set port X to select the last DAC 5394 != AC_WID_AUD_OUT))
5206 */ 5395 num_dacs--;
5207 snd_hda_codec_write_cache(codec, nid, 0, 5396 /* set port E and F to select the last DAC */
5397 if (num_dacs >= 0) {
5398 snd_hda_codec_write_cache(codec, 0xE, 0,
5208 AC_VERB_SET_CONNECT_SEL, num_dacs); 5399 AC_VERB_SET_CONNECT_SEL, num_dacs);
5209 5400 snd_hda_codec_write_cache(codec, 0xF, 0,
5210 codec->patch_ops = stac92xx_patch_ops; 5401 AC_VERB_SET_CONNECT_SEL, num_dacs);
5402 }
5211 5403
5212 codec->proc_widget_hook = stac92hd_proc_hook; 5404 codec->proc_widget_hook = stac92hd_proc_hook;
5213 5405
@@ -5269,6 +5461,54 @@ static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5269 return 0; 5461 return 0;
5270} 5462}
5271 5463
5464/* HP dv7 bass switch - GPIO5 */
5465#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5466static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5467 struct snd_ctl_elem_value *ucontrol)
5468{
5469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5470 struct sigmatel_spec *spec = codec->spec;
5471 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5472 return 0;
5473}
5474
5475static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5476 struct snd_ctl_elem_value *ucontrol)
5477{
5478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5479 struct sigmatel_spec *spec = codec->spec;
5480 unsigned int gpio_data;
5481
5482 gpio_data = (spec->gpio_data & ~0x20) |
5483 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5484 if (gpio_data == spec->gpio_data)
5485 return 0;
5486 spec->gpio_data = gpio_data;
5487 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5488 return 1;
5489}
5490
5491static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5493 .info = stac_hp_bass_gpio_info,
5494 .get = stac_hp_bass_gpio_get,
5495 .put = stac_hp_bass_gpio_put,
5496};
5497
5498static int stac_add_hp_bass_switch(struct hda_codec *codec)
5499{
5500 struct sigmatel_spec *spec = codec->spec;
5501
5502 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5503 "Bass Speaker Playback Switch", 0))
5504 return -ENOMEM;
5505
5506 spec->gpio_mask |= 0x20;
5507 spec->gpio_dir |= 0x20;
5508 spec->gpio_data |= 0x20;
5509 return 0;
5510}
5511
5272static int patch_stac92hd71bxx(struct hda_codec *codec) 5512static int patch_stac92hd71bxx(struct hda_codec *codec)
5273{ 5513{
5274 struct sigmatel_spec *spec; 5514 struct sigmatel_spec *spec;
@@ -5280,6 +5520,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5280 if (spec == NULL) 5520 if (spec == NULL)
5281 return -ENOMEM; 5521 return -ENOMEM;
5282 5522
5523 codec->no_trigger_sense = 1;
5283 codec->spec = spec; 5524 codec->spec = spec;
5284 codec->patch_ops = stac92xx_patch_ops; 5525 codec->patch_ops = stac92xx_patch_ops;
5285 spec->num_pins = STAC92HD71BXX_NUM_PINS; 5526 spec->num_pins = STAC92HD71BXX_NUM_PINS;
@@ -5412,6 +5653,8 @@ again:
5412 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 5653 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5413 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e); 5654 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
5414 5655
5656 snd_printdd("Found board config: %d\n", spec->board_config);
5657
5415 switch (spec->board_config) { 5658 switch (spec->board_config) {
5416 case STAC_HP_M4: 5659 case STAC_HP_M4:
5417 /* enable internal microphone */ 5660 /* enable internal microphone */
@@ -5437,6 +5680,8 @@ again:
5437 */ 5680 */
5438 spec->num_smuxes = 1; 5681 spec->num_smuxes = 1;
5439 spec->num_dmuxes = 1; 5682 spec->num_dmuxes = 1;
5683 /* fallthrough */
5684 case STAC_HP_DV4:
5440 spec->gpio_led = 0x01; 5685 spec->gpio_led = 0x01;
5441 /* fallthrough */ 5686 /* fallthrough */
5442 case STAC_HP_DV5: 5687 case STAC_HP_DV5:
@@ -5452,12 +5697,11 @@ again:
5452 spec->num_dmics = 1; 5697 spec->num_dmics = 1;
5453 spec->num_dmuxes = 1; 5698 spec->num_dmuxes = 1;
5454 spec->num_smuxes = 1; 5699 spec->num_smuxes = 1;
5455 /* orange/white mute led on GPIO3, orange=0, white=1 */
5456 spec->gpio_led = 0x08; 5700 spec->gpio_led = 0x08;
5457 break; 5701 break;
5458 } 5702 }
5459 5703
5460 if (hp_bseries_system(codec->subsystem_id)) { 5704 if (hp_blike_system(codec->subsystem_id)) {
5461 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f); 5705 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5462 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT || 5706 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5463 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER || 5707 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
@@ -5475,26 +5719,10 @@ again:
5475 } 5719 }
5476 } 5720 }
5477 5721
5478 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) { 5722 if (find_mute_led_gpio(codec, 1))
5479 const struct dmi_device *dev = NULL; 5723 snd_printd("mute LED gpio %d polarity %d\n",
5480 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, 5724 spec->gpio_led,
5481 NULL, dev))) { 5725 spec->gpio_led_polarity);
5482 if (strcmp(dev->name, "HP_Mute_LED_1")) {
5483 switch (codec->vendor_id) {
5484 case 0x111d7608:
5485 spec->gpio_led = 0x01;
5486 break;
5487 case 0x111d7600:
5488 case 0x111d7601:
5489 case 0x111d7602:
5490 case 0x111d7603:
5491 spec->gpio_led = 0x08;
5492 break;
5493 }
5494 break;
5495 }
5496 }
5497 }
5498 5726
5499#ifdef CONFIG_SND_HDA_POWER_SAVE 5727#ifdef CONFIG_SND_HDA_POWER_SAVE
5500 if (spec->gpio_led) { 5728 if (spec->gpio_led) {
@@ -5525,6 +5753,16 @@ again:
5525 return err; 5753 return err;
5526 } 5754 }
5527 5755
5756 /* enable bass on HP dv7 */
5757 if (spec->board_config == STAC_HP_DV4 ||
5758 spec->board_config == STAC_HP_DV5) {
5759 unsigned int cap;
5760 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5761 cap &= AC_GPIO_IO_COUNT;
5762 if (cap >= 6)
5763 stac_add_hp_bass_switch(codec);
5764 }
5765
5528 codec->proc_widget_hook = stac92hd7x_proc_hook; 5766 codec->proc_widget_hook = stac92hd7x_proc_hook;
5529 5767
5530 return 0; 5768 return 0;
@@ -5539,6 +5777,7 @@ static int patch_stac922x(struct hda_codec *codec)
5539 if (spec == NULL) 5777 if (spec == NULL)
5540 return -ENOMEM; 5778 return -ENOMEM;
5541 5779
5780 codec->no_trigger_sense = 1;
5542 codec->spec = spec; 5781 codec->spec = spec;
5543 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids); 5782 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
5544 spec->pin_nids = stac922x_pin_nids; 5783 spec->pin_nids = stac922x_pin_nids;
@@ -5642,6 +5881,7 @@ static int patch_stac927x(struct hda_codec *codec)
5642 if (spec == NULL) 5881 if (spec == NULL)
5643 return -ENOMEM; 5882 return -ENOMEM;
5644 5883
5884 codec->no_trigger_sense = 1;
5645 codec->spec = spec; 5885 codec->spec = spec;
5646 codec->slave_dig_outs = stac927x_slave_dig_outs; 5886 codec->slave_dig_outs = stac927x_slave_dig_outs;
5647 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids); 5887 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
@@ -5776,6 +6016,7 @@ static int patch_stac9205(struct hda_codec *codec)
5776 if (spec == NULL) 6016 if (spec == NULL)
5777 return -ENOMEM; 6017 return -ENOMEM;
5778 6018
6019 codec->no_trigger_sense = 1;
5779 codec->spec = spec; 6020 codec->spec = spec;
5780 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids); 6021 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
5781 spec->pin_nids = stac9205_pin_nids; 6022 spec->pin_nids = stac9205_pin_nids;
@@ -5931,6 +6172,7 @@ static int patch_stac9872(struct hda_codec *codec)
5931 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 6172 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5932 if (spec == NULL) 6173 if (spec == NULL)
5933 return -ENOMEM; 6174 return -ENOMEM;
6175 codec->no_trigger_sense = 1;
5934 codec->spec = spec; 6176 codec->spec = spec;
5935 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids); 6177 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5936 spec->pin_nids = stac9872_pin_nids; 6178 spec->pin_nids = stac9872_pin_nids;
@@ -6019,8 +6261,13 @@ static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6019 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 }, 6261 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
6020 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx}, 6262 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
6021 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx}, 6263 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6264 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6022 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx}, 6265 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6023 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx}, 6266 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6267 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6268 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6269 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6270 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
6024 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx}, 6271 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
6025 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx }, 6272 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6026 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx }, 6273 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index ee89db90c9b6..73453814e098 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 VT1702/VT1708/VT1709 codec 4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5 * 5 *
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com> 6 * (C) 2006-2009 VIA Technology, Inc.
7 * Takashi Iwai <tiwai@suse.de> 7 * (C) 2006-2008 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
@@ -22,21 +22,27 @@
22 */ 22 */
23 23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ 24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
25/* */ 25/* */
26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ 26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */ 27/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */ 28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
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 */ 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 */ 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 */ 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 */ 35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */ 36/* 2008-04-09 Lydia Wang Add Independent HP feature */
37/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ 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 */ 38/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39/* */ 39/* 2009-02-16 Logan Li Add support for VT1718S */
40/* 2009-03-13 Logan Li Add support for VT1716S */
41/* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42/* 2009-07-08 Lydia Wang Add support for VT2002P */
43/* 2009-07-21 Lydia Wang Add support for VT1812 */
44/* 2009-09-19 Lydia Wang Add support for VT1818S */
45/* */
40/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 46/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 47
42 48
@@ -48,6 +54,8 @@
48#include "hda_codec.h" 54#include "hda_codec.h"
49#include "hda_local.h" 55#include "hda_local.h"
50 56
57#define NID_MAPPING (-1)
58
51/* amp values */ 59/* amp values */
52#define AMP_VAL_IDX_SHIFT 19 60#define AMP_VAL_IDX_SHIFT 19
53#define AMP_VAL_IDX_MASK (0x0f<<19) 61#define AMP_VAL_IDX_MASK (0x0f<<19)
@@ -76,14 +84,6 @@
76#define VT1702_HP_NID 0x17 84#define VT1702_HP_NID 0x17
77#define VT1702_DIGOUT_NID 0x11 85#define VT1702_DIGOUT_NID 0x11
78 86
79#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
80#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
81#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
82#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
83#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
84#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
85#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
86
87enum VIA_HDA_CODEC { 87enum VIA_HDA_CODEC {
88 UNKNOWN = -1, 88 UNKNOWN = -1,
89 VT1708, 89 VT1708,
@@ -92,12 +92,89 @@ enum VIA_HDA_CODEC {
92 VT1708B_8CH, 92 VT1708B_8CH,
93 VT1708B_4CH, 93 VT1708B_4CH,
94 VT1708S, 94 VT1708S,
95 VT1708BCE,
95 VT1702, 96 VT1702,
97 VT1718S,
98 VT1716S,
99 VT2002P,
100 VT1812,
96 CODEC_TYPES, 101 CODEC_TYPES,
97}; 102};
98 103
99static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) 104struct via_spec {
105 /* codec parameterization */
106 struct snd_kcontrol_new *mixers[6];
107 unsigned int num_mixers;
108
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
111
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
115
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
119
120 /* playback */
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
123
124 /* capture */
125 unsigned int num_adc_nids;
126 hda_nid_t *adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
130
131 /* capture source */
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
134
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
137
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
143
144 /* HP mode source */
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
149 unsigned int dmic_enabled;
150 enum VIA_HDA_CODEC codec_type;
151
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157#ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
159#endif
160};
161
162static struct via_spec * via_new_spec(struct hda_codec *codec)
100{ 163{
164 struct via_spec *spec;
165
166 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
167 if (spec == NULL)
168 return NULL;
169
170 codec->spec = spec;
171 spec->codec = codec;
172 return spec;
173}
174
175static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
176{
177 u32 vendor_id = codec->vendor_id;
101 u16 ven_id = vendor_id >> 16; 178 u16 ven_id = vendor_id >> 16;
102 u16 dev_id = vendor_id & 0xffff; 179 u16 dev_id = vendor_id & 0xffff;
103 enum VIA_HDA_CODEC codec_type; 180 enum VIA_HDA_CODEC codec_type;
@@ -111,9 +188,11 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
111 codec_type = VT1709_10CH; 188 codec_type = VT1709_10CH;
112 else if (dev_id >= 0xe714 && dev_id <= 0xe717) 189 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113 codec_type = VT1709_6CH; 190 codec_type = VT1709_6CH;
114 else if (dev_id >= 0xe720 && dev_id <= 0xe723) 191 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
115 codec_type = VT1708B_8CH; 192 codec_type = VT1708B_8CH;
116 else if (dev_id >= 0xe724 && dev_id <= 0xe727) 193 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
194 codec_type = VT1708BCE;
195 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117 codec_type = VT1708B_4CH; 196 codec_type = VT1708B_4CH;
118 else if ((dev_id & 0xfff) == 0x397 197 else if ((dev_id & 0xfff) == 0x397
119 && (dev_id >> 12) < 8) 198 && (dev_id >> 12) < 8)
@@ -121,6 +200,19 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
121 else if ((dev_id & 0xfff) == 0x398 200 else if ((dev_id & 0xfff) == 0x398
122 && (dev_id >> 12) < 8) 201 && (dev_id >> 12) < 8)
123 codec_type = VT1702; 202 codec_type = VT1702;
203 else if ((dev_id & 0xfff) == 0x428
204 && (dev_id >> 12) < 8)
205 codec_type = VT1718S;
206 else if (dev_id == 0x0433 || dev_id == 0xa721)
207 codec_type = VT1716S;
208 else if (dev_id == 0x0441 || dev_id == 0x4441)
209 codec_type = VT1718S;
210 else if (dev_id == 0x0438 || dev_id == 0x4438)
211 codec_type = VT2002P;
212 else if (dev_id == 0x0448)
213 codec_type = VT1812;
214 else if (dev_id == 0x0440)
215 codec_type = VT1708S;
124 else 216 else
125 codec_type = UNKNOWN; 217 codec_type = UNKNOWN;
126 return codec_type; 218 return codec_type;
@@ -128,10 +220,16 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
128 220
129#define VIA_HP_EVENT 0x01 221#define VIA_HP_EVENT 0x01
130#define VIA_GPIO_EVENT 0x02 222#define VIA_GPIO_EVENT 0x02
223#define VIA_JACK_EVENT 0x04
224#define VIA_MONO_EVENT 0x08
225#define VIA_SPEAKER_EVENT 0x10
226#define VIA_BIND_HP_EVENT 0x20
131 227
132enum { 228enum {
133 VIA_CTL_WIDGET_VOL, 229 VIA_CTL_WIDGET_VOL,
134 VIA_CTL_WIDGET_MUTE, 230 VIA_CTL_WIDGET_MUTE,
231 VIA_CTL_WIDGET_ANALOG_MUTE,
232 VIA_CTL_WIDGET_BIND_PIN_MUTE,
135}; 233};
136 234
137enum { 235enum {
@@ -141,99 +239,162 @@ enum {
141 AUTO_SEQ_SIDE 239 AUTO_SEQ_SIDE
142}; 240};
143 241
144/* Some VT1708S based boards gets the micboost setting wrong, so we have 242static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
145 * to apply some brute-force and re-write the TLV's by software. */ 243static void set_jack_power_state(struct hda_codec *codec);
146static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, 244static int is_aa_path_mute(struct hda_codec *codec);
147 unsigned int size, unsigned int __user *_tlv) 245
246static void vt1708_start_hp_work(struct via_spec *spec)
148{ 247{
149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
150 hda_nid_t nid = get_amp_nid(kcontrol); 249 return;
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detectect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
255}
151 256
152 if (get_codec_type(codec->vendor_id) == VT1708S 257static void vt1708_stop_hp_work(struct via_spec *spec)
153 && (nid == 0x1a || nid == 0x1e)) { 258{
154 if (size < 4 * sizeof(unsigned int)) 259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
155 return -ENOMEM; 260 return;
156 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */ 261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
157 return -EFAULT; 262 && !is_aa_path_mute(spec->codec))
158 if (put_user(2 * sizeof(unsigned int), _tlv + 1)) 263 return;
159 return -EFAULT; 264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
160 if (put_user(0, _tlv + 2)) /* offset = 0 */ 265 !spec->vt1708_jack_detectect);
161 return -EFAULT; 266 cancel_delayed_work(&spec->vt1708_hp_work);
162 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */ 267 flush_scheduled_work();
163 return -EFAULT;
164 }
165 return 0;
166} 268}
167 269
168static int mic_boost_volume_info(struct snd_kcontrol *kcontrol, 270
169 struct snd_ctl_elem_info *uinfo) 271static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol)
170{ 273{
274 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 hda_nid_t nid = get_amp_nid(kcontrol);
173 276
174 if (get_codec_type(codec->vendor_id) == VT1708S 277 set_jack_power_state(codec);
175 && (nid == 0x1a || nid == 0x1e)) { 278 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 279 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
177 uinfo->count = 2; 280 if (is_aa_path_mute(codec))
178 uinfo->value.integer.min = 0; 281 vt1708_start_hp_work(codec->spec);
179 uinfo->value.integer.max = 3; 282 else
283 vt1708_stop_hp_work(codec->spec);
180 } 284 }
181 return 0; 285 return change;
182} 286}
183 287
184static struct snd_kcontrol_new vt1708_control_templates[] = { 288/* modify .put = snd_hda_mixer_amp_switch_put */
185 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 289#define ANALOG_INPUT_MUTE \
186 HDA_CODEC_MUTE(NULL, 0, 0, 0), 290 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
187}; 291 .name = NULL, \
292 .index = 0, \
293 .info = snd_hda_mixer_amp_switch_info, \
294 .get = snd_hda_mixer_amp_switch_get, \
295 .put = analog_input_switch_put, \
296 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
188 297
298static void via_hp_bind_automute(struct hda_codec *codec);
189 299
190struct via_spec { 300static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
191 /* codec parameterization */ 301 struct snd_ctl_elem_value *ucontrol)
192 struct snd_kcontrol_new *mixers[3]; 302{
193 unsigned int num_mixers; 303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
194 304 struct via_spec *spec = codec->spec;
195 struct hda_verb *init_verbs[5]; 305 int i;
196 unsigned int num_iverbs; 306 int change = 0;
197
198 char *stream_name_analog;
199 struct hda_pcm_stream *stream_analog_playback;
200 struct hda_pcm_stream *stream_analog_capture;
201
202 char *stream_name_digital;
203 struct hda_pcm_stream *stream_digital_playback;
204 struct hda_pcm_stream *stream_digital_capture;
205
206 /* playback */
207 struct hda_multi_out multiout;
208 hda_nid_t slave_dig_outs[2];
209
210 /* capture */
211 unsigned int num_adc_nids;
212 hda_nid_t *adc_nids;
213 hda_nid_t mux_nids[3];
214 hda_nid_t dig_in_nid;
215 hda_nid_t dig_in_pin;
216 307
217 /* capture source */ 308 long *valp = ucontrol->value.integer.value;
218 const struct hda_input_mux *input_mux; 309 int lmute, rmute;
219 unsigned int cur_mux[3]; 310 if (strstr(kcontrol->id.name, "Switch") == NULL) {
311 snd_printd("Invalid control!\n");
312 return change;
313 }
314 change = snd_hda_mixer_amp_switch_put(kcontrol,
315 ucontrol);
316 /* Get mute value */
317 lmute = *valp ? 0 : HDA_AMP_MUTE;
318 valp++;
319 rmute = *valp ? 0 : HDA_AMP_MUTE;
320
321 /* Set hp pins */
322 if (!spec->hp_independent_mode) {
323 for (i = 0; i < spec->autocfg.hp_outs; i++) {
324 snd_hda_codec_amp_update(
325 codec, spec->autocfg.hp_pins[i],
326 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
327 lmute);
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
331 rmute);
332 }
333 }
220 334
221 /* PCM information */ 335 if (!lmute && !rmute) {
222 struct hda_pcm pcm_rec[3]; 336 /* Line Outs */
337 for (i = 0; i < spec->autocfg.line_outs; i++)
338 snd_hda_codec_amp_stereo(
339 codec, spec->autocfg.line_out_pins[i],
340 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
341 /* Speakers */
342 for (i = 0; i < spec->autocfg.speaker_outs; i++)
343 snd_hda_codec_amp_stereo(
344 codec, spec->autocfg.speaker_pins[i],
345 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 /* unmute */
347 via_hp_bind_automute(codec);
223 348
224 /* dynamic controls, init_verbs and input_mux */ 349 } else {
225 struct auto_pin_cfg autocfg; 350 if (lmute) {
226 struct snd_array kctls; 351 /* Mute all left channels */
227 struct hda_input_mux private_imux[2]; 352 for (i = 1; i < spec->autocfg.line_outs; i++)
228 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 lmute);
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
360 codec,
361 spec->autocfg.speaker_pins[i],
362 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 lmute);
364 }
365 if (rmute) {
366 /* mute all right channels */
367 for (i = 1; i < spec->autocfg.line_outs; i++)
368 snd_hda_codec_amp_update(
369 codec,
370 spec->autocfg.line_out_pins[i],
371 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
372 rmute);
373 for (i = 0; i < spec->autocfg.speaker_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.speaker_pins[i],
377 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 rmute);
379 }
380 }
381 return change;
382}
229 383
230 /* HP mode source */ 384#define BIND_PIN_MUTE \
231 const struct hda_input_mux *hp_mux; 385 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
232 unsigned int hp_independent_mode; 386 .name = NULL, \
387 .index = 0, \
388 .info = snd_hda_mixer_amp_switch_info, \
389 .get = snd_hda_mixer_amp_switch_get, \
390 .put = bind_pin_switch_put, \
391 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
233 392
234#ifdef CONFIG_SND_HDA_POWER_SAVE 393static struct snd_kcontrol_new via_control_templates[] = {
235 struct hda_loopback_check loopback; 394 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
236#endif 395 HDA_CODEC_MUTE(NULL, 0, 0, 0),
396 ANALOG_INPUT_MUTE,
397 BIND_PIN_MUTE,
237}; 398};
238 399
239static hda_nid_t vt1708_adc_nids[2] = { 400static hda_nid_t vt1708_adc_nids[2] = {
@@ -261,6 +422,27 @@ static hda_nid_t vt1702_adc_nids[3] = {
261 0x12, 0x20, 0x1F 422 0x12, 0x20, 0x1F
262}; 423};
263 424
425static hda_nid_t vt1718S_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
428};
429
430static hda_nid_t vt1716S_adc_nids[2] = {
431 /* ADC1-2 */
432 0x13, 0x14
433};
434
435static hda_nid_t vt2002P_adc_nids[2] = {
436 /* ADC1-2 */
437 0x10, 0x11
438};
439
440static hda_nid_t vt1812_adc_nids[2] = {
441 /* ADC1-2 */
442 0x10, 0x11
443};
444
445
264/* add dynamic controls */ 446/* add dynamic controls */
265static int via_add_control(struct via_spec *spec, int type, const char *name, 447static int via_add_control(struct via_spec *spec, int type, const char *name,
266 unsigned long val) 448 unsigned long val)
@@ -271,14 +453,32 @@ static int via_add_control(struct via_spec *spec, int type, const char *name,
271 knew = snd_array_new(&spec->kctls); 453 knew = snd_array_new(&spec->kctls);
272 if (!knew) 454 if (!knew)
273 return -ENOMEM; 455 return -ENOMEM;
274 *knew = vt1708_control_templates[type]; 456 *knew = via_control_templates[type];
275 knew->name = kstrdup(name, GFP_KERNEL); 457 knew->name = kstrdup(name, GFP_KERNEL);
276 if (!knew->name) 458 if (!knew->name)
277 return -ENOMEM; 459 return -ENOMEM;
460 if (get_amp_nid_(val))
461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
278 knew->private_value = val; 462 knew->private_value = val;
279 return 0; 463 return 0;
280} 464}
281 465
466static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
467 struct snd_kcontrol_new *tmpl)
468{
469 struct snd_kcontrol_new *knew;
470
471 snd_array_init(&spec->kctls, sizeof(*knew), 32);
472 knew = snd_array_new(&spec->kctls);
473 if (!knew)
474 return NULL;
475 *knew = *tmpl;
476 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
477 if (!knew->name)
478 return NULL;
479 return knew;
480}
481
282static void via_free_kctls(struct hda_codec *codec) 482static void via_free_kctls(struct hda_codec *codec)
283{ 483{
284 struct via_spec *spec = codec->spec; 484 struct via_spec *spec = codec->spec;
@@ -293,8 +493,8 @@ static void via_free_kctls(struct hda_codec *codec)
293} 493}
294 494
295/* create input playback/capture controls for the given pin */ 495/* create input playback/capture controls for the given pin */
296static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, 496static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
297 const char *ctlname, int idx, int mix_nid) 497 int idx, int mix_nid)
298{ 498{
299 char name[32]; 499 char name[32];
300 int err; 500 int err;
@@ -305,7 +505,7 @@ static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
305 if (err < 0) 505 if (err < 0)
306 return err; 506 return err;
307 sprintf(name, "%s Playback Switch", ctlname); 507 sprintf(name, "%s Playback Switch", ctlname);
308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 508 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
309 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 509 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
310 if (err < 0) 510 if (err < 0)
311 return err; 511 return err;
@@ -322,7 +522,7 @@ static void via_auto_set_output_and_unmute(struct hda_codec *codec,
322 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 522 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
323 AMP_OUT_UNMUTE); 523 AMP_OUT_UNMUTE);
324 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) 524 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
325 snd_hda_codec_write(codec, nid, 0, 525 snd_hda_codec_write(codec, nid, 0,
326 AC_VERB_SET_EAPD_BTLENABLE, 0x02); 526 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
327} 527}
328 528
@@ -343,10 +543,13 @@ static void via_auto_init_hp_out(struct hda_codec *codec)
343{ 543{
344 struct via_spec *spec = codec->spec; 544 struct via_spec *spec = codec->spec;
345 hda_nid_t pin; 545 hda_nid_t pin;
546 int i;
346 547
347 pin = spec->autocfg.hp_pins[0]; 548 for (i = 0; i < spec->autocfg.hp_outs; i++) {
348 if (pin) /* connect to front */ 549 pin = spec->autocfg.hp_pins[i];
349 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 550 if (pin) /* connect to front */
551 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
552 }
350} 553}
351 554
352static void via_auto_init_analog_input(struct hda_codec *codec) 555static void via_auto_init_analog_input(struct hda_codec *codec)
@@ -364,6 +567,502 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
364 567
365 } 568 }
366} 569}
570
571static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
572
573static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
574 unsigned int *affected_parm)
575{
576 unsigned parm;
577 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
578 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
579 >> AC_DEFCFG_MISC_SHIFT
580 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
581 unsigned present = snd_hda_jack_detect(codec, nid);
582 struct via_spec *spec = codec->spec;
583 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
584 || ((no_presence || present)
585 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
586 *affected_parm = AC_PWRST_D0; /* if it's connected */
587 parm = AC_PWRST_D0;
588 } else
589 parm = AC_PWRST_D3;
590
591 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
592}
593
594static void set_jack_power_state(struct hda_codec *codec)
595{
596 struct via_spec *spec = codec->spec;
597 int imux_is_smixer;
598 unsigned int parm;
599
600 if (spec->codec_type == VT1702) {
601 imux_is_smixer = snd_hda_codec_read(
602 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
603 /* inputs */
604 /* PW 1/2/5 (14h/15h/18h) */
605 parm = AC_PWRST_D3;
606 set_pin_power_state(codec, 0x14, &parm);
607 set_pin_power_state(codec, 0x15, &parm);
608 set_pin_power_state(codec, 0x18, &parm);
609 if (imux_is_smixer)
610 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
611 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
612 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
613 parm);
614 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
615 parm);
616 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
617 parm);
618 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
619 parm);
620
621 /* outputs */
622 /* PW 3/4 (16h/17h) */
623 parm = AC_PWRST_D3;
624 set_pin_power_state(codec, 0x16, &parm);
625 set_pin_power_state(codec, 0x17, &parm);
626 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
627 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
628 imux_is_smixer ? AC_PWRST_D0 : parm);
629 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
630 parm);
631 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
632 parm);
633 } else if (spec->codec_type == VT1708B_8CH
634 || spec->codec_type == VT1708B_4CH
635 || spec->codec_type == VT1708S) {
636 /* SW0 (17h) = stereo mixer */
637 int is_8ch = spec->codec_type != VT1708B_4CH;
638 imux_is_smixer = snd_hda_codec_read(
639 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
640 == ((spec->codec_type == VT1708S) ? 5 : 0);
641 /* inputs */
642 /* PW 1/2/5 (1ah/1bh/1eh) */
643 parm = AC_PWRST_D3;
644 set_pin_power_state(codec, 0x1a, &parm);
645 set_pin_power_state(codec, 0x1b, &parm);
646 set_pin_power_state(codec, 0x1e, &parm);
647 if (imux_is_smixer)
648 parm = AC_PWRST_D0;
649 /* SW0 (17h), AIW 0/1 (13h/14h) */
650 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
651 parm);
652 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
653 parm);
654 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
655 parm);
656
657 /* outputs */
658 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
659 parm = AC_PWRST_D3;
660 set_pin_power_state(codec, 0x19, &parm);
661 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
662 parm);
663 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
664 parm);
665
666 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
667 if (is_8ch) {
668 parm = AC_PWRST_D3;
669 set_pin_power_state(codec, 0x22, &parm);
670 snd_hda_codec_write(codec, 0x26, 0,
671 AC_VERB_SET_POWER_STATE, parm);
672 snd_hda_codec_write(codec, 0x24, 0,
673 AC_VERB_SET_POWER_STATE, parm);
674 }
675
676 /* PW 3/4/7 (1ch/1dh/23h) */
677 parm = AC_PWRST_D3;
678 /* force to D0 for internal Speaker */
679 set_pin_power_state(codec, 0x1c, &parm);
680 set_pin_power_state(codec, 0x1d, &parm);
681 if (is_8ch)
682 set_pin_power_state(codec, 0x23, &parm);
683 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
684 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
685 imux_is_smixer ? AC_PWRST_D0 : parm);
686 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
687 parm);
688 if (is_8ch) {
689 snd_hda_codec_write(codec, 0x25, 0,
690 AC_VERB_SET_POWER_STATE, parm);
691 snd_hda_codec_write(codec, 0x27, 0,
692 AC_VERB_SET_POWER_STATE, parm);
693 }
694 } else if (spec->codec_type == VT1718S) {
695 /* MUX6 (1eh) = stereo mixer */
696 imux_is_smixer = snd_hda_codec_read(
697 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
698 /* inputs */
699 /* PW 5/6/7 (29h/2ah/2bh) */
700 parm = AC_PWRST_D3;
701 set_pin_power_state(codec, 0x29, &parm);
702 set_pin_power_state(codec, 0x2a, &parm);
703 set_pin_power_state(codec, 0x2b, &parm);
704 if (imux_is_smixer)
705 parm = AC_PWRST_D0;
706 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
707 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
708 parm);
709 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
710 parm);
711 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
712 parm);
713 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
714 parm);
715
716 /* outputs */
717 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
718 parm = AC_PWRST_D3;
719 set_pin_power_state(codec, 0x27, &parm);
720 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
721 parm);
722 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
723 parm);
724
725 /* PW2 (26h), AOW2 (ah) */
726 parm = AC_PWRST_D3;
727 set_pin_power_state(codec, 0x26, &parm);
728 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
729 parm);
730
731 /* PW0/1 (24h/25h) */
732 parm = AC_PWRST_D3;
733 set_pin_power_state(codec, 0x24, &parm);
734 set_pin_power_state(codec, 0x25, &parm);
735 if (!spec->hp_independent_mode) /* check for redirected HP */
736 set_pin_power_state(codec, 0x28, &parm);
737 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
738 parm);
739 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
740 parm);
741 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
742 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
743 imux_is_smixer ? AC_PWRST_D0 : parm);
744 if (spec->hp_independent_mode) {
745 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
746 parm = AC_PWRST_D3;
747 set_pin_power_state(codec, 0x28, &parm);
748 snd_hda_codec_write(codec, 0x1b, 0,
749 AC_VERB_SET_POWER_STATE, parm);
750 snd_hda_codec_write(codec, 0x34, 0,
751 AC_VERB_SET_POWER_STATE, parm);
752 snd_hda_codec_write(codec, 0xc, 0,
753 AC_VERB_SET_POWER_STATE, parm);
754 }
755 } else if (spec->codec_type == VT1716S) {
756 unsigned int mono_out, present;
757 /* SW0 (17h) = stereo mixer */
758 imux_is_smixer = snd_hda_codec_read(
759 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
760 /* inputs */
761 /* PW 1/2/5 (1ah/1bh/1eh) */
762 parm = AC_PWRST_D3;
763 set_pin_power_state(codec, 0x1a, &parm);
764 set_pin_power_state(codec, 0x1b, &parm);
765 set_pin_power_state(codec, 0x1e, &parm);
766 if (imux_is_smixer)
767 parm = AC_PWRST_D0;
768 /* SW0 (17h), AIW0(13h) */
769 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
770 parm);
771 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
772 parm);
773
774 parm = AC_PWRST_D3;
775 set_pin_power_state(codec, 0x1e, &parm);
776 /* PW11 (22h) */
777 if (spec->dmic_enabled)
778 set_pin_power_state(codec, 0x22, &parm);
779 else
780 snd_hda_codec_write(
781 codec, 0x22, 0,
782 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
783
784 /* SW2(26h), AIW1(14h) */
785 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
786 parm);
787 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
788 parm);
789
790 /* outputs */
791 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
792 parm = AC_PWRST_D3;
793 set_pin_power_state(codec, 0x19, &parm);
794 /* Smart 5.1 PW2(1bh) */
795 if (spec->smart51_enabled)
796 set_pin_power_state(codec, 0x1b, &parm);
797 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
798 parm);
799 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
800 parm);
801
802 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
803 parm = AC_PWRST_D3;
804 set_pin_power_state(codec, 0x23, &parm);
805 /* Smart 5.1 PW1(1ah) */
806 if (spec->smart51_enabled)
807 set_pin_power_state(codec, 0x1a, &parm);
808 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
809 parm);
810
811 /* Smart 5.1 PW5(1eh) */
812 if (spec->smart51_enabled)
813 set_pin_power_state(codec, 0x1e, &parm);
814 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
815 parm);
816
817 /* Mono out */
818 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
819 present = snd_hda_jack_detect(codec, 0x1c);
820 if (present)
821 mono_out = 0;
822 else {
823 present = snd_hda_jack_detect(codec, 0x1d);
824 if (!spec->hp_independent_mode && present)
825 mono_out = 0;
826 else
827 mono_out = 1;
828 }
829 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
830 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
831 parm);
832 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
833 parm);
834 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
835 parm);
836
837 /* PW 3/4 (1ch/1dh) */
838 parm = AC_PWRST_D3;
839 set_pin_power_state(codec, 0x1c, &parm);
840 set_pin_power_state(codec, 0x1d, &parm);
841 /* HP Independent Mode, power on AOW3 */
842 if (spec->hp_independent_mode)
843 snd_hda_codec_write(codec, 0x25, 0,
844 AC_VERB_SET_POWER_STATE, parm);
845
846 /* force to D0 for internal Speaker */
847 /* MW0 (16h), AOW0 (10h) */
848 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
849 imux_is_smixer ? AC_PWRST_D0 : parm);
850 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
851 mono_out ? AC_PWRST_D0 : parm);
852 } else if (spec->codec_type == VT2002P) {
853 unsigned int present;
854 /* MUX9 (1eh) = stereo mixer */
855 imux_is_smixer = snd_hda_codec_read(
856 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
857 /* inputs */
858 /* PW 5/6/7 (29h/2ah/2bh) */
859 parm = AC_PWRST_D3;
860 set_pin_power_state(codec, 0x29, &parm);
861 set_pin_power_state(codec, 0x2a, &parm);
862 set_pin_power_state(codec, 0x2b, &parm);
863 if (imux_is_smixer)
864 parm = AC_PWRST_D0;
865 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
866 snd_hda_codec_write(codec, 0x1e, 0,
867 AC_VERB_SET_POWER_STATE, parm);
868 snd_hda_codec_write(codec, 0x1f, 0,
869 AC_VERB_SET_POWER_STATE, parm);
870 snd_hda_codec_write(codec, 0x10, 0,
871 AC_VERB_SET_POWER_STATE, parm);
872 snd_hda_codec_write(codec, 0x11, 0,
873 AC_VERB_SET_POWER_STATE, parm);
874
875 /* outputs */
876 /* AOW0 (8h)*/
877 snd_hda_codec_write(codec, 0x8, 0,
878 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
879
880 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
881 parm = AC_PWRST_D3;
882 set_pin_power_state(codec, 0x26, &parm);
883 snd_hda_codec_write(codec, 0x1c, 0,
884 AC_VERB_SET_POWER_STATE, parm);
885 snd_hda_codec_write(codec, 0x37,
886 0, AC_VERB_SET_POWER_STATE, parm);
887
888 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
889 parm = AC_PWRST_D3;
890 set_pin_power_state(codec, 0x25, &parm);
891 snd_hda_codec_write(codec, 0x19, 0,
892 AC_VERB_SET_POWER_STATE, parm);
893 snd_hda_codec_write(codec, 0x35, 0,
894 AC_VERB_SET_POWER_STATE, parm);
895 if (spec->hp_independent_mode) {
896 snd_hda_codec_write(codec, 0x9, 0,
897 AC_VERB_SET_POWER_STATE, parm);
898 }
899
900 /* Class-D */
901 /* PW0 (24h), MW0(18h), MUX0(34h) */
902 present = snd_hda_jack_detect(codec, 0x25);
903 parm = AC_PWRST_D3;
904 set_pin_power_state(codec, 0x24, &parm);
905 if (present) {
906 snd_hda_codec_write(
907 codec, 0x18, 0,
908 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
909 snd_hda_codec_write(
910 codec, 0x34, 0,
911 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
912 } else {
913 snd_hda_codec_write(
914 codec, 0x18, 0,
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
916 snd_hda_codec_write(
917 codec, 0x34, 0,
918 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
919 }
920
921 /* Mono Out */
922 /* PW15 (31h), MW8(17h), MUX8(3bh) */
923 present = snd_hda_jack_detect(codec, 0x26);
924 parm = AC_PWRST_D3;
925 set_pin_power_state(codec, 0x31, &parm);
926 if (present) {
927 snd_hda_codec_write(
928 codec, 0x17, 0,
929 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
930 snd_hda_codec_write(
931 codec, 0x3b, 0,
932 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
933 } else {
934 snd_hda_codec_write(
935 codec, 0x17, 0,
936 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
937 snd_hda_codec_write(
938 codec, 0x3b, 0,
939 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
940 }
941
942 /* MW9 (21h) */
943 if (imux_is_smixer || !is_aa_path_mute(codec))
944 snd_hda_codec_write(
945 codec, 0x21, 0,
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
947 else
948 snd_hda_codec_write(
949 codec, 0x21, 0,
950 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
951 } else if (spec->codec_type == VT1812) {
952 unsigned int present;
953 /* MUX10 (1eh) = stereo mixer */
954 imux_is_smixer = snd_hda_codec_read(
955 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
956 /* inputs */
957 /* PW 5/6/7 (29h/2ah/2bh) */
958 parm = AC_PWRST_D3;
959 set_pin_power_state(codec, 0x29, &parm);
960 set_pin_power_state(codec, 0x2a, &parm);
961 set_pin_power_state(codec, 0x2b, &parm);
962 if (imux_is_smixer)
963 parm = AC_PWRST_D0;
964 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
965 snd_hda_codec_write(codec, 0x1e, 0,
966 AC_VERB_SET_POWER_STATE, parm);
967 snd_hda_codec_write(codec, 0x1f, 0,
968 AC_VERB_SET_POWER_STATE, parm);
969 snd_hda_codec_write(codec, 0x10, 0,
970 AC_VERB_SET_POWER_STATE, parm);
971 snd_hda_codec_write(codec, 0x11, 0,
972 AC_VERB_SET_POWER_STATE, parm);
973
974 /* outputs */
975 /* AOW0 (8h)*/
976 snd_hda_codec_write(codec, 0x8, 0,
977 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
978
979 /* PW4 (28h), MW4 (18h), MUX4(38h) */
980 parm = AC_PWRST_D3;
981 set_pin_power_state(codec, 0x28, &parm);
982 snd_hda_codec_write(codec, 0x18, 0,
983 AC_VERB_SET_POWER_STATE, parm);
984 snd_hda_codec_write(codec, 0x38, 0,
985 AC_VERB_SET_POWER_STATE, parm);
986
987 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
988 parm = AC_PWRST_D3;
989 set_pin_power_state(codec, 0x25, &parm);
990 snd_hda_codec_write(codec, 0x15, 0,
991 AC_VERB_SET_POWER_STATE, parm);
992 snd_hda_codec_write(codec, 0x35, 0,
993 AC_VERB_SET_POWER_STATE, parm);
994 if (spec->hp_independent_mode) {
995 snd_hda_codec_write(codec, 0x9, 0,
996 AC_VERB_SET_POWER_STATE, parm);
997 }
998
999 /* Internal Speaker */
1000 /* PW0 (24h), MW0(14h), MUX0(34h) */
1001 present = snd_hda_jack_detect(codec, 0x25);
1002 parm = AC_PWRST_D3;
1003 set_pin_power_state(codec, 0x24, &parm);
1004 if (present) {
1005 snd_hda_codec_write(codec, 0x14, 0,
1006 AC_VERB_SET_POWER_STATE,
1007 AC_PWRST_D3);
1008 snd_hda_codec_write(codec, 0x34, 0,
1009 AC_VERB_SET_POWER_STATE,
1010 AC_PWRST_D3);
1011 } else {
1012 snd_hda_codec_write(codec, 0x14, 0,
1013 AC_VERB_SET_POWER_STATE,
1014 AC_PWRST_D0);
1015 snd_hda_codec_write(codec, 0x34, 0,
1016 AC_VERB_SET_POWER_STATE,
1017 AC_PWRST_D0);
1018 }
1019 /* Mono Out */
1020 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1021 present = snd_hda_jack_detect(codec, 0x28);
1022 parm = AC_PWRST_D3;
1023 set_pin_power_state(codec, 0x31, &parm);
1024 if (present) {
1025 snd_hda_codec_write(codec, 0x1c, 0,
1026 AC_VERB_SET_POWER_STATE,
1027 AC_PWRST_D3);
1028 snd_hda_codec_write(codec, 0x3c, 0,
1029 AC_VERB_SET_POWER_STATE,
1030 AC_PWRST_D3);
1031 snd_hda_codec_write(codec, 0x3e, 0,
1032 AC_VERB_SET_POWER_STATE,
1033 AC_PWRST_D3);
1034 } else {
1035 snd_hda_codec_write(codec, 0x1c, 0,
1036 AC_VERB_SET_POWER_STATE,
1037 AC_PWRST_D0);
1038 snd_hda_codec_write(codec, 0x3c, 0,
1039 AC_VERB_SET_POWER_STATE,
1040 AC_PWRST_D0);
1041 snd_hda_codec_write(codec, 0x3e, 0,
1042 AC_VERB_SET_POWER_STATE,
1043 AC_PWRST_D0);
1044 }
1045
1046 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1047 parm = AC_PWRST_D3;
1048 set_pin_power_state(codec, 0x33, &parm);
1049 snd_hda_codec_write(codec, 0x1d, 0,
1050 AC_VERB_SET_POWER_STATE, parm);
1051 snd_hda_codec_write(codec, 0x3d, 0,
1052 AC_VERB_SET_POWER_STATE, parm);
1053
1054 /* MW9 (21h) */
1055 if (imux_is_smixer || !is_aa_path_mute(codec))
1056 snd_hda_codec_write(
1057 codec, 0x21, 0,
1058 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1059 else
1060 snd_hda_codec_write(
1061 codec, 0x21, 0,
1062 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1063 }
1064}
1065
367/* 1066/*
368 * input MUX handling 1067 * input MUX handling
369 */ 1068 */
@@ -395,6 +1094,14 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
395 1094
396 if (!spec->mux_nids[adc_idx]) 1095 if (!spec->mux_nids[adc_idx])
397 return -EINVAL; 1096 return -EINVAL;
1097 /* switch to D0 beofre change index */
1098 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1099 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1100 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1101 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1102 /* update jack power state */
1103 set_jack_power_state(codec);
1104
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 1105 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 spec->mux_nids[adc_idx], 1106 spec->mux_nids[adc_idx],
400 &spec->cur_mux[adc_idx]); 1107 &spec->cur_mux[adc_idx]);
@@ -412,80 +1119,340 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
412 struct snd_ctl_elem_value *ucontrol) 1119 struct snd_ctl_elem_value *ucontrol)
413{ 1120{
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct via_spec *spec = codec->spec; 1122 hda_nid_t nid = kcontrol->private_value;
416 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1123 unsigned int pinsel;
417 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
418 AC_VERB_GET_CONNECT_SEL,
419 0x00);
420 1124
1125 /* use !! to translate conn sel 2 for VT1718S */
1126 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1127 AC_VERB_GET_CONNECT_SEL,
1128 0x00);
421 ucontrol->value.enumerated.item[0] = pinsel; 1129 ucontrol->value.enumerated.item[0] = pinsel;
422 1130
423 return 0; 1131 return 0;
424} 1132}
425 1133
1134static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1135{
1136 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1137 if (ctl) {
1138 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1139 ctl->vd[0].access |= active
1140 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1141 snd_ctl_notify(codec->bus->card,
1142 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1143 }
1144}
1145
1146static hda_nid_t side_mute_channel(struct via_spec *spec)
1147{
1148 switch (spec->codec_type) {
1149 case VT1708: return 0x1b;
1150 case VT1709_10CH: return 0x29;
1151 case VT1708B_8CH: /* fall thru */
1152 case VT1708S: return 0x27;
1153 default: return 0;
1154 }
1155}
1156
1157static int update_side_mute_status(struct hda_codec *codec)
1158{
1159 /* mute side channel */
1160 struct via_spec *spec = codec->spec;
1161 unsigned int parm = spec->hp_independent_mode
1162 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1163 hda_nid_t sw3 = side_mute_channel(spec);
1164
1165 if (sw3)
1166 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1167 parm);
1168 return 0;
1169}
1170
426static int via_independent_hp_put(struct snd_kcontrol *kcontrol, 1171static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol) 1172 struct snd_ctl_elem_value *ucontrol)
428{ 1173{
429 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
430 struct via_spec *spec = codec->spec; 1175 struct via_spec *spec = codec->spec;
431 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1176 hda_nid_t nid = kcontrol->private_value;
432 unsigned int pinsel = ucontrol->value.enumerated.item[0]; 1177 unsigned int pinsel = ucontrol->value.enumerated.item[0];
433 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0, 1178 /* Get Independent Mode index of headphone pin widget */
434 AC_VERB_GET_CONNECT_LIST, 0) & 0xff; 1179 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
435 1180 ? 1 : 0;
436 if (con_nid == spec->multiout.hp_nid) { 1181 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
437 if (pinsel == 0) { 1182
438 if (!spec->hp_independent_mode) { 1183 if (spec->multiout.hp_nid && spec->multiout.hp_nid
439 if (spec->multiout.num_dacs > 1) 1184 != spec->multiout.dac_nids[HDA_FRONT])
440 spec->multiout.num_dacs -= 1; 1185 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
441 spec->hp_independent_mode = 1; 1186 0, 0, 0);
442 } 1187
443 } else if (pinsel == 1) { 1188 update_side_mute_status(codec);
444 if (spec->hp_independent_mode) { 1189 /* update HP volume/swtich active state */
445 if (spec->multiout.num_dacs > 1) 1190 if (spec->codec_type == VT1708S
446 spec->multiout.num_dacs += 1; 1191 || spec->codec_type == VT1702
447 spec->hp_independent_mode = 0; 1192 || spec->codec_type == VT1718S
448 } 1193 || spec->codec_type == VT1716S
449 } 1194 || spec->codec_type == VT2002P
450 } else { 1195 || spec->codec_type == VT1812) {
451 if (pinsel == 0) { 1196 activate_ctl(codec, "Headphone Playback Volume",
452 if (spec->hp_independent_mode) { 1197 spec->hp_independent_mode);
453 if (spec->multiout.num_dacs > 1) 1198 activate_ctl(codec, "Headphone Playback Switch",
454 spec->multiout.num_dacs += 1; 1199 spec->hp_independent_mode);
455 spec->hp_independent_mode = 0;
456 }
457 } else if (pinsel == 1) {
458 if (!spec->hp_independent_mode) {
459 if (spec->multiout.num_dacs > 1)
460 spec->multiout.num_dacs -= 1;
461 spec->hp_independent_mode = 1;
462 }
463 }
464 } 1200 }
465 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
466 pinsel);
467
468 if (spec->multiout.hp_nid &&
469 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
470 snd_hda_codec_setup_stream(codec,
471 spec->multiout.hp_nid,
472 0, 0, 0);
473
474 return 0; 1201 return 0;
475} 1202}
476 1203
477static struct snd_kcontrol_new via_hp_mixer[] = { 1204static struct snd_kcontrol_new via_hp_mixer[2] = {
478 { 1205 {
479 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1206 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
480 .name = "Independent HP", 1207 .name = "Independent HP",
481 .count = 1,
482 .info = via_independent_hp_info, 1208 .info = via_independent_hp_info,
483 .get = via_independent_hp_get, 1209 .get = via_independent_hp_get,
484 .put = via_independent_hp_put, 1210 .put = via_independent_hp_put,
485 }, 1211 },
486 { } /* end */ 1212 {
1213 .iface = NID_MAPPING,
1214 .name = "Independent HP",
1215 },
1216};
1217
1218static int via_hp_build(struct hda_codec *codec)
1219{
1220 struct via_spec *spec = codec->spec;
1221 struct snd_kcontrol_new *knew;
1222 hda_nid_t nid;
1223 int nums;
1224 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1225
1226 switch (spec->codec_type) {
1227 case VT1718S:
1228 nid = 0x34;
1229 break;
1230 case VT2002P:
1231 nid = 0x35;
1232 break;
1233 case VT1812:
1234 nid = 0x3d;
1235 break;
1236 default:
1237 nid = spec->autocfg.hp_pins[0];
1238 break;
1239 }
1240
1241 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1242 if (nums <= 1)
1243 return 0;
1244
1245 knew = via_clone_control(spec, &via_hp_mixer[0]);
1246 if (knew == NULL)
1247 return -ENOMEM;
1248
1249 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1250 knew->private_value = nid;
1251
1252 knew = via_clone_control(spec, &via_hp_mixer[1]);
1253 if (knew == NULL)
1254 return -ENOMEM;
1255 knew->subdevice = side_mute_channel(spec);
1256
1257 return 0;
1258}
1259
1260static void notify_aa_path_ctls(struct hda_codec *codec)
1261{
1262 int i;
1263 struct snd_ctl_elem_id id;
1264 const char *labels[] = {"Mic", "Front Mic", "Line"};
1265
1266 memset(&id, 0, sizeof(id));
1267 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1268 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1269 sprintf(id.name, "%s Playback Volume", labels[i]);
1270 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1271 &id);
1272 }
1273}
1274
1275static void mute_aa_path(struct hda_codec *codec, int mute)
1276{
1277 struct via_spec *spec = codec->spec;
1278 hda_nid_t nid_mixer;
1279 int start_idx;
1280 int end_idx;
1281 int i;
1282 /* get nid of MW0 and start & end index */
1283 switch (spec->codec_type) {
1284 case VT1708:
1285 nid_mixer = 0x17;
1286 start_idx = 2;
1287 end_idx = 4;
1288 break;
1289 case VT1709_10CH:
1290 case VT1709_6CH:
1291 nid_mixer = 0x18;
1292 start_idx = 2;
1293 end_idx = 4;
1294 break;
1295 case VT1708B_8CH:
1296 case VT1708B_4CH:
1297 case VT1708S:
1298 case VT1716S:
1299 nid_mixer = 0x16;
1300 start_idx = 2;
1301 end_idx = 4;
1302 break;
1303 default:
1304 return;
1305 }
1306 /* check AA path's mute status */
1307 for (i = start_idx; i <= end_idx; i++) {
1308 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1309 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1310 HDA_AMP_MUTE, val);
1311 }
1312}
1313static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1314{
1315 int res = 0;
1316 int index;
1317 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1318 if (pin == spec->autocfg.input_pins[index]) {
1319 res = 1;
1320 break;
1321 }
1322 }
1323 return res;
1324}
1325
1326static int via_smart51_info(struct snd_kcontrol *kcontrol,
1327 struct snd_ctl_elem_info *uinfo)
1328{
1329 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1330 uinfo->count = 1;
1331 uinfo->value.integer.min = 0;
1332 uinfo->value.integer.max = 1;
1333 return 0;
1334}
1335
1336static int via_smart51_get(struct snd_kcontrol *kcontrol,
1337 struct snd_ctl_elem_value *ucontrol)
1338{
1339 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1340 struct via_spec *spec = codec->spec;
1341 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1342 int on = 1;
1343 int i;
1344
1345 for (i = 0; i < ARRAY_SIZE(index); i++) {
1346 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1347 if (nid) {
1348 int ctl =
1349 snd_hda_codec_read(codec, nid, 0,
1350 AC_VERB_GET_PIN_WIDGET_CONTROL,
1351 0);
1352 if (i == AUTO_PIN_FRONT_MIC
1353 && spec->hp_independent_mode
1354 && spec->codec_type != VT1718S)
1355 continue; /* ignore FMic for independent HP */
1356 if (ctl & AC_PINCTL_IN_EN
1357 && !(ctl & AC_PINCTL_OUT_EN))
1358 on = 0;
1359 }
1360 }
1361 *ucontrol->value.integer.value = on;
1362 return 0;
1363}
1364
1365static int via_smart51_put(struct snd_kcontrol *kcontrol,
1366 struct snd_ctl_elem_value *ucontrol)
1367{
1368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1369 struct via_spec *spec = codec->spec;
1370 int out_in = *ucontrol->value.integer.value
1371 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1372 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1373 int i;
1374
1375 for (i = 0; i < ARRAY_SIZE(index); i++) {
1376 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1377 if (i == AUTO_PIN_FRONT_MIC
1378 && spec->hp_independent_mode
1379 && spec->codec_type != VT1718S)
1380 continue; /* don't retask FMic for independent HP */
1381 if (nid) {
1382 unsigned int parm = snd_hda_codec_read(
1383 codec, nid, 0,
1384 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1385 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1386 parm |= out_in;
1387 snd_hda_codec_write(codec, nid, 0,
1388 AC_VERB_SET_PIN_WIDGET_CONTROL,
1389 parm);
1390 if (out_in == AC_PINCTL_OUT_EN) {
1391 mute_aa_path(codec, 1);
1392 notify_aa_path_ctls(codec);
1393 }
1394 if (spec->codec_type == VT1718S)
1395 snd_hda_codec_amp_stereo(
1396 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1397 HDA_AMP_UNMUTE);
1398 }
1399 if (i == AUTO_PIN_FRONT_MIC) {
1400 if (spec->codec_type == VT1708S
1401 || spec->codec_type == VT1716S) {
1402 /* input = index 1 (AOW3) */
1403 snd_hda_codec_write(
1404 codec, nid, 0,
1405 AC_VERB_SET_CONNECT_SEL, 1);
1406 snd_hda_codec_amp_stereo(
1407 codec, nid, HDA_OUTPUT,
1408 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1409 }
1410 }
1411 }
1412 spec->smart51_enabled = *ucontrol->value.integer.value;
1413 set_jack_power_state(codec);
1414 return 1;
1415}
1416
1417static struct snd_kcontrol_new via_smart51_mixer[2] = {
1418 {
1419 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1420 .name = "Smart 5.1",
1421 .count = 1,
1422 .info = via_smart51_info,
1423 .get = via_smart51_get,
1424 .put = via_smart51_put,
1425 },
1426 {
1427 .iface = NID_MAPPING,
1428 .name = "Smart 5.1",
1429 }
487}; 1430};
488 1431
1432static int via_smart51_build(struct via_spec *spec)
1433{
1434 struct snd_kcontrol_new *knew;
1435 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1436 hda_nid_t nid;
1437 int i;
1438
1439 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1440 if (knew == NULL)
1441 return -ENOMEM;
1442
1443 for (i = 0; i < ARRAY_SIZE(index); i++) {
1444 nid = spec->autocfg.input_pins[index[i]];
1445 if (nid) {
1446 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1447 if (knew == NULL)
1448 return -ENOMEM;
1449 knew->subdevice = nid;
1450 }
1451 }
1452
1453 return 0;
1454}
1455
489/* capture mixer elements */ 1456/* capture mixer elements */
490static struct snd_kcontrol_new vt1708_capture_mixer[] = { 1457static struct snd_kcontrol_new vt1708_capture_mixer[] = {
491 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), 1458 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
@@ -506,6 +1473,112 @@ static struct snd_kcontrol_new vt1708_capture_mixer[] = {
506 }, 1473 },
507 { } /* end */ 1474 { } /* end */
508}; 1475};
1476
1477/* check AA path's mute statue */
1478static int is_aa_path_mute(struct hda_codec *codec)
1479{
1480 int mute = 1;
1481 hda_nid_t nid_mixer;
1482 int start_idx;
1483 int end_idx;
1484 int i;
1485 struct via_spec *spec = codec->spec;
1486 /* get nid of MW0 and start & end index */
1487 switch (spec->codec_type) {
1488 case VT1708B_8CH:
1489 case VT1708B_4CH:
1490 case VT1708S:
1491 case VT1716S:
1492 nid_mixer = 0x16;
1493 start_idx = 2;
1494 end_idx = 4;
1495 break;
1496 case VT1702:
1497 nid_mixer = 0x1a;
1498 start_idx = 1;
1499 end_idx = 3;
1500 break;
1501 case VT1718S:
1502 nid_mixer = 0x21;
1503 start_idx = 1;
1504 end_idx = 3;
1505 break;
1506 case VT2002P:
1507 case VT1812:
1508 nid_mixer = 0x21;
1509 start_idx = 0;
1510 end_idx = 2;
1511 break;
1512 default:
1513 return 0;
1514 }
1515 /* check AA path's mute status */
1516 for (i = start_idx; i <= end_idx; i++) {
1517 unsigned int con_list = snd_hda_codec_read(
1518 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1519 int shift = 8 * (i % 4);
1520 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1521 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1522 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1523 /* check mute status while the pin is connected */
1524 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1525 HDA_INPUT, i) >> 7;
1526 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1527 HDA_INPUT, i) >> 7;
1528 if (!mute_l || !mute_r) {
1529 mute = 0;
1530 break;
1531 }
1532 }
1533 }
1534 return mute;
1535}
1536
1537/* enter/exit analog low-current mode */
1538static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1539{
1540 struct via_spec *spec = codec->spec;
1541 static int saved_stream_idle = 1; /* saved stream idle status */
1542 int enable = is_aa_path_mute(codec);
1543 unsigned int verb = 0;
1544 unsigned int parm = 0;
1545
1546 if (stream_idle == -1) /* stream status did not change */
1547 enable = enable && saved_stream_idle;
1548 else {
1549 enable = enable && stream_idle;
1550 saved_stream_idle = stream_idle;
1551 }
1552
1553 /* decide low current mode's verb & parameter */
1554 switch (spec->codec_type) {
1555 case VT1708B_8CH:
1556 case VT1708B_4CH:
1557 verb = 0xf70;
1558 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1559 break;
1560 case VT1708S:
1561 case VT1718S:
1562 case VT1716S:
1563 verb = 0xf73;
1564 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1565 break;
1566 case VT1702:
1567 verb = 0xf73;
1568 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1569 break;
1570 case VT2002P:
1571 case VT1812:
1572 verb = 0xf93;
1573 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1574 break;
1575 default:
1576 return; /* other codecs are not supported */
1577 }
1578 /* send verb */
1579 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1580}
1581
509/* 1582/*
510 * generic initialization of ADC, input mixers and output mixers 1583 * generic initialization of ADC, input mixers and output mixers
511 */ 1584 */
@@ -534,9 +1607,9 @@ static struct hda_verb vt1708_volume_init_verbs[] = {
534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1607 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
535 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1608 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
536 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1609 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
537 1610
538 /* Setup default input to PW4 */ 1611 /* Setup default input MW0 to PW4 */
539 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 1612 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
540 /* PW9 Output enable */ 1613 /* PW9 Output enable */
541 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 1614 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
542 { } 1615 { }
@@ -547,30 +1620,13 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
547 struct snd_pcm_substream *substream) 1620 struct snd_pcm_substream *substream)
548{ 1621{
549 struct via_spec *spec = codec->spec; 1622 struct via_spec *spec = codec->spec;
1623 int idle = substream->pstr->substream_opened == 1
1624 && substream->ref_count == 0;
1625 analog_low_current_mode(codec, idle);
550 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1626 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
551 hinfo); 1627 hinfo);
552} 1628}
553 1629
554static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
555 struct hda_codec *codec,
556 unsigned int stream_tag,
557 unsigned int format,
558 struct snd_pcm_substream *substream)
559{
560 struct via_spec *spec = codec->spec;
561 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
562 stream_tag, format, substream);
563}
564
565static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
566 struct hda_codec *codec,
567 struct snd_pcm_substream *substream)
568{
569 struct via_spec *spec = codec->spec;
570 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
571}
572
573
574static void playback_multi_pcm_prep_0(struct hda_codec *codec, 1630static void playback_multi_pcm_prep_0(struct hda_codec *codec,
575 unsigned int stream_tag, 1631 unsigned int stream_tag,
576 unsigned int format, 1632 unsigned int format,
@@ -615,8 +1671,8 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec,
615 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 1671 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
616 0, format); 1672 0, format);
617 1673
618 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && 1674 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
619 !spec->hp_independent_mode) 1675 && !spec->hp_independent_mode)
620 /* headphone out will just decode front left/right (stereo) */ 1676 /* headphone out will just decode front left/right (stereo) */
621 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 1677 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
622 0, format); 1678 0, format);
@@ -658,7 +1714,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
658 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1714 snd_hda_codec_setup_stream(codec, mout->hp_nid,
659 stream_tag, 0, format); 1715 stream_tag, 0, format);
660 } 1716 }
661 1717 vt1708_start_hp_work(spec);
662 return 0; 1718 return 0;
663} 1719}
664 1720
@@ -698,7 +1754,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
698 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1754 snd_hda_codec_setup_stream(codec, mout->hp_nid,
699 0, 0, 0); 1755 0, 0, 0);
700 } 1756 }
701 1757 vt1708_stop_hp_work(spec);
702 return 0; 1758 return 0;
703} 1759}
704 1760
@@ -779,7 +1835,7 @@ static struct hda_pcm_stream vt1708_pcm_analog_playback = {
779}; 1835};
780 1836
781static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { 1837static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
782 .substreams = 1, 1838 .substreams = 2,
783 .channels_min = 2, 1839 .channels_min = 2,
784 .channels_max = 8, 1840 .channels_max = 8,
785 .nid = 0x10, /* NID to query formats and rates */ 1841 .nid = 0x10, /* NID to query formats and rates */
@@ -790,8 +1846,8 @@ static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
790 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1846 .formats = SNDRV_PCM_FMTBIT_S16_LE,
791 .ops = { 1847 .ops = {
792 .open = via_playback_pcm_open, 1848 .open = via_playback_pcm_open,
793 .prepare = via_playback_pcm_prepare, 1849 .prepare = via_playback_multi_pcm_prepare,
794 .cleanup = via_playback_pcm_cleanup 1850 .cleanup = via_playback_multi_pcm_cleanup
795 }, 1851 },
796}; 1852};
797 1853
@@ -828,8 +1884,9 @@ static struct hda_pcm_stream vt1708_pcm_digital_capture = {
828static int via_build_controls(struct hda_codec *codec) 1884static int via_build_controls(struct hda_codec *codec)
829{ 1885{
830 struct via_spec *spec = codec->spec; 1886 struct via_spec *spec = codec->spec;
831 int err; 1887 struct snd_kcontrol *kctl;
832 int i; 1888 struct snd_kcontrol_new *knew;
1889 int err, i;
833 1890
834 for (i = 0; i < spec->num_mixers; i++) { 1891 for (i = 0; i < spec->num_mixers; i++) {
835 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 1892 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -853,6 +1910,32 @@ static int via_build_controls(struct hda_codec *codec)
853 if (err < 0) 1910 if (err < 0)
854 return err; 1911 return err;
855 } 1912 }
1913
1914 /* assign Capture Source enums to NID */
1915 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1916 for (i = 0; kctl && i < kctl->count; i++) {
1917 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1918 if (err < 0)
1919 return err;
1920 }
1921
1922 /* other nid->control mapping */
1923 for (i = 0; i < spec->num_mixers; i++) {
1924 for (knew = spec->mixers[i]; knew->name; knew++) {
1925 if (knew->iface != NID_MAPPING)
1926 continue;
1927 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1928 if (kctl == NULL)
1929 continue;
1930 err = snd_hda_add_nid(codec, kctl, 0,
1931 knew->subdevice);
1932 }
1933 }
1934
1935 /* init power states */
1936 set_jack_power_state(codec);
1937 analog_low_current_mode(codec, 1);
1938
856 via_free_kctls(codec); /* no longer needed */ 1939 via_free_kctls(codec); /* no longer needed */
857 return 0; 1940 return 0;
858} 1941}
@@ -866,8 +1949,10 @@ static int via_build_pcms(struct hda_codec *codec)
866 codec->pcm_info = info; 1949 codec->pcm_info = info;
867 1950
868 info->name = spec->stream_name_analog; 1951 info->name = spec->stream_name_analog;
869 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); 1952 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
870 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 1953 *(spec->stream_analog_playback);
1954 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1955 spec->multiout.dac_nids[0];
871 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); 1956 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
872 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 1957 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
873 1958
@@ -904,20 +1989,58 @@ static void via_free(struct hda_codec *codec)
904 return; 1989 return;
905 1990
906 via_free_kctls(codec); 1991 via_free_kctls(codec);
1992 vt1708_stop_hp_work(spec);
907 kfree(codec->spec); 1993 kfree(codec->spec);
908} 1994}
909 1995
910/* mute internal speaker if HP is plugged */ 1996/* mute internal speaker if HP is plugged */
911static void via_hp_automute(struct hda_codec *codec) 1997static void via_hp_automute(struct hda_codec *codec)
912{ 1998{
913 unsigned int present; 1999 unsigned int present = 0;
914 struct via_spec *spec = codec->spec; 2000 struct via_spec *spec = codec->spec;
915 2001
916 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, 2002 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
917 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 2003
918 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], 2004 if (!spec->hp_independent_mode) {
919 HDA_OUTPUT, 0, HDA_AMP_MUTE, 2005 struct snd_ctl_elem_id id;
920 present ? HDA_AMP_MUTE : 0); 2006 /* auto mute */
2007 snd_hda_codec_amp_stereo(
2008 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2009 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2010 /* notify change */
2011 memset(&id, 0, sizeof(id));
2012 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2013 strcpy(id.name, "Front Playback Switch");
2014 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2015 &id);
2016 }
2017}
2018
2019/* mute mono out if HP or Line out is plugged */
2020static void via_mono_automute(struct hda_codec *codec)
2021{
2022 unsigned int hp_present, lineout_present;
2023 struct via_spec *spec = codec->spec;
2024
2025 if (spec->codec_type != VT1716S)
2026 return;
2027
2028 lineout_present = snd_hda_jack_detect(codec,
2029 spec->autocfg.line_out_pins[0]);
2030
2031 /* Mute Mono Out if Line Out is plugged */
2032 if (lineout_present) {
2033 snd_hda_codec_amp_stereo(
2034 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2035 return;
2036 }
2037
2038 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2039
2040 if (!spec->hp_independent_mode)
2041 snd_hda_codec_amp_stereo(
2042 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2043 hp_present ? HDA_AMP_MUTE : 0);
921} 2044}
922 2045
923static void via_gpio_control(struct hda_codec *codec) 2046static void via_gpio_control(struct hda_codec *codec)
@@ -968,15 +2091,83 @@ static void via_gpio_control(struct hda_codec *codec)
968 } 2091 }
969} 2092}
970 2093
2094/* mute Internal-Speaker if HP is plugged */
2095static void via_speaker_automute(struct hda_codec *codec)
2096{
2097 unsigned int hp_present;
2098 struct via_spec *spec = codec->spec;
2099
2100 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2101 return;
2102
2103 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2104
2105 if (!spec->hp_independent_mode) {
2106 struct snd_ctl_elem_id id;
2107 snd_hda_codec_amp_stereo(
2108 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2109 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2110 /* notify change */
2111 memset(&id, 0, sizeof(id));
2112 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2113 strcpy(id.name, "Speaker Playback Switch");
2114 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2115 &id);
2116 }
2117}
2118
2119/* mute line-out and internal speaker if HP is plugged */
2120static void via_hp_bind_automute(struct hda_codec *codec)
2121{
2122 /* use long instead of int below just to avoid an internal compiler
2123 * error with gcc 4.0.x
2124 */
2125 unsigned long hp_present, present = 0;
2126 struct via_spec *spec = codec->spec;
2127 int i;
2128
2129 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2130 return;
2131
2132 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2133
2134 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2135
2136 if (!spec->hp_independent_mode) {
2137 /* Mute Line-Outs */
2138 for (i = 0; i < spec->autocfg.line_outs; i++)
2139 snd_hda_codec_amp_stereo(
2140 codec, spec->autocfg.line_out_pins[i],
2141 HDA_OUTPUT, 0,
2142 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2143 if (hp_present)
2144 present = hp_present;
2145 }
2146 /* Speakers */
2147 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2148 snd_hda_codec_amp_stereo(
2149 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2150 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2151}
2152
2153
971/* unsolicited event for jack sensing */ 2154/* unsolicited event for jack sensing */
972static void via_unsol_event(struct hda_codec *codec, 2155static void via_unsol_event(struct hda_codec *codec,
973 unsigned int res) 2156 unsigned int res)
974{ 2157{
975 res >>= 26; 2158 res >>= 26;
976 if (res == VIA_HP_EVENT) 2159 if (res & VIA_HP_EVENT)
977 via_hp_automute(codec); 2160 via_hp_automute(codec);
978 else if (res == VIA_GPIO_EVENT) 2161 if (res & VIA_GPIO_EVENT)
979 via_gpio_control(codec); 2162 via_gpio_control(codec);
2163 if (res & VIA_JACK_EVENT)
2164 set_jack_power_state(codec);
2165 if (res & VIA_MONO_EVENT)
2166 via_mono_automute(codec);
2167 if (res & VIA_SPEAKER_EVENT)
2168 via_speaker_automute(codec);
2169 if (res & VIA_BIND_HP_EVENT)
2170 via_hp_bind_automute(codec);
980} 2171}
981 2172
982static int via_init(struct hda_codec *codec) 2173static int via_init(struct hda_codec *codec)
@@ -986,6 +2177,10 @@ static int via_init(struct hda_codec *codec)
986 for (i = 0; i < spec->num_iverbs; i++) 2177 for (i = 0; i < spec->num_iverbs; i++)
987 snd_hda_sequence_write(codec, spec->init_verbs[i]); 2178 snd_hda_sequence_write(codec, spec->init_verbs[i]);
988 2179
2180 spec->codec_type = get_codec_type(codec);
2181 if (spec->codec_type == VT1708BCE)
2182 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2183 same */
989 /* Lydia Add for EAPD enable */ 2184 /* Lydia Add for EAPD enable */
990 if (!spec->dig_in_nid) { /* No Digital In connection */ 2185 if (!spec->dig_in_nid) { /* No Digital In connection */
991 if (spec->dig_in_pin) { 2186 if (spec->dig_in_pin) {
@@ -1003,9 +2198,18 @@ static int via_init(struct hda_codec *codec)
1003 if (spec->slave_dig_outs[0]) 2198 if (spec->slave_dig_outs[0])
1004 codec->slave_dig_outs = spec->slave_dig_outs; 2199 codec->slave_dig_outs = spec->slave_dig_outs;
1005 2200
1006 return 0; 2201 return 0;
1007} 2202}
1008 2203
2204#ifdef SND_HDA_NEEDS_RESUME
2205static int via_suspend(struct hda_codec *codec, pm_message_t state)
2206{
2207 struct via_spec *spec = codec->spec;
2208 vt1708_stop_hp_work(spec);
2209 return 0;
2210}
2211#endif
2212
1009#ifdef CONFIG_SND_HDA_POWER_SAVE 2213#ifdef CONFIG_SND_HDA_POWER_SAVE
1010static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 2214static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1011{ 2215{
@@ -1021,6 +2225,9 @@ static struct hda_codec_ops via_patch_ops = {
1021 .build_pcms = via_build_pcms, 2225 .build_pcms = via_build_pcms,
1022 .init = via_init, 2226 .init = via_init,
1023 .free = via_free, 2227 .free = via_free,
2228#ifdef SND_HDA_NEEDS_RESUME
2229 .suspend = via_suspend,
2230#endif
1024#ifdef CONFIG_SND_HDA_POWER_SAVE 2231#ifdef CONFIG_SND_HDA_POWER_SAVE
1025 .check_power_status = via_check_power_status, 2232 .check_power_status = via_check_power_status,
1026#endif 2233#endif
@@ -1036,8 +2243,8 @@ static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1036 spec->multiout.num_dacs = cfg->line_outs; 2243 spec->multiout.num_dacs = cfg->line_outs;
1037 2244
1038 spec->multiout.dac_nids = spec->private_dac_nids; 2245 spec->multiout.dac_nids = spec->private_dac_nids;
1039 2246
1040 for(i = 0; i < 4; i++) { 2247 for (i = 0; i < 4; i++) {
1041 nid = cfg->line_out_pins[i]; 2248 nid = cfg->line_out_pins[i];
1042 if (nid) { 2249 if (nid) {
1043 /* config dac list */ 2250 /* config dac list */
@@ -1067,7 +2274,7 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1067{ 2274{
1068 char name[32]; 2275 char name[32];
1069 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2276 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1070 hda_nid_t nid, nid_vol = 0; 2277 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1071 int i, err; 2278 int i, err;
1072 2279
1073 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2280 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
@@ -1075,9 +2282,8 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1075 2282
1076 if (!nid) 2283 if (!nid)
1077 continue; 2284 continue;
1078 2285
1079 if (i != AUTO_SEQ_FRONT) 2286 nid_vol = nid_vols[i];
1080 nid_vol = 0x18 + i;
1081 2287
1082 if (i == AUTO_SEQ_CENLFE) { 2288 if (i == AUTO_SEQ_CENLFE) {
1083 /* Center/LFE */ 2289 /* Center/LFE */
@@ -1105,21 +2311,21 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1105 HDA_OUTPUT)); 2311 HDA_OUTPUT));
1106 if (err < 0) 2312 if (err < 0)
1107 return err; 2313 return err;
1108 } else if (i == AUTO_SEQ_FRONT){ 2314 } else if (i == AUTO_SEQ_FRONT) {
1109 /* add control to mixer index 0 */ 2315 /* add control to mixer index 0 */
1110 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2316 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1111 "Master Front Playback Volume", 2317 "Master Front Playback Volume",
1112 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2318 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1113 HDA_INPUT)); 2319 HDA_INPUT));
1114 if (err < 0) 2320 if (err < 0)
1115 return err; 2321 return err;
1116 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2322 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1117 "Master Front Playback Switch", 2323 "Master Front Playback Switch",
1118 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2324 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1119 HDA_INPUT)); 2325 HDA_INPUT));
1120 if (err < 0) 2326 if (err < 0)
1121 return err; 2327 return err;
1122 2328
1123 /* add control to PW3 */ 2329 /* add control to PW3 */
1124 sprintf(name, "%s Playback Volume", chname[i]); 2330 sprintf(name, "%s Playback Volume", chname[i]);
1125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2331 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1178,6 +2384,7 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1178 return 0; 2384 return 0;
1179 2385
1180 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ 2386 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2387 spec->hp_independent_mode_index = 1;
1181 2388
1182 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2389 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1183 "Headphone Playback Volume", 2390 "Headphone Playback Volume",
@@ -1218,7 +2425,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1218 case 0x1d: /* Mic */ 2425 case 0x1d: /* Mic */
1219 idx = 2; 2426 idx = 2;
1220 break; 2427 break;
1221 2428
1222 case 0x1e: /* Line In */ 2429 case 0x1e: /* Line In */
1223 idx = 3; 2430 idx = 3;
1224 break; 2431 break;
@@ -1231,8 +2438,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1231 idx = 1; 2438 idx = 1;
1232 break; 2439 break;
1233 } 2440 }
1234 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2441 err = via_new_analog_input(spec, labels[i], idx, 0x17);
1235 idx, 0x17);
1236 if (err < 0) 2442 if (err < 0)
1237 return err; 2443 return err;
1238 imux->items[imux->num_items].label = labels[i]; 2444 imux->items[imux->num_items].label = labels[i];
@@ -1260,16 +2466,60 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1260 def_conf = snd_hda_codec_get_pincfg(codec, nid); 2466 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1261 seqassoc = (unsigned char) get_defcfg_association(def_conf); 2467 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1262 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); 2468 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1263 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { 2469 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
1264 if (seqassoc == 0xff) { 2470 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
1265 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); 2471 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1266 snd_hda_codec_set_pincfg(codec, nid, def_conf); 2472 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1267 }
1268 } 2473 }
1269 2474
1270 return; 2475 return;
1271} 2476}
1272 2477
2478static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2479 struct snd_ctl_elem_value *ucontrol)
2480{
2481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2482 struct via_spec *spec = codec->spec;
2483
2484 if (spec->codec_type != VT1708)
2485 return 0;
2486 spec->vt1708_jack_detectect =
2487 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2488 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2489 return 0;
2490}
2491
2492static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2493 struct snd_ctl_elem_value *ucontrol)
2494{
2495 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2496 struct via_spec *spec = codec->spec;
2497 int change;
2498
2499 if (spec->codec_type != VT1708)
2500 return 0;
2501 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2502 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2503 == !spec->vt1708_jack_detectect;
2504 if (spec->vt1708_jack_detectect) {
2505 mute_aa_path(codec, 1);
2506 notify_aa_path_ctls(codec);
2507 }
2508 return change;
2509}
2510
2511static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2512 {
2513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2514 .name = "Jack Detect",
2515 .count = 1,
2516 .info = snd_ctl_boolean_mono_info,
2517 .get = vt1708_jack_detectect_get,
2518 .put = vt1708_jack_detectect_put,
2519 },
2520 {} /* end */
2521};
2522
1273static int vt1708_parse_auto_config(struct hda_codec *codec) 2523static int vt1708_parse_auto_config(struct hda_codec *codec)
1274{ 2524{
1275 struct via_spec *spec = codec->spec; 2525 struct via_spec *spec = codec->spec;
@@ -1297,6 +2547,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1297 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); 2547 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1298 if (err < 0) 2548 if (err < 0)
1299 return err; 2549 return err;
2550 /* add jack detect on/off control */
2551 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2552 if (err < 0)
2553 return err;
1300 2554
1301 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2555 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1302 2556
@@ -1314,21 +2568,46 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1314 spec->input_mux = &spec->private_imux[0]; 2568 spec->input_mux = &spec->private_imux[0];
1315 2569
1316 if (spec->hp_mux) 2570 if (spec->hp_mux)
1317 spec->mixers[spec->num_mixers++] = via_hp_mixer; 2571 via_hp_build(codec);
1318 2572
2573 via_smart51_build(spec);
1319 return 1; 2574 return 1;
1320} 2575}
1321 2576
1322/* init callback for auto-configuration model -- overriding the default init */ 2577/* init callback for auto-configuration model -- overriding the default init */
1323static int via_auto_init(struct hda_codec *codec) 2578static int via_auto_init(struct hda_codec *codec)
1324{ 2579{
2580 struct via_spec *spec = codec->spec;
2581
1325 via_init(codec); 2582 via_init(codec);
1326 via_auto_init_multi_out(codec); 2583 via_auto_init_multi_out(codec);
1327 via_auto_init_hp_out(codec); 2584 via_auto_init_hp_out(codec);
1328 via_auto_init_analog_input(codec); 2585 via_auto_init_analog_input(codec);
2586 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2587 via_hp_bind_automute(codec);
2588 } else {
2589 via_hp_automute(codec);
2590 via_speaker_automute(codec);
2591 }
2592
1329 return 0; 2593 return 0;
1330} 2594}
1331 2595
2596static void vt1708_update_hp_jack_state(struct work_struct *work)
2597{
2598 struct via_spec *spec = container_of(work, struct via_spec,
2599 vt1708_hp_work.work);
2600 if (spec->codec_type != VT1708)
2601 return;
2602 /* if jack state toggled */
2603 if (spec->vt1708_hp_present
2604 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2605 spec->vt1708_hp_present ^= 1;
2606 via_hp_automute(spec->codec);
2607 }
2608 vt1708_start_hp_work(spec);
2609}
2610
1332static int get_mux_nids(struct hda_codec *codec) 2611static int get_mux_nids(struct hda_codec *codec)
1333{ 2612{
1334 struct via_spec *spec = codec->spec; 2613 struct via_spec *spec = codec->spec;
@@ -1362,12 +2641,10 @@ static int patch_vt1708(struct hda_codec *codec)
1362 int err; 2641 int err;
1363 2642
1364 /* create a codec specific record */ 2643 /* create a codec specific record */
1365 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2644 spec = via_new_spec(codec);
1366 if (spec == NULL) 2645 if (spec == NULL)
1367 return -ENOMEM; 2646 return -ENOMEM;
1368 2647
1369 codec->spec = spec;
1370
1371 /* automatic parse from the BIOS config */ 2648 /* automatic parse from the BIOS config */
1372 err = vt1708_parse_auto_config(codec); 2649 err = vt1708_parse_auto_config(codec);
1373 if (err < 0) { 2650 if (err < 0) {
@@ -1378,7 +2655,7 @@ static int patch_vt1708(struct hda_codec *codec)
1378 "from BIOS. Using genenic mode...\n"); 2655 "from BIOS. Using genenic mode...\n");
1379 } 2656 }
1380 2657
1381 2658
1382 spec->stream_name_analog = "VT1708 Analog"; 2659 spec->stream_name_analog = "VT1708 Analog";
1383 spec->stream_analog_playback = &vt1708_pcm_analog_playback; 2660 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1384 /* disable 32bit format on VT1708 */ 2661 /* disable 32bit format on VT1708 */
@@ -1390,7 +2667,7 @@ static int patch_vt1708(struct hda_codec *codec)
1390 spec->stream_digital_playback = &vt1708_pcm_digital_playback; 2667 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1391 spec->stream_digital_capture = &vt1708_pcm_digital_capture; 2668 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1392 2669
1393 2670
1394 if (!spec->adc_nids && spec->input_mux) { 2671 if (!spec->adc_nids && spec->input_mux) {
1395 spec->adc_nids = vt1708_adc_nids; 2672 spec->adc_nids = vt1708_adc_nids;
1396 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); 2673 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
@@ -1405,7 +2682,7 @@ static int patch_vt1708(struct hda_codec *codec)
1405#ifdef CONFIG_SND_HDA_POWER_SAVE 2682#ifdef CONFIG_SND_HDA_POWER_SAVE
1406 spec->loopback.amplist = vt1708_loopbacks; 2683 spec->loopback.amplist = vt1708_loopbacks;
1407#endif 2684#endif
1408 2685 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
1409 return 0; 2686 return 0;
1410} 2687}
1411 2688
@@ -1433,7 +2710,8 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1433}; 2710};
1434 2711
1435static struct hda_verb vt1709_uniwill_init_verbs[] = { 2712static struct hda_verb vt1709_uniwill_init_verbs[] = {
1436 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 2713 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2714 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
1437 { } 2715 { }
1438}; 2716};
1439 2717
@@ -1473,8 +2751,8 @@ static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1473 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2751 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1474 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2752 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1475 2753
1476 /* Set input of PW4 as AOW4 */ 2754 /* Set input of PW4 as MW0 */
1477 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 2755 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1478 /* PW9 Output enable */ 2756 /* PW9 Output enable */
1479 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 2757 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1480 { } 2758 { }
@@ -1487,8 +2765,8 @@ static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1487 .nid = 0x10, /* NID to query formats and rates */ 2765 .nid = 0x10, /* NID to query formats and rates */
1488 .ops = { 2766 .ops = {
1489 .open = via_playback_pcm_open, 2767 .open = via_playback_pcm_open,
1490 .prepare = via_playback_pcm_prepare, 2768 .prepare = via_playback_multi_pcm_prepare,
1491 .cleanup = via_playback_pcm_cleanup 2769 .cleanup = via_playback_multi_pcm_cleanup,
1492 }, 2770 },
1493}; 2771};
1494 2772
@@ -1499,8 +2777,8 @@ static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1499 .nid = 0x10, /* NID to query formats and rates */ 2777 .nid = 0x10, /* NID to query formats and rates */
1500 .ops = { 2778 .ops = {
1501 .open = via_playback_pcm_open, 2779 .open = via_playback_pcm_open,
1502 .prepare = via_playback_pcm_prepare, 2780 .prepare = via_playback_multi_pcm_prepare,
1503 .cleanup = via_playback_pcm_cleanup 2781 .cleanup = via_playback_multi_pcm_cleanup,
1504 }, 2782 },
1505}; 2783};
1506 2784
@@ -1575,11 +2853,11 @@ static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1575 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ 2853 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1576 2854
1577 } else if (cfg->line_outs == 3) { /* 6 channels */ 2855 } else if (cfg->line_outs == 3) { /* 6 channels */
1578 for(i = 0; i < cfg->line_outs; i++) { 2856 for (i = 0; i < cfg->line_outs; i++) {
1579 nid = cfg->line_out_pins[i]; 2857 nid = cfg->line_out_pins[i];
1580 if (nid) { 2858 if (nid) {
1581 /* config dac list */ 2859 /* config dac list */
1582 switch(i) { 2860 switch (i) {
1583 case AUTO_SEQ_FRONT: 2861 case AUTO_SEQ_FRONT:
1584 /* AOW0 */ 2862 /* AOW0 */
1585 spec->multiout.dac_nids[i] = 0x10; 2863 spec->multiout.dac_nids[i] = 0x10;
@@ -1608,56 +2886,58 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1608{ 2886{
1609 char name[32]; 2887 char name[32];
1610 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2888 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1611 hda_nid_t nid = 0; 2889 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
1612 int i, err; 2890 int i, err;
1613 2891
1614 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2892 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1615 nid = cfg->line_out_pins[i]; 2893 nid = cfg->line_out_pins[i];
1616 2894
1617 if (!nid) 2895 if (!nid)
1618 continue; 2896 continue;
1619 2897
2898 nid_vol = nid_vols[i];
2899
1620 if (i == AUTO_SEQ_CENLFE) { 2900 if (i == AUTO_SEQ_CENLFE) {
1621 /* Center/LFE */ 2901 /* Center/LFE */
1622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2902 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1623 "Center Playback Volume", 2903 "Center Playback Volume",
1624 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2904 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1625 HDA_OUTPUT)); 2905 HDA_OUTPUT));
1626 if (err < 0) 2906 if (err < 0)
1627 return err; 2907 return err;
1628 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2908 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1629 "LFE Playback Volume", 2909 "LFE Playback Volume",
1630 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2910 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1631 HDA_OUTPUT)); 2911 HDA_OUTPUT));
1632 if (err < 0) 2912 if (err < 0)
1633 return err; 2913 return err;
1634 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2914 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1635 "Center Playback Switch", 2915 "Center Playback Switch",
1636 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2916 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1637 HDA_OUTPUT)); 2917 HDA_OUTPUT));
1638 if (err < 0) 2918 if (err < 0)
1639 return err; 2919 return err;
1640 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2920 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1641 "LFE Playback Switch", 2921 "LFE Playback Switch",
1642 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2922 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1643 HDA_OUTPUT)); 2923 HDA_OUTPUT));
1644 if (err < 0) 2924 if (err < 0)
1645 return err; 2925 return err;
1646 } else if (i == AUTO_SEQ_FRONT){ 2926 } else if (i == AUTO_SEQ_FRONT) {
1647 /* add control to mixer index 0 */ 2927 /* ADD control to mixer index 0 */
1648 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2928 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1649 "Master Front Playback Volume", 2929 "Master Front Playback Volume",
1650 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2930 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1651 HDA_INPUT)); 2931 HDA_INPUT));
1652 if (err < 0) 2932 if (err < 0)
1653 return err; 2933 return err;
1654 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2934 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1655 "Master Front Playback Switch", 2935 "Master Front Playback Switch",
1656 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2936 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1657 HDA_INPUT)); 2937 HDA_INPUT));
1658 if (err < 0) 2938 if (err < 0)
1659 return err; 2939 return err;
1660 2940
1661 /* add control to PW3 */ 2941 /* add control to PW3 */
1662 sprintf(name, "%s Playback Volume", chname[i]); 2942 sprintf(name, "%s Playback Volume", chname[i]);
1663 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2943 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1674,26 +2954,26 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1674 } else if (i == AUTO_SEQ_SURROUND) { 2954 } else if (i == AUTO_SEQ_SURROUND) {
1675 sprintf(name, "%s Playback Volume", chname[i]); 2955 sprintf(name, "%s Playback Volume", chname[i]);
1676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2956 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1677 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2957 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1678 HDA_OUTPUT)); 2958 HDA_OUTPUT));
1679 if (err < 0) 2959 if (err < 0)
1680 return err; 2960 return err;
1681 sprintf(name, "%s Playback Switch", chname[i]); 2961 sprintf(name, "%s Playback Switch", chname[i]);
1682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2962 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1683 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2963 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1684 HDA_OUTPUT)); 2964 HDA_OUTPUT));
1685 if (err < 0) 2965 if (err < 0)
1686 return err; 2966 return err;
1687 } else if (i == AUTO_SEQ_SIDE) { 2967 } else if (i == AUTO_SEQ_SIDE) {
1688 sprintf(name, "%s Playback Volume", chname[i]); 2968 sprintf(name, "%s Playback Volume", chname[i]);
1689 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2969 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1690 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2970 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1691 HDA_OUTPUT)); 2971 HDA_OUTPUT));
1692 if (err < 0) 2972 if (err < 0)
1693 return err; 2973 return err;
1694 sprintf(name, "%s Playback Switch", chname[i]); 2974 sprintf(name, "%s Playback Switch", chname[i]);
1695 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2975 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1696 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2976 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1697 HDA_OUTPUT)); 2977 HDA_OUTPUT));
1698 if (err < 0) 2978 if (err < 0)
1699 return err; 2979 return err;
@@ -1714,6 +2994,7 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1714 spec->multiout.hp_nid = VT1709_HP_DAC_NID; 2994 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1715 else if (spec->multiout.num_dacs == 3) /* 6 channels */ 2995 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1716 spec->multiout.hp_nid = 0; 2996 spec->multiout.hp_nid = 0;
2997 spec->hp_independent_mode_index = 1;
1717 2998
1718 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2999 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1719 "Headphone Playback Volume", 3000 "Headphone Playback Volume",
@@ -1752,7 +3033,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1752 case 0x1d: /* Mic */ 3033 case 0x1d: /* Mic */
1753 idx = 2; 3034 idx = 2;
1754 break; 3035 break;
1755 3036
1756 case 0x1e: /* Line In */ 3037 case 0x1e: /* Line In */
1757 idx = 3; 3038 idx = 3;
1758 break; 3039 break;
@@ -1765,8 +3046,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1765 idx = 1; 3046 idx = 1;
1766 break; 3047 break;
1767 } 3048 }
1768 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 3049 err = via_new_analog_input(spec, labels[i], idx, 0x18);
1769 idx, 0x18);
1770 if (err < 0) 3050 if (err < 0)
1771 return err; 3051 return err;
1772 imux->items[imux->num_items].label = labels[i]; 3052 imux->items[imux->num_items].label = labels[i];
@@ -1814,8 +3094,9 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1814 spec->input_mux = &spec->private_imux[0]; 3094 spec->input_mux = &spec->private_imux[0];
1815 3095
1816 if (spec->hp_mux) 3096 if (spec->hp_mux)
1817 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3097 via_hp_build(codec);
1818 3098
3099 via_smart51_build(spec);
1819 return 1; 3100 return 1;
1820} 3101}
1821 3102
@@ -1835,12 +3116,10 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1835 int err; 3116 int err;
1836 3117
1837 /* create a codec specific record */ 3118 /* create a codec specific record */
1838 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3119 spec = via_new_spec(codec);
1839 if (spec == NULL) 3120 if (spec == NULL)
1840 return -ENOMEM; 3121 return -ENOMEM;
1841 3122
1842 codec->spec = spec;
1843
1844 err = vt1709_parse_auto_config(codec); 3123 err = vt1709_parse_auto_config(codec);
1845 if (err < 0) { 3124 if (err < 0) {
1846 via_free(codec); 3125 via_free(codec);
@@ -1861,7 +3140,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1861 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3140 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1862 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3141 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1863 3142
1864 3143
1865 if (!spec->adc_nids && spec->input_mux) { 3144 if (!spec->adc_nids && spec->input_mux) {
1866 spec->adc_nids = vt1709_adc_nids; 3145 spec->adc_nids = vt1709_adc_nids;
1867 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3146 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -1929,12 +3208,10 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1929 int err; 3208 int err;
1930 3209
1931 /* create a codec specific record */ 3210 /* create a codec specific record */
1932 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3211 spec = via_new_spec(codec);
1933 if (spec == NULL) 3212 if (spec == NULL)
1934 return -ENOMEM; 3213 return -ENOMEM;
1935 3214
1936 codec->spec = spec;
1937
1938 err = vt1709_parse_auto_config(codec); 3215 err = vt1709_parse_auto_config(codec);
1939 if (err < 0) { 3216 if (err < 0) {
1940 via_free(codec); 3217 via_free(codec);
@@ -1955,7 +3232,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1955 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3232 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1956 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3233 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1957 3234
1958 3235
1959 if (!spec->adc_nids && spec->input_mux) { 3236 if (!spec->adc_nids && spec->input_mux) {
1960 spec->adc_nids = vt1709_adc_nids; 3237 spec->adc_nids = vt1709_adc_nids;
1961 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3238 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -2024,7 +3301,7 @@ static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2024 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 3301 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2025 3302
2026 /* Setup default input to PW4 */ 3303 /* Setup default input to PW4 */
2027 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, 3304 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2028 /* PW9 Output enable */ 3305 /* PW9 Output enable */
2029 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3306 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2030 /* PW10 Input enable */ 3307 /* PW10 Input enable */
@@ -2068,10 +3345,29 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2068}; 3345};
2069 3346
2070static struct hda_verb vt1708B_uniwill_init_verbs[] = { 3347static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2071 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3348 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3349 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3350 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3351 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3352 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3353 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3354 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3355 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3356 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2072 { } 3357 { }
2073}; 3358};
2074 3359
3360static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3361 struct hda_codec *codec,
3362 struct snd_pcm_substream *substream)
3363{
3364 int idle = substream->pstr->substream_opened == 1
3365 && substream->ref_count == 0;
3366
3367 analog_low_current_mode(codec, idle);
3368 return 0;
3369}
3370
2075static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { 3371static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2076 .substreams = 2, 3372 .substreams = 2,
2077 .channels_min = 2, 3373 .channels_min = 2,
@@ -2080,7 +3376,8 @@ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2080 .ops = { 3376 .ops = {
2081 .open = via_playback_pcm_open, 3377 .open = via_playback_pcm_open,
2082 .prepare = via_playback_multi_pcm_prepare, 3378 .prepare = via_playback_multi_pcm_prepare,
2083 .cleanup = via_playback_multi_pcm_cleanup 3379 .cleanup = via_playback_multi_pcm_cleanup,
3380 .close = via_pcm_open_close
2084 }, 3381 },
2085}; 3382};
2086 3383
@@ -2102,8 +3399,10 @@ static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2102 .channels_max = 2, 3399 .channels_max = 2,
2103 .nid = 0x13, /* NID to query formats and rates */ 3400 .nid = 0x13, /* NID to query formats and rates */
2104 .ops = { 3401 .ops = {
3402 .open = via_pcm_open_close,
2105 .prepare = via_capture_pcm_prepare, 3403 .prepare = via_capture_pcm_prepare,
2106 .cleanup = via_capture_pcm_cleanup 3404 .cleanup = via_capture_pcm_cleanup,
3405 .close = via_pcm_open_close
2107 }, 3406 },
2108}; 3407};
2109 3408
@@ -2260,6 +3559,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2260 return 0; 3559 return 0;
2261 3560
2262 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ 3561 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3562 spec->hp_independent_mode_index = 1;
2263 3563
2264 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3564 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2265 "Headphone Playback Volume", 3565 "Headphone Playback Volume",
@@ -2313,8 +3613,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2313 idx = 1; 3613 idx = 1;
2314 break; 3614 break;
2315 } 3615 }
2316 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 3616 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2317 idx, 0x16);
2318 if (err < 0) 3617 if (err < 0)
2319 return err; 3618 return err;
2320 imux->items[imux->num_items].label = labels[i]; 3619 imux->items[imux->num_items].label = labels[i];
@@ -2362,8 +3661,9 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2362 spec->input_mux = &spec->private_imux[0]; 3661 spec->input_mux = &spec->private_imux[0];
2363 3662
2364 if (spec->hp_mux) 3663 if (spec->hp_mux)
2365 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3664 via_hp_build(codec);
2366 3665
3666 via_smart51_build(spec);
2367 return 1; 3667 return 1;
2368} 3668}
2369 3669
@@ -2376,19 +3676,19 @@ static struct hda_amp_list vt1708B_loopbacks[] = {
2376 { } /* end */ 3676 { } /* end */
2377}; 3677};
2378#endif 3678#endif
2379 3679static int patch_vt1708S(struct hda_codec *codec);
2380static int patch_vt1708B_8ch(struct hda_codec *codec) 3680static int patch_vt1708B_8ch(struct hda_codec *codec)
2381{ 3681{
2382 struct via_spec *spec; 3682 struct via_spec *spec;
2383 int err; 3683 int err;
2384 3684
3685 if (get_codec_type(codec) == VT1708BCE)
3686 return patch_vt1708S(codec);
2385 /* create a codec specific record */ 3687 /* create a codec specific record */
2386 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3688 spec = via_new_spec(codec);
2387 if (spec == NULL) 3689 if (spec == NULL)
2388 return -ENOMEM; 3690 return -ENOMEM;
2389 3691
2390 codec->spec = spec;
2391
2392 /* automatic parse from the BIOS config */ 3692 /* automatic parse from the BIOS config */
2393 err = vt1708B_parse_auto_config(codec); 3693 err = vt1708B_parse_auto_config(codec);
2394 if (err < 0) { 3694 if (err < 0) {
@@ -2435,12 +3735,10 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
2435 int err; 3735 int err;
2436 3736
2437 /* create a codec specific record */ 3737 /* create a codec specific record */
2438 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3738 spec = via_new_spec(codec);
2439 if (spec == NULL) 3739 if (spec == NULL)
2440 return -ENOMEM; 3740 return -ENOMEM;
2441 3741
2442 codec->spec = spec;
2443
2444 /* automatic parse from the BIOS config */ 3742 /* automatic parse from the BIOS config */
2445 err = vt1708B_parse_auto_config(codec); 3743 err = vt1708B_parse_auto_config(codec);
2446 if (err < 0) { 3744 if (err < 0) {
@@ -2483,29 +3781,15 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
2483 3781
2484/* Patch for VT1708S */ 3782/* Patch for VT1708S */
2485 3783
2486/* VT1708S software backdoor based override for buggy hardware micboost
2487 * setting */
2488#define MIC_BOOST_VOLUME(xname, nid) { \
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2490 .name = xname, \
2491 .index = 0, \
2492 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2493 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2494 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2495 .info = mic_boost_volume_info, \
2496 .get = snd_hda_mixer_amp_volume_get, \
2497 .put = snd_hda_mixer_amp_volume_put, \
2498 .tlv = { .c = mic_boost_tlv }, \
2499 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2500
2501/* capture mixer elements */ 3784/* capture mixer elements */
2502static struct snd_kcontrol_new vt1708S_capture_mixer[] = { 3785static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2503 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), 3786 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2504 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), 3787 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2505 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), 3788 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2506 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), 3789 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2507 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A), 3790 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
2508 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E), 3791 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3792 HDA_INPUT),
2509 { 3793 {
2510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3794 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2511 /* The multiple "Capture Source" controls confuse alsamixer 3795 /* The multiple "Capture Source" controls confuse alsamixer
@@ -2542,11 +3826,21 @@ static struct hda_verb vt1708S_volume_init_verbs[] = {
2542 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3826 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2543 /* Enable Mic Boost Volume backdoor */ 3827 /* Enable Mic Boost Volume backdoor */
2544 {0x1, 0xf98, 0x1}, 3828 {0x1, 0xf98, 0x1},
3829 /* don't bybass mixer */
3830 {0x1, 0xf88, 0xc0},
2545 { } 3831 { }
2546}; 3832};
2547 3833
2548static struct hda_verb vt1708S_uniwill_init_verbs[] = { 3834static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2549 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3835 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3836 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3837 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3838 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3839 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3840 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3841 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3842 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3843 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2550 { } 3844 { }
2551}; 3845};
2552 3846
@@ -2557,8 +3851,9 @@ static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2557 .nid = 0x10, /* NID to query formats and rates */ 3851 .nid = 0x10, /* NID to query formats and rates */
2558 .ops = { 3852 .ops = {
2559 .open = via_playback_pcm_open, 3853 .open = via_playback_pcm_open,
2560 .prepare = via_playback_pcm_prepare, 3854 .prepare = via_playback_multi_pcm_prepare,
2561 .cleanup = via_playback_pcm_cleanup 3855 .cleanup = via_playback_multi_pcm_cleanup,
3856 .close = via_pcm_open_close
2562 }, 3857 },
2563}; 3858};
2564 3859
@@ -2568,8 +3863,10 @@ static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2568 .channels_max = 2, 3863 .channels_max = 2,
2569 .nid = 0x13, /* NID to query formats and rates */ 3864 .nid = 0x13, /* NID to query formats and rates */
2570 .ops = { 3865 .ops = {
3866 .open = via_pcm_open_close,
2571 .prepare = via_capture_pcm_prepare, 3867 .prepare = via_capture_pcm_prepare,
2572 .cleanup = via_capture_pcm_cleanup 3868 .cleanup = via_capture_pcm_cleanup,
3869 .close = via_pcm_open_close
2573 }, 3870 },
2574}; 3871};
2575 3872
@@ -2726,6 +4023,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2726 return 0; 4023 return 0;
2727 4024
2728 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ 4025 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
4026 spec->hp_independent_mode_index = 1;
2729 4027
2730 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 4028 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2731 "Headphone Playback Volume", 4029 "Headphone Playback Volume",
@@ -2780,8 +4078,7 @@ static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2780 idx = 1; 4078 idx = 1;
2781 break; 4079 break;
2782 } 4080 }
2783 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 4081 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2784 idx, 0x16);
2785 if (err < 0) 4082 if (err < 0)
2786 return err; 4083 return err;
2787 imux->items[imux->num_items].label = labels[i]; 4084 imux->items[imux->num_items].label = labels[i];
@@ -2850,8 +4147,9 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
2850 spec->input_mux = &spec->private_imux[0]; 4147 spec->input_mux = &spec->private_imux[0];
2851 4148
2852 if (spec->hp_mux) 4149 if (spec->hp_mux)
2853 spec->mixers[spec->num_mixers++] = via_hp_mixer; 4150 via_hp_build(codec);
2854 4151
4152 via_smart51_build(spec);
2855 return 1; 4153 return 1;
2856} 4154}
2857 4155
@@ -2865,18 +4163,26 @@ static struct hda_amp_list vt1708S_loopbacks[] = {
2865}; 4163};
2866#endif 4164#endif
2867 4165
4166static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4167 int offset, int num_steps, int step_size)
4168{
4169 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4170 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4171 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4172 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4173 (0 << AC_AMPCAP_MUTE_SHIFT));
4174}
4175
2868static int patch_vt1708S(struct hda_codec *codec) 4176static int patch_vt1708S(struct hda_codec *codec)
2869{ 4177{
2870 struct via_spec *spec; 4178 struct via_spec *spec;
2871 int err; 4179 int err;
2872 4180
2873 /* create a codec specific record */ 4181 /* create a codec specific record */
2874 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4182 spec = via_new_spec(codec);
2875 if (spec == NULL) 4183 if (spec == NULL)
2876 return -ENOMEM; 4184 return -ENOMEM;
2877 4185
2878 codec->spec = spec;
2879
2880 /* automatic parse from the BIOS config */ 4186 /* automatic parse from the BIOS config */
2881 err = vt1708S_parse_auto_config(codec); 4187 err = vt1708S_parse_auto_config(codec);
2882 if (err < 0) { 4188 if (err < 0) {
@@ -2890,17 +4196,25 @@ static int patch_vt1708S(struct hda_codec *codec)
2890 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; 4196 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2891 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; 4197 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2892 4198
2893 spec->stream_name_analog = "VT1708S Analog"; 4199 if (codec->vendor_id == 0x11060440)
4200 spec->stream_name_analog = "VT1818S Analog";
4201 else
4202 spec->stream_name_analog = "VT1708S Analog";
2894 spec->stream_analog_playback = &vt1708S_pcm_analog_playback; 4203 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2895 spec->stream_analog_capture = &vt1708S_pcm_analog_capture; 4204 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2896 4205
2897 spec->stream_name_digital = "VT1708S Digital"; 4206 if (codec->vendor_id == 0x11060440)
4207 spec->stream_name_digital = "VT1818S Digital";
4208 else
4209 spec->stream_name_digital = "VT1708S Digital";
2898 spec->stream_digital_playback = &vt1708S_pcm_digital_playback; 4210 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2899 4211
2900 if (!spec->adc_nids && spec->input_mux) { 4212 if (!spec->adc_nids && spec->input_mux) {
2901 spec->adc_nids = vt1708S_adc_nids; 4213 spec->adc_nids = vt1708S_adc_nids;
2902 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); 4214 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2903 get_mux_nids(codec); 4215 get_mux_nids(codec);
4216 override_mic_boost(codec, 0x1a, 0, 3, 40);
4217 override_mic_boost(codec, 0x1e, 0, 3, 40);
2904 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; 4218 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2905 spec->num_mixers++; 4219 spec->num_mixers++;
2906 } 4220 }
@@ -2913,6 +4227,16 @@ static int patch_vt1708S(struct hda_codec *codec)
2913 spec->loopback.amplist = vt1708S_loopbacks; 4227 spec->loopback.amplist = vt1708S_loopbacks;
2914#endif 4228#endif
2915 4229
4230 /* correct names for VT1708BCE */
4231 if (get_codec_type(codec) == VT1708BCE) {
4232 kfree(codec->chip_name);
4233 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4234 snprintf(codec->bus->card->mixername,
4235 sizeof(codec->bus->card->mixername),
4236 "%s %s", codec->vendor_name, codec->chip_name);
4237 spec->stream_name_analog = "VT1708BCE Analog";
4238 spec->stream_name_digital = "VT1708BCE Digital";
4239 }
2916 return 0; 4240 return 0;
2917} 4241}
2918 4242
@@ -2967,12 +4291,20 @@ static struct hda_verb vt1702_volume_init_verbs[] = {
2967 /* PW6 PW7 Output enable */ 4291 /* PW6 PW7 Output enable */
2968 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4292 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2969 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4293 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4294 /* mixer enable */
4295 {0x1, 0xF88, 0x3},
4296 /* GPIO 0~2 */
4297 {0x1, 0xF82, 0x3F},
2970 { } 4298 { }
2971}; 4299};
2972 4300
2973static struct hda_verb vt1702_uniwill_init_verbs[] = { 4301static struct hda_verb vt1702_uniwill_init_verbs[] = {
2974 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT}, 4302 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
2975 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 4303 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4304 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4305 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4306 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4307 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2976 { } 4308 { }
2977}; 4309};
2978 4310
@@ -2984,7 +4316,8 @@ static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2984 .ops = { 4316 .ops = {
2985 .open = via_playback_pcm_open, 4317 .open = via_playback_pcm_open,
2986 .prepare = via_playback_multi_pcm_prepare, 4318 .prepare = via_playback_multi_pcm_prepare,
2987 .cleanup = via_playback_multi_pcm_cleanup 4319 .cleanup = via_playback_multi_pcm_cleanup,
4320 .close = via_pcm_open_close
2988 }, 4321 },
2989}; 4322};
2990 4323
@@ -2994,8 +4327,10 @@ static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2994 .channels_max = 2, 4327 .channels_max = 2,
2995 .nid = 0x12, /* NID to query formats and rates */ 4328 .nid = 0x12, /* NID to query formats and rates */
2996 .ops = { 4329 .ops = {
4330 .open = via_pcm_open_close,
2997 .prepare = via_capture_pcm_prepare, 4331 .prepare = via_capture_pcm_prepare,
2998 .cleanup = via_capture_pcm_cleanup 4332 .cleanup = via_capture_pcm_cleanup,
4333 .close = via_pcm_open_close
2999 }, 4334 },
3000}; 4335};
3001 4336
@@ -3065,12 +4400,13 @@ static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3065 4400
3066static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) 4401static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3067{ 4402{
3068 int err; 4403 int err, i;
3069 4404 struct hda_input_mux *imux;
4405 static const char *texts[] = { "ON", "OFF", NULL};
3070 if (!pin) 4406 if (!pin)
3071 return 0; 4407 return 0;
3072
3073 spec->multiout.hp_nid = 0x1D; 4408 spec->multiout.hp_nid = 0x1D;
4409 spec->hp_independent_mode_index = 0;
3074 4410
3075 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 4411 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3076 "Headphone Playback Volume", 4412 "Headphone Playback Volume",
@@ -3084,8 +4420,18 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3084 if (err < 0) 4420 if (err < 0)
3085 return err; 4421 return err;
3086 4422
3087 create_hp_imux(spec); 4423 imux = &spec->private_imux[1];
4424
4425 /* for hp mode select */
4426 i = 0;
4427 while (texts[i] != NULL) {
4428 imux->items[imux->num_items].label = texts[i];
4429 imux->items[imux->num_items].index = i;
4430 imux->num_items++;
4431 i++;
4432 }
3088 4433
4434 spec->hp_mux = &spec->private_imux[1];
3089 return 0; 4435 return 0;
3090} 4436}
3091 4437
@@ -3121,8 +4467,7 @@ static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3121 idx = 3; 4467 idx = 3;
3122 break; 4468 break;
3123 } 4469 }
3124 err = via_new_analog_input(spec, cfg->input_pins[i], 4470 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
3125 labels[i], idx, 0x1A);
3126 if (err < 0) 4471 if (err < 0)
3127 return err; 4472 return err;
3128 imux->items[imux->num_items].label = labels[i]; 4473 imux->items[imux->num_items].label = labels[i];
@@ -3152,6 +4497,12 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3152 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); 4497 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3153 if (err < 0) 4498 if (err < 0)
3154 return err; 4499 return err;
4500 /* limit AA path volume to 0 dB */
4501 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4502 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4503 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4504 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4505 (1 << AC_AMPCAP_MUTE_SHIFT));
3155 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); 4506 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3156 if (err < 0) 4507 if (err < 0)
3157 return err; 4508 return err;
@@ -3166,7 +4517,7 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3166 spec->input_mux = &spec->private_imux[0]; 4517 spec->input_mux = &spec->private_imux[0];
3167 4518
3168 if (spec->hp_mux) 4519 if (spec->hp_mux)
3169 spec->mixers[spec->num_mixers++] = via_hp_mixer; 4520 via_hp_build(codec);
3170 4521
3171 return 1; 4522 return 1;
3172} 4523}
@@ -3185,16 +4536,12 @@ static int patch_vt1702(struct hda_codec *codec)
3185{ 4536{
3186 struct via_spec *spec; 4537 struct via_spec *spec;
3187 int err; 4538 int err;
3188 unsigned int response;
3189 unsigned char control;
3190 4539
3191 /* create a codec specific record */ 4540 /* create a codec specific record */
3192 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4541 spec = via_new_spec(codec);
3193 if (spec == NULL) 4542 if (spec == NULL)
3194 return -ENOMEM; 4543 return -ENOMEM;
3195 4544
3196 codec->spec = spec;
3197
3198 /* automatic parse from the BIOS config */ 4545 /* automatic parse from the BIOS config */
3199 err = vt1702_parse_auto_config(codec); 4546 err = vt1702_parse_auto_config(codec);
3200 if (err < 0) { 4547 if (err < 0) {
@@ -3231,17 +4578,1631 @@ static int patch_vt1702(struct hda_codec *codec)
3231 spec->loopback.amplist = vt1702_loopbacks; 4578 spec->loopback.amplist = vt1702_loopbacks;
3232#endif 4579#endif
3233 4580
3234 /* Open backdoor */ 4581 return 0;
3235 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0); 4582}
3236 control = (unsigned char)(response & 0xff); 4583
3237 control |= 0x3; 4584/* Patch for VT1718S */
3238 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control); 4585
4586/* capture mixer elements */
4587static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4588 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4589 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4590 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4591 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4592 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4593 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4594 HDA_INPUT),
4595 {
4596 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4597 /* The multiple "Capture Source" controls confuse alsamixer
4598 * So call somewhat different..
4599 */
4600 .name = "Input Source",
4601 .count = 2,
4602 .info = via_mux_enum_info,
4603 .get = via_mux_enum_get,
4604 .put = via_mux_enum_put,
4605 },
4606 { } /* end */
4607};
4608
4609static struct hda_verb vt1718S_volume_init_verbs[] = {
4610 /*
4611 * Unmute ADC0-1 and set the default input to mic-in
4612 */
4613 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4614 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4615
4616
4617 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4618 * mixer widget
4619 */
4620 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4621 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4622 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4623 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4624 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4625 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4626
4627 /* Setup default input of Front HP to MW9 */
4628 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4629 /* PW9 PW10 Output enable */
4630 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4631 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4632 /* PW11 Input enable */
4633 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4634 /* Enable Boost Volume backdoor */
4635 {0x1, 0xf88, 0x8},
4636 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4637 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4638 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4639 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4640 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4641 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4642 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4643 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4644 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4645 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4646 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4647 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4648 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4649 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4650 /* Unmute MW4's index 0 */
4651 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4652 { }
4653};
4654
4655
4656static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4657 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4658 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4659 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4660 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4661 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4662 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4663 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4664 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4665 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4666 { }
4667};
4668
4669static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4670 .substreams = 2,
4671 .channels_min = 2,
4672 .channels_max = 10,
4673 .nid = 0x8, /* NID to query formats and rates */
4674 .ops = {
4675 .open = via_playback_pcm_open,
4676 .prepare = via_playback_multi_pcm_prepare,
4677 .cleanup = via_playback_multi_pcm_cleanup,
4678 .close = via_pcm_open_close,
4679 },
4680};
4681
4682static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4683 .substreams = 2,
4684 .channels_min = 2,
4685 .channels_max = 2,
4686 .nid = 0x10, /* NID to query formats and rates */
4687 .ops = {
4688 .open = via_pcm_open_close,
4689 .prepare = via_capture_pcm_prepare,
4690 .cleanup = via_capture_pcm_cleanup,
4691 .close = via_pcm_open_close,
4692 },
4693};
4694
4695static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4696 .substreams = 2,
4697 .channels_min = 2,
4698 .channels_max = 2,
4699 /* NID is set in via_build_pcms */
4700 .ops = {
4701 .open = via_dig_playback_pcm_open,
4702 .close = via_dig_playback_pcm_close,
4703 .prepare = via_dig_playback_pcm_prepare,
4704 .cleanup = via_dig_playback_pcm_cleanup
4705 },
4706};
4707
4708static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4709 .substreams = 1,
4710 .channels_min = 2,
4711 .channels_max = 2,
4712};
4713
4714/* fill in the dac_nids table from the parsed pin configuration */
4715static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4716 const struct auto_pin_cfg *cfg)
4717{
4718 int i;
4719 hda_nid_t nid;
4720
4721 spec->multiout.num_dacs = cfg->line_outs;
4722
4723 spec->multiout.dac_nids = spec->private_dac_nids;
4724
4725 for (i = 0; i < 4; i++) {
4726 nid = cfg->line_out_pins[i];
4727 if (nid) {
4728 /* config dac list */
4729 switch (i) {
4730 case AUTO_SEQ_FRONT:
4731 spec->multiout.dac_nids[i] = 0x8;
4732 break;
4733 case AUTO_SEQ_CENLFE:
4734 spec->multiout.dac_nids[i] = 0xa;
4735 break;
4736 case AUTO_SEQ_SURROUND:
4737 spec->multiout.dac_nids[i] = 0x9;
4738 break;
4739 case AUTO_SEQ_SIDE:
4740 spec->multiout.dac_nids[i] = 0xb;
4741 break;
4742 }
4743 }
4744 }
4745
4746 return 0;
4747}
4748
4749/* add playback controls from the parsed DAC table */
4750static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4751 const struct auto_pin_cfg *cfg)
4752{
4753 char name[32];
4754 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4755 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4756 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4757 hda_nid_t nid, nid_vol, nid_mute = 0;
4758 int i, err;
4759
4760 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4761 nid = cfg->line_out_pins[i];
4762
4763 if (!nid)
4764 continue;
4765 nid_vol = nid_vols[i];
4766 nid_mute = nid_mutes[i];
4767
4768 if (i == AUTO_SEQ_CENLFE) {
4769 /* Center/LFE */
4770 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4771 "Center Playback Volume",
4772 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4773 HDA_OUTPUT));
4774 if (err < 0)
4775 return err;
4776 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4777 "LFE Playback Volume",
4778 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4779 HDA_OUTPUT));
4780 if (err < 0)
4781 return err;
4782 err = via_add_control(
4783 spec, VIA_CTL_WIDGET_MUTE,
4784 "Center Playback Switch",
4785 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4786 HDA_OUTPUT));
4787 if (err < 0)
4788 return err;
4789 err = via_add_control(
4790 spec, VIA_CTL_WIDGET_MUTE,
4791 "LFE Playback Switch",
4792 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4793 HDA_OUTPUT));
4794 if (err < 0)
4795 return err;
4796 } else if (i == AUTO_SEQ_FRONT) {
4797 /* Front */
4798 sprintf(name, "%s Playback Volume", chname[i]);
4799 err = via_add_control(
4800 spec, VIA_CTL_WIDGET_VOL, name,
4801 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4802 if (err < 0)
4803 return err;
4804 sprintf(name, "%s Playback Switch", chname[i]);
4805 err = via_add_control(
4806 spec, VIA_CTL_WIDGET_MUTE, name,
4807 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4808 HDA_OUTPUT));
4809 if (err < 0)
4810 return err;
4811 } else {
4812 sprintf(name, "%s Playback Volume", chname[i]);
4813 err = via_add_control(
4814 spec, VIA_CTL_WIDGET_VOL, name,
4815 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4816 if (err < 0)
4817 return err;
4818 sprintf(name, "%s Playback Switch", chname[i]);
4819 err = via_add_control(
4820 spec, VIA_CTL_WIDGET_MUTE, name,
4821 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4822 HDA_OUTPUT));
4823 if (err < 0)
4824 return err;
4825 }
4826 }
4827 return 0;
4828}
4829
4830static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4831{
4832 int err;
4833
4834 if (!pin)
4835 return 0;
4836
4837 spec->multiout.hp_nid = 0xc; /* AOW4 */
4838 spec->hp_independent_mode_index = 1;
4839
4840 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4841 "Headphone Playback Volume",
4842 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4843 if (err < 0)
4844 return err;
4845
4846 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4847 "Headphone Playback Switch",
4848 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4849 if (err < 0)
4850 return err;
4851
4852 create_hp_imux(spec);
4853 return 0;
4854}
4855
4856/* create playback/capture controls for input pins */
4857static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4858 const struct auto_pin_cfg *cfg)
4859{
4860 static char *labels[] = {
4861 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4862 };
4863 struct hda_input_mux *imux = &spec->private_imux[0];
4864 int i, err, idx = 0;
4865
4866 /* for internal loopback recording select */
4867 imux->items[imux->num_items].label = "Stereo Mixer";
4868 imux->items[imux->num_items].index = 5;
4869 imux->num_items++;
4870
4871 for (i = 0; i < AUTO_PIN_LAST; i++) {
4872 if (!cfg->input_pins[i])
4873 continue;
4874
4875 switch (cfg->input_pins[i]) {
4876 case 0x2b: /* Mic */
4877 idx = 1;
4878 break;
4879
4880 case 0x2a: /* Line In */
4881 idx = 2;
4882 break;
4883
4884 case 0x29: /* Front Mic */
4885 idx = 3;
4886 break;
4887
4888 case 0x2c: /* CD */
4889 idx = 0;
4890 break;
4891 }
4892 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4893 if (err < 0)
4894 return err;
4895 imux->items[imux->num_items].label = labels[i];
4896 imux->items[imux->num_items].index = idx;
4897 imux->num_items++;
4898 }
4899 return 0;
4900}
4901
4902static int vt1718S_parse_auto_config(struct hda_codec *codec)
4903{
4904 struct via_spec *spec = codec->spec;
4905 int err;
4906
4907 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4908
4909 if (err < 0)
4910 return err;
4911 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4912 if (err < 0)
4913 return err;
4914 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4915 return 0; /* can't find valid BIOS pin config */
4916
4917 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4918 if (err < 0)
4919 return err;
4920 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4921 if (err < 0)
4922 return err;
4923 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4924 if (err < 0)
4925 return err;
4926
4927 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4928
4929 fill_dig_outs(codec);
4930
4931 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4932 spec->dig_in_nid = 0x13;
4933
4934 if (spec->kctls.list)
4935 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4936
4937 spec->input_mux = &spec->private_imux[0];
4938
4939 if (spec->hp_mux)
4940 via_hp_build(codec);
4941
4942 via_smart51_build(spec);
4943
4944 return 1;
4945}
4946
4947#ifdef CONFIG_SND_HDA_POWER_SAVE
4948static struct hda_amp_list vt1718S_loopbacks[] = {
4949 { 0x21, HDA_INPUT, 1 },
4950 { 0x21, HDA_INPUT, 2 },
4951 { 0x21, HDA_INPUT, 3 },
4952 { 0x21, HDA_INPUT, 4 },
4953 { } /* end */
4954};
4955#endif
4956
4957static int patch_vt1718S(struct hda_codec *codec)
4958{
4959 struct via_spec *spec;
4960 int err;
4961
4962 /* create a codec specific record */
4963 spec = via_new_spec(codec);
4964 if (spec == NULL)
4965 return -ENOMEM;
4966
4967 /* automatic parse from the BIOS config */
4968 err = vt1718S_parse_auto_config(codec);
4969 if (err < 0) {
4970 via_free(codec);
4971 return err;
4972 } else if (!err) {
4973 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4974 "from BIOS. Using genenic mode...\n");
4975 }
4976
4977 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4978 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4979
4980 if (codec->vendor_id == 0x11060441)
4981 spec->stream_name_analog = "VT2020 Analog";
4982 else if (codec->vendor_id == 0x11064441)
4983 spec->stream_name_analog = "VT1828S Analog";
4984 else
4985 spec->stream_name_analog = "VT1718S Analog";
4986 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4987 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4988
4989 if (codec->vendor_id == 0x11060441)
4990 spec->stream_name_digital = "VT2020 Digital";
4991 else if (codec->vendor_id == 0x11064441)
4992 spec->stream_name_digital = "VT1828S Digital";
4993 else
4994 spec->stream_name_digital = "VT1718S Digital";
4995 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4996 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4997 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4998
4999 if (!spec->adc_nids && spec->input_mux) {
5000 spec->adc_nids = vt1718S_adc_nids;
5001 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
5002 get_mux_nids(codec);
5003 override_mic_boost(codec, 0x2b, 0, 3, 40);
5004 override_mic_boost(codec, 0x29, 0, 3, 40);
5005 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
5006 spec->num_mixers++;
5007 }
5008
5009 codec->patch_ops = via_patch_ops;
5010
5011 codec->patch_ops.init = via_auto_init;
5012 codec->patch_ops.unsol_event = via_unsol_event;
5013
5014#ifdef CONFIG_SND_HDA_POWER_SAVE
5015 spec->loopback.amplist = vt1718S_loopbacks;
5016#endif
5017
5018 return 0;
5019}
5020
5021/* Patch for VT1716S */
5022
5023static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
5024 struct snd_ctl_elem_info *uinfo)
5025{
5026 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
5027 uinfo->count = 1;
5028 uinfo->value.integer.min = 0;
5029 uinfo->value.integer.max = 1;
5030 return 0;
5031}
5032
5033static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
5034 struct snd_ctl_elem_value *ucontrol)
5035{
5036 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5037 int index = 0;
5038
5039 index = snd_hda_codec_read(codec, 0x26, 0,
5040 AC_VERB_GET_CONNECT_SEL, 0);
5041 if (index != -1)
5042 *ucontrol->value.integer.value = index;
5043
5044 return 0;
5045}
5046
5047static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
5048 struct snd_ctl_elem_value *ucontrol)
5049{
5050 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5051 struct via_spec *spec = codec->spec;
5052 int index = *ucontrol->value.integer.value;
5053
5054 snd_hda_codec_write(codec, 0x26, 0,
5055 AC_VERB_SET_CONNECT_SEL, index);
5056 spec->dmic_enabled = index;
5057 set_jack_power_state(codec);
5058
5059 return 1;
5060}
5061
5062/* capture mixer elements */
5063static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
5064 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
5065 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
5066 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
5067 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
5068 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
5069 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5070 HDA_INPUT),
5071 {
5072 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5073 .name = "Input Source",
5074 .count = 1,
5075 .info = via_mux_enum_info,
5076 .get = via_mux_enum_get,
5077 .put = via_mux_enum_put,
5078 },
5079 { } /* end */
5080};
5081
5082static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5083 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5084 {
5085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5086 .name = "Digital Mic Capture Switch",
5087 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
5088 .count = 1,
5089 .info = vt1716s_dmic_info,
5090 .get = vt1716s_dmic_get,
5091 .put = vt1716s_dmic_put,
5092 },
5093 {} /* end */
5094};
5095
5096
5097/* mono-out mixer elements */
5098static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5099 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5100 { } /* end */
5101};
5102
5103static struct hda_verb vt1716S_volume_init_verbs[] = {
5104 /*
5105 * Unmute ADC0-1 and set the default input to mic-in
5106 */
5107 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5108 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5109
5110
5111 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5112 * mixer widget
5113 */
5114 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5115 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5116 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5117 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5118 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5119 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5120
5121 /* MUX Indices: Stereo Mixer = 5 */
5122 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5123
5124 /* Setup default input of PW4 to MW0 */
5125 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5126
5127 /* Setup default input of SW1 as MW0 */
5128 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5129
5130 /* Setup default input of SW4 as AOW0 */
5131 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5132
5133 /* PW9 PW10 Output enable */
5134 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5135 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5136
5137 /* Unmute SW1, PW12 */
5138 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5139 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5140 /* PW12 Output enable */
5141 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5142 /* Enable Boost Volume backdoor */
5143 {0x1, 0xf8a, 0x80},
5144 /* don't bybass mixer */
5145 {0x1, 0xf88, 0xc0},
5146 /* Enable mono output */
5147 {0x1, 0xf90, 0x08},
5148 { }
5149};
5150
5151
5152static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5153 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5154 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5155 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5156 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5157 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5158 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5159 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5160 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5161 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5162 { }
5163};
5164
5165static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5166 .substreams = 2,
5167 .channels_min = 2,
5168 .channels_max = 6,
5169 .nid = 0x10, /* NID to query formats and rates */
5170 .ops = {
5171 .open = via_playback_pcm_open,
5172 .prepare = via_playback_multi_pcm_prepare,
5173 .cleanup = via_playback_multi_pcm_cleanup,
5174 .close = via_pcm_open_close,
5175 },
5176};
5177
5178static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5179 .substreams = 2,
5180 .channels_min = 2,
5181 .channels_max = 2,
5182 .nid = 0x13, /* NID to query formats and rates */
5183 .ops = {
5184 .open = via_pcm_open_close,
5185 .prepare = via_capture_pcm_prepare,
5186 .cleanup = via_capture_pcm_cleanup,
5187 .close = via_pcm_open_close,
5188 },
5189};
5190
5191static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5192 .substreams = 2,
5193 .channels_min = 2,
5194 .channels_max = 2,
5195 /* NID is set in via_build_pcms */
5196 .ops = {
5197 .open = via_dig_playback_pcm_open,
5198 .close = via_dig_playback_pcm_close,
5199 .prepare = via_dig_playback_pcm_prepare,
5200 .cleanup = via_dig_playback_pcm_cleanup
5201 },
5202};
5203
5204/* fill in the dac_nids table from the parsed pin configuration */
5205static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5206 const struct auto_pin_cfg *cfg)
5207{ int i;
5208 hda_nid_t nid;
5209
5210 spec->multiout.num_dacs = cfg->line_outs;
5211
5212 spec->multiout.dac_nids = spec->private_dac_nids;
5213
5214 for (i = 0; i < 3; i++) {
5215 nid = cfg->line_out_pins[i];
5216 if (nid) {
5217 /* config dac list */
5218 switch (i) {
5219 case AUTO_SEQ_FRONT:
5220 spec->multiout.dac_nids[i] = 0x10;
5221 break;
5222 case AUTO_SEQ_CENLFE:
5223 spec->multiout.dac_nids[i] = 0x25;
5224 break;
5225 case AUTO_SEQ_SURROUND:
5226 spec->multiout.dac_nids[i] = 0x11;
5227 break;
5228 }
5229 }
5230 }
5231
5232 return 0;
5233}
5234
5235/* add playback controls from the parsed DAC table */
5236static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5237 const struct auto_pin_cfg *cfg)
5238{
5239 char name[32];
5240 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5241 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5242 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5243 hda_nid_t nid, nid_vol, nid_mute;
5244 int i, err;
5245
5246 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5247 nid = cfg->line_out_pins[i];
5248
5249 if (!nid)
5250 continue;
5251
5252 nid_vol = nid_vols[i];
5253 nid_mute = nid_mutes[i];
5254
5255 if (i == AUTO_SEQ_CENLFE) {
5256 err = via_add_control(
5257 spec, VIA_CTL_WIDGET_VOL,
5258 "Center Playback Volume",
5259 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5260 if (err < 0)
5261 return err;
5262 err = via_add_control(
5263 spec, VIA_CTL_WIDGET_VOL,
5264 "LFE Playback Volume",
5265 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5266 if (err < 0)
5267 return err;
5268 err = via_add_control(
5269 spec, VIA_CTL_WIDGET_MUTE,
5270 "Center Playback Switch",
5271 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5272 HDA_OUTPUT));
5273 if (err < 0)
5274 return err;
5275 err = via_add_control(
5276 spec, VIA_CTL_WIDGET_MUTE,
5277 "LFE Playback Switch",
5278 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5279 HDA_OUTPUT));
5280 if (err < 0)
5281 return err;
5282 } else if (i == AUTO_SEQ_FRONT) {
5283
5284 err = via_add_control(
5285 spec, VIA_CTL_WIDGET_VOL,
5286 "Master Front Playback Volume",
5287 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5288 if (err < 0)
5289 return err;
5290 err = via_add_control(
5291 spec, VIA_CTL_WIDGET_MUTE,
5292 "Master Front Playback Switch",
5293 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5294 if (err < 0)
5295 return err;
5296
5297 sprintf(name, "%s Playback Volume", chname[i]);
5298 err = via_add_control(
5299 spec, VIA_CTL_WIDGET_VOL, name,
5300 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5301 if (err < 0)
5302 return err;
5303 sprintf(name, "%s Playback Switch", chname[i]);
5304 err = via_add_control(
5305 spec, VIA_CTL_WIDGET_MUTE, name,
5306 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5307 HDA_OUTPUT));
5308 if (err < 0)
5309 return err;
5310 } else {
5311 sprintf(name, "%s Playback Volume", chname[i]);
5312 err = via_add_control(
5313 spec, VIA_CTL_WIDGET_VOL, name,
5314 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5315 if (err < 0)
5316 return err;
5317 sprintf(name, "%s Playback Switch", chname[i]);
5318 err = via_add_control(
5319 spec, VIA_CTL_WIDGET_MUTE, name,
5320 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5321 HDA_OUTPUT));
5322 if (err < 0)
5323 return err;
5324 }
5325 }
5326 return 0;
5327}
5328
5329static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5330{
5331 int err;
5332
5333 if (!pin)
5334 return 0;
5335
5336 spec->multiout.hp_nid = 0x25; /* AOW3 */
5337 spec->hp_independent_mode_index = 1;
5338
5339 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5340 "Headphone Playback Volume",
5341 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5342 if (err < 0)
5343 return err;
5344
5345 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5346 "Headphone Playback Switch",
5347 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5348 if (err < 0)
5349 return err;
5350
5351 create_hp_imux(spec);
5352 return 0;
5353}
5354
5355/* create playback/capture controls for input pins */
5356static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5357 const struct auto_pin_cfg *cfg)
5358{
5359 static char *labels[] = {
5360 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5361 };
5362 struct hda_input_mux *imux = &spec->private_imux[0];
5363 int i, err, idx = 0;
5364
5365 /* for internal loopback recording select */
5366 imux->items[imux->num_items].label = "Stereo Mixer";
5367 imux->items[imux->num_items].index = 5;
5368 imux->num_items++;
5369
5370 for (i = 0; i < AUTO_PIN_LAST; i++) {
5371 if (!cfg->input_pins[i])
5372 continue;
5373
5374 switch (cfg->input_pins[i]) {
5375 case 0x1a: /* Mic */
5376 idx = 2;
5377 break;
5378
5379 case 0x1b: /* Line In */
5380 idx = 3;
5381 break;
5382
5383 case 0x1e: /* Front Mic */
5384 idx = 4;
5385 break;
5386
5387 case 0x1f: /* CD */
5388 idx = 1;
5389 break;
5390 }
5391 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5392 if (err < 0)
5393 return err;
5394 imux->items[imux->num_items].label = labels[i];
5395 imux->items[imux->num_items].index = idx-1;
5396 imux->num_items++;
5397 }
5398 return 0;
5399}
5400
5401static int vt1716S_parse_auto_config(struct hda_codec *codec)
5402{
5403 struct via_spec *spec = codec->spec;
5404 int err;
5405
5406 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5407 if (err < 0)
5408 return err;
5409 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5410 if (err < 0)
5411 return err;
5412 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5413 return 0; /* can't find valid BIOS pin config */
5414
5415 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5416 if (err < 0)
5417 return err;
5418 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5419 if (err < 0)
5420 return err;
5421 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5422 if (err < 0)
5423 return err;
5424
5425 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5426
5427 fill_dig_outs(codec);
5428
5429 if (spec->kctls.list)
5430 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5431
5432 spec->input_mux = &spec->private_imux[0];
5433
5434 if (spec->hp_mux)
5435 via_hp_build(codec);
5436
5437 via_smart51_build(spec);
5438
5439 return 1;
5440}
5441
5442#ifdef CONFIG_SND_HDA_POWER_SAVE
5443static struct hda_amp_list vt1716S_loopbacks[] = {
5444 { 0x16, HDA_INPUT, 1 },
5445 { 0x16, HDA_INPUT, 2 },
5446 { 0x16, HDA_INPUT, 3 },
5447 { 0x16, HDA_INPUT, 4 },
5448 { } /* end */
5449};
5450#endif
5451
5452static int patch_vt1716S(struct hda_codec *codec)
5453{
5454 struct via_spec *spec;
5455 int err;
5456
5457 /* create a codec specific record */
5458 spec = via_new_spec(codec);
5459 if (spec == NULL)
5460 return -ENOMEM;
5461
5462 /* automatic parse from the BIOS config */
5463 err = vt1716S_parse_auto_config(codec);
5464 if (err < 0) {
5465 via_free(codec);
5466 return err;
5467 } else if (!err) {
5468 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5469 "from BIOS. Using genenic mode...\n");
5470 }
5471
5472 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5473 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5474
5475 spec->stream_name_analog = "VT1716S Analog";
5476 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5477 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5478
5479 spec->stream_name_digital = "VT1716S Digital";
5480 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5481
5482 if (!spec->adc_nids && spec->input_mux) {
5483 spec->adc_nids = vt1716S_adc_nids;
5484 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5485 get_mux_nids(codec);
5486 override_mic_boost(codec, 0x1a, 0, 3, 40);
5487 override_mic_boost(codec, 0x1e, 0, 3, 40);
5488 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5489 spec->num_mixers++;
5490 }
5491
5492 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5493 spec->num_mixers++;
5494
5495 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5496
5497 codec->patch_ops = via_patch_ops;
5498
5499 codec->patch_ops.init = via_auto_init;
5500 codec->patch_ops.unsol_event = via_unsol_event;
5501
5502#ifdef CONFIG_SND_HDA_POWER_SAVE
5503 spec->loopback.amplist = vt1716S_loopbacks;
5504#endif
5505
5506 return 0;
5507}
5508
5509/* for vt2002P */
5510
5511/* capture mixer elements */
5512static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5513 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5514 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5515 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5516 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5517 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5518 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5519 HDA_INPUT),
5520 {
5521 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5522 /* The multiple "Capture Source" controls confuse alsamixer
5523 * So call somewhat different..
5524 */
5525 /* .name = "Capture Source", */
5526 .name = "Input Source",
5527 .count = 2,
5528 .info = via_mux_enum_info,
5529 .get = via_mux_enum_get,
5530 .put = via_mux_enum_put,
5531 },
5532 { } /* end */
5533};
5534
5535static struct hda_verb vt2002P_volume_init_verbs[] = {
5536 /*
5537 * Unmute ADC0-1 and set the default input to mic-in
5538 */
5539 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5540 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5541
5542
5543 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5544 * mixer widget
5545 */
5546 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5547 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5548 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5549 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5550 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5552
5553 /* MUX Indices: Mic = 0 */
5554 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5555 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5556
5557 /* PW9 Output enable */
5558 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5559
5560 /* Enable Boost Volume backdoor */
5561 {0x1, 0xfb9, 0x24},
5562
5563 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5564 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5565 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5566 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5567 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5568 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5569 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5570 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5571 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5572
5573 /* set MUX0/1/4/8 = 0 (AOW0) */
5574 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5575 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5576 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5577 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5578
5579 /* set PW0 index=0 (MW0) */
5580 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5581
5582 /* Enable AOW0 to MW9 */
5583 {0x1, 0xfb8, 0x88},
5584 { }
5585};
5586
5587
5588static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5589 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5590 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5591 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5592 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5593 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5594 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5595 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5596 { }
5597};
5598
5599static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5600 .substreams = 2,
5601 .channels_min = 2,
5602 .channels_max = 2,
5603 .nid = 0x8, /* NID to query formats and rates */
5604 .ops = {
5605 .open = via_playback_pcm_open,
5606 .prepare = via_playback_multi_pcm_prepare,
5607 .cleanup = via_playback_multi_pcm_cleanup,
5608 .close = via_pcm_open_close,
5609 },
5610};
5611
5612static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5613 .substreams = 2,
5614 .channels_min = 2,
5615 .channels_max = 2,
5616 .nid = 0x10, /* NID to query formats and rates */
5617 .ops = {
5618 .open = via_pcm_open_close,
5619 .prepare = via_capture_pcm_prepare,
5620 .cleanup = via_capture_pcm_cleanup,
5621 .close = via_pcm_open_close,
5622 },
5623};
5624
5625static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5626 .substreams = 1,
5627 .channels_min = 2,
5628 .channels_max = 2,
5629 /* NID is set in via_build_pcms */
5630 .ops = {
5631 .open = via_dig_playback_pcm_open,
5632 .close = via_dig_playback_pcm_close,
5633 .prepare = via_dig_playback_pcm_prepare,
5634 .cleanup = via_dig_playback_pcm_cleanup
5635 },
5636};
5637
5638/* fill in the dac_nids table from the parsed pin configuration */
5639static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5640 const struct auto_pin_cfg *cfg)
5641{
5642 spec->multiout.num_dacs = 1;
5643 spec->multiout.dac_nids = spec->private_dac_nids;
5644 if (cfg->line_out_pins[0])
5645 spec->multiout.dac_nids[0] = 0x8;
5646 return 0;
5647}
5648
5649/* add playback controls from the parsed DAC table */
5650static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5651 const struct auto_pin_cfg *cfg)
5652{
5653 int err;
5654
5655 if (!cfg->line_out_pins[0])
5656 return -1;
5657
5658
5659 /* Line-Out: PortE */
5660 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5661 "Master Front Playback Volume",
5662 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5663 if (err < 0)
5664 return err;
5665 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5666 "Master Front Playback Switch",
5667 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5668 if (err < 0)
5669 return err;
5670
5671 return 0;
5672}
5673
5674static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5675{
5676 int err;
5677
5678 if (!pin)
5679 return 0;
5680
5681 spec->multiout.hp_nid = 0x9;
5682 spec->hp_independent_mode_index = 1;
5683
5684 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5685 "Headphone Playback Volume",
5686 HDA_COMPOSE_AMP_VAL(
5687 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5688 if (err < 0)
5689 return err;
5690
5691 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5692 "Headphone Playback Switch",
5693 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5694 if (err < 0)
5695 return err;
5696
5697 create_hp_imux(spec);
5698 return 0;
5699}
5700
5701/* create playback/capture controls for input pins */
5702static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5703 const struct auto_pin_cfg *cfg)
5704{
5705 static char *labels[] = {
5706 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5707 };
5708 struct hda_input_mux *imux = &spec->private_imux[0];
5709 int i, err, idx = 0;
5710
5711 for (i = 0; i < AUTO_PIN_LAST; i++) {
5712 if (!cfg->input_pins[i])
5713 continue;
5714
5715 switch (cfg->input_pins[i]) {
5716 case 0x2b: /* Mic */
5717 idx = 0;
5718 break;
5719
5720 case 0x2a: /* Line In */
5721 idx = 1;
5722 break;
5723
5724 case 0x29: /* Front Mic */
5725 idx = 2;
5726 break;
5727 }
5728 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5729 if (err < 0)
5730 return err;
5731 imux->items[imux->num_items].label = labels[i];
5732 imux->items[imux->num_items].index = idx;
5733 imux->num_items++;
5734 }
5735
5736 /* build volume/mute control of loopback */
5737 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5738 if (err < 0)
5739 return err;
5740
5741 /* for internal loopback recording select */
5742 imux->items[imux->num_items].label = "Stereo Mixer";
5743 imux->items[imux->num_items].index = 3;
5744 imux->num_items++;
5745
5746 /* for digital mic select */
5747 imux->items[imux->num_items].label = "Digital Mic";
5748 imux->items[imux->num_items].index = 4;
5749 imux->num_items++;
5750
5751 return 0;
5752}
5753
5754static int vt2002P_parse_auto_config(struct hda_codec *codec)
5755{
5756 struct via_spec *spec = codec->spec;
5757 int err;
5758
5759
5760 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5761 if (err < 0)
5762 return err;
5763
5764 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5765 if (err < 0)
5766 return err;
5767
5768 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5769 return 0; /* can't find valid BIOS pin config */
5770
5771 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5772 if (err < 0)
5773 return err;
5774 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5775 if (err < 0)
5776 return err;
5777 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5778 if (err < 0)
5779 return err;
5780
5781 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5782
5783 fill_dig_outs(codec);
5784
5785 if (spec->kctls.list)
5786 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5787
5788 spec->input_mux = &spec->private_imux[0];
5789
5790 if (spec->hp_mux)
5791 via_hp_build(codec);
5792
5793 return 1;
5794}
5795
5796#ifdef CONFIG_SND_HDA_POWER_SAVE
5797static struct hda_amp_list vt2002P_loopbacks[] = {
5798 { 0x21, HDA_INPUT, 0 },
5799 { 0x21, HDA_INPUT, 1 },
5800 { 0x21, HDA_INPUT, 2 },
5801 { } /* end */
5802};
5803#endif
5804
5805
5806/* patch for vt2002P */
5807static int patch_vt2002P(struct hda_codec *codec)
5808{
5809 struct via_spec *spec;
5810 int err;
5811
5812 /* create a codec specific record */
5813 spec = via_new_spec(codec);
5814 if (spec == NULL)
5815 return -ENOMEM;
5816
5817 /* automatic parse from the BIOS config */
5818 err = vt2002P_parse_auto_config(codec);
5819 if (err < 0) {
5820 via_free(codec);
5821 return err;
5822 } else if (!err) {
5823 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5824 "from BIOS. Using genenic mode...\n");
5825 }
5826
5827 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5828 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5829
5830 spec->stream_name_analog = "VT2002P Analog";
5831 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5832 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5833
5834 spec->stream_name_digital = "VT2002P Digital";
5835 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5836
5837 if (!spec->adc_nids && spec->input_mux) {
5838 spec->adc_nids = vt2002P_adc_nids;
5839 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5840 get_mux_nids(codec);
5841 override_mic_boost(codec, 0x2b, 0, 3, 40);
5842 override_mic_boost(codec, 0x29, 0, 3, 40);
5843 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5844 spec->num_mixers++;
5845 }
5846
5847 codec->patch_ops = via_patch_ops;
5848
5849 codec->patch_ops.init = via_auto_init;
5850 codec->patch_ops.unsol_event = via_unsol_event;
5851
5852#ifdef CONFIG_SND_HDA_POWER_SAVE
5853 spec->loopback.amplist = vt2002P_loopbacks;
5854#endif
5855
5856 return 0;
5857}
5858
5859/* for vt1812 */
5860
5861/* capture mixer elements */
5862static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5863 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5864 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5865 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5866 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5867 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5868 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5869 HDA_INPUT),
5870 {
5871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5872 /* The multiple "Capture Source" controls confuse alsamixer
5873 * So call somewhat different..
5874 */
5875 .name = "Input Source",
5876 .count = 2,
5877 .info = via_mux_enum_info,
5878 .get = via_mux_enum_get,
5879 .put = via_mux_enum_put,
5880 },
5881 { } /* end */
5882};
5883
5884static struct hda_verb vt1812_volume_init_verbs[] = {
5885 /*
5886 * Unmute ADC0-1 and set the default input to mic-in
5887 */
5888 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5889 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5890
5891
5892 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5893 * mixer widget
5894 */
5895 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5896 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5897 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5898 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5899 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5900 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5901
5902 /* MUX Indices: Mic = 0 */
5903 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5904 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5905
5906 /* PW9 Output enable */
5907 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5908
5909 /* Enable Boost Volume backdoor */
5910 {0x1, 0xfb9, 0x24},
5911
5912 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5915 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5916 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5917 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5918 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5919 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5920 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5921 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5922 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5923
5924 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5925 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5926 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5927 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5928 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5929 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5930
5931 /* Enable AOW0 to MW9 */
5932 {0x1, 0xfb8, 0xa8},
5933 { }
5934};
5935
5936
5937static struct hda_verb vt1812_uniwill_init_verbs[] = {
5938 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5939 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5940 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5941 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5942 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5943 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5944 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5945 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5946 { }
5947};
5948
5949static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5950 .substreams = 2,
5951 .channels_min = 2,
5952 .channels_max = 2,
5953 .nid = 0x8, /* NID to query formats and rates */
5954 .ops = {
5955 .open = via_playback_pcm_open,
5956 .prepare = via_playback_multi_pcm_prepare,
5957 .cleanup = via_playback_multi_pcm_cleanup,
5958 .close = via_pcm_open_close,
5959 },
5960};
5961
5962static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5963 .substreams = 2,
5964 .channels_min = 2,
5965 .channels_max = 2,
5966 .nid = 0x10, /* NID to query formats and rates */
5967 .ops = {
5968 .open = via_pcm_open_close,
5969 .prepare = via_capture_pcm_prepare,
5970 .cleanup = via_capture_pcm_cleanup,
5971 .close = via_pcm_open_close,
5972 },
5973};
5974
5975static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5976 .substreams = 1,
5977 .channels_min = 2,
5978 .channels_max = 2,
5979 /* NID is set in via_build_pcms */
5980 .ops = {
5981 .open = via_dig_playback_pcm_open,
5982 .close = via_dig_playback_pcm_close,
5983 .prepare = via_dig_playback_pcm_prepare,
5984 .cleanup = via_dig_playback_pcm_cleanup
5985 },
5986};
5987/* fill in the dac_nids table from the parsed pin configuration */
5988static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5989 const struct auto_pin_cfg *cfg)
5990{
5991 spec->multiout.num_dacs = 1;
5992 spec->multiout.dac_nids = spec->private_dac_nids;
5993 if (cfg->line_out_pins[0])
5994 spec->multiout.dac_nids[0] = 0x8;
5995 return 0;
5996}
5997
5998
5999/* add playback controls from the parsed DAC table */
6000static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
6001 const struct auto_pin_cfg *cfg)
6002{
6003 int err;
6004
6005 if (!cfg->line_out_pins[0])
6006 return -1;
6007
6008 /* Line-Out: PortE */
6009 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6010 "Front Playback Volume",
6011 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
6012 if (err < 0)
6013 return err;
6014 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
6015 "Front Playback Switch",
6016 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
6017 if (err < 0)
6018 return err;
6019
6020 return 0;
6021}
6022
6023static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
6024{
6025 int err;
6026
6027 if (!pin)
6028 return 0;
6029
6030 spec->multiout.hp_nid = 0x9;
6031 spec->hp_independent_mode_index = 1;
6032
6033
6034 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6035 "Headphone Playback Volume",
6036 HDA_COMPOSE_AMP_VAL(
6037 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
6038 if (err < 0)
6039 return err;
6040
6041 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
6042 "Headphone Playback Switch",
6043 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
6044 if (err < 0)
6045 return err;
6046
6047 create_hp_imux(spec);
6048 return 0;
6049}
6050
6051/* create playback/capture controls for input pins */
6052static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
6053 const struct auto_pin_cfg *cfg)
6054{
6055 static char *labels[] = {
6056 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6057 };
6058 struct hda_input_mux *imux = &spec->private_imux[0];
6059 int i, err, idx = 0;
6060
6061 for (i = 0; i < AUTO_PIN_LAST; i++) {
6062 if (!cfg->input_pins[i])
6063 continue;
6064
6065 switch (cfg->input_pins[i]) {
6066 case 0x2b: /* Mic */
6067 idx = 0;
6068 break;
6069
6070 case 0x2a: /* Line In */
6071 idx = 1;
6072 break;
6073
6074 case 0x29: /* Front Mic */
6075 idx = 2;
6076 break;
6077 }
6078 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6079 if (err < 0)
6080 return err;
6081 imux->items[imux->num_items].label = labels[i];
6082 imux->items[imux->num_items].index = idx;
6083 imux->num_items++;
6084 }
6085 /* build volume/mute control of loopback */
6086 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6087 if (err < 0)
6088 return err;
6089
6090 /* for internal loopback recording select */
6091 imux->items[imux->num_items].label = "Stereo Mixer";
6092 imux->items[imux->num_items].index = 5;
6093 imux->num_items++;
6094
6095 /* for digital mic select */
6096 imux->items[imux->num_items].label = "Digital Mic";
6097 imux->items[imux->num_items].index = 6;
6098 imux->num_items++;
6099
6100 return 0;
6101}
6102
6103static int vt1812_parse_auto_config(struct hda_codec *codec)
6104{
6105 struct via_spec *spec = codec->spec;
6106 int err;
6107
6108
6109 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6110 if (err < 0)
6111 return err;
6112 fill_dig_outs(codec);
6113 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6114 if (err < 0)
6115 return err;
6116
6117 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6118 return 0; /* can't find valid BIOS pin config */
6119
6120 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6121 if (err < 0)
6122 return err;
6123 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6124 if (err < 0)
6125 return err;
6126 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6127 if (err < 0)
6128 return err;
6129
6130 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6131
6132 fill_dig_outs(codec);
6133
6134 if (spec->kctls.list)
6135 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6136
6137 spec->input_mux = &spec->private_imux[0];
6138
6139 if (spec->hp_mux)
6140 via_hp_build(codec);
6141
6142 return 1;
6143}
6144
6145#ifdef CONFIG_SND_HDA_POWER_SAVE
6146static struct hda_amp_list vt1812_loopbacks[] = {
6147 { 0x21, HDA_INPUT, 0 },
6148 { 0x21, HDA_INPUT, 1 },
6149 { 0x21, HDA_INPUT, 2 },
6150 { } /* end */
6151};
6152#endif
6153
6154
6155/* patch for vt1812 */
6156static int patch_vt1812(struct hda_codec *codec)
6157{
6158 struct via_spec *spec;
6159 int err;
6160
6161 /* create a codec specific record */
6162 spec = via_new_spec(codec);
6163 if (spec == NULL)
6164 return -ENOMEM;
6165
6166 /* automatic parse from the BIOS config */
6167 err = vt1812_parse_auto_config(codec);
6168 if (err < 0) {
6169 via_free(codec);
6170 return err;
6171 } else if (!err) {
6172 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6173 "from BIOS. Using genenic mode...\n");
6174 }
6175
6176
6177 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6178 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6179
6180 spec->stream_name_analog = "VT1812 Analog";
6181 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6182 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
3239 6183
3240 /* Enable GPIO 0&1 for volume&mute control */ 6184 spec->stream_name_digital = "VT1812 Digital";
3241 /* Enable GPIO 2 for DMIC-DATA */ 6185 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
3242 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0); 6186
3243 control = (unsigned char)((response >> 16) & 0x3f); 6187
3244 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control); 6188 if (!spec->adc_nids && spec->input_mux) {
6189 spec->adc_nids = vt1812_adc_nids;
6190 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6191 get_mux_nids(codec);
6192 override_mic_boost(codec, 0x2b, 0, 3, 40);
6193 override_mic_boost(codec, 0x29, 0, 3, 40);
6194 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6195 spec->num_mixers++;
6196 }
6197
6198 codec->patch_ops = via_patch_ops;
6199
6200 codec->patch_ops.init = via_auto_init;
6201 codec->patch_ops.unsol_event = via_unsol_event;
6202
6203#ifdef CONFIG_SND_HDA_POWER_SAVE
6204 spec->loopback.amplist = vt1812_loopbacks;
6205#endif
3245 6206
3246 return 0; 6207 return 0;
3247} 6208}
@@ -3318,6 +6279,23 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
3318 .patch = patch_vt1702}, 6279 .patch = patch_vt1702},
3319 { .id = 0x11067398, .name = "VT1702", 6280 { .id = 0x11067398, .name = "VT1702",
3320 .patch = patch_vt1702}, 6281 .patch = patch_vt1702},
6282 { .id = 0x11060428, .name = "VT1718S",
6283 .patch = patch_vt1718S},
6284 { .id = 0x11064428, .name = "VT1718S",
6285 .patch = patch_vt1718S},
6286 { .id = 0x11060441, .name = "VT2020",
6287 .patch = patch_vt1718S},
6288 { .id = 0x11064441, .name = "VT1828S",
6289 .patch = patch_vt1718S},
6290 { .id = 0x11060433, .name = "VT1716S",
6291 .patch = patch_vt1716S},
6292 { .id = 0x1106a721, .name = "VT1716S",
6293 .patch = patch_vt1716S},
6294 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6295 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6296 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6297 { .id = 0x11060440, .name = "VT1818S",
6298 .patch = patch_vt1708S},
3321 {} /* terminator */ 6299 {} /* terminator */
3322}; 6300};
3323 6301
diff --git a/sound/pci/ice1712/Makefile b/sound/pci/ice1712/Makefile
index 536eae2ccf94..f7ce33f00ea5 100644
--- a/sound/pci/ice1712/Makefile
+++ b/sound/pci/ice1712/Makefile
@@ -5,7 +5,7 @@
5 5
6snd-ice17xx-ak4xxx-objs := ak4xxx.o 6snd-ice17xx-ak4xxx-objs := ak4xxx.o
7snd-ice1712-objs := ice1712.o delta.o hoontech.o ews.o 7snd-ice1712-objs := ice1712.o delta.o hoontech.o ews.o
8snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o prodigy_hifi.o juli.o phase.o wtm.o se.o maya44.o 8snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o prodigy_hifi.o juli.o phase.o wtm.o se.o maya44.o quartet.o
9 9
10# Toplevel Module Dependency 10# Toplevel Module Dependency
11obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o snd-ice17xx-ak4xxx.o 11obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o snd-ice17xx-ak4xxx.o
diff --git a/sound/pci/ice1712/ak4xxx.c b/sound/pci/ice1712/ak4xxx.c
index 03391da8c8c7..90d560c3df13 100644
--- a/sound/pci/ice1712/ak4xxx.c
+++ b/sound/pci/ice1712/ak4xxx.c
@@ -24,6 +24,7 @@
24#include <asm/io.h> 24#include <asm/io.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/slab.h>
27#include <linux/init.h> 28#include <linux/init.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/initval.h> 30#include <sound/initval.h>
diff --git a/sound/pci/ice1712/amp.c b/sound/pci/ice1712/amp.c
index 6da21a2bcade..e328cfb7620c 100644
--- a/sound/pci/ice1712/amp.c
+++ b/sound/pci/ice1712/amp.c
@@ -25,7 +25,6 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/slab.h>
29#include <sound/core.h> 28#include <sound/core.h>
30 29
31#include "ice1712.h" 30#include "ice1712.h"
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 110d16e52733..9e66f6d306f8 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -689,42 +689,27 @@ static int aureon_ac97_mmute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
689 return change; 689 return change;
690} 690}
691 691
692static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1); 692static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -10000, 100, 1);
693static const DECLARE_TLV_DB_SCALE(db_scale_wm_pcm, -6400, 50, 1); 693static const DECLARE_TLV_DB_SCALE(db_scale_wm_pcm, -6400, 50, 1);
694static const DECLARE_TLV_DB_SCALE(db_scale_wm_adc, -1200, 100, 0); 694static const DECLARE_TLV_DB_SCALE(db_scale_wm_adc, -1200, 100, 0);
695static const DECLARE_TLV_DB_SCALE(db_scale_ac97_master, -4650, 150, 0); 695static const DECLARE_TLV_DB_SCALE(db_scale_ac97_master, -4650, 150, 0);
696static const DECLARE_TLV_DB_SCALE(db_scale_ac97_gain, -3450, 150, 0); 696static const DECLARE_TLV_DB_SCALE(db_scale_ac97_gain, -3450, 150, 0);
697 697
698/* 698#define WM_VOL_MAX 100
699 * Logarithmic volume values for WM8770 699#define WM_VOL_CNT 101 /* 0dB .. -100dB */
700 * Computed as 20 * Log10(255 / x)
701 */
702static const unsigned char wm_vol[256] = {
703 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
704 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
705 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
706 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
707 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
708 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,
709 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,
710 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,
711 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,
712 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,
713 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,
714 0, 0
715};
716
717#define WM_VOL_MAX (sizeof(wm_vol) - 1)
718#define WM_VOL_MUTE 0x8000 700#define WM_VOL_MUTE 0x8000
719 701
720static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master) 702static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
721{ 703{
722 unsigned char nvol; 704 unsigned char nvol;
723 705
724 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE)) 706 if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE)) {
725 nvol = 0; 707 nvol = 0;
726 else 708 } else {
727 nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX]; 709 nvol = ((vol % WM_VOL_CNT) * (master % WM_VOL_CNT)) /
710 WM_VOL_MAX;
711 nvol += 0x1b;
712 }
728 713
729 wm_put(ice, index, nvol); 714 wm_put(ice, index, nvol);
730 wm_put_nocache(ice, index, 0x180 | nvol); 715 wm_put_nocache(ice, index, 0x180 | nvol);
@@ -795,7 +780,7 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
795 for (ch = 0; ch < 2; ch++) { 780 for (ch = 0; ch < 2; ch++) {
796 unsigned int vol = ucontrol->value.integer.value[ch]; 781 unsigned int vol = ucontrol->value.integer.value[ch];
797 if (vol > WM_VOL_MAX) 782 if (vol > WM_VOL_MAX)
798 continue; 783 vol = WM_VOL_MAX;
799 vol |= spec->master[ch] & WM_VOL_MUTE; 784 vol |= spec->master[ch] & WM_VOL_MUTE;
800 if (vol != spec->master[ch]) { 785 if (vol != spec->master[ch]) {
801 int dac; 786 int dac;
@@ -820,7 +805,7 @@ static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *
820 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 805 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
821 uinfo->count = voices; 806 uinfo->count = voices;
822 uinfo->value.integer.min = 0; /* mute (-101dB) */ 807 uinfo->value.integer.min = 0; /* mute (-101dB) */
823 uinfo->value.integer.max = 0x7F; /* 0dB */ 808 uinfo->value.integer.max = WM_VOL_MAX; /* 0dB */
824 return 0; 809 return 0;
825} 810}
826 811
@@ -850,9 +835,9 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *
850 snd_ice1712_save_gpio_status(ice); 835 snd_ice1712_save_gpio_status(ice);
851 for (i = 0; i < voices; i++) { 836 for (i = 0; i < voices; i++) {
852 unsigned int vol = ucontrol->value.integer.value[i]; 837 unsigned int vol = ucontrol->value.integer.value[i];
853 if (vol > 0x7f) 838 if (vol > WM_VOL_MAX)
854 continue; 839 vol = WM_VOL_MAX;
855 vol |= spec->vol[ofs+i]; 840 vol |= spec->vol[ofs+i] & WM_VOL_MUTE;
856 if (vol != spec->vol[ofs+i]) { 841 if (vol != spec->vol[ofs+i]) {
857 spec->vol[ofs+i] = vol; 842 spec->vol[ofs+i] = vol;
858 idx = WM_DAC_ATTEN + ofs + i; 843 idx = WM_DAC_ATTEN + ofs + i;
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index d74033a2cfbe..4fc6d8bc637e 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -106,7 +106,7 @@ module_param_array(dxr_enable, int, NULL, 0444);
106MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE."); 106MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
107 107
108 108
109static const struct pci_device_id snd_ice1712_ids[] = { 109static DEFINE_PCI_DEVICE_TABLE(snd_ice1712_ids) = {
110 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_ICE_1712), 0 }, /* ICE1712 */ 110 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_ICE_1712), 0 }, /* ICE1712 */
111 { 0, } 111 { 0, }
112}; 112};
@@ -298,6 +298,16 @@ static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
298 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */ 298 inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
299} 299}
300 300
301static unsigned int snd_ice1712_get_gpio_dir(struct snd_ice1712 *ice)
302{
303 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION);
304}
305
306static unsigned int snd_ice1712_get_gpio_mask(struct snd_ice1712 *ice)
307{
308 return snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK);
309}
310
301static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) 311static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
302{ 312{
303 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data); 313 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
@@ -1170,6 +1180,10 @@ static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
1170 snd_pcm_set_sync(substream); 1180 snd_pcm_set_sync(substream);
1171 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 1181 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1172 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); 1182 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1183 if (is_pro_rate_locked(ice)) {
1184 runtime->hw.rate_min = PRO_RATE_DEFAULT;
1185 runtime->hw.rate_max = PRO_RATE_DEFAULT;
1186 }
1173 1187
1174 if (ice->spdif.ops.open) 1188 if (ice->spdif.ops.open)
1175 ice->spdif.ops.open(ice, substream); 1189 ice->spdif.ops.open(ice, substream);
@@ -1187,6 +1201,11 @@ static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
1187 snd_pcm_set_sync(substream); 1201 snd_pcm_set_sync(substream);
1188 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 1202 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1189 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); 1203 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1204 if (is_pro_rate_locked(ice)) {
1205 runtime->hw.rate_min = PRO_RATE_DEFAULT;
1206 runtime->hw.rate_max = PRO_RATE_DEFAULT;
1207 }
1208
1190 return 0; 1209 return 0;
1191} 1210}
1192 1211
@@ -2557,7 +2576,9 @@ static int __devinit snd_ice1712_create(struct snd_card *card,
2557 mutex_init(&ice->i2c_mutex); 2576 mutex_init(&ice->i2c_mutex);
2558 mutex_init(&ice->open_mutex); 2577 mutex_init(&ice->open_mutex);
2559 ice->gpio.set_mask = snd_ice1712_set_gpio_mask; 2578 ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
2579 ice->gpio.get_mask = snd_ice1712_get_gpio_mask;
2560 ice->gpio.set_dir = snd_ice1712_set_gpio_dir; 2580 ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
2581 ice->gpio.get_dir = snd_ice1712_get_gpio_dir;
2561 ice->gpio.set_data = snd_ice1712_set_gpio_data; 2582 ice->gpio.set_data = snd_ice1712_set_gpio_data;
2562 ice->gpio.get_data = snd_ice1712_get_gpio_data; 2583 ice->gpio.get_data = snd_ice1712_get_gpio_data;
2563 2584
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index d063149e7047..0da778a69ef8 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -359,7 +359,9 @@ struct snd_ice1712 {
359 unsigned int saved[2]; /* for ewx_i2c */ 359 unsigned int saved[2]; /* for ewx_i2c */
360 /* operators */ 360 /* operators */
361 void (*set_mask)(struct snd_ice1712 *ice, unsigned int data); 361 void (*set_mask)(struct snd_ice1712 *ice, unsigned int data);
362 unsigned int (*get_mask)(struct snd_ice1712 *ice);
362 void (*set_dir)(struct snd_ice1712 *ice, unsigned int data); 363 void (*set_dir)(struct snd_ice1712 *ice, unsigned int data);
364 unsigned int (*get_dir)(struct snd_ice1712 *ice);
363 void (*set_data)(struct snd_ice1712 *ice, unsigned int data); 365 void (*set_data)(struct snd_ice1712 *ice, unsigned int data);
364 unsigned int (*get_data)(struct snd_ice1712 *ice); 366 unsigned int (*get_data)(struct snd_ice1712 *ice);
365 /* misc operators - move to another place? */ 367 /* misc operators - move to another place? */
@@ -377,8 +379,11 @@ struct snd_ice1712 {
377 unsigned int (*get_rate)(struct snd_ice1712 *ice); 379 unsigned int (*get_rate)(struct snd_ice1712 *ice);
378 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate); 380 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
379 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate); 381 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
380 void (*set_spdif_clock)(struct snd_ice1712 *ice); 382 int (*set_spdif_clock)(struct snd_ice1712 *ice, int type);
381 383 int (*get_spdif_master_type)(struct snd_ice1712 *ice);
384 char **ext_clock_names;
385 int ext_clock_count;
386 void (*pro_open)(struct snd_ice1712 *, struct snd_pcm_substream *);
382#ifdef CONFIG_PM 387#ifdef CONFIG_PM
383 int (*pm_suspend)(struct snd_ice1712 *); 388 int (*pm_suspend)(struct snd_ice1712 *);
384 int (*pm_resume)(struct snd_ice1712 *); 389 int (*pm_resume)(struct snd_ice1712 *);
@@ -399,6 +404,11 @@ static inline void snd_ice1712_gpio_set_dir(struct snd_ice1712 *ice, unsigned in
399 ice->gpio.set_dir(ice, bits); 404 ice->gpio.set_dir(ice, bits);
400} 405}
401 406
407static inline unsigned int snd_ice1712_gpio_get_dir(struct snd_ice1712 *ice)
408{
409 return ice->gpio.get_dir(ice);
410}
411
402static inline void snd_ice1712_gpio_set_mask(struct snd_ice1712 *ice, unsigned int bits) 412static inline void snd_ice1712_gpio_set_mask(struct snd_ice1712 *ice, unsigned int bits)
403{ 413{
404 ice->gpio.set_mask(ice, bits); 414 ice->gpio.set_mask(ice, bits);
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 10fc92c05574..c1498fa5545f 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -53,6 +53,7 @@
53#include "phase.h" 53#include "phase.h"
54#include "wtm.h" 54#include "wtm.h"
55#include "se.h" 55#include "se.h"
56#include "quartet.h"
56 57
57MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 58MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
58MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)"); 59MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
@@ -70,6 +71,7 @@ MODULE_SUPPORTED_DEVICE("{"
70 PHASE_DEVICE_DESC 71 PHASE_DEVICE_DESC
71 WTM_DEVICE_DESC 72 WTM_DEVICE_DESC
72 SE_DEVICE_DESC 73 SE_DEVICE_DESC
74 QTET_DEVICE_DESC
73 "{VIA,VT1720}," 75 "{VIA,VT1720},"
74 "{VIA,VT1724}," 76 "{VIA,VT1724},"
75 "{ICEnsemble,Generic ICE1724}," 77 "{ICEnsemble,Generic ICE1724},"
@@ -92,7 +94,7 @@ MODULE_PARM_DESC(model, "Use the given board model.");
92 94
93 95
94/* Both VT1720 and VT1724 have the same PCI IDs */ 96/* Both VT1720 and VT1724 have the same PCI IDs */
95static const struct pci_device_id snd_vt1724_ids[] = { 97static DEFINE_PCI_DEVICE_TABLE(snd_vt1724_ids) = {
96 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_VT1724), 0 }, 98 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_VT1724), 0 },
97 { 0, } 99 { 0, }
98}; 100};
@@ -104,6 +106,8 @@ static int PRO_RATE_LOCKED;
104static int PRO_RATE_RESET = 1; 106static int PRO_RATE_RESET = 1;
105static unsigned int PRO_RATE_DEFAULT = 44100; 107static unsigned int PRO_RATE_DEFAULT = 44100;
106 108
109static char *ext_clock_names[1] = { "IEC958 In" };
110
107/* 111/*
108 * Basic I/O 112 * Basic I/O
109 */ 113 */
@@ -118,9 +122,12 @@ static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
118 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0; 122 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
119} 123}
120 124
125/*
126 * locking rate makes sense only for internal clock mode
127 */
121static inline int is_pro_rate_locked(struct snd_ice1712 *ice) 128static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
122{ 129{
123 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED; 130 return (!ice->is_spdif_master(ice)) && PRO_RATE_LOCKED;
124} 131}
125 132
126/* 133/*
@@ -196,6 +203,12 @@ static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
196 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */ 203 inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
197} 204}
198 205
206/* get gpio direction 0 = read, 1 = write */
207static unsigned int snd_vt1724_get_gpio_dir(struct snd_ice1712 *ice)
208{
209 return inl(ICEREG1724(ice, GPIO_DIRECTION));
210}
211
199/* set the gpio mask (0 = writable) */ 212/* set the gpio mask (0 = writable) */
200static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) 213static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
201{ 214{
@@ -205,6 +218,17 @@ static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
205 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */ 218 inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
206} 219}
207 220
221static unsigned int snd_vt1724_get_gpio_mask(struct snd_ice1712 *ice)
222{
223 unsigned int mask;
224 if (!ice->vt1720)
225 mask = (unsigned int)inb(ICEREG1724(ice, GPIO_WRITE_MASK_22));
226 else
227 mask = 0;
228 mask = (mask << 16) | inw(ICEREG1724(ice, GPIO_WRITE_MASK));
229 return mask;
230}
231
208static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data) 232static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
209{ 233{
210 outw(data, ICEREG1724(ice, GPIO_DATA)); 234 outw(data, ICEREG1724(ice, GPIO_DATA));
@@ -651,16 +675,22 @@ static int snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
651 return ((rate == ice->cur_rate) && !force) ? 0 : -EBUSY; 675 return ((rate == ice->cur_rate) && !force) ? 0 : -EBUSY;
652 } 676 }
653 if (!force && is_pro_rate_locked(ice)) { 677 if (!force && is_pro_rate_locked(ice)) {
678 /* comparing required and current rate - makes sense for
679 * internal clock only */
654 spin_unlock_irqrestore(&ice->reg_lock, flags); 680 spin_unlock_irqrestore(&ice->reg_lock, flags);
655 return (rate == ice->cur_rate) ? 0 : -EBUSY; 681 return (rate == ice->cur_rate) ? 0 : -EBUSY;
656 } 682 }
657 683
658 old_rate = ice->get_rate(ice); 684 if (force || !ice->is_spdif_master(ice)) {
659 if (force || (old_rate != rate)) 685 /* force means the rate was switched by ucontrol, otherwise
660 ice->set_rate(ice, rate); 686 * setting clock rate for internal clock mode */
661 else if (rate == ice->cur_rate) { 687 old_rate = ice->get_rate(ice);
662 spin_unlock_irqrestore(&ice->reg_lock, flags); 688 if (force || (old_rate != rate))
663 return 0; 689 ice->set_rate(ice, rate);
690 else if (rate == ice->cur_rate) {
691 spin_unlock_irqrestore(&ice->reg_lock, flags);
692 return 0;
693 }
664 } 694 }
665 695
666 ice->cur_rate = rate; 696 ice->cur_rate = rate;
@@ -1016,6 +1046,8 @@ static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
1016 VT1724_BUFFER_ALIGN); 1046 VT1724_BUFFER_ALIGN);
1017 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1047 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1018 VT1724_BUFFER_ALIGN); 1048 VT1724_BUFFER_ALIGN);
1049 if (ice->pro_open)
1050 ice->pro_open(ice, substream);
1019 return 0; 1051 return 0;
1020} 1052}
1021 1053
@@ -1034,6 +1066,8 @@ static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
1034 VT1724_BUFFER_ALIGN); 1066 VT1724_BUFFER_ALIGN);
1035 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1067 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1036 VT1724_BUFFER_ALIGN); 1068 VT1724_BUFFER_ALIGN);
1069 if (ice->pro_open)
1070 ice->pro_open(ice, substream);
1037 return 0; 1071 return 0;
1038} 1072}
1039 1073
@@ -1787,15 +1821,21 @@ static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1787 struct snd_ctl_elem_info *uinfo) 1821 struct snd_ctl_elem_info *uinfo)
1788{ 1822{
1789 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1823 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1790 1824 int hw_rates_count = ice->hw_rates->count;
1791 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1825 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1792 uinfo->count = 1; 1826 uinfo->count = 1;
1793 uinfo->value.enumerated.items = ice->hw_rates->count + 1; 1827
1828 uinfo->value.enumerated.items = hw_rates_count + ice->ext_clock_count;
1829 /* upper limit - keep at top */
1794 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1830 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1795 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1831 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1796 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1) 1832 if (uinfo->value.enumerated.item >= hw_rates_count)
1797 strcpy(uinfo->value.enumerated.name, "IEC958 Input"); 1833 /* ext_clock items */
1834 strcpy(uinfo->value.enumerated.name,
1835 ice->ext_clock_names[
1836 uinfo->value.enumerated.item - hw_rates_count]);
1798 else 1837 else
1838 /* int clock items */
1799 sprintf(uinfo->value.enumerated.name, "%d", 1839 sprintf(uinfo->value.enumerated.name, "%d",
1800 ice->hw_rates->list[uinfo->value.enumerated.item]); 1840 ice->hw_rates->list[uinfo->value.enumerated.item]);
1801 return 0; 1841 return 0;
@@ -1809,7 +1849,8 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1809 1849
1810 spin_lock_irq(&ice->reg_lock); 1850 spin_lock_irq(&ice->reg_lock);
1811 if (ice->is_spdif_master(ice)) { 1851 if (ice->is_spdif_master(ice)) {
1812 ucontrol->value.enumerated.item[0] = ice->hw_rates->count; 1852 ucontrol->value.enumerated.item[0] = ice->hw_rates->count +
1853 ice->get_spdif_master_type(ice);
1813 } else { 1854 } else {
1814 rate = ice->get_rate(ice); 1855 rate = ice->get_rate(ice);
1815 ucontrol->value.enumerated.item[0] = 0; 1856 ucontrol->value.enumerated.item[0] = 0;
@@ -1824,8 +1865,14 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1824 return 0; 1865 return 0;
1825} 1866}
1826 1867
1868static int stdclock_get_spdif_master_type(struct snd_ice1712 *ice)
1869{
1870 /* standard external clock - only single type - SPDIF IN */
1871 return 0;
1872}
1873
1827/* setting clock to external - SPDIF */ 1874/* setting clock to external - SPDIF */
1828static void stdclock_set_spdif_clock(struct snd_ice1712 *ice) 1875static int stdclock_set_spdif_clock(struct snd_ice1712 *ice, int type)
1829{ 1876{
1830 unsigned char oval; 1877 unsigned char oval;
1831 unsigned char i2s_oval; 1878 unsigned char i2s_oval;
@@ -1834,27 +1881,30 @@ static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1834 /* setting 256fs */ 1881 /* setting 256fs */
1835 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT)); 1882 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1836 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT)); 1883 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1884 return 0;
1837} 1885}
1838 1886
1887
1839static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol, 1888static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1840 struct snd_ctl_elem_value *ucontrol) 1889 struct snd_ctl_elem_value *ucontrol)
1841{ 1890{
1842 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1891 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1843 unsigned int old_rate, new_rate; 1892 unsigned int old_rate, new_rate;
1844 unsigned int item = ucontrol->value.enumerated.item[0]; 1893 unsigned int item = ucontrol->value.enumerated.item[0];
1845 unsigned int spdif = ice->hw_rates->count; 1894 unsigned int first_ext_clock = ice->hw_rates->count;
1846 1895
1847 if (item > spdif) 1896 if (item > first_ext_clock + ice->ext_clock_count - 1)
1848 return -EINVAL; 1897 return -EINVAL;
1849 1898
1899 /* if rate = 0 => external clock */
1850 spin_lock_irq(&ice->reg_lock); 1900 spin_lock_irq(&ice->reg_lock);
1851 if (ice->is_spdif_master(ice)) 1901 if (ice->is_spdif_master(ice))
1852 old_rate = 0; 1902 old_rate = 0;
1853 else 1903 else
1854 old_rate = ice->get_rate(ice); 1904 old_rate = ice->get_rate(ice);
1855 if (item == spdif) { 1905 if (item >= first_ext_clock) {
1856 /* switching to external clock via SPDIF */ 1906 /* switching to external clock */
1857 ice->set_spdif_clock(ice); 1907 ice->set_spdif_clock(ice, item - first_ext_clock);
1858 new_rate = 0; 1908 new_rate = 0;
1859 } else { 1909 } else {
1860 /* internal on-card clock */ 1910 /* internal on-card clock */
@@ -1866,7 +1916,7 @@ static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1866 } 1916 }
1867 spin_unlock_irq(&ice->reg_lock); 1917 spin_unlock_irq(&ice->reg_lock);
1868 1918
1869 /* the first reset to the SPDIF master mode? */ 1919 /* the first switch to the ext. clock mode? */
1870 if (old_rate != new_rate && !new_rate) { 1920 if (old_rate != new_rate && !new_rate) {
1871 /* notify akm chips as well */ 1921 /* notify akm chips as well */
1872 unsigned int i; 1922 unsigned int i;
@@ -2136,6 +2186,7 @@ static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
2136 snd_vt1724_phase_cards, 2186 snd_vt1724_phase_cards,
2137 snd_vt1724_wtm_cards, 2187 snd_vt1724_wtm_cards,
2138 snd_vt1724_se_cards, 2188 snd_vt1724_se_cards,
2189 snd_vt1724_qtet_cards,
2139 NULL, 2190 NULL,
2140}; 2191};
2141 2192
@@ -2434,7 +2485,9 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2434 mutex_init(&ice->open_mutex); 2485 mutex_init(&ice->open_mutex);
2435 mutex_init(&ice->i2c_mutex); 2486 mutex_init(&ice->i2c_mutex);
2436 ice->gpio.set_mask = snd_vt1724_set_gpio_mask; 2487 ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
2488 ice->gpio.get_mask = snd_vt1724_get_gpio_mask;
2437 ice->gpio.set_dir = snd_vt1724_set_gpio_dir; 2489 ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
2490 ice->gpio.get_dir = snd_vt1724_get_gpio_dir;
2438 ice->gpio.set_data = snd_vt1724_set_gpio_data; 2491 ice->gpio.set_data = snd_vt1724_set_gpio_data;
2439 ice->gpio.get_data = snd_vt1724_get_gpio_data; 2492 ice->gpio.get_data = snd_vt1724_get_gpio_data;
2440 ice->card = card; 2493 ice->card = card;
@@ -2522,6 +2575,9 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2522 return err; 2575 return err;
2523 } 2576 }
2524 2577
2578 /* field init before calling chip_init */
2579 ice->ext_clock_count = 0;
2580
2525 for (tbl = card_tables; *tbl; tbl++) { 2581 for (tbl = card_tables; *tbl; tbl++) {
2526 for (c = *tbl; c->subvendor; c++) { 2582 for (c = *tbl; c->subvendor; c++) {
2527 if (c->subvendor == ice->eeprom.subvendor) { 2583 if (c->subvendor == ice->eeprom.subvendor) {
@@ -2560,6 +2616,13 @@ __found:
2560 ice->set_mclk = stdclock_set_mclk; 2616 ice->set_mclk = stdclock_set_mclk;
2561 if (!ice->set_spdif_clock) 2617 if (!ice->set_spdif_clock)
2562 ice->set_spdif_clock = stdclock_set_spdif_clock; 2618 ice->set_spdif_clock = stdclock_set_spdif_clock;
2619 if (!ice->get_spdif_master_type)
2620 ice->get_spdif_master_type = stdclock_get_spdif_master_type;
2621 if (!ice->ext_clock_names)
2622 ice->ext_clock_names = ext_clock_names;
2623 if (!ice->ext_clock_count)
2624 ice->ext_clock_count = ARRAY_SIZE(ext_clock_names);
2625
2563 if (!ice->hw_rates) 2626 if (!ice->hw_rates)
2564 set_std_hw_rates(ice); 2627 set_std_hw_rates(ice);
2565 2628
@@ -2719,7 +2782,7 @@ static int snd_vt1724_resume(struct pci_dev *pci)
2719 2782
2720 if (ice->pm_saved_is_spdif_master) { 2783 if (ice->pm_saved_is_spdif_master) {
2721 /* switching to external clock via SPDIF */ 2784 /* switching to external clock via SPDIF */
2722 ice->set_spdif_clock(ice); 2785 ice->set_spdif_clock(ice, 0);
2723 } else { 2786 } else {
2724 /* internal on-card clock */ 2787 /* internal on-card clock */
2725 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1); 2788 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index fd948bfd9aef..98bc3b7681b5 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -380,7 +380,7 @@ static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
380 * inputs) are fed from Xilinx. 380 * inputs) are fed from Xilinx.
381 * 381 *
382 * I even checked traces on board and coded a support in driver for 382 * I even checked traces on board and coded a support in driver for
383 * an alternative possiblity - the unused I2S ICE output channels 383 * an alternative possibility - the unused I2S ICE output channels
384 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to 384 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
385 * the DAC - to no avail. The I2S outputs seem to be unconnected. 385 * the DAC - to no avail. The I2S outputs seem to be unconnected.
386 * 386 *
@@ -412,25 +412,6 @@ static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
412 }, 412 },
413}; 413};
414 414
415
416static void ak4358_proc_regs_read(struct snd_info_entry *entry,
417 struct snd_info_buffer *buffer)
418{
419 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
420 int reg, val;
421 for (reg = 0; reg <= 0xf; reg++) {
422 val = snd_akm4xxx_get(ice->akm, 0, reg);
423 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
424 }
425}
426
427static void ak4358_proc_init(struct snd_ice1712 *ice)
428{
429 struct snd_info_entry *entry;
430 if (!snd_card_proc_new(ice->card, "ak4358_codec", &entry))
431 snd_info_set_text_ops(entry, ice, ak4358_proc_regs_read);
432}
433
434static char *slave_vols[] __devinitdata = { 415static char *slave_vols[] __devinitdata = {
435 PCM_VOLUME, 416 PCM_VOLUME,
436 MONITOR_AN_IN_VOLUME, 417 MONITOR_AN_IN_VOLUME,
@@ -496,14 +477,37 @@ static int __devinit juli_add_controls(struct snd_ice1712 *ice)
496 /* only capture SPDIF over AK4114 */ 477 /* only capture SPDIF over AK4114 */
497 err = snd_ak4114_build(spec->ak4114, NULL, 478 err = snd_ak4114_build(spec->ak4114, NULL,
498 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 479 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
499
500 ak4358_proc_init(ice);
501 if (err < 0) 480 if (err < 0)
502 return err; 481 return err;
503 return 0; 482 return 0;
504} 483}
505 484
506/* 485/*
486 * suspend/resume
487 * */
488
489#ifdef CONFIG_PM
490static int juli_resume(struct snd_ice1712 *ice)
491{
492 struct snd_akm4xxx *ak = ice->akm;
493 struct juli_spec *spec = ice->spec;
494 /* akm4358 un-reset, un-mute */
495 snd_akm4xxx_reset(ak, 0);
496 /* reinit ak4114 */
497 snd_ak4114_reinit(spec->ak4114);
498 return 0;
499}
500
501static int juli_suspend(struct snd_ice1712 *ice)
502{
503 struct snd_akm4xxx *ak = ice->akm;
504 /* akm4358 reset and soft-mute */
505 snd_akm4xxx_reset(ak, 1);
506 return 0;
507}
508#endif
509
510/*
507 * initialize the chip 511 * initialize the chip
508 */ 512 */
509 513
@@ -550,13 +554,14 @@ static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
550} 554}
551 555
552/* setting clock to external - SPDIF */ 556/* setting clock to external - SPDIF */
553static void juli_set_spdif_clock(struct snd_ice1712 *ice) 557static int juli_set_spdif_clock(struct snd_ice1712 *ice, int type)
554{ 558{
555 unsigned int old; 559 unsigned int old;
556 old = ice->gpio.get_data(ice); 560 old = ice->gpio.get_data(ice);
557 /* external clock (= 0), multiply 1x, 48kHz */ 561 /* external clock (= 0), multiply 1x, 48kHz */
558 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X | 562 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
559 GPIO_FREQ_48KHZ); 563 GPIO_FREQ_48KHZ);
564 return 0;
560} 565}
561 566
562/* Called when ak4114 detects change in the input SPDIF stream */ 567/* Called when ak4114 detects change in the input SPDIF stream */
@@ -646,6 +651,13 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
646 ice->set_spdif_clock = juli_set_spdif_clock; 651 ice->set_spdif_clock = juli_set_spdif_clock;
647 652
648 ice->spdif.ops.open = juli_spdif_in_open; 653 ice->spdif.ops.open = juli_spdif_in_open;
654
655#ifdef CONFIG_PM
656 ice->pm_resume = juli_resume;
657 ice->pm_suspend = juli_suspend;
658 ice->pm_suspend_enabled = 1;
659#endif
660
649 return 0; 661 return 0;
650} 662}
651 663
diff --git a/sound/pci/ice1712/maya44.c b/sound/pci/ice1712/maya44.c
index 3e1c20ae2f1c..726fd4b92e19 100644
--- a/sound/pci/ice1712/maya44.c
+++ b/sound/pci/ice1712/maya44.c
@@ -347,7 +347,7 @@ static int maya_gpio_sw_put(struct snd_kcontrol *kcontrol,
347 347
348/* known working input slots (0-4) */ 348/* known working input slots (0-4) */
349#define MAYA_LINE_IN 1 /* in-2 */ 349#define MAYA_LINE_IN 1 /* in-2 */
350#define MAYA_MIC_IN 4 /* in-5 */ 350#define MAYA_MIC_IN 3 /* in-4 */
351 351
352static void wm8776_select_input(struct snd_maya44 *chip, int idx, int line) 352static void wm8776_select_input(struct snd_maya44 *chip, int idx, int line)
353{ 353{
@@ -393,8 +393,8 @@ static int maya_rec_src_put(struct snd_kcontrol *kcontrol,
393 int changed; 393 int changed;
394 394
395 mutex_lock(&chip->mutex); 395 mutex_lock(&chip->mutex);
396 changed = maya_set_gpio_bits(chip->ice, GPIO_MIC_RELAY, 396 changed = maya_set_gpio_bits(chip->ice, 1 << GPIO_MIC_RELAY,
397 sel ? GPIO_MIC_RELAY : 0); 397 sel ? (1 << GPIO_MIC_RELAY) : 0);
398 wm8776_select_input(chip, 0, sel ? MAYA_MIC_IN : MAYA_LINE_IN); 398 wm8776_select_input(chip, 0, sel ? MAYA_MIC_IN : MAYA_LINE_IN);
399 mutex_unlock(&chip->mutex); 399 mutex_unlock(&chip->mutex);
400 return changed; 400 return changed;
diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c
new file mode 100644
index 000000000000..1948632787e6
--- /dev/null
+++ b/sound/pci/ice1712/quartet.c
@@ -0,0 +1,1130 @@
1/*
2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
3 *
4 * Lowlevel functions for Infrasonic Quartet
5 *
6 * Copyright (c) 2009 Pavel Hofman <pavel.hofman@ivitera.com>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <asm/io.h>
26#include <linux/delay.h>
27#include <linux/interrupt.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <sound/core.h>
31#include <sound/tlv.h>
32#include <sound/info.h>
33
34#include "ice1712.h"
35#include "envy24ht.h"
36#include <sound/ak4113.h>
37#include "quartet.h"
38
39struct qtet_spec {
40 struct ak4113 *ak4113;
41 unsigned int scr; /* system control register */
42 unsigned int mcr; /* monitoring control register */
43 unsigned int cpld; /* cpld register */
44};
45
46struct qtet_kcontrol_private {
47 unsigned int bit;
48 void (*set_register)(struct snd_ice1712 *ice, unsigned int val);
49 unsigned int (*get_register)(struct snd_ice1712 *ice);
50 unsigned char *texts[2];
51};
52
53enum {
54 IN12_SEL = 0,
55 IN34_SEL,
56 AIN34_SEL,
57 COAX_OUT,
58 IN12_MON12,
59 IN12_MON34,
60 IN34_MON12,
61 IN34_MON34,
62 OUT12_MON34,
63 OUT34_MON12,
64};
65
66static char *ext_clock_names[3] = {"IEC958 In", "Word Clock 1xFS",
67 "Word Clock 256xFS"};
68
69/* chip address on I2C bus */
70#define AK4113_ADDR 0x26 /* S/PDIF receiver */
71
72/* chip address on SPI bus */
73#define AK4620_ADDR 0x02 /* ADC/DAC */
74
75
76/*
77 * GPIO pins
78 */
79
80/* GPIO0 - O - DATA0, def. 0 */
81#define GPIO_D0 (1<<0)
82/* GPIO1 - I/O - DATA1, Jack Detect Input0 (0:present, 1:missing), def. 1 */
83#define GPIO_D1_JACKDTC0 (1<<1)
84/* GPIO2 - I/O - DATA2, Jack Detect Input1 (0:present, 1:missing), def. 1 */
85#define GPIO_D2_JACKDTC1 (1<<2)
86/* GPIO3 - I/O - DATA3, def. 1 */
87#define GPIO_D3 (1<<3)
88/* GPIO4 - I/O - DATA4, SPI CDTO, def. 1 */
89#define GPIO_D4_SPI_CDTO (1<<4)
90/* GPIO5 - I/O - DATA5, SPI CCLK, def. 1 */
91#define GPIO_D5_SPI_CCLK (1<<5)
92/* GPIO6 - I/O - DATA6, Cable Detect Input (0:detected, 1:not detected */
93#define GPIO_D6_CD (1<<6)
94/* GPIO7 - I/O - DATA7, Device Detect Input (0:detected, 1:not detected */
95#define GPIO_D7_DD (1<<7)
96/* GPIO8 - O - CPLD Chip Select, def. 1 */
97#define GPIO_CPLD_CSN (1<<8)
98/* GPIO9 - O - CPLD register read/write (0:write, 1:read), def. 0 */
99#define GPIO_CPLD_RW (1<<9)
100/* GPIO10 - O - SPI Chip Select for CODEC#0, def. 1 */
101#define GPIO_SPI_CSN0 (1<<10)
102/* GPIO11 - O - SPI Chip Select for CODEC#1, def. 1 */
103#define GPIO_SPI_CSN1 (1<<11)
104/* GPIO12 - O - Ex. Register Output Enable (0:enable, 1:disable), def. 1,
105 * init 0 */
106#define GPIO_EX_GPIOE (1<<12)
107/* GPIO13 - O - Ex. Register0 Chip Select for System Control Register,
108 * def. 1 */
109#define GPIO_SCR (1<<13)
110/* GPIO14 - O - Ex. Register1 Chip Select for Monitor Control Register,
111 * def. 1 */
112#define GPIO_MCR (1<<14)
113
114#define GPIO_SPI_ALL (GPIO_D4_SPI_CDTO | GPIO_D5_SPI_CCLK |\
115 GPIO_SPI_CSN0 | GPIO_SPI_CSN1)
116
117#define GPIO_DATA_MASK (GPIO_D0 | GPIO_D1_JACKDTC0 | \
118 GPIO_D2_JACKDTC1 | GPIO_D3 | \
119 GPIO_D4_SPI_CDTO | GPIO_D5_SPI_CCLK | \
120 GPIO_D6_CD | GPIO_D7_DD)
121
122/* System Control Register GPIO_SCR data bits */
123/* Mic/Line select relay (0:line, 1:mic) */
124#define SCR_RELAY GPIO_D0
125/* Phantom power drive control (0:5V, 1:48V) */
126#define SCR_PHP_V GPIO_D1_JACKDTC0
127/* H/W mute control (0:Normal, 1:Mute) */
128#define SCR_MUTE GPIO_D2_JACKDTC1
129/* Phantom power control (0:Phantom on, 1:off) */
130#define SCR_PHP GPIO_D3
131/* Analog input 1/2 Source Select */
132#define SCR_AIN12_SEL0 GPIO_D4_SPI_CDTO
133#define SCR_AIN12_SEL1 GPIO_D5_SPI_CCLK
134/* Analog input 3/4 Source Select (0:line, 1:hi-z) */
135#define SCR_AIN34_SEL GPIO_D6_CD
136/* Codec Power Down (0:power down, 1:normal) */
137#define SCR_CODEC_PDN GPIO_D7_DD
138
139#define SCR_AIN12_LINE (0)
140#define SCR_AIN12_MIC (SCR_AIN12_SEL0)
141#define SCR_AIN12_LOWCUT (SCR_AIN12_SEL1 | SCR_AIN12_SEL0)
142
143/* Monitor Control Register GPIO_MCR data bits */
144/* Input 1/2 to Monitor 1/2 (0:off, 1:on) */
145#define MCR_IN12_MON12 GPIO_D0
146/* Input 1/2 to Monitor 3/4 (0:off, 1:on) */
147#define MCR_IN12_MON34 GPIO_D1_JACKDTC0
148/* Input 3/4 to Monitor 1/2 (0:off, 1:on) */
149#define MCR_IN34_MON12 GPIO_D2_JACKDTC1
150/* Input 3/4 to Monitor 3/4 (0:off, 1:on) */
151#define MCR_IN34_MON34 GPIO_D3
152/* Output to Monitor 1/2 (0:off, 1:on) */
153#define MCR_OUT34_MON12 GPIO_D4_SPI_CDTO
154/* Output to Monitor 3/4 (0:off, 1:on) */
155#define MCR_OUT12_MON34 GPIO_D5_SPI_CCLK
156
157/* CPLD Register DATA bits */
158/* Clock Rate Select */
159#define CPLD_CKS0 GPIO_D0
160#define CPLD_CKS1 GPIO_D1_JACKDTC0
161#define CPLD_CKS2 GPIO_D2_JACKDTC1
162/* Sync Source Select (0:Internal, 1:External) */
163#define CPLD_SYNC_SEL GPIO_D3
164/* Word Clock FS Select (0:FS, 1:256FS) */
165#define CPLD_WORD_SEL GPIO_D4_SPI_CDTO
166/* Coaxial Output Source (IS-Link) (0:SPDIF, 1:I2S) */
167#define CPLD_COAX_OUT GPIO_D5_SPI_CCLK
168/* Input 1/2 Source Select (0:Analog12, 1:An34) */
169#define CPLD_IN12_SEL GPIO_D6_CD
170/* Input 3/4 Source Select (0:Analog34, 1:Digital In) */
171#define CPLD_IN34_SEL GPIO_D7_DD
172
173/* internal clock (CPLD_SYNC_SEL = 0) options */
174#define CPLD_CKS_44100HZ (0)
175#define CPLD_CKS_48000HZ (CPLD_CKS0)
176#define CPLD_CKS_88200HZ (CPLD_CKS1)
177#define CPLD_CKS_96000HZ (CPLD_CKS1 | CPLD_CKS0)
178#define CPLD_CKS_176400HZ (CPLD_CKS2)
179#define CPLD_CKS_192000HZ (CPLD_CKS2 | CPLD_CKS0)
180
181#define CPLD_CKS_MASK (CPLD_CKS0 | CPLD_CKS1 | CPLD_CKS2)
182
183/* external clock (CPLD_SYNC_SEL = 1) options */
184/* external clock - SPDIF */
185#define CPLD_EXT_SPDIF (0 | CPLD_SYNC_SEL)
186/* external clock - WordClock 1xfs */
187#define CPLD_EXT_WORDCLOCK_1FS (CPLD_CKS1 | CPLD_SYNC_SEL)
188/* external clock - WordClock 256xfs */
189#define CPLD_EXT_WORDCLOCK_256FS (CPLD_CKS1 | CPLD_WORD_SEL |\
190 CPLD_SYNC_SEL)
191
192#define EXT_SPDIF_TYPE 0
193#define EXT_WORDCLOCK_1FS_TYPE 1
194#define EXT_WORDCLOCK_256FS_TYPE 2
195
196#define AK4620_DFS0 (1<<0)
197#define AK4620_DFS1 (1<<1)
198#define AK4620_CKS0 (1<<2)
199#define AK4620_CKS1 (1<<3)
200/* Clock and Format Control register */
201#define AK4620_DFS_REG 0x02
202
203/* Deem and Volume Control register */
204#define AK4620_DEEMVOL_REG 0x03
205#define AK4620_SMUTE (1<<7)
206
207/*
208 * Conversion from int value to its binary form. Used for debugging.
209 * The output buffer must be allocated prior to calling the function.
210 */
211static char *get_binary(char *buffer, int value)
212{
213 int i, j, pos;
214 pos = 0;
215 for (i = 0; i < 4; ++i) {
216 for (j = 0; j < 8; ++j) {
217 if (value & (1 << (31-(i*8 + j))))
218 buffer[pos] = '1';
219 else
220 buffer[pos] = '0';
221 pos++;
222 }
223 if (i < 3) {
224 buffer[pos] = ' ';
225 pos++;
226 }
227 }
228 buffer[pos] = '\0';
229 return buffer;
230}
231
232/*
233 * Initial setup of the conversion array GPIO <-> rate
234 */
235static unsigned int qtet_rates[] = {
236 44100, 48000, 88200,
237 96000, 176400, 192000,
238};
239
240static unsigned int cks_vals[] = {
241 CPLD_CKS_44100HZ, CPLD_CKS_48000HZ, CPLD_CKS_88200HZ,
242 CPLD_CKS_96000HZ, CPLD_CKS_176400HZ, CPLD_CKS_192000HZ,
243};
244
245static struct snd_pcm_hw_constraint_list qtet_rates_info = {
246 .count = ARRAY_SIZE(qtet_rates),
247 .list = qtet_rates,
248 .mask = 0,
249};
250
251static void qtet_ak4113_write(void *private_data, unsigned char reg,
252 unsigned char val)
253{
254 snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4113_ADDR,
255 reg, val);
256}
257
258static unsigned char qtet_ak4113_read(void *private_data, unsigned char reg)
259{
260 return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data,
261 AK4113_ADDR, reg);
262}
263
264
265/*
266 * AK4620 section
267 */
268
269/*
270 * Write data to addr register of ak4620
271 */
272static void qtet_akm_write(struct snd_akm4xxx *ak, int chip,
273 unsigned char addr, unsigned char data)
274{
275 unsigned int tmp, orig_dir;
276 int idx;
277 unsigned int addrdata;
278 struct snd_ice1712 *ice = ak->private_data[0];
279
280 if (snd_BUG_ON(chip < 0 || chip >= 4))
281 return;
282 /*printk(KERN_DEBUG "Writing to AK4620: chip=%d, addr=0x%x,
283 data=0x%x\n", chip, addr, data);*/
284 orig_dir = ice->gpio.get_dir(ice);
285 ice->gpio.set_dir(ice, orig_dir | GPIO_SPI_ALL);
286 /* set mask - only SPI bits */
287 ice->gpio.set_mask(ice, ~GPIO_SPI_ALL);
288
289 tmp = ice->gpio.get_data(ice);
290 /* high all */
291 tmp |= GPIO_SPI_ALL;
292 ice->gpio.set_data(ice, tmp);
293 udelay(100);
294 /* drop chip select */
295 if (chip)
296 /* CODEC 1 */
297 tmp &= ~GPIO_SPI_CSN1;
298 else
299 tmp &= ~GPIO_SPI_CSN0;
300 ice->gpio.set_data(ice, tmp);
301 udelay(100);
302
303 /* build I2C address + data byte */
304 addrdata = (AK4620_ADDR << 6) | 0x20 | (addr & 0x1f);
305 addrdata = (addrdata << 8) | data;
306 for (idx = 15; idx >= 0; idx--) {
307 /* drop clock */
308 tmp &= ~GPIO_D5_SPI_CCLK;
309 ice->gpio.set_data(ice, tmp);
310 udelay(100);
311 /* set data */
312 if (addrdata & (1 << idx))
313 tmp |= GPIO_D4_SPI_CDTO;
314 else
315 tmp &= ~GPIO_D4_SPI_CDTO;
316 ice->gpio.set_data(ice, tmp);
317 udelay(100);
318 /* raise clock */
319 tmp |= GPIO_D5_SPI_CCLK;
320 ice->gpio.set_data(ice, tmp);
321 udelay(100);
322 }
323 /* all back to 1 */
324 tmp |= GPIO_SPI_ALL;
325 ice->gpio.set_data(ice, tmp);
326 udelay(100);
327
328 /* return all gpios to non-writable */
329 ice->gpio.set_mask(ice, 0xffffff);
330 /* restore GPIOs direction */
331 ice->gpio.set_dir(ice, orig_dir);
332}
333
334static void qtet_akm_set_regs(struct snd_akm4xxx *ak, unsigned char addr,
335 unsigned char mask, unsigned char value)
336{
337 unsigned char tmp;
338 int chip;
339 for (chip = 0; chip < ak->num_chips; chip++) {
340 tmp = snd_akm4xxx_get(ak, chip, addr);
341 /* clear the bits */
342 tmp &= ~mask;
343 /* set the new bits */
344 tmp |= value;
345 snd_akm4xxx_write(ak, chip, addr, tmp);
346 }
347}
348
349/*
350 * change the rate of AK4620
351 */
352static void qtet_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
353{
354 unsigned char ak4620_dfs;
355
356 if (rate == 0) /* no hint - S/PDIF input is master or the new spdif
357 input rate undetected, simply return */
358 return;
359
360 /* adjust DFS on codecs - see datasheet */
361 if (rate > 108000)
362 ak4620_dfs = AK4620_DFS1 | AK4620_CKS1;
363 else if (rate > 54000)
364 ak4620_dfs = AK4620_DFS0 | AK4620_CKS0;
365 else
366 ak4620_dfs = 0;
367
368 /* set new value */
369 qtet_akm_set_regs(ak, AK4620_DFS_REG, AK4620_DFS0 | AK4620_DFS1 |
370 AK4620_CKS0 | AK4620_CKS1, ak4620_dfs);
371}
372
373#define AK_CONTROL(xname, xch) { .name = xname, .num_channels = xch }
374
375#define PCM_12_PLAYBACK_VOLUME "PCM 1/2 Playback Volume"
376#define PCM_34_PLAYBACK_VOLUME "PCM 3/4 Playback Volume"
377#define PCM_12_CAPTURE_VOLUME "PCM 1/2 Capture Volume"
378#define PCM_34_CAPTURE_VOLUME "PCM 3/4 Capture Volume"
379
380static const struct snd_akm4xxx_dac_channel qtet_dac[] = {
381 AK_CONTROL(PCM_12_PLAYBACK_VOLUME, 2),
382 AK_CONTROL(PCM_34_PLAYBACK_VOLUME, 2),
383};
384
385static const struct snd_akm4xxx_adc_channel qtet_adc[] = {
386 AK_CONTROL(PCM_12_CAPTURE_VOLUME, 2),
387 AK_CONTROL(PCM_34_CAPTURE_VOLUME, 2),
388};
389
390static struct snd_akm4xxx akm_qtet_dac __devinitdata = {
391 .type = SND_AK4620,
392 .num_dacs = 4, /* DAC1 - Output 12
393 */
394 .num_adcs = 4, /* ADC1 - Input 12
395 */
396 .ops = {
397 .write = qtet_akm_write,
398 .set_rate_val = qtet_akm_set_rate_val,
399 },
400 .dac_info = qtet_dac,
401 .adc_info = qtet_adc,
402};
403
404/* Communication routines with the CPLD */
405
406
407/* Writes data to external register reg, both reg and data are
408 * GPIO representations */
409static void reg_write(struct snd_ice1712 *ice, unsigned int reg,
410 unsigned int data)
411{
412 unsigned int tmp;
413
414 mutex_lock(&ice->gpio_mutex);
415 /* set direction of used GPIOs*/
416 /* all outputs */
417 tmp = 0x00ffff;
418 ice->gpio.set_dir(ice, tmp);
419 /* mask - writable bits */
420 ice->gpio.set_mask(ice, ~(tmp));
421 /* write the data */
422 tmp = ice->gpio.get_data(ice);
423 tmp &= ~GPIO_DATA_MASK;
424 tmp |= data;
425 ice->gpio.set_data(ice, tmp);
426 udelay(100);
427 /* drop output enable */
428 tmp &= ~GPIO_EX_GPIOE;
429 ice->gpio.set_data(ice, tmp);
430 udelay(100);
431 /* drop the register gpio */
432 tmp &= ~reg;
433 ice->gpio.set_data(ice, tmp);
434 udelay(100);
435 /* raise the register GPIO */
436 tmp |= reg;
437 ice->gpio.set_data(ice, tmp);
438 udelay(100);
439
440 /* raise all data gpios */
441 tmp |= GPIO_DATA_MASK;
442 ice->gpio.set_data(ice, tmp);
443 /* mask - immutable bits */
444 ice->gpio.set_mask(ice, 0xffffff);
445 /* outputs only 8-15 */
446 ice->gpio.set_dir(ice, 0x00ff00);
447 mutex_unlock(&ice->gpio_mutex);
448}
449
450static unsigned int get_scr(struct snd_ice1712 *ice)
451{
452 struct qtet_spec *spec = ice->spec;
453 return spec->scr;
454}
455
456static unsigned int get_mcr(struct snd_ice1712 *ice)
457{
458 struct qtet_spec *spec = ice->spec;
459 return spec->mcr;
460}
461
462static unsigned int get_cpld(struct snd_ice1712 *ice)
463{
464 struct qtet_spec *spec = ice->spec;
465 return spec->cpld;
466}
467
468static void set_scr(struct snd_ice1712 *ice, unsigned int val)
469{
470 struct qtet_spec *spec = ice->spec;
471 reg_write(ice, GPIO_SCR, val);
472 spec->scr = val;
473}
474
475static void set_mcr(struct snd_ice1712 *ice, unsigned int val)
476{
477 struct qtet_spec *spec = ice->spec;
478 reg_write(ice, GPIO_MCR, val);
479 spec->mcr = val;
480}
481
482static void set_cpld(struct snd_ice1712 *ice, unsigned int val)
483{
484 struct qtet_spec *spec = ice->spec;
485 reg_write(ice, GPIO_CPLD_CSN, val);
486 spec->cpld = val;
487}
488#ifdef CONFIG_PROC_FS
489static void proc_regs_read(struct snd_info_entry *entry,
490 struct snd_info_buffer *buffer)
491{
492 struct snd_ice1712 *ice = entry->private_data;
493 char bin_buffer[36];
494
495 snd_iprintf(buffer, "SCR: %s\n", get_binary(bin_buffer,
496 get_scr(ice)));
497 snd_iprintf(buffer, "MCR: %s\n", get_binary(bin_buffer,
498 get_mcr(ice)));
499 snd_iprintf(buffer, "CPLD: %s\n", get_binary(bin_buffer,
500 get_cpld(ice)));
501}
502
503static void proc_init(struct snd_ice1712 *ice)
504{
505 struct snd_info_entry *entry;
506 if (!snd_card_proc_new(ice->card, "quartet", &entry))
507 snd_info_set_text_ops(entry, ice, proc_regs_read);
508}
509#else /* !CONFIG_PROC_FS */
510static void proc_init(struct snd_ice1712 *ice) {}
511#endif
512
513static int qtet_mute_get(struct snd_kcontrol *kcontrol,
514 struct snd_ctl_elem_value *ucontrol)
515{
516 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
517 unsigned int val;
518 val = get_scr(ice) & SCR_MUTE;
519 ucontrol->value.integer.value[0] = (val) ? 0 : 1;
520 return 0;
521}
522
523static int qtet_mute_put(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_value *ucontrol)
525{
526 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
527 unsigned int old, new, smute;
528 old = get_scr(ice) & SCR_MUTE;
529 if (ucontrol->value.integer.value[0]) {
530 /* unmute */
531 new = 0;
532 /* un-smuting DAC */
533 smute = 0;
534 } else {
535 /* mute */
536 new = SCR_MUTE;
537 /* smuting DAC */
538 smute = AK4620_SMUTE;
539 }
540 if (old != new) {
541 struct snd_akm4xxx *ak = ice->akm;
542 set_scr(ice, (get_scr(ice) & ~SCR_MUTE) | new);
543 /* set smute */
544 qtet_akm_set_regs(ak, AK4620_DEEMVOL_REG, AK4620_SMUTE, smute);
545 return 1;
546 }
547 /* no change */
548 return 0;
549}
550
551static int qtet_ain12_enum_info(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_info *uinfo)
553{
554 static char *texts[3] = {"Line In 1/2", "Mic", "Mic + Low-cut"};
555 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
556 uinfo->count = 1;
557 uinfo->value.enumerated.items = ARRAY_SIZE(texts);
558
559 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
560 uinfo->value.enumerated.item =
561 uinfo->value.enumerated.items - 1;
562 strcpy(uinfo->value.enumerated.name,
563 texts[uinfo->value.enumerated.item]);
564
565 return 0;
566}
567
568static int qtet_ain12_sw_get(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol)
570{
571 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
572 unsigned int val, result;
573 val = get_scr(ice) & (SCR_AIN12_SEL1 | SCR_AIN12_SEL0);
574 switch (val) {
575 case SCR_AIN12_LINE:
576 result = 0;
577 break;
578 case SCR_AIN12_MIC:
579 result = 1;
580 break;
581 case SCR_AIN12_LOWCUT:
582 result = 2;
583 break;
584 default:
585 /* BUG - no other combinations allowed */
586 snd_BUG();
587 result = 0;
588 }
589 ucontrol->value.integer.value[0] = result;
590 return 0;
591}
592
593static int qtet_ain12_sw_put(struct snd_kcontrol *kcontrol,
594 struct snd_ctl_elem_value *ucontrol)
595{
596 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
597 unsigned int old, new, tmp, masked_old;
598 old = new = get_scr(ice);
599 masked_old = old & (SCR_AIN12_SEL1 | SCR_AIN12_SEL0);
600 tmp = ucontrol->value.integer.value[0];
601 if (tmp == 2)
602 tmp = 3; /* binary 10 is not supported */
603 tmp <<= 4; /* shifting to SCR_AIN12_SEL0 */
604 if (tmp != masked_old) {
605 /* change requested */
606 switch (tmp) {
607 case SCR_AIN12_LINE:
608 new = old & ~(SCR_AIN12_SEL1 | SCR_AIN12_SEL0);
609 set_scr(ice, new);
610 /* turn off relay */
611 new &= ~SCR_RELAY;
612 set_scr(ice, new);
613 break;
614 case SCR_AIN12_MIC:
615 /* turn on relay */
616 new = old | SCR_RELAY;
617 set_scr(ice, new);
618 new = (new & ~SCR_AIN12_SEL1) | SCR_AIN12_SEL0;
619 set_scr(ice, new);
620 break;
621 case SCR_AIN12_LOWCUT:
622 /* turn on relay */
623 new = old | SCR_RELAY;
624 set_scr(ice, new);
625 new |= SCR_AIN12_SEL1 | SCR_AIN12_SEL0;
626 set_scr(ice, new);
627 break;
628 default:
629 snd_BUG();
630 }
631 return 1;
632 }
633 /* no change */
634 return 0;
635}
636
637static int qtet_php_get(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol)
639{
640 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
641 unsigned int val;
642 /* if phantom voltage =48V, phantom on */
643 val = get_scr(ice) & SCR_PHP_V;
644 ucontrol->value.integer.value[0] = val ? 1 : 0;
645 return 0;
646}
647
648static int qtet_php_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
652 unsigned int old, new;
653 old = new = get_scr(ice);
654 if (ucontrol->value.integer.value[0] /* phantom on requested */
655 && (~old & SCR_PHP_V)) /* 0 = voltage 5V */ {
656 /* is off, turn on */
657 /* turn voltage on first, = 1 */
658 new = old | SCR_PHP_V;
659 set_scr(ice, new);
660 /* turn phantom on, = 0 */
661 new &= ~SCR_PHP;
662 set_scr(ice, new);
663 } else if (!ucontrol->value.integer.value[0] && (old & SCR_PHP_V)) {
664 /* phantom off requested and 1 = voltage 48V */
665 /* is on, turn off */
666 /* turn voltage off first, = 0 */
667 new = old & ~SCR_PHP_V;
668 set_scr(ice, new);
669 /* turn phantom off, = 1 */
670 new |= SCR_PHP;
671 set_scr(ice, new);
672 }
673 if (old != new)
674 return 1;
675 /* no change */
676 return 0;
677}
678
679#define PRIV_SW(xid, xbit, xreg) [xid] = {.bit = xbit,\
680 .set_register = set_##xreg,\
681 .get_register = get_##xreg, }
682
683
684#define PRIV_ENUM2(xid, xbit, xreg, xtext1, xtext2) [xid] = {.bit = xbit,\
685 .set_register = set_##xreg,\
686 .get_register = get_##xreg,\
687 .texts = {xtext1, xtext2} }
688
689static struct qtet_kcontrol_private qtet_privates[] = {
690 PRIV_ENUM2(IN12_SEL, CPLD_IN12_SEL, cpld, "An In 1/2", "An In 3/4"),
691 PRIV_ENUM2(IN34_SEL, CPLD_IN34_SEL, cpld, "An In 3/4", "IEC958 In"),
692 PRIV_ENUM2(AIN34_SEL, SCR_AIN34_SEL, scr, "Line In 3/4", "Hi-Z"),
693 PRIV_ENUM2(COAX_OUT, CPLD_COAX_OUT, cpld, "IEC958", "I2S"),
694 PRIV_SW(IN12_MON12, MCR_IN12_MON12, mcr),
695 PRIV_SW(IN12_MON34, MCR_IN12_MON34, mcr),
696 PRIV_SW(IN34_MON12, MCR_IN34_MON12, mcr),
697 PRIV_SW(IN34_MON34, MCR_IN34_MON34, mcr),
698 PRIV_SW(OUT12_MON34, MCR_OUT12_MON34, mcr),
699 PRIV_SW(OUT34_MON12, MCR_OUT34_MON12, mcr),
700};
701
702static int qtet_enum_info(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_info *uinfo)
704{
705 struct qtet_kcontrol_private private =
706 qtet_privates[kcontrol->private_value];
707 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
708 uinfo->count = 1;
709 uinfo->value.enumerated.items = ARRAY_SIZE(private.texts);
710
711 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
712 uinfo->value.enumerated.item =
713 uinfo->value.enumerated.items - 1;
714 strcpy(uinfo->value.enumerated.name,
715 private.texts[uinfo->value.enumerated.item]);
716
717 return 0;
718}
719
720static int qtet_sw_get(struct snd_kcontrol *kcontrol,
721 struct snd_ctl_elem_value *ucontrol)
722{
723 struct qtet_kcontrol_private private =
724 qtet_privates[kcontrol->private_value];
725 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
726 ucontrol->value.integer.value[0] =
727 (private.get_register(ice) & private.bit) ? 1 : 0;
728 return 0;
729}
730
731static int qtet_sw_put(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_value *ucontrol)
733{
734 struct qtet_kcontrol_private private =
735 qtet_privates[kcontrol->private_value];
736 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
737 unsigned int old, new;
738 old = private.get_register(ice);
739 if (ucontrol->value.integer.value[0])
740 new = old | private.bit;
741 else
742 new = old & ~private.bit;
743 if (old != new) {
744 private.set_register(ice, new);
745 return 1;
746 }
747 /* no change */
748 return 0;
749}
750
751#define qtet_sw_info snd_ctl_boolean_mono_info
752
753#define QTET_CONTROL(xname, xtype, xpriv) \
754 {.iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
755 .name = xname,\
756 .info = qtet_##xtype##_info,\
757 .get = qtet_sw_get,\
758 .put = qtet_sw_put,\
759 .private_value = xpriv }
760
761static struct snd_kcontrol_new qtet_controls[] __devinitdata = {
762 {
763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 .name = "Master Playback Switch",
765 .info = qtet_sw_info,
766 .get = qtet_mute_get,
767 .put = qtet_mute_put,
768 .private_value = 0
769 },
770 {
771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
772 .name = "Phantom Power",
773 .info = qtet_sw_info,
774 .get = qtet_php_get,
775 .put = qtet_php_put,
776 .private_value = 0
777 },
778 {
779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
780 .name = "Analog In 1/2 Capture Switch",
781 .info = qtet_ain12_enum_info,
782 .get = qtet_ain12_sw_get,
783 .put = qtet_ain12_sw_put,
784 .private_value = 0
785 },
786 QTET_CONTROL("Analog In 3/4 Capture Switch", enum, AIN34_SEL),
787 QTET_CONTROL("PCM In 1/2 Capture Switch", enum, IN12_SEL),
788 QTET_CONTROL("PCM In 3/4 Capture Switch", enum, IN34_SEL),
789 QTET_CONTROL("Coax Output Source", enum, COAX_OUT),
790 QTET_CONTROL("Analog In 1/2 to Monitor 1/2", sw, IN12_MON12),
791 QTET_CONTROL("Analog In 1/2 to Monitor 3/4", sw, IN12_MON34),
792 QTET_CONTROL("Analog In 3/4 to Monitor 1/2", sw, IN34_MON12),
793 QTET_CONTROL("Analog In 3/4 to Monitor 3/4", sw, IN34_MON34),
794 QTET_CONTROL("Output 1/2 to Monitor 3/4", sw, OUT12_MON34),
795 QTET_CONTROL("Output 3/4 to Monitor 1/2", sw, OUT34_MON12),
796};
797
798static char *slave_vols[] __devinitdata = {
799 PCM_12_PLAYBACK_VOLUME,
800 PCM_34_PLAYBACK_VOLUME,
801 NULL
802};
803
804static __devinitdata
805DECLARE_TLV_DB_SCALE(qtet_master_db_scale, -6350, 50, 1);
806
807static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card,
808 const char *name)
809{
810 struct snd_ctl_elem_id sid;
811 memset(&sid, 0, sizeof(sid));
812 /* FIXME: strcpy is bad. */
813 strcpy(sid.name, name);
814 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
815 return snd_ctl_find_id(card, &sid);
816}
817
818static void __devinit add_slaves(struct snd_card *card,
819 struct snd_kcontrol *master, char **list)
820{
821 for (; *list; list++) {
822 struct snd_kcontrol *slave = ctl_find(card, *list);
823 if (slave)
824 snd_ctl_add_slave(master, slave);
825 }
826}
827
828static int __devinit qtet_add_controls(struct snd_ice1712 *ice)
829{
830 struct qtet_spec *spec = ice->spec;
831 int err, i;
832 struct snd_kcontrol *vmaster;
833 err = snd_ice1712_akm4xxx_build_controls(ice);
834 if (err < 0)
835 return err;
836 for (i = 0; i < ARRAY_SIZE(qtet_controls); i++) {
837 err = snd_ctl_add(ice->card,
838 snd_ctl_new1(&qtet_controls[i], ice));
839 if (err < 0)
840 return err;
841 }
842
843 /* Create virtual master control */
844 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
845 qtet_master_db_scale);
846 if (!vmaster)
847 return -ENOMEM;
848 add_slaves(ice->card, vmaster, slave_vols);
849 err = snd_ctl_add(ice->card, vmaster);
850 if (err < 0)
851 return err;
852 /* only capture SPDIF over AK4113 */
853 err = snd_ak4113_build(spec->ak4113,
854 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
855 if (err < 0)
856 return err;
857 return 0;
858}
859
860static inline int qtet_is_spdif_master(struct snd_ice1712 *ice)
861{
862 /* CPLD_SYNC_SEL: 0 = internal, 1 = external (i.e. spdif master) */
863 return (get_cpld(ice) & CPLD_SYNC_SEL) ? 1 : 0;
864}
865
866static unsigned int qtet_get_rate(struct snd_ice1712 *ice)
867{
868 int i;
869 unsigned char result;
870
871 result = get_cpld(ice) & CPLD_CKS_MASK;
872 for (i = 0; i < ARRAY_SIZE(cks_vals); i++)
873 if (cks_vals[i] == result)
874 return qtet_rates[i];
875 return 0;
876}
877
878static int get_cks_val(int rate)
879{
880 int i;
881 for (i = 0; i < ARRAY_SIZE(qtet_rates); i++)
882 if (qtet_rates[i] == rate)
883 return cks_vals[i];
884 return 0;
885}
886
887/* setting new rate */
888static void qtet_set_rate(struct snd_ice1712 *ice, unsigned int rate)
889{
890 unsigned int new;
891 unsigned char val;
892 /* switching ice1724 to external clock - supplied by ext. circuits */
893 val = inb(ICEMT1724(ice, RATE));
894 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
895
896 new = (get_cpld(ice) & ~CPLD_CKS_MASK) | get_cks_val(rate);
897 /* switch to internal clock, drop CPLD_SYNC_SEL */
898 new &= ~CPLD_SYNC_SEL;
899 /* printk(KERN_DEBUG "QT - set_rate: old %x, new %x\n",
900 get_cpld(ice), new); */
901 set_cpld(ice, new);
902}
903
904static inline unsigned char qtet_set_mclk(struct snd_ice1712 *ice,
905 unsigned int rate)
906{
907 /* no change in master clock */
908 return 0;
909}
910
911/* setting clock to external - SPDIF */
912static int qtet_set_spdif_clock(struct snd_ice1712 *ice, int type)
913{
914 unsigned int old, new;
915
916 old = new = get_cpld(ice);
917 new &= ~(CPLD_CKS_MASK | CPLD_WORD_SEL);
918 switch (type) {
919 case EXT_SPDIF_TYPE:
920 new |= CPLD_EXT_SPDIF;
921 break;
922 case EXT_WORDCLOCK_1FS_TYPE:
923 new |= CPLD_EXT_WORDCLOCK_1FS;
924 break;
925 case EXT_WORDCLOCK_256FS_TYPE:
926 new |= CPLD_EXT_WORDCLOCK_256FS;
927 break;
928 default:
929 snd_BUG();
930 }
931 if (old != new) {
932 set_cpld(ice, new);
933 /* changed */
934 return 1;
935 }
936 return 0;
937}
938
939static int qtet_get_spdif_master_type(struct snd_ice1712 *ice)
940{
941 unsigned int val;
942 int result;
943 val = get_cpld(ice);
944 /* checking only rate/clock-related bits */
945 val &= (CPLD_CKS_MASK | CPLD_WORD_SEL | CPLD_SYNC_SEL);
946 if (!(val & CPLD_SYNC_SEL)) {
947 /* switched to internal clock, is not any external type */
948 result = -1;
949 } else {
950 switch (val) {
951 case (CPLD_EXT_SPDIF):
952 result = EXT_SPDIF_TYPE;
953 break;
954 case (CPLD_EXT_WORDCLOCK_1FS):
955 result = EXT_WORDCLOCK_1FS_TYPE;
956 break;
957 case (CPLD_EXT_WORDCLOCK_256FS):
958 result = EXT_WORDCLOCK_256FS_TYPE;
959 break;
960 default:
961 /* undefined combination of external clock setup */
962 snd_BUG();
963 result = 0;
964 }
965 }
966 return result;
967}
968
969/* Called when ak4113 detects change in the input SPDIF stream */
970static void qtet_ak4113_change(struct ak4113 *ak4113, unsigned char c0,
971 unsigned char c1)
972{
973 struct snd_ice1712 *ice = ak4113->change_callback_private;
974 int rate;
975 if ((qtet_get_spdif_master_type(ice) == EXT_SPDIF_TYPE) &&
976 c1) {
977 /* only for SPDIF master mode, rate was changed */
978 rate = snd_ak4113_external_rate(ak4113);
979 /* printk(KERN_DEBUG "ak4113 - input rate changed to %d\n",
980 rate); */
981 qtet_akm_set_rate_val(ice->akm, rate);
982 }
983}
984
985/*
986 * If clock slaved to SPDIF-IN, setting runtime rate
987 * to the detected external rate
988 */
989static void qtet_spdif_in_open(struct snd_ice1712 *ice,
990 struct snd_pcm_substream *substream)
991{
992 struct qtet_spec *spec = ice->spec;
993 struct snd_pcm_runtime *runtime = substream->runtime;
994 int rate;
995
996 if (qtet_get_spdif_master_type(ice) != EXT_SPDIF_TYPE)
997 /* not external SPDIF, no rate limitation */
998 return;
999 /* only external SPDIF can detect incoming sample rate */
1000 rate = snd_ak4113_external_rate(spec->ak4113);
1001 if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
1002 runtime->hw.rate_min = rate;
1003 runtime->hw.rate_max = rate;
1004 }
1005}
1006
1007/*
1008 * initialize the chip
1009 */
1010static int __devinit qtet_init(struct snd_ice1712 *ice)
1011{
1012 static const unsigned char ak4113_init_vals[] = {
1013 /* AK4113_REG_PWRDN */ AK4113_RST | AK4113_PWN |
1014 AK4113_OCKS0 | AK4113_OCKS1,
1015 /* AK4113_REQ_FORMAT */ AK4113_DIF_I24I2S | AK4113_VTX |
1016 AK4113_DEM_OFF | AK4113_DEAU,
1017 /* AK4113_REG_IO0 */ AK4113_OPS2 | AK4113_TXE |
1018 AK4113_XTL_24_576M,
1019 /* AK4113_REG_IO1 */ AK4113_EFH_1024LRCLK | AK4113_IPS(0),
1020 /* AK4113_REG_INT0_MASK */ 0,
1021 /* AK4113_REG_INT1_MASK */ 0,
1022 /* AK4113_REG_DATDTS */ 0,
1023 };
1024 int err;
1025 struct qtet_spec *spec;
1026 struct snd_akm4xxx *ak;
1027 unsigned char val;
1028
1029 /* switching ice1724 to external clock - supplied by ext. circuits */
1030 val = inb(ICEMT1724(ice, RATE));
1031 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1032
1033 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1034 if (!spec)
1035 return -ENOMEM;
1036 /* qtet is clocked by Xilinx array */
1037 ice->hw_rates = &qtet_rates_info;
1038 ice->is_spdif_master = qtet_is_spdif_master;
1039 ice->get_rate = qtet_get_rate;
1040 ice->set_rate = qtet_set_rate;
1041 ice->set_mclk = qtet_set_mclk;
1042 ice->set_spdif_clock = qtet_set_spdif_clock;
1043 ice->get_spdif_master_type = qtet_get_spdif_master_type;
1044 ice->ext_clock_names = ext_clock_names;
1045 ice->ext_clock_count = ARRAY_SIZE(ext_clock_names);
1046 /* since Qtet can detect correct SPDIF-in rate, all streams can be
1047 * limited to this specific rate */
1048 ice->spdif.ops.open = ice->pro_open = qtet_spdif_in_open;
1049 ice->spec = spec;
1050
1051 /* Mute Off */
1052 /* SCR Initialize*/
1053 /* keep codec power down first */
1054 set_scr(ice, SCR_PHP);
1055 udelay(1);
1056 /* codec power up */
1057 set_scr(ice, SCR_PHP | SCR_CODEC_PDN);
1058
1059 /* MCR Initialize */
1060 set_mcr(ice, 0);
1061
1062 /* CPLD Initialize */
1063 set_cpld(ice, 0);
1064
1065
1066 ice->num_total_dacs = 2;
1067 ice->num_total_adcs = 2;
1068
1069 ice->akm = kcalloc(2, sizeof(struct snd_akm4xxx), GFP_KERNEL);
1070 ak = ice->akm;
1071 if (!ak)
1072 return -ENOMEM;
1073 /* only one codec with two chips */
1074 ice->akm_codecs = 1;
1075 err = snd_ice1712_akm4xxx_init(ak, &akm_qtet_dac, NULL, ice);
1076 if (err < 0)
1077 return err;
1078 err = snd_ak4113_create(ice->card,
1079 qtet_ak4113_read,
1080 qtet_ak4113_write,
1081 ak4113_init_vals,
1082 ice, &spec->ak4113);
1083 if (err < 0)
1084 return err;
1085 /* callback for codecs rate setting */
1086 spec->ak4113->change_callback = qtet_ak4113_change;
1087 spec->ak4113->change_callback_private = ice;
1088 /* AK41143 in Quartet can detect external rate correctly
1089 * (i.e. check_flags = 0) */
1090 spec->ak4113->check_flags = 0;
1091
1092 proc_init(ice);
1093
1094 qtet_set_rate(ice, 44100);
1095 return 0;
1096}
1097
1098static unsigned char qtet_eeprom[] __devinitdata = {
1099 [ICE_EEP2_SYSCONF] = 0x28, /* clock 256(24MHz), mpu401, 1xADC,
1100 1xDACs, SPDIF in */
1101 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
1102 [ICE_EEP2_I2S] = 0x78, /* 96k, 24bit, 192k */
1103 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, in, out-ext */
1104 [ICE_EEP2_GPIO_DIR] = 0x00, /* 0-7 inputs, switched to output
1105 only during output operations */
1106 [ICE_EEP2_GPIO_DIR1] = 0xff, /* 8-15 outputs */
1107 [ICE_EEP2_GPIO_DIR2] = 0x00,
1108 [ICE_EEP2_GPIO_MASK] = 0xff, /* changed only for OUT operations */
1109 [ICE_EEP2_GPIO_MASK1] = 0x00,
1110 [ICE_EEP2_GPIO_MASK2] = 0xff,
1111
1112 [ICE_EEP2_GPIO_STATE] = 0x00, /* inputs */
1113 [ICE_EEP2_GPIO_STATE1] = 0x7d, /* all 1, but GPIO_CPLD_RW
1114 and GPIO15 always zero */
1115 [ICE_EEP2_GPIO_STATE2] = 0x00, /* inputs */
1116};
1117
1118/* entry point */
1119struct snd_ice1712_card_info snd_vt1724_qtet_cards[] __devinitdata = {
1120 {
1121 .subvendor = VT1724_SUBDEVICE_QTET,
1122 .name = "Infrasonic Quartet",
1123 .model = "quartet",
1124 .chip_init = qtet_init,
1125 .build_controls = qtet_add_controls,
1126 .eeprom_size = sizeof(qtet_eeprom),
1127 .eeprom_data = qtet_eeprom,
1128 },
1129 { } /* terminator */
1130};
diff --git a/sound/pci/ice1712/quartet.h b/sound/pci/ice1712/quartet.h
new file mode 100644
index 000000000000..80809b72439a
--- /dev/null
+++ b/sound/pci/ice1712/quartet.h
@@ -0,0 +1,10 @@
1#ifndef __SOUND_QTET_H
2#define __SOUND_QTET_H
3
4#define QTET_DEVICE_DESC "{Infrasonic,Quartet},"
5
6#define VT1724_SUBDEVICE_QTET 0x30305349 /* Infrasonic Quartet */
7
8extern struct snd_ice1712_card_info snd_vt1724_qtet_cards[];
9
10#endif /* __SOUND_QTET_H */
diff --git a/sound/pci/ice1712/vt1720_mobo.c b/sound/pci/ice1712/vt1720_mobo.c
index 7f9674b641c0..4c551e147c08 100644
--- a/sound/pci/ice1712/vt1720_mobo.c
+++ b/sound/pci/ice1712/vt1720_mobo.c
@@ -25,7 +25,6 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/slab.h>
29#include <sound/core.h> 28#include <sound/core.h>
30 29
31#include "ice1712.h" 30#include "ice1712.h"
diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c
index 5af9e84456d1..e618f789026e 100644
--- a/sound/pci/ice1712/wtm.c
+++ b/sound/pci/ice1712/wtm.c
@@ -29,7 +29,6 @@
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>
32#include <linux/slab.h>
33#include <sound/core.h> 32#include <sound/core.h>
34 33
35#include "ice1712.h" 34#include "ice1712.h"
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index aac20fb4aad2..6433e65c9507 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -420,7 +420,7 @@ struct intel8x0 {
420 u32 int_sta_mask; /* interrupt status mask */ 420 u32 int_sta_mask; /* interrupt status mask */
421}; 421};
422 422
423static struct pci_device_id snd_intel8x0_ids[] = { 423static DEFINE_PCI_DEVICE_TABLE(snd_intel8x0_ids) = {
424 { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL }, /* 82801AA */ 424 { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL }, /* 82801AA */
425 { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL }, /* 82901AB */ 425 { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL }, /* 82901AB */
426 { PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL }, /* 82801BA */ 426 { PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL }, /* 82801BA */
@@ -2063,6 +2063,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
2063 .type = AC97_TUNE_HP_ONLY 2063 .type = AC97_TUNE_HP_ONLY
2064 }, 2064 },
2065 { 2065 {
2066 .subvendor = 0x161f,
2067 .subdevice = 0x203a,
2068 .name = "Gateway 4525GZ", /* AD1981B */
2069 .type = AC97_TUNE_INV_EAPD
2070 },
2071 {
2066 .subvendor = 0x1734, 2072 .subvendor = 0x1734,
2067 .subdevice = 0x0088, 2073 .subdevice = 0x0088,
2068 .name = "Fujitsu-Siemens D1522", /* AD1981 */ 2074 .name = "Fujitsu-Siemens D1522", /* AD1981 */
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 9e7d12e7673f..13cec1e5ced9 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -219,7 +219,7 @@ struct intel8x0m {
219 unsigned int pcm_pos_shift; 219 unsigned int pcm_pos_shift;
220}; 220};
221 221
222static struct pci_device_id snd_intel8x0m_ids[] = { 222static DEFINE_PCI_DEVICE_TABLE(snd_intel8x0m_ids) = {
223 { PCI_VDEVICE(INTEL, 0x2416), DEVICE_INTEL }, /* 82801AA */ 223 { PCI_VDEVICE(INTEL, 0x2416), DEVICE_INTEL }, /* 82801AA */
224 { PCI_VDEVICE(INTEL, 0x2426), DEVICE_INTEL }, /* 82901AB */ 224 { PCI_VDEVICE(INTEL, 0x2426), DEVICE_INTEL }, /* 82901AB */
225 { PCI_VDEVICE(INTEL, 0x2446), DEVICE_INTEL }, /* 82801BA */ 225 { PCI_VDEVICE(INTEL, 0x2446), DEVICE_INTEL }, /* 82801BA */
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 7cc38a11e997..6d795700be79 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -418,7 +418,7 @@ module_param_array(enable, bool, NULL, 0444);
418MODULE_PARM_DESC(enable, "Enable Korg 1212 soundcard."); 418MODULE_PARM_DESC(enable, "Enable Korg 1212 soundcard.");
419MODULE_AUTHOR("Haroldo Gamal <gamal@alternex.com.br>"); 419MODULE_AUTHOR("Haroldo Gamal <gamal@alternex.com.br>");
420 420
421static struct pci_device_id snd_korg1212_ids[] = { 421static DEFINE_PCI_DEVICE_TABLE(snd_korg1212_ids) = {
422 { 422 {
423 .vendor = 0x10b5, 423 .vendor = 0x10b5,
424 .device = 0x906d, 424 .device = 0x906d,
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index 11b8c6514b3d..ef9af3f4ace2 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -26,6 +26,7 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/slab.h>
29 30
30#include <sound/initval.h> 31#include <sound/initval.h>
31#include <sound/control.h> 32#include <sound/control.h>
@@ -55,7 +56,7 @@ static const char card_name[] = "LX6464ES";
55 56
56#define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056 57#define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
57 58
58static struct pci_device_id snd_lx6464es_ids[] = { 59static DEFINE_PCI_DEVICE_TABLE(snd_lx6464es_ids) = {
59 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES), 60 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
60 .subvendor = PCI_VENDOR_ID_DIGIGRAM, 61 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
61 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM 62 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 75283fbb4b3f..b56e33676780 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -849,6 +849,7 @@ struct snd_m3 {
849 struct snd_kcontrol *master_switch; 849 struct snd_kcontrol *master_switch;
850 struct snd_kcontrol *master_volume; 850 struct snd_kcontrol *master_volume;
851 struct tasklet_struct hwvol_tq; 851 struct tasklet_struct hwvol_tq;
852 unsigned int in_suspend;
852 853
853#ifdef CONFIG_PM 854#ifdef CONFIG_PM
854 u16 *suspend_mem; 855 u16 *suspend_mem;
@@ -861,7 +862,7 @@ struct snd_m3 {
861/* 862/*
862 * pci ids 863 * pci ids
863 */ 864 */
864static struct pci_device_id snd_m3_ids[] = { 865static DEFINE_PCI_DEVICE_TABLE(snd_m3_ids) = {
865 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO_1, PCI_ANY_ID, PCI_ANY_ID, 866 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO_1, PCI_ANY_ID, PCI_ANY_ID,
866 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0}, 867 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
867 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO, PCI_ANY_ID, PCI_ANY_ID, 868 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO, PCI_ANY_ID, PCI_ANY_ID,
@@ -884,6 +885,7 @@ static struct pci_device_id snd_m3_ids[] = {
884MODULE_DEVICE_TABLE(pci, snd_m3_ids); 885MODULE_DEVICE_TABLE(pci, snd_m3_ids);
885 886
886static struct snd_pci_quirk m3_amp_quirk_list[] __devinitdata = { 887static struct snd_pci_quirk m3_amp_quirk_list[] __devinitdata = {
888 SND_PCI_QUIRK(0x0E11, 0x0094, "Compaq Evo N600c", 0x0c),
887 SND_PCI_QUIRK(0x10f7, 0x833e, "Panasonic CF-28", 0x0d), 889 SND_PCI_QUIRK(0x10f7, 0x833e, "Panasonic CF-28", 0x0d),
888 SND_PCI_QUIRK(0x10f7, 0x833d, "Panasonic CF-72", 0x0d), 890 SND_PCI_QUIRK(0x10f7, 0x833d, "Panasonic CF-72", 0x0d),
889 SND_PCI_QUIRK(0x1033, 0x80f1, "NEC LM800J/7", 0x03), 891 SND_PCI_QUIRK(0x1033, 0x80f1, "NEC LM800J/7", 0x03),
@@ -1613,6 +1615,11 @@ static void snd_m3_update_hw_volume(unsigned long private_data)
1613 outb(0x88, chip->iobase + SHADOW_MIX_REG_MASTER); 1615 outb(0x88, chip->iobase + SHADOW_MIX_REG_MASTER);
1614 outb(0x88, chip->iobase + HW_VOL_COUNTER_MASTER); 1616 outb(0x88, chip->iobase + HW_VOL_COUNTER_MASTER);
1615 1617
1618 /* Ignore spurious HV interrupts during suspend / resume, this avoids
1619 mistaking them for a mute button press. */
1620 if (chip->in_suspend)
1621 return;
1622
1616 if (!chip->master_switch || !chip->master_volume) 1623 if (!chip->master_switch || !chip->master_volume)
1617 return; 1624 return;
1618 1625
@@ -2424,6 +2431,7 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2424 if (chip->suspend_mem == NULL) 2431 if (chip->suspend_mem == NULL)
2425 return 0; 2432 return 0;
2426 2433
2434 chip->in_suspend = 1;
2427 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2435 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2428 snd_pcm_suspend_all(chip->pcm); 2436 snd_pcm_suspend_all(chip->pcm);
2429 snd_ac97_suspend(chip->ac97); 2437 snd_ac97_suspend(chip->ac97);
@@ -2497,6 +2505,7 @@ static int m3_resume(struct pci_dev *pci)
2497 snd_m3_hv_init(chip); 2505 snd_m3_hv_init(chip);
2498 2506
2499 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2507 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2508 chip->in_suspend = 0;
2500 return 0; 2509 return 0;
2501} 2510}
2502#endif /* CONFIG_PM */ 2511#endif /* CONFIG_PM */
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index a83d1968a845..3be8f97c8bc0 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -27,6 +27,7 @@
27#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/slab.h>
30 31
31#include <sound/core.h> 32#include <sound/core.h>
32#include <sound/initval.h> 33#include <sound/initval.h>
@@ -60,7 +61,7 @@ MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
60/* 61/*
61 */ 62 */
62 63
63static struct pci_device_id snd_mixart_ids[] = { 64static DEFINE_PCI_DEVICE_TABLE(snd_mixart_ids) = {
64 { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */ 65 { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */
65 { 0, } 66 { 0, }
66}; 67};
@@ -1161,13 +1162,15 @@ static long snd_mixart_BA0_read(struct snd_info_entry *entry, void *file_private
1161 unsigned long count, unsigned long pos) 1162 unsigned long count, unsigned long pos)
1162{ 1163{
1163 struct mixart_mgr *mgr = entry->private_data; 1164 struct mixart_mgr *mgr = entry->private_data;
1165 unsigned long maxsize;
1164 1166
1165 count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ 1167 if (pos >= MIXART_BA0_SIZE)
1166 if(count <= 0)
1167 return 0; 1168 return 0;
1168 if(pos + count > MIXART_BA0_SIZE) 1169 maxsize = MIXART_BA0_SIZE - pos;
1169 count = (long)(MIXART_BA0_SIZE - pos); 1170 if (count > maxsize)
1170 if(copy_to_user_fromio(buf, MIXART_MEM( mgr, pos ), count)) 1171 count = maxsize;
1172 count = count & ~3; /* make sure the read size is a multiple of 4 bytes */
1173 if (copy_to_user_fromio(buf, MIXART_MEM(mgr, pos), count))
1171 return -EFAULT; 1174 return -EFAULT;
1172 return count; 1175 return count;
1173} 1176}
@@ -1180,13 +1183,15 @@ static long snd_mixart_BA1_read(struct snd_info_entry *entry, void *file_private
1180 unsigned long count, unsigned long pos) 1183 unsigned long count, unsigned long pos)
1181{ 1184{
1182 struct mixart_mgr *mgr = entry->private_data; 1185 struct mixart_mgr *mgr = entry->private_data;
1186 unsigned long maxsize;
1183 1187
1184 count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ 1188 if (pos > MIXART_BA1_SIZE)
1185 if(count <= 0)
1186 return 0; 1189 return 0;
1187 if(pos + count > MIXART_BA1_SIZE) 1190 maxsize = MIXART_BA1_SIZE - pos;
1188 count = (long)(MIXART_BA1_SIZE - pos); 1191 if (count > maxsize)
1189 if(copy_to_user_fromio(buf, MIXART_REG( mgr, pos ), count)) 1192 count = maxsize;
1193 count = count & ~3; /* make sure the read size is a multiple of 4 bytes */
1194 if (copy_to_user_fromio(buf, MIXART_REG(mgr, pos), count))
1190 return -EFAULT; 1195 return -EFAULT;
1191 return count; 1196 return count;
1192} 1197}
diff --git a/sound/pci/mixart/mixart_hwdep.c b/sound/pci/mixart/mixart_hwdep.c
index 4cf4cd8c939c..bf2696aa5d49 100644
--- a/sound/pci/mixart/mixart_hwdep.c
+++ b/sound/pci/mixart/mixart_hwdep.c
@@ -24,6 +24,7 @@
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/firmware.h> 25#include <linux/firmware.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/slab.h>
27#include <asm/io.h> 28#include <asm/io.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include "mixart.h" 30#include "mixart.h"
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 97a0731331a1..5a60492ac7b3 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -262,7 +262,7 @@ struct nm256 {
262/* 262/*
263 * PCI ids 263 * PCI ids
264 */ 264 */
265static struct pci_device_id snd_nm256_ids[] = { 265static DEFINE_PCI_DEVICE_TABLE(snd_nm256_ids) = {
266 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO), 0}, 266 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO), 0},
267 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO), 0}, 267 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO), 0},
268 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO), 0}, 268 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO), 0},
diff --git a/sound/pci/oxygen/Makefile b/sound/pci/oxygen/Makefile
index 4ba07d42fd1d..acd8f15f7bff 100644
--- a/sound/pci/oxygen/Makefile
+++ b/sound/pci/oxygen/Makefile
@@ -1,7 +1,8 @@
1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o 1snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o
2snd-hifier-objs := hifier.o 2snd-hifier-objs := hifier.o
3snd-oxygen-objs := oxygen.o 3snd-oxygen-objs := oxygen.o
4snd-virtuoso-objs := virtuoso.o 4snd-virtuoso-objs := virtuoso.o xonar_lib.o \
5 xonar_pcm179x.o xonar_cs43xx.o xonar_wm87x6.o xonar_hdmi.o
5 6
6obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o 7obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o
7obj-$(CONFIG_SND_HIFIER) += snd-hifier.o 8obj-$(CONFIG_SND_HIFIER) += snd-hifier.o
diff --git a/sound/pci/oxygen/cs2000.h b/sound/pci/oxygen/cs2000.h
new file mode 100644
index 000000000000..c3501bdb5edc
--- /dev/null
+++ b/sound/pci/oxygen/cs2000.h
@@ -0,0 +1,83 @@
1#ifndef CS2000_H_INCLUDED
2#define CS2000_H_INCLUDED
3
4#define CS2000_DEV_ID 0x01
5#define CS2000_DEV_CTRL 0x02
6#define CS2000_DEV_CFG_1 0x03
7#define CS2000_DEV_CFG_2 0x04
8#define CS2000_GLOBAL_CFG 0x05
9#define CS2000_RATIO_0 0x06 /* 32 bits, big endian */
10#define CS2000_RATIO_1 0x0a
11#define CS2000_RATIO_2 0x0e
12#define CS2000_RATIO_3 0x12
13#define CS2000_FUN_CFG_1 0x16
14#define CS2000_FUN_CFG_2 0x17
15#define CS2000_FUN_CFG_3 0x1e
16
17/* DEV_ID */
18#define CS2000_DEVICE_MASK 0xf8
19#define CS2000_REVISION_MASK 0x07
20
21/* DEV_CTRL */
22#define CS2000_UNLOCK 0x80
23#define CS2000_AUX_OUT_DIS 0x02
24#define CS2000_CLK_OUT_DIS 0x01
25
26/* DEV_CFG_1 */
27#define CS2000_R_MOD_SEL_MASK 0xe0
28#define CS2000_R_MOD_SEL_1 0x00
29#define CS2000_R_MOD_SEL_2 0x20
30#define CS2000_R_MOD_SEL_4 0x40
31#define CS2000_R_MOD_SEL_8 0x60
32#define CS2000_R_MOD_SEL_1_2 0x80
33#define CS2000_R_MOD_SEL_1_4 0xa0
34#define CS2000_R_MOD_SEL_1_8 0xc0
35#define CS2000_R_MOD_SEL_1_16 0xe0
36#define CS2000_R_SEL_MASK 0x18
37#define CS2000_R_SEL_SHIFT 3
38#define CS2000_AUX_OUT_SRC_MASK 0x06
39#define CS2000_AUX_OUT_SRC_REF_CLK 0x00
40#define CS2000_AUX_OUT_SRC_CLK_IN 0x02
41#define CS2000_AUX_OUT_SRC_CLK_OUT 0x04
42#define CS2000_AUX_OUT_SRC_PLL_LOCK 0x06
43#define CS2000_EN_DEV_CFG_1 0x01
44
45/* DEV_CFG_2 */
46#define CS2000_LOCK_CLK_MASK 0x06
47#define CS2000_LOCK_CLK_SHIFT 1
48#define CS2000_FRAC_N_SRC_MASK 0x01
49#define CS2000_FRAC_N_SRC_STATIC 0x00
50#define CS2000_FRAC_N_SRC_DYNAMIC 0x01
51
52/* GLOBAL_CFG */
53#define CS2000_FREEZE 0x08
54#define CS2000_EN_DEV_CFG_2 0x01
55
56/* FUN_CFG_1 */
57#define CS2000_CLK_SKIP_EN 0x80
58#define CS2000_AUX_LOCK_CFG_MASK 0x40
59#define CS2000_AUX_LOCK_CFG_PP_HIGH 0x00
60#define CS2000_AUX_LOCK_CFG_OD_LOW 0x40
61#define CS2000_REF_CLK_DIV_MASK 0x18
62#define CS2000_REF_CLK_DIV_4 0x00
63#define CS2000_REF_CLK_DIV_2 0x08
64#define CS2000_REF_CLK_DIV_1 0x10
65
66/* FUN_CFG_2 */
67#define CS2000_CLK_OUT_UNL 0x10
68#define CS2000_L_F_RATIO_CFG_MASK 0x08
69#define CS2000_L_F_RATIO_CFG_20_12 0x00
70#define CS2000_L_F_RATIO_CFG_12_20 0x08
71
72/* FUN_CFG_3 */
73#define CS2000_CLK_IN_BW_MASK 0x70
74#define CS2000_CLK_IN_BW_1 0x00
75#define CS2000_CLK_IN_BW_2 0x10
76#define CS2000_CLK_IN_BW_4 0x20
77#define CS2000_CLK_IN_BW_8 0x30
78#define CS2000_CLK_IN_BW_16 0x40
79#define CS2000_CLK_IN_BW_32 0x50
80#define CS2000_CLK_IN_BW_64 0x60
81#define CS2000_CLK_IN_BW_128 0x70
82
83#endif
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index 84ef13183419..5a87d683691f 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -17,6 +17,12 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20/*
21 * CMI8788:
22 *
23 * SPI 0 -> AK4396
24 */
25
20#include <linux/delay.h> 26#include <linux/delay.h>
21#include <linux/pci.h> 27#include <linux/pci.h>
22#include <sound/control.h> 28#include <sound/control.h>
@@ -42,7 +48,7 @@ MODULE_PARM_DESC(id, "ID string");
42module_param_array(enable, bool, NULL, 0444); 48module_param_array(enable, bool, NULL, 0444);
43MODULE_PARM_DESC(enable, "enable card"); 49MODULE_PARM_DESC(enable, "enable card");
44 50
45static struct pci_device_id hifier_ids[] __devinitdata = { 51static DEFINE_PCI_DEVICE_TABLE(hifier_ids) = {
46 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) }, 52 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
47 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) }, 53 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
48 { OXYGEN_PCI_SUBID_BROKEN_EEPROM }, 54 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
@@ -51,23 +57,28 @@ static struct pci_device_id hifier_ids[] __devinitdata = {
51MODULE_DEVICE_TABLE(pci, hifier_ids); 57MODULE_DEVICE_TABLE(pci, hifier_ids);
52 58
53struct hifier_data { 59struct hifier_data {
54 u8 ak4396_ctl2; 60 u8 ak4396_regs[5];
55}; 61};
56 62
57static void ak4396_write(struct oxygen *chip, u8 reg, u8 value) 63static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
58{ 64{
65 struct hifier_data *data = chip->model_data;
66
59 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | 67 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
60 OXYGEN_SPI_DATA_LENGTH_2 | 68 OXYGEN_SPI_DATA_LENGTH_2 |
61 OXYGEN_SPI_CLOCK_160 | 69 OXYGEN_SPI_CLOCK_160 |
62 (0 << OXYGEN_SPI_CODEC_SHIFT) | 70 (0 << OXYGEN_SPI_CODEC_SHIFT) |
63 OXYGEN_SPI_CEN_LATCH_CLOCK_HI, 71 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
64 AK4396_WRITE | (reg << 8) | value); 72 AK4396_WRITE | (reg << 8) | value);
73 data->ak4396_regs[reg] = value;
65} 74}
66 75
67static void update_ak4396_volume(struct oxygen *chip) 76static void ak4396_write_cached(struct oxygen *chip, u8 reg, u8 value)
68{ 77{
69 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]); 78 struct hifier_data *data = chip->model_data;
70 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]); 79
80 if (value != data->ak4396_regs[reg])
81 ak4396_write(chip, reg, value);
71} 82}
72 83
73static void hifier_registers_init(struct oxygen *chip) 84static void hifier_registers_init(struct oxygen *chip)
@@ -75,16 +86,19 @@ static void hifier_registers_init(struct oxygen *chip)
75 struct hifier_data *data = chip->model_data; 86 struct hifier_data *data = chip->model_data;
76 87
77 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 88 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
78 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2); 89 ak4396_write(chip, AK4396_CONTROL_2,
90 data->ak4396_regs[AK4396_CONTROL_2]);
79 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); 91 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
80 update_ak4396_volume(chip); 92 ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
93 ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
81} 94}
82 95
83static void hifier_init(struct oxygen *chip) 96static void hifier_init(struct oxygen *chip)
84{ 97{
85 struct hifier_data *data = chip->model_data; 98 struct hifier_data *data = chip->model_data;
86 99
87 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; 100 data->ak4396_regs[AK4396_CONTROL_2] =
101 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
88 hifier_registers_init(chip); 102 hifier_registers_init(chip);
89 103
90 snd_component_add(chip->card, "AK4396"); 104 snd_component_add(chip->card, "AK4396");
@@ -106,20 +120,29 @@ static void set_ak4396_params(struct oxygen *chip,
106 struct hifier_data *data = chip->model_data; 120 struct hifier_data *data = chip->model_data;
107 u8 value; 121 u8 value;
108 122
109 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; 123 value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
110 if (params_rate(params) <= 54000) 124 if (params_rate(params) <= 54000)
111 value |= AK4396_DFS_NORMAL; 125 value |= AK4396_DFS_NORMAL;
112 else if (params_rate(params) <= 108000) 126 else if (params_rate(params) <= 108000)
113 value |= AK4396_DFS_DOUBLE; 127 value |= AK4396_DFS_DOUBLE;
114 else 128 else
115 value |= AK4396_DFS_QUAD; 129 value |= AK4396_DFS_QUAD;
116 data->ak4396_ctl2 = value;
117 130
118 msleep(1); /* wait for the new MCLK to become stable */ 131 msleep(1); /* wait for the new MCLK to become stable */
119 132
120 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB); 133 if (value != data->ak4396_regs[AK4396_CONTROL_2]) {
121 ak4396_write(chip, AK4396_CONTROL_2, value); 134 ak4396_write(chip, AK4396_CONTROL_1,
122 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 135 AK4396_DIF_24_MSB);
136 ak4396_write(chip, AK4396_CONTROL_2, value);
137 ak4396_write(chip, AK4396_CONTROL_1,
138 AK4396_DIF_24_MSB | AK4396_RSTN);
139 }
140}
141
142static void update_ak4396_volume(struct oxygen *chip)
143{
144 ak4396_write_cached(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
145 ak4396_write_cached(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
123} 146}
124 147
125static void update_ak4396_mute(struct oxygen *chip) 148static void update_ak4396_mute(struct oxygen *chip)
@@ -127,11 +150,10 @@ static void update_ak4396_mute(struct oxygen *chip)
127 struct hifier_data *data = chip->model_data; 150 struct hifier_data *data = chip->model_data;
128 u8 value; 151 u8 value;
129 152
130 value = data->ak4396_ctl2 & ~AK4396_SMUTE; 153 value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_SMUTE;
131 if (chip->dac_mute) 154 if (chip->dac_mute)
132 value |= AK4396_SMUTE; 155 value |= AK4396_SMUTE;
133 data->ak4396_ctl2 = value; 156 ak4396_write_cached(chip, AK4396_CONTROL_2, value);
134 ak4396_write(chip, AK4396_CONTROL_2, value);
135} 157}
136 158
137static void set_cs5340_params(struct oxygen *chip, 159static void set_cs5340_params(struct oxygen *chip,
@@ -141,21 +163,14 @@ static void set_cs5340_params(struct oxygen *chip,
141 163
142static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 164static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
143 165
144static int hifier_control_filter(struct snd_kcontrol_new *template)
145{
146 if (!strcmp(template->name, "Stereo Upmixing"))
147 return 1; /* stereo only - we don't need upmixing */
148 return 0;
149}
150
151static const struct oxygen_model model_hifier = { 166static const struct oxygen_model model_hifier = {
152 .shortname = "C-Media CMI8787", 167 .shortname = "C-Media CMI8787",
153 .longname = "C-Media Oxygen HD Audio", 168 .longname = "C-Media Oxygen HD Audio",
154 .chip = "CMI8788", 169 .chip = "CMI8788",
155 .init = hifier_init, 170 .init = hifier_init,
156 .control_filter = hifier_control_filter,
157 .cleanup = hifier_cleanup, 171 .cleanup = hifier_cleanup,
158 .resume = hifier_resume, 172 .resume = hifier_resume,
173 .get_i2s_mclk = oxygen_default_i2s_mclk,
159 .set_dac_params = set_ak4396_params, 174 .set_dac_params = set_ak4396_params,
160 .set_adc_params = set_cs5340_params, 175 .set_adc_params = set_cs5340_params,
161 .update_dac_volume = update_ak4396_volume, 176 .update_dac_volume = update_ak4396_volume,
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 72db4c39007f..289cb4dacfc7 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -18,6 +18,8 @@
18 */ 18 */
19 19
20/* 20/*
21 * CMI8788:
22 *
21 * SPI 0 -> 1st AK4396 (front) 23 * SPI 0 -> 1st AK4396 (front)
22 * SPI 1 -> 2nd AK4396 (surround) 24 * SPI 1 -> 2nd AK4396 (surround)
23 * SPI 2 -> 3rd AK4396 (center/LFE) 25 * SPI 2 -> 3rd AK4396 (center/LFE)
@@ -27,6 +29,10 @@
27 * GPIO 0 -> DFS0 of AK5385 29 * GPIO 0 -> DFS0 of AK5385
28 * GPIO 1 -> DFS1 of AK5385 30 * GPIO 1 -> DFS1 of AK5385
29 * GPIO 8 -> enable headphone amplifier on HT-Omega models 31 * GPIO 8 -> enable headphone amplifier on HT-Omega models
32 *
33 * CM9780:
34 *
35 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
30 */ 36 */
31 37
32#include <linux/delay.h> 38#include <linux/delay.h>
@@ -66,7 +72,7 @@ enum {
66 MODEL_CLARO_HALO, /* HT-Omega Claro halo */ 72 MODEL_CLARO_HALO, /* HT-Omega Claro halo */
67}; 73};
68 74
69static struct pci_device_id oxygen_ids[] __devinitdata = { 75static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
70 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF }, 76 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data = MODEL_CMEDIA_REF },
71 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF }, 77 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data = MODEL_CMEDIA_REF },
72 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF }, 78 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data = MODEL_CMEDIA_REF },
@@ -91,8 +97,8 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
91#define GPIO_CLARO_HP 0x0100 97#define GPIO_CLARO_HP 0x0100
92 98
93struct generic_data { 99struct generic_data {
94 u8 ak4396_ctl2; 100 u8 ak4396_regs[4][5];
95 u16 saved_wm8785_registers[2]; 101 u16 wm8785_regs[3];
96}; 102};
97 103
98static void ak4396_write(struct oxygen *chip, unsigned int codec, 104static void ak4396_write(struct oxygen *chip, unsigned int codec,
@@ -102,12 +108,24 @@ static void ak4396_write(struct oxygen *chip, unsigned int codec,
102 static const u8 codec_spi_map[4] = { 108 static const u8 codec_spi_map[4] = {
103 0, 1, 2, 4 109 0, 1, 2, 4
104 }; 110 };
111 struct generic_data *data = chip->model_data;
112
105 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | 113 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
106 OXYGEN_SPI_DATA_LENGTH_2 | 114 OXYGEN_SPI_DATA_LENGTH_2 |
107 OXYGEN_SPI_CLOCK_160 | 115 OXYGEN_SPI_CLOCK_160 |
108 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | 116 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
109 OXYGEN_SPI_CEN_LATCH_CLOCK_HI, 117 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
110 AK4396_WRITE | (reg << 8) | value); 118 AK4396_WRITE | (reg << 8) | value);
119 data->ak4396_regs[codec][reg] = value;
120}
121
122static void ak4396_write_cached(struct oxygen *chip, unsigned int codec,
123 u8 reg, u8 value)
124{
125 struct generic_data *data = chip->model_data;
126
127 if (value != data->ak4396_regs[codec][reg])
128 ak4396_write(chip, codec, reg, value);
111} 129}
112 130
113static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) 131static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
@@ -120,20 +138,8 @@ static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
120 (3 << OXYGEN_SPI_CODEC_SHIFT) | 138 (3 << OXYGEN_SPI_CODEC_SHIFT) |
121 OXYGEN_SPI_CEN_LATCH_CLOCK_LO, 139 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
122 (reg << 9) | value); 140 (reg << 9) | value);
123 if (reg < ARRAY_SIZE(data->saved_wm8785_registers)) 141 if (reg < ARRAY_SIZE(data->wm8785_regs))
124 data->saved_wm8785_registers[reg] = value; 142 data->wm8785_regs[reg] = value;
125}
126
127static void update_ak4396_volume(struct oxygen *chip)
128{
129 unsigned int i;
130
131 for (i = 0; i < 4; ++i) {
132 ak4396_write(chip, i,
133 AK4396_LCH_ATT, chip->dac_volume[i * 2]);
134 ak4396_write(chip, i,
135 AK4396_RCH_ATT, chip->dac_volume[i * 2 + 1]);
136 }
137} 143}
138 144
139static void ak4396_registers_init(struct oxygen *chip) 145static void ak4396_registers_init(struct oxygen *chip)
@@ -142,21 +148,25 @@ static void ak4396_registers_init(struct oxygen *chip)
142 unsigned int i; 148 unsigned int i;
143 149
144 for (i = 0; i < 4; ++i) { 150 for (i = 0; i < 4; ++i) {
145 ak4396_write(chip, i, 151 ak4396_write(chip, i, AK4396_CONTROL_1,
146 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 152 AK4396_DIF_24_MSB | AK4396_RSTN);
147 ak4396_write(chip, i, 153 ak4396_write(chip, i, AK4396_CONTROL_2,
148 AK4396_CONTROL_2, data->ak4396_ctl2); 154 data->ak4396_regs[0][AK4396_CONTROL_2]);
149 ak4396_write(chip, i, 155 ak4396_write(chip, i, AK4396_CONTROL_3,
150 AK4396_CONTROL_3, AK4396_PCM); 156 AK4396_PCM);
157 ak4396_write(chip, i, AK4396_LCH_ATT,
158 chip->dac_volume[i * 2]);
159 ak4396_write(chip, i, AK4396_RCH_ATT,
160 chip->dac_volume[i * 2 + 1]);
151 } 161 }
152 update_ak4396_volume(chip);
153} 162}
154 163
155static void ak4396_init(struct oxygen *chip) 164static void ak4396_init(struct oxygen *chip)
156{ 165{
157 struct generic_data *data = chip->model_data; 166 struct generic_data *data = chip->model_data;
158 167
159 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; 168 data->ak4396_regs[0][AK4396_CONTROL_2] =
169 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
160 ak4396_registers_init(chip); 170 ak4396_registers_init(chip);
161 snd_component_add(chip->card, "AK4396"); 171 snd_component_add(chip->card, "AK4396");
162} 172}
@@ -173,17 +183,17 @@ static void wm8785_registers_init(struct oxygen *chip)
173 struct generic_data *data = chip->model_data; 183 struct generic_data *data = chip->model_data;
174 184
175 wm8785_write(chip, WM8785_R7, 0); 185 wm8785_write(chip, WM8785_R7, 0);
176 wm8785_write(chip, WM8785_R0, data->saved_wm8785_registers[0]); 186 wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]);
177 wm8785_write(chip, WM8785_R1, data->saved_wm8785_registers[1]); 187 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
178} 188}
179 189
180static void wm8785_init(struct oxygen *chip) 190static void wm8785_init(struct oxygen *chip)
181{ 191{
182 struct generic_data *data = chip->model_data; 192 struct generic_data *data = chip->model_data;
183 193
184 data->saved_wm8785_registers[0] = WM8785_MCR_SLAVE | 194 data->wm8785_regs[0] =
185 WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; 195 WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
186 data->saved_wm8785_registers[1] = WM8785_WL_24; 196 data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL;
187 wm8785_registers_init(chip); 197 wm8785_registers_init(chip);
188 snd_component_add(chip->card, "WM8785"); 198 snd_component_add(chip->card, "WM8785");
189} 199}
@@ -264,24 +274,36 @@ static void set_ak4396_params(struct oxygen *chip,
264 unsigned int i; 274 unsigned int i;
265 u8 value; 275 u8 value;
266 276
267 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; 277 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
268 if (params_rate(params) <= 54000) 278 if (params_rate(params) <= 54000)
269 value |= AK4396_DFS_NORMAL; 279 value |= AK4396_DFS_NORMAL;
270 else if (params_rate(params) <= 108000) 280 else if (params_rate(params) <= 108000)
271 value |= AK4396_DFS_DOUBLE; 281 value |= AK4396_DFS_DOUBLE;
272 else 282 else
273 value |= AK4396_DFS_QUAD; 283 value |= AK4396_DFS_QUAD;
274 data->ak4396_ctl2 = value;
275 284
276 msleep(1); /* wait for the new MCLK to become stable */ 285 msleep(1); /* wait for the new MCLK to become stable */
277 286
287 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
288 for (i = 0; i < 4; ++i) {
289 ak4396_write(chip, i, AK4396_CONTROL_1,
290 AK4396_DIF_24_MSB);
291 ak4396_write(chip, i, AK4396_CONTROL_2, value);
292 ak4396_write(chip, i, AK4396_CONTROL_1,
293 AK4396_DIF_24_MSB | AK4396_RSTN);
294 }
295 }
296}
297
298static void update_ak4396_volume(struct oxygen *chip)
299{
300 unsigned int i;
301
278 for (i = 0; i < 4; ++i) { 302 for (i = 0; i < 4; ++i) {
279 ak4396_write(chip, i, 303 ak4396_write_cached(chip, i, AK4396_LCH_ATT,
280 AK4396_CONTROL_1, AK4396_DIF_24_MSB); 304 chip->dac_volume[i * 2]);
281 ak4396_write(chip, i, 305 ak4396_write_cached(chip, i, AK4396_RCH_ATT,
282 AK4396_CONTROL_2, value); 306 chip->dac_volume[i * 2 + 1]);
283 ak4396_write(chip, i,
284 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
285 } 307 }
286} 308}
287 309
@@ -291,21 +313,19 @@ static void update_ak4396_mute(struct oxygen *chip)
291 unsigned int i; 313 unsigned int i;
292 u8 value; 314 u8 value;
293 315
294 value = data->ak4396_ctl2 & ~AK4396_SMUTE; 316 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
295 if (chip->dac_mute) 317 if (chip->dac_mute)
296 value |= AK4396_SMUTE; 318 value |= AK4396_SMUTE;
297 data->ak4396_ctl2 = value;
298 for (i = 0; i < 4; ++i) 319 for (i = 0; i < 4; ++i)
299 ak4396_write(chip, i, AK4396_CONTROL_2, value); 320 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
300} 321}
301 322
302static void set_wm8785_params(struct oxygen *chip, 323static void set_wm8785_params(struct oxygen *chip,
303 struct snd_pcm_hw_params *params) 324 struct snd_pcm_hw_params *params)
304{ 325{
326 struct generic_data *data = chip->model_data;
305 unsigned int value; 327 unsigned int value;
306 328
307 wm8785_write(chip, WM8785_R7, 0);
308
309 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; 329 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST;
310 if (params_rate(params) <= 48000) 330 if (params_rate(params) <= 48000)
311 value |= WM8785_OSR_SINGLE; 331 value |= WM8785_OSR_SINGLE;
@@ -313,13 +333,11 @@ static void set_wm8785_params(struct oxygen *chip,
313 value |= WM8785_OSR_DOUBLE; 333 value |= WM8785_OSR_DOUBLE;
314 else 334 else
315 value |= WM8785_OSR_QUAD; 335 value |= WM8785_OSR_QUAD;
316 wm8785_write(chip, WM8785_R0, value); 336 if (value != data->wm8785_regs[0]) {
317 337 wm8785_write(chip, WM8785_R7, 0);
318 if (snd_pcm_format_width(params_format(params)) <= 16) 338 wm8785_write(chip, WM8785_R0, value);
319 value = WM8785_WL_16; 339 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
320 else 340 }
321 value = WM8785_WL_24;
322 wm8785_write(chip, WM8785_R1, value);
323} 341}
324 342
325static void set_ak5385_params(struct oxygen *chip, 343static void set_ak5385_params(struct oxygen *chip,
@@ -337,6 +355,134 @@ static void set_ak5385_params(struct oxygen *chip,
337 value, GPIO_AK5385_DFS_MASK); 355 value, GPIO_AK5385_DFS_MASK);
338} 356}
339 357
358static int rolloff_info(struct snd_kcontrol *ctl,
359 struct snd_ctl_elem_info *info)
360{
361 static const char *const names[2] = {
362 "Sharp Roll-off", "Slow Roll-off"
363 };
364
365 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
366 info->count = 1;
367 info->value.enumerated.items = 2;
368 if (info->value.enumerated.item >= 2)
369 info->value.enumerated.item = 1;
370 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
371 return 0;
372}
373
374static int rolloff_get(struct snd_kcontrol *ctl,
375 struct snd_ctl_elem_value *value)
376{
377 struct oxygen *chip = ctl->private_data;
378 struct generic_data *data = chip->model_data;
379
380 value->value.enumerated.item[0] =
381 (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0;
382 return 0;
383}
384
385static int rolloff_put(struct snd_kcontrol *ctl,
386 struct snd_ctl_elem_value *value)
387{
388 struct oxygen *chip = ctl->private_data;
389 struct generic_data *data = chip->model_data;
390 unsigned int i;
391 int changed;
392 u8 reg;
393
394 mutex_lock(&chip->mutex);
395 reg = data->ak4396_regs[0][AK4396_CONTROL_2];
396 if (value->value.enumerated.item[0])
397 reg |= AK4396_SLOW;
398 else
399 reg &= ~AK4396_SLOW;
400 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
401 if (changed) {
402 for (i = 0; i < 4; ++i)
403 ak4396_write(chip, i, AK4396_CONTROL_2, reg);
404 }
405 mutex_unlock(&chip->mutex);
406 return changed;
407}
408
409static const struct snd_kcontrol_new rolloff_control = {
410 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
411 .name = "DAC Filter Playback Enum",
412 .info = rolloff_info,
413 .get = rolloff_get,
414 .put = rolloff_put,
415};
416
417static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
418{
419 static const char *const names[2] = {
420 "None", "High-pass Filter"
421 };
422
423 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
424 info->count = 1;
425 info->value.enumerated.items = 2;
426 if (info->value.enumerated.item >= 2)
427 info->value.enumerated.item = 1;
428 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
429 return 0;
430}
431
432static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
433{
434 struct oxygen *chip = ctl->private_data;
435 struct generic_data *data = chip->model_data;
436
437 value->value.enumerated.item[0] =
438 (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0;
439 return 0;
440}
441
442static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
443{
444 struct oxygen *chip = ctl->private_data;
445 struct generic_data *data = chip->model_data;
446 unsigned int reg;
447 int changed;
448
449 mutex_lock(&chip->mutex);
450 reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL);
451 if (value->value.enumerated.item[0])
452 reg |= WM8785_HPFR | WM8785_HPFL;
453 changed = reg != data->wm8785_regs[WM8785_R2];
454 if (changed)
455 wm8785_write(chip, WM8785_R2, reg);
456 mutex_unlock(&chip->mutex);
457 return changed;
458}
459
460static const struct snd_kcontrol_new hpf_control = {
461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
462 .name = "ADC Filter Capture Enum",
463 .info = hpf_info,
464 .get = hpf_get,
465 .put = hpf_put,
466};
467
468static int generic_mixer_init(struct oxygen *chip)
469{
470 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
471}
472
473static int generic_wm8785_mixer_init(struct oxygen *chip)
474{
475 int err;
476
477 err = generic_mixer_init(chip);
478 if (err < 0)
479 return err;
480 err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip));
481 if (err < 0)
482 return err;
483 return 0;
484}
485
340static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 486static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
341 487
342static const struct oxygen_model model_generic = { 488static const struct oxygen_model model_generic = {
@@ -344,8 +490,10 @@ static const struct oxygen_model model_generic = {
344 .longname = "C-Media Oxygen HD Audio", 490 .longname = "C-Media Oxygen HD Audio",
345 .chip = "CMI8788", 491 .chip = "CMI8788",
346 .init = generic_init, 492 .init = generic_init,
493 .mixer_init = generic_wm8785_mixer_init,
347 .cleanup = generic_cleanup, 494 .cleanup = generic_cleanup,
348 .resume = generic_resume, 495 .resume = generic_resume,
496 .get_i2s_mclk = oxygen_default_i2s_mclk,
349 .set_dac_params = set_ak4396_params, 497 .set_dac_params = set_ak4396_params,
350 .set_adc_params = set_wm8785_params, 498 .set_adc_params = set_wm8785_params,
351 .update_dac_volume = update_ak4396_volume, 499 .update_dac_volume = update_ak4396_volume,
@@ -374,6 +522,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
374 switch (id->driver_data) { 522 switch (id->driver_data) {
375 case MODEL_MERIDIAN: 523 case MODEL_MERIDIAN:
376 chip->model.init = meridian_init; 524 chip->model.init = meridian_init;
525 chip->model.mixer_init = generic_mixer_init;
377 chip->model.resume = meridian_resume; 526 chip->model.resume = meridian_resume;
378 chip->model.set_adc_params = set_ak5385_params; 527 chip->model.set_adc_params = set_ak5385_params;
379 chip->model.device_config = PLAYBACK_0_TO_I2S | 528 chip->model.device_config = PLAYBACK_0_TO_I2S |
@@ -389,6 +538,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
389 break; 538 break;
390 case MODEL_CLARO_HALO: 539 case MODEL_CLARO_HALO:
391 chip->model.init = claro_halo_init; 540 chip->model.init = claro_halo_init;
541 chip->model.mixer_init = generic_mixer_init;
392 chip->model.cleanup = claro_cleanup; 542 chip->model.cleanup = claro_cleanup;
393 chip->model.suspend = claro_suspend; 543 chip->model.suspend = claro_suspend;
394 chip->model.resume = claro_resume; 544 chip->model.resume = claro_resume;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index bd615dbffadb..6147216af744 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -78,12 +78,15 @@ struct oxygen_model {
78 void (*resume)(struct oxygen *chip); 78 void (*resume)(struct oxygen *chip);
79 void (*pcm_hardware_filter)(unsigned int channel, 79 void (*pcm_hardware_filter)(unsigned int channel,
80 struct snd_pcm_hardware *hardware); 80 struct snd_pcm_hardware *hardware);
81 unsigned int (*get_i2s_mclk)(struct oxygen *chip, unsigned int channel,
82 struct snd_pcm_hw_params *hw_params);
81 void (*set_dac_params)(struct oxygen *chip, 83 void (*set_dac_params)(struct oxygen *chip,
82 struct snd_pcm_hw_params *params); 84 struct snd_pcm_hw_params *params);
83 void (*set_adc_params)(struct oxygen *chip, 85 void (*set_adc_params)(struct oxygen *chip,
84 struct snd_pcm_hw_params *params); 86 struct snd_pcm_hw_params *params);
85 void (*update_dac_volume)(struct oxygen *chip); 87 void (*update_dac_volume)(struct oxygen *chip);
86 void (*update_dac_mute)(struct oxygen *chip); 88 void (*update_dac_mute)(struct oxygen *chip);
89 void (*update_center_lfe_mix)(struct oxygen *chip, bool mixed);
87 void (*gpio_changed)(struct oxygen *chip); 90 void (*gpio_changed)(struct oxygen *chip);
88 void (*uart_input)(struct oxygen *chip); 91 void (*uart_input)(struct oxygen *chip);
89 void (*ac97_switch)(struct oxygen *chip, 92 void (*ac97_switch)(struct oxygen *chip,
@@ -162,6 +165,8 @@ void oxygen_update_spdif_source(struct oxygen *chip);
162/* oxygen_pcm.c */ 165/* oxygen_pcm.c */
163 166
164int oxygen_pcm_init(struct oxygen *chip); 167int oxygen_pcm_init(struct oxygen *chip);
168unsigned int oxygen_default_i2s_mclk(struct oxygen *chip, unsigned int channel,
169 struct snd_pcm_hw_params *hw_params);
165 170
166/* oxygen_io.c */ 171/* oxygen_io.c */
167 172
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 9a8936e20744..fad03d64e3ad 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/slab.h>
24#include <sound/ac97_codec.h> 25#include <sound/ac97_codec.h>
25#include <sound/asoundef.h> 26#include <sound/asoundef.h>
26#include <sound/core.h> 27#include <sound/core.h>
@@ -278,7 +279,11 @@ oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
278static void oxygen_restore_eeprom(struct oxygen *chip, 279static void oxygen_restore_eeprom(struct oxygen *chip,
279 const struct pci_device_id *id) 280 const struct pci_device_id *id)
280{ 281{
281 if (oxygen_read_eeprom(chip, 0) != OXYGEN_EEPROM_ID) { 282 u16 eeprom_id;
283
284 eeprom_id = oxygen_read_eeprom(chip, 0);
285 if (eeprom_id != OXYGEN_EEPROM_ID &&
286 (eeprom_id != 0xffff || id->subdevice != 0x8788)) {
282 /* 287 /*
283 * This function gets called only when a known card model has 288 * This function gets called only when a known card model has
284 * been detected, i.e., we know there is a valid subsystem 289 * been detected, i.e., we know there is a valid subsystem
@@ -303,6 +308,28 @@ static void oxygen_restore_eeprom(struct oxygen *chip,
303 } 308 }
304} 309}
305 310
311static void pci_bridge_magic(void)
312{
313 struct pci_dev *pci = NULL;
314 u32 tmp;
315
316 for (;;) {
317 /* If there is any Pericom PI7C9X110 PCI-E/PCI bridge ... */
318 pci = pci_get_device(0x12d8, 0xe110, pci);
319 if (!pci)
320 break;
321 /*
322 * ... configure its secondary internal arbiter to park to
323 * the secondary port, instead of to the last master.
324 */
325 if (!pci_read_config_dword(pci, 0x40, &tmp)) {
326 tmp |= 1;
327 pci_write_config_dword(pci, 0x40, tmp);
328 }
329 /* Why? Try asking C-Media. */
330 }
331}
332
306static void oxygen_init(struct oxygen *chip) 333static void oxygen_init(struct oxygen *chip)
307{ 334{
308 unsigned int i; 335 unsigned int i;
@@ -581,6 +608,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
581 snd_card_set_dev(card, &pci->dev); 608 snd_card_set_dev(card, &pci->dev);
582 card->private_free = oxygen_card_free; 609 card->private_free = oxygen_card_free;
583 610
611 pci_bridge_magic();
584 oxygen_init(chip); 612 oxygen_init(chip);
585 chip->model.init(chip); 613 chip->model.init(chip);
586 614
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 5401c547c4e3..f375b8a27862 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -99,11 +99,15 @@ static int dac_mute_put(struct snd_kcontrol *ctl,
99 99
100static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) 100static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
101{ 101{
102 static const char *const names[3] = { 102 static const char *const names[5] = {
103 "Front", "Front+Surround", "Front+Surround+Back" 103 "Front",
104 "Front+Surround",
105 "Front+Surround+Back",
106 "Front+Surround+Center/LFE",
107 "Front+Surround+Center/LFE+Back",
104 }; 108 };
105 struct oxygen *chip = ctl->private_data; 109 struct oxygen *chip = ctl->private_data;
106 unsigned int count = 2 + (chip->model.dac_channels == 8); 110 unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3;
107 111
108 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 112 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
109 info->count = 1; 113 info->count = 1;
@@ -127,7 +131,7 @@ static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
127void oxygen_update_dac_routing(struct oxygen *chip) 131void oxygen_update_dac_routing(struct oxygen *chip)
128{ 132{
129 /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */ 133 /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */
130 static const unsigned int reg_values[3] = { 134 static const unsigned int reg_values[5] = {
131 /* stereo -> front */ 135 /* stereo -> front */
132 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | 136 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
133 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | 137 (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
@@ -143,6 +147,16 @@ void oxygen_update_dac_routing(struct oxygen *chip)
143 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | 147 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
144 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | 148 (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
145 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), 149 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
150 /* stereo -> front+surround+center/LFE */
151 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
152 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
153 (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
154 (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
155 /* stereo -> front+surround+center/LFE+back */
156 (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) |
157 (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) |
158 (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) |
159 (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT),
146 }; 160 };
147 u8 channels; 161 u8 channels;
148 unsigned int reg_value; 162 unsigned int reg_value;
@@ -167,22 +181,23 @@ void oxygen_update_dac_routing(struct oxygen *chip)
167 OXYGEN_PLAY_DAC1_SOURCE_MASK | 181 OXYGEN_PLAY_DAC1_SOURCE_MASK |
168 OXYGEN_PLAY_DAC2_SOURCE_MASK | 182 OXYGEN_PLAY_DAC2_SOURCE_MASK |
169 OXYGEN_PLAY_DAC3_SOURCE_MASK); 183 OXYGEN_PLAY_DAC3_SOURCE_MASK);
184 if (chip->model.update_center_lfe_mix)
185 chip->model.update_center_lfe_mix(chip, chip->dac_routing > 2);
170} 186}
171 187
172static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) 188static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
173{ 189{
174 struct oxygen *chip = ctl->private_data; 190 struct oxygen *chip = ctl->private_data;
175 unsigned int count = 2 + (chip->model.dac_channels == 8); 191 unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3;
176 int changed; 192 int changed;
177 193
194 if (value->value.enumerated.item[0] >= count)
195 return -EINVAL;
178 mutex_lock(&chip->mutex); 196 mutex_lock(&chip->mutex);
179 changed = value->value.enumerated.item[0] != chip->dac_routing; 197 changed = value->value.enumerated.item[0] != chip->dac_routing;
180 if (changed) { 198 if (changed) {
181 chip->dac_routing = min(value->value.enumerated.item[0], 199 chip->dac_routing = value->value.enumerated.item[0];
182 count - 1);
183 spin_lock_irq(&chip->reg_lock);
184 oxygen_update_dac_routing(chip); 200 oxygen_update_dac_routing(chip);
185 spin_unlock_irq(&chip->reg_lock);
186 } 201 }
187 mutex_unlock(&chip->mutex); 202 mutex_unlock(&chip->mutex);
188 return changed; 203 return changed;
@@ -790,7 +805,7 @@ static const struct {
790 .controls = { 805 .controls = {
791 { 806 {
792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
793 .name = "Analog Input Monitor Switch", 808 .name = "Analog Input Monitor Playback Switch",
794 .info = snd_ctl_boolean_mono_info, 809 .info = snd_ctl_boolean_mono_info,
795 .get = monitor_get, 810 .get = monitor_get,
796 .put = monitor_put, 811 .put = monitor_put,
@@ -798,7 +813,7 @@ static const struct {
798 }, 813 },
799 { 814 {
800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
801 .name = "Analog Input Monitor Volume", 816 .name = "Analog Input Monitor Playback Volume",
802 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 817 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
803 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 818 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
804 .info = monitor_volume_info, 819 .info = monitor_volume_info,
@@ -815,7 +830,7 @@ static const struct {
815 .controls = { 830 .controls = {
816 { 831 {
817 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 832 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
818 .name = "Analog Input Monitor Switch", 833 .name = "Analog Input Monitor Playback Switch",
819 .info = snd_ctl_boolean_mono_info, 834 .info = snd_ctl_boolean_mono_info,
820 .get = monitor_get, 835 .get = monitor_get,
821 .put = monitor_put, 836 .put = monitor_put,
@@ -823,7 +838,7 @@ static const struct {
823 }, 838 },
824 { 839 {
825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 .name = "Analog Input Monitor Volume", 841 .name = "Analog Input Monitor Playback Volume",
827 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 842 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
828 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 843 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
829 .info = monitor_volume_info, 844 .info = monitor_volume_info,
@@ -840,7 +855,7 @@ static const struct {
840 .controls = { 855 .controls = {
841 { 856 {
842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 857 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
843 .name = "Analog Input Monitor Switch", 858 .name = "Analog Input Monitor Playback Switch",
844 .index = 1, 859 .index = 1,
845 .info = snd_ctl_boolean_mono_info, 860 .info = snd_ctl_boolean_mono_info,
846 .get = monitor_get, 861 .get = monitor_get,
@@ -849,7 +864,7 @@ static const struct {
849 }, 864 },
850 { 865 {
851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .name = "Analog Input Monitor Volume", 867 .name = "Analog Input Monitor Playback Volume",
853 .index = 1, 868 .index = 1,
854 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 869 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
855 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 870 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
@@ -867,7 +882,7 @@ static const struct {
867 .controls = { 882 .controls = {
868 { 883 {
869 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
870 .name = "Digital Input Monitor Switch", 885 .name = "Digital Input Monitor Playback Switch",
871 .info = snd_ctl_boolean_mono_info, 886 .info = snd_ctl_boolean_mono_info,
872 .get = monitor_get, 887 .get = monitor_get,
873 .put = monitor_put, 888 .put = monitor_put,
@@ -875,7 +890,7 @@ static const struct {
875 }, 890 },
876 { 891 {
877 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 892 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
878 .name = "Digital Input Monitor Volume", 893 .name = "Digital Input Monitor Playback Volume",
879 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 894 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
880 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 895 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
881 .info = monitor_volume_info, 896 .info = monitor_volume_info,
@@ -954,6 +969,9 @@ static int add_controls(struct oxygen *chip,
954 if (err == 1) 969 if (err == 1)
955 continue; 970 continue;
956 } 971 }
972 if (!strcmp(template.name, "Stereo Upmixing") &&
973 chip->model.dac_channels == 2)
974 continue;
957 if (!strcmp(template.name, "Master Playback Volume") && 975 if (!strcmp(template.name, "Master Playback Volume") &&
958 chip->model.dac_tlv) { 976 chip->model.dac_tlv) {
959 template.tlv.p = chip->model.dac_tlv; 977 template.tlv.p = chip->model.dac_tlv;
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index ef2345d82b86..9dff6954c397 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -271,13 +271,16 @@ static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params)
271 } 271 }
272} 272}
273 273
274static unsigned int oxygen_i2s_mclk(struct snd_pcm_hw_params *hw_params) 274unsigned int oxygen_default_i2s_mclk(struct oxygen *chip,
275 unsigned int channel,
276 struct snd_pcm_hw_params *hw_params)
275{ 277{
276 if (params_rate(hw_params) <= 96000) 278 if (params_rate(hw_params) <= 96000)
277 return OXYGEN_I2S_MCLK_256; 279 return OXYGEN_I2S_MCLK_256;
278 else 280 else
279 return OXYGEN_I2S_MCLK_128; 281 return OXYGEN_I2S_MCLK_128;
280} 282}
283EXPORT_SYMBOL(oxygen_default_i2s_mclk);
281 284
282static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params) 285static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params)
283{ 286{
@@ -354,7 +357,7 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
354 OXYGEN_REC_FORMAT_A_MASK); 357 OXYGEN_REC_FORMAT_A_MASK);
355 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, 358 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT,
356 oxygen_rate(hw_params) | 359 oxygen_rate(hw_params) |
357 oxygen_i2s_mclk(hw_params) | 360 chip->model.get_i2s_mclk(chip, PCM_A, hw_params) |
358 chip->model.adc_i2s_format | 361 chip->model.adc_i2s_format |
359 oxygen_i2s_bits(hw_params), 362 oxygen_i2s_bits(hw_params),
360 OXYGEN_I2S_RATE_MASK | 363 OXYGEN_I2S_RATE_MASK |
@@ -390,7 +393,8 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
390 if (!is_ac97) 393 if (!is_ac97)
391 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, 394 oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT,
392 oxygen_rate(hw_params) | 395 oxygen_rate(hw_params) |
393 oxygen_i2s_mclk(hw_params) | 396 chip->model.get_i2s_mclk(chip, PCM_B,
397 hw_params) |
394 chip->model.adc_i2s_format | 398 chip->model.adc_i2s_format |
395 oxygen_i2s_bits(hw_params), 399 oxygen_i2s_bits(hw_params),
396 OXYGEN_I2S_RATE_MASK | 400 OXYGEN_I2S_RATE_MASK |
@@ -435,6 +439,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
435 if (err < 0) 439 if (err < 0)
436 return err; 440 return err;
437 441
442 mutex_lock(&chip->mutex);
438 spin_lock_irq(&chip->reg_lock); 443 spin_lock_irq(&chip->reg_lock);
439 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, 444 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
440 OXYGEN_SPDIF_OUT_ENABLE); 445 OXYGEN_SPDIF_OUT_ENABLE);
@@ -446,6 +451,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
446 OXYGEN_SPDIF_OUT_RATE_MASK); 451 OXYGEN_SPDIF_OUT_RATE_MASK);
447 oxygen_update_spdif_source(chip); 452 oxygen_update_spdif_source(chip);
448 spin_unlock_irq(&chip->reg_lock); 453 spin_unlock_irq(&chip->reg_lock);
454 mutex_unlock(&chip->mutex);
449 return 0; 455 return 0;
450} 456}
451 457
@@ -459,6 +465,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
459 if (err < 0) 465 if (err < 0)
460 return err; 466 return err;
461 467
468 mutex_lock(&chip->mutex);
462 spin_lock_irq(&chip->reg_lock); 469 spin_lock_irq(&chip->reg_lock);
463 oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, 470 oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS,
464 oxygen_play_channels(hw_params), 471 oxygen_play_channels(hw_params),
@@ -469,18 +476,18 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
469 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, 476 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
470 oxygen_rate(hw_params) | 477 oxygen_rate(hw_params) |
471 chip->model.dac_i2s_format | 478 chip->model.dac_i2s_format |
472 oxygen_i2s_mclk(hw_params) | 479 chip->model.get_i2s_mclk(chip, PCM_MULTICH,
480 hw_params) |
473 oxygen_i2s_bits(hw_params), 481 oxygen_i2s_bits(hw_params),
474 OXYGEN_I2S_RATE_MASK | 482 OXYGEN_I2S_RATE_MASK |
475 OXYGEN_I2S_FORMAT_MASK | 483 OXYGEN_I2S_FORMAT_MASK |
476 OXYGEN_I2S_MCLK_MASK | 484 OXYGEN_I2S_MCLK_MASK |
477 OXYGEN_I2S_BITS_MASK); 485 OXYGEN_I2S_BITS_MASK);
478 oxygen_update_dac_routing(chip);
479 oxygen_update_spdif_source(chip); 486 oxygen_update_spdif_source(chip);
480 spin_unlock_irq(&chip->reg_lock); 487 spin_unlock_irq(&chip->reg_lock);
481 488
482 mutex_lock(&chip->mutex);
483 chip->model.set_dac_params(chip, hw_params); 489 chip->model.set_dac_params(chip, hw_params);
490 oxygen_update_dac_routing(chip);
484 mutex_unlock(&chip->mutex); 491 mutex_unlock(&chip->mutex);
485 return 0; 492 return 0;
486} 493}
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index 6ebcb6bdd712..f03a2f2cffee 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -17,145 +17,12 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20/*
21 * Xonar D2/D2X
22 * ------------
23 *
24 * CMI8788:
25 *
26 * SPI 0 -> 1st PCM1796 (front)
27 * SPI 1 -> 2nd PCM1796 (surround)
28 * SPI 2 -> 3rd PCM1796 (center/LFE)
29 * SPI 4 -> 4th PCM1796 (back)
30 *
31 * GPIO 2 -> M0 of CS5381
32 * GPIO 3 -> M1 of CS5381
33 * GPIO 5 <- external power present (D2X only)
34 * GPIO 7 -> ALT
35 * GPIO 8 -> enable output to speakers
36 */
37
38/*
39 * Xonar D1/DX
40 * -----------
41 *
42 * CMI8788:
43 *
44 * I²C <-> CS4398 (front)
45 * <-> CS4362A (surround, center/LFE, back)
46 *
47 * GPI 0 <- external power present (DX only)
48 *
49 * GPIO 0 -> enable output to speakers
50 * GPIO 1 -> enable front panel I/O
51 * GPIO 2 -> M0 of CS5361
52 * GPIO 3 -> M1 of CS5361
53 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
54 *
55 * CS4398:
56 *
57 * AD0 <- 1
58 * AD1 <- 1
59 *
60 * CS4362A:
61 *
62 * AD0 <- 0
63 */
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
115/*
116 * Xonar Essence ST (Deluxe)/STX
117 * -----------------------------
118 *
119 * CMI8788:
120 *
121 * I²C <-> PCM1792A
122 *
123 * GPI 0 <- external power present
124 *
125 * GPIO 0 -> enable output to speakers
126 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
127 * GPIO 2 -> M0 of CS5381
128 * GPIO 3 -> M1 of CS5381
129 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
130 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
131 *
132 * PCM1792A:
133 *
134 * AD0 <- 0
135 *
136 * H6 daughterboard
137 * ----------------
138 *
139 * GPIO 4 <- 0
140 * GPIO 5 <- 0
141 */
142
143#include <linux/pci.h> 20#include <linux/pci.h>
144#include <linux/delay.h> 21#include <linux/delay.h>
145#include <linux/mutex.h>
146#include <sound/ac97_codec.h>
147#include <sound/asoundef.h>
148#include <sound/control.h>
149#include <sound/core.h> 22#include <sound/core.h>
150#include <sound/initval.h> 23#include <sound/initval.h>
151#include <sound/pcm.h> 24#include <sound/pcm.h>
152#include <sound/pcm_params.h> 25#include "xonar.h"
153#include <sound/tlv.h>
154#include "oxygen.h"
155#include "cm9780.h"
156#include "pcm1796.h"
157#include "cs4398.h"
158#include "cs4362a.h"
159 26
160MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 27MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
161MODULE_DESCRIPTION("Asus AVx00 driver"); 28MODULE_DESCRIPTION("Asus AVx00 driver");
@@ -173,972 +40,31 @@ MODULE_PARM_DESC(id, "ID string");
173module_param_array(enable, bool, NULL, 0444); 40module_param_array(enable, bool, NULL, 0444);
174MODULE_PARM_DESC(enable, "enable card"); 41MODULE_PARM_DESC(enable, "enable card");
175 42
176enum { 43static DEFINE_PCI_DEVICE_TABLE(xonar_ids) = {
177 MODEL_D2, 44 { OXYGEN_PCI_SUBID(0x1043, 0x8269) },
178 MODEL_D2X, 45 { OXYGEN_PCI_SUBID(0x1043, 0x8275) },
179 MODEL_D1, 46 { OXYGEN_PCI_SUBID(0x1043, 0x82b7) },
180 MODEL_DX, 47 { OXYGEN_PCI_SUBID(0x1043, 0x8314) },
181 MODEL_HDAV, /* without daughterboard */ 48 { OXYGEN_PCI_SUBID(0x1043, 0x8327) },
182 MODEL_HDAV_H6, /* with H6 daughterboard */ 49 { OXYGEN_PCI_SUBID(0x1043, 0x834f) },
183 MODEL_ST, 50 { OXYGEN_PCI_SUBID(0x1043, 0x835c) },
184 MODEL_ST_H6, 51 { OXYGEN_PCI_SUBID(0x1043, 0x835d) },
185 MODEL_STX, 52 { OXYGEN_PCI_SUBID(0x1043, 0x838e) },
186};
187
188static struct pci_device_id xonar_ids[] __devinitdata = {
189 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
190 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
191 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
192 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV },
193 { OXYGEN_PCI_SUBID(0x1043, 0x8327), .driver_data = MODEL_DX },
194 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 },
195 { OXYGEN_PCI_SUBID(0x1043, 0x835c), .driver_data = MODEL_STX },
196 { OXYGEN_PCI_SUBID(0x1043, 0x835d), .driver_data = MODEL_ST },
197 { OXYGEN_PCI_SUBID_BROKEN_EEPROM }, 53 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
198 { } 54 { }
199}; 55};
200MODULE_DEVICE_TABLE(pci, xonar_ids); 56MODULE_DEVICE_TABLE(pci, xonar_ids);
201 57
202
203#define GPIO_CS53x1_M_MASK 0x000c
204#define GPIO_CS53x1_M_SINGLE 0x0000
205#define GPIO_CS53x1_M_DOUBLE 0x0004
206#define GPIO_CS53x1_M_QUAD 0x0008
207
208#define GPIO_D2X_EXT_POWER 0x0020
209#define GPIO_D2_ALT 0x0080
210#define GPIO_D2_OUTPUT_ENABLE 0x0100
211
212#define GPI_DX_EXT_POWER 0x01
213#define GPIO_DX_OUTPUT_ENABLE 0x0001
214#define GPIO_DX_FRONT_PANEL 0x0002
215#define GPIO_DX_INPUT_ROUTE 0x0100
216
217#define GPIO_DB_MASK 0x0030
218#define GPIO_DB_H6 0x0000
219#define GPIO_DB_XX 0x0020
220
221#define GPIO_ST_HP_REAR 0x0002
222#define GPIO_ST_HP 0x0080
223
224#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
225#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
226#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
227
228struct xonar_data {
229 unsigned int anti_pop_delay;
230 unsigned int dacs;
231 u16 output_enable_bit;
232 u8 ext_power_reg;
233 u8 ext_power_int_reg;
234 u8 ext_power_bit;
235 u8 has_power;
236 u8 pcm1796_oversampling;
237 u8 cs4398_fm;
238 u8 cs4362a_fm;
239 u8 hdmi_params[5];
240};
241
242static void xonar_gpio_changed(struct oxygen *chip);
243
244static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
245 u8 reg, u8 value)
246{
247 /* maps ALSA channel pair number to SPI output */
248 static const u8 codec_map[4] = {
249 0, 1, 2, 4
250 };
251 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
252 OXYGEN_SPI_DATA_LENGTH_2 |
253 OXYGEN_SPI_CLOCK_160 |
254 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
255 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
256 (reg << 8) | value);
257}
258
259static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
260 u8 reg, u8 value)
261{
262 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
263}
264
265static void pcm1796_write(struct oxygen *chip, unsigned int codec,
266 u8 reg, u8 value)
267{
268 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
269 OXYGEN_FUNCTION_SPI)
270 pcm1796_write_spi(chip, codec, reg, value);
271 else
272 pcm1796_write_i2c(chip, codec, reg, value);
273}
274
275static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
276{
277 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
278}
279
280static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
281{
282 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
283}
284
285static void hdmi_write_command(struct oxygen *chip, u8 command,
286 unsigned int count, const u8 *params)
287{
288 unsigned int i;
289 u8 checksum;
290
291 oxygen_write_uart(chip, 0xfb);
292 oxygen_write_uart(chip, 0xef);
293 oxygen_write_uart(chip, command);
294 oxygen_write_uart(chip, count);
295 for (i = 0; i < count; ++i)
296 oxygen_write_uart(chip, params[i]);
297 checksum = 0xfb + 0xef + command + count;
298 for (i = 0; i < count; ++i)
299 checksum += params[i];
300 oxygen_write_uart(chip, checksum);
301}
302
303static void xonar_enable_output(struct oxygen *chip)
304{
305 struct xonar_data *data = chip->model_data;
306
307 msleep(data->anti_pop_delay);
308 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
309}
310
311static void xonar_common_init(struct oxygen *chip)
312{
313 struct xonar_data *data = chip->model_data;
314
315 if (data->ext_power_reg) {
316 oxygen_set_bits8(chip, data->ext_power_int_reg,
317 data->ext_power_bit);
318 chip->interrupt_mask |= OXYGEN_INT_GPIO;
319 chip->model.gpio_changed = xonar_gpio_changed;
320 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
321 & data->ext_power_bit);
322 }
323 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
324 GPIO_CS53x1_M_MASK | data->output_enable_bit);
325 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
326 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
327 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
328 xonar_enable_output(chip);
329}
330
331static void update_pcm1796_volume(struct oxygen *chip)
332{
333 struct xonar_data *data = chip->model_data;
334 unsigned int i;
335
336 for (i = 0; i < data->dacs; ++i) {
337 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
338 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
339 }
340}
341
342static void update_pcm1796_mute(struct oxygen *chip)
343{
344 struct xonar_data *data = chip->model_data;
345 unsigned int i;
346 u8 value;
347
348 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
349 if (chip->dac_mute)
350 value |= PCM1796_MUTE;
351 for (i = 0; i < data->dacs; ++i)
352 pcm1796_write(chip, i, 18, value);
353}
354
355static void pcm1796_init(struct oxygen *chip)
356{
357 struct xonar_data *data = chip->model_data;
358 unsigned int i;
359
360 for (i = 0; i < data->dacs; ++i) {
361 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
362 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
363 pcm1796_write(chip, i, 21, 0);
364 }
365 update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */
366 update_pcm1796_volume(chip);
367}
368
369static void xonar_d2_init(struct oxygen *chip)
370{
371 struct xonar_data *data = chip->model_data;
372
373 data->anti_pop_delay = 300;
374 data->dacs = 4;
375 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
376 data->pcm1796_oversampling = PCM1796_OS_64;
377
378 pcm1796_init(chip);
379
380 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
381 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
382
383 xonar_common_init(chip);
384
385 snd_component_add(chip->card, "PCM1796");
386 snd_component_add(chip->card, "CS5381");
387}
388
389static void xonar_d2x_init(struct oxygen *chip)
390{
391 struct xonar_data *data = chip->model_data;
392
393 data->ext_power_reg = OXYGEN_GPIO_DATA;
394 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
395 data->ext_power_bit = GPIO_D2X_EXT_POWER;
396 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
397
398 xonar_d2_init(chip);
399}
400
401static void update_cs4362a_volumes(struct oxygen *chip)
402{
403 u8 mute;
404
405 mute = chip->dac_mute ? CS4362A_MUTE : 0;
406 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
407 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
408 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
409 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
410 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
411 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
412}
413
414static void update_cs43xx_volume(struct oxygen *chip)
415{
416 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
417 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
418 update_cs4362a_volumes(chip);
419}
420
421static void update_cs43xx_mute(struct oxygen *chip)
422{
423 u8 reg;
424
425 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
426 if (chip->dac_mute)
427 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
428 cs4398_write(chip, 4, reg);
429 update_cs4362a_volumes(chip);
430}
431
432static void cs43xx_init(struct oxygen *chip)
433{
434 struct xonar_data *data = chip->model_data;
435
436 /* set CPEN (control port mode) and power down */
437 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
438 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
439 /* configure */
440 cs4398_write(chip, 2, data->cs4398_fm);
441 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
442 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
443 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
444 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
445 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
446 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
447 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
448 cs4362a_write(chip, 0x05, 0);
449 cs4362a_write(chip, 0x06, data->cs4362a_fm);
450 cs4362a_write(chip, 0x09, data->cs4362a_fm);
451 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
452 update_cs43xx_volume(chip);
453 update_cs43xx_mute(chip);
454 /* clear power down */
455 cs4398_write(chip, 8, CS4398_CPEN);
456 cs4362a_write(chip, 0x01, CS4362A_CPEN);
457}
458
459static void xonar_d1_init(struct oxygen *chip)
460{
461 struct xonar_data *data = chip->model_data;
462
463 data->anti_pop_delay = 800;
464 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
465 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
466 data->cs4362a_fm = CS4362A_FM_SINGLE |
467 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
468
469 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
470 OXYGEN_2WIRE_LENGTH_8 |
471 OXYGEN_2WIRE_INTERRUPT_MASK |
472 OXYGEN_2WIRE_SPEED_FAST);
473
474 cs43xx_init(chip);
475
476 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
477 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
478 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
479 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
480
481 xonar_common_init(chip);
482
483 snd_component_add(chip->card, "CS4398");
484 snd_component_add(chip->card, "CS4362A");
485 snd_component_add(chip->card, "CS5361");
486}
487
488static void xonar_dx_init(struct oxygen *chip)
489{
490 struct xonar_data *data = chip->model_data;
491
492 data->ext_power_reg = OXYGEN_GPI_DATA;
493 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
494 data->ext_power_bit = GPI_DX_EXT_POWER;
495
496 xonar_d1_init(chip);
497}
498
499static void xonar_hdav_init(struct oxygen *chip)
500{
501 struct xonar_data *data = chip->model_data;
502 u8 param;
503
504 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
505 OXYGEN_2WIRE_LENGTH_8 |
506 OXYGEN_2WIRE_INTERRUPT_MASK |
507 OXYGEN_2WIRE_SPEED_FAST);
508
509 data->anti_pop_delay = 100;
510 data->dacs = chip->model.private_data == MODEL_HDAV_H6 ? 4 : 1;
511 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
512 data->ext_power_reg = OXYGEN_GPI_DATA;
513 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
514 data->ext_power_bit = GPI_DX_EXT_POWER;
515 data->pcm1796_oversampling = PCM1796_OS_64;
516
517 pcm1796_init(chip);
518
519 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE);
520 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE);
521
522 oxygen_reset_uart(chip);
523 param = 0;
524 hdmi_write_command(chip, 0x61, 1, &param);
525 param = 1;
526 hdmi_write_command(chip, 0x74, 1, &param);
527 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
528 data->hdmi_params[4] = 1;
529 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
530
531 xonar_common_init(chip);
532
533 snd_component_add(chip->card, "PCM1796");
534 snd_component_add(chip->card, "CS5381");
535}
536
537static void xonar_st_init(struct oxygen *chip)
538{
539 struct xonar_data *data = chip->model_data;
540
541 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
542 OXYGEN_2WIRE_LENGTH_8 |
543 OXYGEN_2WIRE_INTERRUPT_MASK |
544 OXYGEN_2WIRE_SPEED_FAST);
545
546 if (chip->model.private_data == MODEL_ST_H6)
547 chip->model.dac_channels = 8;
548 data->anti_pop_delay = 100;
549 data->dacs = chip->model.private_data == MODEL_ST_H6 ? 4 : 1;
550 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
551 data->pcm1796_oversampling = PCM1796_OS_64;
552
553 pcm1796_init(chip);
554
555 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
556 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
557 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
558 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
559
560 xonar_common_init(chip);
561
562 snd_component_add(chip->card, "PCM1792A");
563 snd_component_add(chip->card, "CS5381");
564}
565
566static void xonar_stx_init(struct oxygen *chip)
567{
568 struct xonar_data *data = chip->model_data;
569
570 data->ext_power_reg = OXYGEN_GPI_DATA;
571 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
572 data->ext_power_bit = GPI_DX_EXT_POWER;
573
574 xonar_st_init(chip);
575}
576
577static void xonar_disable_output(struct oxygen *chip)
578{
579 struct xonar_data *data = chip->model_data;
580
581 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
582}
583
584static void xonar_d2_cleanup(struct oxygen *chip)
585{
586 xonar_disable_output(chip);
587}
588
589static void xonar_d1_cleanup(struct oxygen *chip)
590{
591 xonar_disable_output(chip);
592 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
593 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
594}
595
596static void xonar_hdav_cleanup(struct oxygen *chip)
597{
598 u8 param = 0;
599
600 hdmi_write_command(chip, 0x74, 1, &param);
601 xonar_disable_output(chip);
602}
603
604static void xonar_st_cleanup(struct oxygen *chip)
605{
606 xonar_disable_output(chip);
607}
608
609static void xonar_d2_suspend(struct oxygen *chip)
610{
611 xonar_d2_cleanup(chip);
612}
613
614static void xonar_d1_suspend(struct oxygen *chip)
615{
616 xonar_d1_cleanup(chip);
617}
618
619static void xonar_hdav_suspend(struct oxygen *chip)
620{
621 xonar_hdav_cleanup(chip);
622 msleep(2);
623}
624
625static void xonar_st_suspend(struct oxygen *chip)
626{
627 xonar_st_cleanup(chip);
628}
629
630static void xonar_d2_resume(struct oxygen *chip)
631{
632 pcm1796_init(chip);
633 xonar_enable_output(chip);
634}
635
636static void xonar_d1_resume(struct oxygen *chip)
637{
638 oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
639 msleep(1);
640 cs43xx_init(chip);
641 xonar_enable_output(chip);
642}
643
644static void xonar_hdav_resume(struct oxygen *chip)
645{
646 struct xonar_data *data = chip->model_data;
647 u8 param;
648
649 oxygen_reset_uart(chip);
650 param = 0;
651 hdmi_write_command(chip, 0x61, 1, &param);
652 param = 1;
653 hdmi_write_command(chip, 0x74, 1, &param);
654 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
655 pcm1796_init(chip);
656 xonar_enable_output(chip);
657}
658
659static void xonar_st_resume(struct oxygen *chip)
660{
661 pcm1796_init(chip);
662 xonar_enable_output(chip);
663}
664
665static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
666 struct snd_pcm_hardware *hardware)
667{
668 if (channel == PCM_MULTICH) {
669 hardware->rates = SNDRV_PCM_RATE_44100 |
670 SNDRV_PCM_RATE_48000 |
671 SNDRV_PCM_RATE_96000 |
672 SNDRV_PCM_RATE_192000;
673 hardware->rate_min = 44100;
674 }
675}
676
677static void set_pcm1796_params(struct oxygen *chip,
678 struct snd_pcm_hw_params *params)
679{
680 struct xonar_data *data = chip->model_data;
681 unsigned int i;
682
683 data->pcm1796_oversampling =
684 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
685 for (i = 0; i < data->dacs; ++i)
686 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
687}
688
689static void set_cs53x1_params(struct oxygen *chip,
690 struct snd_pcm_hw_params *params)
691{
692 unsigned int value;
693
694 if (params_rate(params) <= 54000)
695 value = GPIO_CS53x1_M_SINGLE;
696 else if (params_rate(params) <= 108000)
697 value = GPIO_CS53x1_M_DOUBLE;
698 else
699 value = GPIO_CS53x1_M_QUAD;
700 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
701 value, GPIO_CS53x1_M_MASK);
702}
703
704static void set_cs43xx_params(struct oxygen *chip,
705 struct snd_pcm_hw_params *params)
706{
707 struct xonar_data *data = chip->model_data;
708
709 data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST;
710 data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
711 if (params_rate(params) <= 50000) {
712 data->cs4398_fm |= CS4398_FM_SINGLE;
713 data->cs4362a_fm |= CS4362A_FM_SINGLE;
714 } else if (params_rate(params) <= 100000) {
715 data->cs4398_fm |= CS4398_FM_DOUBLE;
716 data->cs4362a_fm |= CS4362A_FM_DOUBLE;
717 } else {
718 data->cs4398_fm |= CS4398_FM_QUAD;
719 data->cs4362a_fm |= CS4362A_FM_QUAD;
720 }
721 cs4398_write(chip, 2, data->cs4398_fm);
722 cs4362a_write(chip, 0x06, data->cs4362a_fm);
723 cs4362a_write(chip, 0x09, data->cs4362a_fm);
724 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
725}
726
727static void set_hdmi_params(struct oxygen *chip,
728 struct snd_pcm_hw_params *params)
729{
730 struct xonar_data *data = chip->model_data;
731
732 data->hdmi_params[0] = 0; /* 1 = non-audio */
733 switch (params_rate(params)) {
734 case 44100:
735 data->hdmi_params[1] = IEC958_AES3_CON_FS_44100;
736 break;
737 case 48000:
738 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
739 break;
740 default: /* 96000 */
741 data->hdmi_params[1] = IEC958_AES3_CON_FS_96000;
742 break;
743 case 192000:
744 data->hdmi_params[1] = IEC958_AES3_CON_FS_192000;
745 break;
746 }
747 data->hdmi_params[2] = params_channels(params) / 2 - 1;
748 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
749 data->hdmi_params[3] = 0;
750 else
751 data->hdmi_params[3] = 0xc0;
752 data->hdmi_params[4] = 1; /* ? */
753 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
754}
755
756static void set_hdav_params(struct oxygen *chip,
757 struct snd_pcm_hw_params *params)
758{
759 set_pcm1796_params(chip, params);
760 set_hdmi_params(chip, params);
761}
762
763static void xonar_gpio_changed(struct oxygen *chip)
764{
765 struct xonar_data *data = chip->model_data;
766 u8 has_power;
767
768 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
769 & data->ext_power_bit);
770 if (has_power != data->has_power) {
771 data->has_power = has_power;
772 if (has_power) {
773 snd_printk(KERN_NOTICE "power restored\n");
774 } else {
775 snd_printk(KERN_CRIT
776 "Hey! Don't unplug the power cable!\n");
777 /* TODO: stop PCMs */
778 }
779 }
780}
781
782static void xonar_hdav_uart_input(struct oxygen *chip)
783{
784 if (chip->uart_input_count >= 2 &&
785 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
786 chip->uart_input[chip->uart_input_count - 1] == 'K') {
787 printk(KERN_DEBUG "message from Xonar HDAV HDMI chip received:\n");
788 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
789 chip->uart_input, chip->uart_input_count);
790 chip->uart_input_count = 0;
791 }
792}
793
794static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
795 struct snd_ctl_elem_value *value)
796{
797 struct oxygen *chip = ctl->private_data;
798 u16 bit = ctl->private_value;
799
800 value->value.integer.value[0] =
801 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
802 return 0;
803}
804
805static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
806 struct snd_ctl_elem_value *value)
807{
808 struct oxygen *chip = ctl->private_data;
809 u16 bit = ctl->private_value;
810 u16 old_bits, new_bits;
811 int changed;
812
813 spin_lock_irq(&chip->reg_lock);
814 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
815 if (value->value.integer.value[0])
816 new_bits = old_bits | bit;
817 else
818 new_bits = old_bits & ~bit;
819 changed = new_bits != old_bits;
820 if (changed)
821 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
822 spin_unlock_irq(&chip->reg_lock);
823 return changed;
824}
825
826static const struct snd_kcontrol_new alt_switch = {
827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
828 .name = "Analog Loopback Switch",
829 .info = snd_ctl_boolean_mono_info,
830 .get = gpio_bit_switch_get,
831 .put = gpio_bit_switch_put,
832 .private_value = GPIO_D2_ALT,
833};
834
835static const struct snd_kcontrol_new front_panel_switch = {
836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
837 .name = "Front Panel Switch",
838 .info = snd_ctl_boolean_mono_info,
839 .get = gpio_bit_switch_get,
840 .put = gpio_bit_switch_put,
841 .private_value = GPIO_DX_FRONT_PANEL,
842};
843
844static int st_output_switch_info(struct snd_kcontrol *ctl,
845 struct snd_ctl_elem_info *info)
846{
847 static const char *const names[3] = {
848 "Speakers", "Headphones", "FP Headphones"
849 };
850
851 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
852 info->count = 1;
853 info->value.enumerated.items = 3;
854 if (info->value.enumerated.item >= 3)
855 info->value.enumerated.item = 2;
856 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
857 return 0;
858}
859
860static int st_output_switch_get(struct snd_kcontrol *ctl,
861 struct snd_ctl_elem_value *value)
862{
863 struct oxygen *chip = ctl->private_data;
864 u16 gpio;
865
866 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
867 if (!(gpio & GPIO_ST_HP))
868 value->value.enumerated.item[0] = 0;
869 else if (gpio & GPIO_ST_HP_REAR)
870 value->value.enumerated.item[0] = 1;
871 else
872 value->value.enumerated.item[0] = 2;
873 return 0;
874}
875
876
877static int st_output_switch_put(struct snd_kcontrol *ctl,
878 struct snd_ctl_elem_value *value)
879{
880 struct oxygen *chip = ctl->private_data;
881 u16 gpio_old, gpio;
882
883 mutex_lock(&chip->mutex);
884 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
885 gpio = gpio_old;
886 switch (value->value.enumerated.item[0]) {
887 case 0:
888 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
889 break;
890 case 1:
891 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
892 break;
893 case 2:
894 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
895 break;
896 }
897 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
898 mutex_unlock(&chip->mutex);
899 return gpio != gpio_old;
900}
901
902static const struct snd_kcontrol_new st_output_switch = {
903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
904 .name = "Analog Output",
905 .info = st_output_switch_info,
906 .get = st_output_switch_get,
907 .put = st_output_switch_put,
908};
909
910static void xonar_line_mic_ac97_switch(struct oxygen *chip,
911 unsigned int reg, unsigned int mute)
912{
913 if (reg == AC97_LINE) {
914 spin_lock_irq(&chip->reg_lock);
915 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
916 mute ? GPIO_DX_INPUT_ROUTE : 0,
917 GPIO_DX_INPUT_ROUTE);
918 spin_unlock_irq(&chip->reg_lock);
919 }
920}
921
922static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
923static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0);
924
925static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
926{
927 if (!strncmp(template->name, "CD Capture ", 11))
928 /* CD in is actually connected to the video in pin */
929 template->private_value ^= AC97_CD ^ AC97_VIDEO;
930 return 0;
931}
932
933static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
934{
935 if (!strncmp(template->name, "CD Capture ", 11))
936 return 1; /* no CD input */
937 return 0;
938}
939
940static int xonar_st_control_filter(struct snd_kcontrol_new *template)
941{
942 if (!strncmp(template->name, "CD Capture ", 11))
943 return 1; /* no CD input */
944 if (!strcmp(template->name, "Stereo Upmixing"))
945 return 1; /* stereo only - we don't need upmixing */
946 return 0;
947}
948
949static int xonar_d2_mixer_init(struct oxygen *chip)
950{
951 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
952}
953
954static int xonar_d1_mixer_init(struct oxygen *chip)
955{
956 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
957}
958
959static int xonar_st_mixer_init(struct oxygen *chip)
960{
961 return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip));
962}
963
964static const struct oxygen_model model_xonar_d2 = {
965 .longname = "Asus Virtuoso 200",
966 .chip = "AV200",
967 .init = xonar_d2_init,
968 .control_filter = xonar_d2_control_filter,
969 .mixer_init = xonar_d2_mixer_init,
970 .cleanup = xonar_d2_cleanup,
971 .suspend = xonar_d2_suspend,
972 .resume = xonar_d2_resume,
973 .set_dac_params = set_pcm1796_params,
974 .set_adc_params = set_cs53x1_params,
975 .update_dac_volume = update_pcm1796_volume,
976 .update_dac_mute = update_pcm1796_mute,
977 .dac_tlv = pcm1796_db_scale,
978 .model_data_size = sizeof(struct xonar_data),
979 .device_config = PLAYBACK_0_TO_I2S |
980 PLAYBACK_1_TO_SPDIF |
981 CAPTURE_0_FROM_I2S_2 |
982 CAPTURE_1_FROM_SPDIF |
983 MIDI_OUTPUT |
984 MIDI_INPUT,
985 .dac_channels = 8,
986 .dac_volume_min = 255 - 2*60,
987 .dac_volume_max = 255,
988 .misc_flags = OXYGEN_MISC_MIDI,
989 .function_flags = OXYGEN_FUNCTION_SPI |
990 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
991 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
992 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
993};
994
995static const struct oxygen_model model_xonar_d1 = {
996 .longname = "Asus Virtuoso 100",
997 .chip = "AV200",
998 .init = xonar_d1_init,
999 .control_filter = xonar_d1_control_filter,
1000 .mixer_init = xonar_d1_mixer_init,
1001 .cleanup = xonar_d1_cleanup,
1002 .suspend = xonar_d1_suspend,
1003 .resume = xonar_d1_resume,
1004 .set_dac_params = set_cs43xx_params,
1005 .set_adc_params = set_cs53x1_params,
1006 .update_dac_volume = update_cs43xx_volume,
1007 .update_dac_mute = update_cs43xx_mute,
1008 .ac97_switch = xonar_line_mic_ac97_switch,
1009 .dac_tlv = cs4362a_db_scale,
1010 .model_data_size = sizeof(struct xonar_data),
1011 .device_config = PLAYBACK_0_TO_I2S |
1012 PLAYBACK_1_TO_SPDIF |
1013 CAPTURE_0_FROM_I2S_2,
1014 .dac_channels = 8,
1015 .dac_volume_min = 127 - 60,
1016 .dac_volume_max = 127,
1017 .function_flags = OXYGEN_FUNCTION_2WIRE,
1018 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1019 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1020};
1021
1022static const struct oxygen_model model_xonar_hdav = {
1023 .longname = "Asus Virtuoso 200",
1024 .chip = "AV200",
1025 .init = xonar_hdav_init,
1026 .cleanup = xonar_hdav_cleanup,
1027 .suspend = xonar_hdav_suspend,
1028 .resume = xonar_hdav_resume,
1029 .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter,
1030 .set_dac_params = set_hdav_params,
1031 .set_adc_params = set_cs53x1_params,
1032 .update_dac_volume = update_pcm1796_volume,
1033 .update_dac_mute = update_pcm1796_mute,
1034 .uart_input = xonar_hdav_uart_input,
1035 .ac97_switch = xonar_line_mic_ac97_switch,
1036 .dac_tlv = pcm1796_db_scale,
1037 .model_data_size = sizeof(struct xonar_data),
1038 .device_config = PLAYBACK_0_TO_I2S |
1039 PLAYBACK_1_TO_SPDIF |
1040 CAPTURE_0_FROM_I2S_2 |
1041 CAPTURE_1_FROM_SPDIF,
1042 .dac_channels = 8,
1043 .dac_volume_min = 255 - 2*60,
1044 .dac_volume_max = 255,
1045 .misc_flags = OXYGEN_MISC_MIDI,
1046 .function_flags = OXYGEN_FUNCTION_2WIRE,
1047 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1048 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1049};
1050
1051static const struct oxygen_model model_xonar_st = {
1052 .longname = "Asus Virtuoso 100",
1053 .chip = "AV200",
1054 .init = xonar_st_init,
1055 .control_filter = xonar_st_control_filter,
1056 .mixer_init = xonar_st_mixer_init,
1057 .cleanup = xonar_st_cleanup,
1058 .suspend = xonar_st_suspend,
1059 .resume = xonar_st_resume,
1060 .set_dac_params = set_pcm1796_params,
1061 .set_adc_params = set_cs53x1_params,
1062 .update_dac_volume = update_pcm1796_volume,
1063 .update_dac_mute = update_pcm1796_mute,
1064 .ac97_switch = xonar_line_mic_ac97_switch,
1065 .dac_tlv = pcm1796_db_scale,
1066 .model_data_size = sizeof(struct xonar_data),
1067 .device_config = PLAYBACK_0_TO_I2S |
1068 PLAYBACK_1_TO_SPDIF |
1069 CAPTURE_0_FROM_I2S_2,
1070 .dac_channels = 2,
1071 .dac_volume_min = 255 - 2*60,
1072 .dac_volume_max = 255,
1073 .function_flags = OXYGEN_FUNCTION_2WIRE,
1074 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1075 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1076};
1077
1078static int __devinit get_xonar_model(struct oxygen *chip, 58static int __devinit get_xonar_model(struct oxygen *chip,
1079 const struct pci_device_id *id) 59 const struct pci_device_id *id)
1080{ 60{
1081 static const struct oxygen_model *const models[] = { 61 if (get_xonar_pcm179x_model(chip, id) >= 0)
1082 [MODEL_D1] = &model_xonar_d1, 62 return 0;
1083 [MODEL_DX] = &model_xonar_d1, 63 if (get_xonar_cs43xx_model(chip, id) >= 0)
1084 [MODEL_D2] = &model_xonar_d2, 64 return 0;
1085 [MODEL_D2X] = &model_xonar_d2, 65 if (get_xonar_wm87x6_model(chip, id) >= 0)
1086 [MODEL_HDAV] = &model_xonar_hdav, 66 return 0;
1087 [MODEL_ST] = &model_xonar_st, 67 return -EINVAL;
1088 [MODEL_STX] = &model_xonar_st,
1089 };
1090 static const char *const names[] = {
1091 [MODEL_D1] = "Xonar D1",
1092 [MODEL_DX] = "Xonar DX",
1093 [MODEL_D2] = "Xonar D2",
1094 [MODEL_D2X] = "Xonar D2X",
1095 [MODEL_HDAV] = "Xonar HDAV1.3",
1096 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
1097 [MODEL_ST] = "Xonar Essence ST",
1098 [MODEL_ST_H6] = "Xonar Essence ST+H6",
1099 [MODEL_STX] = "Xonar Essence STX",
1100 };
1101 unsigned int model = id->driver_data;
1102
1103 if (model >= ARRAY_SIZE(models) || !models[model])
1104 return -EINVAL;
1105 chip->model = *models[model];
1106
1107 switch (model) {
1108 case MODEL_D2X:
1109 chip->model.init = xonar_d2x_init;
1110 break;
1111 case MODEL_DX:
1112 chip->model.init = xonar_dx_init;
1113 break;
1114 case MODEL_HDAV:
1115 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1116 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1117 case GPIO_DB_H6:
1118 model = MODEL_HDAV_H6;
1119 break;
1120 case GPIO_DB_XX:
1121 snd_printk(KERN_ERR "unknown daughterboard\n");
1122 return -ENODEV;
1123 }
1124 break;
1125 case MODEL_ST:
1126 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1127 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1128 case GPIO_DB_H6:
1129 model = MODEL_ST_H6;
1130 break;
1131 }
1132 break;
1133 case MODEL_STX:
1134 chip->model.init = xonar_stx_init;
1135 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1136 break;
1137 }
1138
1139 chip->model.shortname = names[model];
1140 chip->model.private_data = model;
1141 return 0;
1142} 68}
1143 69
1144static int __devinit xonar_probe(struct pci_dev *pci, 70static int __devinit xonar_probe(struct pci_dev *pci,
diff --git a/sound/pci/oxygen/wm8766.h b/sound/pci/oxygen/wm8766.h
new file mode 100644
index 000000000000..e0e849a7eaeb
--- /dev/null
+++ b/sound/pci/oxygen/wm8766.h
@@ -0,0 +1,73 @@
1#ifndef WM8766_H_INCLUDED
2#define WM8766_H_INCLUDED
3
4#define WM8766_LDA1 0x00
5#define WM8766_RDA1 0x01
6#define WM8766_DAC_CTRL 0x02
7#define WM8766_INT_CTRL 0x03
8#define WM8766_LDA2 0x04
9#define WM8766_RDA2 0x05
10#define WM8766_LDA3 0x06
11#define WM8766_RDA3 0x07
12#define WM8766_MASTDA 0x08
13#define WM8766_DAC_CTRL2 0x09
14#define WM8766_DAC_CTRL3 0x0a
15#define WM8766_MUTE1 0x0c
16#define WM8766_MUTE2 0x0f
17#define WM8766_RESET 0x1f
18
19/* LDAx/RDAx/MASTDA */
20#define WM8766_ATT_MASK 0x0ff
21#define WM8766_UPDATE 0x100
22/* DAC_CTRL */
23#define WM8766_MUTEALL 0x001
24#define WM8766_DEEMPALL 0x002
25#define WM8766_PWDN 0x004
26#define WM8766_ATC 0x008
27#define WM8766_IZD 0x010
28#define WM8766_PL_LEFT_MASK 0x060
29#define WM8766_PL_LEFT_MUTE 0x000
30#define WM8766_PL_LEFT_LEFT 0x020
31#define WM8766_PL_LEFT_RIGHT 0x040
32#define WM8766_PL_LEFT_LRMIX 0x060
33#define WM8766_PL_RIGHT_MASK 0x180
34#define WM8766_PL_RIGHT_MUTE 0x000
35#define WM8766_PL_RIGHT_LEFT 0x080
36#define WM8766_PL_RIGHT_RIGHT 0x100
37#define WM8766_PL_RIGHT_LRMIX 0x180
38/* INT_CTRL */
39#define WM8766_FMT_MASK 0x003
40#define WM8766_FMT_RJUST 0x000
41#define WM8766_FMT_LJUST 0x001
42#define WM8766_FMT_I2S 0x002
43#define WM8766_FMT_DSP 0x003
44#define WM8766_LRP 0x004
45#define WM8766_BCP 0x008
46#define WM8766_IWL_MASK 0x030
47#define WM8766_IWL_16 0x000
48#define WM8766_IWL_20 0x010
49#define WM8766_IWL_24 0x020
50#define WM8766_IWL_32 0x030
51#define WM8766_PHASE_MASK 0x1c0
52/* DAC_CTRL2 */
53#define WM8766_ZCD 0x001
54#define WM8766_DZFM_MASK 0x006
55#define WM8766_DMUTE_MASK 0x038
56#define WM8766_DEEMP_MASK 0x1c0
57/* DAC_CTRL3 */
58#define WM8766_DACPD_MASK 0x00e
59#define WM8766_PWRDNALL 0x010
60#define WM8766_MS 0x020
61#define WM8766_RATE_MASK 0x1c0
62#define WM8766_RATE_128 0x000
63#define WM8766_RATE_192 0x040
64#define WM8766_RATE_256 0x080
65#define WM8766_RATE_384 0x0c0
66#define WM8766_RATE_512 0x100
67#define WM8766_RATE_768 0x140
68/* MUTE1 */
69#define WM8766_MPD1 0x040
70/* MUTE2 */
71#define WM8766_MPD2 0x020
72
73#endif
diff --git a/sound/pci/oxygen/wm8776.h b/sound/pci/oxygen/wm8776.h
new file mode 100644
index 000000000000..1a96f5615727
--- /dev/null
+++ b/sound/pci/oxygen/wm8776.h
@@ -0,0 +1,177 @@
1#ifndef WM8776_H_INCLUDED
2#define WM8776_H_INCLUDED
3
4/*
5 * the following register names are from:
6 * wm8776.h -- WM8776 ASoC driver
7 *
8 * Copyright 2009 Wolfson Microelectronics plc
9 *
10 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#define WM8776_HPLVOL 0x00
18#define WM8776_HPRVOL 0x01
19#define WM8776_HPMASTER 0x02
20#define WM8776_DACLVOL 0x03
21#define WM8776_DACRVOL 0x04
22#define WM8776_DACMASTER 0x05
23#define WM8776_PHASESWAP 0x06
24#define WM8776_DACCTRL1 0x07
25#define WM8776_DACMUTE 0x08
26#define WM8776_DACCTRL2 0x09
27#define WM8776_DACIFCTRL 0x0a
28#define WM8776_ADCIFCTRL 0x0b
29#define WM8776_MSTRCTRL 0x0c
30#define WM8776_PWRDOWN 0x0d
31#define WM8776_ADCLVOL 0x0e
32#define WM8776_ADCRVOL 0x0f
33#define WM8776_ALCCTRL1 0x10
34#define WM8776_ALCCTRL2 0x11
35#define WM8776_ALCCTRL3 0x12
36#define WM8776_NOISEGATE 0x13
37#define WM8776_LIMITER 0x14
38#define WM8776_ADCMUX 0x15
39#define WM8776_OUTMUX 0x16
40#define WM8776_RESET 0x17
41
42
43/* HPLVOL/HPRVOL/HPMASTER */
44#define WM8776_HPATT_MASK 0x07f
45#define WM8776_HPZCEN 0x080
46#define WM8776_UPDATE 0x100
47
48/* DACLVOL/DACRVOL/DACMASTER */
49#define WM8776_DATT_MASK 0x0ff
50/*#define WM8776_UPDATE 0x100*/
51
52/* PHASESWAP */
53#define WM8776_PH_MASK 0x003
54
55/* DACCTRL1 */
56#define WM8776_DZCEN 0x001
57#define WM8776_ATC 0x002
58#define WM8776_IZD 0x004
59#define WM8776_TOD 0x008
60#define WM8776_PL_LEFT_MASK 0x030
61#define WM8776_PL_LEFT_MUTE 0x000
62#define WM8776_PL_LEFT_LEFT 0x010
63#define WM8776_PL_LEFT_RIGHT 0x020
64#define WM8776_PL_LEFT_LRMIX 0x030
65#define WM8776_PL_RIGHT_MASK 0x0c0
66#define WM8776_PL_RIGHT_MUTE 0x000
67#define WM8776_PL_RIGHT_LEFT 0x040
68#define WM8776_PL_RIGHT_RIGHT 0x080
69#define WM8776_PL_RIGHT_LRMIX 0x0c0
70
71/* DACMUTE */
72#define WM8776_DMUTE 0x001
73
74/* DACCTRL2 */
75#define WM8776_DEEMPH 0x001
76#define WM8776_DZFM_MASK 0x006
77#define WM8776_DZFM_NONE 0x000
78#define WM8776_DZFM_LR 0x002
79#define WM8776_DZFM_BOTH 0x004
80#define WM8776_DZFM_EITHER 0x006
81
82/* DACIFCTRL */
83#define WM8776_DACFMT_MASK 0x003
84#define WM8776_DACFMT_RJUST 0x000
85#define WM8776_DACFMT_LJUST 0x001
86#define WM8776_DACFMT_I2S 0x002
87#define WM8776_DACFMT_DSP 0x003
88#define WM8776_DACLRP 0x004
89#define WM8776_DACBCP 0x008
90#define WM8776_DACWL_MASK 0x030
91#define WM8776_DACWL_16 0x000
92#define WM8776_DACWL_20 0x010
93#define WM8776_DACWL_24 0x020
94#define WM8776_DACWL_32 0x030
95
96/* ADCIFCTRL */
97#define WM8776_ADCFMT_MASK 0x003
98#define WM8776_ADCFMT_RJUST 0x000
99#define WM8776_ADCFMT_LJUST 0x001
100#define WM8776_ADCFMT_I2S 0x002
101#define WM8776_ADCFMT_DSP 0x003
102#define WM8776_ADCLRP 0x004
103#define WM8776_ADCBCP 0x008
104#define WM8776_ADCWL_MASK 0x030
105#define WM8776_ADCWL_16 0x000
106#define WM8776_ADCWL_20 0x010
107#define WM8776_ADCWL_24 0x020
108#define WM8776_ADCWL_32 0x030
109#define WM8776_ADCMCLK 0x040
110#define WM8776_ADCHPD 0x100
111
112/* MSTRCTRL */
113#define WM8776_ADCRATE_MASK 0x007
114#define WM8776_ADCRATE_256 0x002
115#define WM8776_ADCRATE_384 0x003
116#define WM8776_ADCRATE_512 0x004
117#define WM8776_ADCRATE_768 0x005
118#define WM8776_ADCOSR 0x008
119#define WM8776_DACRATE_MASK 0x070
120#define WM8776_DACRATE_128 0x000
121#define WM8776_DACRATE_192 0x010
122#define WM8776_DACRATE_256 0x020
123#define WM8776_DACRATE_384 0x030
124#define WM8776_DACRATE_512 0x040
125#define WM8776_DACRATE_768 0x050
126#define WM8776_DACMS 0x080
127#define WM8776_ADCMS 0x100
128
129/* PWRDOWN */
130#define WM8776_PDWN 0x001
131#define WM8776_ADCPD 0x002
132#define WM8776_DACPD 0x004
133#define WM8776_HPPD 0x008
134#define WM8776_AINPD 0x040
135
136/* ADCLVOL/ADCRVOL */
137#define WM8776_AGMASK 0x0ff
138#define WM8776_ZCA 0x100
139
140/* ALCCTRL1 */
141#define WM8776_LCT_MASK 0x00f
142#define WM8776_MAXGAIN_MASK 0x070
143#define WM8776_LCSEL_MASK 0x180
144#define WM8776_LCSEL_LIMITER 0x000
145#define WM8776_LCSEL_ALC_RIGHT 0x080
146#define WM8776_LCSEL_ALC_LEFT 0x100
147#define WM8776_LCSEL_ALC_STEREO 0x180
148
149/* ALCCTRL2 */
150#define WM8776_HLD_MASK 0x00f
151#define WM8776_ALCZC 0x080
152#define WM8776_LCEN 0x100
153
154/* ALCCTRL3 */
155#define WM8776_ATK_MASK 0x00f
156#define WM8776_DCY_MASK 0x0f0
157
158/* NOISEGATE */
159#define WM8776_NGAT 0x001
160#define WM8776_NGTH_MASK 0x01c
161
162/* LIMITER */
163#define WM8776_MAXATTEN_MASK 0x00f
164#define WM8776_TRANWIN_MASK 0x070
165
166/* ADCMUX */
167#define WM8776_AMX_MASK 0x01f
168#define WM8776_MUTERA 0x040
169#define WM8776_MUTELA 0x080
170#define WM8776_LRBOTH 0x100
171
172/* OUTMUX */
173#define WM8776_MX_DAC 0x001
174#define WM8776_MX_AUX 0x002
175#define WM8776_MX_BYPASS 0x004
176
177#endif
diff --git a/sound/pci/oxygen/xonar.h b/sound/pci/oxygen/xonar.h
new file mode 100644
index 000000000000..b35343b0a9a5
--- /dev/null
+++ b/sound/pci/oxygen/xonar.h
@@ -0,0 +1,52 @@
1#ifndef XONAR_H_INCLUDED
2#define XONAR_H_INCLUDED
3
4#include "oxygen.h"
5
6struct xonar_generic {
7 unsigned int anti_pop_delay;
8 u16 output_enable_bit;
9 u8 ext_power_reg;
10 u8 ext_power_int_reg;
11 u8 ext_power_bit;
12 u8 has_power;
13};
14
15struct xonar_hdmi {
16 u8 params[5];
17};
18
19/* generic helper functions */
20
21void xonar_enable_output(struct oxygen *chip);
22void xonar_disable_output(struct oxygen *chip);
23void xonar_init_ext_power(struct oxygen *chip);
24void xonar_init_cs53x1(struct oxygen *chip);
25void xonar_set_cs53x1_params(struct oxygen *chip,
26 struct snd_pcm_hw_params *params);
27int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
28 struct snd_ctl_elem_value *value);
29int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
30 struct snd_ctl_elem_value *value);
31
32/* model-specific card drivers */
33
34int get_xonar_pcm179x_model(struct oxygen *chip,
35 const struct pci_device_id *id);
36int get_xonar_cs43xx_model(struct oxygen *chip,
37 const struct pci_device_id *id);
38int get_xonar_wm87x6_model(struct oxygen *chip,
39 const struct pci_device_id *id);
40
41/* HDMI helper functions */
42
43void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *data);
44void xonar_hdmi_cleanup(struct oxygen *chip);
45void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi);
46void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
47 struct snd_pcm_hardware *hardware);
48void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
49 struct snd_pcm_hw_params *params);
50void xonar_hdmi_uart_input(struct oxygen *chip);
51
52#endif
diff --git a/sound/pci/oxygen/xonar_cs43xx.c b/sound/pci/oxygen/xonar_cs43xx.c
new file mode 100644
index 000000000000..7c4986b27f2b
--- /dev/null
+++ b/sound/pci/oxygen/xonar_cs43xx.c
@@ -0,0 +1,437 @@
1/*
2 * card driver for models with CS4398/CS4362A DACs (Xonar D1/DX)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Xonar D1/DX
21 * -----------
22 *
23 * CMI8788:
24 *
25 * I²C <-> CS4398 (front)
26 * <-> CS4362A (surround, center/LFE, back)
27 *
28 * GPI 0 <- external power present (DX only)
29 *
30 * GPIO 0 -> enable output to speakers
31 * GPIO 1 -> enable front panel I/O
32 * GPIO 2 -> M0 of CS5361
33 * GPIO 3 -> M1 of CS5361
34 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
35 *
36 * CS4398:
37 *
38 * AD0 <- 1
39 * AD1 <- 1
40 *
41 * CS4362A:
42 *
43 * AD0 <- 0
44 *
45 * CM9780:
46 *
47 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5361 input
48 */
49
50#include <linux/pci.h>
51#include <linux/delay.h>
52#include <sound/ac97_codec.h>
53#include <sound/control.h>
54#include <sound/core.h>
55#include <sound/pcm.h>
56#include <sound/pcm_params.h>
57#include <sound/tlv.h>
58#include "xonar.h"
59#include "cm9780.h"
60#include "cs4398.h"
61#include "cs4362a.h"
62
63#define GPI_EXT_POWER 0x01
64#define GPIO_D1_OUTPUT_ENABLE 0x0001
65#define GPIO_D1_FRONT_PANEL 0x0002
66#define GPIO_D1_INPUT_ROUTE 0x0100
67
68#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
69#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
70
71struct xonar_cs43xx {
72 struct xonar_generic generic;
73 u8 cs4398_regs[8];
74 u8 cs4362a_regs[15];
75};
76
77static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
78{
79 struct xonar_cs43xx *data = chip->model_data;
80
81 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
82 if (reg < ARRAY_SIZE(data->cs4398_regs))
83 data->cs4398_regs[reg] = value;
84}
85
86static void cs4398_write_cached(struct oxygen *chip, u8 reg, u8 value)
87{
88 struct xonar_cs43xx *data = chip->model_data;
89
90 if (value != data->cs4398_regs[reg])
91 cs4398_write(chip, reg, value);
92}
93
94static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
95{
96 struct xonar_cs43xx *data = chip->model_data;
97
98 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
99 if (reg < ARRAY_SIZE(data->cs4362a_regs))
100 data->cs4362a_regs[reg] = value;
101}
102
103static void cs4362a_write_cached(struct oxygen *chip, u8 reg, u8 value)
104{
105 struct xonar_cs43xx *data = chip->model_data;
106
107 if (value != data->cs4362a_regs[reg])
108 cs4362a_write(chip, reg, value);
109}
110
111static void cs43xx_registers_init(struct oxygen *chip)
112{
113 struct xonar_cs43xx *data = chip->model_data;
114 unsigned int i;
115
116 /* set CPEN (control port mode) and power down */
117 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
118 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
119 /* configure */
120 cs4398_write(chip, 2, data->cs4398_regs[2]);
121 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
122 cs4398_write(chip, 4, data->cs4398_regs[4]);
123 cs4398_write(chip, 5, data->cs4398_regs[5]);
124 cs4398_write(chip, 6, data->cs4398_regs[6]);
125 cs4398_write(chip, 7, data->cs4398_regs[7]);
126 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
127 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
128 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
129 cs4362a_write(chip, 0x04, data->cs4362a_regs[0x04]);
130 cs4362a_write(chip, 0x05, 0);
131 for (i = 6; i <= 14; ++i)
132 cs4362a_write(chip, i, data->cs4362a_regs[i]);
133 /* clear power down */
134 cs4398_write(chip, 8, CS4398_CPEN);
135 cs4362a_write(chip, 0x01, CS4362A_CPEN);
136}
137
138static void xonar_d1_init(struct oxygen *chip)
139{
140 struct xonar_cs43xx *data = chip->model_data;
141
142 data->generic.anti_pop_delay = 800;
143 data->generic.output_enable_bit = GPIO_D1_OUTPUT_ENABLE;
144 data->cs4398_regs[2] =
145 CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
146 data->cs4398_regs[4] = CS4398_MUTEP_LOW |
147 CS4398_MUTE_B | CS4398_MUTE_A | CS4398_PAMUTE;
148 data->cs4398_regs[5] = 60 * 2;
149 data->cs4398_regs[6] = 60 * 2;
150 data->cs4398_regs[7] = CS4398_RMP_DN | CS4398_RMP_UP |
151 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP;
152 data->cs4362a_regs[4] = CS4362A_RMP_DN | CS4362A_DEM_NONE;
153 data->cs4362a_regs[6] = CS4362A_FM_SINGLE |
154 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
155 data->cs4362a_regs[7] = 60 | CS4362A_MUTE;
156 data->cs4362a_regs[8] = 60 | CS4362A_MUTE;
157 data->cs4362a_regs[9] = data->cs4362a_regs[6];
158 data->cs4362a_regs[10] = 60 | CS4362A_MUTE;
159 data->cs4362a_regs[11] = 60 | CS4362A_MUTE;
160 data->cs4362a_regs[12] = data->cs4362a_regs[6];
161 data->cs4362a_regs[13] = 60 | CS4362A_MUTE;
162 data->cs4362a_regs[14] = 60 | CS4362A_MUTE;
163
164 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
165 OXYGEN_2WIRE_LENGTH_8 |
166 OXYGEN_2WIRE_INTERRUPT_MASK |
167 OXYGEN_2WIRE_SPEED_FAST);
168
169 cs43xx_registers_init(chip);
170
171 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
172 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE);
173 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
174 GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE);
175
176 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
177
178 xonar_init_cs53x1(chip);
179 xonar_enable_output(chip);
180
181 snd_component_add(chip->card, "CS4398");
182 snd_component_add(chip->card, "CS4362A");
183 snd_component_add(chip->card, "CS5361");
184}
185
186static void xonar_dx_init(struct oxygen *chip)
187{
188 struct xonar_cs43xx *data = chip->model_data;
189
190 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
191 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
192 data->generic.ext_power_bit = GPI_EXT_POWER;
193 xonar_init_ext_power(chip);
194 xonar_d1_init(chip);
195}
196
197static void xonar_d1_cleanup(struct oxygen *chip)
198{
199 xonar_disable_output(chip);
200 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
201 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
202}
203
204static void xonar_d1_suspend(struct oxygen *chip)
205{
206 xonar_d1_cleanup(chip);
207}
208
209static void xonar_d1_resume(struct oxygen *chip)
210{
211 oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
212 msleep(1);
213 cs43xx_registers_init(chip);
214 xonar_enable_output(chip);
215}
216
217static void set_cs43xx_params(struct oxygen *chip,
218 struct snd_pcm_hw_params *params)
219{
220 struct xonar_cs43xx *data = chip->model_data;
221 u8 cs4398_fm, cs4362a_fm;
222
223 if (params_rate(params) <= 50000) {
224 cs4398_fm = CS4398_FM_SINGLE;
225 cs4362a_fm = CS4362A_FM_SINGLE;
226 } else if (params_rate(params) <= 100000) {
227 cs4398_fm = CS4398_FM_DOUBLE;
228 cs4362a_fm = CS4362A_FM_DOUBLE;
229 } else {
230 cs4398_fm = CS4398_FM_QUAD;
231 cs4362a_fm = CS4362A_FM_QUAD;
232 }
233 cs4398_fm |= CS4398_DEM_NONE | CS4398_DIF_LJUST;
234 cs4398_write_cached(chip, 2, cs4398_fm);
235 cs4362a_fm |= data->cs4362a_regs[6] & ~CS4362A_FM_MASK;
236 cs4362a_write_cached(chip, 6, cs4362a_fm);
237 cs4362a_write_cached(chip, 12, cs4362a_fm);
238 cs4362a_fm &= CS4362A_FM_MASK;
239 cs4362a_fm |= data->cs4362a_regs[9] & ~CS4362A_FM_MASK;
240 cs4362a_write_cached(chip, 9, cs4362a_fm);
241}
242
243static void update_cs4362a_volumes(struct oxygen *chip)
244{
245 unsigned int i;
246 u8 mute;
247
248 mute = chip->dac_mute ? CS4362A_MUTE : 0;
249 for (i = 0; i < 6; ++i)
250 cs4362a_write_cached(chip, 7 + i + i / 2,
251 (127 - chip->dac_volume[2 + i]) | mute);
252}
253
254static void update_cs43xx_volume(struct oxygen *chip)
255{
256 cs4398_write_cached(chip, 5, (127 - chip->dac_volume[0]) * 2);
257 cs4398_write_cached(chip, 6, (127 - chip->dac_volume[1]) * 2);
258 update_cs4362a_volumes(chip);
259}
260
261static void update_cs43xx_mute(struct oxygen *chip)
262{
263 u8 reg;
264
265 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
266 if (chip->dac_mute)
267 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
268 cs4398_write_cached(chip, 4, reg);
269 update_cs4362a_volumes(chip);
270}
271
272static void update_cs43xx_center_lfe_mix(struct oxygen *chip, bool mixed)
273{
274 struct xonar_cs43xx *data = chip->model_data;
275 u8 reg;
276
277 reg = data->cs4362a_regs[9] & ~CS4362A_ATAPI_MASK;
278 if (mixed)
279 reg |= CS4362A_ATAPI_B_LR | CS4362A_ATAPI_A_LR;
280 else
281 reg |= CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
282 cs4362a_write_cached(chip, 9, reg);
283}
284
285static const struct snd_kcontrol_new front_panel_switch = {
286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
287 .name = "Front Panel Switch",
288 .info = snd_ctl_boolean_mono_info,
289 .get = xonar_gpio_bit_switch_get,
290 .put = xonar_gpio_bit_switch_put,
291 .private_value = GPIO_D1_FRONT_PANEL,
292};
293
294static int rolloff_info(struct snd_kcontrol *ctl,
295 struct snd_ctl_elem_info *info)
296{
297 static const char *const names[2] = {
298 "Fast Roll-off", "Slow Roll-off"
299 };
300
301 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
302 info->count = 1;
303 info->value.enumerated.items = 2;
304 if (info->value.enumerated.item >= 2)
305 info->value.enumerated.item = 1;
306 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
307 return 0;
308}
309
310static int rolloff_get(struct snd_kcontrol *ctl,
311 struct snd_ctl_elem_value *value)
312{
313 struct oxygen *chip = ctl->private_data;
314 struct xonar_cs43xx *data = chip->model_data;
315
316 value->value.enumerated.item[0] =
317 (data->cs4398_regs[7] & CS4398_FILT_SEL) != 0;
318 return 0;
319}
320
321static int rolloff_put(struct snd_kcontrol *ctl,
322 struct snd_ctl_elem_value *value)
323{
324 struct oxygen *chip = ctl->private_data;
325 struct xonar_cs43xx *data = chip->model_data;
326 int changed;
327 u8 reg;
328
329 mutex_lock(&chip->mutex);
330 reg = data->cs4398_regs[7];
331 if (value->value.enumerated.item[0])
332 reg |= CS4398_FILT_SEL;
333 else
334 reg &= ~CS4398_FILT_SEL;
335 changed = reg != data->cs4398_regs[7];
336 if (changed) {
337 cs4398_write(chip, 7, reg);
338 if (reg & CS4398_FILT_SEL)
339 reg = data->cs4362a_regs[0x04] | CS4362A_FILT_SEL;
340 else
341 reg = data->cs4362a_regs[0x04] & ~CS4362A_FILT_SEL;
342 cs4362a_write(chip, 0x04, reg);
343 }
344 mutex_unlock(&chip->mutex);
345 return changed;
346}
347
348static const struct snd_kcontrol_new rolloff_control = {
349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
350 .name = "DAC Filter Playback Enum",
351 .info = rolloff_info,
352 .get = rolloff_get,
353 .put = rolloff_put,
354};
355
356static void xonar_d1_line_mic_ac97_switch(struct oxygen *chip,
357 unsigned int reg, unsigned int mute)
358{
359 if (reg == AC97_LINE) {
360 spin_lock_irq(&chip->reg_lock);
361 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
362 mute ? GPIO_D1_INPUT_ROUTE : 0,
363 GPIO_D1_INPUT_ROUTE);
364 spin_unlock_irq(&chip->reg_lock);
365 }
366}
367
368static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0);
369
370static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
371{
372 if (!strncmp(template->name, "CD Capture ", 11))
373 return 1; /* no CD input */
374 return 0;
375}
376
377static int xonar_d1_mixer_init(struct oxygen *chip)
378{
379 int err;
380
381 err = snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
382 if (err < 0)
383 return err;
384 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
385 if (err < 0)
386 return err;
387 return 0;
388}
389
390static const struct oxygen_model model_xonar_d1 = {
391 .longname = "Asus Virtuoso 100",
392 .chip = "AV200",
393 .init = xonar_d1_init,
394 .control_filter = xonar_d1_control_filter,
395 .mixer_init = xonar_d1_mixer_init,
396 .cleanup = xonar_d1_cleanup,
397 .suspend = xonar_d1_suspend,
398 .resume = xonar_d1_resume,
399 .get_i2s_mclk = oxygen_default_i2s_mclk,
400 .set_dac_params = set_cs43xx_params,
401 .set_adc_params = xonar_set_cs53x1_params,
402 .update_dac_volume = update_cs43xx_volume,
403 .update_dac_mute = update_cs43xx_mute,
404 .update_center_lfe_mix = update_cs43xx_center_lfe_mix,
405 .ac97_switch = xonar_d1_line_mic_ac97_switch,
406 .dac_tlv = cs4362a_db_scale,
407 .model_data_size = sizeof(struct xonar_cs43xx),
408 .device_config = PLAYBACK_0_TO_I2S |
409 PLAYBACK_1_TO_SPDIF |
410 CAPTURE_0_FROM_I2S_2,
411 .dac_channels = 8,
412 .dac_volume_min = 127 - 60,
413 .dac_volume_max = 127,
414 .function_flags = OXYGEN_FUNCTION_2WIRE,
415 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
416 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
417};
418
419int __devinit get_xonar_cs43xx_model(struct oxygen *chip,
420 const struct pci_device_id *id)
421{
422 switch (id->subdevice) {
423 case 0x834f:
424 chip->model = model_xonar_d1;
425 chip->model.shortname = "Xonar D1";
426 break;
427 case 0x8275:
428 case 0x8327:
429 chip->model = model_xonar_d1;
430 chip->model.shortname = "Xonar DX";
431 chip->model.init = xonar_dx_init;
432 break;
433 default:
434 return -EINVAL;
435 }
436 return 0;
437}
diff --git a/sound/pci/oxygen/xonar_hdmi.c b/sound/pci/oxygen/xonar_hdmi.c
new file mode 100644
index 000000000000..b12db1f1cea9
--- /dev/null
+++ b/sound/pci/oxygen/xonar_hdmi.c
@@ -0,0 +1,128 @@
1/*
2 * helper functions for HDMI models (Xonar HDAV1.3)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/pci.h>
20#include <linux/delay.h>
21#include <sound/asoundef.h>
22#include <sound/control.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/tlv.h>
27#include "xonar.h"
28
29static void hdmi_write_command(struct oxygen *chip, u8 command,
30 unsigned int count, const u8 *params)
31{
32 unsigned int i;
33 u8 checksum;
34
35 oxygen_write_uart(chip, 0xfb);
36 oxygen_write_uart(chip, 0xef);
37 oxygen_write_uart(chip, command);
38 oxygen_write_uart(chip, count);
39 for (i = 0; i < count; ++i)
40 oxygen_write_uart(chip, params[i]);
41 checksum = 0xfb + 0xef + command + count;
42 for (i = 0; i < count; ++i)
43 checksum += params[i];
44 oxygen_write_uart(chip, checksum);
45}
46
47static void xonar_hdmi_init_commands(struct oxygen *chip,
48 struct xonar_hdmi *hdmi)
49{
50 u8 param;
51
52 oxygen_reset_uart(chip);
53 param = 0;
54 hdmi_write_command(chip, 0x61, 1, &param);
55 param = 1;
56 hdmi_write_command(chip, 0x74, 1, &param);
57 hdmi_write_command(chip, 0x54, 5, hdmi->params);
58}
59
60void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi)
61{
62 hdmi->params[1] = IEC958_AES3_CON_FS_48000;
63 hdmi->params[4] = 1;
64 xonar_hdmi_init_commands(chip, hdmi);
65}
66
67void xonar_hdmi_cleanup(struct oxygen *chip)
68{
69 u8 param = 0;
70
71 hdmi_write_command(chip, 0x74, 1, &param);
72}
73
74void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi)
75{
76 xonar_hdmi_init_commands(chip, hdmi);
77}
78
79void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
80 struct snd_pcm_hardware *hardware)
81{
82 if (channel == PCM_MULTICH) {
83 hardware->rates = SNDRV_PCM_RATE_44100 |
84 SNDRV_PCM_RATE_48000 |
85 SNDRV_PCM_RATE_96000 |
86 SNDRV_PCM_RATE_192000;
87 hardware->rate_min = 44100;
88 }
89}
90
91void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
92 struct snd_pcm_hw_params *params)
93{
94 hdmi->params[0] = 0; /* 1 = non-audio */
95 switch (params_rate(params)) {
96 case 44100:
97 hdmi->params[1] = IEC958_AES3_CON_FS_44100;
98 break;
99 case 48000:
100 hdmi->params[1] = IEC958_AES3_CON_FS_48000;
101 break;
102 default: /* 96000 */
103 hdmi->params[1] = IEC958_AES3_CON_FS_96000;
104 break;
105 case 192000:
106 hdmi->params[1] = IEC958_AES3_CON_FS_192000;
107 break;
108 }
109 hdmi->params[2] = params_channels(params) / 2 - 1;
110 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
111 hdmi->params[3] = 0;
112 else
113 hdmi->params[3] = 0xc0;
114 hdmi->params[4] = 1; /* ? */
115 hdmi_write_command(chip, 0x54, 5, hdmi->params);
116}
117
118void xonar_hdmi_uart_input(struct oxygen *chip)
119{
120 if (chip->uart_input_count >= 2 &&
121 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
122 chip->uart_input[chip->uart_input_count - 1] == 'K') {
123 printk(KERN_DEBUG "message from HDMI chip received:\n");
124 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
125 chip->uart_input, chip->uart_input_count);
126 chip->uart_input_count = 0;
127 }
128}
diff --git a/sound/pci/oxygen/xonar_lib.c b/sound/pci/oxygen/xonar_lib.c
new file mode 100644
index 000000000000..b3ff71316653
--- /dev/null
+++ b/sound/pci/oxygen/xonar_lib.c
@@ -0,0 +1,132 @@
1/*
2 * helper functions for Asus Xonar cards
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/delay.h>
20#include <sound/core.h>
21#include <sound/control.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include "xonar.h"
25
26
27#define GPIO_CS53x1_M_MASK 0x000c
28#define GPIO_CS53x1_M_SINGLE 0x0000
29#define GPIO_CS53x1_M_DOUBLE 0x0004
30#define GPIO_CS53x1_M_QUAD 0x0008
31
32
33void xonar_enable_output(struct oxygen *chip)
34{
35 struct xonar_generic *data = chip->model_data;
36
37 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
38 msleep(data->anti_pop_delay);
39 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
40}
41
42void xonar_disable_output(struct oxygen *chip)
43{
44 struct xonar_generic *data = chip->model_data;
45
46 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
47}
48
49static void xonar_ext_power_gpio_changed(struct oxygen *chip)
50{
51 struct xonar_generic *data = chip->model_data;
52 u8 has_power;
53
54 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
55 & data->ext_power_bit);
56 if (has_power != data->has_power) {
57 data->has_power = has_power;
58 if (has_power) {
59 snd_printk(KERN_NOTICE "power restored\n");
60 } else {
61 snd_printk(KERN_CRIT
62 "Hey! Don't unplug the power cable!\n");
63 /* TODO: stop PCMs */
64 }
65 }
66}
67
68void xonar_init_ext_power(struct oxygen *chip)
69{
70 struct xonar_generic *data = chip->model_data;
71
72 oxygen_set_bits8(chip, data->ext_power_int_reg,
73 data->ext_power_bit);
74 chip->interrupt_mask |= OXYGEN_INT_GPIO;
75 chip->model.gpio_changed = xonar_ext_power_gpio_changed;
76 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
77 & data->ext_power_bit);
78}
79
80void xonar_init_cs53x1(struct oxygen *chip)
81{
82 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
83 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
84 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
85}
86
87void xonar_set_cs53x1_params(struct oxygen *chip,
88 struct snd_pcm_hw_params *params)
89{
90 unsigned int value;
91
92 if (params_rate(params) <= 54000)
93 value = GPIO_CS53x1_M_SINGLE;
94 else if (params_rate(params) <= 108000)
95 value = GPIO_CS53x1_M_DOUBLE;
96 else
97 value = GPIO_CS53x1_M_QUAD;
98 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
99 value, GPIO_CS53x1_M_MASK);
100}
101
102int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
103 struct snd_ctl_elem_value *value)
104{
105 struct oxygen *chip = ctl->private_data;
106 u16 bit = ctl->private_value;
107
108 value->value.integer.value[0] =
109 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
110 return 0;
111}
112
113int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
114 struct snd_ctl_elem_value *value)
115{
116 struct oxygen *chip = ctl->private_data;
117 u16 bit = ctl->private_value;
118 u16 old_bits, new_bits;
119 int changed;
120
121 spin_lock_irq(&chip->reg_lock);
122 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
123 if (value->value.integer.value[0])
124 new_bits = old_bits | bit;
125 else
126 new_bits = old_bits & ~bit;
127 changed = new_bits != old_bits;
128 if (changed)
129 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
130 spin_unlock_irq(&chip->reg_lock);
131 return changed;
132}
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c
new file mode 100644
index 000000000000..ba18fb546b4f
--- /dev/null
+++ b/sound/pci/oxygen/xonar_pcm179x.c
@@ -0,0 +1,1115 @@
1/*
2 * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Xonar D2/D2X
21 * ------------
22 *
23 * CMI8788:
24 *
25 * SPI 0 -> 1st PCM1796 (front)
26 * SPI 1 -> 2nd PCM1796 (surround)
27 * SPI 2 -> 3rd PCM1796 (center/LFE)
28 * SPI 4 -> 4th PCM1796 (back)
29 *
30 * GPIO 2 -> M0 of CS5381
31 * GPIO 3 -> M1 of CS5381
32 * GPIO 5 <- external power present (D2X only)
33 * GPIO 7 -> ALT
34 * GPIO 8 -> enable output to speakers
35 *
36 * CM9780:
37 *
38 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
39 */
40
41/*
42 * Xonar HDAV1.3 (Deluxe)
43 * ----------------------
44 *
45 * CMI8788:
46 *
47 * I²C <-> PCM1796 (front)
48 *
49 * GPI 0 <- external power present
50 *
51 * GPIO 0 -> enable output to speakers
52 * GPIO 2 -> M0 of CS5381
53 * GPIO 3 -> M1 of CS5381
54 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
55 *
56 * TXD -> HDMI controller
57 * RXD <- HDMI controller
58 *
59 * PCM1796 front: AD1,0 <- 0,0
60 *
61 * CM9780:
62 *
63 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
64 *
65 * no daughterboard
66 * ----------------
67 *
68 * GPIO 4 <- 1
69 *
70 * H6 daughterboard
71 * ----------------
72 *
73 * GPIO 4 <- 0
74 * GPIO 5 <- 0
75 *
76 * I²C <-> PCM1796 (surround)
77 * <-> PCM1796 (center/LFE)
78 * <-> PCM1796 (back)
79 *
80 * PCM1796 surround: AD1,0 <- 0,1
81 * PCM1796 center/LFE: AD1,0 <- 1,0
82 * PCM1796 back: AD1,0 <- 1,1
83 *
84 * unknown daughterboard
85 * ---------------------
86 *
87 * GPIO 4 <- 0
88 * GPIO 5 <- 1
89 *
90 * I²C <-> CS4362A (surround, center/LFE, back)
91 *
92 * CS4362A: AD0 <- 0
93 */
94
95/*
96 * Xonar Essence ST (Deluxe)/STX
97 * -----------------------------
98 *
99 * CMI8788:
100 *
101 * I²C <-> PCM1792A
102 * <-> CS2000 (ST only)
103 *
104 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
105 *
106 * GPI 0 <- external power present (STX only)
107 *
108 * GPIO 0 -> enable output to speakers
109 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
110 * GPIO 2 -> M0 of CS5381
111 * GPIO 3 -> M1 of CS5381
112 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
113 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
114 *
115 * PCM1792A:
116 *
117 * AD1,0 <- 0,0
118 * SCK <- CLK_OUT of CS2000 (ST only)
119 *
120 * CS2000:
121 *
122 * AD0 <- 0
123 *
124 * CM9780:
125 *
126 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
127 *
128 * H6 daughterboard
129 * ----------------
130 *
131 * GPIO 4 <- 0
132 * GPIO 5 <- 0
133 */
134
135#include <linux/pci.h>
136#include <linux/delay.h>
137#include <linux/mutex.h>
138#include <sound/ac97_codec.h>
139#include <sound/control.h>
140#include <sound/core.h>
141#include <sound/pcm.h>
142#include <sound/pcm_params.h>
143#include <sound/tlv.h>
144#include "xonar.h"
145#include "cm9780.h"
146#include "pcm1796.h"
147#include "cs2000.h"
148
149
150#define GPIO_D2X_EXT_POWER 0x0020
151#define GPIO_D2_ALT 0x0080
152#define GPIO_D2_OUTPUT_ENABLE 0x0100
153
154#define GPI_EXT_POWER 0x01
155#define GPIO_INPUT_ROUTE 0x0100
156
157#define GPIO_HDAV_OUTPUT_ENABLE 0x0001
158
159#define GPIO_DB_MASK 0x0030
160#define GPIO_DB_H6 0x0000
161
162#define GPIO_ST_OUTPUT_ENABLE 0x0001
163#define GPIO_ST_HP_REAR 0x0002
164#define GPIO_ST_HP 0x0080
165
166#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
167#define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
168
169#define PCM1796_REG_BASE 16
170
171
172struct xonar_pcm179x {
173 struct xonar_generic generic;
174 unsigned int dacs;
175 u8 pcm1796_regs[4][5];
176 unsigned int current_rate;
177 bool os_128;
178 bool hp_active;
179 s8 hp_gain_offset;
180 bool has_cs2000;
181 u8 cs2000_fun_cfg_1;
182};
183
184struct xonar_hdav {
185 struct xonar_pcm179x pcm179x;
186 struct xonar_hdmi hdmi;
187};
188
189
190static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
191 u8 reg, u8 value)
192{
193 /* maps ALSA channel pair number to SPI output */
194 static const u8 codec_map[4] = {
195 0, 1, 2, 4
196 };
197 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
198 OXYGEN_SPI_DATA_LENGTH_2 |
199 OXYGEN_SPI_CLOCK_160 |
200 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
201 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
202 (reg << 8) | value);
203}
204
205static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
206 u8 reg, u8 value)
207{
208 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
209}
210
211static void pcm1796_write(struct oxygen *chip, unsigned int codec,
212 u8 reg, u8 value)
213{
214 struct xonar_pcm179x *data = chip->model_data;
215
216 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
217 OXYGEN_FUNCTION_SPI)
218 pcm1796_write_spi(chip, codec, reg, value);
219 else
220 pcm1796_write_i2c(chip, codec, reg, value);
221 if ((unsigned int)(reg - PCM1796_REG_BASE)
222 < ARRAY_SIZE(data->pcm1796_regs[codec]))
223 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
224}
225
226static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
227 u8 reg, u8 value)
228{
229 struct xonar_pcm179x *data = chip->model_data;
230
231 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
232 pcm1796_write(chip, codec, reg, value);
233}
234
235static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
236{
237 struct xonar_pcm179x *data = chip->model_data;
238
239 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
240 if (reg == CS2000_FUN_CFG_1)
241 data->cs2000_fun_cfg_1 = value;
242}
243
244static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
245{
246 struct xonar_pcm179x *data = chip->model_data;
247
248 if (reg != CS2000_FUN_CFG_1 ||
249 value != data->cs2000_fun_cfg_1)
250 cs2000_write(chip, reg, value);
251}
252
253static void pcm1796_registers_init(struct oxygen *chip)
254{
255 struct xonar_pcm179x *data = chip->model_data;
256 unsigned int i;
257 s8 gain_offset;
258
259 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
260 for (i = 0; i < data->dacs; ++i) {
261 /* set ATLD before ATL/ATR */
262 pcm1796_write(chip, i, 18,
263 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
264 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
265 + gain_offset);
266 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
267 + gain_offset);
268 pcm1796_write(chip, i, 19,
269 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
270 pcm1796_write(chip, i, 20,
271 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
272 pcm1796_write(chip, i, 21, 0);
273 }
274}
275
276static void pcm1796_init(struct oxygen *chip)
277{
278 struct xonar_pcm179x *data = chip->model_data;
279
280 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
281 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
282 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
283 PCM1796_FLT_SHARP | PCM1796_ATS_1;
284 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
285 pcm1796_registers_init(chip);
286 data->current_rate = 48000;
287}
288
289static void xonar_d2_init(struct oxygen *chip)
290{
291 struct xonar_pcm179x *data = chip->model_data;
292
293 data->generic.anti_pop_delay = 300;
294 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
295 data->dacs = 4;
296
297 pcm1796_init(chip);
298
299 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
300 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
301
302 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
303
304 xonar_init_cs53x1(chip);
305 xonar_enable_output(chip);
306
307 snd_component_add(chip->card, "PCM1796");
308 snd_component_add(chip->card, "CS5381");
309}
310
311static void xonar_d2x_init(struct oxygen *chip)
312{
313 struct xonar_pcm179x *data = chip->model_data;
314
315 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
316 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
317 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
318 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
319 xonar_init_ext_power(chip);
320 xonar_d2_init(chip);
321}
322
323static void xonar_hdav_init(struct oxygen *chip)
324{
325 struct xonar_hdav *data = chip->model_data;
326
327 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
328 OXYGEN_2WIRE_LENGTH_8 |
329 OXYGEN_2WIRE_INTERRUPT_MASK |
330 OXYGEN_2WIRE_SPEED_FAST);
331
332 data->pcm179x.generic.anti_pop_delay = 100;
333 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
334 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
335 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
336 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
337 data->pcm179x.dacs = chip->model.private_data ? 4 : 1;
338
339 pcm1796_init(chip);
340
341 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_INPUT_ROUTE);
342 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
343
344 xonar_init_cs53x1(chip);
345 xonar_init_ext_power(chip);
346 xonar_hdmi_init(chip, &data->hdmi);
347 xonar_enable_output(chip);
348
349 snd_component_add(chip->card, "PCM1796");
350 snd_component_add(chip->card, "CS5381");
351}
352
353static void xonar_st_init_i2c(struct oxygen *chip)
354{
355 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
356 OXYGEN_2WIRE_LENGTH_8 |
357 OXYGEN_2WIRE_INTERRUPT_MASK |
358 OXYGEN_2WIRE_SPEED_FAST);
359}
360
361static void xonar_st_init_common(struct oxygen *chip)
362{
363 struct xonar_pcm179x *data = chip->model_data;
364
365 data->generic.anti_pop_delay = 100;
366 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
367 data->dacs = chip->model.private_data ? 4 : 1;
368 data->hp_gain_offset = 2*-18;
369
370 pcm1796_init(chip);
371
372 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
373 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
374 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
375 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
376
377 xonar_init_cs53x1(chip);
378 xonar_enable_output(chip);
379
380 snd_component_add(chip->card, "PCM1792A");
381 snd_component_add(chip->card, "CS5381");
382}
383
384static void cs2000_registers_init(struct oxygen *chip)
385{
386 struct xonar_pcm179x *data = chip->model_data;
387
388 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
389 cs2000_write(chip, CS2000_DEV_CTRL, 0);
390 cs2000_write(chip, CS2000_DEV_CFG_1,
391 CS2000_R_MOD_SEL_1 |
392 (0 << CS2000_R_SEL_SHIFT) |
393 CS2000_AUX_OUT_SRC_REF_CLK |
394 CS2000_EN_DEV_CFG_1);
395 cs2000_write(chip, CS2000_DEV_CFG_2,
396 (0 << CS2000_LOCK_CLK_SHIFT) |
397 CS2000_FRAC_N_SRC_STATIC);
398 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
399 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
400 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
401 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
402 cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1);
403 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
404 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
405}
406
407static void xonar_st_init(struct oxygen *chip)
408{
409 struct xonar_pcm179x *data = chip->model_data;
410
411 data->has_cs2000 = 1;
412 data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1;
413
414 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
415 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
416 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
417 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
418
419 xonar_st_init_i2c(chip);
420 cs2000_registers_init(chip);
421 xonar_st_init_common(chip);
422
423 snd_component_add(chip->card, "CS2000");
424}
425
426static void xonar_stx_init(struct oxygen *chip)
427{
428 struct xonar_pcm179x *data = chip->model_data;
429
430 xonar_st_init_i2c(chip);
431 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
432 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
433 data->generic.ext_power_bit = GPI_EXT_POWER;
434 xonar_init_ext_power(chip);
435 xonar_st_init_common(chip);
436}
437
438static void xonar_d2_cleanup(struct oxygen *chip)
439{
440 xonar_disable_output(chip);
441}
442
443static void xonar_hdav_cleanup(struct oxygen *chip)
444{
445 xonar_hdmi_cleanup(chip);
446 xonar_disable_output(chip);
447 msleep(2);
448}
449
450static void xonar_st_cleanup(struct oxygen *chip)
451{
452 xonar_disable_output(chip);
453}
454
455static void xonar_d2_suspend(struct oxygen *chip)
456{
457 xonar_d2_cleanup(chip);
458}
459
460static void xonar_hdav_suspend(struct oxygen *chip)
461{
462 xonar_hdav_cleanup(chip);
463}
464
465static void xonar_st_suspend(struct oxygen *chip)
466{
467 xonar_st_cleanup(chip);
468}
469
470static void xonar_d2_resume(struct oxygen *chip)
471{
472 pcm1796_registers_init(chip);
473 xonar_enable_output(chip);
474}
475
476static void xonar_hdav_resume(struct oxygen *chip)
477{
478 struct xonar_hdav *data = chip->model_data;
479
480 pcm1796_registers_init(chip);
481 xonar_hdmi_resume(chip, &data->hdmi);
482 xonar_enable_output(chip);
483}
484
485static void xonar_stx_resume(struct oxygen *chip)
486{
487 pcm1796_registers_init(chip);
488 xonar_enable_output(chip);
489}
490
491static void xonar_st_resume(struct oxygen *chip)
492{
493 cs2000_registers_init(chip);
494 xonar_stx_resume(chip);
495}
496
497static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
498{
499 struct xonar_pcm179x *data = chip->model_data;
500
501 if (rate <= 32000)
502 return OXYGEN_I2S_MCLK_512;
503 else if (rate <= 48000 && data->os_128)
504 return OXYGEN_I2S_MCLK_512;
505 else if (rate <= 96000)
506 return OXYGEN_I2S_MCLK_256;
507 else
508 return OXYGEN_I2S_MCLK_128;
509}
510
511static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
512 unsigned int channel,
513 struct snd_pcm_hw_params *params)
514{
515 if (channel == PCM_MULTICH)
516 return mclk_from_rate(chip, params_rate(params));
517 else
518 return oxygen_default_i2s_mclk(chip, channel, params);
519}
520
521static void update_pcm1796_oversampling(struct oxygen *chip)
522{
523 struct xonar_pcm179x *data = chip->model_data;
524 unsigned int i;
525 u8 reg;
526
527 if (data->current_rate <= 32000)
528 reg = PCM1796_OS_128;
529 else if (data->current_rate <= 48000 && data->os_128)
530 reg = PCM1796_OS_128;
531 else if (data->current_rate <= 96000 || data->os_128)
532 reg = PCM1796_OS_64;
533 else
534 reg = PCM1796_OS_32;
535 for (i = 0; i < data->dacs; ++i)
536 pcm1796_write_cached(chip, i, 20, reg);
537}
538
539static void set_pcm1796_params(struct oxygen *chip,
540 struct snd_pcm_hw_params *params)
541{
542 struct xonar_pcm179x *data = chip->model_data;
543
544 data->current_rate = params_rate(params);
545 update_pcm1796_oversampling(chip);
546}
547
548static void update_pcm1796_volume(struct oxygen *chip)
549{
550 struct xonar_pcm179x *data = chip->model_data;
551 unsigned int i;
552 s8 gain_offset;
553
554 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
555 for (i = 0; i < data->dacs; ++i) {
556 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
557 + gain_offset);
558 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
559 + gain_offset);
560 }
561}
562
563static void update_pcm1796_mute(struct oxygen *chip)
564{
565 struct xonar_pcm179x *data = chip->model_data;
566 unsigned int i;
567 u8 value;
568
569 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
570 if (chip->dac_mute)
571 value |= PCM1796_MUTE;
572 for (i = 0; i < data->dacs; ++i)
573 pcm1796_write_cached(chip, i, 18, value);
574}
575
576static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
577{
578 struct xonar_pcm179x *data = chip->model_data;
579 u8 rate_mclk, reg;
580
581 switch (rate) {
582 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
583 case 32000:
584 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
585 break;
586 case 44100:
587 if (data->os_128)
588 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
589 else
590 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
591 break;
592 default: /* 48000 */
593 if (data->os_128)
594 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
595 else
596 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
597 break;
598 case 64000:
599 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
600 break;
601 case 88200:
602 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
603 break;
604 case 96000:
605 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
606 break;
607 case 176400:
608 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
609 break;
610 case 192000:
611 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
612 break;
613 }
614 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
615 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
616 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128)
617 reg = CS2000_REF_CLK_DIV_1;
618 else
619 reg = CS2000_REF_CLK_DIV_2;
620 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
621}
622
623static void set_st_params(struct oxygen *chip,
624 struct snd_pcm_hw_params *params)
625{
626 update_cs2000_rate(chip, params_rate(params));
627 set_pcm1796_params(chip, params);
628}
629
630static void set_hdav_params(struct oxygen *chip,
631 struct snd_pcm_hw_params *params)
632{
633 struct xonar_hdav *data = chip->model_data;
634
635 set_pcm1796_params(chip, params);
636 xonar_set_hdmi_params(chip, &data->hdmi, params);
637}
638
639static const struct snd_kcontrol_new alt_switch = {
640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
641 .name = "Analog Loopback Switch",
642 .info = snd_ctl_boolean_mono_info,
643 .get = xonar_gpio_bit_switch_get,
644 .put = xonar_gpio_bit_switch_put,
645 .private_value = GPIO_D2_ALT,
646};
647
648static int rolloff_info(struct snd_kcontrol *ctl,
649 struct snd_ctl_elem_info *info)
650{
651 static const char *const names[2] = {
652 "Sharp Roll-off", "Slow Roll-off"
653 };
654
655 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
656 info->count = 1;
657 info->value.enumerated.items = 2;
658 if (info->value.enumerated.item >= 2)
659 info->value.enumerated.item = 1;
660 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
661 return 0;
662}
663
664static int rolloff_get(struct snd_kcontrol *ctl,
665 struct snd_ctl_elem_value *value)
666{
667 struct oxygen *chip = ctl->private_data;
668 struct xonar_pcm179x *data = chip->model_data;
669
670 value->value.enumerated.item[0] =
671 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
672 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
673 return 0;
674}
675
676static int rolloff_put(struct snd_kcontrol *ctl,
677 struct snd_ctl_elem_value *value)
678{
679 struct oxygen *chip = ctl->private_data;
680 struct xonar_pcm179x *data = chip->model_data;
681 unsigned int i;
682 int changed;
683 u8 reg;
684
685 mutex_lock(&chip->mutex);
686 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
687 reg &= ~PCM1796_FLT_MASK;
688 if (!value->value.enumerated.item[0])
689 reg |= PCM1796_FLT_SHARP;
690 else
691 reg |= PCM1796_FLT_SLOW;
692 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
693 if (changed) {
694 for (i = 0; i < data->dacs; ++i)
695 pcm1796_write(chip, i, 19, reg);
696 }
697 mutex_unlock(&chip->mutex);
698 return changed;
699}
700
701static const struct snd_kcontrol_new rolloff_control = {
702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
703 .name = "DAC Filter Playback Enum",
704 .info = rolloff_info,
705 .get = rolloff_get,
706 .put = rolloff_put,
707};
708
709static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
710{
711 static const char *const names[2] = { "64x", "128x" };
712
713 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
714 info->count = 1;
715 info->value.enumerated.items = 2;
716 if (info->value.enumerated.item >= 2)
717 info->value.enumerated.item = 1;
718 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
719 return 0;
720}
721
722static int os_128_get(struct snd_kcontrol *ctl,
723 struct snd_ctl_elem_value *value)
724{
725 struct oxygen *chip = ctl->private_data;
726 struct xonar_pcm179x *data = chip->model_data;
727
728 value->value.enumerated.item[0] = data->os_128;
729 return 0;
730}
731
732static int os_128_put(struct snd_kcontrol *ctl,
733 struct snd_ctl_elem_value *value)
734{
735 struct oxygen *chip = ctl->private_data;
736 struct xonar_pcm179x *data = chip->model_data;
737 int changed;
738
739 mutex_lock(&chip->mutex);
740 changed = value->value.enumerated.item[0] != data->os_128;
741 if (changed) {
742 data->os_128 = value->value.enumerated.item[0];
743 if (data->has_cs2000)
744 update_cs2000_rate(chip, data->current_rate);
745 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
746 mclk_from_rate(chip, data->current_rate),
747 OXYGEN_I2S_MCLK_MASK);
748 update_pcm1796_oversampling(chip);
749 }
750 mutex_unlock(&chip->mutex);
751 return changed;
752}
753
754static const struct snd_kcontrol_new os_128_control = {
755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
756 .name = "DAC Oversampling Playback Enum",
757 .info = os_128_info,
758 .get = os_128_get,
759 .put = os_128_put,
760};
761
762static int st_output_switch_info(struct snd_kcontrol *ctl,
763 struct snd_ctl_elem_info *info)
764{
765 static const char *const names[3] = {
766 "Speakers", "Headphones", "FP Headphones"
767 };
768
769 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
770 info->count = 1;
771 info->value.enumerated.items = 3;
772 if (info->value.enumerated.item >= 3)
773 info->value.enumerated.item = 2;
774 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
775 return 0;
776}
777
778static int st_output_switch_get(struct snd_kcontrol *ctl,
779 struct snd_ctl_elem_value *value)
780{
781 struct oxygen *chip = ctl->private_data;
782 u16 gpio;
783
784 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
785 if (!(gpio & GPIO_ST_HP))
786 value->value.enumerated.item[0] = 0;
787 else if (gpio & GPIO_ST_HP_REAR)
788 value->value.enumerated.item[0] = 1;
789 else
790 value->value.enumerated.item[0] = 2;
791 return 0;
792}
793
794
795static int st_output_switch_put(struct snd_kcontrol *ctl,
796 struct snd_ctl_elem_value *value)
797{
798 struct oxygen *chip = ctl->private_data;
799 struct xonar_pcm179x *data = chip->model_data;
800 u16 gpio_old, gpio;
801
802 mutex_lock(&chip->mutex);
803 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
804 gpio = gpio_old;
805 switch (value->value.enumerated.item[0]) {
806 case 0:
807 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
808 break;
809 case 1:
810 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
811 break;
812 case 2:
813 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
814 break;
815 }
816 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
817 data->hp_active = gpio & GPIO_ST_HP;
818 update_pcm1796_volume(chip);
819 mutex_unlock(&chip->mutex);
820 return gpio != gpio_old;
821}
822
823static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
824 struct snd_ctl_elem_info *info)
825{
826 static const char *const names[3] = {
827 "< 64 ohms", "64-300 ohms", "300-600 ohms"
828 };
829
830 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
831 info->count = 1;
832 info->value.enumerated.items = 3;
833 if (info->value.enumerated.item > 2)
834 info->value.enumerated.item = 2;
835 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
836 return 0;
837}
838
839static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
840 struct snd_ctl_elem_value *value)
841{
842 struct oxygen *chip = ctl->private_data;
843 struct xonar_pcm179x *data = chip->model_data;
844
845 mutex_lock(&chip->mutex);
846 if (data->hp_gain_offset < 2*-6)
847 value->value.enumerated.item[0] = 0;
848 else if (data->hp_gain_offset < 0)
849 value->value.enumerated.item[0] = 1;
850 else
851 value->value.enumerated.item[0] = 2;
852 mutex_unlock(&chip->mutex);
853 return 0;
854}
855
856
857static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
858 struct snd_ctl_elem_value *value)
859{
860 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
861 struct oxygen *chip = ctl->private_data;
862 struct xonar_pcm179x *data = chip->model_data;
863 s8 offset;
864 int changed;
865
866 if (value->value.enumerated.item[0] > 2)
867 return -EINVAL;
868 offset = offsets[value->value.enumerated.item[0]];
869 mutex_lock(&chip->mutex);
870 changed = offset != data->hp_gain_offset;
871 if (changed) {
872 data->hp_gain_offset = offset;
873 update_pcm1796_volume(chip);
874 }
875 mutex_unlock(&chip->mutex);
876 return changed;
877}
878
879static const struct snd_kcontrol_new st_controls[] = {
880 {
881 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
882 .name = "Analog Output",
883 .info = st_output_switch_info,
884 .get = st_output_switch_get,
885 .put = st_output_switch_put,
886 },
887 {
888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
889 .name = "Headphones Impedance Playback Enum",
890 .info = st_hp_volume_offset_info,
891 .get = st_hp_volume_offset_get,
892 .put = st_hp_volume_offset_put,
893 },
894};
895
896static void xonar_line_mic_ac97_switch(struct oxygen *chip,
897 unsigned int reg, unsigned int mute)
898{
899 if (reg == AC97_LINE) {
900 spin_lock_irq(&chip->reg_lock);
901 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
902 mute ? GPIO_INPUT_ROUTE : 0,
903 GPIO_INPUT_ROUTE);
904 spin_unlock_irq(&chip->reg_lock);
905 }
906}
907
908static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
909
910static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
911{
912 if (!strncmp(template->name, "CD Capture ", 11))
913 /* CD in is actually connected to the video in pin */
914 template->private_value ^= AC97_CD ^ AC97_VIDEO;
915 return 0;
916}
917
918static int xonar_st_control_filter(struct snd_kcontrol_new *template)
919{
920 if (!strncmp(template->name, "CD Capture ", 11))
921 return 1; /* no CD input */
922 return 0;
923}
924
925static int add_pcm1796_controls(struct oxygen *chip)
926{
927 int err;
928
929 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
930 if (err < 0)
931 return err;
932 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip));
933 if (err < 0)
934 return err;
935 return 0;
936}
937
938static int xonar_d2_mixer_init(struct oxygen *chip)
939{
940 int err;
941
942 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
943 if (err < 0)
944 return err;
945 err = add_pcm1796_controls(chip);
946 if (err < 0)
947 return err;
948 return 0;
949}
950
951static int xonar_hdav_mixer_init(struct oxygen *chip)
952{
953 return add_pcm1796_controls(chip);
954}
955
956static int xonar_st_mixer_init(struct oxygen *chip)
957{
958 unsigned int i;
959 int err;
960
961 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
962 err = snd_ctl_add(chip->card,
963 snd_ctl_new1(&st_controls[i], chip));
964 if (err < 0)
965 return err;
966 }
967 err = add_pcm1796_controls(chip);
968 if (err < 0)
969 return err;
970 return 0;
971}
972
973static const struct oxygen_model model_xonar_d2 = {
974 .longname = "Asus Virtuoso 200",
975 .chip = "AV200",
976 .init = xonar_d2_init,
977 .control_filter = xonar_d2_control_filter,
978 .mixer_init = xonar_d2_mixer_init,
979 .cleanup = xonar_d2_cleanup,
980 .suspend = xonar_d2_suspend,
981 .resume = xonar_d2_resume,
982 .get_i2s_mclk = get_pcm1796_i2s_mclk,
983 .set_dac_params = set_pcm1796_params,
984 .set_adc_params = xonar_set_cs53x1_params,
985 .update_dac_volume = update_pcm1796_volume,
986 .update_dac_mute = update_pcm1796_mute,
987 .dac_tlv = pcm1796_db_scale,
988 .model_data_size = sizeof(struct xonar_pcm179x),
989 .device_config = PLAYBACK_0_TO_I2S |
990 PLAYBACK_1_TO_SPDIF |
991 CAPTURE_0_FROM_I2S_2 |
992 CAPTURE_1_FROM_SPDIF |
993 MIDI_OUTPUT |
994 MIDI_INPUT,
995 .dac_channels = 8,
996 .dac_volume_min = 255 - 2*60,
997 .dac_volume_max = 255,
998 .misc_flags = OXYGEN_MISC_MIDI,
999 .function_flags = OXYGEN_FUNCTION_SPI |
1000 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1001 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1002 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1003};
1004
1005static const struct oxygen_model model_xonar_hdav = {
1006 .longname = "Asus Virtuoso 200",
1007 .chip = "AV200",
1008 .init = xonar_hdav_init,
1009 .mixer_init = xonar_hdav_mixer_init,
1010 .cleanup = xonar_hdav_cleanup,
1011 .suspend = xonar_hdav_suspend,
1012 .resume = xonar_hdav_resume,
1013 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1014 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1015 .set_dac_params = set_hdav_params,
1016 .set_adc_params = xonar_set_cs53x1_params,
1017 .update_dac_volume = update_pcm1796_volume,
1018 .update_dac_mute = update_pcm1796_mute,
1019 .uart_input = xonar_hdmi_uart_input,
1020 .ac97_switch = xonar_line_mic_ac97_switch,
1021 .dac_tlv = pcm1796_db_scale,
1022 .model_data_size = sizeof(struct xonar_hdav),
1023 .device_config = PLAYBACK_0_TO_I2S |
1024 PLAYBACK_1_TO_SPDIF |
1025 CAPTURE_0_FROM_I2S_2 |
1026 CAPTURE_1_FROM_SPDIF,
1027 .dac_channels = 8,
1028 .dac_volume_min = 255 - 2*60,
1029 .dac_volume_max = 255,
1030 .misc_flags = OXYGEN_MISC_MIDI,
1031 .function_flags = OXYGEN_FUNCTION_2WIRE,
1032 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1033 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1034};
1035
1036static const struct oxygen_model model_xonar_st = {
1037 .longname = "Asus Virtuoso 100",
1038 .chip = "AV200",
1039 .init = xonar_st_init,
1040 .control_filter = xonar_st_control_filter,
1041 .mixer_init = xonar_st_mixer_init,
1042 .cleanup = xonar_st_cleanup,
1043 .suspend = xonar_st_suspend,
1044 .resume = xonar_st_resume,
1045 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1046 .set_dac_params = set_st_params,
1047 .set_adc_params = xonar_set_cs53x1_params,
1048 .update_dac_volume = update_pcm1796_volume,
1049 .update_dac_mute = update_pcm1796_mute,
1050 .ac97_switch = xonar_line_mic_ac97_switch,
1051 .dac_tlv = pcm1796_db_scale,
1052 .model_data_size = sizeof(struct xonar_pcm179x),
1053 .device_config = PLAYBACK_0_TO_I2S |
1054 PLAYBACK_1_TO_SPDIF |
1055 CAPTURE_0_FROM_I2S_2,
1056 .dac_channels = 2,
1057 .dac_volume_min = 255 - 2*60,
1058 .dac_volume_max = 255,
1059 .function_flags = OXYGEN_FUNCTION_2WIRE,
1060 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1061 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1062};
1063
1064int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1065 const struct pci_device_id *id)
1066{
1067 switch (id->subdevice) {
1068 case 0x8269:
1069 chip->model = model_xonar_d2;
1070 chip->model.shortname = "Xonar D2";
1071 break;
1072 case 0x82b7:
1073 chip->model = model_xonar_d2;
1074 chip->model.shortname = "Xonar D2X";
1075 chip->model.init = xonar_d2x_init;
1076 break;
1077 case 0x8314:
1078 chip->model = model_xonar_hdav;
1079 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1080 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1081 default:
1082 chip->model.shortname = "Xonar HDAV1.3";
1083 break;
1084 case GPIO_DB_H6:
1085 chip->model.shortname = "Xonar HDAV1.3+H6";
1086 chip->model.private_data = 1;
1087 break;
1088 }
1089 break;
1090 case 0x835d:
1091 chip->model = model_xonar_st;
1092 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1093 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1094 default:
1095 chip->model.shortname = "Xonar ST";
1096 break;
1097 case GPIO_DB_H6:
1098 chip->model.shortname = "Xonar ST+H6";
1099 chip->model.dac_channels = 8;
1100 chip->model.private_data = 1;
1101 break;
1102 }
1103 break;
1104 case 0x835c:
1105 chip->model = model_xonar_st;
1106 chip->model.shortname = "Xonar STX";
1107 chip->model.init = xonar_stx_init;
1108 chip->model.resume = xonar_stx_resume;
1109 chip->model.set_dac_params = set_pcm1796_params;
1110 break;
1111 default:
1112 return -EINVAL;
1113 }
1114 return 0;
1115}
diff --git a/sound/pci/oxygen/xonar_wm87x6.c b/sound/pci/oxygen/xonar_wm87x6.c
new file mode 100644
index 000000000000..dbc4b89d74e4
--- /dev/null
+++ b/sound/pci/oxygen/xonar_wm87x6.c
@@ -0,0 +1,1021 @@
1/*
2 * card driver for models with WM8776/WM8766 DACs (Xonar DS)
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
9 *
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Xonar DS
21 * --------
22 *
23 * CMI8788:
24 *
25 * SPI 0 -> WM8766 (surround, center/LFE, back)
26 * SPI 1 -> WM8776 (front, input)
27 *
28 * GPIO 4 <- headphone detect
29 * GPIO 6 -> route input jack to input 1/2 (1/0)
30 * GPIO 7 -> enable output to speakers
31 * GPIO 8 -> enable output to speakers
32 */
33
34#include <linux/pci.h>
35#include <linux/delay.h>
36#include <sound/control.h>
37#include <sound/core.h>
38#include <sound/pcm.h>
39#include <sound/pcm_params.h>
40#include <sound/tlv.h>
41#include "xonar.h"
42#include "wm8776.h"
43#include "wm8766.h"
44
45#define GPIO_DS_HP_DETECT 0x0010
46#define GPIO_DS_INPUT_ROUTE 0x0040
47#define GPIO_DS_OUTPUT_ENABLE 0x0180
48
49#define LC_CONTROL_LIMITER 0x40000000
50#define LC_CONTROL_ALC 0x20000000
51
52struct xonar_wm87x6 {
53 struct xonar_generic generic;
54 u16 wm8776_regs[0x17];
55 u16 wm8766_regs[0x10];
56 struct snd_kcontrol *lc_controls[13];
57};
58
59static void wm8776_write(struct oxygen *chip,
60 unsigned int reg, unsigned int value)
61{
62 struct xonar_wm87x6 *data = chip->model_data;
63
64 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
65 OXYGEN_SPI_DATA_LENGTH_2 |
66 OXYGEN_SPI_CLOCK_160 |
67 (1 << OXYGEN_SPI_CODEC_SHIFT) |
68 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
69 (reg << 9) | value);
70 if (reg < ARRAY_SIZE(data->wm8776_regs)) {
71 if (reg >= WM8776_HPLVOL && reg <= WM8776_DACMASTER)
72 value &= ~WM8776_UPDATE;
73 data->wm8776_regs[reg] = value;
74 }
75}
76
77static void wm8776_write_cached(struct oxygen *chip,
78 unsigned int reg, unsigned int value)
79{
80 struct xonar_wm87x6 *data = chip->model_data;
81
82 if (reg >= ARRAY_SIZE(data->wm8776_regs) ||
83 value != data->wm8776_regs[reg])
84 wm8776_write(chip, reg, value);
85}
86
87static void wm8766_write(struct oxygen *chip,
88 unsigned int reg, unsigned int value)
89{
90 struct xonar_wm87x6 *data = chip->model_data;
91
92 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
93 OXYGEN_SPI_DATA_LENGTH_2 |
94 OXYGEN_SPI_CLOCK_160 |
95 (0 << OXYGEN_SPI_CODEC_SHIFT) |
96 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
97 (reg << 9) | value);
98 if (reg < ARRAY_SIZE(data->wm8766_regs))
99 data->wm8766_regs[reg] = value;
100}
101
102static void wm8766_write_cached(struct oxygen *chip,
103 unsigned int reg, unsigned int value)
104{
105 struct xonar_wm87x6 *data = chip->model_data;
106
107 if (reg >= ARRAY_SIZE(data->wm8766_regs) ||
108 value != data->wm8766_regs[reg]) {
109 if ((reg >= WM8766_LDA1 && reg <= WM8766_RDA1) ||
110 (reg >= WM8766_LDA2 && reg <= WM8766_MASTDA))
111 value &= ~WM8766_UPDATE;
112 wm8766_write(chip, reg, value);
113 }
114}
115
116static void wm8776_registers_init(struct oxygen *chip)
117{
118 struct xonar_wm87x6 *data = chip->model_data;
119
120 wm8776_write(chip, WM8776_RESET, 0);
121 wm8776_write(chip, WM8776_DACCTRL1, WM8776_DZCEN |
122 WM8776_PL_LEFT_LEFT | WM8776_PL_RIGHT_RIGHT);
123 wm8776_write(chip, WM8776_DACMUTE, chip->dac_mute ? WM8776_DMUTE : 0);
124 wm8776_write(chip, WM8776_DACIFCTRL,
125 WM8776_DACFMT_LJUST | WM8776_DACWL_24);
126 wm8776_write(chip, WM8776_ADCIFCTRL,
127 data->wm8776_regs[WM8776_ADCIFCTRL]);
128 wm8776_write(chip, WM8776_MSTRCTRL, data->wm8776_regs[WM8776_MSTRCTRL]);
129 wm8776_write(chip, WM8776_PWRDOWN, data->wm8776_regs[WM8776_PWRDOWN]);
130 wm8776_write(chip, WM8776_HPLVOL, data->wm8776_regs[WM8776_HPLVOL]);
131 wm8776_write(chip, WM8776_HPRVOL, data->wm8776_regs[WM8776_HPRVOL] |
132 WM8776_UPDATE);
133 wm8776_write(chip, WM8776_ADCLVOL, data->wm8776_regs[WM8776_ADCLVOL]);
134 wm8776_write(chip, WM8776_ADCRVOL, data->wm8776_regs[WM8776_ADCRVOL]);
135 wm8776_write(chip, WM8776_ADCMUX, data->wm8776_regs[WM8776_ADCMUX]);
136 wm8776_write(chip, WM8776_DACLVOL, chip->dac_volume[0]);
137 wm8776_write(chip, WM8776_DACRVOL, chip->dac_volume[1] | WM8776_UPDATE);
138}
139
140static void wm8766_registers_init(struct oxygen *chip)
141{
142 wm8766_write(chip, WM8766_RESET, 0);
143 wm8766_write(chip, WM8766_INT_CTRL, WM8766_FMT_LJUST | WM8766_IWL_24);
144 wm8766_write(chip, WM8766_DAC_CTRL2,
145 WM8766_ZCD | (chip->dac_mute ? WM8766_DMUTE_MASK : 0));
146 wm8766_write(chip, WM8766_LDA1, chip->dac_volume[2]);
147 wm8766_write(chip, WM8766_RDA1, chip->dac_volume[3]);
148 wm8766_write(chip, WM8766_LDA2, chip->dac_volume[4]);
149 wm8766_write(chip, WM8766_RDA2, chip->dac_volume[5]);
150 wm8766_write(chip, WM8766_LDA3, chip->dac_volume[6]);
151 wm8766_write(chip, WM8766_RDA3, chip->dac_volume[7] | WM8766_UPDATE);
152}
153
154static void wm8776_init(struct oxygen *chip)
155{
156 struct xonar_wm87x6 *data = chip->model_data;
157
158 data->wm8776_regs[WM8776_HPLVOL] = (0x79 - 60) | WM8776_HPZCEN;
159 data->wm8776_regs[WM8776_HPRVOL] = (0x79 - 60) | WM8776_HPZCEN;
160 data->wm8776_regs[WM8776_ADCIFCTRL] =
161 WM8776_ADCFMT_LJUST | WM8776_ADCWL_24 | WM8776_ADCMCLK;
162 data->wm8776_regs[WM8776_MSTRCTRL] =
163 WM8776_ADCRATE_256 | WM8776_DACRATE_256;
164 data->wm8776_regs[WM8776_PWRDOWN] = WM8776_HPPD;
165 data->wm8776_regs[WM8776_ADCLVOL] = 0xa5 | WM8776_ZCA;
166 data->wm8776_regs[WM8776_ADCRVOL] = 0xa5 | WM8776_ZCA;
167 data->wm8776_regs[WM8776_ADCMUX] = 0x001;
168 wm8776_registers_init(chip);
169}
170
171static void xonar_ds_init(struct oxygen *chip)
172{
173 struct xonar_wm87x6 *data = chip->model_data;
174
175 data->generic.anti_pop_delay = 300;
176 data->generic.output_enable_bit = GPIO_DS_OUTPUT_ENABLE;
177
178 wm8776_init(chip);
179 wm8766_registers_init(chip);
180
181 oxygen_write16_masked(chip, OXYGEN_GPIO_CONTROL, GPIO_DS_INPUT_ROUTE,
182 GPIO_DS_HP_DETECT | GPIO_DS_INPUT_ROUTE);
183 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DS_INPUT_ROUTE);
184 oxygen_set_bits16(chip, OXYGEN_GPIO_INTERRUPT_MASK, GPIO_DS_HP_DETECT);
185 chip->interrupt_mask |= OXYGEN_INT_GPIO;
186
187 xonar_enable_output(chip);
188
189 snd_component_add(chip->card, "WM8776");
190 snd_component_add(chip->card, "WM8766");
191}
192
193static void xonar_ds_cleanup(struct oxygen *chip)
194{
195 xonar_disable_output(chip);
196}
197
198static void xonar_ds_suspend(struct oxygen *chip)
199{
200 xonar_ds_cleanup(chip);
201}
202
203static void xonar_ds_resume(struct oxygen *chip)
204{
205 wm8776_registers_init(chip);
206 wm8766_registers_init(chip);
207 xonar_enable_output(chip);
208}
209
210static void wm8776_adc_hardware_filter(unsigned int channel,
211 struct snd_pcm_hardware *hardware)
212{
213 if (channel == PCM_A) {
214 hardware->rates = SNDRV_PCM_RATE_32000 |
215 SNDRV_PCM_RATE_44100 |
216 SNDRV_PCM_RATE_48000 |
217 SNDRV_PCM_RATE_64000 |
218 SNDRV_PCM_RATE_88200 |
219 SNDRV_PCM_RATE_96000;
220 hardware->rate_max = 96000;
221 }
222}
223
224static void set_wm87x6_dac_params(struct oxygen *chip,
225 struct snd_pcm_hw_params *params)
226{
227}
228
229static void set_wm8776_adc_params(struct oxygen *chip,
230 struct snd_pcm_hw_params *params)
231{
232 u16 reg;
233
234 reg = WM8776_ADCRATE_256 | WM8776_DACRATE_256;
235 if (params_rate(params) > 48000)
236 reg |= WM8776_ADCOSR;
237 wm8776_write_cached(chip, WM8776_MSTRCTRL, reg);
238}
239
240static void update_wm8776_volume(struct oxygen *chip)
241{
242 struct xonar_wm87x6 *data = chip->model_data;
243 u8 to_change;
244
245 if (chip->dac_volume[0] == chip->dac_volume[1]) {
246 if (chip->dac_volume[0] != data->wm8776_regs[WM8776_DACLVOL] ||
247 chip->dac_volume[1] != data->wm8776_regs[WM8776_DACRVOL]) {
248 wm8776_write(chip, WM8776_DACMASTER,
249 chip->dac_volume[0] | WM8776_UPDATE);
250 data->wm8776_regs[WM8776_DACLVOL] = chip->dac_volume[0];
251 data->wm8776_regs[WM8776_DACRVOL] = chip->dac_volume[0];
252 }
253 } else {
254 to_change = (chip->dac_volume[0] !=
255 data->wm8776_regs[WM8776_DACLVOL]) << 0;
256 to_change |= (chip->dac_volume[1] !=
257 data->wm8776_regs[WM8776_DACLVOL]) << 1;
258 if (to_change & 1)
259 wm8776_write(chip, WM8776_DACLVOL, chip->dac_volume[0] |
260 ((to_change & 2) ? 0 : WM8776_UPDATE));
261 if (to_change & 2)
262 wm8776_write(chip, WM8776_DACRVOL,
263 chip->dac_volume[1] | WM8776_UPDATE);
264 }
265}
266
267static void update_wm87x6_volume(struct oxygen *chip)
268{
269 static const u8 wm8766_regs[6] = {
270 WM8766_LDA1, WM8766_RDA1,
271 WM8766_LDA2, WM8766_RDA2,
272 WM8766_LDA3, WM8766_RDA3,
273 };
274 struct xonar_wm87x6 *data = chip->model_data;
275 unsigned int i;
276 u8 to_change;
277
278 update_wm8776_volume(chip);
279 if (chip->dac_volume[2] == chip->dac_volume[3] &&
280 chip->dac_volume[2] == chip->dac_volume[4] &&
281 chip->dac_volume[2] == chip->dac_volume[5] &&
282 chip->dac_volume[2] == chip->dac_volume[6] &&
283 chip->dac_volume[2] == chip->dac_volume[7]) {
284 to_change = 0;
285 for (i = 0; i < 6; ++i)
286 if (chip->dac_volume[2] !=
287 data->wm8766_regs[wm8766_regs[i]])
288 to_change = 1;
289 if (to_change) {
290 wm8766_write(chip, WM8766_MASTDA,
291 chip->dac_volume[2] | WM8766_UPDATE);
292 for (i = 0; i < 6; ++i)
293 data->wm8766_regs[wm8766_regs[i]] =
294 chip->dac_volume[2];
295 }
296 } else {
297 to_change = 0;
298 for (i = 0; i < 6; ++i)
299 to_change |= (chip->dac_volume[2 + i] !=
300 data->wm8766_regs[wm8766_regs[i]]) << i;
301 for (i = 0; i < 6; ++i)
302 if (to_change & (1 << i))
303 wm8766_write(chip, wm8766_regs[i],
304 chip->dac_volume[2 + i] |
305 ((to_change & (0x3e << i))
306 ? 0 : WM8766_UPDATE));
307 }
308}
309
310static void update_wm8776_mute(struct oxygen *chip)
311{
312 wm8776_write_cached(chip, WM8776_DACMUTE,
313 chip->dac_mute ? WM8776_DMUTE : 0);
314}
315
316static void update_wm87x6_mute(struct oxygen *chip)
317{
318 update_wm8776_mute(chip);
319 wm8766_write_cached(chip, WM8766_DAC_CTRL2, WM8766_ZCD |
320 (chip->dac_mute ? WM8766_DMUTE_MASK : 0));
321}
322
323static void xonar_ds_gpio_changed(struct oxygen *chip)
324{
325 u16 bits;
326
327 bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
328 snd_printk(KERN_INFO "HP detect: %d\n", !!(bits & GPIO_DS_HP_DETECT));
329}
330
331static int wm8776_bit_switch_get(struct snd_kcontrol *ctl,
332 struct snd_ctl_elem_value *value)
333{
334 struct oxygen *chip = ctl->private_data;
335 struct xonar_wm87x6 *data = chip->model_data;
336 u16 bit = ctl->private_value & 0xffff;
337 unsigned int reg_index = (ctl->private_value >> 16) & 0xff;
338 bool invert = (ctl->private_value >> 24) & 1;
339
340 value->value.integer.value[0] =
341 ((data->wm8776_regs[reg_index] & bit) != 0) ^ invert;
342 return 0;
343}
344
345static int wm8776_bit_switch_put(struct snd_kcontrol *ctl,
346 struct snd_ctl_elem_value *value)
347{
348 struct oxygen *chip = ctl->private_data;
349 struct xonar_wm87x6 *data = chip->model_data;
350 u16 bit = ctl->private_value & 0xffff;
351 u16 reg_value;
352 unsigned int reg_index = (ctl->private_value >> 16) & 0xff;
353 bool invert = (ctl->private_value >> 24) & 1;
354 int changed;
355
356 mutex_lock(&chip->mutex);
357 reg_value = data->wm8776_regs[reg_index] & ~bit;
358 if (value->value.integer.value[0] ^ invert)
359 reg_value |= bit;
360 changed = reg_value != data->wm8776_regs[reg_index];
361 if (changed)
362 wm8776_write(chip, reg_index, reg_value);
363 mutex_unlock(&chip->mutex);
364 return changed;
365}
366
367static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
368 struct snd_ctl_elem_info *info)
369{
370 static const char *const hld[16] = {
371 "0 ms", "2.67 ms", "5.33 ms", "10.6 ms",
372 "21.3 ms", "42.7 ms", "85.3 ms", "171 ms",
373 "341 ms", "683 ms", "1.37 s", "2.73 s",
374 "5.46 s", "10.9 s", "21.8 s", "43.7 s",
375 };
376 static const char *const atk_lim[11] = {
377 "0.25 ms", "0.5 ms", "1 ms", "2 ms",
378 "4 ms", "8 ms", "16 ms", "32 ms",
379 "64 ms", "128 ms", "256 ms",
380 };
381 static const char *const atk_alc[11] = {
382 "8.40 ms", "16.8 ms", "33.6 ms", "67.2 ms",
383 "134 ms", "269 ms", "538 ms", "1.08 s",
384 "2.15 s", "4.3 s", "8.6 s",
385 };
386 static const char *const dcy_lim[11] = {
387 "1.2 ms", "2.4 ms", "4.8 ms", "9.6 ms",
388 "19.2 ms", "38.4 ms", "76.8 ms", "154 ms",
389 "307 ms", "614 ms", "1.23 s",
390 };
391 static const char *const dcy_alc[11] = {
392 "33.5 ms", "67.0 ms", "134 ms", "268 ms",
393 "536 ms", "1.07 s", "2.14 s", "4.29 s",
394 "8.58 s", "17.2 s", "34.3 s",
395 };
396 static const char *const tranwin[8] = {
397 "0 us", "62.5 us", "125 us", "250 us",
398 "500 us", "1 ms", "2 ms", "4 ms",
399 };
400 u8 max;
401 const char *const *names;
402
403 max = (ctl->private_value >> 12) & 0xf;
404 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
405 info->count = 1;
406 info->value.enumerated.items = max + 1;
407 if (info->value.enumerated.item > max)
408 info->value.enumerated.item = max;
409 switch ((ctl->private_value >> 24) & 0x1f) {
410 case WM8776_ALCCTRL2:
411 names = hld;
412 break;
413 case WM8776_ALCCTRL3:
414 if (((ctl->private_value >> 20) & 0xf) == 0) {
415 if (ctl->private_value & LC_CONTROL_LIMITER)
416 names = atk_lim;
417 else
418 names = atk_alc;
419 } else {
420 if (ctl->private_value & LC_CONTROL_LIMITER)
421 names = dcy_lim;
422 else
423 names = dcy_alc;
424 }
425 break;
426 case WM8776_LIMITER:
427 names = tranwin;
428 break;
429 default:
430 return -ENXIO;
431 }
432 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
433 return 0;
434}
435
436static int wm8776_field_volume_info(struct snd_kcontrol *ctl,
437 struct snd_ctl_elem_info *info)
438{
439 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
440 info->count = 1;
441 info->value.integer.min = (ctl->private_value >> 8) & 0xf;
442 info->value.integer.max = (ctl->private_value >> 12) & 0xf;
443 return 0;
444}
445
446static void wm8776_field_set_from_ctl(struct snd_kcontrol *ctl)
447{
448 struct oxygen *chip = ctl->private_data;
449 struct xonar_wm87x6 *data = chip->model_data;
450 unsigned int value, reg_index, mode;
451 u8 min, max, shift;
452 u16 mask, reg_value;
453 bool invert;
454
455 if ((data->wm8776_regs[WM8776_ALCCTRL1] & WM8776_LCSEL_MASK) ==
456 WM8776_LCSEL_LIMITER)
457 mode = LC_CONTROL_LIMITER;
458 else
459 mode = LC_CONTROL_ALC;
460 if (!(ctl->private_value & mode))
461 return;
462
463 value = ctl->private_value & 0xf;
464 min = (ctl->private_value >> 8) & 0xf;
465 max = (ctl->private_value >> 12) & 0xf;
466 mask = (ctl->private_value >> 16) & 0xf;
467 shift = (ctl->private_value >> 20) & 0xf;
468 reg_index = (ctl->private_value >> 24) & 0x1f;
469 invert = (ctl->private_value >> 29) & 0x1;
470
471 if (invert)
472 value = max - (value - min);
473 reg_value = data->wm8776_regs[reg_index];
474 reg_value &= ~(mask << shift);
475 reg_value |= value << shift;
476 wm8776_write_cached(chip, reg_index, reg_value);
477}
478
479static int wm8776_field_set(struct snd_kcontrol *ctl, unsigned int value)
480{
481 struct oxygen *chip = ctl->private_data;
482 u8 min, max;
483 int changed;
484
485 min = (ctl->private_value >> 8) & 0xf;
486 max = (ctl->private_value >> 12) & 0xf;
487 if (value < min || value > max)
488 return -EINVAL;
489 mutex_lock(&chip->mutex);
490 changed = value != (ctl->private_value & 0xf);
491 if (changed) {
492 ctl->private_value = (ctl->private_value & ~0xf) | value;
493 wm8776_field_set_from_ctl(ctl);
494 }
495 mutex_unlock(&chip->mutex);
496 return changed;
497}
498
499static int wm8776_field_enum_get(struct snd_kcontrol *ctl,
500 struct snd_ctl_elem_value *value)
501{
502 value->value.enumerated.item[0] = ctl->private_value & 0xf;
503 return 0;
504}
505
506static int wm8776_field_volume_get(struct snd_kcontrol *ctl,
507 struct snd_ctl_elem_value *value)
508{
509 value->value.integer.value[0] = ctl->private_value & 0xf;
510 return 0;
511}
512
513static int wm8776_field_enum_put(struct snd_kcontrol *ctl,
514 struct snd_ctl_elem_value *value)
515{
516 return wm8776_field_set(ctl, value->value.enumerated.item[0]);
517}
518
519static int wm8776_field_volume_put(struct snd_kcontrol *ctl,
520 struct snd_ctl_elem_value *value)
521{
522 return wm8776_field_set(ctl, value->value.integer.value[0]);
523}
524
525static int wm8776_hp_vol_info(struct snd_kcontrol *ctl,
526 struct snd_ctl_elem_info *info)
527{
528 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
529 info->count = 2;
530 info->value.integer.min = 0x79 - 60;
531 info->value.integer.max = 0x7f;
532 return 0;
533}
534
535static int wm8776_hp_vol_get(struct snd_kcontrol *ctl,
536 struct snd_ctl_elem_value *value)
537{
538 struct oxygen *chip = ctl->private_data;
539 struct xonar_wm87x6 *data = chip->model_data;
540
541 mutex_lock(&chip->mutex);
542 value->value.integer.value[0] =
543 data->wm8776_regs[WM8776_HPLVOL] & WM8776_HPATT_MASK;
544 value->value.integer.value[1] =
545 data->wm8776_regs[WM8776_HPRVOL] & WM8776_HPATT_MASK;
546 mutex_unlock(&chip->mutex);
547 return 0;
548}
549
550static int wm8776_hp_vol_put(struct snd_kcontrol *ctl,
551 struct snd_ctl_elem_value *value)
552{
553 struct oxygen *chip = ctl->private_data;
554 struct xonar_wm87x6 *data = chip->model_data;
555 u8 to_update;
556
557 mutex_lock(&chip->mutex);
558 to_update = (value->value.integer.value[0] !=
559 (data->wm8776_regs[WM8776_HPLVOL] & WM8776_HPATT_MASK))
560 << 0;
561 to_update |= (value->value.integer.value[1] !=
562 (data->wm8776_regs[WM8776_HPRVOL] & WM8776_HPATT_MASK))
563 << 1;
564 if (value->value.integer.value[0] == value->value.integer.value[1]) {
565 if (to_update) {
566 wm8776_write(chip, WM8776_HPMASTER,
567 value->value.integer.value[0] |
568 WM8776_HPZCEN | WM8776_UPDATE);
569 data->wm8776_regs[WM8776_HPLVOL] =
570 value->value.integer.value[0] | WM8776_HPZCEN;
571 data->wm8776_regs[WM8776_HPRVOL] =
572 value->value.integer.value[0] | WM8776_HPZCEN;
573 }
574 } else {
575 if (to_update & 1)
576 wm8776_write(chip, WM8776_HPLVOL,
577 value->value.integer.value[0] |
578 WM8776_HPZCEN |
579 ((to_update & 2) ? 0 : WM8776_UPDATE));
580 if (to_update & 2)
581 wm8776_write(chip, WM8776_HPRVOL,
582 value->value.integer.value[1] |
583 WM8776_HPZCEN | WM8776_UPDATE);
584 }
585 mutex_unlock(&chip->mutex);
586 return to_update != 0;
587}
588
589static int wm8776_input_mux_get(struct snd_kcontrol *ctl,
590 struct snd_ctl_elem_value *value)
591{
592 struct oxygen *chip = ctl->private_data;
593 struct xonar_wm87x6 *data = chip->model_data;
594 unsigned int mux_bit = ctl->private_value;
595
596 value->value.integer.value[0] =
597 !!(data->wm8776_regs[WM8776_ADCMUX] & mux_bit);
598 return 0;
599}
600
601static int wm8776_input_mux_put(struct snd_kcontrol *ctl,
602 struct snd_ctl_elem_value *value)
603{
604 struct oxygen *chip = ctl->private_data;
605 struct xonar_wm87x6 *data = chip->model_data;
606 unsigned int mux_bit = ctl->private_value;
607 u16 reg;
608 int changed;
609
610 mutex_lock(&chip->mutex);
611 reg = data->wm8776_regs[WM8776_ADCMUX];
612 if (value->value.integer.value[0]) {
613 reg &= ~0x003;
614 reg |= mux_bit;
615 } else
616 reg &= ~mux_bit;
617 changed = reg != data->wm8776_regs[WM8776_ADCMUX];
618 if (changed) {
619 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
620 reg & 1 ? GPIO_DS_INPUT_ROUTE : 0,
621 GPIO_DS_INPUT_ROUTE);
622 wm8776_write(chip, WM8776_ADCMUX, reg);
623 }
624 mutex_unlock(&chip->mutex);
625 return changed;
626}
627
628static int wm8776_input_vol_info(struct snd_kcontrol *ctl,
629 struct snd_ctl_elem_info *info)
630{
631 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
632 info->count = 2;
633 info->value.integer.min = 0xa5;
634 info->value.integer.max = 0xff;
635 return 0;
636}
637
638static int wm8776_input_vol_get(struct snd_kcontrol *ctl,
639 struct snd_ctl_elem_value *value)
640{
641 struct oxygen *chip = ctl->private_data;
642 struct xonar_wm87x6 *data = chip->model_data;
643
644 mutex_lock(&chip->mutex);
645 value->value.integer.value[0] =
646 data->wm8776_regs[WM8776_ADCLVOL] & WM8776_AGMASK;
647 value->value.integer.value[1] =
648 data->wm8776_regs[WM8776_ADCRVOL] & WM8776_AGMASK;
649 mutex_unlock(&chip->mutex);
650 return 0;
651}
652
653static int wm8776_input_vol_put(struct snd_kcontrol *ctl,
654 struct snd_ctl_elem_value *value)
655{
656 struct oxygen *chip = ctl->private_data;
657 struct xonar_wm87x6 *data = chip->model_data;
658 int changed = 0;
659
660 mutex_lock(&chip->mutex);
661 changed = (value->value.integer.value[0] !=
662 (data->wm8776_regs[WM8776_ADCLVOL] & WM8776_AGMASK)) ||
663 (value->value.integer.value[1] !=
664 (data->wm8776_regs[WM8776_ADCRVOL] & WM8776_AGMASK));
665 wm8776_write_cached(chip, WM8776_ADCLVOL,
666 value->value.integer.value[0] | WM8776_ZCA);
667 wm8776_write_cached(chip, WM8776_ADCRVOL,
668 value->value.integer.value[1] | WM8776_ZCA);
669 mutex_unlock(&chip->mutex);
670 return changed;
671}
672
673static int wm8776_level_control_info(struct snd_kcontrol *ctl,
674 struct snd_ctl_elem_info *info)
675{
676 static const char *const names[3] = {
677 "None", "Peak Limiter", "Automatic Level Control"
678 };
679 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
680 info->count = 1;
681 info->value.enumerated.items = 3;
682 if (info->value.enumerated.item >= 3)
683 info->value.enumerated.item = 2;
684 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
685 return 0;
686}
687
688static int wm8776_level_control_get(struct snd_kcontrol *ctl,
689 struct snd_ctl_elem_value *value)
690{
691 struct oxygen *chip = ctl->private_data;
692 struct xonar_wm87x6 *data = chip->model_data;
693
694 if (!(data->wm8776_regs[WM8776_ALCCTRL2] & WM8776_LCEN))
695 value->value.enumerated.item[0] = 0;
696 else if ((data->wm8776_regs[WM8776_ALCCTRL1] & WM8776_LCSEL_MASK) ==
697 WM8776_LCSEL_LIMITER)
698 value->value.enumerated.item[0] = 1;
699 else
700 value->value.enumerated.item[0] = 2;
701 return 0;
702}
703
704static void activate_control(struct oxygen *chip,
705 struct snd_kcontrol *ctl, unsigned int mode)
706{
707 unsigned int access;
708
709 if (ctl->private_value & mode)
710 access = 0;
711 else
712 access = SNDRV_CTL_ELEM_ACCESS_INACTIVE;
713 if ((ctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_INACTIVE) != access) {
714 ctl->vd[0].access ^= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
715 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
716 }
717}
718
719static int wm8776_level_control_put(struct snd_kcontrol *ctl,
720 struct snd_ctl_elem_value *value)
721{
722 struct oxygen *chip = ctl->private_data;
723 struct xonar_wm87x6 *data = chip->model_data;
724 unsigned int mode = 0, i;
725 u16 ctrl1, ctrl2;
726 int changed;
727
728 if (value->value.enumerated.item[0] >= 3)
729 return -EINVAL;
730 mutex_lock(&chip->mutex);
731 changed = value->value.enumerated.item[0] != ctl->private_value;
732 if (changed) {
733 ctl->private_value = value->value.enumerated.item[0];
734 ctrl1 = data->wm8776_regs[WM8776_ALCCTRL1];
735 ctrl2 = data->wm8776_regs[WM8776_ALCCTRL2];
736 switch (value->value.enumerated.item[0]) {
737 default:
738 wm8776_write_cached(chip, WM8776_ALCCTRL2,
739 ctrl2 & ~WM8776_LCEN);
740 break;
741 case 1:
742 wm8776_write_cached(chip, WM8776_ALCCTRL1,
743 (ctrl1 & ~WM8776_LCSEL_MASK) |
744 WM8776_LCSEL_LIMITER);
745 wm8776_write_cached(chip, WM8776_ALCCTRL2,
746 ctrl2 | WM8776_LCEN);
747 mode = LC_CONTROL_LIMITER;
748 break;
749 case 2:
750 wm8776_write_cached(chip, WM8776_ALCCTRL1,
751 (ctrl1 & ~WM8776_LCSEL_MASK) |
752 WM8776_LCSEL_ALC_STEREO);
753 wm8776_write_cached(chip, WM8776_ALCCTRL2,
754 ctrl2 | WM8776_LCEN);
755 mode = LC_CONTROL_ALC;
756 break;
757 }
758 for (i = 0; i < ARRAY_SIZE(data->lc_controls); ++i)
759 activate_control(chip, data->lc_controls[i], mode);
760 }
761 mutex_unlock(&chip->mutex);
762 return changed;
763}
764
765static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
766{
767 static const char *const names[2] = {
768 "None", "High-pass Filter"
769 };
770
771 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
772 info->count = 1;
773 info->value.enumerated.items = 2;
774 if (info->value.enumerated.item >= 2)
775 info->value.enumerated.item = 1;
776 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
777 return 0;
778}
779
780static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
781{
782 struct oxygen *chip = ctl->private_data;
783 struct xonar_wm87x6 *data = chip->model_data;
784
785 value->value.enumerated.item[0] =
786 !(data->wm8776_regs[WM8776_ADCIFCTRL] & WM8776_ADCHPD);
787 return 0;
788}
789
790static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
791{
792 struct oxygen *chip = ctl->private_data;
793 struct xonar_wm87x6 *data = chip->model_data;
794 unsigned int reg;
795 int changed;
796
797 mutex_lock(&chip->mutex);
798 reg = data->wm8776_regs[WM8776_ADCIFCTRL] & ~WM8776_ADCHPD;
799 if (!value->value.enumerated.item[0])
800 reg |= WM8776_ADCHPD;
801 changed = reg != data->wm8776_regs[WM8776_ADCIFCTRL];
802 if (changed)
803 wm8776_write(chip, WM8776_ADCIFCTRL, reg);
804 mutex_unlock(&chip->mutex);
805 return changed;
806}
807
808#define WM8776_BIT_SWITCH(xname, reg, bit, invert, flags) { \
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
810 .name = xname, \
811 .info = snd_ctl_boolean_mono_info, \
812 .get = wm8776_bit_switch_get, \
813 .put = wm8776_bit_switch_put, \
814 .private_value = ((reg) << 16) | (bit) | ((invert) << 24) | (flags), \
815}
816#define _WM8776_FIELD_CTL(xname, reg, shift, initval, min, max, mask, flags) \
817 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
818 .name = xname, \
819 .private_value = (initval) | ((min) << 8) | ((max) << 12) | \
820 ((mask) << 16) | ((shift) << 20) | ((reg) << 24) | (flags)
821#define WM8776_FIELD_CTL_ENUM(xname, reg, shift, init, min, max, mask, flags) {\
822 _WM8776_FIELD_CTL(xname " Capture Enum", \
823 reg, shift, init, min, max, mask, flags), \
824 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
825 SNDRV_CTL_ELEM_ACCESS_INACTIVE, \
826 .info = wm8776_field_enum_info, \
827 .get = wm8776_field_enum_get, \
828 .put = wm8776_field_enum_put, \
829}
830#define WM8776_FIELD_CTL_VOLUME(a, b, c, d, e, f, g, h, tlv_p) { \
831 _WM8776_FIELD_CTL(a " Capture Volume", b, c, d, e, f, g, h), \
832 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
833 SNDRV_CTL_ELEM_ACCESS_INACTIVE | \
834 SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
835 .info = wm8776_field_volume_info, \
836 .get = wm8776_field_volume_get, \
837 .put = wm8776_field_volume_put, \
838 .tlv = { .p = tlv_p }, \
839}
840
841static const DECLARE_TLV_DB_SCALE(wm87x6_dac_db_scale, -6000, 50, 0);
842static const DECLARE_TLV_DB_SCALE(wm8776_adc_db_scale, -2100, 50, 0);
843static const DECLARE_TLV_DB_SCALE(wm8776_hp_db_scale, -6000, 100, 0);
844static const DECLARE_TLV_DB_SCALE(wm8776_lct_db_scale, -1600, 100, 0);
845static const DECLARE_TLV_DB_SCALE(wm8776_maxgain_db_scale, 0, 400, 0);
846static const DECLARE_TLV_DB_SCALE(wm8776_ngth_db_scale, -7800, 600, 0);
847static const DECLARE_TLV_DB_SCALE(wm8776_maxatten_lim_db_scale, -1200, 100, 0);
848static const DECLARE_TLV_DB_SCALE(wm8776_maxatten_alc_db_scale, -2100, 400, 0);
849
850static const struct snd_kcontrol_new ds_controls[] = {
851 {
852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
853 .name = "Headphone Playback Volume",
854 .info = wm8776_hp_vol_info,
855 .get = wm8776_hp_vol_get,
856 .put = wm8776_hp_vol_put,
857 .tlv = { .p = wm8776_hp_db_scale },
858 },
859 WM8776_BIT_SWITCH("Headphone Playback Switch",
860 WM8776_PWRDOWN, WM8776_HPPD, 1, 0),
861 {
862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
863 .name = "Input Capture Volume",
864 .info = wm8776_input_vol_info,
865 .get = wm8776_input_vol_get,
866 .put = wm8776_input_vol_put,
867 .tlv = { .p = wm8776_adc_db_scale },
868 },
869 {
870 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
871 .name = "Line Capture Switch",
872 .info = snd_ctl_boolean_mono_info,
873 .get = wm8776_input_mux_get,
874 .put = wm8776_input_mux_put,
875 .private_value = 1 << 0,
876 },
877 {
878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
879 .name = "Mic Capture Switch",
880 .info = snd_ctl_boolean_mono_info,
881 .get = wm8776_input_mux_get,
882 .put = wm8776_input_mux_put,
883 .private_value = 1 << 1,
884 },
885 WM8776_BIT_SWITCH("Aux", WM8776_ADCMUX, 1 << 2, 0, 0),
886 {
887 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
888 .name = "ADC Filter Capture Enum",
889 .info = hpf_info,
890 .get = hpf_get,
891 .put = hpf_put,
892 },
893 {
894 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
895 .name = "Level Control Capture Enum",
896 .info = wm8776_level_control_info,
897 .get = wm8776_level_control_get,
898 .put = wm8776_level_control_put,
899 .private_value = 0,
900 },
901};
902static const struct snd_kcontrol_new lc_controls[] = {
903 WM8776_FIELD_CTL_VOLUME("Limiter Threshold",
904 WM8776_ALCCTRL1, 0, 11, 0, 15, 0xf,
905 LC_CONTROL_LIMITER, wm8776_lct_db_scale),
906 WM8776_FIELD_CTL_ENUM("Limiter Attack Time",
907 WM8776_ALCCTRL3, 0, 2, 0, 10, 0xf,
908 LC_CONTROL_LIMITER),
909 WM8776_FIELD_CTL_ENUM("Limiter Decay Time",
910 WM8776_ALCCTRL3, 4, 3, 0, 10, 0xf,
911 LC_CONTROL_LIMITER),
912 WM8776_FIELD_CTL_ENUM("Limiter Transient Window",
913 WM8776_LIMITER, 4, 2, 0, 7, 0x7,
914 LC_CONTROL_LIMITER),
915 WM8776_FIELD_CTL_VOLUME("Limiter Maximum Attenuation",
916 WM8776_LIMITER, 0, 6, 3, 12, 0xf,
917 LC_CONTROL_LIMITER,
918 wm8776_maxatten_lim_db_scale),
919 WM8776_FIELD_CTL_VOLUME("ALC Target Level",
920 WM8776_ALCCTRL1, 0, 11, 0, 15, 0xf,
921 LC_CONTROL_ALC, wm8776_lct_db_scale),
922 WM8776_FIELD_CTL_ENUM("ALC Attack Time",
923 WM8776_ALCCTRL3, 0, 2, 0, 10, 0xf,
924 LC_CONTROL_ALC),
925 WM8776_FIELD_CTL_ENUM("ALC Decay Time",
926 WM8776_ALCCTRL3, 4, 3, 0, 10, 0xf,
927 LC_CONTROL_ALC),
928 WM8776_FIELD_CTL_VOLUME("ALC Maximum Gain",
929 WM8776_ALCCTRL1, 4, 7, 1, 7, 0x7,
930 LC_CONTROL_ALC, wm8776_maxgain_db_scale),
931 WM8776_FIELD_CTL_VOLUME("ALC Maximum Attenuation",
932 WM8776_LIMITER, 0, 10, 10, 15, 0xf,
933 LC_CONTROL_ALC, wm8776_maxatten_alc_db_scale),
934 WM8776_FIELD_CTL_ENUM("ALC Hold Time",
935 WM8776_ALCCTRL2, 0, 0, 0, 15, 0xf,
936 LC_CONTROL_ALC),
937 WM8776_BIT_SWITCH("Noise Gate Capture Switch",
938 WM8776_NOISEGATE, WM8776_NGAT, 0,
939 LC_CONTROL_ALC),
940 WM8776_FIELD_CTL_VOLUME("Noise Gate Threshold",
941 WM8776_NOISEGATE, 2, 0, 0, 7, 0x7,
942 LC_CONTROL_ALC, wm8776_ngth_db_scale),
943};
944
945static int xonar_ds_control_filter(struct snd_kcontrol_new *template)
946{
947 if (!strncmp(template->name, "CD Capture ", 11))
948 return 1; /* no CD input */
949 return 0;
950}
951
952static int xonar_ds_mixer_init(struct oxygen *chip)
953{
954 struct xonar_wm87x6 *data = chip->model_data;
955 unsigned int i;
956 struct snd_kcontrol *ctl;
957 int err;
958
959 for (i = 0; i < ARRAY_SIZE(ds_controls); ++i) {
960 ctl = snd_ctl_new1(&ds_controls[i], chip);
961 if (!ctl)
962 return -ENOMEM;
963 err = snd_ctl_add(chip->card, ctl);
964 if (err < 0)
965 return err;
966 }
967 BUILD_BUG_ON(ARRAY_SIZE(lc_controls) != ARRAY_SIZE(data->lc_controls));
968 for (i = 0; i < ARRAY_SIZE(lc_controls); ++i) {
969 ctl = snd_ctl_new1(&lc_controls[i], chip);
970 if (!ctl)
971 return -ENOMEM;
972 err = snd_ctl_add(chip->card, ctl);
973 if (err < 0)
974 return err;
975 data->lc_controls[i] = ctl;
976 }
977 return 0;
978}
979
980static const struct oxygen_model model_xonar_ds = {
981 .shortname = "Xonar DS",
982 .longname = "Asus Virtuoso 200",
983 .chip = "AV200",
984 .init = xonar_ds_init,
985 .control_filter = xonar_ds_control_filter,
986 .mixer_init = xonar_ds_mixer_init,
987 .cleanup = xonar_ds_cleanup,
988 .suspend = xonar_ds_suspend,
989 .resume = xonar_ds_resume,
990 .pcm_hardware_filter = wm8776_adc_hardware_filter,
991 .get_i2s_mclk = oxygen_default_i2s_mclk,
992 .set_dac_params = set_wm87x6_dac_params,
993 .set_adc_params = set_wm8776_adc_params,
994 .update_dac_volume = update_wm87x6_volume,
995 .update_dac_mute = update_wm87x6_mute,
996 .gpio_changed = xonar_ds_gpio_changed,
997 .dac_tlv = wm87x6_dac_db_scale,
998 .model_data_size = sizeof(struct xonar_wm87x6),
999 .device_config = PLAYBACK_0_TO_I2S |
1000 PLAYBACK_1_TO_SPDIF |
1001 CAPTURE_0_FROM_I2S_1,
1002 .dac_channels = 8,
1003 .dac_volume_min = 255 - 2*60,
1004 .dac_volume_max = 255,
1005 .function_flags = OXYGEN_FUNCTION_SPI,
1006 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1007 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1008};
1009
1010int __devinit get_xonar_wm87x6_model(struct oxygen *chip,
1011 const struct pci_device_id *id)
1012{
1013 switch (id->subdevice) {
1014 case 0x838e:
1015 chip->model = model_xonar_ds;
1016 break;
1017 default:
1018 return -EINVAL;
1019 }
1020 return 0;
1021}
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 833e9c7b27c7..95cfde27d25c 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -94,7 +94,7 @@ enum {
94 PCI_ID_LAST 94 PCI_ID_LAST
95}; 95};
96 96
97static struct pci_device_id pcxhr_ids[] = { 97static DEFINE_PCI_DEVICE_TABLE(pcxhr_ids) = {
98 { 0x10b5, 0x9656, 0x1369, 0xb001, 0, 0, PCI_ID_VX882HR, }, 98 { 0x10b5, 0x9656, 0x1369, 0xb001, 0, 0, PCI_ID_VX882HR, },
99 { 0x10b5, 0x9656, 0x1369, 0xb101, 0, 0, PCI_ID_PCX882HR, }, 99 { 0x10b5, 0x9656, 0x1369, 0xb101, 0, 0, PCI_ID_PCX882HR, },
100 { 0x10b5, 0x9656, 0x1369, 0xb201, 0, 0, PCI_ID_VX881HR, }, 100 { 0x10b5, 0x9656, 0x1369, 0xb201, 0, 0, PCI_ID_VX881HR, },
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index b5ca02e2038c..ad4462677615 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -506,7 +506,7 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip);
506/* 506/*
507 */ 507 */
508 508
509static struct pci_device_id snd_riptide_ids[] = { 509static DEFINE_PCI_DEVICE_TABLE(snd_riptide_ids) = {
510 { PCI_DEVICE(0x127a, 0x4310) }, 510 { PCI_DEVICE(0x127a, 0x4310) },
511 { PCI_DEVICE(0x127a, 0x4320) }, 511 { PCI_DEVICE(0x127a, 0x4320) },
512 { PCI_DEVICE(0x127a, 0x4330) }, 512 { PCI_DEVICE(0x127a, 0x4330) },
@@ -515,7 +515,7 @@ static struct pci_device_id snd_riptide_ids[] = {
515}; 515};
516 516
517#ifdef SUPPORT_JOYSTICK 517#ifdef SUPPORT_JOYSTICK
518static struct pci_device_id snd_riptide_joystick_ids[] __devinitdata = { 518static DEFINE_PCI_DEVICE_TABLE(snd_riptide_joystick_ids) = {
519 { PCI_DEVICE(0x127a, 0x4312) }, 519 { PCI_DEVICE(0x127a, 0x4312) },
520 { PCI_DEVICE(0x127a, 0x4322) }, 520 { PCI_DEVICE(0x127a, 0x4322) },
521 { PCI_DEVICE(0x127a, 0x4332) }, 521 { PCI_DEVICE(0x127a, 0x4332) },
@@ -1058,7 +1058,7 @@ setsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int rate)
1058 rptr.retwords[2] != M && 1058 rptr.retwords[2] != M &&
1059 rptr.retwords[3] != N && 1059 rptr.retwords[3] != N &&
1060 i++ < MAX_WRITE_RETRY); 1060 i++ < MAX_WRITE_RETRY);
1061 if (i == MAX_WRITE_RETRY) { 1061 if (i > MAX_WRITE_RETRY) {
1062 snd_printdd("sent samplerate %d: %d failed\n", 1062 snd_printdd("sent samplerate %d: %d failed\n",
1063 *intdec, rate); 1063 *intdec, rate);
1064 return -EIO; 1064 return -EIO;
@@ -1974,9 +1974,9 @@ snd_riptide_proc_read(struct snd_info_entry *entry,
1974 } 1974 }
1975 snd_iprintf(buffer, "Paths:\n"); 1975 snd_iprintf(buffer, "Paths:\n");
1976 i = getpaths(cif, p); 1976 i = getpaths(cif, p);
1977 while (i--) { 1977 while (i >= 2) {
1978 snd_iprintf(buffer, "%x->%x ", p[i - 1], p[i]); 1978 i -= 2;
1979 i--; 1979 snd_iprintf(buffer, "%x->%x ", p[i], p[i + 1]);
1980 } 1980 }
1981 snd_iprintf(buffer, "\n"); 1981 snd_iprintf(buffer, "\n");
1982} 1982}
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index f977dba7cbd0..3c04524de37c 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -70,10 +70,10 @@
70 70
71 71
72#include <linux/delay.h> 72#include <linux/delay.h>
73#include <linux/gfp.h>
73#include <linux/init.h> 74#include <linux/init.h>
74#include <linux/interrupt.h> 75#include <linux/interrupt.h>
75#include <linux/pci.h> 76#include <linux/pci.h>
76#include <linux/slab.h>
77#include <linux/moduleparam.h> 77#include <linux/moduleparam.h>
78 78
79#include <sound/core.h> 79#include <sound/core.h>
@@ -226,7 +226,7 @@ struct rme32 {
226 struct snd_kcontrol *spdif_ctl; 226 struct snd_kcontrol *spdif_ctl;
227}; 227};
228 228
229static struct pci_device_id snd_rme32_ids[] = { 229static DEFINE_PCI_DEVICE_TABLE(snd_rme32_ids) = {
230 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32), 0,}, 230 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32), 0,},
231 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8), 0,}, 231 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8), 0,},
232 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO), 0,}, 232 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO), 0,},
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 2ba5c0fd55db..d19dc052c391 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -27,7 +27,6 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/slab.h>
31#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
32 31
33#include <sound/core.h> 32#include <sound/core.h>
@@ -231,7 +230,7 @@ struct rme96 {
231 struct snd_kcontrol *spdif_ctl; 230 struct snd_kcontrol *spdif_ctl;
232}; 231};
233 232
234static struct pci_device_id snd_rme96_ids[] = { 233static DEFINE_PCI_DEVICE_TABLE(snd_rme96_ids) = {
235 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96), 0, }, 234 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96), 0, },
236 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8), 0, }, 235 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8), 0, },
237 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO), 0, }, 236 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO), 0, },
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 7bb827c7d806..b92adef8e81e 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -24,7 +24,6 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/slab.h>
28#include <linux/pci.h> 27#include <linux/pci.h>
29#include <linux/firmware.h> 28#include <linux/firmware.h>
30#include <linux/moduleparam.h> 29#include <linux/moduleparam.h>
@@ -585,7 +584,7 @@ static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_d
585} 584}
586 585
587 586
588static struct pci_device_id snd_hdsp_ids[] = { 587static DEFINE_PCI_DEVICE_TABLE(snd_hdsp_ids) = {
589 { 588 {
590 .vendor = PCI_VENDOR_ID_XILINX, 589 .vendor = PCI_VENDOR_ID_XILINX,
591 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP, 590 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 0dce331a2a3b..547b713d7204 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -512,7 +512,7 @@ static char channel_map_madi_ss[HDSPM_MAX_CHANNELS] = {
512}; 512};
513 513
514 514
515static struct pci_device_id snd_hdspm_ids[] __devinitdata = { 515static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = {
516 { 516 {
517 .vendor = PCI_VENDOR_ID_XILINX, 517 .vendor = PCI_VENDOR_ID_XILINX,
518 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI, 518 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
@@ -2479,7 +2479,7 @@ static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol,
2479 on MADICARD 2479 on MADICARD
2480 - playback mixer matrix: [channelout+64] [output] [value] 2480 - playback mixer matrix: [channelout+64] [output] [value]
2481 - input(thru) mixer matrix: [channelin] [output] [value] 2481 - input(thru) mixer matrix: [channelin] [output] [value]
2482 (better do 2 kontrols for seperation ?) 2482 (better do 2 kontrols for separation ?)
2483*/ 2483*/
2484 2484
2485#define HDSPM_MIXER(xname, xindex) \ 2485#define HDSPM_MIXER(xname, xindex) \
@@ -3017,7 +3017,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
3017 insel = "Coaxial"; 3017 insel = "Coaxial";
3018 break; 3018 break;
3019 default: 3019 default:
3020 insel = "Unkown"; 3020 insel = "Unknown";
3021 } 3021 }
3022 3022
3023 switch (hdspm->control_register & HDSPM_SyncRefMask) { 3023 switch (hdspm->control_register & HDSPM_SyncRefMask) {
@@ -3028,7 +3028,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
3028 syncref = "MADI"; 3028 syncref = "MADI";
3029 break; 3029 break;
3030 default: 3030 default:
3031 syncref = "Unkown"; 3031 syncref = "Unknown";
3032 } 3032 }
3033 snd_iprintf(buffer, "Inputsel = %s, SyncRef = %s\n", insel, 3033 snd_iprintf(buffer, "Inputsel = %s, SyncRef = %s\n", insel,
3034 syncref); 3034 syncref);
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index bc539abb2105..c492af5b25f3 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -24,7 +24,6 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/slab.h>
28#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
29 28
30#include <sound/core.h> 29#include <sound/core.h>
@@ -314,7 +313,7 @@ static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_d
314} 313}
315 314
316 315
317static struct pci_device_id snd_rme9652_ids[] = { 316static DEFINE_PCI_DEVICE_TABLE(snd_rme9652_ids) = {
318 { 317 {
319 .vendor = 0x10ee, 318 .vendor = 0x10ee,
320 .device = 0x3fc4, 319 .device = 0x3fc4,
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index 1a5ff0611072..9cc1b5aa0148 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/slab.h>
27#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
28#include <linux/interrupt.h> 29#include <linux/interrupt.h>
29#include <linux/delay.h> 30#include <linux/delay.h>
@@ -48,7 +49,7 @@ MODULE_PARM_DESC(id, "ID string for SiS7019 Audio Accelerator.");
48module_param(enable, bool, 0444); 49module_param(enable, bool, 0444);
49MODULE_PARM_DESC(enable, "Enable SiS7019 Audio Accelerator."); 50MODULE_PARM_DESC(enable, "Enable SiS7019 Audio Accelerator.");
50 51
51static struct pci_device_id snd_sis7019_ids[] = { 52static DEFINE_PCI_DEVICE_TABLE(snd_sis7019_ids) = {
52 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x7019) }, 53 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x7019) },
53 { 0, } 54 { 0, }
54}; 55};
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 1f6406c4534d..337b9facadfd 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -242,7 +242,7 @@ struct sonicvibes {
242#endif 242#endif
243}; 243};
244 244
245static struct pci_device_id snd_sonic_ids[] = { 245static DEFINE_PCI_DEVICE_TABLE(snd_sonic_ids) = {
246 { PCI_VDEVICE(S3, 0xca00), 0, }, 246 { PCI_VDEVICE(S3, 0xca00), 0, },
247 { 0, } 247 { 0, }
248}; 248};
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
index 21cef97d478d..6d0581841d7a 100644
--- a/sound/pci/trident/trident.c
+++ b/sound/pci/trident/trident.c
@@ -62,7 +62,7 @@ MODULE_PARM_DESC(pcm_channels, "Number of hardware channels assigned for PCM.");
62module_param_array(wavetable_size, int, NULL, 0444); 62module_param_array(wavetable_size, int, NULL, 0444);
63MODULE_PARM_DESC(wavetable_size, "Maximum memory size in kB for wavetable synth."); 63MODULE_PARM_DESC(wavetable_size, "Maximum memory size in kB for wavetable synth.");
64 64
65static struct pci_device_id snd_trident_ids[] = { 65static DEFINE_PCI_DEVICE_TABLE(snd_trident_ids) = {
66 {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX), 66 {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX),
67 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0}, 67 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
68 {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX), 68 {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX),
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 8a332d2f615c..7e494b6a1d0e 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -401,7 +401,7 @@ struct via82xx {
401#endif 401#endif
402}; 402};
403 403
404static struct pci_device_id snd_via82xx_ids[] = { 404static DEFINE_PCI_DEVICE_TABLE(snd_via82xx_ids) = {
405 /* 0x1106, 0x3058 */ 405 /* 0x1106, 0x3058 */
406 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */ 406 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */
407 /* 0x1106, 0x3059 */ 407 /* 0x1106, 0x3059 */
@@ -1791,6 +1791,12 @@ static struct ac97_quirk ac97_quirks[] = {
1791 .type = AC97_TUNE_HP_ONLY 1791 .type = AC97_TUNE_HP_ONLY
1792 }, 1792 },
1793 { 1793 {
1794 .subvendor = 0x110a,
1795 .subdevice = 0x0079,
1796 .name = "Fujitsu Siemens D1289",
1797 .type = AC97_TUNE_HP_ONLY
1798 },
1799 {
1794 .subvendor = 0x1019, 1800 .subvendor = 0x1019,
1795 .subdevice = 0x0a81, 1801 .subdevice = 0x0a81,
1796 .name = "ECS K7VTA3", 1802 .name = "ECS K7VTA3",
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 47eb61561dfc..f7e8bbbe3953 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -260,7 +260,7 @@ struct via82xx_modem {
260 struct snd_info_entry *proc_entry; 260 struct snd_info_entry *proc_entry;
261}; 261};
262 262
263static struct pci_device_id snd_via82xx_modem_ids[] = { 263static DEFINE_PCI_DEVICE_TABLE(snd_via82xx_modem_ids) = {
264 { PCI_VDEVICE(VIA, 0x3068), TYPE_CARD_VIA82XX_MODEM, }, 264 { PCI_VDEVICE(VIA, 0x3068), TYPE_CARD_VIA82XX_MODEM, },
265 { 0, } 265 { 0, }
266}; 266};
diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c
index fc9136c3e0d7..99a9a814be0b 100644
--- a/sound/pci/vx222/vx222.c
+++ b/sound/pci/vx222/vx222.c
@@ -60,7 +60,7 @@ enum {
60 VX_PCI_VX222_NEW 60 VX_PCI_VX222_NEW
61}; 61};
62 62
63static struct pci_device_id snd_vx222_ids[] = { 63static DEFINE_PCI_DEVICE_TABLE(snd_vx222_ids) = {
64 { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, }, /* PLX */ 64 { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, }, /* PLX */
65 { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, }, /* PLX */ 65 { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, }, /* PLX */
66 { 0, } 66 { 0, }
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index e6b18b90d451..80c682113381 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -66,7 +66,7 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address");
66module_param_array(rear_switch, bool, NULL, 0444); 66module_param_array(rear_switch, bool, NULL, 0444);
67MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch"); 67MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch");
68 68
69static struct pci_device_id snd_ymfpci_ids[] = { 69static DEFINE_PCI_DEVICE_TABLE(snd_ymfpci_ids) = {
70 { PCI_VDEVICE(YAMAHA, 0x0004), 0, }, /* YMF724 */ 70 { PCI_VDEVICE(YAMAHA, 0x0004), 0, }, /* YMF724 */
71 { PCI_VDEVICE(YAMAHA, 0x000d), 0, }, /* YMF724F */ 71 { PCI_VDEVICE(YAMAHA, 0x000d), 0, }, /* YMF724F */
72 { PCI_VDEVICE(YAMAHA, 0x000a), 0, }, /* YMF740 */ 72 { PCI_VDEVICE(YAMAHA, 0x000a), 0, }, /* YMF740 */