aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda')
-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
24 files changed, 8483 insertions, 2088 deletions
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