aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda')
-rw-r--r--sound/pci/hda/Kconfig13
-rw-r--r--sound/pci/hda/hda_beep.c114
-rw-r--r--sound/pci/hda/hda_beep.h10
-rw-r--r--sound/pci/hda/hda_codec.c617
-rw-r--r--sound/pci/hda/hda_codec.h16
-rw-r--r--sound/pci/hda/hda_eld.c20
-rw-r--r--sound/pci/hda/hda_generic.c17
-rw-r--r--sound/pci/hda/hda_hwdep.c45
-rw-r--r--sound/pci/hda/hda_intel.c74
-rw-r--r--sound/pci/hda/hda_local.h69
-rw-r--r--sound/pci/hda/hda_proc.c77
-rw-r--r--sound/pci/hda/patch_analog.c86
-rw-r--r--sound/pci/hda/patch_ca0110.c4
-rw-r--r--sound/pci/hda/patch_cirrus.c55
-rw-r--r--sound/pci/hda/patch_cmedia.c6
-rw-r--r--sound/pci/hda/patch_conexant.c248
-rw-r--r--sound/pci/hda/patch_intelhdmi.c584
-rw-r--r--sound/pci/hda/patch_nvhdmi.c2
-rw-r--r--sound/pci/hda/patch_realtek.c972
-rw-r--r--sound/pci/hda/patch_sigmatel.c290
-rw-r--r--sound/pci/hda/patch_via.c3509
21 files changed, 5776 insertions, 1052 deletions
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 55545e0818b5..556cff937be7 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
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 3f51a981e604..5fe34a8d8c81 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -113,23 +113,25 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
113 return 0; 113 return 0;
114} 114}
115 115
116int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) 116static void snd_hda_do_detach(struct hda_beep *beep)
117{
118 input_unregister_device(beep->dev);
119 beep->dev = NULL;
120 cancel_work_sync(&beep->beep_work);
121 /* turn off beep for sure */
122 snd_hda_codec_write_cache(beep->codec, beep->nid, 0,
123 AC_VERB_SET_BEEP_CONTROL, 0);
124}
125
126static int snd_hda_do_attach(struct hda_beep *beep)
117{ 127{
118 struct input_dev *input_dev; 128 struct input_dev *input_dev;
119 struct hda_beep *beep; 129 struct hda_codec *codec = beep->codec;
120 int err; 130 int err;
121 131
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(); 132 input_dev = input_allocate_device();
131 if (!input_dev) { 133 if (!input_dev) {
132 kfree(beep); 134 printk(KERN_INFO "hda_beep: unable to allocate input device\n");
133 return -ENOMEM; 135 return -ENOMEM;
134 } 136 }
135 137
@@ -151,21 +153,96 @@ int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
151 err = input_register_device(input_dev); 153 err = input_register_device(input_dev);
152 if (err < 0) { 154 if (err < 0) {
153 input_free_device(input_dev); 155 input_free_device(input_dev);
154 kfree(beep); 156 printk(KERN_INFO "hda_beep: unable to register input device\n");
155 return err; 157 return err;
156 } 158 }
159 beep->dev = input_dev;
160 return 0;
161}
162
163static void snd_hda_do_register(struct work_struct *work)
164{
165 struct hda_beep *beep =
166 container_of(work, struct hda_beep, register_work);
167
168 mutex_lock(&beep->mutex);
169 if (beep->enabled && !beep->dev)
170 snd_hda_do_attach(beep);
171 mutex_unlock(&beep->mutex);
172}
173
174static void snd_hda_do_unregister(struct work_struct *work)
175{
176 struct hda_beep *beep =
177 container_of(work, struct hda_beep, unregister_work.work);
178
179 mutex_lock(&beep->mutex);
180 if (!beep->enabled && beep->dev)
181 snd_hda_do_detach(beep);
182 mutex_unlock(&beep->mutex);
183}
157 184
185int snd_hda_enable_beep_device(struct hda_codec *codec, int enable)
186{
187 struct hda_beep *beep = codec->beep;
188 enable = !!enable;
189 if (beep == NULL)
190 return 0;
191 if (beep->enabled != enable) {
192 beep->enabled = enable;
193 if (!enable) {
194 /* turn off beep */
195 snd_hda_codec_write_cache(beep->codec, beep->nid, 0,
196 AC_VERB_SET_BEEP_CONTROL, 0);
197 }
198 if (beep->mode == HDA_BEEP_MODE_SWREG) {
199 if (enable) {
200 cancel_delayed_work(&beep->unregister_work);
201 schedule_work(&beep->register_work);
202 } else {
203 schedule_delayed_work(&beep->unregister_work,
204 HZ);
205 }
206 }
207 return 1;
208 }
209 return 0;
210}
211EXPORT_SYMBOL_HDA(snd_hda_enable_beep_device);
212
213int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
214{
215 struct hda_beep *beep;
216
217 if (!snd_hda_get_bool_hint(codec, "beep"))
218 return 0; /* disabled explicitly by hints */
219 if (codec->beep_mode == HDA_BEEP_MODE_OFF)
220 return 0; /* disabled by module option */
221
222 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
223 if (beep == NULL)
224 return -ENOMEM;
225 snprintf(beep->phys, sizeof(beep->phys),
226 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
158 /* enable linear scale */ 227 /* enable linear scale */
159 snd_hda_codec_write(codec, nid, 0, 228 snd_hda_codec_write(codec, nid, 0,
160 AC_VERB_SET_DIGI_CONVERT_2, 0x01); 229 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
161 230
162 beep->nid = nid; 231 beep->nid = nid;
163 beep->dev = input_dev;
164 beep->codec = codec; 232 beep->codec = codec;
165 beep->enabled = 1; 233 beep->mode = codec->beep_mode;
166 codec->beep = beep; 234 codec->beep = beep;
167 235
236 INIT_WORK(&beep->register_work, &snd_hda_do_register);
237 INIT_DELAYED_WORK(&beep->unregister_work, &snd_hda_do_unregister);
168 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); 238 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
239 mutex_init(&beep->mutex);
240
241 if (beep->mode == HDA_BEEP_MODE_ON) {
242 beep->enabled = 1;
243 snd_hda_do_register(&beep->register_work);
244 }
245
169 return 0; 246 return 0;
170} 247}
171EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device); 248EXPORT_SYMBOL_HDA(snd_hda_attach_beep_device);
@@ -174,11 +251,12 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
174{ 251{
175 struct hda_beep *beep = codec->beep; 252 struct hda_beep *beep = codec->beep;
176 if (beep) { 253 if (beep) {
177 cancel_work_sync(&beep->beep_work); 254 cancel_work_sync(&beep->register_work);
178 255 cancel_delayed_work(&beep->unregister_work);
179 input_unregister_device(beep->dev); 256 if (beep->enabled)
180 kfree(beep); 257 snd_hda_do_detach(beep);
181 codec->beep = NULL; 258 codec->beep = NULL;
259 kfree(beep);
182 } 260 }
183} 261}
184EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device); 262EXPORT_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..950ee5cfcacf 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}
@@ -820,6 +843,16 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
820 return 0; 843 return 0;
821} 844}
822 845
846/**
847 * snd_hda_codec_set_pincfg - Override a pin default configuration
848 * @codec: the HDA codec
849 * @nid: NID to set the pin config
850 * @cfg: the pin default config value
851 *
852 * Override a pin default configuration value in the cache.
853 * This value can be read by snd_hda_codec_get_pincfg() in a higher
854 * priority than the real hardware value.
855 */
823int snd_hda_codec_set_pincfg(struct hda_codec *codec, 856int snd_hda_codec_set_pincfg(struct hda_codec *codec,
824 hda_nid_t nid, unsigned int cfg) 857 hda_nid_t nid, unsigned int cfg)
825{ 858{
@@ -827,7 +860,15 @@ int snd_hda_codec_set_pincfg(struct hda_codec *codec,
827} 860}
828EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg); 861EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
829 862
830/* get the current pin config value of the given pin NID */ 863/**
864 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
865 * @codec: the HDA codec
866 * @nid: NID to get the pin config
867 *
868 * Get the current pin config value of the given pin NID.
869 * If the pincfg value is cached or overridden via sysfs or driver,
870 * returns the cached value.
871 */
831unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) 872unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
832{ 873{
833 struct hda_pincfg *pin; 874 struct hda_pincfg *pin;
@@ -944,7 +985,7 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
944 mutex_init(&codec->control_mutex); 985 mutex_init(&codec->control_mutex);
945 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 986 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
946 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 987 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
947 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32); 988 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 60);
948 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 989 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
949 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 990 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
950 if (codec->bus->modelname) { 991 if (codec->bus->modelname) {
@@ -1026,6 +1067,15 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
1026} 1067}
1027EXPORT_SYMBOL_HDA(snd_hda_codec_new); 1068EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1028 1069
1070/**
1071 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1072 * @codec: the HDA codec
1073 *
1074 * Start parsing of the given codec tree and (re-)initialize the whole
1075 * patch instance.
1076 *
1077 * Returns 0 if successful or a negative error code.
1078 */
1029int snd_hda_codec_configure(struct hda_codec *codec) 1079int snd_hda_codec_configure(struct hda_codec *codec)
1030{ 1080{
1031 int err; 1081 int err;
@@ -1036,11 +1086,6 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1036 if (err < 0) 1086 if (err < 0)
1037 return err; 1087 return err;
1038 } 1088 }
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 1089
1045 if (is_generic_config(codec)) { 1090 if (is_generic_config(codec)) {
1046 err = snd_hda_parse_generic_codec(codec); 1091 err = snd_hda_parse_generic_codec(codec);
@@ -1059,6 +1104,11 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1059 patched: 1104 patched:
1060 if (!err && codec->patch_ops.unsol_event) 1105 if (!err && codec->patch_ops.unsol_event)
1061 err = init_unsol_queue(codec->bus); 1106 err = init_unsol_queue(codec->bus);
1107 /* audio codec should override the mixer name */
1108 if (!err && (codec->afg || !*codec->bus->card->mixername))
1109 snprintf(codec->bus->card->mixername,
1110 sizeof(codec->bus->card->mixername),
1111 "%s %s", codec->vendor_name, codec->chip_name);
1062 return err; 1112 return err;
1063} 1113}
1064EXPORT_SYMBOL_HDA(snd_hda_codec_configure); 1114EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
@@ -1088,6 +1138,11 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1088} 1138}
1089EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); 1139EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1090 1140
1141/**
1142 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1143 * @codec: the CODEC to clean up
1144 * @nid: the NID to clean up
1145 */
1091void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 1146void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1092{ 1147{
1093 if (!nid) 1148 if (!nid)
@@ -1163,8 +1218,17 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1163 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1218 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1164} 1219}
1165 1220
1166/* 1221/**
1167 * query AMP capabilities for the given widget and direction 1222 * query_amp_caps - query AMP capabilities
1223 * @codec: the HD-auio codec
1224 * @nid: the NID to query
1225 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1226 *
1227 * Query AMP capabilities for the given widget and direction.
1228 * Returns the obtained capability bits.
1229 *
1230 * When cap bits have been already read, this doesn't read again but
1231 * returns the cached value.
1168 */ 1232 */
1169u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1233u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1170{ 1234{
@@ -1187,6 +1251,19 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1187} 1251}
1188EXPORT_SYMBOL_HDA(query_amp_caps); 1252EXPORT_SYMBOL_HDA(query_amp_caps);
1189 1253
1254/**
1255 * snd_hda_override_amp_caps - Override the AMP capabilities
1256 * @codec: the CODEC to clean up
1257 * @nid: the NID to clean up
1258 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1259 * @caps: the capability bits to set
1260 *
1261 * Override the cached AMP caps bits value by the given one.
1262 * This function is useful if the driver needs to adjust the AMP ranges,
1263 * e.g. limit to 0dB, etc.
1264 *
1265 * Returns zero if successful or a negative error code.
1266 */
1190int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1267int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1191 unsigned int caps) 1268 unsigned int caps)
1192{ 1269{
@@ -1222,6 +1299,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); 1299 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1223} 1300}
1224 1301
1302/**
1303 * snd_hda_query_pin_caps - Query PIN capabilities
1304 * @codec: the HD-auio codec
1305 * @nid: the NID to query
1306 *
1307 * Query PIN capabilities for the given widget.
1308 * Returns the obtained capability bits.
1309 *
1310 * When cap bits have been already read, this doesn't read again but
1311 * returns the cached value.
1312 */
1225u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1313u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1226{ 1314{
1227 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1315 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
@@ -1229,6 +1317,40 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1229} 1317}
1230EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1318EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1231 1319
1320/**
1321 * snd_hda_pin_sense - execute pin sense measurement
1322 * @codec: the CODEC to sense
1323 * @nid: the pin NID to sense
1324 *
1325 * Execute necessary pin sense measurement and return its Presence Detect,
1326 * Impedance, ELD Valid etc. status bits.
1327 */
1328u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1329{
1330 u32 pincap = snd_hda_query_pin_caps(codec, nid);
1331
1332 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1333 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
1334
1335 return snd_hda_codec_read(codec, nid, 0,
1336 AC_VERB_GET_PIN_SENSE, 0);
1337}
1338EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1339
1340/**
1341 * snd_hda_jack_detect - query pin Presence Detect status
1342 * @codec: the CODEC to sense
1343 * @nid: the pin NID to sense
1344 *
1345 * Query and return the pin's Presence Detect status.
1346 */
1347int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1348{
1349 u32 sense = snd_hda_pin_sense(codec, nid);
1350 return !!(sense & AC_PINSENSE_PRESENCE);
1351}
1352EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1353
1232/* 1354/*
1233 * read the current volume to info 1355 * read the current volume to info
1234 * if the cache exists, read the cache value. 1356 * if the cache exists, read the cache value.
@@ -1269,8 +1391,15 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1269 info->vol[ch] = val; 1391 info->vol[ch] = val;
1270} 1392}
1271 1393
1272/* 1394/**
1273 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. 1395 * snd_hda_codec_amp_read - Read AMP value
1396 * @codec: HD-audio codec
1397 * @nid: NID to read the AMP value
1398 * @ch: channel (left=0 or right=1)
1399 * @direction: #HDA_INPUT or #HDA_OUTPUT
1400 * @index: the index value (only for input direction)
1401 *
1402 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1274 */ 1403 */
1275int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 1404int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1276 int direction, int index) 1405 int direction, int index)
@@ -1283,8 +1412,18 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1283} 1412}
1284EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1413EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1285 1414
1286/* 1415/**
1287 * update the AMP value, mask = bit mask to set, val = the value 1416 * snd_hda_codec_amp_update - update the AMP value
1417 * @codec: HD-audio codec
1418 * @nid: NID to read the AMP value
1419 * @ch: channel (left=0 or right=1)
1420 * @direction: #HDA_INPUT or #HDA_OUTPUT
1421 * @idx: the index value (only for input direction)
1422 * @mask: bit mask to set
1423 * @val: the bits value to set
1424 *
1425 * Update the AMP value with a bit mask.
1426 * Returns 0 if the value is unchanged, 1 if changed.
1288 */ 1427 */
1289int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1428int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1290 int direction, int idx, int mask, int val) 1429 int direction, int idx, int mask, int val)
@@ -1303,8 +1442,17 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1303} 1442}
1304EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); 1443EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1305 1444
1306/* 1445/**
1307 * update the AMP stereo with the same mask and value 1446 * snd_hda_codec_amp_stereo - update the AMP stereo values
1447 * @codec: HD-audio codec
1448 * @nid: NID to read the AMP value
1449 * @direction: #HDA_INPUT or #HDA_OUTPUT
1450 * @idx: the index value (only for input direction)
1451 * @mask: bit mask to set
1452 * @val: the bits value to set
1453 *
1454 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1455 * stereo widget with the same mask and value.
1308 */ 1456 */
1309int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 1457int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1310 int direction, int idx, int mask, int val) 1458 int direction, int idx, int mask, int val)
@@ -1318,7 +1466,12 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1318EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); 1466EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1319 1467
1320#ifdef SND_HDA_NEEDS_RESUME 1468#ifdef SND_HDA_NEEDS_RESUME
1321/* resume the all amp commands from the cache */ 1469/**
1470 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1471 * @codec: HD-audio codec
1472 *
1473 * Resume the all amp commands from the cache.
1474 */
1322void snd_hda_codec_resume_amp(struct hda_codec *codec) 1475void snd_hda_codec_resume_amp(struct hda_codec *codec)
1323{ 1476{
1324 struct hda_amp_info *buffer = codec->amp_cache.buf.list; 1477 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
@@ -1344,7 +1497,12 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
1344EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); 1497EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1345#endif /* SND_HDA_NEEDS_RESUME */ 1498#endif /* SND_HDA_NEEDS_RESUME */
1346 1499
1347/* volume */ 1500/**
1501 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1502 *
1503 * The control element is supposed to have the private_value field
1504 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1505 */
1348int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 1506int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_info *uinfo) 1507 struct snd_ctl_elem_info *uinfo)
1350{ 1508{
@@ -1400,6 +1558,12 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1400 HDA_AMP_VOLMASK, val); 1558 HDA_AMP_VOLMASK, val);
1401} 1559}
1402 1560
1561/**
1562 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1563 *
1564 * The control element is supposed to have the private_value field
1565 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1566 */
1403int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1567int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1404 struct snd_ctl_elem_value *ucontrol) 1568 struct snd_ctl_elem_value *ucontrol)
1405{ 1569{
@@ -1419,6 +1583,12 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1419} 1583}
1420EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); 1584EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1421 1585
1586/**
1587 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1588 *
1589 * The control element is supposed to have the private_value field
1590 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1591 */
1422int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1592int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol) 1593 struct snd_ctl_elem_value *ucontrol)
1424{ 1594{
@@ -1443,6 +1613,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1443} 1613}
1444EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put); 1614EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1445 1615
1616/**
1617 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1618 *
1619 * The control element is supposed to have the private_value field
1620 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1621 */
1446int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1622int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1447 unsigned int size, unsigned int __user *_tlv) 1623 unsigned int size, unsigned int __user *_tlv)
1448{ 1624{
@@ -1472,8 +1648,16 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1472} 1648}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv); 1649EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1474 1650
1475/* 1651/**
1476 * set (static) TLV for virtual master volume; recalculated as max 0dB 1652 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1653 * @codec: HD-audio codec
1654 * @nid: NID of a reference widget
1655 * @dir: #HDA_INPUT or #HDA_OUTPUT
1656 * @tlv: TLV data to be stored, at least 4 elements
1657 *
1658 * Set (static) TLV data for a virtual master volume using the AMP caps
1659 * obtained from the reference NID.
1660 * The volume range is recalculated as if the max volume is 0dB.
1477 */ 1661 */
1478void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 1662void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1479 unsigned int *tlv) 1663 unsigned int *tlv)
@@ -1507,6 +1691,13 @@ _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1507 return snd_ctl_find_id(codec->bus->card, &id); 1691 return snd_ctl_find_id(codec->bus->card, &id);
1508} 1692}
1509 1693
1694/**
1695 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1696 * @codec: HD-audio codec
1697 * @name: ctl id name string
1698 *
1699 * Get the control element with the given id string and IFACE_MIXER.
1700 */
1510struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1701struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1511 const char *name) 1702 const char *name)
1512{ 1703{
@@ -1514,30 +1705,57 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1514} 1705}
1515EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); 1706EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1516 1707
1517/* Add a control element and assign to the codec */ 1708/**
1518int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl) 1709 * snd_hda_ctl-add - Add a control element and assign to the codec
1710 * @codec: HD-audio codec
1711 * @nid: corresponding NID (optional)
1712 * @kctl: the control element to assign
1713 *
1714 * Add the given control element to an array inside the codec instance.
1715 * All control elements belonging to a codec are supposed to be added
1716 * by this function so that a proper clean-up works at the free or
1717 * reconfiguration time.
1718 *
1719 * If non-zero @nid is passed, the NID is assigned to the control element.
1720 * The assignment is shown in the codec proc file.
1721 *
1722 * snd_hda_ctl_add() checks the control subdev id field whether
1723 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1724 * bits value is taken as the NID to assign.
1725 */
1726int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1727 struct snd_kcontrol *kctl)
1519{ 1728{
1520 int err; 1729 int err;
1521 struct snd_kcontrol **knewp; 1730 struct hda_nid_item *item;
1522 1731
1732 if (kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) {
1733 if (nid == 0)
1734 nid = kctl->id.subdevice & 0xffff;
1735 kctl->id.subdevice = 0;
1736 }
1523 err = snd_ctl_add(codec->bus->card, kctl); 1737 err = snd_ctl_add(codec->bus->card, kctl);
1524 if (err < 0) 1738 if (err < 0)
1525 return err; 1739 return err;
1526 knewp = snd_array_new(&codec->mixers); 1740 item = snd_array_new(&codec->mixers);
1527 if (!knewp) 1741 if (!item)
1528 return -ENOMEM; 1742 return -ENOMEM;
1529 *knewp = kctl; 1743 item->kctl = kctl;
1744 item->nid = nid;
1530 return 0; 1745 return 0;
1531} 1746}
1532EXPORT_SYMBOL_HDA(snd_hda_ctl_add); 1747EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1533 1748
1534/* Clear all controls assigned to the given codec */ 1749/**
1750 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1751 * @codec: HD-audio codec
1752 */
1535void snd_hda_ctls_clear(struct hda_codec *codec) 1753void snd_hda_ctls_clear(struct hda_codec *codec)
1536{ 1754{
1537 int i; 1755 int i;
1538 struct snd_kcontrol **kctls = codec->mixers.list; 1756 struct hda_nid_item *items = codec->mixers.list;
1539 for (i = 0; i < codec->mixers.used; i++) 1757 for (i = 0; i < codec->mixers.used; i++)
1540 snd_ctl_remove(codec->bus->card, kctls[i]); 1758 snd_ctl_remove(codec->bus->card, items[i].kctl);
1541 snd_array_free(&codec->mixers); 1759 snd_array_free(&codec->mixers);
1542} 1760}
1543 1761
@@ -1563,6 +1781,16 @@ static void hda_unlock_devices(struct snd_card *card)
1563 spin_unlock(&card->files_lock); 1781 spin_unlock(&card->files_lock);
1564} 1782}
1565 1783
1784/**
1785 * snd_hda_codec_reset - Clear all objects assigned to the codec
1786 * @codec: HD-audio codec
1787 *
1788 * This frees the all PCM and control elements assigned to the codec, and
1789 * clears the caches and restores the pin default configurations.
1790 *
1791 * When a device is being used, it returns -EBSY. If successfully freed,
1792 * returns zero.
1793 */
1566int snd_hda_codec_reset(struct hda_codec *codec) 1794int snd_hda_codec_reset(struct hda_codec *codec)
1567{ 1795{
1568 struct snd_card *card = codec->bus->card; 1796 struct snd_card *card = codec->bus->card;
@@ -1626,7 +1854,22 @@ int snd_hda_codec_reset(struct hda_codec *codec)
1626 return 0; 1854 return 0;
1627} 1855}
1628 1856
1629/* create a virtual master control and add slaves */ 1857/**
1858 * snd_hda_add_vmaster - create a virtual master control and add slaves
1859 * @codec: HD-audio codec
1860 * @name: vmaster control name
1861 * @tlv: TLV data (optional)
1862 * @slaves: slave control names (optional)
1863 *
1864 * Create a virtual master control with the given name. The TLV data
1865 * must be either NULL or a valid data.
1866 *
1867 * @slaves is a NULL-terminated array of strings, each of which is a
1868 * slave control name. All controls with these names are assigned to
1869 * the new virtual master control.
1870 *
1871 * This function returns zero if successful or a negative error code.
1872 */
1630int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1873int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1631 unsigned int *tlv, const char **slaves) 1874 unsigned int *tlv, const char **slaves)
1632{ 1875{
@@ -1643,7 +1886,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1643 kctl = snd_ctl_make_virtual_master(name, tlv); 1886 kctl = snd_ctl_make_virtual_master(name, tlv);
1644 if (!kctl) 1887 if (!kctl)
1645 return -ENOMEM; 1888 return -ENOMEM;
1646 err = snd_hda_ctl_add(codec, kctl); 1889 err = snd_hda_ctl_add(codec, 0, kctl);
1647 if (err < 0) 1890 if (err < 0)
1648 return err; 1891 return err;
1649 1892
@@ -1668,7 +1911,12 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1668} 1911}
1669EXPORT_SYMBOL_HDA(snd_hda_add_vmaster); 1912EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1670 1913
1671/* switch */ 1914/**
1915 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
1916 *
1917 * The control element is supposed to have the private_value field
1918 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1919 */
1672int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1920int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_info *uinfo) 1921 struct snd_ctl_elem_info *uinfo)
1674{ 1922{
@@ -1682,6 +1930,12 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1682} 1930}
1683EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info); 1931EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1684 1932
1933/**
1934 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
1935 *
1936 * The control element is supposed to have the private_value field
1937 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1938 */
1685int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 1939int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol) 1940 struct snd_ctl_elem_value *ucontrol)
1687{ 1941{
@@ -1702,6 +1956,12 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1702} 1956}
1703EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get); 1957EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1704 1958
1959/**
1960 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
1961 *
1962 * The control element is supposed to have the private_value field
1963 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1964 */
1705int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 1965int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol) 1966 struct snd_ctl_elem_value *ucontrol)
1707{ 1967{
@@ -1733,6 +1993,25 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1733} 1993}
1734EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put); 1994EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1735 1995
1996#ifdef CONFIG_SND_HDA_INPUT_BEEP
1997/**
1998 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
1999 *
2000 * This function calls snd_hda_enable_beep_device(), which behaves differently
2001 * depending on beep_mode option.
2002 */
2003int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2004 struct snd_ctl_elem_value *ucontrol)
2005{
2006 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2007 long *valp = ucontrol->value.integer.value;
2008
2009 snd_hda_enable_beep_device(codec, *valp);
2010 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2011}
2012EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2013#endif /* CONFIG_SND_HDA_INPUT_BEEP */
2014
1736/* 2015/*
1737 * bound volume controls 2016 * bound volume controls
1738 * 2017 *
@@ -1742,6 +2021,12 @@ EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1742#define AMP_VAL_IDX_SHIFT 19 2021#define AMP_VAL_IDX_SHIFT 19
1743#define AMP_VAL_IDX_MASK (0x0f<<19) 2022#define AMP_VAL_IDX_MASK (0x0f<<19)
1744 2023
2024/**
2025 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2026 *
2027 * The control element is supposed to have the private_value field
2028 * set up via HDA_BIND_MUTE*() macros.
2029 */
1745int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, 2030int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol) 2031 struct snd_ctl_elem_value *ucontrol)
1747{ 2032{
@@ -1759,6 +2044,12 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1759} 2044}
1760EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get); 2045EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1761 2046
2047/**
2048 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2049 *
2050 * The control element is supposed to have the private_value field
2051 * set up via HDA_BIND_MUTE*() macros.
2052 */
1762int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 2053int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol) 2054 struct snd_ctl_elem_value *ucontrol)
1764{ 2055{
@@ -1783,8 +2074,11 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1783} 2074}
1784EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put); 2075EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1785 2076
1786/* 2077/**
1787 * generic bound volume/swtich controls 2078 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2079 *
2080 * The control element is supposed to have the private_value field
2081 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
1788 */ 2082 */
1789int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, 2083int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_info *uinfo) 2084 struct snd_ctl_elem_info *uinfo)
@@ -1803,6 +2097,12 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1803} 2097}
1804EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info); 2098EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1805 2099
2100/**
2101 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2102 *
2103 * The control element is supposed to have the private_value field
2104 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2105 */
1806int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 2106int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1807 struct snd_ctl_elem_value *ucontrol) 2107 struct snd_ctl_elem_value *ucontrol)
1808{ 2108{
@@ -1820,6 +2120,12 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1820} 2120}
1821EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get); 2121EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1822 2122
2123/**
2124 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2125 *
2126 * The control element is supposed to have the private_value field
2127 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2128 */
1823int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 2129int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol) 2130 struct snd_ctl_elem_value *ucontrol)
1825{ 2131{
@@ -1843,6 +2149,12 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1843} 2149}
1844EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put); 2150EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1845 2151
2152/**
2153 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2154 *
2155 * The control element is supposed to have the private_value field
2156 * set up via HDA_BIND_VOL() macro.
2157 */
1846int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 2158int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1847 unsigned int size, unsigned int __user *tlv) 2159 unsigned int size, unsigned int __user *tlv)
1848{ 2160{
@@ -2126,7 +2438,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2126 return -ENOMEM; 2438 return -ENOMEM;
2127 kctl->id.index = idx; 2439 kctl->id.index = idx;
2128 kctl->private_value = nid; 2440 kctl->private_value = nid;
2129 err = snd_hda_ctl_add(codec, kctl); 2441 err = snd_hda_ctl_add(codec, nid, kctl);
2130 if (err < 0) 2442 if (err < 0)
2131 return err; 2443 return err;
2132 } 2444 }
@@ -2165,14 +2477,19 @@ static struct snd_kcontrol_new spdif_share_sw = {
2165 .put = spdif_share_sw_put, 2477 .put = spdif_share_sw_put,
2166}; 2478};
2167 2479
2480/**
2481 * snd_hda_create_spdif_share_sw - create Default PCM switch
2482 * @codec: the HDA codec
2483 * @mout: multi-out instance
2484 */
2168int snd_hda_create_spdif_share_sw(struct hda_codec *codec, 2485int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2169 struct hda_multi_out *mout) 2486 struct hda_multi_out *mout)
2170{ 2487{
2171 if (!mout->dig_out_nid) 2488 if (!mout->dig_out_nid)
2172 return 0; 2489 return 0;
2173 /* ATTENTION: here mout is passed as private_data, instead of codec */ 2490 /* ATTENTION: here mout is passed as private_data, instead of codec */
2174 return snd_hda_ctl_add(codec, 2491 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2175 snd_ctl_new1(&spdif_share_sw, mout)); 2492 snd_ctl_new1(&spdif_share_sw, mout));
2176} 2493}
2177EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw); 2494EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2178 2495
@@ -2276,7 +2593,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2276 if (!kctl) 2593 if (!kctl)
2277 return -ENOMEM; 2594 return -ENOMEM;
2278 kctl->private_value = nid; 2595 kctl->private_value = nid;
2279 err = snd_hda_ctl_add(codec, kctl); 2596 err = snd_hda_ctl_add(codec, nid, kctl);
2280 if (err < 0) 2597 if (err < 0)
2281 return err; 2598 return err;
2282 } 2599 }
@@ -2332,7 +2649,12 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2332} 2649}
2333EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); 2650EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2334 2651
2335/* resume the all commands from the cache */ 2652/**
2653 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2654 * @codec: HD-audio codec
2655 *
2656 * Execute all verbs recorded in the command caches to resume.
2657 */
2336void snd_hda_codec_resume_cache(struct hda_codec *codec) 2658void snd_hda_codec_resume_cache(struct hda_codec *codec)
2337{ 2659{
2338 struct hda_cache_head *buffer = codec->cmd_cache.buf.list; 2660 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
@@ -2452,9 +2774,11 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
2452 codec->afg ? codec->afg : codec->mfg, 2774 codec->afg ? codec->afg : codec->mfg,
2453 AC_PWRST_D3); 2775 AC_PWRST_D3);
2454#ifdef CONFIG_SND_HDA_POWER_SAVE 2776#ifdef CONFIG_SND_HDA_POWER_SAVE
2777 snd_hda_update_power_acct(codec);
2455 cancel_delayed_work(&codec->power_work); 2778 cancel_delayed_work(&codec->power_work);
2456 codec->power_on = 0; 2779 codec->power_on = 0;
2457 codec->power_transition = 0; 2780 codec->power_transition = 0;
2781 codec->power_jiffies = jiffies;
2458#endif 2782#endif
2459} 2783}
2460 2784
@@ -2756,8 +3080,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2756} 3080}
2757 3081
2758/** 3082/**
2759 * snd_hda_is_supported_format - check whether the given node supports 3083 * snd_hda_is_supported_format - Check the validity of the format
2760 * the format val 3084 * @codec: HD-audio codec
3085 * @nid: NID to check
3086 * @format: the HD-audio format value to check
3087 *
3088 * Check whether the given node supports the format value.
2761 * 3089 *
2762 * Returns 1 if supported, 0 if not. 3090 * Returns 1 if supported, 0 if not.
2763 */ 3091 */
@@ -2877,51 +3205,36 @@ static int set_pcm_default_values(struct hda_codec *codec,
2877 return 0; 3205 return 0;
2878} 3206}
2879 3207
3208/* global */
3209const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3210 "Audio", "SPDIF", "HDMI", "Modem"
3211};
3212
2880/* 3213/*
2881 * get the empty PCM device number to assign 3214 * get the empty PCM device number to assign
2882 */ 3215 */
2883static int get_empty_pcm_device(struct hda_bus *bus, int type) 3216static int get_empty_pcm_device(struct hda_bus *bus, int type)
2884{ 3217{
2885 static const char *dev_name[HDA_PCM_NTYPES] = { 3218 /* audio device indices; not linear to keep compatibility */
2886 "Audio", "SPDIF", "HDMI", "Modem" 3219 static int audio_idx[HDA_PCM_NTYPES][5] = {
2887 }; 3220 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
2888 /* starting device index for each PCM type */ 3221 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
2889 static int dev_idx[HDA_PCM_NTYPES] = { 3222 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
2890 [HDA_PCM_TYPE_AUDIO] = 0, 3223 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
2891 [HDA_PCM_TYPE_SPDIF] = 1,
2892 [HDA_PCM_TYPE_HDMI] = 3,
2893 [HDA_PCM_TYPE_MODEM] = 6
2894 }; 3224 };
2895 /* normal audio device indices; not linear to keep compatibility */ 3225 int i;
2896 static int audio_idx[4] = { 0, 2, 4, 5 }; 3226
2897 int i, dev; 3227 if (type >= HDA_PCM_NTYPES) {
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); 3228 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2920 return -EINVAL; 3229 return -EINVAL;
2921 } 3230 }
2922 ok: 3231
2923 set_bit(dev, bus->pcm_dev_bits); 3232 for (i = 0; audio_idx[type][i] >= 0 ; i++)
2924 return dev; 3233 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3234 return audio_idx[type][i];
3235
3236 snd_printk(KERN_WARNING "Too many %s devices\n", snd_hda_pcm_type_name[type]);
3237 return -EAGAIN;
2925} 3238}
2926 3239
2927/* 3240/*
@@ -3159,14 +3472,14 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3159 */ 3472 */
3160int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew) 3473int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3161{ 3474{
3162 int err; 3475 int err;
3163 3476
3164 for (; knew->name; knew++) { 3477 for (; knew->name; knew++) {
3165 struct snd_kcontrol *kctl; 3478 struct snd_kcontrol *kctl;
3166 kctl = snd_ctl_new1(knew, codec); 3479 kctl = snd_ctl_new1(knew, codec);
3167 if (!kctl) 3480 if (!kctl)
3168 return -ENOMEM; 3481 return -ENOMEM;
3169 err = snd_hda_ctl_add(codec, kctl); 3482 err = snd_hda_ctl_add(codec, 0, kctl);
3170 if (err < 0) { 3483 if (err < 0) {
3171 if (!codec->addr) 3484 if (!codec->addr)
3172 return err; 3485 return err;
@@ -3174,7 +3487,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3174 if (!kctl) 3487 if (!kctl)
3175 return -ENOMEM; 3488 return -ENOMEM;
3176 kctl->id.device = codec->addr; 3489 kctl->id.device = codec->addr;
3177 err = snd_hda_ctl_add(codec, kctl); 3490 err = snd_hda_ctl_add(codec, 0, kctl);
3178 if (err < 0) 3491 if (err < 0)
3179 return err; 3492 return err;
3180 } 3493 }
@@ -3207,8 +3520,27 @@ static void hda_keep_power_on(struct hda_codec *codec)
3207{ 3520{
3208 codec->power_count++; 3521 codec->power_count++;
3209 codec->power_on = 1; 3522 codec->power_on = 1;
3523 codec->power_jiffies = jiffies;
3210} 3524}
3211 3525
3526/* update the power on/off account with the current jiffies */
3527void snd_hda_update_power_acct(struct hda_codec *codec)
3528{
3529 unsigned long delta = jiffies - codec->power_jiffies;
3530 if (codec->power_on)
3531 codec->power_on_acct += delta;
3532 else
3533 codec->power_off_acct += delta;
3534 codec->power_jiffies += delta;
3535}
3536
3537/**
3538 * snd_hda_power_up - Power-up the codec
3539 * @codec: HD-audio codec
3540 *
3541 * Increment the power-up counter and power up the hardware really when
3542 * not turned on yet.
3543 */
3212void snd_hda_power_up(struct hda_codec *codec) 3544void snd_hda_power_up(struct hda_codec *codec)
3213{ 3545{
3214 struct hda_bus *bus = codec->bus; 3546 struct hda_bus *bus = codec->bus;
@@ -3217,7 +3549,9 @@ void snd_hda_power_up(struct hda_codec *codec)
3217 if (codec->power_on || codec->power_transition) 3549 if (codec->power_on || codec->power_transition)
3218 return; 3550 return;
3219 3551
3552 snd_hda_update_power_acct(codec);
3220 codec->power_on = 1; 3553 codec->power_on = 1;
3554 codec->power_jiffies = jiffies;
3221 if (bus->ops.pm_notify) 3555 if (bus->ops.pm_notify)
3222 bus->ops.pm_notify(bus); 3556 bus->ops.pm_notify(bus);
3223 hda_call_codec_resume(codec); 3557 hda_call_codec_resume(codec);
@@ -3229,9 +3563,13 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up);
3229#define power_save(codec) \ 3563#define power_save(codec) \
3230 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3564 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3231 3565
3232#define power_save(codec) \ 3566/**
3233 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3567 * snd_hda_power_down - Power-down the codec
3234 3568 * @codec: HD-audio codec
3569 *
3570 * Decrement the power-up counter and schedules the power-off work if
3571 * the counter rearches to zero.
3572 */
3235void snd_hda_power_down(struct hda_codec *codec) 3573void snd_hda_power_down(struct hda_codec *codec)
3236{ 3574{
3237 --codec->power_count; 3575 --codec->power_count;
@@ -3245,6 +3583,19 @@ void snd_hda_power_down(struct hda_codec *codec)
3245} 3583}
3246EXPORT_SYMBOL_HDA(snd_hda_power_down); 3584EXPORT_SYMBOL_HDA(snd_hda_power_down);
3247 3585
3586/**
3587 * snd_hda_check_amp_list_power - Check the amp list and update the power
3588 * @codec: HD-audio codec
3589 * @check: the object containing an AMP list and the status
3590 * @nid: NID to check / update
3591 *
3592 * Check whether the given NID is in the amp list. If it's in the list,
3593 * check the current AMP status, and update the the power-status according
3594 * to the mute status.
3595 *
3596 * This function is supposed to be set or called from the check_power_status
3597 * patch ops.
3598 */
3248int snd_hda_check_amp_list_power(struct hda_codec *codec, 3599int snd_hda_check_amp_list_power(struct hda_codec *codec,
3249 struct hda_loopback_check *check, 3600 struct hda_loopback_check *check,
3250 hda_nid_t nid) 3601 hda_nid_t nid)
@@ -3286,6 +3637,10 @@ EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3286/* 3637/*
3287 * Channel mode helper 3638 * Channel mode helper
3288 */ 3639 */
3640
3641/**
3642 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3643 */
3289int snd_hda_ch_mode_info(struct hda_codec *codec, 3644int snd_hda_ch_mode_info(struct hda_codec *codec,
3290 struct snd_ctl_elem_info *uinfo, 3645 struct snd_ctl_elem_info *uinfo,
3291 const struct hda_channel_mode *chmode, 3646 const struct hda_channel_mode *chmode,
@@ -3302,6 +3657,9 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
3302} 3657}
3303EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info); 3658EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3304 3659
3660/**
3661 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3662 */
3305int snd_hda_ch_mode_get(struct hda_codec *codec, 3663int snd_hda_ch_mode_get(struct hda_codec *codec,
3306 struct snd_ctl_elem_value *ucontrol, 3664 struct snd_ctl_elem_value *ucontrol,
3307 const struct hda_channel_mode *chmode, 3665 const struct hda_channel_mode *chmode,
@@ -3320,6 +3678,9 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
3320} 3678}
3321EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get); 3679EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3322 3680
3681/**
3682 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3683 */
3323int snd_hda_ch_mode_put(struct hda_codec *codec, 3684int snd_hda_ch_mode_put(struct hda_codec *codec,
3324 struct snd_ctl_elem_value *ucontrol, 3685 struct snd_ctl_elem_value *ucontrol,
3325 const struct hda_channel_mode *chmode, 3686 const struct hda_channel_mode *chmode,
@@ -3344,6 +3705,10 @@ EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3344/* 3705/*
3345 * input MUX helper 3706 * input MUX helper
3346 */ 3707 */
3708
3709/**
3710 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3711 */
3347int snd_hda_input_mux_info(const struct hda_input_mux *imux, 3712int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3348 struct snd_ctl_elem_info *uinfo) 3713 struct snd_ctl_elem_info *uinfo)
3349{ 3714{
@@ -3362,6 +3727,9 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3362} 3727}
3363EXPORT_SYMBOL_HDA(snd_hda_input_mux_info); 3728EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3364 3729
3730/**
3731 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3732 */
3365int snd_hda_input_mux_put(struct hda_codec *codec, 3733int snd_hda_input_mux_put(struct hda_codec *codec,
3366 const struct hda_input_mux *imux, 3734 const struct hda_input_mux *imux,
3367 struct snd_ctl_elem_value *ucontrol, 3735 struct snd_ctl_elem_value *ucontrol,
@@ -3421,8 +3789,29 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3421 } 3789 }
3422} 3790}
3423 3791
3424/* 3792/**
3425 * open the digital out in the exclusive mode 3793 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3794 * @bus: HD-audio bus
3795 */
3796void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3797{
3798 struct hda_codec *codec;
3799
3800 if (!bus)
3801 return;
3802 list_for_each_entry(codec, &bus->codec_list, list) {
3803#ifdef CONFIG_SND_HDA_POWER_SAVE
3804 if (!codec->power_on)
3805 continue;
3806#endif
3807 if (codec->patch_ops.reboot_notify)
3808 codec->patch_ops.reboot_notify(codec);
3809 }
3810}
3811EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3812
3813/**
3814 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3426 */ 3815 */
3427int snd_hda_multi_out_dig_open(struct hda_codec *codec, 3816int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3428 struct hda_multi_out *mout) 3817 struct hda_multi_out *mout)
@@ -3437,6 +3826,9 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3437} 3826}
3438EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open); 3827EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3439 3828
3829/**
3830 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3831 */
3440int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3832int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3441 struct hda_multi_out *mout, 3833 struct hda_multi_out *mout,
3442 unsigned int stream_tag, 3834 unsigned int stream_tag,
@@ -3450,6 +3842,9 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3450} 3842}
3451EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare); 3843EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3452 3844
3845/**
3846 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3847 */
3453int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, 3848int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3454 struct hda_multi_out *mout) 3849 struct hda_multi_out *mout)
3455{ 3850{
@@ -3460,8 +3855,8 @@ int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3460} 3855}
3461EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup); 3856EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
3462 3857
3463/* 3858/**
3464 * release the digital out 3859 * snd_hda_multi_out_dig_close - release the digital out stream
3465 */ 3860 */
3466int snd_hda_multi_out_dig_close(struct hda_codec *codec, 3861int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3467 struct hda_multi_out *mout) 3862 struct hda_multi_out *mout)
@@ -3473,8 +3868,12 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3473} 3868}
3474EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close); 3869EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
3475 3870
3476/* 3871/**
3477 * set up more restrictions for analog out 3872 * snd_hda_multi_out_analog_open - open analog outputs
3873 *
3874 * Open analog outputs and set up the hw-constraints.
3875 * If the digital outputs can be opened as slave, open the digital
3876 * outputs, too.
3478 */ 3877 */
3479int snd_hda_multi_out_analog_open(struct hda_codec *codec, 3878int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3480 struct hda_multi_out *mout, 3879 struct hda_multi_out *mout,
@@ -3519,9 +3918,11 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3519} 3918}
3520EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open); 3919EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
3521 3920
3522/* 3921/**
3523 * set up the i/o for analog out 3922 * 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. 3923 *
3924 * Set up the i/o for analog out.
3925 * When the digital out is available, copy the front out to digital out, too.
3525 */ 3926 */
3526int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 3927int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3527 struct hda_multi_out *mout, 3928 struct hda_multi_out *mout,
@@ -3578,8 +3979,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3578} 3979}
3579EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); 3980EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
3580 3981
3581/* 3982/**
3582 * clean up the setting for analog out 3983 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3583 */ 3984 */
3584int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, 3985int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3585 struct hda_multi_out *mout) 3986 struct hda_multi_out *mout)
@@ -3965,8 +4366,14 @@ EXPORT_SYMBOL_HDA(snd_hda_resume);
3965 * generic arrays 4366 * generic arrays
3966 */ 4367 */
3967 4368
3968/* get a new element from the given array 4369/**
3969 * if it exceeds the pre-allocated array size, re-allocate the array 4370 * snd_array_new - get a new element from the given array
4371 * @array: the array object
4372 *
4373 * Get a new element from the given array. If it exceeds the
4374 * pre-allocated array size, re-allocate the array.
4375 *
4376 * Returns NULL if allocation failed.
3970 */ 4377 */
3971void *snd_array_new(struct snd_array *array) 4378void *snd_array_new(struct snd_array *array)
3972{ 4379{
@@ -3990,7 +4397,10 @@ void *snd_array_new(struct snd_array *array)
3990} 4397}
3991EXPORT_SYMBOL_HDA(snd_array_new); 4398EXPORT_SYMBOL_HDA(snd_array_new);
3992 4399
3993/* free the given array elements */ 4400/**
4401 * snd_array_free - free the given array elements
4402 * @array: the array object
4403 */
3994void snd_array_free(struct snd_array *array) 4404void snd_array_free(struct snd_array *array)
3995{ 4405{
3996 kfree(array->list); 4406 kfree(array->list);
@@ -4000,7 +4410,12 @@ void snd_array_free(struct snd_array *array)
4000} 4410}
4001EXPORT_SYMBOL_HDA(snd_array_free); 4411EXPORT_SYMBOL_HDA(snd_array_free);
4002 4412
4003/* 4413/**
4414 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4415 * @pcm: PCM caps bits
4416 * @buf: the string buffer to write
4417 * @buflen: the max buffer length
4418 *
4004 * used by hda_proc.c and hda_eld.c 4419 * used by hda_proc.c and hda_eld.c
4005 */ 4420 */
4006void snd_print_pcm_rates(int pcm, char *buf, int buflen) 4421void snd_print_pcm_rates(int pcm, char *buf, int buflen)
@@ -4019,6 +4434,14 @@ void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4019} 4434}
4020EXPORT_SYMBOL_HDA(snd_print_pcm_rates); 4435EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4021 4436
4437/**
4438 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4439 * @pcm: PCM caps bits
4440 * @buf: the string buffer to write
4441 * @buflen: the max buffer length
4442 *
4443 * used by hda_proc.c and hda_eld.c
4444 */
4022void snd_print_pcm_bits(int pcm, char *buf, int buflen) 4445void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4023{ 4446{
4024 static unsigned int bits[] = { 8, 16, 20, 24, 32 }; 4447 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..1d541b7f5547 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)
@@ -631,6 +639,7 @@ struct hda_bus {
631 unsigned int rirb_error:1; /* error in codec communication */ 639 unsigned int rirb_error:1; /* error in codec communication */
632 unsigned int response_reset:1; /* controller was reset */ 640 unsigned int response_reset:1; /* controller was reset */
633 unsigned int in_reset:1; /* during reset operation */ 641 unsigned int in_reset:1; /* during reset operation */
642 unsigned int power_keep_link_on:1; /* don't power off HDA link */
634}; 643};
635 644
636/* 645/*
@@ -674,6 +683,7 @@ struct hda_codec_ops {
674#ifdef CONFIG_SND_HDA_POWER_SAVE 683#ifdef CONFIG_SND_HDA_POWER_SAVE
675 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); 684 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
676#endif 685#endif
686 void (*reboot_notify)(struct hda_codec *codec);
677}; 687};
678 688
679/* record for amp information cache */ 689/* record for amp information cache */
@@ -771,6 +781,7 @@ struct hda_codec {
771 781
772 /* beep device */ 782 /* beep device */
773 struct hda_beep *beep; 783 struct hda_beep *beep;
784 unsigned int beep_mode;
774 785
775 /* widget capabilities cache */ 786 /* widget capabilities cache */
776 unsigned int num_nodes; 787 unsigned int num_nodes;
@@ -811,6 +822,9 @@ struct hda_codec {
811 unsigned int power_transition :1; /* power-state in transition */ 822 unsigned int power_transition :1; /* power-state in transition */
812 int power_count; /* current (global) power refcount */ 823 int power_count; /* current (global) power refcount */
813 struct delayed_work power_work; /* delayed task for powerdown */ 824 struct delayed_work power_work; /* delayed task for powerdown */
825 unsigned long power_on_acct;
826 unsigned long power_off_acct;
827 unsigned long power_jiffies;
814#endif 828#endif
815 829
816 /* codec-specific additional proc output */ 830 /* codec-specific additional proc output */
@@ -910,6 +924,7 @@ int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
910 * Misc 924 * Misc
911 */ 925 */
912void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen); 926void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
927void snd_hda_bus_reboot_notify(struct hda_bus *bus);
913 928
914/* 929/*
915 * power management 930 * power management
@@ -933,6 +948,7 @@ const char *snd_hda_get_jack_location(u32 cfg);
933void snd_hda_power_up(struct hda_codec *codec); 948void snd_hda_power_up(struct hda_codec *codec);
934void snd_hda_power_down(struct hda_codec *codec); 949void snd_hda_power_down(struct hda_codec *codec);
935#define snd_hda_codec_needs_resume(codec) codec->power_count 950#define snd_hda_codec_needs_resume(codec) codec->power_count
951void snd_hda_update_power_acct(struct hda_codec *codec);
936#else 952#else
937static inline void snd_hda_power_up(struct hda_codec *codec) {} 953static inline void snd_hda_power_up(struct hda_codec *codec) {}
938static inline void snd_hda_power_down(struct hda_codec *codec) {} 954static 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..4228f2fe5956 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -309,17 +309,12 @@ out_fail:
309 return -EINVAL; 309 return -EINVAL;
310} 310}
311 311
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) 312static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid)
318{ 313{
319 int eldv; 314 int eldv;
320 int present; 315 int present;
321 316
322 present = hdmi_present_sense(codec, nid); 317 present = snd_hda_pin_sense(codec, nid);
323 eldv = (present & AC_PINSENSE_ELDV); 318 eldv = (present & AC_PINSENSE_ELDV);
324 present = (present & AC_PINSENSE_PRESENCE); 319 present = (present & AC_PINSENSE_PRESENCE);
325 320
@@ -477,6 +472,8 @@ static void hdmi_print_eld_info(struct snd_info_entry *entry,
477 [4 ... 7] = "reserved" 472 [4 ... 7] = "reserved"
478 }; 473 };
479 474
475 snd_iprintf(buffer, "monitor_present\t\t%d\n", e->monitor_present);
476 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); 477 snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
481 snd_iprintf(buffer, "connection_type\t\t%s\n", 478 snd_iprintf(buffer, "connection_type\t\t%s\n",
482 eld_connection_type_names[e->conn_type]); 479 eld_connection_type_names[e->conn_type]);
@@ -518,7 +515,11 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
518 * monitor_name manufacture_id product_id 515 * monitor_name manufacture_id product_id
519 * eld_version edid_version 516 * eld_version edid_version
520 */ 517 */
521 if (!strcmp(name, "connection_type")) 518 if (!strcmp(name, "monitor_present"))
519 e->monitor_present = val;
520 else if (!strcmp(name, "eld_valid"))
521 e->eld_valid = val;
522 else if (!strcmp(name, "connection_type"))
522 e->conn_type = val; 523 e->conn_type = val;
523 else if (!strcmp(name, "port_id")) 524 else if (!strcmp(name, "port_id"))
524 e->port_id = val; 525 e->port_id = val;
@@ -560,13 +561,14 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
560} 561}
561 562
562 563
563int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld) 564int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
565 int index)
564{ 566{
565 char name[32]; 567 char name[32];
566 struct snd_info_entry *entry; 568 struct snd_info_entry *entry;
567 int err; 569 int err;
568 570
569 snprintf(name, sizeof(name), "eld#%d", codec->addr); 571 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
570 err = snd_card_proc_new(codec->bus->card, name, &entry); 572 err = snd_card_proc_new(codec->bus->card, name, &entry);
571 if (err < 0) 573 if (err < 0)
572 return err; 574 return err;
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index b36f6c5a92df..092c6a7c2ff3 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,7 @@ 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, 0, snd_ctl_new1(&cap_sel, codec));
861 if (err < 0) 865 if (err < 0)
862 return err; 866 return err;
863 867
@@ -875,7 +879,8 @@ static int build_input_controls(struct hda_codec *codec)
875 HDA_CODEC_VOLUME(name, adc_node->nid, 879 HDA_CODEC_VOLUME(name, adc_node->nid,
876 spec->input_mux.items[i].index, 880 spec->input_mux.items[i].index,
877 HDA_INPUT); 881 HDA_INPUT);
878 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec)); 882 err = snd_hda_ctl_add(codec, adc_node->nid,
883 snd_ctl_new1(&knew, codec));
879 if (err < 0) 884 if (err < 0)
880 return err; 885 return err;
881 } 886 }
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index cc24e6721d74..40ccb419b6e9 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/*
@@ -390,8 +429,7 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
390 char *key, *val; 429 char *key, *val;
391 struct hda_hint *hint; 430 struct hda_hint *hint;
392 431
393 while (isspace(*buf)) 432 buf = skip_spaces(buf);
394 buf++;
395 if (!*buf || *buf == '#' || *buf == '\n') 433 if (!*buf || *buf == '#' || *buf == '\n')
396 return 0; 434 return 0;
397 if (*buf == '=') 435 if (*buf == '=')
@@ -406,8 +444,7 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
406 return -EINVAL; 444 return -EINVAL;
407 } 445 }
408 *val++ = 0; 446 *val++ = 0;
409 while (isspace(*val)) 447 val = skip_spaces(val);
410 val++;
411 remove_trail_spaces(key); 448 remove_trail_spaces(key);
412 remove_trail_spaces(val); 449 remove_trail_spaces(val);
413 hint = get_hint(codec, key); 450 hint = get_hint(codec, key);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index e340792f6cb3..ff8ad46cc50e 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;
@@ -404,6 +413,7 @@ struct azx {
404 unsigned short codec_mask; 413 unsigned short codec_mask;
405 int codec_probe_mask; /* copied from probe_mask option */ 414 int codec_probe_mask; /* copied from probe_mask option */
406 struct hda_bus *bus; 415 struct hda_bus *bus;
416 unsigned int beep_mode;
407 417
408 /* CORB/RIRB */ 418 /* CORB/RIRB */
409 struct azx_rb corb; 419 struct azx_rb corb;
@@ -677,6 +687,14 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
677 } 687 }
678 } 688 }
679 689
690 if (!chip->polling_mode) {
691 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
692 "switching to polling mode: last cmd=0x%08x\n",
693 chip->last_cmd[addr]);
694 chip->polling_mode = 1;
695 goto again;
696 }
697
680 if (chip->msi) { 698 if (chip->msi) {
681 snd_printk(KERN_WARNING SFX "No response from codec, " 699 snd_printk(KERN_WARNING SFX "No response from codec, "
682 "disabling MSI: last cmd=0x%08x\n", 700 "disabling MSI: last cmd=0x%08x\n",
@@ -692,14 +710,6 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
692 goto again; 710 goto again;
693 } 711 }
694 712
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) { 713 if (chip->probing) {
704 /* If this critical timeout happens during the codec probing 714 /* If this critical timeout happens during the codec probing
705 * phase, this is likely an access to a non-existing codec 715 * phase, this is likely an access to a non-existing codec
@@ -722,9 +732,10 @@ static unsigned int azx_rirb_get_response(struct hda_bus *bus,
722 chip->last_cmd[addr]); 732 chip->last_cmd[addr]);
723 chip->single_cmd = 1; 733 chip->single_cmd = 1;
724 bus->response_reset = 0; 734 bus->response_reset = 0;
725 /* re-initialize CORB/RIRB */ 735 /* release CORB/RIRB */
726 azx_free_cmd_io(chip); 736 azx_free_cmd_io(chip);
727 azx_init_cmd_io(chip); 737 /* disable unsolicited responses */
738 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
728 return -1; 739 return -1;
729} 740}
730 741
@@ -865,7 +876,9 @@ static int azx_reset(struct azx *chip)
865 } 876 }
866 877
867 /* Accept unsolicited responses */ 878 /* Accept unsolicited responses */
868 azx_writel(chip, GCTL, azx_readl(chip, GCTL) | ICH6_GCTL_UNSOL); 879 if (!chip->single_cmd)
880 azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
881 ICH6_GCTL_UNSOL);
869 882
870 /* detect codecs */ 883 /* detect codecs */
871 if (!chip->codec_mask) { 884 if (!chip->codec_mask) {
@@ -980,7 +993,8 @@ static void azx_init_chip(struct azx *chip)
980 azx_int_enable(chip); 993 azx_int_enable(chip);
981 994
982 /* initialize the codec command I/O */ 995 /* initialize the codec command I/O */
983 azx_init_cmd_io(chip); 996 if (!chip->single_cmd)
997 azx_init_cmd_io(chip);
984 998
985 /* program the position buffer */ 999 /* program the position buffer */
986 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); 1000 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
@@ -1400,6 +1414,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model)
1400 err = snd_hda_codec_new(chip->bus, c, &codec); 1414 err = snd_hda_codec_new(chip->bus, c, &codec);
1401 if (err < 0) 1415 if (err < 0)
1402 continue; 1416 continue;
1417 codec->beep_mode = chip->beep_mode;
1403 codecs++; 1418 codecs++;
1404 } 1419 }
1405 } 1420 }
@@ -2067,7 +2082,8 @@ static void azx_power_notify(struct hda_bus *bus)
2067 } 2082 }
2068 if (power_on) 2083 if (power_on)
2069 azx_init_chip(chip); 2084 azx_init_chip(chip);
2070 else if (chip->running && power_save_controller) 2085 else if (chip->running && power_save_controller &&
2086 !bus->power_keep_link_on)
2071 azx_stop_chip(chip); 2087 azx_stop_chip(chip);
2072} 2088}
2073#endif /* CONFIG_SND_HDA_POWER_SAVE */ 2089#endif /* CONFIG_SND_HDA_POWER_SAVE */
@@ -2150,6 +2166,7 @@ static int azx_resume(struct pci_dev *pci)
2150static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) 2166static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
2151{ 2167{
2152 struct azx *chip = container_of(nb, struct azx, reboot_notifier); 2168 struct azx *chip = container_of(nb, struct azx, reboot_notifier);
2169 snd_hda_bus_reboot_notify(chip->bus);
2153 azx_stop_chip(chip); 2170 azx_stop_chip(chip);
2154 return NOTIFY_OK; 2171 return NOTIFY_OK;
2155} 2172}
@@ -2217,7 +2234,9 @@ static int azx_dev_free(struct snd_device *device)
2217static struct snd_pci_quirk position_fix_list[] __devinitdata = { 2234static struct snd_pci_quirk position_fix_list[] __devinitdata = {
2218 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), 2235 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
2219 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), 2236 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
2237 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
2220 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), 2238 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
2239 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
2221 {} 2240 {}
2222}; 2241};
2223 2242
@@ -2300,11 +2319,10 @@ static void __devinit check_probe_mask(struct azx *chip, int dev)
2300} 2319}
2301 2320
2302/* 2321/*
2303 * white-list for enable_msi 2322 * white/black-list for enable_msi
2304 */ 2323 */
2305static struct snd_pci_quirk msi_white_list[] __devinitdata = { 2324static struct snd_pci_quirk msi_black_list[] __devinitdata = {
2306 SND_PCI_QUIRK(0x103c, 0x30f7, "HP Pavilion dv4t-1300", 1), 2325 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
2307 SND_PCI_QUIRK(0x103c, 0x3607, "HP Compa CQ40", 1),
2308 {} 2326 {}
2309}; 2327};
2310 2328
@@ -2312,10 +2330,12 @@ static void __devinit check_msi(struct azx *chip)
2312{ 2330{
2313 const struct snd_pci_quirk *q; 2331 const struct snd_pci_quirk *q;
2314 2332
2315 chip->msi = enable_msi; 2333 if (enable_msi >= 0) {
2316 if (chip->msi) 2334 chip->msi = !!enable_msi;
2317 return; 2335 return;
2318 q = snd_pci_quirk_lookup(chip->pci, msi_white_list); 2336 }
2337 chip->msi = 1; /* enable MSI as default */
2338 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
2319 if (q) { 2339 if (q) {
2320 printk(KERN_INFO 2340 printk(KERN_INFO
2321 "hda_intel: msi for device %04x:%04x set to %d\n", 2341 "hda_intel: msi for device %04x:%04x set to %d\n",
@@ -2432,6 +2452,11 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2432 } 2452 }
2433 } 2453 }
2434 2454
2455 /* disable 64bit DMA address for Teradici */
2456 /* it does not work with device 6549:1200 subsys e4a2:040b */
2457 if (chip->driver_type == AZX_DRIVER_TERA)
2458 gcap &= ~ICH6_GCAP_64OK;
2459
2435 /* allow 64bit DMA address if supported by H/W */ 2460 /* allow 64bit DMA address if supported by H/W */
2436 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 2461 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
2437 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); 2462 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
@@ -2574,6 +2599,10 @@ static int __devinit azx_probe(struct pci_dev *pci,
2574 goto out_free; 2599 goto out_free;
2575 card->private_data = chip; 2600 card->private_data = chip;
2576 2601
2602#ifdef CONFIG_SND_HDA_INPUT_BEEP
2603 chip->beep_mode = beep_mode[dev];
2604#endif
2605
2577 /* create codec instances */ 2606 /* create codec instances */
2578 err = azx_codec_create(chip, model[dev]); 2607 err = azx_codec_create(chip, model[dev]);
2579 if (err < 0) 2608 if (err < 0)
@@ -2685,6 +2714,9 @@ static struct pci_device_id azx_ids[] = {
2685 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA }, 2714 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
2686 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA }, 2715 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
2687 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA }, 2716 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
2717 { PCI_DEVICE(0x10de, 0x0be2), .driver_data = AZX_DRIVER_NVIDIA },
2718 { PCI_DEVICE(0x10de, 0x0be3), .driver_data = AZX_DRIVER_NVIDIA },
2719 { PCI_DEVICE(0x10de, 0x0be4), .driver_data = AZX_DRIVER_NVIDIA },
2688 { PCI_DEVICE(0x10de, 0x0d94), .driver_data = AZX_DRIVER_NVIDIA }, 2720 { PCI_DEVICE(0x10de, 0x0d94), .driver_data = AZX_DRIVER_NVIDIA },
2689 { PCI_DEVICE(0x10de, 0x0d95), .driver_data = AZX_DRIVER_NVIDIA }, 2721 { PCI_DEVICE(0x10de, 0x0d95), .driver_data = AZX_DRIVER_NVIDIA },
2690 { PCI_DEVICE(0x10de, 0x0d96), .driver_data = AZX_DRIVER_NVIDIA }, 2722 { PCI_DEVICE(0x10de, 0x0d96), .driver_data = AZX_DRIVER_NVIDIA },
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 5f1dcc59002b..5778ae882b83 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -23,6 +23,15 @@
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
26/* 35/*
27 * for mixer controls 36 * for mixer controls
28 */ 37 */
@@ -33,6 +42,7 @@
33/* mono volume with index (index=0,1,...) (channel=1,2) */ 42/* mono volume with index (index=0,1,...) (channel=1,2) */
34#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 43#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
35 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 44 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
45 .subdevice = HDA_SUBDEV_NID_FLAG | (nid), \
36 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 46 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
37 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 47 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
38 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ 48 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
@@ -53,6 +63,7 @@
53/* mono mute switch with index (index=0,1,...) (channel=1,2) */ 63/* mono mute switch with index (index=0,1,...) (channel=1,2) */
54#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 64#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
55 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 65 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
66 .subdevice = HDA_SUBDEV_NID_FLAG | (nid), \
56 .info = snd_hda_mixer_amp_switch_info, \ 67 .info = snd_hda_mixer_amp_switch_info, \
57 .get = snd_hda_mixer_amp_switch_get, \ 68 .get = snd_hda_mixer_amp_switch_get, \
58 .put = snd_hda_mixer_amp_switch_put, \ 69 .put = snd_hda_mixer_amp_switch_put, \
@@ -66,6 +77,28 @@
66/* stereo mute switch */ 77/* stereo mute switch */
67#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \ 78#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
68 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction) 79 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
80#ifdef CONFIG_SND_HDA_INPUT_BEEP
81/* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
82#define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
83 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
84 .subdevice = HDA_SUBDEV_NID_FLAG | (nid), \
85 .info = snd_hda_mixer_amp_switch_info, \
86 .get = snd_hda_mixer_amp_switch_get, \
87 .put = snd_hda_mixer_amp_switch_put_beep, \
88 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
89#else
90/* no digital beep - just the standard one */
91#define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
92 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
93#endif /* CONFIG_SND_HDA_INPUT_BEEP */
94/* special beep mono mute switch */
95#define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
96 HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
97/* special beep stereo mute switch */
98#define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
99 HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
100
101extern const char *snd_hda_pcm_type_name[];
69 102
70int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 103int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
71 struct snd_ctl_elem_info *uinfo); 104 struct snd_ctl_elem_info *uinfo);
@@ -81,6 +114,10 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
81 struct snd_ctl_elem_value *ucontrol); 114 struct snd_ctl_elem_value *ucontrol);
82int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 115int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
83 struct snd_ctl_elem_value *ucontrol); 116 struct snd_ctl_elem_value *ucontrol);
117#ifdef CONFIG_SND_HDA_INPUT_BEEP
118int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
119 struct snd_ctl_elem_value *ucontrol);
120#endif
84/* lowlevel accessor with caching; use carefully */ 121/* lowlevel accessor with caching; use carefully */
85int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 122int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
86 int direction, int index); 123 int direction, int index);
@@ -424,8 +461,16 @@ 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, 461int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
425 unsigned int caps); 462 unsigned int caps);
426u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); 463u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
464u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
465int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
427 466
428int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl); 467struct hda_nid_item {
468 struct snd_kcontrol *kctl;
469 hda_nid_t nid;
470};
471
472int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
473 struct snd_kcontrol *kctl);
429void snd_hda_ctls_clear(struct hda_codec *codec); 474void snd_hda_ctls_clear(struct hda_codec *codec);
430 475
431/* 476/*
@@ -437,6 +482,15 @@ int snd_hda_create_hwdep(struct hda_codec *codec);
437static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; } 482static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
438#endif 483#endif
439 484
485#if defined(CONFIG_SND_HDA_POWER_SAVE) && defined(CONFIG_SND_HDA_HWDEP)
486int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec);
487#else
488static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
489{
490 return 0;
491}
492#endif
493
440#ifdef CONFIG_SND_HDA_RECONFIG 494#ifdef CONFIG_SND_HDA_RECONFIG
441int snd_hda_hwdep_add_sysfs(struct hda_codec *codec); 495int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
442#else 496#else
@@ -490,7 +544,8 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
490 * AMP control callbacks 544 * AMP control callbacks
491 */ 545 */
492/* retrieve parameters from private_value */ 546/* retrieve parameters from private_value */
493#define get_amp_nid(kc) ((kc)->private_value & 0xffff) 547#define get_amp_nid_(pv) ((pv) & 0xffff)
548#define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
494#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3) 549#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
495#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1) 550#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
496#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 551#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
@@ -516,9 +571,11 @@ struct cea_sad {
516 * ELD: EDID Like Data 571 * ELD: EDID Like Data
517 */ 572 */
518struct hdmi_eld { 573struct hdmi_eld {
574 bool monitor_present;
575 bool eld_valid;
519 int eld_size; 576 int eld_size;
520 int baseline_len; 577 int baseline_len;
521 int eld_ver; /* (eld_ver == 0) indicates invalid ELD */ 578 int eld_ver;
522 int cea_edid_ver; 579 int cea_edid_ver;
523 char monitor_name[ELD_MAX_MNL + 1]; 580 char monitor_name[ELD_MAX_MNL + 1];
524 int manufacture_id; 581 int manufacture_id;
@@ -541,11 +598,13 @@ int snd_hdmi_get_eld(struct hdmi_eld *, struct hda_codec *, hda_nid_t);
541void snd_hdmi_show_eld(struct hdmi_eld *eld); 598void snd_hdmi_show_eld(struct hdmi_eld *eld);
542 599
543#ifdef CONFIG_PROC_FS 600#ifdef CONFIG_PROC_FS
544int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld); 601int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld,
602 int index);
545void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld); 603void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld);
546#else 604#else
547static inline int snd_hda_eld_proc_new(struct hda_codec *codec, 605static inline int snd_hda_eld_proc_new(struct hda_codec *codec,
548 struct hdmi_eld *eld) 606 struct hdmi_eld *eld,
607 int index)
549{ 608{
550 return 0; 609 return 0;
551} 610}
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 95f24e4729f8..c9afc04adac8 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,41 @@ 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_mixers(struct snd_info_buffer *buffer,
65 struct hda_codec *codec, hda_nid_t nid)
66{
67 int i;
68 struct hda_nid_item *items = codec->mixers.list;
69 struct snd_kcontrol *kctl;
70 for (i = 0; i < codec->mixers.used; i++) {
71 if (items[i].nid == nid) {
72 kctl = items[i].kctl;
73 snd_iprintf(buffer,
74 " Control: name=\"%s\", index=%i, device=%i\n",
75 kctl->id.name, kctl->id.index, kctl->id.device);
76 }
77 }
78}
79
80static void print_nid_pcms(struct snd_info_buffer *buffer,
81 struct hda_codec *codec, hda_nid_t nid)
82{
83 int pcm, type;
84 struct hda_pcm *cpcm;
85 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
86 cpcm = &codec->pcm_info[pcm];
87 for (type = 0; type < 2; type++) {
88 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
89 continue;
90 snd_iprintf(buffer, " Device: name=\"%s\", "
91 "type=\"%s\", device=%i\n",
92 cpcm->name,
93 snd_hda_pcm_type_name[cpcm->pcm_type],
94 cpcm->pcm->device);
95 }
96 }
97}
98
49static void print_amp_caps(struct snd_info_buffer *buffer, 99static void print_amp_caps(struct snd_info_buffer *buffer,
50 struct hda_codec *codec, hda_nid_t nid, int dir) 100 struct hda_codec *codec, hda_nid_t nid, int dir)
51{ 101{
@@ -190,9 +240,14 @@ static void print_pin_caps(struct snd_info_buffer *buffer,
190 /* Realtek uses this bit as a different meaning */ 240 /* Realtek uses this bit as a different meaning */
191 if ((codec->vendor_id >> 16) == 0x10ec) 241 if ((codec->vendor_id >> 16) == 0x10ec)
192 snd_iprintf(buffer, " R/L"); 242 snd_iprintf(buffer, " R/L");
193 else 243 else {
244 if (caps & AC_PINCAP_HBR)
245 snd_iprintf(buffer, " HBR");
194 snd_iprintf(buffer, " HDMI"); 246 snd_iprintf(buffer, " HDMI");
247 }
195 } 248 }
249 if (caps & AC_PINCAP_DP)
250 snd_iprintf(buffer, " DP");
196 if (caps & AC_PINCAP_TRIG_REQ) 251 if (caps & AC_PINCAP_TRIG_REQ)
197 snd_iprintf(buffer, " Trigger"); 252 snd_iprintf(buffer, " Trigger");
198 if (caps & AC_PINCAP_IMP_SENSE) 253 if (caps & AC_PINCAP_IMP_SENSE)
@@ -363,8 +418,24 @@ static const char *get_pwr_state(u32 state)
363static void print_power_state(struct snd_info_buffer *buffer, 418static void print_power_state(struct snd_info_buffer *buffer,
364 struct hda_codec *codec, hda_nid_t nid) 419 struct hda_codec *codec, hda_nid_t nid)
365{ 420{
421 static char *names[] = {
422 [ilog2(AC_PWRST_D0SUP)] = "D0",
423 [ilog2(AC_PWRST_D1SUP)] = "D1",
424 [ilog2(AC_PWRST_D2SUP)] = "D2",
425 [ilog2(AC_PWRST_D3SUP)] = "D3",
426 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
427 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
428 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
429 [ilog2(AC_PWRST_EPSS)] = "EPSS",
430 };
431
432 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
366 int pwr = snd_hda_codec_read(codec, nid, 0, 433 int pwr = snd_hda_codec_read(codec, nid, 0,
367 AC_VERB_GET_POWER_STATE, 0); 434 AC_VERB_GET_POWER_STATE, 0);
435 if (sup)
436 snd_iprintf(buffer, " Power states: %s\n",
437 bits_names(sup, names, ARRAY_SIZE(names)));
438
368 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n", 439 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n",
369 get_pwr_state(pwr & AC_PWRST_SETTING), 440 get_pwr_state(pwr & AC_PWRST_SETTING),
370 get_pwr_state((pwr & AC_PWRST_ACTUAL) >> 441 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
@@ -457,6 +528,7 @@ static void print_gpio(struct snd_info_buffer *buffer,
457 (data & (1<<i)) ? 1 : 0, 528 (data & (1<<i)) ? 1 : 0,
458 (unsol & (1<<i)) ? 1 : 0); 529 (unsol & (1<<i)) ? 1 : 0);
459 /* FIXME: add GPO and GPI pin information */ 530 /* FIXME: add GPO and GPI pin information */
531 print_nid_mixers(buffer, codec, nid);
460} 532}
461 533
462static void print_codec_info(struct snd_info_entry *entry, 534static void print_codec_info(struct snd_info_entry *entry,
@@ -536,6 +608,9 @@ static void print_codec_info(struct snd_info_entry *entry,
536 snd_iprintf(buffer, " CP"); 608 snd_iprintf(buffer, " CP");
537 snd_iprintf(buffer, "\n"); 609 snd_iprintf(buffer, "\n");
538 610
611 print_nid_mixers(buffer, codec, nid);
612 print_nid_pcms(buffer, codec, nid);
613
539 /* volume knob is a special widget that always have connection 614 /* volume knob is a special widget that always have connection
540 * list 615 * list
541 */ 616 */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 2d603f6aba63..1a36137e13ec 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,15 +157,19 @@ 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{
@@ -194,6 +199,7 @@ static int ad198x_build_controls(struct hda_codec *codec)
194 } 199 }
195 200
196 /* create beep controls if needed */ 201 /* create beep controls if needed */
202#ifdef CONFIG_SND_HDA_INPUT_BEEP
197 if (spec->beep_amp) { 203 if (spec->beep_amp) {
198 struct snd_kcontrol_new *knew; 204 struct snd_kcontrol_new *knew;
199 for (knew = ad_beep_mixer; knew->name; knew++) { 205 for (knew = ad_beep_mixer; knew->name; knew++) {
@@ -202,11 +208,14 @@ static int ad198x_build_controls(struct hda_codec *codec)
202 if (!kctl) 208 if (!kctl)
203 return -ENOMEM; 209 return -ENOMEM;
204 kctl->private_value = spec->beep_amp; 210 kctl->private_value = spec->beep_amp;
205 err = snd_hda_ctl_add(codec, kctl); 211 err = snd_hda_ctl_add(codec,
212 get_amp_nid_(spec->beep_amp),
213 kctl);
206 if (err < 0) 214 if (err < 0)
207 return err; 215 return err;
208 } 216 }
209 } 217 }
218#endif
210 219
211 /* if we have no master control, let's create it */ 220 /* if we have no master control, let's create it */
212 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 221 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
@@ -450,7 +459,7 @@ static struct hda_codec_ops ad198x_patch_ops = {
450 459
451/* 460/*
452 * EAPD control 461 * EAPD control
453 * the private value = nid | (invert << 8) 462 * the private value = nid
454 */ 463 */
455#define ad198x_eapd_info snd_ctl_boolean_mono_info 464#define ad198x_eapd_info snd_ctl_boolean_mono_info
456 465
@@ -459,8 +468,7 @@ static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
459{ 468{
460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
461 struct ad198x_spec *spec = codec->spec; 470 struct ad198x_spec *spec = codec->spec;
462 int invert = (kcontrol->private_value >> 8) & 1; 471 if (spec->inv_eapd)
463 if (invert)
464 ucontrol->value.integer.value[0] = ! spec->cur_eapd; 472 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
465 else 473 else
466 ucontrol->value.integer.value[0] = spec->cur_eapd; 474 ucontrol->value.integer.value[0] = spec->cur_eapd;
@@ -472,11 +480,10 @@ static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
472{ 480{
473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474 struct ad198x_spec *spec = codec->spec; 482 struct ad198x_spec *spec = codec->spec;
475 int invert = (kcontrol->private_value >> 8) & 1;
476 hda_nid_t nid = kcontrol->private_value & 0xff; 483 hda_nid_t nid = kcontrol->private_value & 0xff;
477 unsigned int eapd; 484 unsigned int eapd;
478 eapd = !!ucontrol->value.integer.value[0]; 485 eapd = !!ucontrol->value.integer.value[0];
479 if (invert) 486 if (spec->inv_eapd)
480 eapd = !eapd; 487 eapd = !eapd;
481 if (eapd == spec->cur_eapd) 488 if (eapd == spec->cur_eapd)
482 return 0; 489 return 0;
@@ -697,7 +704,7 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
697 .info = ad198x_eapd_info, 704 .info = ad198x_eapd_info,
698 .get = ad198x_eapd_get, 705 .get = ad198x_eapd_get,
699 .put = ad198x_eapd_put, 706 .put = ad198x_eapd_put,
700 .private_value = 0x1b | (1 << 8), /* port-D, inversed */ 707 .private_value = 0x1b, /* port-D */
701 }, 708 },
702 { } /* end */ 709 { } /* end */
703}; 710};
@@ -712,10 +719,10 @@ static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
712static void ad1986a_automic(struct hda_codec *codec) 719static void ad1986a_automic(struct hda_codec *codec)
713{ 720{
714 unsigned int present; 721 unsigned int present;
715 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0); 722 present = snd_hda_jack_detect(codec, 0x1f);
716 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */ 723 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
717 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL, 724 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
718 (present & AC_PINSENSE_PRESENCE) ? 0 : 2); 725 present ? 0 : 2);
719} 726}
720 727
721#define AD1986A_MIC_EVENT 0x36 728#define AD1986A_MIC_EVENT 0x36
@@ -754,10 +761,8 @@ static void ad1986a_update_hp(struct hda_codec *codec)
754static void ad1986a_hp_automute(struct hda_codec *codec) 761static void ad1986a_hp_automute(struct hda_codec *codec)
755{ 762{
756 struct ad198x_spec *spec = codec->spec; 763 struct ad198x_spec *spec = codec->spec;
757 unsigned int present;
758 764
759 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0); 765 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
760 spec->jack_present = !!(present & 0x80000000);
761 if (spec->inv_jack_detect) 766 if (spec->inv_jack_detect)
762 spec->jack_present = !spec->jack_present; 767 spec->jack_present = !spec->jack_present;
763 ad1986a_update_hp(codec); 768 ad1986a_update_hp(codec);
@@ -1068,6 +1073,7 @@ static int patch_ad1986a(struct hda_codec *codec)
1068 spec->loopback.amplist = ad1986a_loopbacks; 1073 spec->loopback.amplist = ad1986a_loopbacks;
1069#endif 1074#endif
1070 spec->vmaster_nid = 0x1b; 1075 spec->vmaster_nid = 0x1b;
1076 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
1071 1077
1072 codec->patch_ops = ad198x_patch_ops; 1078 codec->patch_ops = ad198x_patch_ops;
1073 1079
@@ -1547,8 +1553,7 @@ static void ad1981_hp_automute(struct hda_codec *codec)
1547{ 1553{
1548 unsigned int present; 1554 unsigned int present;
1549 1555
1550 present = snd_hda_codec_read(codec, 0x06, 0, 1556 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, 1557 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1553 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 1558 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1554} 1559}
@@ -1568,8 +1573,7 @@ static void ad1981_hp_automic(struct hda_codec *codec)
1568 }; 1573 };
1569 unsigned int present; 1574 unsigned int present;
1570 1575
1571 present = snd_hda_codec_read(codec, 0x08, 0, 1576 present = snd_hda_jack_detect(codec, 0x08);
1572 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1573 if (present) 1577 if (present)
1574 snd_hda_sequence_write(codec, mic_jack_on); 1578 snd_hda_sequence_write(codec, mic_jack_on);
1575 else 1579 else
@@ -1785,6 +1789,14 @@ static int patch_ad1981(struct hda_codec *codec)
1785 1789
1786 codec->patch_ops.init = ad1981_hp_init; 1790 codec->patch_ops.init = ad1981_hp_init;
1787 codec->patch_ops.unsol_event = ad1981_hp_unsol_event; 1791 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1792 /* set the upper-limit for mixer amp to 0dB for avoiding the
1793 * possible damage by overloading
1794 */
1795 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1796 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1797 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1798 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1799 (1 << AC_AMPCAP_MUTE_SHIFT));
1788 break; 1800 break;
1789 case AD1981_THINKPAD: 1801 case AD1981_THINKPAD:
1790 spec->mixers[0] = ad1981_thinkpad_mixers; 1802 spec->mixers[0] = ad1981_thinkpad_mixers;
@@ -2120,7 +2132,7 @@ static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2120 .info = ad198x_eapd_info, 2132 .info = ad198x_eapd_info,
2121 .get = ad198x_eapd_get, 2133 .get = ad198x_eapd_get,
2122 .put = ad198x_eapd_put, 2134 .put = ad198x_eapd_put,
2123 .private_value = 0x12 | (1 << 8), /* port-D, inversed */ 2135 .private_value = 0x12, /* port-D */
2124 }, 2136 },
2125 2137
2126 { } /* end */ 2138 { } /* end */
@@ -2524,7 +2536,7 @@ static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2524{ 2536{
2525 if ((res >> 26) != AD1988_HP_EVENT) 2537 if ((res >> 26) != AD1988_HP_EVENT)
2526 return; 2538 return;
2527 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31)) 2539 if (snd_hda_jack_detect(codec, 0x11))
2528 snd_hda_sequence_write(codec, ad1988_laptop_hp_on); 2540 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2529 else 2541 else
2530 snd_hda_sequence_write(codec, ad1988_laptop_hp_off); 2542 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
@@ -2569,6 +2581,8 @@ static int add_control(struct ad198x_spec *spec, int type, const char *name,
2569 knew->name = kstrdup(name, GFP_KERNEL); 2581 knew->name = kstrdup(name, GFP_KERNEL);
2570 if (! knew->name) 2582 if (! knew->name)
2571 return -ENOMEM; 2583 return -ENOMEM;
2584 if (get_amp_nid_(val))
2585 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
2572 knew->private_value = val; 2586 knew->private_value = val;
2573 return 0; 2587 return 0;
2574} 2588}
@@ -3059,6 +3073,7 @@ static int patch_ad1988(struct hda_codec *codec)
3059 spec->input_mux = &ad1988_laptop_capture_source; 3073 spec->input_mux = &ad1988_laptop_capture_source;
3060 spec->num_mixers = 1; 3074 spec->num_mixers = 1;
3061 spec->mixers[0] = ad1988_laptop_mixers; 3075 spec->mixers[0] = ad1988_laptop_mixers;
3076 spec->inv_eapd = 1; /* inverted EAPD */
3062 spec->num_init_verbs = 1; 3077 spec->num_init_verbs = 1;
3063 spec->init_verbs[0] = ad1988_laptop_init_verbs; 3078 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3064 if (board_config == AD1988_LAPTOP_DIG) 3079 if (board_config == AD1988_LAPTOP_DIG)
@@ -3768,8 +3783,7 @@ static void ad1884a_hp_automute(struct hda_codec *codec)
3768{ 3783{
3769 unsigned int present; 3784 unsigned int present;
3770 3785
3771 present = snd_hda_codec_read(codec, 0x11, 0, 3786 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, 3787 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3774 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 3788 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3775 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE, 3789 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
@@ -3781,8 +3795,7 @@ static void ad1884a_hp_automic(struct hda_codec *codec)
3781{ 3795{
3782 unsigned int present; 3796 unsigned int present;
3783 3797
3784 present = snd_hda_codec_read(codec, 0x14, 0, 3798 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, 3799 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3787 present ? 0 : 1); 3800 present ? 0 : 1);
3788} 3801}
@@ -3817,13 +3830,9 @@ static void ad1884a_laptop_automute(struct hda_codec *codec)
3817{ 3830{
3818 unsigned int present; 3831 unsigned int present;
3819 3832
3820 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0); 3833 present = snd_hda_jack_detect(codec, 0x11);
3821 present &= AC_PINSENSE_PRESENCE; 3834 if (!present)
3822 if (!present) { 3835 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, 3836 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3828 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 3837 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3829 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE, 3838 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
@@ -3835,11 +3844,9 @@ static void ad1884a_laptop_automic(struct hda_codec *codec)
3835{ 3844{
3836 unsigned int idx; 3845 unsigned int idx;
3837 3846
3838 if (snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0) & 3847 if (snd_hda_jack_detect(codec, 0x14))
3839 AC_PINSENSE_PRESENCE)
3840 idx = 0; 3848 idx = 0;
3841 else if (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 3849 else if (snd_hda_jack_detect(codec, 0x1c))
3842 AC_PINSENSE_PRESENCE)
3843 idx = 4; 3850 idx = 4;
3844 else 3851 else
3845 idx = 1; 3852 idx = 1;
@@ -4008,8 +4015,7 @@ static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4008{ 4015{
4009 unsigned int present; 4016 unsigned int present;
4010 4017
4011 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) 4018 present = snd_hda_jack_detect(codec, 0x11);
4012 & AC_PINSENSE_PRESENCE;
4013 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0, 4019 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4014 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 4020 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4015} 4021}
@@ -4117,14 +4123,12 @@ static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4117/* switch to external mic if plugged */ 4123/* switch to external mic if plugged */
4118static void ad1984a_touchsmart_automic(struct hda_codec *codec) 4124static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4119{ 4125{
4120 if (snd_hda_codec_read(codec, 0x1c, 0, 4126 if (snd_hda_jack_detect(codec, 0x1c))
4121 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000) {
4122 snd_hda_codec_write(codec, 0x0c, 0, 4127 snd_hda_codec_write(codec, 0x0c, 0,
4123 AC_VERB_SET_CONNECT_SEL, 0x4); 4128 AC_VERB_SET_CONNECT_SEL, 0x4);
4124 } else { 4129 else
4125 snd_hda_codec_write(codec, 0x0c, 0, 4130 snd_hda_codec_write(codec, 0x0c, 0,
4126 AC_VERB_SET_CONNECT_SEL, 0x5); 4131 AC_VERB_SET_CONNECT_SEL, 0x5);
4127 }
4128} 4132}
4129 4133
4130 4134
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..fe0423c39598 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,7 @@ 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 return snd_hda_ctl_add(codec, get_amp_nid_(pval), *kctlp);
504} 505}
505 506
506static int add_volume(struct hda_codec *codec, const char *name, 507static int add_volume(struct hda_codec *codec, const char *name,
@@ -513,7 +514,7 @@ static int add_volume(struct hda_codec *codec, const char *name,
513 knew.private_value = pval; 514 knew.private_value = pval;
514 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]); 515 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
515 *kctlp = snd_ctl_new1(&knew, codec); 516 *kctlp = snd_ctl_new1(&knew, codec);
516 return snd_hda_ctl_add(codec, *kctlp); 517 return snd_hda_ctl_add(codec, get_amp_nid_(pval), *kctlp);
517} 518}
518 519
519static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) 520static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
@@ -536,14 +537,14 @@ static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
536 537
537 spec->vmaster_sw = 538 spec->vmaster_sw =
538 snd_ctl_make_virtual_master("Master Playback Switch", NULL); 539 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
539 err = snd_hda_ctl_add(codec, spec->vmaster_sw); 540 err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
540 if (err < 0) 541 if (err < 0)
541 return err; 542 return err;
542 543
543 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv); 544 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
544 spec->vmaster_vol = 545 spec->vmaster_vol =
545 snd_ctl_make_virtual_master("Master Playback Volume", tlv); 546 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
546 err = snd_hda_ctl_add(codec, spec->vmaster_vol); 547 err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
547 if (err < 0) 548 if (err < 0)
548 return err; 549 return err;
549 return 0; 550 return 0;
@@ -756,13 +757,13 @@ static int build_input(struct hda_codec *codec)
756 if (!kctl) 757 if (!kctl)
757 return -ENOMEM; 758 return -ENOMEM;
758 kctl->private_value = (long)spec->capture_bind[i]; 759 kctl->private_value = (long)spec->capture_bind[i];
759 err = snd_hda_ctl_add(codec, kctl); 760 err = snd_hda_ctl_add(codec, 0, kctl);
760 if (err < 0) 761 if (err < 0)
761 return err; 762 return err;
762 } 763 }
763 764
764 if (spec->num_inputs > 1 && !spec->mic_detect) { 765 if (spec->num_inputs > 1 && !spec->mic_detect) {
765 err = snd_hda_ctl_add(codec, 766 err = snd_hda_ctl_add(codec, 0,
766 snd_ctl_new1(&cs_capture_source, codec)); 767 snd_ctl_new1(&cs_capture_source, codec));
767 if (err < 0) 768 if (err < 0)
768 return err; 769 return err;
@@ -807,7 +808,7 @@ static void cs_automute(struct hda_codec *codec)
807{ 808{
808 struct cs_spec *spec = codec->spec; 809 struct cs_spec *spec = codec->spec;
809 struct auto_pin_cfg *cfg = &spec->autocfg; 810 struct auto_pin_cfg *cfg = &spec->autocfg;
810 unsigned int caps, present, hp_present; 811 unsigned int caps, hp_present;
811 hda_nid_t nid; 812 hda_nid_t nid;
812 int i; 813 int i;
813 814
@@ -817,12 +818,7 @@ static void cs_automute(struct hda_codec *codec)
817 caps = snd_hda_query_pin_caps(codec, nid); 818 caps = snd_hda_query_pin_caps(codec, nid);
818 if (!(caps & AC_PINCAP_PRES_DETECT)) 819 if (!(caps & AC_PINCAP_PRES_DETECT))
819 continue; 820 continue;
820 if (caps & AC_PINCAP_TRIG_REQ) 821 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) 822 if (hp_present)
827 break; 823 break;
828 } 824 }
@@ -832,7 +828,8 @@ static void cs_automute(struct hda_codec *codec)
832 AC_VERB_SET_PIN_WIDGET_CONTROL, 828 AC_VERB_SET_PIN_WIDGET_CONTROL,
833 hp_present ? 0 : PIN_OUT); 829 hp_present ? 0 : PIN_OUT);
834 } 830 }
835 if (spec->board_config == CS420X_MBP55) { 831 if (spec->board_config == CS420X_MBP55 ||
832 spec->board_config == CS420X_IMAC27) {
836 unsigned int gpio = hp_present ? 0x02 : 0x08; 833 unsigned int gpio = hp_present ? 0x02 : 0x08;
837 snd_hda_codec_write(codec, 0x01, 0, 834 snd_hda_codec_write(codec, 0x01, 0,
838 AC_VERB_SET_GPIO_DATA, gpio); 835 AC_VERB_SET_GPIO_DATA, gpio);
@@ -844,15 +841,11 @@ static void cs_automic(struct hda_codec *codec)
844 struct cs_spec *spec = codec->spec; 841 struct cs_spec *spec = codec->spec;
845 struct auto_pin_cfg *cfg = &spec->autocfg; 842 struct auto_pin_cfg *cfg = &spec->autocfg;
846 hda_nid_t nid; 843 hda_nid_t nid;
847 unsigned int caps, present; 844 unsigned int present;
848 845
849 nid = cfg->input_pins[spec->automic_idx]; 846 nid = cfg->input_pins[spec->automic_idx];
850 caps = snd_hda_query_pin_caps(codec, nid); 847 present = snd_hda_jack_detect(codec, nid);
851 if (caps & AC_PINCAP_TRIG_REQ) 848 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); 849 change_cur_input(codec, spec->automic_idx, 0);
857 else { 850 else {
858 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ? 851 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
@@ -947,7 +940,7 @@ static void init_input(struct hda_codec *codec)
947 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */ 940 coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */
948 if (is_active_pin(codec, CS_DMIC1_PIN_NID)) 941 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
949 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0 942 coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0
950 * No effect if SPDIF_OUT2 is slected in 943 * No effect if SPDIF_OUT2 is selected in
951 * IDX_SPDIF_CTL. 944 * IDX_SPDIF_CTL.
952 */ 945 */
953 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef); 946 cs_vendor_coef_set(codec, IDX_ADC_CFG, coef);
@@ -1078,12 +1071,14 @@ static int cs_parse_auto_config(struct hda_codec *codec)
1078 1071
1079static const char *cs420x_models[CS420X_MODELS] = { 1072static const char *cs420x_models[CS420X_MODELS] = {
1080 [CS420X_MBP55] = "mbp55", 1073 [CS420X_MBP55] = "mbp55",
1074 [CS420X_IMAC27] = "imac27",
1081 [CS420X_AUTO] = "auto", 1075 [CS420X_AUTO] = "auto",
1082}; 1076};
1083 1077
1084 1078
1085static struct snd_pci_quirk cs420x_cfg_tbl[] = { 1079static struct snd_pci_quirk cs420x_cfg_tbl[] = {
1086 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55), 1080 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
1081 SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),
1087 {} /* terminator */ 1082 {} /* terminator */
1088}; 1083};
1089 1084
@@ -1106,8 +1101,23 @@ static struct cs_pincfg mbp55_pincfgs[] = {
1106 {} /* terminator */ 1101 {} /* terminator */
1107}; 1102};
1108 1103
1104static struct cs_pincfg imac27_pincfgs[] = {
1105 { 0x09, 0x012b4050 },
1106 { 0x0a, 0x90100140 },
1107 { 0x0b, 0x90100142 },
1108 { 0x0c, 0x018b3020 },
1109 { 0x0d, 0x90a00110 },
1110 { 0x0e, 0x400000f0 },
1111 { 0x0f, 0x01cbe030 },
1112 { 0x10, 0x014be060 },
1113 { 0x12, 0x01ab9070 },
1114 { 0x15, 0x400000f0 },
1115 {} /* terminator */
1116};
1117
1109static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = { 1118static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = {
1110 [CS420X_MBP55] = mbp55_pincfgs, 1119 [CS420X_MBP55] = mbp55_pincfgs,
1120 [CS420X_IMAC27] = imac27_pincfgs,
1111}; 1121};
1112 1122
1113static void fix_pincfg(struct hda_codec *codec, int model) 1123static void fix_pincfg(struct hda_codec *codec, int model)
@@ -1137,6 +1147,7 @@ static int patch_cs420x(struct hda_codec *codec)
1137 fix_pincfg(codec, spec->board_config); 1147 fix_pincfg(codec, spec->board_config);
1138 1148
1139 switch (spec->board_config) { 1149 switch (spec->board_config) {
1150 case CS420X_IMAC27:
1140 case CS420X_MBP55: 1151 case CS420X_MBP55:
1141 /* GPIO1 = headphones */ 1152 /* GPIO1 = headphones */
1142 /* GPIO3 = speakers */ 1153 /* GPIO3 = speakers */
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 780e1a72114a..a45c1169762b 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
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 3fbbc8c01e70..c578c28f368e 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
@@ -110,6 +111,8 @@ struct conexant_spec {
110 111
111 unsigned int dell_automute; 112 unsigned int dell_automute;
112 unsigned int port_d_mode; 113 unsigned int port_d_mode;
114 unsigned char ext_mic_bias;
115 unsigned int dell_vostro;
113}; 116};
114 117
115static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 118static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
@@ -396,9 +399,7 @@ static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
396 for (i = 0; i < spec->jacks.used; i++) { 399 for (i = 0; i < spec->jacks.used; i++) {
397 if (jacks->nid == nid) { 400 if (jacks->nid == nid) {
398 unsigned int present; 401 unsigned int present;
399 present = snd_hda_codec_read(codec, nid, 0, 402 present = snd_hda_jack_detect(codec, nid);
400 AC_VERB_GET_PIN_SENSE, 0) &
401 AC_PINSENSE_PRESENCE;
402 403
403 present = (present) ? jacks->type : 0 ; 404 present = (present) ? jacks->type : 0 ;
404 405
@@ -477,6 +478,7 @@ static void conexant_free(struct hda_codec *codec)
477 snd_array_free(&spec->jacks); 478 snd_array_free(&spec->jacks);
478 } 479 }
479#endif 480#endif
481 snd_hda_detach_beep_device(codec);
480 kfree(codec->spec); 482 kfree(codec->spec);
481} 483}
482 484
@@ -749,8 +751,7 @@ static void cxt5045_hp_automic(struct hda_codec *codec)
749 }; 751 };
750 unsigned int present; 752 unsigned int present;
751 753
752 present = snd_hda_codec_read(codec, 0x12, 0, 754 present = snd_hda_jack_detect(codec, 0x12);
753 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
754 if (present) 755 if (present)
755 snd_hda_sequence_write(codec, mic_jack_on); 756 snd_hda_sequence_write(codec, mic_jack_on);
756 else 757 else
@@ -764,8 +765,7 @@ static void cxt5045_hp_automute(struct hda_codec *codec)
764 struct conexant_spec *spec = codec->spec; 765 struct conexant_spec *spec = codec->spec;
765 unsigned int bits; 766 unsigned int bits;
766 767
767 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, 768 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
768 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
769 769
770 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 770 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
771 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 771 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
@@ -1174,9 +1174,10 @@ static int patch_cxt5045(struct hda_codec *codec)
1174 1174
1175 switch (codec->subsystem_id >> 16) { 1175 switch (codec->subsystem_id >> 16) {
1176 case 0x103c: 1176 case 0x103c:
1177 /* HP laptop has a really bad sound over 0dB on NID 0x17. 1177 case 0x1734:
1178 * Fix max PCM level to 0 dB 1178 /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1179 * (originall it has 0x2b steps with 0dB offset 0x14) 1179 * on NID 0x17. Fix max PCM level to 0 dB
1180 * (originally it has 0x2b steps with 0dB offset 0x14)
1180 */ 1181 */
1181 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 1182 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1182 (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 1183 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
@@ -1242,8 +1243,7 @@ static void cxt5047_hp_automute(struct hda_codec *codec)
1242 struct conexant_spec *spec = codec->spec; 1243 struct conexant_spec *spec = codec->spec;
1243 unsigned int bits; 1244 unsigned int bits;
1244 1245
1245 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1246 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1246 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1247 1247
1248 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 1248 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1249 /* See the note in cxt5047_hp_master_sw_put */ 1249 /* See the note in cxt5047_hp_master_sw_put */
@@ -1266,8 +1266,7 @@ static void cxt5047_hp_automic(struct hda_codec *codec)
1266 }; 1266 };
1267 unsigned int present; 1267 unsigned int present;
1268 1268
1269 present = snd_hda_codec_read(codec, 0x15, 0, 1269 present = snd_hda_jack_detect(codec, 0x15);
1270 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1271 if (present) 1270 if (present)
1272 snd_hda_sequence_write(codec, mic_jack_on); 1271 snd_hda_sequence_write(codec, mic_jack_on);
1273 else 1272 else
@@ -1414,16 +1413,7 @@ static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1414 .get = conexant_mux_enum_get, 1413 .get = conexant_mux_enum_get,
1415 .put = conexant_mux_enum_put, 1414 .put = conexant_mux_enum_put,
1416 }, 1415 },
1417 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1416 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1419 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1420 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1421 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1422 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1423 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1424 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1426 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1427 1417
1428 { } /* end */ 1418 { } /* end */
1429}; 1419};
@@ -1620,9 +1610,7 @@ static void cxt5051_portb_automic(struct hda_codec *codec)
1620 1610
1621 if (spec->no_auto_mic) 1611 if (spec->no_auto_mic)
1622 return; 1612 return;
1623 present = snd_hda_codec_read(codec, 0x17, 0, 1613 present = snd_hda_jack_detect(codec, 0x17);
1624 AC_VERB_GET_PIN_SENSE, 0) &
1625 AC_PINSENSE_PRESENCE;
1626 snd_hda_codec_write(codec, 0x14, 0, 1614 snd_hda_codec_write(codec, 0x14, 0,
1627 AC_VERB_SET_CONNECT_SEL, 1615 AC_VERB_SET_CONNECT_SEL,
1628 present ? 0x01 : 0x00); 1616 present ? 0x01 : 0x00);
@@ -1637,9 +1625,7 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1637 1625
1638 if (spec->no_auto_mic) 1626 if (spec->no_auto_mic)
1639 return; 1627 return;
1640 present = snd_hda_codec_read(codec, 0x18, 0, 1628 present = snd_hda_jack_detect(codec, 0x18);
1641 AC_VERB_GET_PIN_SENSE, 0) &
1642 AC_PINSENSE_PRESENCE;
1643 if (present) 1629 if (present)
1644 spec->cur_adc_idx = 1; 1630 spec->cur_adc_idx = 1;
1645 else 1631 else
@@ -1660,9 +1646,7 @@ static void cxt5051_hp_automute(struct hda_codec *codec)
1660{ 1646{
1661 struct conexant_spec *spec = codec->spec; 1647 struct conexant_spec *spec = codec->spec;
1662 1648
1663 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, 1649 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1664 AC_VERB_GET_PIN_SENSE, 0) &
1665 AC_PINSENSE_PRESENCE;
1666 cxt5051_update_speaker(codec); 1650 cxt5051_update_speaker(codec);
1667} 1651}
1668 1652
@@ -1927,6 +1911,11 @@ static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1927static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 1911static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1928#define CXT5066_SPDIF_OUT 0x21 1912#define CXT5066_SPDIF_OUT 0x21
1929 1913
1914/* OLPC's microphone port is DC coupled for use with external sensors,
1915 * therefore we use a 50% mic bias in order to center the input signal with
1916 * the DC input range of the codec. */
1917#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1918
1930static struct hda_channel_mode cxt5066_modes[1] = { 1919static struct hda_channel_mode cxt5066_modes[1] = {
1931 { 2, NULL }, 1920 { 2, NULL },
1932}; 1921};
@@ -1980,9 +1969,10 @@ static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1980/* toggle input of built-in and mic jack appropriately */ 1969/* toggle input of built-in and mic jack appropriately */
1981static void cxt5066_automic(struct hda_codec *codec) 1970static void cxt5066_automic(struct hda_codec *codec)
1982{ 1971{
1983 static struct hda_verb ext_mic_present[] = { 1972 struct conexant_spec *spec = codec->spec;
1973 struct hda_verb ext_mic_present[] = {
1984 /* enable external mic, port B */ 1974 /* enable external mic, port B */
1985 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1975 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
1986 1976
1987 /* switch to external mic input */ 1977 /* switch to external mic input */
1988 {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 1978 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
@@ -2004,8 +1994,47 @@ static void cxt5066_automic(struct hda_codec *codec)
2004 }; 1994 };
2005 unsigned int present; 1995 unsigned int present;
2006 1996
2007 present = snd_hda_codec_read(codec, 0x1a, 0, 1997 present = snd_hda_jack_detect(codec, 0x1a);
2008 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1998 if (present) {
1999 snd_printdd("CXT5066: external microphone detected\n");
2000 snd_hda_sequence_write(codec, ext_mic_present);
2001 } else {
2002 snd_printdd("CXT5066: external microphone absent\n");
2003 snd_hda_sequence_write(codec, ext_mic_absent);
2004 }
2005}
2006
2007/* toggle input of built-in digital mic and mic jack appropriately */
2008static void cxt5066_vostro_automic(struct hda_codec *codec)
2009{
2010 struct conexant_spec *spec = codec->spec;
2011 unsigned int present;
2012
2013 struct hda_verb ext_mic_present[] = {
2014 /* enable external mic, port B */
2015 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2016
2017 /* switch to external mic input */
2018 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2019 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2020
2021 /* disable internal digital mic */
2022 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2023 {}
2024 };
2025 static struct hda_verb ext_mic_absent[] = {
2026 /* enable internal mic, port C */
2027 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2028
2029 /* switch to internal mic input */
2030 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2031
2032 /* disable external mic, port B */
2033 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2034 {}
2035 };
2036
2037 present = snd_hda_jack_detect(codec, 0x1a);
2009 if (present) { 2038 if (present) {
2010 snd_printdd("CXT5066: external microphone detected\n"); 2039 snd_printdd("CXT5066: external microphone detected\n");
2011 snd_hda_sequence_write(codec, ext_mic_present); 2040 snd_hda_sequence_write(codec, ext_mic_present);
@@ -2022,12 +2051,10 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
2022 unsigned int portA, portD; 2051 unsigned int portA, portD;
2023 2052
2024 /* Port A */ 2053 /* Port A */
2025 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0) 2054 portA = snd_hda_jack_detect(codec, 0x19);
2026 & AC_PINSENSE_PRESENCE;
2027 2055
2028 /* Port D */ 2056 /* Port D */
2029 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) 2057 portD = snd_hda_jack_detect(codec, 0x1c);
2030 & AC_PINSENSE_PRESENCE) << 1;
2031 2058
2032 spec->hp_present = !!(portA | portD); 2059 spec->hp_present = !!(portA | portD);
2033 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2060 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
@@ -2049,6 +2076,20 @@ static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2049 } 2076 }
2050} 2077}
2051 2078
2079/* unsolicited event for jack sensing */
2080static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2081{
2082 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2083 switch (res >> 26) {
2084 case CONEXANT_HP_EVENT:
2085 cxt5066_hp_automute(codec);
2086 break;
2087 case CONEXANT_MIC_EVENT:
2088 cxt5066_vostro_automic(codec);
2089 break;
2090 }
2091}
2092
2052static const struct hda_input_mux cxt5066_analog_mic_boost = { 2093static const struct hda_input_mux cxt5066_analog_mic_boost = {
2053 .num_items = 5, 2094 .num_items = 5,
2054 .items = { 2095 .items = {
@@ -2071,9 +2112,12 @@ static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2071{ 2112{
2072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2113 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2073 int val; 2114 int val;
2115 hda_nid_t nid = kcontrol->private_value & 0xff;
2116 int inout = (kcontrol->private_value & 0x100) ?
2117 AC_AMP_GET_INPUT : AC_AMP_GET_OUTPUT;
2074 2118
2075 val = snd_hda_codec_read(codec, 0x17, 0, 2119 val = snd_hda_codec_read(codec, nid, 0,
2076 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT); 2120 AC_VERB_GET_AMP_GAIN_MUTE, inout);
2077 2121
2078 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN; 2122 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2079 return 0; 2123 return 0;
@@ -2085,6 +2129,9 @@ static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2085 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2129 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2086 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2130 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2087 unsigned int idx; 2131 unsigned int idx;
2132 hda_nid_t nid = kcontrol->private_value & 0xff;
2133 int inout = (kcontrol->private_value & 0x100) ?
2134 AC_AMP_SET_INPUT : AC_AMP_SET_OUTPUT;
2088 2135
2089 if (!imux->num_items) 2136 if (!imux->num_items)
2090 return 0; 2137 return 0;
@@ -2092,9 +2139,9 @@ static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2092 if (idx >= imux->num_items) 2139 if (idx >= imux->num_items)
2093 idx = imux->num_items - 1; 2140 idx = imux->num_items - 1;
2094 2141
2095 snd_hda_codec_write_cache(codec, 0x17, 0, 2142 snd_hda_codec_write_cache(codec, nid, 0,
2096 AC_VERB_SET_AMP_GAIN_MUTE, 2143 AC_VERB_SET_AMP_GAIN_MUTE,
2097 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2144 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | inout |
2098 imux->items[idx].index); 2145 imux->items[idx].index);
2099 2146
2100 return 1; 2147 return 1;
@@ -2163,10 +2210,11 @@ static struct snd_kcontrol_new cxt5066_mixers[] = {
2163 2210
2164 { 2211 {
2165 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2212 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2166 .name = "Analog Mic Boost Capture Enum", 2213 .name = "Ext Mic Boost Capture Enum",
2167 .info = cxt5066_mic_boost_mux_enum_info, 2214 .info = cxt5066_mic_boost_mux_enum_info,
2168 .get = cxt5066_mic_boost_mux_enum_get, 2215 .get = cxt5066_mic_boost_mux_enum_get,
2169 .put = cxt5066_mic_boost_mux_enum_put, 2216 .put = cxt5066_mic_boost_mux_enum_put,
2217 .private_value = 0x17,
2170 }, 2218 },
2171 2219
2172 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 2220 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
@@ -2174,6 +2222,19 @@ static struct snd_kcontrol_new cxt5066_mixers[] = {
2174 {} 2222 {}
2175}; 2223};
2176 2224
2225static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2226 {
2227 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2228 .name = "Int Mic Boost Capture Enum",
2229 .info = cxt5066_mic_boost_mux_enum_info,
2230 .get = cxt5066_mic_boost_mux_enum_get,
2231 .put = cxt5066_mic_boost_mux_enum_put,
2232 .private_value = 0x23 | 0x100,
2233 },
2234 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2235 {}
2236};
2237
2177static struct hda_verb cxt5066_init_verbs[] = { 2238static struct hda_verb cxt5066_init_verbs[] = {
2178 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2239 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2179 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2240 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
@@ -2235,7 +2296,7 @@ static struct hda_verb cxt5066_init_verbs_olpc[] = {
2235 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2296 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2236 2297
2237 /* Port B: external microphone */ 2298 /* Port B: external microphone */
2238 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2299 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
2239 2300
2240 /* Port C: internal microphone */ 2301 /* Port C: internal microphone */
2241 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2302 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
@@ -2290,6 +2351,67 @@ static struct hda_verb cxt5066_init_verbs_olpc[] = {
2290 { } /* end */ 2351 { } /* end */
2291}; 2352};
2292 2353
2354static struct hda_verb cxt5066_init_verbs_vostro[] = {
2355 /* Port A: headphones */
2356 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2357 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2358
2359 /* Port B: external microphone */
2360 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2361
2362 /* Port C: unused */
2363 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2364
2365 /* Port D: unused */
2366 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2367
2368 /* Port E: unused, but has primary EAPD */
2369 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2370 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2371
2372 /* Port F: unused */
2373 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2374
2375 /* Port G: internal speakers */
2376 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2377 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2378
2379 /* DAC1 */
2380 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2381
2382 /* DAC2: unused */
2383 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2384
2385 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2386 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2387 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2388 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2389 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2390 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2391 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2392 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2393 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2394 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2395 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2396 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2397
2398 /* Digital microphone port */
2399 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2400
2401 /* Audio input selectors */
2402 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2403 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2404
2405 /* Disable SPDIF */
2406 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2407 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2408
2409 /* enable unsolicited events for Port A and B */
2410 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2411 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2412 { } /* end */
2413};
2414
2293static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 2415static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2294 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2416 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2295 { } /* end */ 2417 { } /* end */
@@ -2298,11 +2420,16 @@ static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2298/* initialize jack-sensing, too */ 2420/* initialize jack-sensing, too */
2299static int cxt5066_init(struct hda_codec *codec) 2421static int cxt5066_init(struct hda_codec *codec)
2300{ 2422{
2423 struct conexant_spec *spec = codec->spec;
2424
2301 snd_printdd("CXT5066: init\n"); 2425 snd_printdd("CXT5066: init\n");
2302 conexant_init(codec); 2426 conexant_init(codec);
2303 if (codec->patch_ops.unsol_event) { 2427 if (codec->patch_ops.unsol_event) {
2304 cxt5066_hp_automute(codec); 2428 cxt5066_hp_automute(codec);
2305 cxt5066_automic(codec); 2429 if (spec->dell_vostro)
2430 cxt5066_vostro_automic(codec);
2431 else
2432 cxt5066_automic(codec);
2306 } 2433 }
2307 return 0; 2434 return 0;
2308} 2435}
@@ -2311,6 +2438,7 @@ enum {
2311 CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 2438 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2312 CXT5066_DELL_LAPTOP, /* Dell Laptop */ 2439 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2313 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 2440 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2441 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
2314 CXT5066_MODELS 2442 CXT5066_MODELS
2315}; 2443};
2316 2444
@@ -2318,6 +2446,7 @@ static const char *cxt5066_models[CXT5066_MODELS] = {
2318 [CXT5066_LAPTOP] = "laptop", 2446 [CXT5066_LAPTOP] = "laptop",
2319 [CXT5066_DELL_LAPTOP] = "dell-laptop", 2447 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2320 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 2448 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2449 [CXT5066_DELL_VOSTO] = "dell-vostro"
2321}; 2450};
2322 2451
2323static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 2452static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
@@ -2325,6 +2454,8 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2325 CXT5066_LAPTOP), 2454 CXT5066_LAPTOP),
2326 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 2455 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2327 CXT5066_DELL_LAPTOP), 2456 CXT5066_DELL_LAPTOP),
2457 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2458 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
2328 {} 2459 {}
2329}; 2460};
2330 2461
@@ -2352,6 +2483,7 @@ static int patch_cxt5066(struct hda_codec *codec)
2352 spec->input_mux = &cxt5066_capture_source; 2483 spec->input_mux = &cxt5066_capture_source;
2353 2484
2354 spec->port_d_mode = PIN_HP; 2485 spec->port_d_mode = PIN_HP;
2486 spec->ext_mic_bias = PIN_VREF80;
2355 2487
2356 spec->num_init_verbs = 1; 2488 spec->num_init_verbs = 1;
2357 spec->init_verbs[0] = cxt5066_init_verbs; 2489 spec->init_verbs[0] = cxt5066_init_verbs;
@@ -2383,6 +2515,23 @@ static int patch_cxt5066(struct hda_codec *codec)
2383 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 2515 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2384 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2516 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2385 spec->port_d_mode = 0; 2517 spec->port_d_mode = 0;
2518 spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
2519
2520 /* no S/PDIF out */
2521 spec->multiout.dig_out_nid = 0;
2522
2523 /* input source automatically selected */
2524 spec->input_mux = NULL;
2525 break;
2526 case CXT5066_DELL_VOSTO:
2527 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2528 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2529 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2530 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2531 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
2532 spec->port_d_mode = 0;
2533 spec->dell_vostro = 1;
2534 snd_hda_attach_beep_device(codec, 0x13);
2386 2535
2387 /* no S/PDIF out */ 2536 /* no S/PDIF out */
2388 spec->multiout.dig_out_nid = 0; 2537 spec->multiout.dig_out_nid = 0;
@@ -2407,6 +2556,8 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
2407 .patch = patch_cxt5051 }, 2556 .patch = patch_cxt5051 },
2408 { .id = 0x14f15066, .name = "CX20582 (Pebble)", 2557 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2409 .patch = patch_cxt5066 }, 2558 .patch = patch_cxt5066 },
2559 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2560 .patch = patch_cxt5066 },
2410 {} /* terminator */ 2561 {} /* terminator */
2411}; 2562};
2412 2563
@@ -2414,6 +2565,7 @@ MODULE_ALIAS("snd-hda-codec-id:14f15045");
2414MODULE_ALIAS("snd-hda-codec-id:14f15047"); 2565MODULE_ALIAS("snd-hda-codec-id:14f15047");
2415MODULE_ALIAS("snd-hda-codec-id:14f15051"); 2566MODULE_ALIAS("snd-hda-codec-id:14f15051");
2416MODULE_ALIAS("snd-hda-codec-id:14f15066"); 2567MODULE_ALIAS("snd-hda-codec-id:14f15066");
2568MODULE_ALIAS("snd-hda-codec-id:14f15067");
2417 2569
2418MODULE_LICENSE("GPL"); 2570MODULE_LICENSE("GPL");
2419MODULE_DESCRIPTION("Conexant HD-audio codec"); 2571MODULE_DESCRIPTION("Conexant HD-audio codec");
diff --git a/sound/pci/hda/patch_intelhdmi.c b/sound/pci/hda/patch_intelhdmi.c
index 01a18ed475ac..918f40378d52 100644
--- a/sound/pci/hda/patch_intelhdmi.c
+++ b/sound/pci/hda/patch_intelhdmi.c
@@ -33,15 +33,41 @@
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 */ 36/*
37static hda_nid_t pin_nid; /* HDMI output pin */ 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).
40 *
41 * The HDA correspondence of pipes/ports are converter/pin nodes.
42 */
43#define INTEL_HDMI_CVTS 2
44#define INTEL_HDMI_PINS 3
38 45
39#define INTEL_HDMI_EVENT_TAG 0x08 46static char *intel_hdmi_pcm_names[INTEL_HDMI_CVTS] = {
47 "INTEL HDMI 0",
48 "INTEL HDMI 1",
49};
40 50
41struct intel_hdmi_spec { 51struct intel_hdmi_spec {
42 struct hda_multi_out multiout; 52 int num_cvts;
43 struct hda_pcm pcm_rec; 53 int num_pins;
44 struct hdmi_eld sink_eld; 54 hda_nid_t cvt[INTEL_HDMI_CVTS+1]; /* audio sources */
55 hda_nid_t pin[INTEL_HDMI_PINS+1]; /* audio sinks */
56
57 /*
58 * source connection for each pin
59 */
60 hda_nid_t pin_cvt[INTEL_HDMI_PINS+1];
61
62 /*
63 * HDMI sink attached to each pin
64 */
65 struct hdmi_eld sink_eld[INTEL_HDMI_PINS];
66
67 /*
68 * export one pcm per pipe
69 */
70 struct hda_pcm pcm_rec[INTEL_HDMI_CVTS];
45}; 71};
46 72
47struct hdmi_audio_infoframe { 73struct hdmi_audio_infoframe {
@@ -120,38 +146,78 @@ struct cea_channel_speaker_allocation {
120}; 146};
121 147
122/* 148/*
149 * ALSA sequence is:
150 *
151 * surround40 surround41 surround50 surround51 surround71
152 * ch0 front left = = = =
153 * ch1 front right = = = =
154 * ch2 rear left = = = =
155 * ch3 rear right = = = =
156 * ch4 LFE center center center
157 * ch5 LFE LFE
158 * ch6 side left
159 * ch7 side right
160 *
161 * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
162 */
163static int hdmi_channel_mapping[0x32][8] = {
164 /* stereo */
165 [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
166 /* 2.1 */
167 [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
168 /* Dolby Surround */
169 [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
170 /* surround40 */
171 [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
172 /* 4ch */
173 [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
174 /* surround41 */
175 [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 },
176 /* surround50 */
177 [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
178 /* surround51 */
179 [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
180 /* 7.1 */
181 [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
182};
183
184/*
123 * This is an ordered list! 185 * This is an ordered list!
124 * 186 *
125 * The preceding ones have better chances to be selected by 187 * The preceding ones have better chances to be selected by
126 * hdmi_setup_channel_allocation(). 188 * hdmi_setup_channel_allocation().
127 */ 189 */
128static struct cea_channel_speaker_allocation channel_allocations[] = { 190static struct cea_channel_speaker_allocation channel_allocations[] = {
129/* channel: 8 7 6 5 4 3 2 1 */ 191/* channel: 7 6 5 4 3 2 1 0 */
130{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, 192{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
131 /* 2.1 */ 193 /* 2.1 */
132{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, 194{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
133 /* Dolby Surround */ 195 /* Dolby Surround */
134{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, 196{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
197 /* surround40 */
198{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
199 /* surround41 */
200{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
201 /* surround50 */
202{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
203 /* surround51 */
204{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
205 /* 6.1 */
206{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
207 /* surround71 */
208{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
209
135{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, 210{ .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 } }, 211{ .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 } }, 212{ .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 } }, 213{ .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 } }, 214{ .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 } }, 215{ .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 } }, 216{ .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 } }, 217{ .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 } }, 218{ .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 } }, 219{ .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 } }, 220{ .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 } }, 221{ .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 } }, 222{ .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 } }, 223{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
@@ -185,39 +251,195 @@ static struct cea_channel_speaker_allocation channel_allocations[] = {
185}; 251};
186 252
187/* 253/*
254 * HDA/HDMI auto parsing
255 */
256
257static int hda_node_index(hda_nid_t *nids, hda_nid_t nid)
258{
259 int i;
260
261 for (i = 0; nids[i]; i++)
262 if (nids[i] == nid)
263 return i;
264
265 snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid);
266 return -EINVAL;
267}
268
269static int intel_hdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid)
270{
271 struct intel_hdmi_spec *spec = codec->spec;
272 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
273 int conn_len, curr;
274 int index;
275
276 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
277 snd_printk(KERN_WARNING
278 "HDMI: pin %d wcaps %#x "
279 "does not support connection list\n",
280 pin_nid, get_wcaps(codec, pin_nid));
281 return -EINVAL;
282 }
283
284 conn_len = snd_hda_get_connections(codec, pin_nid, conn_list,
285 HDA_MAX_CONNECTIONS);
286 if (conn_len > 1)
287 curr = snd_hda_codec_read(codec, pin_nid, 0,
288 AC_VERB_GET_CONNECT_SEL, 0);
289 else
290 curr = 0;
291
292 index = hda_node_index(spec->pin, pin_nid);
293 if (index < 0)
294 return -EINVAL;
295
296 spec->pin_cvt[index] = conn_list[curr];
297
298 return 0;
299}
300
301static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid,
302 struct hdmi_eld *eld)
303{
304 if (!snd_hdmi_get_eld(eld, codec, pin_nid))
305 snd_hdmi_show_eld(eld);
306}
307
308static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
309 struct hdmi_eld *eld)
310{
311 int present = snd_hda_pin_sense(codec, pin_nid);
312
313 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
314 eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
315
316 if (present & AC_PINSENSE_ELDV)
317 hdmi_get_show_eld(codec, pin_nid, eld);
318}
319
320static int intel_hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
321{
322 struct intel_hdmi_spec *spec = codec->spec;
323
324 if (spec->num_pins >= INTEL_HDMI_PINS) {
325 snd_printk(KERN_WARNING
326 "HDMI: no space for pin %d \n", pin_nid);
327 return -EINVAL;
328 }
329
330 hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]);
331
332 spec->pin[spec->num_pins] = pin_nid;
333 spec->num_pins++;
334
335 /*
336 * It is assumed that converter nodes come first in the node list and
337 * hence have been registered and usable now.
338 */
339 return intel_hdmi_read_pin_conn(codec, pin_nid);
340}
341
342static int intel_hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid)
343{
344 struct intel_hdmi_spec *spec = codec->spec;
345
346 if (spec->num_cvts >= INTEL_HDMI_CVTS) {
347 snd_printk(KERN_WARNING
348 "HDMI: no space for converter %d \n", nid);
349 return -EINVAL;
350 }
351
352 spec->cvt[spec->num_cvts] = nid;
353 spec->num_cvts++;
354
355 return 0;
356}
357
358static int intel_hdmi_parse_codec(struct hda_codec *codec)
359{
360 hda_nid_t nid;
361 int i, nodes;
362
363 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
364 if (!nid || nodes < 0) {
365 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
366 return -EINVAL;
367 }
368
369 for (i = 0; i < nodes; i++, nid++) {
370 unsigned int caps;
371 unsigned int type;
372
373 caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
374 type = get_wcaps_type(caps);
375
376 if (!(caps & AC_WCAP_DIGITAL))
377 continue;
378
379 switch (type) {
380 case AC_WID_AUD_OUT:
381 if (intel_hdmi_add_cvt(codec, nid) < 0)
382 return -EINVAL;
383 break;
384 case AC_WID_PIN:
385 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
386 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
387 continue;
388 if (intel_hdmi_add_pin(codec, nid) < 0)
389 return -EINVAL;
390 break;
391 }
392 }
393
394 /*
395 * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
396 * can be lost and presence sense verb will become inaccurate if the
397 * HDA link is powered off at hot plug or hw initialization time.
398 */
399#ifdef CONFIG_SND_HDA_POWER_SAVE
400 if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
401 AC_PWRST_EPSS))
402 codec->bus->power_keep_link_on = 1;
403#endif
404
405 return 0;
406}
407
408/*
188 * HDMI routines 409 * HDMI routines
189 */ 410 */
190 411
191#ifdef BE_PARANOID 412#ifdef BE_PARANOID
192static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t nid, 413static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
193 int *packet_index, int *byte_index) 414 int *packet_index, int *byte_index)
194{ 415{
195 int val; 416 int val;
196 417
197 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_INDEX, 0); 418 val = snd_hda_codec_read(codec, pin_nid, 0,
419 AC_VERB_GET_HDMI_DIP_INDEX, 0);
198 420
199 *packet_index = val >> 5; 421 *packet_index = val >> 5;
200 *byte_index = val & 0x1f; 422 *byte_index = val & 0x1f;
201} 423}
202#endif 424#endif
203 425
204static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t nid, 426static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
205 int packet_index, int byte_index) 427 int packet_index, int byte_index)
206{ 428{
207 int val; 429 int val;
208 430
209 val = (packet_index << 5) | (byte_index & 0x1f); 431 val = (packet_index << 5) | (byte_index & 0x1f);
210 432
211 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); 433 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
212} 434}
213 435
214static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid, 436static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
215 unsigned char val) 437 unsigned char val)
216{ 438{
217 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); 439 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
218} 440}
219 441
220static void hdmi_enable_output(struct hda_codec *codec) 442static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid)
221{ 443{
222 /* Unmute */ 444 /* Unmute */
223 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 445 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
@@ -231,7 +453,8 @@ static void hdmi_enable_output(struct hda_codec *codec)
231/* 453/*
232 * Enable Audio InfoFrame Transmission 454 * Enable Audio InfoFrame Transmission
233 */ 455 */
234static void hdmi_start_infoframe_trans(struct hda_codec *codec) 456static void hdmi_start_infoframe_trans(struct hda_codec *codec,
457 hda_nid_t pin_nid)
235{ 458{
236 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 459 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
237 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 460 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
@@ -241,59 +464,50 @@ static void hdmi_start_infoframe_trans(struct hda_codec *codec)
241/* 464/*
242 * Disable Audio InfoFrame Transmission 465 * Disable Audio InfoFrame Transmission
243 */ 466 */
244static void hdmi_stop_infoframe_trans(struct hda_codec *codec) 467static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
468 hda_nid_t pin_nid)
245{ 469{
246 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 470 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
247 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 471 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
248 AC_DIPXMIT_DISABLE); 472 AC_DIPXMIT_DISABLE);
249} 473}
250 474
251static int hdmi_get_channel_count(struct hda_codec *codec) 475static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid)
252{ 476{
253 return 1 + snd_hda_codec_read(codec, cvt_nid, 0, 477 return 1 + snd_hda_codec_read(codec, nid, 0,
254 AC_VERB_GET_CVT_CHAN_COUNT, 0); 478 AC_VERB_GET_CVT_CHAN_COUNT, 0);
255} 479}
256 480
257static void hdmi_set_channel_count(struct hda_codec *codec, int chs) 481static void hdmi_set_channel_count(struct hda_codec *codec,
482 hda_nid_t nid, int chs)
258{ 483{
259 snd_hda_codec_write(codec, cvt_nid, 0, 484 if (chs != hdmi_get_channel_count(codec, nid))
260 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 485 snd_hda_codec_write(codec, nid, 0,
261 486 AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
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} 487}
266 488
267static void hdmi_debug_channel_mapping(struct hda_codec *codec) 489static void hdmi_debug_channel_mapping(struct hda_codec *codec,
490 hda_nid_t pin_nid)
268{ 491{
269#ifdef CONFIG_SND_DEBUG_VERBOSE 492#ifdef CONFIG_SND_DEBUG_VERBOSE
270 int i; 493 int i;
271 int slot; 494 int slot;
272 495
273 for (i = 0; i < 8; i++) { 496 for (i = 0; i < 8; i++) {
274 slot = snd_hda_codec_read(codec, cvt_nid, 0, 497 slot = snd_hda_codec_read(codec, pin_nid, 0,
275 AC_VERB_GET_HDMI_CHAN_SLOT, i); 498 AC_VERB_GET_HDMI_CHAN_SLOT, i);
276 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 499 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
277 slot >> 4, slot & 0x7); 500 slot >> 4, slot & 0xf);
278 } 501 }
279#endif 502#endif
280} 503}
281 504
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 505
292/* 506/*
293 * Audio InfoFrame routines 507 * Audio InfoFrame routines
294 */ 508 */
295 509
296static void hdmi_debug_dip_size(struct hda_codec *codec) 510static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
297{ 511{
298#ifdef CONFIG_SND_DEBUG_VERBOSE 512#ifdef CONFIG_SND_DEBUG_VERBOSE
299 int i; 513 int i;
@@ -310,7 +524,7 @@ static void hdmi_debug_dip_size(struct hda_codec *codec)
310#endif 524#endif
311} 525}
312 526
313static void hdmi_clear_dip_buffers(struct hda_codec *codec) 527static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
314{ 528{
315#ifdef BE_PARANOID 529#ifdef BE_PARANOID
316 int i, j; 530 int i, j;
@@ -339,23 +553,35 @@ static void hdmi_clear_dip_buffers(struct hda_codec *codec)
339#endif 553#endif
340} 554}
341 555
342static void hdmi_fill_audio_infoframe(struct hda_codec *codec, 556static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai)
343 struct hdmi_audio_infoframe *ai)
344{ 557{
345 u8 *params = (u8 *)ai; 558 u8 *bytes = (u8 *)ai;
346 u8 sum = 0; 559 u8 sum = 0;
347 int i; 560 int i;
348 561
349 hdmi_debug_dip_size(codec); 562 ai->checksum = 0;
350 hdmi_clear_dip_buffers(codec); /* be paranoid */ 563
564 for (i = 0; i < sizeof(*ai); i++)
565 sum += bytes[i];
351 566
352 for (i = 0; i < sizeof(ai); i++)
353 sum += params[i];
354 ai->checksum = - sum; 567 ai->checksum = - sum;
568}
569
570static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
571 hda_nid_t pin_nid,
572 struct hdmi_audio_infoframe *ai)
573{
574 u8 *bytes = (u8 *)ai;
575 int i;
576
577 hdmi_debug_dip_size(codec, pin_nid);
578 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
579
580 hdmi_checksum_audio_infoframe(ai);
355 581
356 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 582 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
357 for (i = 0; i < sizeof(ai); i++) 583 for (i = 0; i < sizeof(*ai); i++)
358 hdmi_write_dip_byte(codec, pin_nid, params[i]); 584 hdmi_write_dip_byte(codec, pin_nid, bytes[i]);
359} 585}
360 586
361/* 587/*
@@ -386,11 +612,11 @@ static void init_channel_allocations(void)
386 * 612 *
387 * TODO: it could select the wrong CA from multiple candidates. 613 * TODO: it could select the wrong CA from multiple candidates.
388*/ 614*/
389static int hdmi_setup_channel_allocation(struct hda_codec *codec, 615static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid,
390 struct hdmi_audio_infoframe *ai) 616 struct hdmi_audio_infoframe *ai)
391{ 617{
392 struct intel_hdmi_spec *spec = codec->spec; 618 struct intel_hdmi_spec *spec = codec->spec;
393 struct hdmi_eld *eld = &spec->sink_eld; 619 struct hdmi_eld *eld;
394 int i; 620 int i;
395 int spk_mask = 0; 621 int spk_mask = 0;
396 int channels = 1 + (ai->CC02_CT47 & 0x7); 622 int channels = 1 + (ai->CC02_CT47 & 0x7);
@@ -402,6 +628,11 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
402 if (channels <= 2) 628 if (channels <= 2)
403 return 0; 629 return 0;
404 630
631 i = hda_node_index(spec->pin_cvt, nid);
632 if (i < 0)
633 return 0;
634 eld = &spec->sink_eld[i];
635
405 /* 636 /*
406 * HDMI sink's ELD info cannot always be retrieved for now, e.g. 637 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
407 * in console or for audio devices. Assume the highest speakers 638 * in console or for audio devices. Assume the highest speakers
@@ -440,30 +671,61 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
440} 671}
441 672
442static void hdmi_setup_channel_mapping(struct hda_codec *codec, 673static void hdmi_setup_channel_mapping(struct hda_codec *codec,
443 struct hdmi_audio_infoframe *ai) 674 hda_nid_t pin_nid,
675 struct hdmi_audio_infoframe *ai)
444{ 676{
445 int i; 677 int i;
678 int ca = ai->CA;
679 int err;
446 680
447 if (!ai->CA) 681 if (hdmi_channel_mapping[ca][1] == 0) {
448 return; 682 for (i = 0; i < channel_allocations[ca].channels; i++)
449 683 hdmi_channel_mapping[ca][i] = i | (i << 4);
450 /* 684 for (; i < 8; i++)
451 * TODO: adjust channel mapping if necessary 685 hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
452 * ALSA sequence is front/surr/clfe/side? 686 }
453 */
454 687
455 for (i = 0; i < 8; i++) 688 for (i = 0; i < 8; i++) {
456 snd_hda_codec_write(codec, cvt_nid, 0, 689 err = snd_hda_codec_write(codec, pin_nid, 0,
457 AC_VERB_SET_HDMI_CHAN_SLOT, 690 AC_VERB_SET_HDMI_CHAN_SLOT,
458 (i << 4) | i); 691 hdmi_channel_mapping[ca][i]);
692 if (err) {
693 snd_printdd(KERN_INFO "HDMI: channel mapping failed\n");
694 break;
695 }
696 }
459 697
460 hdmi_debug_channel_mapping(codec); 698 hdmi_debug_channel_mapping(codec, pin_nid);
461} 699}
462 700
701static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
702 struct hdmi_audio_infoframe *ai)
703{
704 u8 *bytes = (u8 *)ai;
705 u8 val;
706 int i;
707
708 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
709 != AC_DIPXMIT_BEST)
710 return false;
711
712 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
713 for (i = 0; i < sizeof(*ai); i++) {
714 val = snd_hda_codec_read(codec, pin_nid, 0,
715 AC_VERB_GET_HDMI_DIP_DATA, 0);
716 if (val != bytes[i])
717 return false;
718 }
719
720 return true;
721}
463 722
464static void hdmi_setup_audio_infoframe(struct hda_codec *codec, 723static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid,
465 struct snd_pcm_substream *substream) 724 struct snd_pcm_substream *substream)
466{ 725{
726 struct intel_hdmi_spec *spec = codec->spec;
727 hda_nid_t pin_nid;
728 int i;
467 struct hdmi_audio_infoframe ai = { 729 struct hdmi_audio_infoframe ai = {
468 .type = 0x84, 730 .type = 0x84,
469 .ver = 0x01, 731 .ver = 0x01,
@@ -471,11 +733,22 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
471 .CC02_CT47 = substream->runtime->channels - 1, 733 .CC02_CT47 = substream->runtime->channels - 1,
472 }; 734 };
473 735
474 hdmi_setup_channel_allocation(codec, &ai); 736 hdmi_setup_channel_allocation(codec, nid, &ai);
475 hdmi_setup_channel_mapping(codec, &ai);
476 737
477 hdmi_fill_audio_infoframe(codec, &ai); 738 for (i = 0; i < spec->num_pins; i++) {
478 hdmi_start_infoframe_trans(codec); 739 if (spec->pin_cvt[i] != nid)
740 continue;
741 if (!spec->sink_eld[i].monitor_present)
742 continue;
743
744 pin_nid = spec->pin[i];
745 if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) {
746 hdmi_setup_channel_mapping(codec, pin_nid, &ai);
747 hdmi_stop_infoframe_trans(codec, pin_nid);
748 hdmi_fill_audio_infoframe(codec, pin_nid, &ai);
749 hdmi_start_infoframe_trans(codec, pin_nid);
750 }
751 }
479} 752}
480 753
481 754
@@ -485,27 +758,39 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
485 758
486static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 759static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
487{ 760{
761 struct intel_hdmi_spec *spec = codec->spec;
762 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
488 int pind = !!(res & AC_UNSOL_RES_PD); 763 int pind = !!(res & AC_UNSOL_RES_PD);
489 int eldv = !!(res & AC_UNSOL_RES_ELDV); 764 int eldv = !!(res & AC_UNSOL_RES_ELDV);
765 int index;
490 766
491 printk(KERN_INFO 767 printk(KERN_INFO
492 "HDMI hot plug event: Presence_Detect=%d ELD_Valid=%d\n", 768 "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
493 pind, eldv); 769 tag, pind, eldv);
770
771 index = hda_node_index(spec->pin, tag);
772 if (index < 0)
773 return;
774
775 spec->sink_eld[index].monitor_present = pind;
776 spec->sink_eld[index].eld_valid = eldv;
494 777
495 if (pind && eldv) { 778 if (pind && eldv) {
496 hdmi_parse_eld(codec); 779 hdmi_get_show_eld(codec, spec->pin[index], &spec->sink_eld[index]);
497 /* TODO: do real things about ELD */ 780 /* TODO: do real things about ELD */
498 } 781 }
499} 782}
500 783
501static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 784static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
502{ 785{
786 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
503 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 787 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
504 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 788 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
505 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 789 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
506 790
507 printk(KERN_INFO 791 printk(KERN_INFO
508 "HDMI content protection event: SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 792 "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
793 tag,
509 subtag, 794 subtag,
510 cp_state, 795 cp_state,
511 cp_ready); 796 cp_ready);
@@ -520,10 +805,11 @@ static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
520 805
521static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res) 806static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
522{ 807{
808 struct intel_hdmi_spec *spec = codec->spec;
523 int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 809 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
524 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 810 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
525 811
526 if (tag != INTEL_HDMI_EVENT_TAG) { 812 if (hda_node_index(spec->pin, tag) < 0) {
527 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 813 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
528 return; 814 return;
529 } 815 }
@@ -538,24 +824,29 @@ static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
538 * Callbacks 824 * Callbacks
539 */ 825 */
540 826
541static int intel_hdmi_playback_pcm_open(struct hda_pcm_stream *hinfo, 827static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid,
542 struct hda_codec *codec, 828 u32 stream_tag, int format)
543 struct snd_pcm_substream *substream)
544{ 829{
545 struct intel_hdmi_spec *spec = codec->spec; 830 int tag;
546 831 int fmt;
547 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
548}
549 832
550static int intel_hdmi_playback_pcm_close(struct hda_pcm_stream *hinfo, 833 tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4;
551 struct hda_codec *codec, 834 fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0);
552 struct snd_pcm_substream *substream)
553{
554 struct intel_hdmi_spec *spec = codec->spec;
555 835
556 hdmi_stop_infoframe_trans(codec); 836 snd_printdd("hdmi_setup_stream: "
837 "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
838 nid,
839 tag == stream_tag ? "" : "new-",
840 stream_tag,
841 fmt == format ? "" : "new-",
842 format);
557 843
558 return snd_hda_multi_out_dig_close(codec, &spec->multiout); 844 if (tag != stream_tag)
845 snd_hda_codec_write(codec, nid, 0,
846 AC_VERB_SET_CHANNEL_STREAMID, stream_tag << 4);
847 if (fmt != format)
848 snd_hda_codec_write(codec, nid, 0,
849 AC_VERB_SET_STREAM_FORMAT, format);
559} 850}
560 851
561static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 852static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -564,43 +855,53 @@ static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
564 unsigned int format, 855 unsigned int format,
565 struct snd_pcm_substream *substream) 856 struct snd_pcm_substream *substream)
566{ 857{
567 struct intel_hdmi_spec *spec = codec->spec; 858 hdmi_set_channel_count(codec, hinfo->nid,
568 859 substream->runtime->channels);
569 snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
570 format, substream);
571 860
572 hdmi_set_channel_count(codec, substream->runtime->channels); 861 hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
573 862
574 hdmi_setup_audio_infoframe(codec, substream); 863 hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
864 return 0;
865}
575 866
867static int intel_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
868 struct hda_codec *codec,
869 struct snd_pcm_substream *substream)
870{
576 return 0; 871 return 0;
577} 872}
578 873
579static struct hda_pcm_stream intel_hdmi_pcm_playback = { 874static struct hda_pcm_stream intel_hdmi_pcm_playback = {
580 .substreams = 1, 875 .substreams = 1,
581 .channels_min = 2, 876 .channels_min = 2,
582 .channels_max = 8,
583 .ops = { 877 .ops = {
584 .open = intel_hdmi_playback_pcm_open, 878 .prepare = intel_hdmi_playback_pcm_prepare,
585 .close = intel_hdmi_playback_pcm_close, 879 .cleanup = intel_hdmi_playback_pcm_cleanup,
586 .prepare = intel_hdmi_playback_pcm_prepare
587 }, 880 },
588}; 881};
589 882
590static int intel_hdmi_build_pcms(struct hda_codec *codec) 883static int intel_hdmi_build_pcms(struct hda_codec *codec)
591{ 884{
592 struct intel_hdmi_spec *spec = codec->spec; 885 struct intel_hdmi_spec *spec = codec->spec;
593 struct hda_pcm *info = &spec->pcm_rec; 886 struct hda_pcm *info = spec->pcm_rec;
887 int i;
594 888
595 codec->num_pcms = 1; 889 codec->num_pcms = spec->num_cvts;
596 codec->pcm_info = info; 890 codec->pcm_info = info;
597 891
598 /* NID to query formats and rates and setup streams */ 892 for (i = 0; i < codec->num_pcms; i++, info++) {
599 intel_hdmi_pcm_playback.nid = cvt_nid; 893 unsigned int chans;
894
895 chans = get_wcaps(codec, spec->cvt[i]);
896 chans = get_wcaps_channels(chans);
600 897
601 info->name = "INTEL HDMI"; 898 info->name = intel_hdmi_pcm_names[i];
602 info->pcm_type = HDA_PCM_TYPE_HDMI; 899 info->pcm_type = HDA_PCM_TYPE_HDMI;
603 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback; 900 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
901 intel_hdmi_pcm_playback;
902 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->cvt[i];
903 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = chans;
904 }
604 905
605 return 0; 906 return 0;
606} 907}
@@ -609,29 +910,39 @@ static int intel_hdmi_build_controls(struct hda_codec *codec)
609{ 910{
610 struct intel_hdmi_spec *spec = codec->spec; 911 struct intel_hdmi_spec *spec = codec->spec;
611 int err; 912 int err;
913 int i;
612 914
613 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 915 for (i = 0; i < codec->num_pcms; i++) {
614 if (err < 0) 916 err = snd_hda_create_spdif_out_ctls(codec, spec->cvt[i]);
615 return err; 917 if (err < 0)
918 return err;
919 }
616 920
617 return 0; 921 return 0;
618} 922}
619 923
620static int intel_hdmi_init(struct hda_codec *codec) 924static int intel_hdmi_init(struct hda_codec *codec)
621{ 925{
622 hdmi_enable_output(codec); 926 struct intel_hdmi_spec *spec = codec->spec;
927 int i;
623 928
624 snd_hda_codec_write(codec, pin_nid, 0, 929 for (i = 0; spec->pin[i]; i++) {
625 AC_VERB_SET_UNSOLICITED_ENABLE, 930 hdmi_enable_output(codec, spec->pin[i]);
626 AC_USRSP_EN | INTEL_HDMI_EVENT_TAG); 931 snd_hda_codec_write(codec, spec->pin[i], 0,
932 AC_VERB_SET_UNSOLICITED_ENABLE,
933 AC_USRSP_EN | spec->pin[i]);
934 }
627 return 0; 935 return 0;
628} 936}
629 937
630static void intel_hdmi_free(struct hda_codec *codec) 938static void intel_hdmi_free(struct hda_codec *codec)
631{ 939{
632 struct intel_hdmi_spec *spec = codec->spec; 940 struct intel_hdmi_spec *spec = codec->spec;
941 int i;
942
943 for (i = 0; i < spec->num_pins; i++)
944 snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
633 945
634 snd_hda_eld_proc_free(codec, &spec->sink_eld);
635 kfree(spec); 946 kfree(spec);
636} 947}
637 948
@@ -643,49 +954,38 @@ static struct hda_codec_ops intel_hdmi_patch_ops = {
643 .unsol_event = intel_hdmi_unsol_event, 954 .unsol_event = intel_hdmi_unsol_event,
644}; 955};
645 956
646static int do_patch_intel_hdmi(struct hda_codec *codec) 957static int patch_intel_hdmi(struct hda_codec *codec)
647{ 958{
648 struct intel_hdmi_spec *spec; 959 struct intel_hdmi_spec *spec;
960 int i;
649 961
650 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 962 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
651 if (spec == NULL) 963 if (spec == NULL)
652 return -ENOMEM; 964 return -ENOMEM;
653 965
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; 966 codec->spec = spec;
967 if (intel_hdmi_parse_codec(codec) < 0) {
968 codec->spec = NULL;
969 kfree(spec);
970 return -EINVAL;
971 }
659 codec->patch_ops = intel_hdmi_patch_ops; 972 codec->patch_ops = intel_hdmi_patch_ops;
660 973
661 snd_hda_eld_proc_new(codec, &spec->sink_eld); 974 for (i = 0; i < spec->num_pins; i++)
975 snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
662 976
663 init_channel_allocations(); 977 init_channel_allocations();
664 978
665 return 0; 979 return 0;
666} 980}
667 981
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[] = { 982static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
683 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi }, 983 { .id = 0x808629fb, .name = "G45 DEVCL", .patch = patch_intel_hdmi },
684 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi }, 984 { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
685 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi }, 985 { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
686 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi }, 986 { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
687 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi }, 987 { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi },
688 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi_ibexpeak }, 988 { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi },
689 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi }, 989 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
690 {} /* terminator */ 990 {} /* terminator */
691}; 991};
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
index 9fb60276f5c9..6afdab09bab7 100644
--- a/sound/pci/hda/patch_nvhdmi.c
+++ b/sound/pci/hda/patch_nvhdmi.c
@@ -397,6 +397,7 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
397static struct hda_codec_preset snd_hda_preset_nvhdmi[] = { 397static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
398 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 398 { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
399 { .id = 0x10de0003, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 399 { .id = 0x10de0003, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
400 { .id = 0x10de0005, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
400 { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch }, 401 { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
401 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi_8ch }, 402 { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi_8ch },
402 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, 403 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
@@ -406,6 +407,7 @@ static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
406 407
407MODULE_ALIAS("snd-hda-codec-id:10de0002"); 408MODULE_ALIAS("snd-hda-codec-id:10de0002");
408MODULE_ALIAS("snd-hda-codec-id:10de0003"); 409MODULE_ALIAS("snd-hda-codec-id:10de0003");
410MODULE_ALIAS("snd-hda-codec-id:10de0005");
409MODULE_ALIAS("snd-hda-codec-id:10de0006"); 411MODULE_ALIAS("snd-hda-codec-id:10de0006");
410MODULE_ALIAS("snd-hda-codec-id:10de0007"); 412MODULE_ALIAS("snd-hda-codec-id:10de0007");
411MODULE_ALIAS("snd-hda-codec-id:10de0067"); 413MODULE_ALIAS("snd-hda-codec-id:10de0067");
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index ff20048504b6..c7465053d6bb 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -131,8 +131,8 @@ enum {
131enum { 131enum {
132 ALC269_BASIC, 132 ALC269_BASIC,
133 ALC269_QUANTA_FL1, 133 ALC269_QUANTA_FL1,
134 ALC269_ASUS_EEEPC_P703, 134 ALC269_ASUS_AMIC,
135 ALC269_ASUS_EEEPC_P901, 135 ALC269_ASUS_DMIC,
136 ALC269_FUJITSU, 136 ALC269_FUJITSU,
137 ALC269_LIFEBOOK, 137 ALC269_LIFEBOOK,
138 ALC269_AUTO, 138 ALC269_AUTO,
@@ -188,6 +188,8 @@ enum {
188 ALC663_ASUS_MODE4, 188 ALC663_ASUS_MODE4,
189 ALC663_ASUS_MODE5, 189 ALC663_ASUS_MODE5,
190 ALC663_ASUS_MODE6, 190 ALC663_ASUS_MODE6,
191 ALC663_ASUS_MODE7,
192 ALC663_ASUS_MODE8,
191 ALC272_DELL, 193 ALC272_DELL,
192 ALC272_DELL_ZM1, 194 ALC272_DELL_ZM1,
193 ALC272_SAMSUNG_NC10, 195 ALC272_SAMSUNG_NC10,
@@ -208,6 +210,7 @@ enum {
208 ALC885_MBP3, 210 ALC885_MBP3,
209 ALC885_MB5, 211 ALC885_MB5,
210 ALC885_IMAC24, 212 ALC885_IMAC24,
213 ALC885_IMAC91,
211 ALC883_3ST_2ch_DIG, 214 ALC883_3ST_2ch_DIG,
212 ALC883_3ST_6ch_DIG, 215 ALC883_3ST_6ch_DIG,
213 ALC883_3ST_6ch, 216 ALC883_3ST_6ch,
@@ -334,6 +337,9 @@ struct alc_spec {
334 /* hooks */ 337 /* hooks */
335 void (*init_hook)(struct hda_codec *codec); 338 void (*init_hook)(struct hda_codec *codec);
336 void (*unsol_event)(struct hda_codec *codec, unsigned int res); 339 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
340#ifdef CONFIG_SND_HDA_POWER_SAVE
341 void (*power_hook)(struct hda_codec *codec, int power);
342#endif
337 343
338 /* for pin sensing */ 344 /* for pin sensing */
339 unsigned int sense_updated: 1; 345 unsigned int sense_updated: 1;
@@ -385,6 +391,7 @@ struct alc_config_preset {
385 void (*init_hook)(struct hda_codec *); 391 void (*init_hook)(struct hda_codec *);
386#ifdef CONFIG_SND_HDA_POWER_SAVE 392#ifdef CONFIG_SND_HDA_POWER_SAVE
387 struct hda_amp_list *loopbacks; 393 struct hda_amp_list *loopbacks;
394 void (*power_hook)(struct hda_codec *codec, int power);
388#endif 395#endif
389}; 396};
390 397
@@ -897,6 +904,7 @@ static void setup_preset(struct hda_codec *codec,
897 spec->unsol_event = preset->unsol_event; 904 spec->unsol_event = preset->unsol_event;
898 spec->init_hook = preset->init_hook; 905 spec->init_hook = preset->init_hook;
899#ifdef CONFIG_SND_HDA_POWER_SAVE 906#ifdef CONFIG_SND_HDA_POWER_SAVE
907 spec->power_hook = preset->power_hook;
900 spec->loopback.amplist = preset->loopbacks; 908 spec->loopback.amplist = preset->loopbacks;
901#endif 909#endif
902 910
@@ -961,18 +969,12 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
961static void alc_automute_pin(struct hda_codec *codec) 969static void alc_automute_pin(struct hda_codec *codec)
962{ 970{
963 struct alc_spec *spec = codec->spec; 971 struct alc_spec *spec = codec->spec;
964 unsigned int present, pincap;
965 unsigned int nid = spec->autocfg.hp_pins[0]; 972 unsigned int nid = spec->autocfg.hp_pins[0];
966 int i; 973 int i;
967 974
968 if (!nid) 975 if (!nid)
969 return; 976 return;
970 pincap = snd_hda_query_pin_caps(codec, nid); 977 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++) { 978 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977 nid = spec->autocfg.speaker_pins[i]; 979 nid = spec->autocfg.speaker_pins[i];
978 if (!nid) 980 if (!nid)
@@ -1012,9 +1014,7 @@ static void alc_mic_automute(struct hda_codec *codec)
1012 1014
1013 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0]; 1015 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014 1016
1015 present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0, 1017 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) { 1018 if (present) {
1019 alive = &spec->ext_mic; 1019 alive = &spec->ext_mic;
1020 dead = &spec->int_mic; 1020 dead = &spec->int_mic;
@@ -1402,6 +1402,17 @@ static void alc_pick_fixup(struct hda_codec *codec,
1402 add_verb(codec->spec, fix->verbs); 1402 add_verb(codec->spec, fix->verbs);
1403} 1403}
1404 1404
1405static int alc_read_coef_idx(struct hda_codec *codec,
1406 unsigned int coef_idx)
1407{
1408 unsigned int val;
1409 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1410 coef_idx);
1411 val = snd_hda_codec_read(codec, 0x20, 0,
1412 AC_VERB_GET_PROC_COEF, 0);
1413 return val;
1414}
1415
1405/* 1416/*
1406 * ALC888 1417 * ALC888
1407 */ 1418 */
@@ -1513,7 +1524,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1513static void alc_automute_amp(struct hda_codec *codec) 1524static void alc_automute_amp(struct hda_codec *codec)
1514{ 1525{
1515 struct alc_spec *spec = codec->spec; 1526 struct alc_spec *spec = codec->spec;
1516 unsigned int val, mute, pincap; 1527 unsigned int mute;
1517 hda_nid_t nid; 1528 hda_nid_t nid;
1518 int i; 1529 int i;
1519 1530
@@ -1522,13 +1533,7 @@ static void alc_automute_amp(struct hda_codec *codec)
1522 nid = spec->autocfg.hp_pins[i]; 1533 nid = spec->autocfg.hp_pins[i];
1523 if (!nid) 1534 if (!nid)
1524 break; 1535 break;
1525 pincap = snd_hda_query_pin_caps(codec, nid); 1536 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; 1537 spec->jack_present = 1;
1533 break; 1538 break;
1534 } 1539 }
@@ -1665,9 +1670,6 @@ static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1665/* some bit here disables the other DACs. Init=0x4900 */ 1670/* some bit here disables the other DACs. Init=0x4900 */
1666 {0x20, AC_VERB_SET_COEF_INDEX, 0x08}, 1671 {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1667 {0x20, AC_VERB_SET_PROC_COEF, 0x0000}, 1672 {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 1673/* DMIC fix
1672 * This laptop has a stereo digital microphone. The mics are only 1cm apart 1674 * 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 1675 * which makes the stereo useless. However, either the mic or the ALC889
@@ -1780,12 +1782,33 @@ static struct snd_kcontrol_new alc888_base_mixer[] = {
1780 { } /* end */ 1782 { } /* end */
1781}; 1783};
1782 1784
1785static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
1786 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1787 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1788 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1789 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1790 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1791 HDA_OUTPUT),
1792 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1793 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1794 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1795 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1796 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1797 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1798 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1799 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1800 { } /* end */
1801};
1802
1803
1783static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec) 1804static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1784{ 1805{
1785 struct alc_spec *spec = codec->spec; 1806 struct alc_spec *spec = codec->spec;
1786 1807
1787 spec->autocfg.hp_pins[0] = 0x15; 1808 spec->autocfg.hp_pins[0] = 0x15;
1788 spec->autocfg.speaker_pins[0] = 0x14; 1809 spec->autocfg.speaker_pins[0] = 0x14;
1810 spec->autocfg.speaker_pins[1] = 0x16;
1811 spec->autocfg.speaker_pins[2] = 0x17;
1789} 1812}
1790 1813
1791static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec) 1814static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
@@ -1808,6 +1831,16 @@ static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1808 spec->autocfg.speaker_pins[2] = 0x1b; 1831 spec->autocfg.speaker_pins[2] = 0x1b;
1809} 1832}
1810 1833
1834#ifdef CONFIG_SND_HDA_POWER_SAVE
1835static void alc889_power_eapd(struct hda_codec *codec, int power)
1836{
1837 snd_hda_codec_write(codec, 0x14, 0,
1838 AC_VERB_SET_EAPD_BTLENABLE, power ? 2 : 0);
1839 snd_hda_codec_write(codec, 0x15, 0,
1840 AC_VERB_SET_EAPD_BTLENABLE, power ? 2 : 0);
1841}
1842#endif
1843
1811/* 1844/*
1812 * ALC880 3-stack model 1845 * ALC880 3-stack model
1813 * 1846 *
@@ -2401,6 +2434,8 @@ static const char *alc_slave_sws[] = {
2401 "Speaker Playback Switch", 2434 "Speaker Playback Switch",
2402 "Mono Playback Switch", 2435 "Mono Playback Switch",
2403 "IEC958 Playback Switch", 2436 "IEC958 Playback Switch",
2437 "Line-Out Playback Switch",
2438 "PCM Playback Switch",
2404 NULL, 2439 NULL,
2405}; 2440};
2406 2441
@@ -2410,12 +2445,14 @@ static const char *alc_slave_sws[] = {
2410 2445
2411static void alc_free_kctls(struct hda_codec *codec); 2446static void alc_free_kctls(struct hda_codec *codec);
2412 2447
2448#ifdef CONFIG_SND_HDA_INPUT_BEEP
2413/* additional beep mixers; the actual parameters are overwritten at build */ 2449/* additional beep mixers; the actual parameters are overwritten at build */
2414static struct snd_kcontrol_new alc_beep_mixer[] = { 2450static struct snd_kcontrol_new alc_beep_mixer[] = {
2415 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT), 2451 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2416 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT), 2452 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2417 { } /* end */ 2453 { } /* end */
2418}; 2454};
2455#endif
2419 2456
2420static int alc_build_controls(struct hda_codec *codec) 2457static int alc_build_controls(struct hda_codec *codec)
2421{ 2458{
@@ -2452,6 +2489,7 @@ static int alc_build_controls(struct hda_codec *codec)
2452 return err; 2489 return err;
2453 } 2490 }
2454 2491
2492#ifdef CONFIG_SND_HDA_INPUT_BEEP
2455 /* create beep controls if needed */ 2493 /* create beep controls if needed */
2456 if (spec->beep_amp) { 2494 if (spec->beep_amp) {
2457 struct snd_kcontrol_new *knew; 2495 struct snd_kcontrol_new *knew;
@@ -2461,11 +2499,13 @@ static int alc_build_controls(struct hda_codec *codec)
2461 if (!kctl) 2499 if (!kctl)
2462 return -ENOMEM; 2500 return -ENOMEM;
2463 kctl->private_value = spec->beep_amp; 2501 kctl->private_value = spec->beep_amp;
2464 err = snd_hda_ctl_add(codec, kctl); 2502 err = snd_hda_ctl_add(codec,
2503 get_amp_nid_(spec->beep_amp), kctl);
2465 if (err < 0) 2504 if (err < 0)
2466 return err; 2505 return err;
2467 } 2506 }
2468 } 2507 }
2508#endif
2469 2509
2470 /* if we have no master control, let's create it */ 2510 /* if we have no master control, let's create it */
2471 if (!spec->no_analog && 2511 if (!spec->no_analog &&
@@ -2779,8 +2819,7 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2779 unsigned int present; 2819 unsigned int present;
2780 unsigned char bits; 2820 unsigned char bits;
2781 2821
2782 present = snd_hda_codec_read(codec, 0x18, 0, 2822 present = snd_hda_jack_detect(codec, 0x18);
2783 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2784 bits = present ? HDA_AMP_MUTE : 0; 2823 bits = present ? HDA_AMP_MUTE : 0;
2785 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 2824 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2786} 2825}
@@ -3480,7 +3519,7 @@ static int alc_build_pcms(struct hda_codec *codec)
3480 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), 3519 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3481 "%s Analog", codec->chip_name); 3520 "%s Analog", codec->chip_name);
3482 info->name = spec->stream_name_analog; 3521 info->name = spec->stream_name_analog;
3483 3522
3484 if (spec->stream_analog_playback) { 3523 if (spec->stream_analog_playback) {
3485 if (snd_BUG_ON(!spec->multiout.dac_nids)) 3524 if (snd_BUG_ON(!spec->multiout.dac_nids))
3486 return -EINVAL; 3525 return -EINVAL;
@@ -3595,12 +3634,29 @@ static void alc_free(struct hda_codec *codec)
3595 snd_hda_detach_beep_device(codec); 3634 snd_hda_detach_beep_device(codec);
3596} 3635}
3597 3636
3637#ifdef CONFIG_SND_HDA_POWER_SAVE
3638static int alc_suspend(struct hda_codec *codec, pm_message_t state)
3639{
3640 struct alc_spec *spec = codec->spec;
3641 if (spec && spec->power_hook)
3642 spec->power_hook(codec, 0);
3643 return 0;
3644}
3645#endif
3646
3598#ifdef SND_HDA_NEEDS_RESUME 3647#ifdef SND_HDA_NEEDS_RESUME
3599static int alc_resume(struct hda_codec *codec) 3648static int alc_resume(struct hda_codec *codec)
3600{ 3649{
3650#ifdef CONFIG_SND_HDA_POWER_SAVE
3651 struct alc_spec *spec = codec->spec;
3652#endif
3601 codec->patch_ops.init(codec); 3653 codec->patch_ops.init(codec);
3602 snd_hda_codec_resume_amp(codec); 3654 snd_hda_codec_resume_amp(codec);
3603 snd_hda_codec_resume_cache(codec); 3655 snd_hda_codec_resume_cache(codec);
3656#ifdef CONFIG_SND_HDA_POWER_SAVE
3657 if (spec && spec->power_hook)
3658 spec->power_hook(codec, 1);
3659#endif
3604 return 0; 3660 return 0;
3605} 3661}
3606#endif 3662#endif
@@ -3617,6 +3673,7 @@ static struct hda_codec_ops alc_patch_ops = {
3617 .resume = alc_resume, 3673 .resume = alc_resume,
3618#endif 3674#endif
3619#ifdef CONFIG_SND_HDA_POWER_SAVE 3675#ifdef CONFIG_SND_HDA_POWER_SAVE
3676 .suspend = alc_suspend,
3620 .check_power_status = alc_check_power_status, 3677 .check_power_status = alc_check_power_status,
3621#endif 3678#endif
3622}; 3679};
@@ -4322,10 +4379,26 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
4322 knew->name = kstrdup(name, GFP_KERNEL); 4379 knew->name = kstrdup(name, GFP_KERNEL);
4323 if (!knew->name) 4380 if (!knew->name)
4324 return -ENOMEM; 4381 return -ENOMEM;
4382 if (get_amp_nid_(val))
4383 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
4325 knew->private_value = val; 4384 knew->private_value = val;
4326 return 0; 4385 return 0;
4327} 4386}
4328 4387
4388static int add_control_with_pfx(struct alc_spec *spec, int type,
4389 const char *pfx, const char *dir,
4390 const char *sfx, unsigned long val)
4391{
4392 char name[32];
4393 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4394 return add_control(spec, type, name, val);
4395}
4396
4397#define add_pb_vol_ctrl(spec, type, pfx, val) \
4398 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4399#define add_pb_sw_ctrl(spec, type, pfx, val) \
4400 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4401
4329#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17) 4402#define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
4330#define alc880_fixed_pin_idx(nid) ((nid) - 0x14) 4403#define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
4331#define alc880_is_multi_pin(nid) ((nid) >= 0x18) 4404#define alc880_is_multi_pin(nid) ((nid) >= 0x18)
@@ -4379,7 +4452,6 @@ static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4379static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, 4452static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4380 const struct auto_pin_cfg *cfg) 4453 const struct auto_pin_cfg *cfg)
4381{ 4454{
4382 char name[32];
4383 static const char *chname[4] = { 4455 static const char *chname[4] = {
4384 "Front", "Surround", NULL /*CLFE*/, "Side" 4456 "Front", "Surround", NULL /*CLFE*/, "Side"
4385 }; 4457 };
@@ -4392,26 +4464,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])); 4464 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4393 if (i == 2) { 4465 if (i == 2) {
4394 /* Center/LFE */ 4466 /* Center/LFE */
4395 err = add_control(spec, ALC_CTL_WIDGET_VOL, 4467 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4396 "Center Playback Volume", 4468 "Center",
4397 HDA_COMPOSE_AMP_VAL(nid, 1, 0, 4469 HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4398 HDA_OUTPUT)); 4470 HDA_OUTPUT));
4399 if (err < 0) 4471 if (err < 0)
4400 return err; 4472 return err;
4401 err = add_control(spec, ALC_CTL_WIDGET_VOL, 4473 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4402 "LFE Playback Volume", 4474 "LFE",
4403 HDA_COMPOSE_AMP_VAL(nid, 2, 0, 4475 HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4404 HDA_OUTPUT)); 4476 HDA_OUTPUT));
4405 if (err < 0) 4477 if (err < 0)
4406 return err; 4478 return err;
4407 err = add_control(spec, ALC_CTL_BIND_MUTE, 4479 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4408 "Center Playback Switch", 4480 "Center",
4409 HDA_COMPOSE_AMP_VAL(nid, 1, 2, 4481 HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4410 HDA_INPUT)); 4482 HDA_INPUT));
4411 if (err < 0) 4483 if (err < 0)
4412 return err; 4484 return err;
4413 err = add_control(spec, ALC_CTL_BIND_MUTE, 4485 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4414 "LFE Playback Switch", 4486 "LFE",
4415 HDA_COMPOSE_AMP_VAL(nid, 2, 2, 4487 HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4416 HDA_INPUT)); 4488 HDA_INPUT));
4417 if (err < 0) 4489 if (err < 0)
@@ -4423,14 +4495,12 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4423 pfx = "Speaker"; 4495 pfx = "Speaker";
4424 else 4496 else
4425 pfx = chname[i]; 4497 pfx = chname[i];
4426 sprintf(name, "%s Playback Volume", pfx); 4498 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, 4499 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4429 HDA_OUTPUT)); 4500 HDA_OUTPUT));
4430 if (err < 0) 4501 if (err < 0)
4431 return err; 4502 return err;
4432 sprintf(name, "%s Playback Switch", pfx); 4503 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, 4504 HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4435 HDA_INPUT)); 4505 HDA_INPUT));
4436 if (err < 0) 4506 if (err < 0)
@@ -4446,7 +4516,6 @@ static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4446{ 4516{
4447 hda_nid_t nid; 4517 hda_nid_t nid;
4448 int err; 4518 int err;
4449 char name[32];
4450 4519
4451 if (!pin) 4520 if (!pin)
4452 return 0; 4521 return 0;
@@ -4460,21 +4529,18 @@ static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4460 spec->multiout.extra_out_nid[0] = nid; 4529 spec->multiout.extra_out_nid[0] = nid;
4461 /* control HP volume/switch on the output mixer amp */ 4530 /* control HP volume/switch on the output mixer amp */
4462 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin)); 4531 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4463 sprintf(name, "%s Playback Volume", pfx); 4532 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)); 4533 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4466 if (err < 0) 4534 if (err < 0)
4467 return err; 4535 return err;
4468 sprintf(name, "%s Playback Switch", pfx); 4536 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)); 4537 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4471 if (err < 0) 4538 if (err < 0)
4472 return err; 4539 return err;
4473 } else if (alc880_is_multi_pin(pin)) { 4540 } else if (alc880_is_multi_pin(pin)) {
4474 /* set manual connection */ 4541 /* set manual connection */
4475 /* we have only a switch on HP-out PIN */ 4542 /* we have only a switch on HP-out PIN */
4476 sprintf(name, "%s Playback Switch", pfx); 4543 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)); 4544 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4479 if (err < 0) 4545 if (err < 0)
4480 return err; 4546 return err;
@@ -4487,16 +4553,13 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4487 const char *ctlname, 4553 const char *ctlname,
4488 int idx, hda_nid_t mix_nid) 4554 int idx, hda_nid_t mix_nid)
4489{ 4555{
4490 char name[32];
4491 int err; 4556 int err;
4492 4557
4493 sprintf(name, "%s Playback Volume", ctlname); 4558 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)); 4559 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4496 if (err < 0) 4560 if (err < 0)
4497 return err; 4561 return err;
4498 sprintf(name, "%s Playback Switch", ctlname); 4562 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)); 4563 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4501 if (err < 0) 4564 if (err < 0)
4502 return err; 4565 return err;
@@ -4684,9 +4747,9 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
4684 spec->multiout.dig_out_nid = dig_nid; 4747 spec->multiout.dig_out_nid = dig_nid;
4685 else { 4748 else {
4686 spec->multiout.slave_dig_outs = spec->slave_dig_outs; 4749 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4687 spec->slave_dig_outs[i - 1] = dig_nid; 4750 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4688 if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4689 break; 4751 break;
4752 spec->slave_dig_outs[i - 1] = dig_nid;
4690 } 4753 }
4691 } 4754 }
4692 if (spec->autocfg.dig_in_pin) 4755 if (spec->autocfg.dig_in_pin)
@@ -4773,8 +4836,12 @@ static void set_capture_mixer(struct hda_codec *codec)
4773 } 4836 }
4774} 4837}
4775 4838
4839#ifdef CONFIG_SND_HDA_INPUT_BEEP
4776#define set_beep_amp(spec, nid, idx, dir) \ 4840#define set_beep_amp(spec, nid, idx, dir) \
4777 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir)) 4841 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4842#else
4843#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4844#endif
4778 4845
4779/* 4846/*
4780 * OK, here we have finally the patch for ALC880 4847 * OK, here we have finally the patch for ALC880
@@ -5087,11 +5154,8 @@ static struct hda_verb alc260_hp_unsol_verbs[] = {
5087static void alc260_hp_automute(struct hda_codec *codec) 5154static void alc260_hp_automute(struct hda_codec *codec)
5088{ 5155{
5089 struct alc_spec *spec = codec->spec; 5156 struct alc_spec *spec = codec->spec;
5090 unsigned int present;
5091 5157
5092 present = snd_hda_codec_read(codec, 0x10, 0, 5158 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); 5159 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5096} 5160}
5097 5161
@@ -5156,11 +5220,8 @@ static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5156static void alc260_hp_3013_automute(struct hda_codec *codec) 5220static void alc260_hp_3013_automute(struct hda_codec *codec)
5157{ 5221{
5158 struct alc_spec *spec = codec->spec; 5222 struct alc_spec *spec = codec->spec;
5159 unsigned int present;
5160 5223
5161 present = snd_hda_codec_read(codec, 0x15, 0, 5224 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); 5225 alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5165} 5226}
5166 5227
@@ -5173,12 +5234,8 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5173 5234
5174static void alc260_hp_3012_automute(struct hda_codec *codec) 5235static void alc260_hp_3012_automute(struct hda_codec *codec)
5175{ 5236{
5176 unsigned int present, bits; 5237 unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
5177
5178 present = snd_hda_codec_read(codec, 0x10, 0,
5179 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5180 5238
5181 bits = present ? 0 : PIN_OUT;
5182 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5239 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5183 bits); 5240 bits);
5184 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5241 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
@@ -5748,8 +5805,7 @@ static void alc260_replacer_672v_automute(struct hda_codec *codec)
5748 unsigned int present; 5805 unsigned int present;
5749 5806
5750 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */ 5807 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5751 present = snd_hda_codec_read(codec, 0x0f, 0, 5808 present = snd_hda_jack_detect(codec, 0x0f);
5752 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5753 if (present) { 5809 if (present) {
5754 snd_hda_codec_write_cache(codec, 0x01, 0, 5810 snd_hda_codec_write_cache(codec, 0x01, 0,
5755 AC_VERB_SET_GPIO_DATA, 1); 5811 AC_VERB_SET_GPIO_DATA, 1);
@@ -5989,7 +6045,6 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5989{ 6045{
5990 hda_nid_t nid_vol; 6046 hda_nid_t nid_vol;
5991 unsigned long vol_val, sw_val; 6047 unsigned long vol_val, sw_val;
5992 char name[32];
5993 int err; 6048 int err;
5994 6049
5995 if (nid >= 0x0f && nid < 0x11) { 6050 if (nid >= 0x0f && nid < 0x11) {
@@ -6009,14 +6064,12 @@ static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6009 6064
6010 if (!(*vol_bits & (1 << nid_vol))) { 6065 if (!(*vol_bits & (1 << nid_vol))) {
6011 /* first control for the volume widget */ 6066 /* first control for the volume widget */
6012 snprintf(name, sizeof(name), "%s Playback Volume", pfx); 6067 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) 6068 if (err < 0)
6015 return err; 6069 return err;
6016 *vol_bits |= (1 << nid_vol); 6070 *vol_bits |= (1 << nid_vol);
6017 } 6071 }
6018 snprintf(name, sizeof(name), "%s Playback Switch", pfx); 6072 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) 6073 if (err < 0)
6021 return err; 6074 return err;
6022 return 1; 6075 return 1;
@@ -6246,10 +6299,11 @@ static const char *alc260_models[ALC260_MODEL_LAST] = {
6246 6299
6247static struct snd_pci_quirk alc260_cfg_tbl[] = { 6300static struct snd_pci_quirk alc260_cfg_tbl[] = {
6248 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER), 6301 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6302 SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
6249 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER), 6303 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6250 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100), 6304 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6251 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013), 6305 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6252 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013), 6306 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
6253 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013), 6307 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6254 SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013), 6308 SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6255 SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600), 6309 SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
@@ -6619,7 +6673,7 @@ static struct hda_input_mux alc889A_mb31_capture_source = {
6619 /* Front Mic (0x01) unused */ 6673 /* Front Mic (0x01) unused */
6620 { "Line", 0x2 }, 6674 { "Line", 0x2 },
6621 /* Line 2 (0x03) unused */ 6675 /* Line 2 (0x03) unused */
6622 /* CD (0x04) unsused? */ 6676 /* CD (0x04) unused? */
6623 }, 6677 },
6624}; 6678};
6625 6679
@@ -7051,6 +7105,20 @@ static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7051 { } /* end */ 7105 { } /* end */
7052}; 7106};
7053 7107
7108static struct snd_kcontrol_new alc885_imac91_mixer[] = {
7109 HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7110 HDA_BIND_MUTE ("Line-Out Playback Switch", 0x0c, 0x02, HDA_INPUT),
7111 HDA_CODEC_MUTE ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
7112 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7113 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7114 HDA_CODEC_MUTE ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7115 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7116 HDA_CODEC_MUTE ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7117 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7118 { } /* end */
7119};
7120
7121
7054static struct snd_kcontrol_new alc882_w2jc_mixer[] = { 7122static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7055 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 7123 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7056 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 7124 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -7336,8 +7404,8 @@ static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7336 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT), 7404 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7337 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 7405 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7338 /* FIXME: this looks suspicious... 7406 /* FIXME: this looks suspicious...
7339 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT), 7407 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7340 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT), 7408 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7341 */ 7409 */
7342 { } /* end */ 7410 { } /* end */
7343}; 7411};
@@ -7506,6 +7574,66 @@ static struct hda_verb alc885_mbp3_init_verbs[] = {
7506 { } 7574 { }
7507}; 7575};
7508 7576
7577/* iMac 9,1 */
7578static struct hda_verb alc885_imac91_init_verbs[] = {
7579 /* Line-Out mixer: unmute input/output amp left and right (volume = 0) */
7580 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7581 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7582 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7583 /* Rear mixer */
7584 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7585 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7586 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7587 /* HP Pin: output 0 (0x0c) */
7588 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7589 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7590 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7591 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7592 /* Internal Speakers: output 0 (0x0d) */
7593 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7594 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7595 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7596 /* Mic (rear) pin: input vref at 80% */
7597 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7598 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7599 /* Front Mic pin: input vref at 80% */
7600 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7601 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7602 /* Line In pin: use output 1 when in LineOut mode */
7603 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7604 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7605 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7606
7607 /* FIXME: use matrix-type input source selection */
7608 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7609 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7610 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7611 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7612 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7613 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7614 /* Input mixer2 */
7615 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7616 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7617 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7618 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7619 /* Input mixer3 */
7620 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7621 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7622 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7623 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7624 /* ADC1: mute amp left and right */
7625 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7626 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7627 /* ADC2: mute amp left and right */
7628 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7629 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7630 /* ADC3: mute amp left and right */
7631 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7632 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7633
7634 { }
7635};
7636
7509/* iMac 24 mixer. */ 7637/* iMac 24 mixer. */
7510static struct snd_kcontrol_new alc885_imac24_mixer[] = { 7638static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7511 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT), 7639 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
@@ -7552,6 +7680,26 @@ static void alc885_mbp3_setup(struct hda_codec *codec)
7552 spec->autocfg.speaker_pins[0] = 0x14; 7680 spec->autocfg.speaker_pins[0] = 0x14;
7553} 7681}
7554 7682
7683static void alc885_imac91_automute(struct hda_codec *codec)
7684{
7685 unsigned int present;
7686
7687 present = snd_hda_codec_read(codec, 0x14, 0,
7688 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7689 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7690 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7691 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
7692 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7693
7694}
7695
7696static void alc885_imac91_unsol_event(struct hda_codec *codec,
7697 unsigned int res)
7698{
7699 /* Headphone insertion or removal. */
7700 if ((res >> 26) == ALC880_HP_EVENT)
7701 alc885_imac91_automute(codec);
7702}
7555 7703
7556static struct hda_verb alc882_targa_verbs[] = { 7704static struct hda_verb alc882_targa_verbs[] = {
7557 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7705 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -8184,12 +8332,8 @@ static void alc883_mitac_setup(struct hda_codec *codec)
8184/* 8332/*
8185static void alc883_mitac_mic_automute(struct hda_codec *codec) 8333static void alc883_mitac_mic_automute(struct hda_codec *codec)
8186{ 8334{
8187 unsigned int present; 8335 unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
8188 unsigned char bits;
8189 8336
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); 8337 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8194} 8338}
8195*/ 8339*/
@@ -8411,10 +8555,8 @@ static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8411/* toggle front-jack and RCA according to the hp-jack state */ 8555/* toggle front-jack and RCA according to the hp-jack state */
8412static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec) 8556static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8413{ 8557{
8414 unsigned int present; 8558 unsigned int present = snd_hda_jack_detect(codec, 0x1b);
8415 8559
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, 8560 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8419 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8561 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8420 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8562 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -8424,10 +8566,8 @@ static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8424/* toggle RCA according to the front-jack state */ 8566/* toggle RCA according to the front-jack state */
8425static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec) 8567static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8426{ 8568{
8427 unsigned int present; 8569 unsigned int present = snd_hda_jack_detect(codec, 0x14);
8428 8570
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, 8571 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8432 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8572 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8433} 8573}
@@ -8468,8 +8608,7 @@ static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8468{ 8608{
8469 unsigned int present; 8609 unsigned int present;
8470 8610
8471 present = snd_hda_codec_read(codec, 0x18, 0, 8611 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, 8612 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8474 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8613 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8475} 8614}
@@ -8520,24 +8659,16 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
8520 8659
8521static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 8660static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8522{ 8661{
8523 unsigned int present; 8662 int bits = snd_hda_jack_detect(codec, 0x14) ? HDA_AMP_MUTE : 0;
8524 unsigned char bits;
8525 8663
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, 8664 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8530 HDA_AMP_MUTE, bits); 8665 HDA_AMP_MUTE, bits);
8531} 8666}
8532 8667
8533static void alc883_lenovo_101e_all_automute(struct hda_codec *codec) 8668static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8534{ 8669{
8535 unsigned int present; 8670 int bits = snd_hda_jack_detect(codec, 0x1b) ? HDA_AMP_MUTE : 0;
8536 unsigned char bits;
8537 8671
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, 8672 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8542 HDA_AMP_MUTE, bits); 8673 HDA_AMP_MUTE, bits);
8543 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8674 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -8688,8 +8819,7 @@ static void alc889A_mb31_automute(struct hda_codec *codec)
8688 /* Mute only in 2ch or 4ch mode */ 8819 /* Mute only in 2ch or 4ch mode */
8689 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0) 8820 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8690 == 0x00) { 8821 == 0x00) {
8691 present = snd_hda_codec_read(codec, 0x15, 0, 8822 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, 8823 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8694 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8824 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8695 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 8825 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
@@ -8737,6 +8867,7 @@ static const char *alc882_models[ALC882_MODEL_LAST] = {
8737 [ALC885_MB5] = "mb5", 8867 [ALC885_MB5] = "mb5",
8738 [ALC885_MBP3] = "mbp3", 8868 [ALC885_MBP3] = "mbp3",
8739 [ALC885_IMAC24] = "imac24", 8869 [ALC885_IMAC24] = "imac24",
8870 [ALC885_IMAC91] = "imac91",
8740 [ALC883_3ST_2ch_DIG] = "3stack-2ch-dig", 8871 [ALC883_3ST_2ch_DIG] = "3stack-2ch-dig",
8741 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig", 8872 [ALC883_3ST_6ch_DIG] = "3stack-6ch-dig",
8742 [ALC883_3ST_6ch] = "3stack-6ch", 8873 [ALC883_3ST_6ch] = "3stack-6ch",
@@ -8839,7 +8970,7 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
8839 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 8970 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8840 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG), 8971 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8841 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */ 8972 SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8 */
8842 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG), 8973 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC882_AUTO),
8843 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG), 8974 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8844 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 8975 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8845 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG), 8976 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
@@ -8910,11 +9041,13 @@ static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8910 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31), 9041 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8911 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3), 9042 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8912 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24), 9043 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
9044 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC885_IMAC91),
8913 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5), 9045 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8914 /* FIXME: HP jack sense seems not working for MBP 5,1, so apparently 9046 /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
8915 * no perfect solution yet 9047 * so apparently no perfect solution yet
8916 */ 9048 */
8917 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5), 9049 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
9050 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
8918 {} /* terminator */ 9051 {} /* terminator */
8919}; 9052};
8920 9053
@@ -9020,6 +9153,20 @@ static struct alc_config_preset alc882_presets[] = {
9020 .setup = alc885_imac24_setup, 9153 .setup = alc885_imac24_setup,
9021 .init_hook = alc885_imac24_init_hook, 9154 .init_hook = alc885_imac24_init_hook,
9022 }, 9155 },
9156 [ALC885_IMAC91] = {
9157 .mixers = { alc885_imac91_mixer, alc882_chmode_mixer },
9158 .init_verbs = { alc885_imac91_init_verbs,
9159 alc880_gpio1_init_verbs },
9160 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9161 .dac_nids = alc882_dac_nids,
9162 .channel_mode = alc885_mbp_4ch_modes,
9163 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
9164 .input_mux = &alc882_capture_source,
9165 .dig_out_nid = ALC882_DIGOUT_NID,
9166 .dig_in_nid = ALC882_DIGIN_NID,
9167 .unsol_event = alc885_imac91_unsol_event,
9168 .init_hook = alc885_imac91_automute,
9169 },
9023 [ALC882_TARGA] = { 9170 [ALC882_TARGA] = {
9024 .mixers = { alc882_targa_mixer, alc882_chmode_mixer }, 9171 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9025 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs, 9172 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
@@ -9186,6 +9333,7 @@ static struct alc_config_preset alc882_presets[] = {
9186 .dac_nids = alc883_dac_nids, 9333 .dac_nids = alc883_dac_nids,
9187 .adc_nids = alc883_adc_nids_alt, 9334 .adc_nids = alc883_adc_nids_alt,
9188 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt), 9335 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9336 .capsrc_nids = alc883_capsrc_nids,
9189 .dig_out_nid = ALC883_DIGOUT_NID, 9337 .dig_out_nid = ALC883_DIGOUT_NID,
9190 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 9338 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9191 .channel_mode = alc883_3ST_2ch_modes, 9339 .channel_mode = alc883_3ST_2ch_modes,
@@ -9282,10 +9430,11 @@ static struct alc_config_preset alc882_presets[] = {
9282 .init_hook = alc_automute_amp, 9430 .init_hook = alc_automute_amp,
9283 }, 9431 },
9284 [ALC888_ACER_ASPIRE_8930G] = { 9432 [ALC888_ACER_ASPIRE_8930G] = {
9285 .mixers = { alc888_base_mixer, 9433 .mixers = { alc889_acer_aspire_8930g_mixer,
9286 alc883_chmode_mixer }, 9434 alc883_chmode_mixer },
9287 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs, 9435 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9288 alc889_acer_aspire_8930g_verbs }, 9436 alc889_acer_aspire_8930g_verbs,
9437 alc889_eapd_verbs},
9289 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9438 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9290 .dac_nids = alc883_dac_nids, 9439 .dac_nids = alc883_dac_nids,
9291 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids), 9440 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
@@ -9302,6 +9451,9 @@ static struct alc_config_preset alc882_presets[] = {
9302 .unsol_event = alc_automute_amp_unsol_event, 9451 .unsol_event = alc_automute_amp_unsol_event,
9303 .setup = alc889_acer_aspire_8930g_setup, 9452 .setup = alc889_acer_aspire_8930g_setup,
9304 .init_hook = alc_automute_amp, 9453 .init_hook = alc_automute_amp,
9454#ifdef CONFIG_SND_HDA_POWER_SAVE
9455 .power_hook = alc889_power_eapd,
9456#endif
9305 }, 9457 },
9306 [ALC888_ACER_ASPIRE_7730G] = { 9458 [ALC888_ACER_ASPIRE_7730G] = {
9307 .mixers = { alc883_3ST_6ch_mixer, 9459 .mixers = { alc883_3ST_6ch_mixer,
@@ -9332,6 +9484,7 @@ static struct alc_config_preset alc882_presets[] = {
9332 .dac_nids = alc883_dac_nids, 9484 .dac_nids = alc883_dac_nids,
9333 .adc_nids = alc883_adc_nids_alt, 9485 .adc_nids = alc883_adc_nids_alt,
9334 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt), 9486 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9487 .capsrc_nids = alc883_capsrc_nids,
9335 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 9488 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9336 .channel_mode = alc883_sixstack_modes, 9489 .channel_mode = alc883_sixstack_modes,
9337 .input_mux = &alc883_capture_source, 9490 .input_mux = &alc883_capture_source,
@@ -9393,6 +9546,7 @@ static struct alc_config_preset alc882_presets[] = {
9393 .dac_nids = alc883_dac_nids, 9546 .dac_nids = alc883_dac_nids,
9394 .adc_nids = alc883_adc_nids_alt, 9547 .adc_nids = alc883_adc_nids_alt,
9395 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt), 9548 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9549 .capsrc_nids = alc883_capsrc_nids,
9396 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 9550 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9397 .channel_mode = alc883_3ST_2ch_modes, 9551 .channel_mode = alc883_3ST_2ch_modes,
9398 .input_mux = &alc883_lenovo_101e_capture_source, 9552 .input_mux = &alc883_lenovo_101e_capture_source,
@@ -9572,6 +9726,7 @@ static struct alc_config_preset alc882_presets[] = {
9572 alc880_gpio1_init_verbs }, 9726 alc880_gpio1_init_verbs },
9573 .adc_nids = alc883_adc_nids, 9727 .adc_nids = alc883_adc_nids,
9574 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids), 9728 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9729 .capsrc_nids = alc883_capsrc_nids,
9575 .dac_nids = alc883_dac_nids, 9730 .dac_nids = alc883_dac_nids,
9576 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 9731 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9577 .channel_mode = alc889A_mb31_6ch_modes, 9732 .channel_mode = alc889A_mb31_6ch_modes,
@@ -9813,9 +9968,9 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
9813 spec->multiout.dig_out_nid = dig_nid; 9968 spec->multiout.dig_out_nid = dig_nid;
9814 else { 9969 else {
9815 spec->multiout.slave_dig_outs = spec->slave_dig_outs; 9970 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9816 spec->slave_dig_outs[i - 1] = dig_nid; 9971 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
9817 if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
9818 break; 9972 break;
9973 spec->slave_dig_outs[i - 1] = dig_nid;
9819 } 9974 }
9820 } 9975 }
9821 if (spec->autocfg.dig_in_pin) 9976 if (spec->autocfg.dig_in_pin)
@@ -9926,10 +10081,12 @@ static int patch_alc882(struct hda_codec *codec)
9926 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */ 10081 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9927 10082
9928 if (!spec->adc_nids && spec->input_mux) { 10083 if (!spec->adc_nids && spec->input_mux) {
9929 int i; 10084 int i, j;
9930 spec->num_adc_nids = 0; 10085 spec->num_adc_nids = 0;
9931 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) { 10086 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
10087 const struct hda_input_mux *imux = spec->input_mux;
9932 hda_nid_t cap; 10088 hda_nid_t cap;
10089 hda_nid_t items[16];
9933 hda_nid_t nid = alc882_adc_nids[i]; 10090 hda_nid_t nid = alc882_adc_nids[i];
9934 unsigned int wcap = get_wcaps(codec, nid); 10091 unsigned int wcap = get_wcaps(codec, nid);
9935 /* get type */ 10092 /* get type */
@@ -9940,6 +10097,15 @@ static int patch_alc882(struct hda_codec *codec)
9940 err = snd_hda_get_connections(codec, nid, &cap, 1); 10097 err = snd_hda_get_connections(codec, nid, &cap, 1);
9941 if (err < 0) 10098 if (err < 0)
9942 continue; 10099 continue;
10100 err = snd_hda_get_connections(codec, cap, items,
10101 ARRAY_SIZE(items));
10102 if (err < 0)
10103 continue;
10104 for (j = 0; j < imux->num_items; j++)
10105 if (imux->items[j].index >= err)
10106 break;
10107 if (j < imux->num_items)
10108 continue;
9943 spec->private_capsrc_nids[spec->num_adc_nids] = cap; 10109 spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9944 spec->num_adc_nids++; 10110 spec->num_adc_nids++;
9945 } 10111 }
@@ -10031,10 +10197,8 @@ static void alc262_hp_master_update(struct hda_codec *codec)
10031static void alc262_hp_bpc_automute(struct hda_codec *codec) 10197static void alc262_hp_bpc_automute(struct hda_codec *codec)
10032{ 10198{
10033 struct alc_spec *spec = codec->spec; 10199 struct alc_spec *spec = codec->spec;
10034 unsigned int presence; 10200
10035 presence = snd_hda_codec_read(codec, 0x1b, 0, 10201 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10036 AC_VERB_GET_PIN_SENSE, 0);
10037 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10038 alc262_hp_master_update(codec); 10202 alc262_hp_master_update(codec);
10039} 10203}
10040 10204
@@ -10048,10 +10212,8 @@ static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10048static void alc262_hp_wildwest_automute(struct hda_codec *codec) 10212static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10049{ 10213{
10050 struct alc_spec *spec = codec->spec; 10214 struct alc_spec *spec = codec->spec;
10051 unsigned int presence; 10215
10052 presence = snd_hda_codec_read(codec, 0x15, 0, 10216 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10053 AC_VERB_GET_PIN_SENSE, 0);
10054 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10055 alc262_hp_master_update(codec); 10217 alc262_hp_master_update(codec);
10056} 10218}
10057 10219
@@ -10285,13 +10447,8 @@ static void alc262_hippo_automute(struct hda_codec *codec)
10285{ 10447{
10286 struct alc_spec *spec = codec->spec; 10448 struct alc_spec *spec = codec->spec;
10287 hda_nid_t hp_nid = spec->autocfg.hp_pins[0]; 10449 hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10288 unsigned int present;
10289 10450
10290 /* need to execute and sync at first */ 10451 spec->jack_present = snd_hda_jack_detect(codec, hp_nid);
10291 snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10292 present = snd_hda_codec_read(codec, hp_nid, 0,
10293 AC_VERB_GET_PIN_SENSE, 0);
10294 spec->jack_present = (present & 0x80000000) != 0;
10295 alc262_hippo_master_update(codec); 10452 alc262_hippo_master_update(codec);
10296} 10453}
10297 10454
@@ -10580,6 +10737,13 @@ static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10580 {} 10737 {}
10581}; 10738};
10582 10739
10740static struct hda_verb alc262_lenovo_3000_init_verbs[] = {
10741 /* Front Mic pin: input vref at 50% */
10742 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10743 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10744 {}
10745};
10746
10583static struct hda_input_mux alc262_fujitsu_capture_source = { 10747static struct hda_input_mux alc262_fujitsu_capture_source = {
10584 .num_items = 3, 10748 .num_items = 3,
10585 .items = { 10749 .items = {
@@ -10617,21 +10781,8 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10617 unsigned int mute; 10781 unsigned int mute;
10618 10782
10619 if (force || !spec->sense_updated) { 10783 if (force || !spec->sense_updated) {
10620 unsigned int present; 10784 spec->jack_present = snd_hda_jack_detect(codec, 0x14) ||
10621 /* need to execute and sync at first */ 10785 snd_hda_jack_detect(codec, 0x1b);
10622 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10623 /* check laptop HP jack */
10624 present = snd_hda_codec_read(codec, 0x14, 0,
10625 AC_VERB_GET_PIN_SENSE, 0);
10626 /* need to execute and sync at first */
10627 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10628 /* check docking HP jack */
10629 present |= snd_hda_codec_read(codec, 0x1b, 0,
10630 AC_VERB_GET_PIN_SENSE, 0);
10631 if (present & AC_PINSENSE_PRESENCE)
10632 spec->jack_present = 1;
10633 else
10634 spec->jack_present = 0;
10635 spec->sense_updated = 1; 10786 spec->sense_updated = 1;
10636 } 10787 }
10637 /* unmute internal speaker only if both HPs are unplugged and 10788 /* unmute internal speaker only if both HPs are unplugged and
@@ -10676,12 +10827,7 @@ static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10676 unsigned int mute; 10827 unsigned int mute;
10677 10828
10678 if (force || !spec->sense_updated) { 10829 if (force || !spec->sense_updated) {
10679 unsigned int present_int_hp; 10830 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10680 /* need to execute and sync at first */
10681 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10682 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10683 AC_VERB_GET_PIN_SENSE, 0);
10684 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10685 spec->sense_updated = 1; 10831 spec->sense_updated = 1;
10686 } 10832 }
10687 if (spec->jack_present) { 10833 if (spec->jack_present) {
@@ -10873,12 +11019,7 @@ static void alc262_ultra_automute(struct hda_codec *codec)
10873 mute = 0; 11019 mute = 0;
10874 /* auto-mute only when HP is used as HP */ 11020 /* auto-mute only when HP is used as HP */
10875 if (!spec->cur_mux[0]) { 11021 if (!spec->cur_mux[0]) {
10876 unsigned int present; 11022 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10877 /* need to execute and sync at first */
10878 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10879 present = snd_hda_codec_read(codec, 0x15, 0,
10880 AC_VERB_GET_PIN_SENSE, 0);
10881 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10882 if (spec->jack_present) 11023 if (spec->jack_present)
10883 mute = HDA_AMP_MUTE; 11024 mute = HDA_AMP_MUTE;
10884 } 11025 }
@@ -10955,7 +11096,6 @@ static int alc262_check_volbit(hda_nid_t nid)
10955static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid, 11096static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10956 const char *pfx, int *vbits) 11097 const char *pfx, int *vbits)
10957{ 11098{
10958 char name[32];
10959 unsigned long val; 11099 unsigned long val;
10960 int vbit; 11100 int vbit;
10961 11101
@@ -10965,28 +11105,25 @@ static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10965 if (*vbits & vbit) /* a volume control for this mixer already there */ 11105 if (*vbits & vbit) /* a volume control for this mixer already there */
10966 return 0; 11106 return 0;
10967 *vbits |= vbit; 11107 *vbits |= vbit;
10968 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
10969 if (vbit == 2) 11108 if (vbit == 2)
10970 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT); 11109 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10971 else 11110 else
10972 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT); 11111 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10973 return add_control(spec, ALC_CTL_WIDGET_VOL, name, val); 11112 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10974} 11113}
10975 11114
10976static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid, 11115static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10977 const char *pfx) 11116 const char *pfx)
10978{ 11117{
10979 char name[32];
10980 unsigned long val; 11118 unsigned long val;
10981 11119
10982 if (!nid) 11120 if (!nid)
10983 return 0; 11121 return 0;
10984 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
10985 if (nid == 0x16) 11122 if (nid == 0x16)
10986 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT); 11123 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10987 else 11124 else
10988 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); 11125 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10989 return add_control(spec, ALC_CTL_WIDGET_MUTE, name, val); 11126 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10990} 11127}
10991 11128
10992/* add playback controls from the parsed DAC table */ 11129/* add playback controls from the parsed DAC table */
@@ -11460,8 +11597,12 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
11460 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD), 11597 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11461 SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */ 11598 SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11462 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06), 11599 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11600 SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11601 SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
11602#if 0 /* disable the quirk since model=auto works better in recent versions */
11463 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO", 11603 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11464 ALC262_SONY_ASSAMD), 11604 ALC262_SONY_ASSAMD),
11605#endif
11465 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 11606 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11466 ALC262_TOSHIBA_RX1), 11607 ALC262_TOSHIBA_RX1),
11467 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06), 11608 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
@@ -11645,7 +11786,8 @@ static struct alc_config_preset alc262_presets[] = {
11645 [ALC262_LENOVO_3000] = { 11786 [ALC262_LENOVO_3000] = {
11646 .mixers = { alc262_lenovo_3000_mixer }, 11787 .mixers = { alc262_lenovo_3000_mixer },
11647 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs, 11788 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11648 alc262_lenovo_3000_unsol_verbs }, 11789 alc262_lenovo_3000_unsol_verbs,
11790 alc262_lenovo_3000_init_verbs },
11649 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 11791 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11650 .dac_nids = alc262_dac_nids, 11792 .dac_nids = alc262_dac_nids,
11651 .hp_nid = 0x03, 11793 .hp_nid = 0x03,
@@ -11920,10 +12062,7 @@ static void alc268_acer_automute(struct hda_codec *codec, int force)
11920 unsigned int mute; 12062 unsigned int mute;
11921 12063
11922 if (force || !spec->sense_updated) { 12064 if (force || !spec->sense_updated) {
11923 unsigned int present; 12065 spec->jack_present = snd_hda_jack_detect(codec, 0x14);
11924 present = snd_hda_codec_read(codec, 0x14, 0,
11925 AC_VERB_GET_PIN_SENSE, 0);
11926 spec->jack_present = (present & 0x80000000) != 0;
11927 spec->sense_updated = 1; 12066 spec->sense_updated = 1;
11928 } 12067 }
11929 if (spec->jack_present) 12068 if (spec->jack_present)
@@ -12042,8 +12181,7 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12042 unsigned int present; 12181 unsigned int present;
12043 unsigned char bits; 12182 unsigned char bits;
12044 12183
12045 present = snd_hda_codec_read(codec, 0x15, 0, 12184 present = snd_hda_jack_detect(codec, 0x15);
12046 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12047 bits = present ? AMP_IN_MUTE(0) : 0; 12185 bits = present ? AMP_IN_MUTE(0) : 0;
12048 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0, 12186 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12049 AMP_IN_MUTE(0), bits); 12187 AMP_IN_MUTE(0), bits);
@@ -12324,11 +12462,9 @@ static struct snd_kcontrol_new alc268_test_mixer[] = {
12324static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid, 12462static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12325 const char *ctlname, int idx) 12463 const char *ctlname, int idx)
12326{ 12464{
12327 char name[32];
12328 hda_nid_t dac; 12465 hda_nid_t dac;
12329 int err; 12466 int err;
12330 12467
12331 sprintf(name, "%s Playback Volume", ctlname);
12332 switch (nid) { 12468 switch (nid) {
12333 case 0x14: 12469 case 0x14:
12334 case 0x16: 12470 case 0x16:
@@ -12342,7 +12478,7 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12342 } 12478 }
12343 if (spec->multiout.dac_nids[0] != dac && 12479 if (spec->multiout.dac_nids[0] != dac &&
12344 spec->multiout.dac_nids[1] != dac) { 12480 spec->multiout.dac_nids[1] != dac) {
12345 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, 12481 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12346 HDA_COMPOSE_AMP_VAL(dac, 3, idx, 12482 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12347 HDA_OUTPUT)); 12483 HDA_OUTPUT));
12348 if (err < 0) 12484 if (err < 0)
@@ -12350,12 +12486,11 @@ static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12350 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac; 12486 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12351 } 12487 }
12352 12488
12353 sprintf(name, "%s Playback Switch", ctlname);
12354 if (nid != 0x16) 12489 if (nid != 0x16)
12355 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12490 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12356 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT)); 12491 HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12357 else /* mono */ 12492 else /* mono */
12358 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, 12493 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12359 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT)); 12494 HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12360 if (err < 0) 12495 if (err < 0)
12361 return err; 12496 return err;
@@ -12385,8 +12520,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12385 12520
12386 nid = cfg->speaker_pins[0]; 12521 nid = cfg->speaker_pins[0];
12387 if (nid == 0x1d) { 12522 if (nid == 0x1d) {
12388 err = add_control(spec, ALC_CTL_WIDGET_VOL, 12523 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12389 "Speaker Playback Volume",
12390 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT)); 12524 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12391 if (err < 0) 12525 if (err < 0)
12392 return err; 12526 return err;
@@ -12404,8 +12538,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12404 12538
12405 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2]; 12539 nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12406 if (nid == 0x16) { 12540 if (nid == 0x16) {
12407 err = add_control(spec, ALC_CTL_WIDGET_MUTE, 12541 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12408 "Mono Playback Switch",
12409 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT)); 12542 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12410 if (err < 0) 12543 if (err < 0)
12411 return err; 12544 return err;
@@ -12791,7 +12924,7 @@ static int patch_alc268(struct hda_codec *codec)
12791 int board_config; 12924 int board_config;
12792 int i, has_beep, err; 12925 int i, has_beep, err;
12793 12926
12794 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 12927 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12795 if (spec == NULL) 12928 if (spec == NULL)
12796 return -ENOMEM; 12929 return -ENOMEM;
12797 12930
@@ -13031,8 +13164,7 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13031 unsigned int present; 13164 unsigned int present;
13032 unsigned char bits; 13165 unsigned char bits;
13033 13166
13034 present = snd_hda_codec_read(codec, 0x15, 0, 13167 present = snd_hda_jack_detect(codec, 0x15);
13035 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13036 bits = present ? AMP_IN_MUTE(0) : 0; 13168 bits = present ? AMP_IN_MUTE(0) : 0;
13037 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13169 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13038 AMP_IN_MUTE(0), bits); 13170 AMP_IN_MUTE(0), bits);
@@ -13057,12 +13189,10 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13057 unsigned char bits; 13189 unsigned char bits;
13058 13190
13059 /* Check laptop headphone socket */ 13191 /* Check laptop headphone socket */
13060 present = snd_hda_codec_read(codec, 0x15, 0, 13192 present = snd_hda_jack_detect(codec, 0x15);
13061 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13062 13193
13063 /* Check port replicator headphone socket */ 13194 /* Check port replicator headphone socket */
13064 present |= snd_hda_codec_read(codec, 0x1a, 0, 13195 present |= snd_hda_jack_detect(codec, 0x1a);
13065 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13066 13196
13067 bits = present ? AMP_IN_MUTE(0) : 0; 13197 bits = present ? AMP_IN_MUTE(0) : 0;
13068 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13198 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
@@ -13086,11 +13216,8 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13086 unsigned int present_laptop; 13216 unsigned int present_laptop;
13087 unsigned int present_dock; 13217 unsigned int present_dock;
13088 13218
13089 present_laptop = snd_hda_codec_read(codec, 0x18, 0, 13219 present_laptop = snd_hda_jack_detect(codec, 0x18);
13090 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 13220 present_dock = snd_hda_jack_detect(codec, 0x1b);
13091
13092 present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13093 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13094 13221
13095 /* Laptop mic port overrides dock mic port, design decision */ 13222 /* Laptop mic port overrides dock mic port, design decision */
13096 if (present_dock) 13223 if (present_dock)
@@ -13172,11 +13299,12 @@ static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13172/* toggle speaker-output according to the hp-jack state */ 13299/* toggle speaker-output according to the hp-jack state */
13173static void alc269_speaker_automute(struct hda_codec *codec) 13300static void alc269_speaker_automute(struct hda_codec *codec)
13174{ 13301{
13302 struct alc_spec *spec = codec->spec;
13303 unsigned int nid = spec->autocfg.hp_pins[0];
13175 unsigned int present; 13304 unsigned int present;
13176 unsigned char bits; 13305 unsigned char bits;
13177 13306
13178 present = snd_hda_codec_read(codec, 0x15, 0, 13307 present = snd_hda_jack_detect(codec, nid);
13179 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13180 bits = present ? AMP_IN_MUTE(0) : 0; 13308 bits = present ? AMP_IN_MUTE(0) : 0;
13181 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13309 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13182 AMP_IN_MUTE(0), bits); 13310 AMP_IN_MUTE(0), bits);
@@ -13401,8 +13529,8 @@ static void alc269_auto_init(struct hda_codec *codec)
13401static const char *alc269_models[ALC269_MODEL_LAST] = { 13529static const char *alc269_models[ALC269_MODEL_LAST] = {
13402 [ALC269_BASIC] = "basic", 13530 [ALC269_BASIC] = "basic",
13403 [ALC269_QUANTA_FL1] = "quanta", 13531 [ALC269_QUANTA_FL1] = "quanta",
13404 [ALC269_ASUS_EEEPC_P703] = "eeepc-p703", 13532 [ALC269_ASUS_AMIC] = "asus-amic",
13405 [ALC269_ASUS_EEEPC_P901] = "eeepc-p901", 13533 [ALC269_ASUS_DMIC] = "asus-dmic",
13406 [ALC269_FUJITSU] = "fujitsu", 13534 [ALC269_FUJITSU] = "fujitsu",
13407 [ALC269_LIFEBOOK] = "lifebook", 13535 [ALC269_LIFEBOOK] = "lifebook",
13408 [ALC269_AUTO] = "auto", 13536 [ALC269_AUTO] = "auto",
@@ -13411,18 +13539,41 @@ static const char *alc269_models[ALC269_MODEL_LAST] = {
13411static struct snd_pci_quirk alc269_cfg_tbl[] = { 13539static struct snd_pci_quirk alc269_cfg_tbl[] = {
13412 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1), 13540 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13413 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", 13541 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13414 ALC269_ASUS_EEEPC_P703), 13542 ALC269_ASUS_AMIC),
13415 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703), 13543 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_ASUS_AMIC),
13416 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703), 13544 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80JT", ALC269_ASUS_AMIC),
13417 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703), 13545 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_ASUS_AMIC),
13418 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703), 13546 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82Jv", ALC269_ASUS_AMIC),
13419 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703), 13547 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_ASUS_AMIC),
13420 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703), 13548 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_ASUS_AMIC),
13549 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_ASUS_AMIC),
13550 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_ASUS_AMIC),
13551 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_ASUS_AMIC),
13552 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_ASUS_AMIC),
13553 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_ASUS_AMIC),
13554 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_ASUS_AMIC),
13555 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_ASUS_AMIC),
13556 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_ASUS_AMIC),
13557 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_ASUS_AMIC),
13558 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_ASUS_AMIC),
13559 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_ASUS_AMIC),
13560 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_ASUS_AMIC),
13561 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_ASUS_AMIC),
13562 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_ASUS_AMIC),
13563 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_AMIC),
13564 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_ASUS_AMIC),
13565 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_AMIC),
13566 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_DMIC),
13567 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_AMIC),
13568 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_AMIC),
13569 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_AMIC),
13570 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_AMIC),
13421 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901", 13571 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13422 ALC269_ASUS_EEEPC_P901), 13572 ALC269_ASUS_DMIC),
13423 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101", 13573 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13424 ALC269_ASUS_EEEPC_P901), 13574 ALC269_ASUS_DMIC),
13425 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901), 13575 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005HA", ALC269_ASUS_DMIC),
13576 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005HA", ALC269_ASUS_DMIC),
13426 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU), 13577 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13427 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK), 13578 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13428 {} 13579 {}
@@ -13452,7 +13603,7 @@ static struct alc_config_preset alc269_presets[] = {
13452 .setup = alc269_quanta_fl1_setup, 13603 .setup = alc269_quanta_fl1_setup,
13453 .init_hook = alc269_quanta_fl1_init_hook, 13604 .init_hook = alc269_quanta_fl1_init_hook,
13454 }, 13605 },
13455 [ALC269_ASUS_EEEPC_P703] = { 13606 [ALC269_ASUS_AMIC] = {
13456 .mixers = { alc269_eeepc_mixer }, 13607 .mixers = { alc269_eeepc_mixer },
13457 .cap_mixer = alc269_epc_capture_mixer, 13608 .cap_mixer = alc269_epc_capture_mixer,
13458 .init_verbs = { alc269_init_verbs, 13609 .init_verbs = { alc269_init_verbs,
@@ -13466,7 +13617,7 @@ static struct alc_config_preset alc269_presets[] = {
13466 .setup = alc269_eeepc_amic_setup, 13617 .setup = alc269_eeepc_amic_setup,
13467 .init_hook = alc269_eeepc_inithook, 13618 .init_hook = alc269_eeepc_inithook,
13468 }, 13619 },
13469 [ALC269_ASUS_EEEPC_P901] = { 13620 [ALC269_ASUS_DMIC] = {
13470 .mixers = { alc269_eeepc_mixer }, 13621 .mixers = { alc269_eeepc_mixer },
13471 .cap_mixer = alc269_epc_capture_mixer, 13622 .cap_mixer = alc269_epc_capture_mixer,
13472 .init_verbs = { alc269_init_verbs, 13623 .init_verbs = { alc269_init_verbs,
@@ -13522,6 +13673,15 @@ static int patch_alc269(struct hda_codec *codec)
13522 13673
13523 alc_fix_pll_init(codec, 0x20, 0x04, 15); 13674 alc_fix_pll_init(codec, 0x20, 0x04, 15);
13524 13675
13676 if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010){
13677 kfree(codec->chip_name);
13678 codec->chip_name = kstrdup("ALC259", GFP_KERNEL);
13679 if (!codec->chip_name) {
13680 alc_free(codec);
13681 return -ENOMEM;
13682 }
13683 }
13684
13525 board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST, 13685 board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13526 alc269_models, 13686 alc269_models,
13527 alc269_cfg_tbl); 13687 alc269_cfg_tbl);
@@ -14154,10 +14314,8 @@ static struct hda_verb alc861_toshiba_init_verbs[] = {
14154/* toggle speaker-output according to the hp-jack state */ 14314/* toggle speaker-output according to the hp-jack state */
14155static void alc861_toshiba_automute(struct hda_codec *codec) 14315static void alc861_toshiba_automute(struct hda_codec *codec)
14156{ 14316{
14157 unsigned int present; 14317 unsigned int present = snd_hda_jack_detect(codec, 0x0f);
14158 14318
14159 present = snd_hda_codec_read(codec, 0x0f, 0,
14160 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14161 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0, 14319 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14162 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 14320 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14163 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3, 14321 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
@@ -14257,9 +14415,7 @@ static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14257static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx, 14415static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14258 hda_nid_t nid, unsigned int chs) 14416 hda_nid_t nid, unsigned int chs)
14259{ 14417{
14260 char name[32]; 14418 return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14261 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
14262 return add_control(codec->spec, ALC_CTL_WIDGET_MUTE, name,
14263 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 14419 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14264} 14420}
14265 14421
@@ -14624,6 +14780,27 @@ static struct alc_config_preset alc861_presets[] = {
14624 }, 14780 },
14625}; 14781};
14626 14782
14783/* Pin config fixes */
14784enum {
14785 PINFIX_FSC_AMILO_PI1505,
14786};
14787
14788static struct alc_pincfg alc861_fsc_amilo_pi1505_pinfix[] = {
14789 { 0x0b, 0x0221101f }, /* HP */
14790 { 0x0f, 0x90170310 }, /* speaker */
14791 { }
14792};
14793
14794static const struct alc_fixup alc861_fixups[] = {
14795 [PINFIX_FSC_AMILO_PI1505] = {
14796 .pins = alc861_fsc_amilo_pi1505_pinfix
14797 },
14798};
14799
14800static struct snd_pci_quirk alc861_fixup_tbl[] = {
14801 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
14802 {}
14803};
14627 14804
14628static int patch_alc861(struct hda_codec *codec) 14805static int patch_alc861(struct hda_codec *codec)
14629{ 14806{
@@ -14647,6 +14824,8 @@ static int patch_alc861(struct hda_codec *codec)
14647 board_config = ALC861_AUTO; 14824 board_config = ALC861_AUTO;
14648 } 14825 }
14649 14826
14827 alc_pick_fixup(codec, alc861_fixup_tbl, alc861_fixups);
14828
14650 if (board_config == ALC861_AUTO) { 14829 if (board_config == ALC861_AUTO) {
14651 /* automatic parse from the BIOS config */ 14830 /* automatic parse from the BIOS config */
14652 err = alc861_parse_auto_config(codec); 14831 err = alc861_parse_auto_config(codec);
@@ -15064,9 +15243,9 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15064 unsigned int present; 15243 unsigned int present;
15065 unsigned char bits; 15244 unsigned char bits;
15066 15245
15067 present = snd_hda_codec_read(codec, 0x18, 0, 15246 present = snd_hda_jack_detect(codec, 0x18);
15068 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15069 bits = present ? HDA_AMP_MUTE : 0; 15247 bits = present ? HDA_AMP_MUTE : 0;
15248
15070 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, 15249 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15071 HDA_AMP_MUTE, bits); 15250 HDA_AMP_MUTE, bits);
15072} 15251}
@@ -15383,7 +15562,6 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15383static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec, 15562static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15384 const struct auto_pin_cfg *cfg) 15563 const struct auto_pin_cfg *cfg)
15385{ 15564{
15386 char name[32];
15387 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"}; 15565 static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15388 hda_nid_t nid_v, nid_s; 15566 hda_nid_t nid_v, nid_s;
15389 int i, err; 15567 int i, err;
@@ -15400,26 +15578,26 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15400 15578
15401 if (i == 2) { 15579 if (i == 2) {
15402 /* Center/LFE */ 15580 /* Center/LFE */
15403 err = add_control(spec, ALC_CTL_WIDGET_VOL, 15581 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15404 "Center Playback Volume", 15582 "Center",
15405 HDA_COMPOSE_AMP_VAL(nid_v, 1, 0, 15583 HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15406 HDA_OUTPUT)); 15584 HDA_OUTPUT));
15407 if (err < 0) 15585 if (err < 0)
15408 return err; 15586 return err;
15409 err = add_control(spec, ALC_CTL_WIDGET_VOL, 15587 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15410 "LFE Playback Volume", 15588 "LFE",
15411 HDA_COMPOSE_AMP_VAL(nid_v, 2, 0, 15589 HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15412 HDA_OUTPUT)); 15590 HDA_OUTPUT));
15413 if (err < 0) 15591 if (err < 0)
15414 return err; 15592 return err;
15415 err = add_control(spec, ALC_CTL_BIND_MUTE, 15593 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15416 "Center Playback Switch", 15594 "Center",
15417 HDA_COMPOSE_AMP_VAL(nid_s, 1, 2, 15595 HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15418 HDA_INPUT)); 15596 HDA_INPUT));
15419 if (err < 0) 15597 if (err < 0)
15420 return err; 15598 return err;
15421 err = add_control(spec, ALC_CTL_BIND_MUTE, 15599 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15422 "LFE Playback Switch", 15600 "LFE",
15423 HDA_COMPOSE_AMP_VAL(nid_s, 2, 2, 15601 HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15424 HDA_INPUT)); 15602 HDA_INPUT));
15425 if (err < 0) 15603 if (err < 0)
@@ -15434,8 +15612,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15434 pfx = "PCM"; 15612 pfx = "PCM";
15435 } else 15613 } else
15436 pfx = chname[i]; 15614 pfx = chname[i];
15437 sprintf(name, "%s Playback Volume", pfx); 15615 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15438 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15439 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, 15616 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15440 HDA_OUTPUT)); 15617 HDA_OUTPUT));
15441 if (err < 0) 15618 if (err < 0)
@@ -15443,8 +15620,7 @@ static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15443 if (cfg->line_outs == 1 && 15620 if (cfg->line_outs == 1 &&
15444 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) 15621 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15445 pfx = "Speaker"; 15622 pfx = "Speaker";
15446 sprintf(name, "%s Playback Switch", pfx); 15623 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15447 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15448 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, 15624 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15449 HDA_INPUT)); 15625 HDA_INPUT));
15450 if (err < 0) 15626 if (err < 0)
@@ -15462,7 +15638,6 @@ static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15462{ 15638{
15463 hda_nid_t nid_v, nid_s; 15639 hda_nid_t nid_v, nid_s;
15464 int err; 15640 int err;
15465 char name[32];
15466 15641
15467 if (!pin) 15642 if (!pin)
15468 return 0; 15643 return 0;
@@ -15480,21 +15655,18 @@ static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15480 nid_s = alc861vd_idx_to_mixer_switch( 15655 nid_s = alc861vd_idx_to_mixer_switch(
15481 alc880_fixed_pin_idx(pin)); 15656 alc880_fixed_pin_idx(pin));
15482 15657
15483 sprintf(name, "%s Playback Volume", pfx); 15658 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15484 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15485 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT)); 15659 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15486 if (err < 0) 15660 if (err < 0)
15487 return err; 15661 return err;
15488 sprintf(name, "%s Playback Switch", pfx); 15662 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15489 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15490 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT)); 15663 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15491 if (err < 0) 15664 if (err < 0)
15492 return err; 15665 return err;
15493 } else if (alc880_is_multi_pin(pin)) { 15666 } else if (alc880_is_multi_pin(pin)) {
15494 /* set manual connection */ 15667 /* set manual connection */
15495 /* we have only a switch on HP-out PIN */ 15668 /* we have only a switch on HP-out PIN */
15496 sprintf(name, "%s Playback Switch", pfx); 15669 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15497 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15498 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 15670 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15499 if (err < 0) 15671 if (err < 0)
15500 return err; 15672 return err;
@@ -16080,6 +16252,52 @@ static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16080 { } /* end */ 16252 { } /* end */
16081}; 16253};
16082 16254
16255static struct hda_bind_ctls alc663_asus_mode7_8_all_bind_switch = {
16256 .ops = &snd_hda_bind_sw,
16257 .values = {
16258 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16259 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
16260 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
16261 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
16262 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
16263 0
16264 },
16265};
16266
16267static struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
16268 .ops = &snd_hda_bind_sw,
16269 .values = {
16270 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16271 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
16272 0
16273 },
16274};
16275
16276static struct snd_kcontrol_new alc663_mode7_mixer[] = {
16277 HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
16278 HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
16279 HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
16280 HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16281 HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16282 HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16283 HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16284 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16285 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16286 { } /* end */
16287};
16288
16289static struct snd_kcontrol_new alc663_mode8_mixer[] = {
16290 HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
16291 HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
16292 HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
16293 HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16294 HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16295 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16296 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16297 { } /* end */
16298};
16299
16300
16083static struct snd_kcontrol_new alc662_chmode_mixer[] = { 16301static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16084 { 16302 {
16085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 16303 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -16367,6 +16585,45 @@ static struct hda_verb alc272_dell_init_verbs[] = {
16367 {} 16585 {}
16368}; 16586};
16369 16587
16588static struct hda_verb alc663_mode7_init_verbs[] = {
16589 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16590 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16591 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16592 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16593 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16594 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16595 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
16596 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16597 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16598 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
16599 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16600 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16601 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16602 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16603 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16604 {}
16605};
16606
16607static struct hda_verb alc663_mode8_init_verbs[] = {
16608 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16609 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16610 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16611 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
16612 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16613 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16614 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16615 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16616 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16617 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16618 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
16619 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16620 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16621 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16622 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16623 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16624 {}
16625};
16626
16370static struct snd_kcontrol_new alc662_auto_capture_mixer[] = { 16627static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16371 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 16628 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16372 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT), 16629 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
@@ -16384,9 +16641,9 @@ static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16384 unsigned int present; 16641 unsigned int present;
16385 unsigned char bits; 16642 unsigned char bits;
16386 16643
16387 present = snd_hda_codec_read(codec, 0x14, 0, 16644 present = snd_hda_jack_detect(codec, 0x14);
16388 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16389 bits = present ? HDA_AMP_MUTE : 0; 16645 bits = present ? HDA_AMP_MUTE : 0;
16646
16390 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16647 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16391 HDA_AMP_MUTE, bits); 16648 HDA_AMP_MUTE, bits);
16392} 16649}
@@ -16396,9 +16653,9 @@ static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16396 unsigned int present; 16653 unsigned int present;
16397 unsigned char bits; 16654 unsigned char bits;
16398 16655
16399 present = snd_hda_codec_read(codec, 0x1b, 0, 16656 present = snd_hda_jack_detect(codec, 0x1b);
16400 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16401 bits = present ? HDA_AMP_MUTE : 0; 16657 bits = present ? HDA_AMP_MUTE : 0;
16658
16402 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16659 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16403 HDA_AMP_MUTE, bits); 16660 HDA_AMP_MUTE, bits);
16404 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 16661 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -16457,9 +16714,7 @@ static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16457 unsigned int present; 16714 unsigned int present;
16458 unsigned char bits; 16715 unsigned char bits;
16459 16716
16460 present = snd_hda_codec_read(codec, 0x21, 0, 16717 present = snd_hda_jack_detect(codec, 0x21);
16461 AC_VERB_GET_PIN_SENSE, 0)
16462 & AC_PINSENSE_PRESENCE;
16463 bits = present ? HDA_AMP_MUTE : 0; 16718 bits = present ? HDA_AMP_MUTE : 0;
16464 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16719 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16465 AMP_IN_MUTE(0), bits); 16720 AMP_IN_MUTE(0), bits);
@@ -16472,9 +16727,7 @@ static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16472 unsigned int present; 16727 unsigned int present;
16473 unsigned char bits; 16728 unsigned char bits;
16474 16729
16475 present = snd_hda_codec_read(codec, 0x21, 0, 16730 present = snd_hda_jack_detect(codec, 0x21);
16476 AC_VERB_GET_PIN_SENSE, 0)
16477 & AC_PINSENSE_PRESENCE;
16478 bits = present ? HDA_AMP_MUTE : 0; 16731 bits = present ? HDA_AMP_MUTE : 0;
16479 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16732 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16480 AMP_IN_MUTE(0), bits); 16733 AMP_IN_MUTE(0), bits);
@@ -16491,9 +16744,7 @@ static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16491 unsigned int present; 16744 unsigned int present;
16492 unsigned char bits; 16745 unsigned char bits;
16493 16746
16494 present = snd_hda_codec_read(codec, 0x15, 0, 16747 present = snd_hda_jack_detect(codec, 0x15);
16495 AC_VERB_GET_PIN_SENSE, 0)
16496 & AC_PINSENSE_PRESENCE;
16497 bits = present ? HDA_AMP_MUTE : 0; 16748 bits = present ? HDA_AMP_MUTE : 0;
16498 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16749 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16499 AMP_IN_MUTE(0), bits); 16750 AMP_IN_MUTE(0), bits);
@@ -16510,9 +16761,7 @@ static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16510 unsigned int present; 16761 unsigned int present;
16511 unsigned char bits; 16762 unsigned char bits;
16512 16763
16513 present = snd_hda_codec_read(codec, 0x1b, 0, 16764 present = snd_hda_jack_detect(codec, 0x1b);
16514 AC_VERB_GET_PIN_SENSE, 0)
16515 & AC_PINSENSE_PRESENCE;
16516 bits = present ? 0 : PIN_OUT; 16765 bits = present ? 0 : PIN_OUT;
16517 snd_hda_codec_write(codec, 0x14, 0, 16766 snd_hda_codec_write(codec, 0x14, 0,
16518 AC_VERB_SET_PIN_WIDGET_CONTROL, bits); 16767 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
@@ -16522,12 +16771,8 @@ static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16522{ 16771{
16523 unsigned int present1, present2; 16772 unsigned int present1, present2;
16524 16773
16525 present1 = snd_hda_codec_read(codec, 0x21, 0, 16774 present1 = snd_hda_jack_detect(codec, 0x21);
16526 AC_VERB_GET_PIN_SENSE, 0) 16775 present2 = snd_hda_jack_detect(codec, 0x15);
16527 & AC_PINSENSE_PRESENCE;
16528 present2 = snd_hda_codec_read(codec, 0x15, 0,
16529 AC_VERB_GET_PIN_SENSE, 0)
16530 & AC_PINSENSE_PRESENCE;
16531 16776
16532 if (present1 || present2) { 16777 if (present1 || present2) {
16533 snd_hda_codec_write_cache(codec, 0x14, 0, 16778 snd_hda_codec_write_cache(codec, 0x14, 0,
@@ -16542,12 +16787,8 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16542{ 16787{
16543 unsigned int present1, present2; 16788 unsigned int present1, present2;
16544 16789
16545 present1 = snd_hda_codec_read(codec, 0x1b, 0, 16790 present1 = snd_hda_jack_detect(codec, 0x1b);
16546 AC_VERB_GET_PIN_SENSE, 0) 16791 present2 = snd_hda_jack_detect(codec, 0x15);
16547 & AC_PINSENSE_PRESENCE;
16548 present2 = snd_hda_codec_read(codec, 0x15, 0,
16549 AC_VERB_GET_PIN_SENSE, 0)
16550 & AC_PINSENSE_PRESENCE;
16551 16792
16552 if (present1 || present2) { 16793 if (present1 || present2) {
16553 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16794 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
@@ -16562,6 +16803,54 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16562 } 16803 }
16563} 16804}
16564 16805
16806static void alc663_two_hp_m7_speaker_automute(struct hda_codec *codec)
16807{
16808 unsigned int present1, present2;
16809
16810 present1 = snd_hda_codec_read(codec, 0x1b, 0,
16811 AC_VERB_GET_PIN_SENSE, 0)
16812 & AC_PINSENSE_PRESENCE;
16813 present2 = snd_hda_codec_read(codec, 0x21, 0,
16814 AC_VERB_GET_PIN_SENSE, 0)
16815 & AC_PINSENSE_PRESENCE;
16816
16817 if (present1 || present2) {
16818 snd_hda_codec_write_cache(codec, 0x14, 0,
16819 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16820 snd_hda_codec_write_cache(codec, 0x17, 0,
16821 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16822 } else {
16823 snd_hda_codec_write_cache(codec, 0x14, 0,
16824 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16825 snd_hda_codec_write_cache(codec, 0x17, 0,
16826 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16827 }
16828}
16829
16830static void alc663_two_hp_m8_speaker_automute(struct hda_codec *codec)
16831{
16832 unsigned int present1, present2;
16833
16834 present1 = snd_hda_codec_read(codec, 0x21, 0,
16835 AC_VERB_GET_PIN_SENSE, 0)
16836 & AC_PINSENSE_PRESENCE;
16837 present2 = snd_hda_codec_read(codec, 0x15, 0,
16838 AC_VERB_GET_PIN_SENSE, 0)
16839 & AC_PINSENSE_PRESENCE;
16840
16841 if (present1 || present2) {
16842 snd_hda_codec_write_cache(codec, 0x14, 0,
16843 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16844 snd_hda_codec_write_cache(codec, 0x17, 0,
16845 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16846 } else {
16847 snd_hda_codec_write_cache(codec, 0x14, 0,
16848 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16849 snd_hda_codec_write_cache(codec, 0x17, 0,
16850 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16851 }
16852}
16853
16565static void alc663_m51va_unsol_event(struct hda_codec *codec, 16854static void alc663_m51va_unsol_event(struct hda_codec *codec,
16566 unsigned int res) 16855 unsigned int res)
16567{ 16856{
@@ -16581,7 +16870,7 @@ static void alc663_m51va_setup(struct hda_codec *codec)
16581 spec->ext_mic.pin = 0x18; 16870 spec->ext_mic.pin = 0x18;
16582 spec->ext_mic.mux_idx = 0; 16871 spec->ext_mic.mux_idx = 0;
16583 spec->int_mic.pin = 0x12; 16872 spec->int_mic.pin = 0x12;
16584 spec->int_mic.mux_idx = 1; 16873 spec->int_mic.mux_idx = 9;
16585 spec->auto_mic = 1; 16874 spec->auto_mic = 1;
16586} 16875}
16587 16876
@@ -16593,7 +16882,17 @@ static void alc663_m51va_inithook(struct hda_codec *codec)
16593 16882
16594/* ***************** Mode1 ******************************/ 16883/* ***************** Mode1 ******************************/
16595#define alc663_mode1_unsol_event alc663_m51va_unsol_event 16884#define alc663_mode1_unsol_event alc663_m51va_unsol_event
16596#define alc663_mode1_setup alc663_m51va_setup 16885
16886static void alc663_mode1_setup(struct hda_codec *codec)
16887{
16888 struct alc_spec *spec = codec->spec;
16889 spec->ext_mic.pin = 0x18;
16890 spec->ext_mic.mux_idx = 0;
16891 spec->int_mic.pin = 0x19;
16892 spec->int_mic.mux_idx = 1;
16893 spec->auto_mic = 1;
16894}
16895
16597#define alc663_mode1_inithook alc663_m51va_inithook 16896#define alc663_mode1_inithook alc663_m51va_inithook
16598 16897
16599/* ***************** Mode2 ******************************/ 16898/* ***************** Mode2 ******************************/
@@ -16610,7 +16909,7 @@ static void alc662_mode2_unsol_event(struct hda_codec *codec,
16610 } 16909 }
16611} 16910}
16612 16911
16613#define alc662_mode2_setup alc663_m51va_setup 16912#define alc662_mode2_setup alc663_mode1_setup
16614 16913
16615static void alc662_mode2_inithook(struct hda_codec *codec) 16914static void alc662_mode2_inithook(struct hda_codec *codec)
16616{ 16915{
@@ -16631,7 +16930,7 @@ static void alc663_mode3_unsol_event(struct hda_codec *codec,
16631 } 16930 }
16632} 16931}
16633 16932
16634#define alc663_mode3_setup alc663_m51va_setup 16933#define alc663_mode3_setup alc663_mode1_setup
16635 16934
16636static void alc663_mode3_inithook(struct hda_codec *codec) 16935static void alc663_mode3_inithook(struct hda_codec *codec)
16637{ 16936{
@@ -16652,7 +16951,7 @@ static void alc663_mode4_unsol_event(struct hda_codec *codec,
16652 } 16951 }
16653} 16952}
16654 16953
16655#define alc663_mode4_setup alc663_m51va_setup 16954#define alc663_mode4_setup alc663_mode1_setup
16656 16955
16657static void alc663_mode4_inithook(struct hda_codec *codec) 16956static void alc663_mode4_inithook(struct hda_codec *codec)
16658{ 16957{
@@ -16673,7 +16972,7 @@ static void alc663_mode5_unsol_event(struct hda_codec *codec,
16673 } 16972 }
16674} 16973}
16675 16974
16676#define alc663_mode5_setup alc663_m51va_setup 16975#define alc663_mode5_setup alc663_mode1_setup
16677 16976
16678static void alc663_mode5_inithook(struct hda_codec *codec) 16977static void alc663_mode5_inithook(struct hda_codec *codec)
16679{ 16978{
@@ -16694,7 +16993,7 @@ static void alc663_mode6_unsol_event(struct hda_codec *codec,
16694 } 16993 }
16695} 16994}
16696 16995
16697#define alc663_mode6_setup alc663_m51va_setup 16996#define alc663_mode6_setup alc663_mode1_setup
16698 16997
16699static void alc663_mode6_inithook(struct hda_codec *codec) 16998static void alc663_mode6_inithook(struct hda_codec *codec)
16700{ 16999{
@@ -16702,14 +17001,56 @@ static void alc663_mode6_inithook(struct hda_codec *codec)
16702 alc_mic_automute(codec); 17001 alc_mic_automute(codec);
16703} 17002}
16704 17003
17004/* ***************** Mode7 ******************************/
17005static void alc663_mode7_unsol_event(struct hda_codec *codec,
17006 unsigned int res)
17007{
17008 switch (res >> 26) {
17009 case ALC880_HP_EVENT:
17010 alc663_two_hp_m7_speaker_automute(codec);
17011 break;
17012 case ALC880_MIC_EVENT:
17013 alc_mic_automute(codec);
17014 break;
17015 }
17016}
17017
17018#define alc663_mode7_setup alc663_mode1_setup
17019
17020static void alc663_mode7_inithook(struct hda_codec *codec)
17021{
17022 alc663_two_hp_m7_speaker_automute(codec);
17023 alc_mic_automute(codec);
17024}
17025
17026/* ***************** Mode8 ******************************/
17027static void alc663_mode8_unsol_event(struct hda_codec *codec,
17028 unsigned int res)
17029{
17030 switch (res >> 26) {
17031 case ALC880_HP_EVENT:
17032 alc663_two_hp_m8_speaker_automute(codec);
17033 break;
17034 case ALC880_MIC_EVENT:
17035 alc_mic_automute(codec);
17036 break;
17037 }
17038}
17039
17040#define alc663_mode8_setup alc663_m51va_setup
17041
17042static void alc663_mode8_inithook(struct hda_codec *codec)
17043{
17044 alc663_two_hp_m8_speaker_automute(codec);
17045 alc_mic_automute(codec);
17046}
17047
16705static void alc663_g71v_hp_automute(struct hda_codec *codec) 17048static void alc663_g71v_hp_automute(struct hda_codec *codec)
16706{ 17049{
16707 unsigned int present; 17050 unsigned int present;
16708 unsigned char bits; 17051 unsigned char bits;
16709 17052
16710 present = snd_hda_codec_read(codec, 0x21, 0, 17053 present = snd_hda_jack_detect(codec, 0x21);
16711 AC_VERB_GET_PIN_SENSE, 0)
16712 & AC_PINSENSE_PRESENCE;
16713 bits = present ? HDA_AMP_MUTE : 0; 17054 bits = present ? HDA_AMP_MUTE : 0;
16714 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 17055 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16715 HDA_AMP_MUTE, bits); 17056 HDA_AMP_MUTE, bits);
@@ -16722,9 +17063,7 @@ static void alc663_g71v_front_automute(struct hda_codec *codec)
16722 unsigned int present; 17063 unsigned int present;
16723 unsigned char bits; 17064 unsigned char bits;
16724 17065
16725 present = snd_hda_codec_read(codec, 0x15, 0, 17066 present = snd_hda_jack_detect(codec, 0x15);
16726 AC_VERB_GET_PIN_SENSE, 0)
16727 & AC_PINSENSE_PRESENCE;
16728 bits = present ? HDA_AMP_MUTE : 0; 17067 bits = present ? HDA_AMP_MUTE : 0;
16729 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 17068 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16730 HDA_AMP_MUTE, bits); 17069 HDA_AMP_MUTE, bits);
@@ -16840,6 +17179,8 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
16840 [ALC663_ASUS_MODE4] = "asus-mode4", 17179 [ALC663_ASUS_MODE4] = "asus-mode4",
16841 [ALC663_ASUS_MODE5] = "asus-mode5", 17180 [ALC663_ASUS_MODE5] = "asus-mode5",
16842 [ALC663_ASUS_MODE6] = "asus-mode6", 17181 [ALC663_ASUS_MODE6] = "asus-mode6",
17182 [ALC663_ASUS_MODE7] = "asus-mode7",
17183 [ALC663_ASUS_MODE8] = "asus-mode8",
16843 [ALC272_DELL] = "dell", 17184 [ALC272_DELL] = "dell",
16844 [ALC272_DELL_ZM1] = "dell-zm1", 17185 [ALC272_DELL_ZM1] = "dell-zm1",
16845 [ALC272_SAMSUNG_NC10] = "samsung-nc10", 17186 [ALC272_SAMSUNG_NC10] = "samsung-nc10",
@@ -16856,12 +17197,22 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16856 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1), 17197 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16857 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2), 17198 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16858 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1), 17199 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
17200 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
17201 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
16859 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2), 17202 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
17203 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
17204 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
17205 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
17206 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
17207 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
16860 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2), 17208 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
17209 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
17210 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
16861 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2), 17211 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16862 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6), 17212 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16863 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6), 17213 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16864 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2), 17214 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
17215 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
16865 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3), 17216 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16866 SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA), 17217 SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16867 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2), 17218 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
@@ -16911,6 +17262,7 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16911 ALC662_3ST_6ch_DIG), 17262 ALC662_3ST_6ch_DIG),
16912 SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x", 17263 SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16913 ALC663_ASUS_H13), 17264 ALC663_ASUS_H13),
17265 SND_PCI_QUIRK(0x8086, 0xd604, "Intel mobo", ALC662_3ST_2ch_DIG),
16914 {} 17266 {}
16915}; 17267};
16916 17268
@@ -17144,6 +17496,36 @@ static struct alc_config_preset alc662_presets[] = {
17144 .setup = alc663_mode6_setup, 17496 .setup = alc663_mode6_setup,
17145 .init_hook = alc663_mode6_inithook, 17497 .init_hook = alc663_mode6_inithook,
17146 }, 17498 },
17499 [ALC663_ASUS_MODE7] = {
17500 .mixers = { alc663_mode7_mixer },
17501 .cap_mixer = alc662_auto_capture_mixer,
17502 .init_verbs = { alc662_init_verbs,
17503 alc663_mode7_init_verbs },
17504 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17505 .hp_nid = 0x03,
17506 .dac_nids = alc662_dac_nids,
17507 .dig_out_nid = ALC662_DIGOUT_NID,
17508 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17509 .channel_mode = alc662_3ST_2ch_modes,
17510 .unsol_event = alc663_mode7_unsol_event,
17511 .setup = alc663_mode7_setup,
17512 .init_hook = alc663_mode7_inithook,
17513 },
17514 [ALC663_ASUS_MODE8] = {
17515 .mixers = { alc663_mode8_mixer },
17516 .cap_mixer = alc662_auto_capture_mixer,
17517 .init_verbs = { alc662_init_verbs,
17518 alc663_mode8_init_verbs },
17519 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17520 .hp_nid = 0x03,
17521 .dac_nids = alc662_dac_nids,
17522 .dig_out_nid = ALC662_DIGOUT_NID,
17523 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17524 .channel_mode = alc662_3ST_2ch_modes,
17525 .unsol_event = alc663_mode8_unsol_event,
17526 .setup = alc663_mode8_setup,
17527 .init_hook = alc663_mode8_inithook,
17528 },
17147 [ALC272_DELL] = { 17529 [ALC272_DELL] = {
17148 .mixers = { alc663_m51va_mixer }, 17530 .mixers = { alc663_m51va_mixer },
17149 .cap_mixer = alc272_auto_capture_mixer, 17531 .cap_mixer = alc272_auto_capture_mixer,
@@ -17261,21 +17643,17 @@ static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17261 return 0; 17643 return 0;
17262} 17644}
17263 17645
17264static int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx, 17646static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17265 hda_nid_t nid, unsigned int chs) 17647 hda_nid_t nid, unsigned int chs)
17266{ 17648{
17267 char name[32]; 17649 return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17268 sprintf(name, "%s Playback Volume", pfx);
17269 return add_control(spec, ALC_CTL_WIDGET_VOL, name,
17270 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 17650 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17271} 17651}
17272 17652
17273static int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx, 17653static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17274 hda_nid_t nid, unsigned int chs) 17654 hda_nid_t nid, unsigned int chs)
17275{ 17655{
17276 char name[32]; 17656 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17277 sprintf(name, "%s Playback Switch", pfx);
17278 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17279 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT)); 17657 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17280} 17658}
17281 17659
@@ -17353,13 +17731,11 @@ static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17353 return 0; 17731 return 0;
17354 nid = alc662_look_for_dac(codec, pin); 17732 nid = alc662_look_for_dac(codec, pin);
17355 if (!nid) { 17733 if (!nid) {
17356 char name[32];
17357 /* the corresponding DAC is already occupied */ 17734 /* the corresponding DAC is already occupied */
17358 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) 17735 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17359 return 0; /* no way */ 17736 return 0; /* no way */
17360 /* create a switch only */ 17737 /* create a switch only */
17361 sprintf(name, "%s Playback Switch", pfx); 17738 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17362 return add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17363 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 17739 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17364 } 17740 }
17365 17741
@@ -17535,6 +17911,15 @@ static int patch_alc662(struct hda_codec *codec)
17535 17911
17536 alc_fix_pll_init(codec, 0x20, 0x04, 15); 17912 alc_fix_pll_init(codec, 0x20, 0x04, 15);
17537 17913
17914 if (alc_read_coef_idx(codec, 0)==0x8020){
17915 kfree(codec->chip_name);
17916 codec->chip_name = kstrdup("ALC661", GFP_KERNEL);
17917 if (!codec->chip_name) {
17918 alc_free(codec);
17919 return -ENOMEM;
17920 }
17921 }
17922
17538 board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST, 17923 board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17539 alc662_models, 17924 alc662_models,
17540 alc662_cfg_tbl); 17925 alc662_cfg_tbl);
@@ -17601,6 +17986,20 @@ static int patch_alc662(struct hda_codec *codec)
17601 return 0; 17986 return 0;
17602} 17987}
17603 17988
17989static int patch_alc888(struct hda_codec *codec)
17990{
17991 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
17992 kfree(codec->chip_name);
17993 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
17994 if (!codec->chip_name) {
17995 alc_free(codec);
17996 return -ENOMEM;
17997 }
17998 return patch_alc662(codec);
17999 }
18000 return patch_alc882(codec);
18001}
18002
17604/* 18003/*
17605 * patch entries 18004 * patch entries
17606 */ 18005 */
@@ -17610,7 +18009,9 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17610 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 }, 18009 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17611 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 }, 18010 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17612 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 }, 18011 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
18012 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
17613 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 }, 18013 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
18014 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
17614 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660", 18015 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17615 .patch = patch_alc861 }, 18016 .patch = patch_alc861 },
17616 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd }, 18017 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
@@ -17632,8 +18033,9 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
17632 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 }, 18033 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17633 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 18034 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17634 .patch = patch_alc882 }, 18035 .patch = patch_alc882 },
17635 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 }, 18036 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
17636 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, 18037 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
18038 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
17637 {} /* terminator */ 18039 {} /* terminator */
17638}; 18040};
17639 18041
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 66c0876bf734..eeda7beeb57a 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -28,6 +28,7 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/dmi.h>
31#include <sound/core.h> 32#include <sound/core.h>
32#include <sound/asoundef.h> 33#include <sound/asoundef.h>
33#include <sound/jack.h> 34#include <sound/jack.h>
@@ -92,6 +93,7 @@ enum {
92 STAC_92HD83XXX_REF, 93 STAC_92HD83XXX_REF,
93 STAC_92HD83XXX_PWR_REF, 94 STAC_92HD83XXX_PWR_REF,
94 STAC_DELL_S14, 95 STAC_DELL_S14,
96 STAC_92HD83XXX_HP,
95 STAC_92HD83XXX_MODELS 97 STAC_92HD83XXX_MODELS
96}; 98};
97 99
@@ -207,6 +209,7 @@ struct sigmatel_spec {
207 unsigned int gpio_data; 209 unsigned int gpio_data;
208 unsigned int gpio_mute; 210 unsigned int gpio_mute;
209 unsigned int gpio_led; 211 unsigned int gpio_led;
212 unsigned int gpio_led_polarity;
210 213
211 /* stream */ 214 /* stream */
212 unsigned int stream_delay; 215 unsigned int stream_delay;
@@ -1084,7 +1087,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1084 if (!spec->auto_mic && spec->num_dmuxes > 0 && 1087 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1085 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) { 1088 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
1086 stac_dmux_mixer.count = spec->num_dmuxes; 1089 stac_dmux_mixer.count = spec->num_dmuxes;
1087 err = snd_hda_ctl_add(codec, 1090 err = snd_hda_ctl_add(codec, 0,
1088 snd_ctl_new1(&stac_dmux_mixer, codec)); 1091 snd_ctl_new1(&stac_dmux_mixer, codec));
1089 if (err < 0) 1092 if (err < 0)
1090 return err; 1093 return err;
@@ -1100,7 +1103,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1100 spec->spdif_mute = 1; 1103 spec->spdif_mute = 1;
1101 } 1104 }
1102 stac_smux_mixer.count = spec->num_smuxes; 1105 stac_smux_mixer.count = spec->num_smuxes;
1103 err = snd_hda_ctl_add(codec, 1106 err = snd_hda_ctl_add(codec, 0,
1104 snd_ctl_new1(&stac_smux_mixer, codec)); 1107 snd_ctl_new1(&stac_smux_mixer, codec));
1105 if (err < 0) 1108 if (err < 0)
1106 return err; 1109 return err;
@@ -1536,6 +1539,13 @@ static unsigned int alienware_m17x_pin_configs[13] = {
1536 0x904601b0, 1539 0x904601b0,
1537}; 1540};
1538 1541
1542static unsigned int intel_dg45id_pin_configs[14] = {
1543 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
1544 0x01A19250, 0x01011212, 0x01016211, 0x40f000f0,
1545 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x014510A0,
1546 0x074510B0, 0x40f000f0
1547};
1548
1539static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1549static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1540 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1550 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1541 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs, 1551 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
@@ -1543,6 +1553,7 @@ static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1543 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs, 1553 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
1544 [STAC_DELL_EQ] = dell_m6_pin_configs, 1554 [STAC_DELL_EQ] = dell_m6_pin_configs,
1545 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs, 1555 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
1556 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
1546}; 1557};
1547 1558
1548static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1559static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
@@ -1589,6 +1600,8 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1589 "Dell Studio 17", STAC_DELL_M6_DMIC), 1600 "Dell Studio 17", STAC_DELL_M6_DMIC),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be, 1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1591 "Dell Studio 1555", STAC_DELL_M6_DMIC), 1602 "Dell Studio 1555", STAC_DELL_M6_DMIC),
1603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1604 "Dell Studio 1557", STAC_DELL_M6_DMIC),
1592 {} /* terminator */ 1605 {} /* terminator */
1593}; 1606};
1594 1607
@@ -1621,6 +1634,7 @@ static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1621 [STAC_92HD83XXX_REF] = "ref", 1634 [STAC_92HD83XXX_REF] = "ref",
1622 [STAC_92HD83XXX_PWR_REF] = "mic-ref", 1635 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1623 [STAC_DELL_S14] = "dell-s14", 1636 [STAC_DELL_S14] = "dell-s14",
1637 [STAC_92HD83XXX_HP] = "hp",
1624}; 1638};
1625 1639
1626static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { 1640static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
@@ -1631,6 +1645,8 @@ static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1631 "DFI LanParty", STAC_92HD83XXX_REF), 1645 "DFI LanParty", STAC_92HD83XXX_REF),
1632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba, 1646 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1633 "unknown Dell", STAC_DELL_S14), 1647 "unknown Dell", STAC_DELL_S14),
1648 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1649 "HP", STAC_92HD83XXX_HP),
1634 {} /* terminator */ 1650 {} /* terminator */
1635}; 1651};
1636 1652
@@ -1693,6 +1709,8 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1693 "DFI LanParty", STAC_92HD71BXX_REF), 1709 "DFI LanParty", STAC_92HD71BXX_REF),
1694 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb, 1710 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1695 "HP dv4-1222nr", STAC_HP_DV4_1222NR), 1711 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
1712 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1713 "HP", STAC_HP_DV5),
1696 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080, 1714 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1697 "HP", STAC_HP_DV5), 1715 "HP", STAC_HP_DV5),
1698 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0, 1716 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
@@ -2086,6 +2104,7 @@ static unsigned int ref9205_pin_configs[12] = {
2086 10280204 2104 10280204
2087 1028021F 2105 1028021F
2088 10280228 (Dell Vostro 1500) 2106 10280228 (Dell Vostro 1500)
2107 10280229 (Dell Vostro 1700)
2089*/ 2108*/
2090static unsigned int dell_9205_m42_pin_configs[12] = { 2109static unsigned int dell_9205_m42_pin_configs[12] = {
2091 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310, 2110 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
@@ -2171,6 +2190,8 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2171 "Dell Inspiron", STAC_9205_DELL_M44), 2190 "Dell Inspiron", STAC_9205_DELL_M44),
2172 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228, 2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2173 "Dell Vostro 1500", STAC_9205_DELL_M42), 2192 "Dell Vostro 1500", STAC_9205_DELL_M42),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2194 "Dell Vostro 1700", STAC_9205_DELL_M42),
2174 /* Gateway */ 2195 /* Gateway */
2175 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD), 2196 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
2176 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD), 2197 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
@@ -2643,6 +2664,7 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2643enum { 2664enum {
2644 STAC_CTL_WIDGET_VOL, 2665 STAC_CTL_WIDGET_VOL,
2645 STAC_CTL_WIDGET_MUTE, 2666 STAC_CTL_WIDGET_MUTE,
2667 STAC_CTL_WIDGET_MUTE_BEEP,
2646 STAC_CTL_WIDGET_MONO_MUX, 2668 STAC_CTL_WIDGET_MONO_MUX,
2647 STAC_CTL_WIDGET_HP_SWITCH, 2669 STAC_CTL_WIDGET_HP_SWITCH,
2648 STAC_CTL_WIDGET_IO_SWITCH, 2670 STAC_CTL_WIDGET_IO_SWITCH,
@@ -2653,6 +2675,7 @@ enum {
2653static struct snd_kcontrol_new stac92xx_control_templates[] = { 2675static struct snd_kcontrol_new stac92xx_control_templates[] = {
2654 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2676 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2655 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2677 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2678 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
2656 STAC_MONO_MUX, 2679 STAC_MONO_MUX,
2657 STAC_CODEC_HP_SWITCH(NULL), 2680 STAC_CODEC_HP_SWITCH(NULL),
2658 STAC_CODEC_IO_SWITCH(NULL, 0), 2681 STAC_CODEC_IO_SWITCH(NULL, 0),
@@ -2664,7 +2687,8 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2664static struct snd_kcontrol_new * 2687static struct snd_kcontrol_new *
2665stac_control_new(struct sigmatel_spec *spec, 2688stac_control_new(struct sigmatel_spec *spec,
2666 struct snd_kcontrol_new *ktemp, 2689 struct snd_kcontrol_new *ktemp,
2667 const char *name) 2690 const char *name,
2691 hda_nid_t nid)
2668{ 2692{
2669 struct snd_kcontrol_new *knew; 2693 struct snd_kcontrol_new *knew;
2670 2694
@@ -2680,6 +2704,8 @@ stac_control_new(struct sigmatel_spec *spec,
2680 spec->kctls.alloced--; 2704 spec->kctls.alloced--;
2681 return NULL; 2705 return NULL;
2682 } 2706 }
2707 if (nid)
2708 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
2683 return knew; 2709 return knew;
2684} 2710}
2685 2711
@@ -2688,7 +2714,8 @@ static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2688 int idx, const char *name, 2714 int idx, const char *name,
2689 unsigned long val) 2715 unsigned long val)
2690{ 2716{
2691 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name); 2717 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
2718 get_amp_nid_(val));
2692 if (!knew) 2719 if (!knew)
2693 return -ENOMEM; 2720 return -ENOMEM;
2694 knew->index = idx; 2721 knew->index = idx;
@@ -2759,7 +2786,7 @@ static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2759 if (!spec->num_adcs || imux->num_items <= 1) 2786 if (!spec->num_adcs || imux->num_items <= 1)
2760 return 0; /* no need for input source control */ 2787 return 0; /* no need for input source control */
2761 knew = stac_control_new(spec, &stac_input_src_temp, 2788 knew = stac_control_new(spec, &stac_input_src_temp,
2762 stac_input_src_temp.name); 2789 stac_input_src_temp.name, 0);
2763 if (!knew) 2790 if (!knew)
2764 return -ENOMEM; 2791 return -ENOMEM;
2765 knew->count = spec->num_adcs; 2792 knew->count = spec->num_adcs;
@@ -3216,12 +3243,15 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3216{ 3243{
3217 struct sigmatel_spec *spec = codec->spec; 3244 struct sigmatel_spec *spec = codec->spec;
3218 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT); 3245 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3219 int err; 3246 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3247
3248 if (spec->anabeep_nid == nid)
3249 type = STAC_CTL_WIDGET_MUTE;
3220 3250
3221 /* check for mute support for the the amp */ 3251 /* check for mute support for the the amp */
3222 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) { 3252 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3223 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, 3253 err = stac92xx_add_control(spec, type,
3224 "PC Beep Playback Switch", 3254 "Beep Playback Switch",
3225 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3255 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3226 if (err < 0) 3256 if (err < 0)
3227 return err; 3257 return err;
@@ -3230,7 +3260,7 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3230 /* check to see if there is volume support for the amp */ 3260 /* check to see if there is volume support for the amp */
3231 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) { 3261 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3232 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, 3262 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3233 "PC Beep Playback Volume", 3263 "Beep Playback Volume",
3234 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3264 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3235 if (err < 0) 3265 if (err < 0)
3236 return err; 3266 return err;
@@ -3253,12 +3283,7 @@ static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3253 struct snd_ctl_elem_value *ucontrol) 3283 struct snd_ctl_elem_value *ucontrol)
3254{ 3284{
3255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3285 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3256 int enabled = !!ucontrol->value.integer.value[0]; 3286 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
3257 if (codec->beep->enabled != enabled) {
3258 codec->beep->enabled = enabled;
3259 return 1;
3260 }
3261 return 0;
3262} 3287}
3263 3288
3264static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = { 3289static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
@@ -3271,7 +3296,7 @@ static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3271static int stac92xx_beep_switch_ctl(struct hda_codec *codec) 3296static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3272{ 3297{
3273 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl, 3298 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3274 0, "PC Beep Playback Switch", 0); 3299 0, "Beep Playback Switch", 0);
3275} 3300}
3276#endif 3301#endif
3277 3302
@@ -3626,6 +3651,26 @@ static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3626 } 3651 }
3627} 3652}
3628 3653
3654static int is_dual_headphones(struct hda_codec *codec)
3655{
3656 struct sigmatel_spec *spec = codec->spec;
3657 int i, valid_hps;
3658
3659 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3660 spec->autocfg.hp_outs <= 1)
3661 return 0;
3662 valid_hps = 0;
3663 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3664 hda_nid_t nid = spec->autocfg.hp_pins[i];
3665 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3666 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3667 continue;
3668 valid_hps++;
3669 }
3670 return (valid_hps > 1);
3671}
3672
3673
3629static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) 3674static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3630{ 3675{
3631 struct sigmatel_spec *spec = codec->spec; 3676 struct sigmatel_spec *spec = codec->spec;
@@ -3642,8 +3687,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3642 /* If we have no real line-out pin and multiple hp-outs, HPs should 3687 /* If we have no real line-out pin and multiple hp-outs, HPs should
3643 * be set up as multi-channel outputs. 3688 * be set up as multi-channel outputs.
3644 */ 3689 */
3645 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && 3690 if (is_dual_headphones(codec)) {
3646 spec->autocfg.hp_outs > 1) {
3647 /* Copy hp_outs to line_outs, backup line_outs in 3691 /* Copy hp_outs to line_outs, backup line_outs in
3648 * speaker_outs so that the following routines can handle 3692 * speaker_outs so that the following routines can handle
3649 * HP pins as primary outputs. 3693 * HP pins as primary outputs.
@@ -3738,15 +3782,16 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3738 err = snd_hda_attach_beep_device(codec, nid); 3782 err = snd_hda_attach_beep_device(codec, nid);
3739 if (err < 0) 3783 if (err < 0)
3740 return err; 3784 return err;
3741 /* IDT/STAC codecs have linear beep tone parameter */ 3785 if (codec->beep) {
3742 codec->beep->linear_tone = 1; 3786 /* IDT/STAC codecs have linear beep tone parameter */
3743 /* if no beep switch is available, make its own one */ 3787 codec->beep->linear_tone = 1;
3744 caps = query_amp_caps(codec, nid, HDA_OUTPUT); 3788 /* if no beep switch is available, make its own one */
3745 if (codec->beep && 3789 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3746 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) { 3790 if (!(caps & AC_AMPCAP_MUTE)) {
3747 err = stac92xx_beep_switch_ctl(codec); 3791 err = stac92xx_beep_switch_ctl(codec);
3748 if (err < 0) 3792 if (err < 0)
3749 return err; 3793 return err;
3794 }
3750 } 3795 }
3751 } 3796 }
3752#endif 3797#endif
@@ -4324,6 +4369,28 @@ static void stac92xx_free_kctls(struct hda_codec *codec)
4324 snd_array_free(&spec->kctls); 4369 snd_array_free(&spec->kctls);
4325} 4370}
4326 4371
4372static void stac92xx_shutup(struct hda_codec *codec)
4373{
4374 struct sigmatel_spec *spec = codec->spec;
4375 int i;
4376 hda_nid_t nid;
4377
4378 /* reset each pin before powering down DAC/ADC to avoid click noise */
4379 nid = codec->start_nid;
4380 for (i = 0; i < codec->num_nodes; i++, nid++) {
4381 unsigned int wcaps = get_wcaps(codec, nid);
4382 unsigned int wid_type = get_wcaps_type(wcaps);
4383 if (wid_type == AC_WID_PIN)
4384 snd_hda_codec_read(codec, nid, 0,
4385 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4386 }
4387
4388 if (spec->eapd_mask)
4389 stac_gpio_set(codec, spec->gpio_mask,
4390 spec->gpio_dir, spec->gpio_data &
4391 ~spec->eapd_mask);
4392}
4393
4327static void stac92xx_free(struct hda_codec *codec) 4394static void stac92xx_free(struct hda_codec *codec)
4328{ 4395{
4329 struct sigmatel_spec *spec = codec->spec; 4396 struct sigmatel_spec *spec = codec->spec;
@@ -4331,6 +4398,7 @@ static void stac92xx_free(struct hda_codec *codec)
4331 if (! spec) 4398 if (! spec)
4332 return; 4399 return;
4333 4400
4401 stac92xx_shutup(codec);
4334 stac92xx_free_jacks(codec); 4402 stac92xx_free_jacks(codec);
4335 snd_array_free(&spec->events); 4403 snd_array_free(&spec->events);
4336 4404
@@ -4381,12 +4449,16 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4381 pin_ctl & ~flag); 4449 pin_ctl & ~flag);
4382} 4450}
4383 4451
4384static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) 4452static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
4385{ 4453{
4386 if (!nid) 4454 if (!nid)
4387 return 0; 4455 return 0;
4388 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00) 4456 /* NOTE: we can't use snd_hda_jack_detect() here because STAC/IDT
4389 & (1 << 31)) 4457 * codecs behave wrongly when SET_PIN_SENSE is triggered, although
4458 * the pincap gives TRIG_REQ bit.
4459 */
4460 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0) &
4461 AC_PINSENSE_PRESENCE)
4390 return 1; 4462 return 1;
4391 return 0; 4463 return 0;
4392} 4464}
@@ -4665,6 +4737,82 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4665 } 4737 }
4666} 4738}
4667 4739
4740/*
4741 * This method searches for the mute LED GPIO configuration
4742 * provided as OEM string in SMBIOS. The format of that string
4743 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4744 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4745 * that corresponds to the NOT muted state of the master volume
4746 * and G is the index of the GPIO to use as the mute LED control (0..9)
4747 * If _G portion is missing it is assigned based on the codec ID
4748 *
4749 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4750 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
4751 */
4752static int find_mute_led_gpio(struct hda_codec *codec)
4753{
4754 struct sigmatel_spec *spec = codec->spec;
4755 const struct dmi_device *dev = NULL;
4756
4757 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4758 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4759 NULL, dev))) {
4760 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
4761 &spec->gpio_led_polarity,
4762 &spec->gpio_led) == 2) {
4763 spec->gpio_led = 1 << spec->gpio_led;
4764 return 1;
4765 }
4766 if (sscanf(dev->name, "HP_Mute_LED_%d",
4767 &spec->gpio_led_polarity) == 1) {
4768 switch (codec->vendor_id) {
4769 case 0x111d7608:
4770 /* GPIO 0 */
4771 spec->gpio_led = 0x01;
4772 return 1;
4773 case 0x111d7600:
4774 case 0x111d7601:
4775 case 0x111d7602:
4776 case 0x111d7603:
4777 /* GPIO 3 */
4778 spec->gpio_led = 0x08;
4779 return 1;
4780 }
4781 }
4782 }
4783 }
4784 return 0;
4785}
4786
4787static int hp_blike_system(u32 subsystem_id)
4788{
4789 switch (subsystem_id) {
4790 case 0x103c1520:
4791 case 0x103c1521:
4792 case 0x103c1523:
4793 case 0x103c1524:
4794 case 0x103c1525:
4795 case 0x103c1722:
4796 case 0x103c1723:
4797 case 0x103c1724:
4798 case 0x103c1725:
4799 case 0x103c1726:
4800 case 0x103c1727:
4801 case 0x103c1728:
4802 case 0x103c1729:
4803 case 0x103c172a:
4804 case 0x103c172b:
4805 case 0x103c307e:
4806 case 0x103c307f:
4807 case 0x103c3080:
4808 case 0x103c3081:
4809 case 0x103c7007:
4810 case 0x103c7008:
4811 return 1;
4812 }
4813 return 0;
4814}
4815
4668#ifdef CONFIG_PROC_FS 4816#ifdef CONFIG_PROC_FS
4669static void stac92hd_proc_hook(struct snd_info_buffer *buffer, 4817static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4670 struct hda_codec *codec, hda_nid_t nid) 4818 struct hda_codec *codec, hda_nid_t nid)
@@ -4754,6 +4902,11 @@ static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4754 else 4902 else
4755 spec->gpio_data |= spec->gpio_led; /* white */ 4903 spec->gpio_data |= spec->gpio_led; /* white */
4756 4904
4905 if (!spec->gpio_led_polarity) {
4906 /* LED state is inverted on these systems */
4907 spec->gpio_data ^= spec->gpio_led;
4908 }
4909
4757 stac_gpio_set(codec, spec->gpio_mask, 4910 stac_gpio_set(codec, spec->gpio_mask,
4758 spec->gpio_dir, 4911 spec->gpio_dir,
4759 spec->gpio_data); 4912 spec->gpio_data);
@@ -4761,28 +4914,28 @@ static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4761 4914
4762 return 0; 4915 return 0;
4763} 4916}
4764#endif
4765 4917
4766static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) 4918static int idt92hd83xxx_hp_check_power_status(struct hda_codec *codec,
4919 hda_nid_t nid)
4767{ 4920{
4768 struct sigmatel_spec *spec = codec->spec; 4921 struct sigmatel_spec *spec = codec->spec;
4769 int i;
4770 hda_nid_t nid;
4771 4922
4772 /* reset each pin before powering down DAC/ADC to avoid click noise */ 4923 if (nid != 0x13)
4773 nid = codec->start_nid; 4924 return 0;
4774 for (i = 0; i < codec->num_nodes; i++, nid++) { 4925 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) & HDA_AMP_MUTE)
4775 unsigned int wcaps = get_wcaps(codec, nid); 4926 spec->gpio_data |= spec->gpio_led; /* mute LED on */
4776 unsigned int wid_type = get_wcaps_type(wcaps); 4927 else
4777 if (wid_type == AC_WID_PIN) 4928 spec->gpio_data &= ~spec->gpio_led; /* mute LED off */
4778 snd_hda_codec_read(codec, nid, 0, 4929 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
4779 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4780 }
4781 4930
4782 if (spec->eapd_mask) 4931 return 0;
4783 stac_gpio_set(codec, spec->gpio_mask, 4932}
4784 spec->gpio_dir, spec->gpio_data & 4933
4785 ~spec->eapd_mask); 4934#endif
4935
4936static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4937{
4938 stac92xx_shutup(codec);
4786 return 0; 4939 return 0;
4787} 4940}
4788#endif 4941#endif
@@ -4797,6 +4950,7 @@ static struct hda_codec_ops stac92xx_patch_ops = {
4797 .suspend = stac92xx_suspend, 4950 .suspend = stac92xx_suspend,
4798 .resume = stac92xx_resume, 4951 .resume = stac92xx_resume,
4799#endif 4952#endif
4953 .reboot_notify = stac92xx_shutup,
4800}; 4954};
4801 4955
4802static int patch_stac9200(struct hda_codec *codec) 4956static int patch_stac9200(struct hda_codec *codec)
@@ -5142,6 +5296,22 @@ again:
5142 break; 5296 break;
5143 } 5297 }
5144 5298
5299 codec->patch_ops = stac92xx_patch_ops;
5300
5301 if (spec->board_config == STAC_92HD83XXX_HP)
5302 spec->gpio_led = 0x01;
5303
5304#ifdef CONFIG_SND_HDA_POWER_SAVE
5305 if (spec->gpio_led) {
5306 spec->gpio_mask |= spec->gpio_led;
5307 spec->gpio_dir |= spec->gpio_led;
5308 spec->gpio_data |= spec->gpio_led;
5309 /* register check_power_status callback. */
5310 codec->patch_ops.check_power_status =
5311 idt92hd83xxx_hp_check_power_status;
5312 }
5313#endif
5314
5145 err = stac92xx_parse_auto_config(codec, 0x1d, 0); 5315 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5146 if (!err) { 5316 if (!err) {
5147 if (spec->board_config < 0) { 5317 if (spec->board_config < 0) {
@@ -5177,8 +5347,6 @@ again:
5177 snd_hda_codec_write_cache(codec, nid, 0, 5347 snd_hda_codec_write_cache(codec, nid, 0,
5178 AC_VERB_SET_CONNECT_SEL, num_dacs); 5348 AC_VERB_SET_CONNECT_SEL, num_dacs);
5179 5349
5180 codec->patch_ops = stac92xx_patch_ops;
5181
5182 codec->proc_widget_hook = stac92hd_proc_hook; 5350 codec->proc_widget_hook = stac92hd_proc_hook;
5183 5351
5184 return 0; 5352 return 0;
@@ -5243,6 +5411,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
5243{ 5411{
5244 struct sigmatel_spec *spec; 5412 struct sigmatel_spec *spec;
5245 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init; 5413 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
5414 unsigned int pin_cfg;
5246 int err = 0; 5415 int err = 0;
5247 5416
5248 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5417 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -5426,6 +5595,29 @@ again:
5426 break; 5595 break;
5427 } 5596 }
5428 5597
5598 if (hp_blike_system(codec->subsystem_id)) {
5599 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5600 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5601 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5602 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5603 /* It was changed in the BIOS to just satisfy MS DTM.
5604 * Lets turn it back into slaved HP
5605 */
5606 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5607 | (AC_JACK_HP_OUT <<
5608 AC_DEFCFG_DEVICE_SHIFT);
5609 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5610 | AC_DEFCFG_SEQUENCE)))
5611 | 0x1f;
5612 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5613 }
5614 }
5615
5616 if (find_mute_led_gpio(codec))
5617 snd_printd("mute LED gpio %d polarity %d\n",
5618 spec->gpio_led,
5619 spec->gpio_led_polarity);
5620
5429#ifdef CONFIG_SND_HDA_POWER_SAVE 5621#ifdef CONFIG_SND_HDA_POWER_SAVE
5430 if (spec->gpio_led) { 5622 if (spec->gpio_led) {
5431 spec->gpio_mask |= spec->gpio_led; 5623 spec->gpio_mask |= spec->gpio_led;
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index ee89db90c9b6..b70e26ad263f 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
@@ -76,14 +82,6 @@
76#define VT1702_HP_NID 0x17 82#define VT1702_HP_NID 0x17
77#define VT1702_DIGOUT_NID 0x11 83#define VT1702_DIGOUT_NID 0x11
78 84
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 { 85enum VIA_HDA_CODEC {
88 UNKNOWN = -1, 86 UNKNOWN = -1,
89 VT1708, 87 VT1708,
@@ -92,12 +90,76 @@ enum VIA_HDA_CODEC {
92 VT1708B_8CH, 90 VT1708B_8CH,
93 VT1708B_4CH, 91 VT1708B_4CH,
94 VT1708S, 92 VT1708S,
93 VT1708BCE,
95 VT1702, 94 VT1702,
95 VT1718S,
96 VT1716S,
97 VT2002P,
98 VT1812,
96 CODEC_TYPES, 99 CODEC_TYPES,
97}; 100};
98 101
99static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) 102struct via_spec {
103 /* codec parameterization */
104 struct snd_kcontrol_new *mixers[6];
105 unsigned int num_mixers;
106
107 struct hda_verb *init_verbs[5];
108 unsigned int num_iverbs;
109
110 char *stream_name_analog;
111 struct hda_pcm_stream *stream_analog_playback;
112 struct hda_pcm_stream *stream_analog_capture;
113
114 char *stream_name_digital;
115 struct hda_pcm_stream *stream_digital_playback;
116 struct hda_pcm_stream *stream_digital_capture;
117
118 /* playback */
119 struct hda_multi_out multiout;
120 hda_nid_t slave_dig_outs[2];
121
122 /* capture */
123 unsigned int num_adc_nids;
124 hda_nid_t *adc_nids;
125 hda_nid_t mux_nids[3];
126 hda_nid_t dig_in_nid;
127 hda_nid_t dig_in_pin;
128
129 /* capture source */
130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
132
133 /* PCM information */
134 struct hda_pcm pcm_rec[3];
135
136 /* dynamic controls, init_verbs and input_mux */
137 struct auto_pin_cfg autocfg;
138 struct snd_array kctls;
139 struct hda_input_mux private_imux[2];
140 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
141
142 /* HP mode source */
143 const struct hda_input_mux *hp_mux;
144 unsigned int hp_independent_mode;
145 unsigned int hp_independent_mode_index;
146 unsigned int smart51_enabled;
147 unsigned int dmic_enabled;
148 enum VIA_HDA_CODEC codec_type;
149
150 /* work to check hp jack state */
151 struct hda_codec *codec;
152 struct delayed_work vt1708_hp_work;
153 int vt1708_jack_detectect;
154 int vt1708_hp_present;
155#ifdef CONFIG_SND_HDA_POWER_SAVE
156 struct hda_loopback_check loopback;
157#endif
158};
159
160static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
100{ 161{
162 u32 vendor_id = codec->vendor_id;
101 u16 ven_id = vendor_id >> 16; 163 u16 ven_id = vendor_id >> 16;
102 u16 dev_id = vendor_id & 0xffff; 164 u16 dev_id = vendor_id & 0xffff;
103 enum VIA_HDA_CODEC codec_type; 165 enum VIA_HDA_CODEC codec_type;
@@ -111,9 +173,11 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
111 codec_type = VT1709_10CH; 173 codec_type = VT1709_10CH;
112 else if (dev_id >= 0xe714 && dev_id <= 0xe717) 174 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113 codec_type = VT1709_6CH; 175 codec_type = VT1709_6CH;
114 else if (dev_id >= 0xe720 && dev_id <= 0xe723) 176 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
115 codec_type = VT1708B_8CH; 177 codec_type = VT1708B_8CH;
116 else if (dev_id >= 0xe724 && dev_id <= 0xe727) 178 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
179 codec_type = VT1708BCE;
180 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117 codec_type = VT1708B_4CH; 181 codec_type = VT1708B_4CH;
118 else if ((dev_id & 0xfff) == 0x397 182 else if ((dev_id & 0xfff) == 0x397
119 && (dev_id >> 12) < 8) 183 && (dev_id >> 12) < 8)
@@ -121,6 +185,19 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
121 else if ((dev_id & 0xfff) == 0x398 185 else if ((dev_id & 0xfff) == 0x398
122 && (dev_id >> 12) < 8) 186 && (dev_id >> 12) < 8)
123 codec_type = VT1702; 187 codec_type = VT1702;
188 else if ((dev_id & 0xfff) == 0x428
189 && (dev_id >> 12) < 8)
190 codec_type = VT1718S;
191 else if (dev_id == 0x0433 || dev_id == 0xa721)
192 codec_type = VT1716S;
193 else if (dev_id == 0x0441 || dev_id == 0x4441)
194 codec_type = VT1718S;
195 else if (dev_id == 0x0438 || dev_id == 0x4438)
196 codec_type = VT2002P;
197 else if (dev_id == 0x0448)
198 codec_type = VT1812;
199 else if (dev_id == 0x0440)
200 codec_type = VT1708S;
124 else 201 else
125 codec_type = UNKNOWN; 202 codec_type = UNKNOWN;
126 return codec_type; 203 return codec_type;
@@ -128,10 +205,16 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
128 205
129#define VIA_HP_EVENT 0x01 206#define VIA_HP_EVENT 0x01
130#define VIA_GPIO_EVENT 0x02 207#define VIA_GPIO_EVENT 0x02
208#define VIA_JACK_EVENT 0x04
209#define VIA_MONO_EVENT 0x08
210#define VIA_SPEAKER_EVENT 0x10
211#define VIA_BIND_HP_EVENT 0x20
131 212
132enum { 213enum {
133 VIA_CTL_WIDGET_VOL, 214 VIA_CTL_WIDGET_VOL,
134 VIA_CTL_WIDGET_MUTE, 215 VIA_CTL_WIDGET_MUTE,
216 VIA_CTL_WIDGET_ANALOG_MUTE,
217 VIA_CTL_WIDGET_BIND_PIN_MUTE,
135}; 218};
136 219
137enum { 220enum {
@@ -141,99 +224,162 @@ enum {
141 AUTO_SEQ_SIDE 224 AUTO_SEQ_SIDE
142}; 225};
143 226
144/* Some VT1708S based boards gets the micboost setting wrong, so we have 227static 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. */ 228static void set_jack_power_state(struct hda_codec *codec);
146static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, 229static int is_aa_path_mute(struct hda_codec *codec);
147 unsigned int size, unsigned int __user *_tlv) 230
231static void vt1708_start_hp_work(struct via_spec *spec)
148{ 232{
149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 233 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
150 hda_nid_t nid = get_amp_nid(kcontrol); 234 return;
235 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
236 !spec->vt1708_jack_detectect);
237 if (!delayed_work_pending(&spec->vt1708_hp_work))
238 schedule_delayed_work(&spec->vt1708_hp_work,
239 msecs_to_jiffies(100));
240}
151 241
152 if (get_codec_type(codec->vendor_id) == VT1708S 242static void vt1708_stop_hp_work(struct via_spec *spec)
153 && (nid == 0x1a || nid == 0x1e)) { 243{
154 if (size < 4 * sizeof(unsigned int)) 244 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
155 return -ENOMEM; 245 return;
156 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */ 246 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
157 return -EFAULT; 247 && !is_aa_path_mute(spec->codec))
158 if (put_user(2 * sizeof(unsigned int), _tlv + 1)) 248 return;
159 return -EFAULT; 249 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
160 if (put_user(0, _tlv + 2)) /* offset = 0 */ 250 !spec->vt1708_jack_detectect);
161 return -EFAULT; 251 cancel_delayed_work(&spec->vt1708_hp_work);
162 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */ 252 flush_scheduled_work();
163 return -EFAULT;
164 }
165 return 0;
166} 253}
167 254
168static int mic_boost_volume_info(struct snd_kcontrol *kcontrol, 255
169 struct snd_ctl_elem_info *uinfo) 256static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
170{ 258{
259 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 hda_nid_t nid = get_amp_nid(kcontrol);
173 261
174 if (get_codec_type(codec->vendor_id) == VT1708S 262 set_jack_power_state(codec);
175 && (nid == 0x1a || nid == 0x1e)) { 263 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 264 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
177 uinfo->count = 2; 265 if (is_aa_path_mute(codec))
178 uinfo->value.integer.min = 0; 266 vt1708_start_hp_work(codec->spec);
179 uinfo->value.integer.max = 3; 267 else
268 vt1708_stop_hp_work(codec->spec);
180 } 269 }
181 return 0; 270 return change;
182} 271}
183 272
184static struct snd_kcontrol_new vt1708_control_templates[] = { 273/* modify .put = snd_hda_mixer_amp_switch_put */
185 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 274#define ANALOG_INPUT_MUTE \
186 HDA_CODEC_MUTE(NULL, 0, 0, 0), 275 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
187}; 276 .name = NULL, \
188 277 .index = 0, \
189 278 .info = snd_hda_mixer_amp_switch_info, \
190struct via_spec { 279 .get = snd_hda_mixer_amp_switch_get, \
191 /* codec parameterization */ 280 .put = analog_input_switch_put, \
192 struct snd_kcontrol_new *mixers[3]; 281 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
193 unsigned int num_mixers;
194 282
195 struct hda_verb *init_verbs[5]; 283static void via_hp_bind_automute(struct hda_codec *codec);
196 unsigned int num_iverbs;
197 284
198 char *stream_name_analog; 285static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
199 struct hda_pcm_stream *stream_analog_playback; 286 struct snd_ctl_elem_value *ucontrol)
200 struct hda_pcm_stream *stream_analog_capture; 287{
201 288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
202 char *stream_name_digital; 289 struct via_spec *spec = codec->spec;
203 struct hda_pcm_stream *stream_digital_playback; 290 int i;
204 struct hda_pcm_stream *stream_digital_capture; 291 int change = 0;
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 292
217 /* capture source */ 293 long *valp = ucontrol->value.integer.value;
218 const struct hda_input_mux *input_mux; 294 int lmute, rmute;
219 unsigned int cur_mux[3]; 295 if (strstr(kcontrol->id.name, "Switch") == NULL) {
296 snd_printd("Invalid control!\n");
297 return change;
298 }
299 change = snd_hda_mixer_amp_switch_put(kcontrol,
300 ucontrol);
301 /* Get mute value */
302 lmute = *valp ? 0 : HDA_AMP_MUTE;
303 valp++;
304 rmute = *valp ? 0 : HDA_AMP_MUTE;
305
306 /* Set hp pins */
307 if (!spec->hp_independent_mode) {
308 for (i = 0; i < spec->autocfg.hp_outs; i++) {
309 snd_hda_codec_amp_update(
310 codec, spec->autocfg.hp_pins[i],
311 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
312 lmute);
313 snd_hda_codec_amp_update(
314 codec, spec->autocfg.hp_pins[i],
315 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
316 rmute);
317 }
318 }
220 319
221 /* PCM information */ 320 if (!lmute && !rmute) {
222 struct hda_pcm pcm_rec[3]; 321 /* Line Outs */
322 for (i = 0; i < spec->autocfg.line_outs; i++)
323 snd_hda_codec_amp_stereo(
324 codec, spec->autocfg.line_out_pins[i],
325 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
326 /* Speakers */
327 for (i = 0; i < spec->autocfg.speaker_outs; i++)
328 snd_hda_codec_amp_stereo(
329 codec, spec->autocfg.speaker_pins[i],
330 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
331 /* unmute */
332 via_hp_bind_automute(codec);
223 333
224 /* dynamic controls, init_verbs and input_mux */ 334 } else {
225 struct auto_pin_cfg autocfg; 335 if (lmute) {
226 struct snd_array kctls; 336 /* Mute all left channels */
227 struct hda_input_mux private_imux[2]; 337 for (i = 1; i < spec->autocfg.line_outs; i++)
228 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 338 snd_hda_codec_amp_update(
339 codec,
340 spec->autocfg.line_out_pins[i],
341 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
342 lmute);
343 for (i = 0; i < spec->autocfg.speaker_outs; i++)
344 snd_hda_codec_amp_update(
345 codec,
346 spec->autocfg.speaker_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 lmute);
349 }
350 if (rmute) {
351 /* mute all right channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 rmute);
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 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 rmute);
364 }
365 }
366 return change;
367}
229 368
230 /* HP mode source */ 369#define BIND_PIN_MUTE \
231 const struct hda_input_mux *hp_mux; 370 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
232 unsigned int hp_independent_mode; 371 .name = NULL, \
372 .index = 0, \
373 .info = snd_hda_mixer_amp_switch_info, \
374 .get = snd_hda_mixer_amp_switch_get, \
375 .put = bind_pin_switch_put, \
376 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
233 377
234#ifdef CONFIG_SND_HDA_POWER_SAVE 378static struct snd_kcontrol_new via_control_templates[] = {
235 struct hda_loopback_check loopback; 379 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
236#endif 380 HDA_CODEC_MUTE(NULL, 0, 0, 0),
381 ANALOG_INPUT_MUTE,
382 BIND_PIN_MUTE,
237}; 383};
238 384
239static hda_nid_t vt1708_adc_nids[2] = { 385static hda_nid_t vt1708_adc_nids[2] = {
@@ -261,6 +407,27 @@ static hda_nid_t vt1702_adc_nids[3] = {
261 0x12, 0x20, 0x1F 407 0x12, 0x20, 0x1F
262}; 408};
263 409
410static hda_nid_t vt1718S_adc_nids[2] = {
411 /* ADC1-2 */
412 0x10, 0x11
413};
414
415static hda_nid_t vt1716S_adc_nids[2] = {
416 /* ADC1-2 */
417 0x13, 0x14
418};
419
420static hda_nid_t vt2002P_adc_nids[2] = {
421 /* ADC1-2 */
422 0x10, 0x11
423};
424
425static hda_nid_t vt1812_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
428};
429
430
264/* add dynamic controls */ 431/* add dynamic controls */
265static int via_add_control(struct via_spec *spec, int type, const char *name, 432static int via_add_control(struct via_spec *spec, int type, const char *name,
266 unsigned long val) 433 unsigned long val)
@@ -271,10 +438,12 @@ static int via_add_control(struct via_spec *spec, int type, const char *name,
271 knew = snd_array_new(&spec->kctls); 438 knew = snd_array_new(&spec->kctls);
272 if (!knew) 439 if (!knew)
273 return -ENOMEM; 440 return -ENOMEM;
274 *knew = vt1708_control_templates[type]; 441 *knew = via_control_templates[type];
275 knew->name = kstrdup(name, GFP_KERNEL); 442 knew->name = kstrdup(name, GFP_KERNEL);
276 if (!knew->name) 443 if (!knew->name)
277 return -ENOMEM; 444 return -ENOMEM;
445 if (get_amp_nid_(val))
446 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
278 knew->private_value = val; 447 knew->private_value = val;
279 return 0; 448 return 0;
280} 449}
@@ -293,8 +462,8 @@ static void via_free_kctls(struct hda_codec *codec)
293} 462}
294 463
295/* create input playback/capture controls for the given pin */ 464/* create input playback/capture controls for the given pin */
296static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, 465static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
297 const char *ctlname, int idx, int mix_nid) 466 int idx, int mix_nid)
298{ 467{
299 char name[32]; 468 char name[32];
300 int err; 469 int err;
@@ -305,7 +474,7 @@ static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
305 if (err < 0) 474 if (err < 0)
306 return err; 475 return err;
307 sprintf(name, "%s Playback Switch", ctlname); 476 sprintf(name, "%s Playback Switch", ctlname);
308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 477 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
309 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 478 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
310 if (err < 0) 479 if (err < 0)
311 return err; 480 return err;
@@ -322,7 +491,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, 491 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
323 AMP_OUT_UNMUTE); 492 AMP_OUT_UNMUTE);
324 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) 493 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
325 snd_hda_codec_write(codec, nid, 0, 494 snd_hda_codec_write(codec, nid, 0,
326 AC_VERB_SET_EAPD_BTLENABLE, 0x02); 495 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
327} 496}
328 497
@@ -343,10 +512,13 @@ static void via_auto_init_hp_out(struct hda_codec *codec)
343{ 512{
344 struct via_spec *spec = codec->spec; 513 struct via_spec *spec = codec->spec;
345 hda_nid_t pin; 514 hda_nid_t pin;
515 int i;
346 516
347 pin = spec->autocfg.hp_pins[0]; 517 for (i = 0; i < spec->autocfg.hp_outs; i++) {
348 if (pin) /* connect to front */ 518 pin = spec->autocfg.hp_pins[i];
349 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 519 if (pin) /* connect to front */
520 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
521 }
350} 522}
351 523
352static void via_auto_init_analog_input(struct hda_codec *codec) 524static void via_auto_init_analog_input(struct hda_codec *codec)
@@ -364,6 +536,502 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
364 536
365 } 537 }
366} 538}
539
540static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
541
542static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
543 unsigned int *affected_parm)
544{
545 unsigned parm;
546 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
547 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
548 >> AC_DEFCFG_MISC_SHIFT
549 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
550 unsigned present = snd_hda_jack_detect(codec, nid);
551 struct via_spec *spec = codec->spec;
552 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
553 || ((no_presence || present)
554 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
555 *affected_parm = AC_PWRST_D0; /* if it's connected */
556 parm = AC_PWRST_D0;
557 } else
558 parm = AC_PWRST_D3;
559
560 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
561}
562
563static void set_jack_power_state(struct hda_codec *codec)
564{
565 struct via_spec *spec = codec->spec;
566 int imux_is_smixer;
567 unsigned int parm;
568
569 if (spec->codec_type == VT1702) {
570 imux_is_smixer = snd_hda_codec_read(
571 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
572 /* inputs */
573 /* PW 1/2/5 (14h/15h/18h) */
574 parm = AC_PWRST_D3;
575 set_pin_power_state(codec, 0x14, &parm);
576 set_pin_power_state(codec, 0x15, &parm);
577 set_pin_power_state(codec, 0x18, &parm);
578 if (imux_is_smixer)
579 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
580 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
581 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
582 parm);
583 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
584 parm);
585 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
586 parm);
587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
588 parm);
589
590 /* outputs */
591 /* PW 3/4 (16h/17h) */
592 parm = AC_PWRST_D3;
593 set_pin_power_state(codec, 0x16, &parm);
594 set_pin_power_state(codec, 0x17, &parm);
595 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
596 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
597 imux_is_smixer ? AC_PWRST_D0 : parm);
598 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
599 parm);
600 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
601 parm);
602 } else if (spec->codec_type == VT1708B_8CH
603 || spec->codec_type == VT1708B_4CH
604 || spec->codec_type == VT1708S) {
605 /* SW0 (17h) = stereo mixer */
606 int is_8ch = spec->codec_type != VT1708B_4CH;
607 imux_is_smixer = snd_hda_codec_read(
608 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
609 == ((spec->codec_type == VT1708S) ? 5 : 0);
610 /* inputs */
611 /* PW 1/2/5 (1ah/1bh/1eh) */
612 parm = AC_PWRST_D3;
613 set_pin_power_state(codec, 0x1a, &parm);
614 set_pin_power_state(codec, 0x1b, &parm);
615 set_pin_power_state(codec, 0x1e, &parm);
616 if (imux_is_smixer)
617 parm = AC_PWRST_D0;
618 /* SW0 (17h), AIW 0/1 (13h/14h) */
619 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
620 parm);
621 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
622 parm);
623 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
624 parm);
625
626 /* outputs */
627 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
628 parm = AC_PWRST_D3;
629 set_pin_power_state(codec, 0x19, &parm);
630 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
631 parm);
632 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
633 parm);
634
635 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
636 if (is_8ch) {
637 parm = AC_PWRST_D3;
638 set_pin_power_state(codec, 0x22, &parm);
639 snd_hda_codec_write(codec, 0x26, 0,
640 AC_VERB_SET_POWER_STATE, parm);
641 snd_hda_codec_write(codec, 0x24, 0,
642 AC_VERB_SET_POWER_STATE, parm);
643 }
644
645 /* PW 3/4/7 (1ch/1dh/23h) */
646 parm = AC_PWRST_D3;
647 /* force to D0 for internal Speaker */
648 set_pin_power_state(codec, 0x1c, &parm);
649 set_pin_power_state(codec, 0x1d, &parm);
650 if (is_8ch)
651 set_pin_power_state(codec, 0x23, &parm);
652 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
653 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
654 imux_is_smixer ? AC_PWRST_D0 : parm);
655 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
656 parm);
657 if (is_8ch) {
658 snd_hda_codec_write(codec, 0x25, 0,
659 AC_VERB_SET_POWER_STATE, parm);
660 snd_hda_codec_write(codec, 0x27, 0,
661 AC_VERB_SET_POWER_STATE, parm);
662 }
663 } else if (spec->codec_type == VT1718S) {
664 /* MUX6 (1eh) = stereo mixer */
665 imux_is_smixer = snd_hda_codec_read(
666 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
667 /* inputs */
668 /* PW 5/6/7 (29h/2ah/2bh) */
669 parm = AC_PWRST_D3;
670 set_pin_power_state(codec, 0x29, &parm);
671 set_pin_power_state(codec, 0x2a, &parm);
672 set_pin_power_state(codec, 0x2b, &parm);
673 if (imux_is_smixer)
674 parm = AC_PWRST_D0;
675 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
676 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
677 parm);
678 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
679 parm);
680 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
681 parm);
682 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
683 parm);
684
685 /* outputs */
686 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
687 parm = AC_PWRST_D3;
688 set_pin_power_state(codec, 0x27, &parm);
689 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
690 parm);
691 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
692 parm);
693
694 /* PW2 (26h), AOW2 (ah) */
695 parm = AC_PWRST_D3;
696 set_pin_power_state(codec, 0x26, &parm);
697 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
698 parm);
699
700 /* PW0/1 (24h/25h) */
701 parm = AC_PWRST_D3;
702 set_pin_power_state(codec, 0x24, &parm);
703 set_pin_power_state(codec, 0x25, &parm);
704 if (!spec->hp_independent_mode) /* check for redirected HP */
705 set_pin_power_state(codec, 0x28, &parm);
706 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
707 parm);
708 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
709 parm);
710 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
711 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
712 imux_is_smixer ? AC_PWRST_D0 : parm);
713 if (spec->hp_independent_mode) {
714 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
715 parm = AC_PWRST_D3;
716 set_pin_power_state(codec, 0x28, &parm);
717 snd_hda_codec_write(codec, 0x1b, 0,
718 AC_VERB_SET_POWER_STATE, parm);
719 snd_hda_codec_write(codec, 0x34, 0,
720 AC_VERB_SET_POWER_STATE, parm);
721 snd_hda_codec_write(codec, 0xc, 0,
722 AC_VERB_SET_POWER_STATE, parm);
723 }
724 } else if (spec->codec_type == VT1716S) {
725 unsigned int mono_out, present;
726 /* SW0 (17h) = stereo mixer */
727 imux_is_smixer = snd_hda_codec_read(
728 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
729 /* inputs */
730 /* PW 1/2/5 (1ah/1bh/1eh) */
731 parm = AC_PWRST_D3;
732 set_pin_power_state(codec, 0x1a, &parm);
733 set_pin_power_state(codec, 0x1b, &parm);
734 set_pin_power_state(codec, 0x1e, &parm);
735 if (imux_is_smixer)
736 parm = AC_PWRST_D0;
737 /* SW0 (17h), AIW0(13h) */
738 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
739 parm);
740 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
741 parm);
742
743 parm = AC_PWRST_D3;
744 set_pin_power_state(codec, 0x1e, &parm);
745 /* PW11 (22h) */
746 if (spec->dmic_enabled)
747 set_pin_power_state(codec, 0x22, &parm);
748 else
749 snd_hda_codec_write(
750 codec, 0x22, 0,
751 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
752
753 /* SW2(26h), AIW1(14h) */
754 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
755 parm);
756 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
757 parm);
758
759 /* outputs */
760 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
761 parm = AC_PWRST_D3;
762 set_pin_power_state(codec, 0x19, &parm);
763 /* Smart 5.1 PW2(1bh) */
764 if (spec->smart51_enabled)
765 set_pin_power_state(codec, 0x1b, &parm);
766 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
767 parm);
768 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
769 parm);
770
771 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
772 parm = AC_PWRST_D3;
773 set_pin_power_state(codec, 0x23, &parm);
774 /* Smart 5.1 PW1(1ah) */
775 if (spec->smart51_enabled)
776 set_pin_power_state(codec, 0x1a, &parm);
777 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
778 parm);
779
780 /* Smart 5.1 PW5(1eh) */
781 if (spec->smart51_enabled)
782 set_pin_power_state(codec, 0x1e, &parm);
783 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
784 parm);
785
786 /* Mono out */
787 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
788 present = snd_hda_jack_detect(codec, 0x1c);
789 if (present)
790 mono_out = 0;
791 else {
792 present = snd_hda_jack_detect(codec, 0x1d);
793 if (!spec->hp_independent_mode && present)
794 mono_out = 0;
795 else
796 mono_out = 1;
797 }
798 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
799 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
800 parm);
801 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
802 parm);
803 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
804 parm);
805
806 /* PW 3/4 (1ch/1dh) */
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x1c, &parm);
809 set_pin_power_state(codec, 0x1d, &parm);
810 /* HP Independent Mode, power on AOW3 */
811 if (spec->hp_independent_mode)
812 snd_hda_codec_write(codec, 0x25, 0,
813 AC_VERB_SET_POWER_STATE, parm);
814
815 /* force to D0 for internal Speaker */
816 /* MW0 (16h), AOW0 (10h) */
817 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
818 imux_is_smixer ? AC_PWRST_D0 : parm);
819 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
820 mono_out ? AC_PWRST_D0 : parm);
821 } else if (spec->codec_type == VT2002P) {
822 unsigned int present;
823 /* MUX9 (1eh) = stereo mixer */
824 imux_is_smixer = snd_hda_codec_read(
825 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
826 /* inputs */
827 /* PW 5/6/7 (29h/2ah/2bh) */
828 parm = AC_PWRST_D3;
829 set_pin_power_state(codec, 0x29, &parm);
830 set_pin_power_state(codec, 0x2a, &parm);
831 set_pin_power_state(codec, 0x2b, &parm);
832 if (imux_is_smixer)
833 parm = AC_PWRST_D0;
834 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
835 snd_hda_codec_write(codec, 0x1e, 0,
836 AC_VERB_SET_POWER_STATE, parm);
837 snd_hda_codec_write(codec, 0x1f, 0,
838 AC_VERB_SET_POWER_STATE, parm);
839 snd_hda_codec_write(codec, 0x10, 0,
840 AC_VERB_SET_POWER_STATE, parm);
841 snd_hda_codec_write(codec, 0x11, 0,
842 AC_VERB_SET_POWER_STATE, parm);
843
844 /* outputs */
845 /* AOW0 (8h)*/
846 snd_hda_codec_write(codec, 0x8, 0,
847 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
848
849 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
850 parm = AC_PWRST_D3;
851 set_pin_power_state(codec, 0x26, &parm);
852 snd_hda_codec_write(codec, 0x1c, 0,
853 AC_VERB_SET_POWER_STATE, parm);
854 snd_hda_codec_write(codec, 0x37,
855 0, AC_VERB_SET_POWER_STATE, parm);
856
857 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
858 parm = AC_PWRST_D3;
859 set_pin_power_state(codec, 0x25, &parm);
860 snd_hda_codec_write(codec, 0x19, 0,
861 AC_VERB_SET_POWER_STATE, parm);
862 snd_hda_codec_write(codec, 0x35, 0,
863 AC_VERB_SET_POWER_STATE, parm);
864 if (spec->hp_independent_mode) {
865 snd_hda_codec_write(codec, 0x9, 0,
866 AC_VERB_SET_POWER_STATE, parm);
867 }
868
869 /* Class-D */
870 /* PW0 (24h), MW0(18h), MUX0(34h) */
871 present = snd_hda_jack_detect(codec, 0x25);
872 parm = AC_PWRST_D3;
873 set_pin_power_state(codec, 0x24, &parm);
874 if (present) {
875 snd_hda_codec_write(
876 codec, 0x18, 0,
877 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
878 snd_hda_codec_write(
879 codec, 0x34, 0,
880 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
881 } else {
882 snd_hda_codec_write(
883 codec, 0x18, 0,
884 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
885 snd_hda_codec_write(
886 codec, 0x34, 0,
887 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
888 }
889
890 /* Mono Out */
891 /* PW15 (31h), MW8(17h), MUX8(3bh) */
892 present = snd_hda_jack_detect(codec, 0x26);
893 parm = AC_PWRST_D3;
894 set_pin_power_state(codec, 0x31, &parm);
895 if (present) {
896 snd_hda_codec_write(
897 codec, 0x17, 0,
898 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
899 snd_hda_codec_write(
900 codec, 0x3b, 0,
901 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
902 } else {
903 snd_hda_codec_write(
904 codec, 0x17, 0,
905 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
906 snd_hda_codec_write(
907 codec, 0x3b, 0,
908 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
909 }
910
911 /* MW9 (21h) */
912 if (imux_is_smixer || !is_aa_path_mute(codec))
913 snd_hda_codec_write(
914 codec, 0x21, 0,
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
916 else
917 snd_hda_codec_write(
918 codec, 0x21, 0,
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 } else if (spec->codec_type == VT1812) {
921 unsigned int present;
922 /* MUX10 (1eh) = stereo mixer */
923 imux_is_smixer = snd_hda_codec_read(
924 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
925 /* inputs */
926 /* PW 5/6/7 (29h/2ah/2bh) */
927 parm = AC_PWRST_D3;
928 set_pin_power_state(codec, 0x29, &parm);
929 set_pin_power_state(codec, 0x2a, &parm);
930 set_pin_power_state(codec, 0x2b, &parm);
931 if (imux_is_smixer)
932 parm = AC_PWRST_D0;
933 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
934 snd_hda_codec_write(codec, 0x1e, 0,
935 AC_VERB_SET_POWER_STATE, parm);
936 snd_hda_codec_write(codec, 0x1f, 0,
937 AC_VERB_SET_POWER_STATE, parm);
938 snd_hda_codec_write(codec, 0x10, 0,
939 AC_VERB_SET_POWER_STATE, parm);
940 snd_hda_codec_write(codec, 0x11, 0,
941 AC_VERB_SET_POWER_STATE, parm);
942
943 /* outputs */
944 /* AOW0 (8h)*/
945 snd_hda_codec_write(codec, 0x8, 0,
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
947
948 /* PW4 (28h), MW4 (18h), MUX4(38h) */
949 parm = AC_PWRST_D3;
950 set_pin_power_state(codec, 0x28, &parm);
951 snd_hda_codec_write(codec, 0x18, 0,
952 AC_VERB_SET_POWER_STATE, parm);
953 snd_hda_codec_write(codec, 0x38, 0,
954 AC_VERB_SET_POWER_STATE, parm);
955
956 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
957 parm = AC_PWRST_D3;
958 set_pin_power_state(codec, 0x25, &parm);
959 snd_hda_codec_write(codec, 0x15, 0,
960 AC_VERB_SET_POWER_STATE, parm);
961 snd_hda_codec_write(codec, 0x35, 0,
962 AC_VERB_SET_POWER_STATE, parm);
963 if (spec->hp_independent_mode) {
964 snd_hda_codec_write(codec, 0x9, 0,
965 AC_VERB_SET_POWER_STATE, parm);
966 }
967
968 /* Internal Speaker */
969 /* PW0 (24h), MW0(14h), MUX0(34h) */
970 present = snd_hda_jack_detect(codec, 0x25);
971 parm = AC_PWRST_D3;
972 set_pin_power_state(codec, 0x24, &parm);
973 if (present) {
974 snd_hda_codec_write(codec, 0x14, 0,
975 AC_VERB_SET_POWER_STATE,
976 AC_PWRST_D3);
977 snd_hda_codec_write(codec, 0x34, 0,
978 AC_VERB_SET_POWER_STATE,
979 AC_PWRST_D3);
980 } else {
981 snd_hda_codec_write(codec, 0x14, 0,
982 AC_VERB_SET_POWER_STATE,
983 AC_PWRST_D0);
984 snd_hda_codec_write(codec, 0x34, 0,
985 AC_VERB_SET_POWER_STATE,
986 AC_PWRST_D0);
987 }
988 /* Mono Out */
989 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
990 present = snd_hda_jack_detect(codec, 0x28);
991 parm = AC_PWRST_D3;
992 set_pin_power_state(codec, 0x31, &parm);
993 if (present) {
994 snd_hda_codec_write(codec, 0x1c, 0,
995 AC_VERB_SET_POWER_STATE,
996 AC_PWRST_D3);
997 snd_hda_codec_write(codec, 0x3c, 0,
998 AC_VERB_SET_POWER_STATE,
999 AC_PWRST_D3);
1000 snd_hda_codec_write(codec, 0x3e, 0,
1001 AC_VERB_SET_POWER_STATE,
1002 AC_PWRST_D3);
1003 } else {
1004 snd_hda_codec_write(codec, 0x1c, 0,
1005 AC_VERB_SET_POWER_STATE,
1006 AC_PWRST_D0);
1007 snd_hda_codec_write(codec, 0x3c, 0,
1008 AC_VERB_SET_POWER_STATE,
1009 AC_PWRST_D0);
1010 snd_hda_codec_write(codec, 0x3e, 0,
1011 AC_VERB_SET_POWER_STATE,
1012 AC_PWRST_D0);
1013 }
1014
1015 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1016 parm = AC_PWRST_D3;
1017 set_pin_power_state(codec, 0x33, &parm);
1018 snd_hda_codec_write(codec, 0x1d, 0,
1019 AC_VERB_SET_POWER_STATE, parm);
1020 snd_hda_codec_write(codec, 0x3d, 0,
1021 AC_VERB_SET_POWER_STATE, parm);
1022
1023 /* MW9 (21h) */
1024 if (imux_is_smixer || !is_aa_path_mute(codec))
1025 snd_hda_codec_write(
1026 codec, 0x21, 0,
1027 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1028 else
1029 snd_hda_codec_write(
1030 codec, 0x21, 0,
1031 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1032 }
1033}
1034
367/* 1035/*
368 * input MUX handling 1036 * input MUX handling
369 */ 1037 */
@@ -395,6 +1063,14 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
395 1063
396 if (!spec->mux_nids[adc_idx]) 1064 if (!spec->mux_nids[adc_idx])
397 return -EINVAL; 1065 return -EINVAL;
1066 /* switch to D0 beofre change index */
1067 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1068 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1069 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1071 /* update jack power state */
1072 set_jack_power_state(codec);
1073
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 1074 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 spec->mux_nids[adc_idx], 1075 spec->mux_nids[adc_idx],
400 &spec->cur_mux[adc_idx]); 1076 &spec->cur_mux[adc_idx]);
@@ -413,16 +1089,74 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
413{ 1089{
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct via_spec *spec = codec->spec; 1091 struct via_spec *spec = codec->spec;
416 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1092 hda_nid_t nid;
417 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0, 1093 unsigned int pinsel;
418 AC_VERB_GET_CONNECT_SEL, 1094
419 0x00); 1095 switch (spec->codec_type) {
420 1096 case VT1718S:
1097 nid = 0x34;
1098 break;
1099 case VT2002P:
1100 nid = 0x35;
1101 break;
1102 case VT1812:
1103 nid = 0x3d;
1104 break;
1105 default:
1106 nid = spec->autocfg.hp_pins[0];
1107 break;
1108 }
1109 /* use !! to translate conn sel 2 for VT1718S */
1110 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1111 AC_VERB_GET_CONNECT_SEL,
1112 0x00);
421 ucontrol->value.enumerated.item[0] = pinsel; 1113 ucontrol->value.enumerated.item[0] = pinsel;
422 1114
423 return 0; 1115 return 0;
424} 1116}
425 1117
1118static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1119{
1120 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1121 if (ctl) {
1122 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1123 ctl->vd[0].access |= active
1124 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1125 snd_ctl_notify(codec->bus->card,
1126 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1127 }
1128}
1129
1130static int update_side_mute_status(struct hda_codec *codec)
1131{
1132 /* mute side channel */
1133 struct via_spec *spec = codec->spec;
1134 unsigned int parm = spec->hp_independent_mode
1135 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1136 hda_nid_t sw3;
1137
1138 switch (spec->codec_type) {
1139 case VT1708:
1140 sw3 = 0x1b;
1141 break;
1142 case VT1709_10CH:
1143 sw3 = 0x29;
1144 break;
1145 case VT1708B_8CH:
1146 case VT1708S:
1147 sw3 = 0x27;
1148 break;
1149 default:
1150 sw3 = 0;
1151 break;
1152 }
1153
1154 if (sw3)
1155 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1156 parm);
1157 return 0;
1158}
1159
426static int via_independent_hp_put(struct snd_kcontrol *kcontrol, 1160static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol) 1161 struct snd_ctl_elem_value *ucontrol)
428{ 1162{
@@ -430,47 +1164,46 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
430 struct via_spec *spec = codec->spec; 1164 struct via_spec *spec = codec->spec;
431 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1165 hda_nid_t nid = spec->autocfg.hp_pins[0];
432 unsigned int pinsel = ucontrol->value.enumerated.item[0]; 1166 unsigned int pinsel = ucontrol->value.enumerated.item[0];
433 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0, 1167 /* Get Independent Mode index of headphone pin widget */
434 AC_VERB_GET_CONNECT_LIST, 0) & 0xff; 1168 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
435 1169 ? 1 : 0;
436 if (con_nid == spec->multiout.hp_nid) { 1170
437 if (pinsel == 0) { 1171 switch (spec->codec_type) {
438 if (!spec->hp_independent_mode) { 1172 case VT1718S:
439 if (spec->multiout.num_dacs > 1) 1173 nid = 0x34;
440 spec->multiout.num_dacs -= 1; 1174 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
441 spec->hp_independent_mode = 1; 1175 spec->multiout.num_dacs = 4;
442 } 1176 break;
443 } else if (pinsel == 1) { 1177 case VT2002P:
444 if (spec->hp_independent_mode) { 1178 nid = 0x35;
445 if (spec->multiout.num_dacs > 1) 1179 break;
446 spec->multiout.num_dacs += 1; 1180 case VT1812:
447 spec->hp_independent_mode = 0; 1181 nid = 0x3d;
448 } 1182 break;
449 } 1183 default:
450 } else { 1184 nid = spec->autocfg.hp_pins[0];
451 if (pinsel == 0) { 1185 break;
452 if (spec->hp_independent_mode) { 1186 }
453 if (spec->multiout.num_dacs > 1) 1187 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
454 spec->multiout.num_dacs += 1; 1188
455 spec->hp_independent_mode = 0; 1189 if (spec->multiout.hp_nid && spec->multiout.hp_nid
456 } 1190 != spec->multiout.dac_nids[HDA_FRONT])
457 } else if (pinsel == 1) { 1191 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
458 if (!spec->hp_independent_mode) { 1192 0, 0, 0);
459 if (spec->multiout.num_dacs > 1) 1193
460 spec->multiout.num_dacs -= 1; 1194 update_side_mute_status(codec);
461 spec->hp_independent_mode = 1; 1195 /* update HP volume/swtich active state */
462 } 1196 if (spec->codec_type == VT1708S
463 } 1197 || spec->codec_type == VT1702
1198 || spec->codec_type == VT1718S
1199 || spec->codec_type == VT1716S
1200 || spec->codec_type == VT2002P
1201 || spec->codec_type == VT1812) {
1202 activate_ctl(codec, "Headphone Playback Volume",
1203 spec->hp_independent_mode);
1204 activate_ctl(codec, "Headphone Playback Switch",
1205 spec->hp_independent_mode);
464 } 1206 }
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; 1207 return 0;
475} 1208}
476 1209
@@ -486,6 +1219,175 @@ static struct snd_kcontrol_new via_hp_mixer[] = {
486 { } /* end */ 1219 { } /* end */
487}; 1220};
488 1221
1222static void notify_aa_path_ctls(struct hda_codec *codec)
1223{
1224 int i;
1225 struct snd_ctl_elem_id id;
1226 const char *labels[] = {"Mic", "Front Mic", "Line"};
1227
1228 memset(&id, 0, sizeof(id));
1229 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1230 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1231 sprintf(id.name, "%s Playback Volume", labels[i]);
1232 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1233 &id);
1234 }
1235}
1236
1237static void mute_aa_path(struct hda_codec *codec, int mute)
1238{
1239 struct via_spec *spec = codec->spec;
1240 hda_nid_t nid_mixer;
1241 int start_idx;
1242 int end_idx;
1243 int i;
1244 /* get nid of MW0 and start & end index */
1245 switch (spec->codec_type) {
1246 case VT1708:
1247 nid_mixer = 0x17;
1248 start_idx = 2;
1249 end_idx = 4;
1250 break;
1251 case VT1709_10CH:
1252 case VT1709_6CH:
1253 nid_mixer = 0x18;
1254 start_idx = 2;
1255 end_idx = 4;
1256 break;
1257 case VT1708B_8CH:
1258 case VT1708B_4CH:
1259 case VT1708S:
1260 case VT1716S:
1261 nid_mixer = 0x16;
1262 start_idx = 2;
1263 end_idx = 4;
1264 break;
1265 default:
1266 return;
1267 }
1268 /* check AA path's mute status */
1269 for (i = start_idx; i <= end_idx; i++) {
1270 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1271 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1272 HDA_AMP_MUTE, val);
1273 }
1274}
1275static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1276{
1277 int res = 0;
1278 int index;
1279 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1280 if (pin == spec->autocfg.input_pins[index]) {
1281 res = 1;
1282 break;
1283 }
1284 }
1285 return res;
1286}
1287
1288static int via_smart51_info(struct snd_kcontrol *kcontrol,
1289 struct snd_ctl_elem_info *uinfo)
1290{
1291 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1292 uinfo->count = 1;
1293 uinfo->value.integer.min = 0;
1294 uinfo->value.integer.max = 1;
1295 return 0;
1296}
1297
1298static int via_smart51_get(struct snd_kcontrol *kcontrol,
1299 struct snd_ctl_elem_value *ucontrol)
1300{
1301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1302 struct via_spec *spec = codec->spec;
1303 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1304 int on = 1;
1305 int i;
1306
1307 for (i = 0; i < ARRAY_SIZE(index); i++) {
1308 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1309 if (nid) {
1310 int ctl =
1311 snd_hda_codec_read(codec, nid, 0,
1312 AC_VERB_GET_PIN_WIDGET_CONTROL,
1313 0);
1314 if (i == AUTO_PIN_FRONT_MIC
1315 && spec->hp_independent_mode
1316 && spec->codec_type != VT1718S)
1317 continue; /* ignore FMic for independent HP */
1318 if (ctl & AC_PINCTL_IN_EN
1319 && !(ctl & AC_PINCTL_OUT_EN))
1320 on = 0;
1321 }
1322 }
1323 *ucontrol->value.integer.value = on;
1324 return 0;
1325}
1326
1327static int via_smart51_put(struct snd_kcontrol *kcontrol,
1328 struct snd_ctl_elem_value *ucontrol)
1329{
1330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1331 struct via_spec *spec = codec->spec;
1332 int out_in = *ucontrol->value.integer.value
1333 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1334 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1335 int i;
1336
1337 for (i = 0; i < ARRAY_SIZE(index); i++) {
1338 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1339 if (i == AUTO_PIN_FRONT_MIC
1340 && spec->hp_independent_mode
1341 && spec->codec_type != VT1718S)
1342 continue; /* don't retask FMic for independent HP */
1343 if (nid) {
1344 unsigned int parm = snd_hda_codec_read(
1345 codec, nid, 0,
1346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1347 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1348 parm |= out_in;
1349 snd_hda_codec_write(codec, nid, 0,
1350 AC_VERB_SET_PIN_WIDGET_CONTROL,
1351 parm);
1352 if (out_in == AC_PINCTL_OUT_EN) {
1353 mute_aa_path(codec, 1);
1354 notify_aa_path_ctls(codec);
1355 }
1356 if (spec->codec_type == VT1718S)
1357 snd_hda_codec_amp_stereo(
1358 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1359 HDA_AMP_UNMUTE);
1360 }
1361 if (i == AUTO_PIN_FRONT_MIC) {
1362 if (spec->codec_type == VT1708S
1363 || spec->codec_type == VT1716S) {
1364 /* input = index 1 (AOW3) */
1365 snd_hda_codec_write(
1366 codec, nid, 0,
1367 AC_VERB_SET_CONNECT_SEL, 1);
1368 snd_hda_codec_amp_stereo(
1369 codec, nid, HDA_OUTPUT,
1370 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1371 }
1372 }
1373 }
1374 spec->smart51_enabled = *ucontrol->value.integer.value;
1375 set_jack_power_state(codec);
1376 return 1;
1377}
1378
1379static struct snd_kcontrol_new via_smart51_mixer[] = {
1380 {
1381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1382 .name = "Smart 5.1",
1383 .count = 1,
1384 .info = via_smart51_info,
1385 .get = via_smart51_get,
1386 .put = via_smart51_put,
1387 },
1388 {} /* end */
1389};
1390
489/* capture mixer elements */ 1391/* capture mixer elements */
490static struct snd_kcontrol_new vt1708_capture_mixer[] = { 1392static struct snd_kcontrol_new vt1708_capture_mixer[] = {
491 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), 1393 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
@@ -506,6 +1408,112 @@ static struct snd_kcontrol_new vt1708_capture_mixer[] = {
506 }, 1408 },
507 { } /* end */ 1409 { } /* end */
508}; 1410};
1411
1412/* check AA path's mute statue */
1413static int is_aa_path_mute(struct hda_codec *codec)
1414{
1415 int mute = 1;
1416 hda_nid_t nid_mixer;
1417 int start_idx;
1418 int end_idx;
1419 int i;
1420 struct via_spec *spec = codec->spec;
1421 /* get nid of MW0 and start & end index */
1422 switch (spec->codec_type) {
1423 case VT1708B_8CH:
1424 case VT1708B_4CH:
1425 case VT1708S:
1426 case VT1716S:
1427 nid_mixer = 0x16;
1428 start_idx = 2;
1429 end_idx = 4;
1430 break;
1431 case VT1702:
1432 nid_mixer = 0x1a;
1433 start_idx = 1;
1434 end_idx = 3;
1435 break;
1436 case VT1718S:
1437 nid_mixer = 0x21;
1438 start_idx = 1;
1439 end_idx = 3;
1440 break;
1441 case VT2002P:
1442 case VT1812:
1443 nid_mixer = 0x21;
1444 start_idx = 0;
1445 end_idx = 2;
1446 break;
1447 default:
1448 return 0;
1449 }
1450 /* check AA path's mute status */
1451 for (i = start_idx; i <= end_idx; i++) {
1452 unsigned int con_list = snd_hda_codec_read(
1453 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1454 int shift = 8 * (i % 4);
1455 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1456 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1457 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1458 /* check mute status while the pin is connected */
1459 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1460 HDA_INPUT, i) >> 7;
1461 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1462 HDA_INPUT, i) >> 7;
1463 if (!mute_l || !mute_r) {
1464 mute = 0;
1465 break;
1466 }
1467 }
1468 }
1469 return mute;
1470}
1471
1472/* enter/exit analog low-current mode */
1473static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1474{
1475 struct via_spec *spec = codec->spec;
1476 static int saved_stream_idle = 1; /* saved stream idle status */
1477 int enable = is_aa_path_mute(codec);
1478 unsigned int verb = 0;
1479 unsigned int parm = 0;
1480
1481 if (stream_idle == -1) /* stream status did not change */
1482 enable = enable && saved_stream_idle;
1483 else {
1484 enable = enable && stream_idle;
1485 saved_stream_idle = stream_idle;
1486 }
1487
1488 /* decide low current mode's verb & parameter */
1489 switch (spec->codec_type) {
1490 case VT1708B_8CH:
1491 case VT1708B_4CH:
1492 verb = 0xf70;
1493 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1494 break;
1495 case VT1708S:
1496 case VT1718S:
1497 case VT1716S:
1498 verb = 0xf73;
1499 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1500 break;
1501 case VT1702:
1502 verb = 0xf73;
1503 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1504 break;
1505 case VT2002P:
1506 case VT1812:
1507 verb = 0xf93;
1508 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1509 break;
1510 default:
1511 return; /* other codecs are not supported */
1512 }
1513 /* send verb */
1514 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1515}
1516
509/* 1517/*
510 * generic initialization of ADC, input mixers and output mixers 1518 * generic initialization of ADC, input mixers and output mixers
511 */ 1519 */
@@ -534,9 +1542,9 @@ static struct hda_verb vt1708_volume_init_verbs[] = {
534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
535 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1543 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
536 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1544 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
537 1545
538 /* Setup default input to PW4 */ 1546 /* Setup default input MW0 to PW4 */
539 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 1547 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
540 /* PW9 Output enable */ 1548 /* PW9 Output enable */
541 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 1549 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
542 { } 1550 { }
@@ -547,30 +1555,13 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
547 struct snd_pcm_substream *substream) 1555 struct snd_pcm_substream *substream)
548{ 1556{
549 struct via_spec *spec = codec->spec; 1557 struct via_spec *spec = codec->spec;
1558 int idle = substream->pstr->substream_opened == 1
1559 && substream->ref_count == 0;
1560 analog_low_current_mode(codec, idle);
550 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1561 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
551 hinfo); 1562 hinfo);
552} 1563}
553 1564
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, 1565static void playback_multi_pcm_prep_0(struct hda_codec *codec,
575 unsigned int stream_tag, 1566 unsigned int stream_tag,
576 unsigned int format, 1567 unsigned int format,
@@ -615,8 +1606,8 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec,
615 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 1606 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
616 0, format); 1607 0, format);
617 1608
618 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && 1609 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
619 !spec->hp_independent_mode) 1610 && !spec->hp_independent_mode)
620 /* headphone out will just decode front left/right (stereo) */ 1611 /* headphone out will just decode front left/right (stereo) */
621 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 1612 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
622 0, format); 1613 0, format);
@@ -658,7 +1649,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
658 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1649 snd_hda_codec_setup_stream(codec, mout->hp_nid,
659 stream_tag, 0, format); 1650 stream_tag, 0, format);
660 } 1651 }
661 1652 vt1708_start_hp_work(spec);
662 return 0; 1653 return 0;
663} 1654}
664 1655
@@ -698,7 +1689,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
698 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1689 snd_hda_codec_setup_stream(codec, mout->hp_nid,
699 0, 0, 0); 1690 0, 0, 0);
700 } 1691 }
701 1692 vt1708_stop_hp_work(spec);
702 return 0; 1693 return 0;
703} 1694}
704 1695
@@ -779,7 +1770,7 @@ static struct hda_pcm_stream vt1708_pcm_analog_playback = {
779}; 1770};
780 1771
781static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { 1772static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
782 .substreams = 1, 1773 .substreams = 2,
783 .channels_min = 2, 1774 .channels_min = 2,
784 .channels_max = 8, 1775 .channels_max = 8,
785 .nid = 0x10, /* NID to query formats and rates */ 1776 .nid = 0x10, /* NID to query formats and rates */
@@ -790,8 +1781,8 @@ static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
790 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1781 .formats = SNDRV_PCM_FMTBIT_S16_LE,
791 .ops = { 1782 .ops = {
792 .open = via_playback_pcm_open, 1783 .open = via_playback_pcm_open,
793 .prepare = via_playback_pcm_prepare, 1784 .prepare = via_playback_multi_pcm_prepare,
794 .cleanup = via_playback_pcm_cleanup 1785 .cleanup = via_playback_multi_pcm_cleanup
795 }, 1786 },
796}; 1787};
797 1788
@@ -853,6 +1844,11 @@ static int via_build_controls(struct hda_codec *codec)
853 if (err < 0) 1844 if (err < 0)
854 return err; 1845 return err;
855 } 1846 }
1847
1848 /* init power states */
1849 set_jack_power_state(codec);
1850 analog_low_current_mode(codec, 1);
1851
856 via_free_kctls(codec); /* no longer needed */ 1852 via_free_kctls(codec); /* no longer needed */
857 return 0; 1853 return 0;
858} 1854}
@@ -866,8 +1862,10 @@ static int via_build_pcms(struct hda_codec *codec)
866 codec->pcm_info = info; 1862 codec->pcm_info = info;
867 1863
868 info->name = spec->stream_name_analog; 1864 info->name = spec->stream_name_analog;
869 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); 1865 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
870 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 1866 *(spec->stream_analog_playback);
1867 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1868 spec->multiout.dac_nids[0];
871 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); 1869 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
872 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 1870 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
873 1871
@@ -904,20 +1902,58 @@ static void via_free(struct hda_codec *codec)
904 return; 1902 return;
905 1903
906 via_free_kctls(codec); 1904 via_free_kctls(codec);
1905 vt1708_stop_hp_work(spec);
907 kfree(codec->spec); 1906 kfree(codec->spec);
908} 1907}
909 1908
910/* mute internal speaker if HP is plugged */ 1909/* mute internal speaker if HP is plugged */
911static void via_hp_automute(struct hda_codec *codec) 1910static void via_hp_automute(struct hda_codec *codec)
912{ 1911{
913 unsigned int present; 1912 unsigned int present = 0;
914 struct via_spec *spec = codec->spec; 1913 struct via_spec *spec = codec->spec;
915 1914
916 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, 1915 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
917 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1916
918 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], 1917 if (!spec->hp_independent_mode) {
919 HDA_OUTPUT, 0, HDA_AMP_MUTE, 1918 struct snd_ctl_elem_id id;
920 present ? HDA_AMP_MUTE : 0); 1919 /* auto mute */
1920 snd_hda_codec_amp_stereo(
1921 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1922 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1923 /* notify change */
1924 memset(&id, 0, sizeof(id));
1925 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1926 strcpy(id.name, "Front Playback Switch");
1927 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1928 &id);
1929 }
1930}
1931
1932/* mute mono out if HP or Line out is plugged */
1933static void via_mono_automute(struct hda_codec *codec)
1934{
1935 unsigned int hp_present, lineout_present;
1936 struct via_spec *spec = codec->spec;
1937
1938 if (spec->codec_type != VT1716S)
1939 return;
1940
1941 lineout_present = snd_hda_jack_detect(codec,
1942 spec->autocfg.line_out_pins[0]);
1943
1944 /* Mute Mono Out if Line Out is plugged */
1945 if (lineout_present) {
1946 snd_hda_codec_amp_stereo(
1947 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1948 return;
1949 }
1950
1951 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1952
1953 if (!spec->hp_independent_mode)
1954 snd_hda_codec_amp_stereo(
1955 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1956 hp_present ? HDA_AMP_MUTE : 0);
921} 1957}
922 1958
923static void via_gpio_control(struct hda_codec *codec) 1959static void via_gpio_control(struct hda_codec *codec)
@@ -968,15 +2004,83 @@ static void via_gpio_control(struct hda_codec *codec)
968 } 2004 }
969} 2005}
970 2006
2007/* mute Internal-Speaker if HP is plugged */
2008static void via_speaker_automute(struct hda_codec *codec)
2009{
2010 unsigned int hp_present;
2011 struct via_spec *spec = codec->spec;
2012
2013 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2014 return;
2015
2016 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2017
2018 if (!spec->hp_independent_mode) {
2019 struct snd_ctl_elem_id id;
2020 snd_hda_codec_amp_stereo(
2021 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2022 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2023 /* notify change */
2024 memset(&id, 0, sizeof(id));
2025 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2026 strcpy(id.name, "Speaker Playback Switch");
2027 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2028 &id);
2029 }
2030}
2031
2032/* mute line-out and internal speaker if HP is plugged */
2033static void via_hp_bind_automute(struct hda_codec *codec)
2034{
2035 /* use long instead of int below just to avoid an internal compiler
2036 * error with gcc 4.0.x
2037 */
2038 unsigned long hp_present, present = 0;
2039 struct via_spec *spec = codec->spec;
2040 int i;
2041
2042 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2043 return;
2044
2045 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2046
2047 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2048
2049 if (!spec->hp_independent_mode) {
2050 /* Mute Line-Outs */
2051 for (i = 0; i < spec->autocfg.line_outs; i++)
2052 snd_hda_codec_amp_stereo(
2053 codec, spec->autocfg.line_out_pins[i],
2054 HDA_OUTPUT, 0,
2055 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2056 if (hp_present)
2057 present = hp_present;
2058 }
2059 /* Speakers */
2060 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2061 snd_hda_codec_amp_stereo(
2062 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2063 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2064}
2065
2066
971/* unsolicited event for jack sensing */ 2067/* unsolicited event for jack sensing */
972static void via_unsol_event(struct hda_codec *codec, 2068static void via_unsol_event(struct hda_codec *codec,
973 unsigned int res) 2069 unsigned int res)
974{ 2070{
975 res >>= 26; 2071 res >>= 26;
976 if (res == VIA_HP_EVENT) 2072 if (res & VIA_HP_EVENT)
977 via_hp_automute(codec); 2073 via_hp_automute(codec);
978 else if (res == VIA_GPIO_EVENT) 2074 if (res & VIA_GPIO_EVENT)
979 via_gpio_control(codec); 2075 via_gpio_control(codec);
2076 if (res & VIA_JACK_EVENT)
2077 set_jack_power_state(codec);
2078 if (res & VIA_MONO_EVENT)
2079 via_mono_automute(codec);
2080 if (res & VIA_SPEAKER_EVENT)
2081 via_speaker_automute(codec);
2082 if (res & VIA_BIND_HP_EVENT)
2083 via_hp_bind_automute(codec);
980} 2084}
981 2085
982static int via_init(struct hda_codec *codec) 2086static int via_init(struct hda_codec *codec)
@@ -986,6 +2090,10 @@ static int via_init(struct hda_codec *codec)
986 for (i = 0; i < spec->num_iverbs; i++) 2090 for (i = 0; i < spec->num_iverbs; i++)
987 snd_hda_sequence_write(codec, spec->init_verbs[i]); 2091 snd_hda_sequence_write(codec, spec->init_verbs[i]);
988 2092
2093 spec->codec_type = get_codec_type(codec);
2094 if (spec->codec_type == VT1708BCE)
2095 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2096 same */
989 /* Lydia Add for EAPD enable */ 2097 /* Lydia Add for EAPD enable */
990 if (!spec->dig_in_nid) { /* No Digital In connection */ 2098 if (!spec->dig_in_nid) { /* No Digital In connection */
991 if (spec->dig_in_pin) { 2099 if (spec->dig_in_pin) {
@@ -1003,8 +2111,17 @@ static int via_init(struct hda_codec *codec)
1003 if (spec->slave_dig_outs[0]) 2111 if (spec->slave_dig_outs[0])
1004 codec->slave_dig_outs = spec->slave_dig_outs; 2112 codec->slave_dig_outs = spec->slave_dig_outs;
1005 2113
1006 return 0; 2114 return 0;
2115}
2116
2117#ifdef SND_HDA_NEEDS_RESUME
2118static int via_suspend(struct hda_codec *codec, pm_message_t state)
2119{
2120 struct via_spec *spec = codec->spec;
2121 vt1708_stop_hp_work(spec);
2122 return 0;
1007} 2123}
2124#endif
1008 2125
1009#ifdef CONFIG_SND_HDA_POWER_SAVE 2126#ifdef CONFIG_SND_HDA_POWER_SAVE
1010static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 2127static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
@@ -1021,6 +2138,9 @@ static struct hda_codec_ops via_patch_ops = {
1021 .build_pcms = via_build_pcms, 2138 .build_pcms = via_build_pcms,
1022 .init = via_init, 2139 .init = via_init,
1023 .free = via_free, 2140 .free = via_free,
2141#ifdef SND_HDA_NEEDS_RESUME
2142 .suspend = via_suspend,
2143#endif
1024#ifdef CONFIG_SND_HDA_POWER_SAVE 2144#ifdef CONFIG_SND_HDA_POWER_SAVE
1025 .check_power_status = via_check_power_status, 2145 .check_power_status = via_check_power_status,
1026#endif 2146#endif
@@ -1036,8 +2156,8 @@ static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1036 spec->multiout.num_dacs = cfg->line_outs; 2156 spec->multiout.num_dacs = cfg->line_outs;
1037 2157
1038 spec->multiout.dac_nids = spec->private_dac_nids; 2158 spec->multiout.dac_nids = spec->private_dac_nids;
1039 2159
1040 for(i = 0; i < 4; i++) { 2160 for (i = 0; i < 4; i++) {
1041 nid = cfg->line_out_pins[i]; 2161 nid = cfg->line_out_pins[i];
1042 if (nid) { 2162 if (nid) {
1043 /* config dac list */ 2163 /* config dac list */
@@ -1067,7 +2187,7 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1067{ 2187{
1068 char name[32]; 2188 char name[32];
1069 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2189 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1070 hda_nid_t nid, nid_vol = 0; 2190 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1071 int i, err; 2191 int i, err;
1072 2192
1073 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2193 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
@@ -1075,9 +2195,8 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1075 2195
1076 if (!nid) 2196 if (!nid)
1077 continue; 2197 continue;
1078 2198
1079 if (i != AUTO_SEQ_FRONT) 2199 nid_vol = nid_vols[i];
1080 nid_vol = 0x18 + i;
1081 2200
1082 if (i == AUTO_SEQ_CENLFE) { 2201 if (i == AUTO_SEQ_CENLFE) {
1083 /* Center/LFE */ 2202 /* Center/LFE */
@@ -1105,21 +2224,21 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1105 HDA_OUTPUT)); 2224 HDA_OUTPUT));
1106 if (err < 0) 2225 if (err < 0)
1107 return err; 2226 return err;
1108 } else if (i == AUTO_SEQ_FRONT){ 2227 } else if (i == AUTO_SEQ_FRONT) {
1109 /* add control to mixer index 0 */ 2228 /* add control to mixer index 0 */
1110 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2229 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1111 "Master Front Playback Volume", 2230 "Master Front Playback Volume",
1112 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2231 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1113 HDA_INPUT)); 2232 HDA_INPUT));
1114 if (err < 0) 2233 if (err < 0)
1115 return err; 2234 return err;
1116 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2235 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1117 "Master Front Playback Switch", 2236 "Master Front Playback Switch",
1118 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2237 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1119 HDA_INPUT)); 2238 HDA_INPUT));
1120 if (err < 0) 2239 if (err < 0)
1121 return err; 2240 return err;
1122 2241
1123 /* add control to PW3 */ 2242 /* add control to PW3 */
1124 sprintf(name, "%s Playback Volume", chname[i]); 2243 sprintf(name, "%s Playback Volume", chname[i]);
1125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2244 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1178,6 +2297,7 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1178 return 0; 2297 return 0;
1179 2298
1180 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ 2299 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2300 spec->hp_independent_mode_index = 1;
1181 2301
1182 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2302 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1183 "Headphone Playback Volume", 2303 "Headphone Playback Volume",
@@ -1218,7 +2338,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1218 case 0x1d: /* Mic */ 2338 case 0x1d: /* Mic */
1219 idx = 2; 2339 idx = 2;
1220 break; 2340 break;
1221 2341
1222 case 0x1e: /* Line In */ 2342 case 0x1e: /* Line In */
1223 idx = 3; 2343 idx = 3;
1224 break; 2344 break;
@@ -1231,8 +2351,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1231 idx = 1; 2351 idx = 1;
1232 break; 2352 break;
1233 } 2353 }
1234 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2354 err = via_new_analog_input(spec, labels[i], idx, 0x17);
1235 idx, 0x17);
1236 if (err < 0) 2355 if (err < 0)
1237 return err; 2356 return err;
1238 imux->items[imux->num_items].label = labels[i]; 2357 imux->items[imux->num_items].label = labels[i];
@@ -1260,16 +2379,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); 2379 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1261 seqassoc = (unsigned char) get_defcfg_association(def_conf); 2380 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1262 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); 2381 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1263 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { 2382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
1264 if (seqassoc == 0xff) { 2383 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
1265 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); 2384 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1266 snd_hda_codec_set_pincfg(codec, nid, def_conf); 2385 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1267 }
1268 } 2386 }
1269 2387
1270 return; 2388 return;
1271} 2389}
1272 2390
2391static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_value *ucontrol)
2393{
2394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2395 struct via_spec *spec = codec->spec;
2396
2397 if (spec->codec_type != VT1708)
2398 return 0;
2399 spec->vt1708_jack_detectect =
2400 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2401 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2402 return 0;
2403}
2404
2405static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2406 struct snd_ctl_elem_value *ucontrol)
2407{
2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2409 struct via_spec *spec = codec->spec;
2410 int change;
2411
2412 if (spec->codec_type != VT1708)
2413 return 0;
2414 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2415 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2416 == !spec->vt1708_jack_detectect;
2417 if (spec->vt1708_jack_detectect) {
2418 mute_aa_path(codec, 1);
2419 notify_aa_path_ctls(codec);
2420 }
2421 return change;
2422}
2423
2424static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2425 {
2426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2427 .name = "Jack Detect",
2428 .count = 1,
2429 .info = snd_ctl_boolean_mono_info,
2430 .get = vt1708_jack_detectect_get,
2431 .put = vt1708_jack_detectect_put,
2432 },
2433 {} /* end */
2434};
2435
1273static int vt1708_parse_auto_config(struct hda_codec *codec) 2436static int vt1708_parse_auto_config(struct hda_codec *codec)
1274{ 2437{
1275 struct via_spec *spec = codec->spec; 2438 struct via_spec *spec = codec->spec;
@@ -1297,6 +2460,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1297 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); 2460 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1298 if (err < 0) 2461 if (err < 0)
1299 return err; 2462 return err;
2463 /* add jack detect on/off control */
2464 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2465 if (err < 0)
2466 return err;
1300 2467
1301 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2468 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1302 2469
@@ -1316,19 +2483,44 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1316 if (spec->hp_mux) 2483 if (spec->hp_mux)
1317 spec->mixers[spec->num_mixers++] = via_hp_mixer; 2484 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1318 2485
2486 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1319 return 1; 2487 return 1;
1320} 2488}
1321 2489
1322/* init callback for auto-configuration model -- overriding the default init */ 2490/* init callback for auto-configuration model -- overriding the default init */
1323static int via_auto_init(struct hda_codec *codec) 2491static int via_auto_init(struct hda_codec *codec)
1324{ 2492{
2493 struct via_spec *spec = codec->spec;
2494
1325 via_init(codec); 2495 via_init(codec);
1326 via_auto_init_multi_out(codec); 2496 via_auto_init_multi_out(codec);
1327 via_auto_init_hp_out(codec); 2497 via_auto_init_hp_out(codec);
1328 via_auto_init_analog_input(codec); 2498 via_auto_init_analog_input(codec);
2499 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2500 via_hp_bind_automute(codec);
2501 } else {
2502 via_hp_automute(codec);
2503 via_speaker_automute(codec);
2504 }
2505
1329 return 0; 2506 return 0;
1330} 2507}
1331 2508
2509static void vt1708_update_hp_jack_state(struct work_struct *work)
2510{
2511 struct via_spec *spec = container_of(work, struct via_spec,
2512 vt1708_hp_work.work);
2513 if (spec->codec_type != VT1708)
2514 return;
2515 /* if jack state toggled */
2516 if (spec->vt1708_hp_present
2517 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2518 spec->vt1708_hp_present ^= 1;
2519 via_hp_automute(spec->codec);
2520 }
2521 vt1708_start_hp_work(spec);
2522}
2523
1332static int get_mux_nids(struct hda_codec *codec) 2524static int get_mux_nids(struct hda_codec *codec)
1333{ 2525{
1334 struct via_spec *spec = codec->spec; 2526 struct via_spec *spec = codec->spec;
@@ -1378,7 +2570,7 @@ static int patch_vt1708(struct hda_codec *codec)
1378 "from BIOS. Using genenic mode...\n"); 2570 "from BIOS. Using genenic mode...\n");
1379 } 2571 }
1380 2572
1381 2573
1382 spec->stream_name_analog = "VT1708 Analog"; 2574 spec->stream_name_analog = "VT1708 Analog";
1383 spec->stream_analog_playback = &vt1708_pcm_analog_playback; 2575 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1384 /* disable 32bit format on VT1708 */ 2576 /* disable 32bit format on VT1708 */
@@ -1390,7 +2582,7 @@ static int patch_vt1708(struct hda_codec *codec)
1390 spec->stream_digital_playback = &vt1708_pcm_digital_playback; 2582 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1391 spec->stream_digital_capture = &vt1708_pcm_digital_capture; 2583 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1392 2584
1393 2585
1394 if (!spec->adc_nids && spec->input_mux) { 2586 if (!spec->adc_nids && spec->input_mux) {
1395 spec->adc_nids = vt1708_adc_nids; 2587 spec->adc_nids = vt1708_adc_nids;
1396 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); 2588 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
@@ -1405,7 +2597,8 @@ static int patch_vt1708(struct hda_codec *codec)
1405#ifdef CONFIG_SND_HDA_POWER_SAVE 2597#ifdef CONFIG_SND_HDA_POWER_SAVE
1406 spec->loopback.amplist = vt1708_loopbacks; 2598 spec->loopback.amplist = vt1708_loopbacks;
1407#endif 2599#endif
1408 2600 spec->codec = codec;
2601 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
1409 return 0; 2602 return 0;
1410} 2603}
1411 2604
@@ -1433,7 +2626,8 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1433}; 2626};
1434 2627
1435static struct hda_verb vt1709_uniwill_init_verbs[] = { 2628static struct hda_verb vt1709_uniwill_init_verbs[] = {
1436 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 2629 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2630 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
1437 { } 2631 { }
1438}; 2632};
1439 2633
@@ -1473,8 +2667,8 @@ static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1473 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2667 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1474 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2668 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1475 2669
1476 /* Set input of PW4 as AOW4 */ 2670 /* Set input of PW4 as MW0 */
1477 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 2671 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1478 /* PW9 Output enable */ 2672 /* PW9 Output enable */
1479 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 2673 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1480 { } 2674 { }
@@ -1487,8 +2681,8 @@ static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1487 .nid = 0x10, /* NID to query formats and rates */ 2681 .nid = 0x10, /* NID to query formats and rates */
1488 .ops = { 2682 .ops = {
1489 .open = via_playback_pcm_open, 2683 .open = via_playback_pcm_open,
1490 .prepare = via_playback_pcm_prepare, 2684 .prepare = via_playback_multi_pcm_prepare,
1491 .cleanup = via_playback_pcm_cleanup 2685 .cleanup = via_playback_multi_pcm_cleanup,
1492 }, 2686 },
1493}; 2687};
1494 2688
@@ -1499,8 +2693,8 @@ static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1499 .nid = 0x10, /* NID to query formats and rates */ 2693 .nid = 0x10, /* NID to query formats and rates */
1500 .ops = { 2694 .ops = {
1501 .open = via_playback_pcm_open, 2695 .open = via_playback_pcm_open,
1502 .prepare = via_playback_pcm_prepare, 2696 .prepare = via_playback_multi_pcm_prepare,
1503 .cleanup = via_playback_pcm_cleanup 2697 .cleanup = via_playback_multi_pcm_cleanup,
1504 }, 2698 },
1505}; 2699};
1506 2700
@@ -1575,11 +2769,11 @@ static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1575 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ 2769 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1576 2770
1577 } else if (cfg->line_outs == 3) { /* 6 channels */ 2771 } else if (cfg->line_outs == 3) { /* 6 channels */
1578 for(i = 0; i < cfg->line_outs; i++) { 2772 for (i = 0; i < cfg->line_outs; i++) {
1579 nid = cfg->line_out_pins[i]; 2773 nid = cfg->line_out_pins[i];
1580 if (nid) { 2774 if (nid) {
1581 /* config dac list */ 2775 /* config dac list */
1582 switch(i) { 2776 switch (i) {
1583 case AUTO_SEQ_FRONT: 2777 case AUTO_SEQ_FRONT:
1584 /* AOW0 */ 2778 /* AOW0 */
1585 spec->multiout.dac_nids[i] = 0x10; 2779 spec->multiout.dac_nids[i] = 0x10;
@@ -1608,56 +2802,58 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1608{ 2802{
1609 char name[32]; 2803 char name[32];
1610 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2804 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1611 hda_nid_t nid = 0; 2805 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
1612 int i, err; 2806 int i, err;
1613 2807
1614 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2808 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1615 nid = cfg->line_out_pins[i]; 2809 nid = cfg->line_out_pins[i];
1616 2810
1617 if (!nid) 2811 if (!nid)
1618 continue; 2812 continue;
1619 2813
2814 nid_vol = nid_vols[i];
2815
1620 if (i == AUTO_SEQ_CENLFE) { 2816 if (i == AUTO_SEQ_CENLFE) {
1621 /* Center/LFE */ 2817 /* Center/LFE */
1622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2818 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1623 "Center Playback Volume", 2819 "Center Playback Volume",
1624 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2820 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1625 HDA_OUTPUT)); 2821 HDA_OUTPUT));
1626 if (err < 0) 2822 if (err < 0)
1627 return err; 2823 return err;
1628 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2824 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1629 "LFE Playback Volume", 2825 "LFE Playback Volume",
1630 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2826 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1631 HDA_OUTPUT)); 2827 HDA_OUTPUT));
1632 if (err < 0) 2828 if (err < 0)
1633 return err; 2829 return err;
1634 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2830 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1635 "Center Playback Switch", 2831 "Center Playback Switch",
1636 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2832 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1637 HDA_OUTPUT)); 2833 HDA_OUTPUT));
1638 if (err < 0) 2834 if (err < 0)
1639 return err; 2835 return err;
1640 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2836 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1641 "LFE Playback Switch", 2837 "LFE Playback Switch",
1642 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2838 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1643 HDA_OUTPUT)); 2839 HDA_OUTPUT));
1644 if (err < 0) 2840 if (err < 0)
1645 return err; 2841 return err;
1646 } else if (i == AUTO_SEQ_FRONT){ 2842 } else if (i == AUTO_SEQ_FRONT) {
1647 /* add control to mixer index 0 */ 2843 /* ADD control to mixer index 0 */
1648 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2844 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1649 "Master Front Playback Volume", 2845 "Master Front Playback Volume",
1650 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2846 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1651 HDA_INPUT)); 2847 HDA_INPUT));
1652 if (err < 0) 2848 if (err < 0)
1653 return err; 2849 return err;
1654 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2850 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1655 "Master Front Playback Switch", 2851 "Master Front Playback Switch",
1656 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2852 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1657 HDA_INPUT)); 2853 HDA_INPUT));
1658 if (err < 0) 2854 if (err < 0)
1659 return err; 2855 return err;
1660 2856
1661 /* add control to PW3 */ 2857 /* add control to PW3 */
1662 sprintf(name, "%s Playback Volume", chname[i]); 2858 sprintf(name, "%s Playback Volume", chname[i]);
1663 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2859 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1674,26 +2870,26 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1674 } else if (i == AUTO_SEQ_SURROUND) { 2870 } else if (i == AUTO_SEQ_SURROUND) {
1675 sprintf(name, "%s Playback Volume", chname[i]); 2871 sprintf(name, "%s Playback Volume", chname[i]);
1676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2872 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1677 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2873 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1678 HDA_OUTPUT)); 2874 HDA_OUTPUT));
1679 if (err < 0) 2875 if (err < 0)
1680 return err; 2876 return err;
1681 sprintf(name, "%s Playback Switch", chname[i]); 2877 sprintf(name, "%s Playback Switch", chname[i]);
1682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2878 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1683 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2879 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1684 HDA_OUTPUT)); 2880 HDA_OUTPUT));
1685 if (err < 0) 2881 if (err < 0)
1686 return err; 2882 return err;
1687 } else if (i == AUTO_SEQ_SIDE) { 2883 } else if (i == AUTO_SEQ_SIDE) {
1688 sprintf(name, "%s Playback Volume", chname[i]); 2884 sprintf(name, "%s Playback Volume", chname[i]);
1689 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2885 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1690 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2886 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1691 HDA_OUTPUT)); 2887 HDA_OUTPUT));
1692 if (err < 0) 2888 if (err < 0)
1693 return err; 2889 return err;
1694 sprintf(name, "%s Playback Switch", chname[i]); 2890 sprintf(name, "%s Playback Switch", chname[i]);
1695 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2891 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1696 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2892 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1697 HDA_OUTPUT)); 2893 HDA_OUTPUT));
1698 if (err < 0) 2894 if (err < 0)
1699 return err; 2895 return err;
@@ -1714,6 +2910,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; 2910 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1715 else if (spec->multiout.num_dacs == 3) /* 6 channels */ 2911 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1716 spec->multiout.hp_nid = 0; 2912 spec->multiout.hp_nid = 0;
2913 spec->hp_independent_mode_index = 1;
1717 2914
1718 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2915 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1719 "Headphone Playback Volume", 2916 "Headphone Playback Volume",
@@ -1752,7 +2949,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1752 case 0x1d: /* Mic */ 2949 case 0x1d: /* Mic */
1753 idx = 2; 2950 idx = 2;
1754 break; 2951 break;
1755 2952
1756 case 0x1e: /* Line In */ 2953 case 0x1e: /* Line In */
1757 idx = 3; 2954 idx = 3;
1758 break; 2955 break;
@@ -1765,8 +2962,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1765 idx = 1; 2962 idx = 1;
1766 break; 2963 break;
1767 } 2964 }
1768 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2965 err = via_new_analog_input(spec, labels[i], idx, 0x18);
1769 idx, 0x18);
1770 if (err < 0) 2966 if (err < 0)
1771 return err; 2967 return err;
1772 imux->items[imux->num_items].label = labels[i]; 2968 imux->items[imux->num_items].label = labels[i];
@@ -1816,6 +3012,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1816 if (spec->hp_mux) 3012 if (spec->hp_mux)
1817 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3013 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1818 3014
3015 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1819 return 1; 3016 return 1;
1820} 3017}
1821 3018
@@ -1861,7 +3058,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1861 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3058 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1862 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3059 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1863 3060
1864 3061
1865 if (!spec->adc_nids && spec->input_mux) { 3062 if (!spec->adc_nids && spec->input_mux) {
1866 spec->adc_nids = vt1709_adc_nids; 3063 spec->adc_nids = vt1709_adc_nids;
1867 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3064 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -1955,7 +3152,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1955 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3152 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1956 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3153 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1957 3154
1958 3155
1959 if (!spec->adc_nids && spec->input_mux) { 3156 if (!spec->adc_nids && spec->input_mux) {
1960 spec->adc_nids = vt1709_adc_nids; 3157 spec->adc_nids = vt1709_adc_nids;
1961 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3158 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -2024,7 +3221,7 @@ static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2024 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 3221 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2025 3222
2026 /* Setup default input to PW4 */ 3223 /* Setup default input to PW4 */
2027 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, 3224 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2028 /* PW9 Output enable */ 3225 /* PW9 Output enable */
2029 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3226 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2030 /* PW10 Input enable */ 3227 /* PW10 Input enable */
@@ -2068,10 +3265,29 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2068}; 3265};
2069 3266
2070static struct hda_verb vt1708B_uniwill_init_verbs[] = { 3267static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2071 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3268 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3269 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3270 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3271 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3272 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3273 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3274 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3275 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3276 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2072 { } 3277 { }
2073}; 3278};
2074 3279
3280static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3281 struct hda_codec *codec,
3282 struct snd_pcm_substream *substream)
3283{
3284 int idle = substream->pstr->substream_opened == 1
3285 && substream->ref_count == 0;
3286
3287 analog_low_current_mode(codec, idle);
3288 return 0;
3289}
3290
2075static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { 3291static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2076 .substreams = 2, 3292 .substreams = 2,
2077 .channels_min = 2, 3293 .channels_min = 2,
@@ -2080,7 +3296,8 @@ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2080 .ops = { 3296 .ops = {
2081 .open = via_playback_pcm_open, 3297 .open = via_playback_pcm_open,
2082 .prepare = via_playback_multi_pcm_prepare, 3298 .prepare = via_playback_multi_pcm_prepare,
2083 .cleanup = via_playback_multi_pcm_cleanup 3299 .cleanup = via_playback_multi_pcm_cleanup,
3300 .close = via_pcm_open_close
2084 }, 3301 },
2085}; 3302};
2086 3303
@@ -2102,8 +3319,10 @@ static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2102 .channels_max = 2, 3319 .channels_max = 2,
2103 .nid = 0x13, /* NID to query formats and rates */ 3320 .nid = 0x13, /* NID to query formats and rates */
2104 .ops = { 3321 .ops = {
3322 .open = via_pcm_open_close,
2105 .prepare = via_capture_pcm_prepare, 3323 .prepare = via_capture_pcm_prepare,
2106 .cleanup = via_capture_pcm_cleanup 3324 .cleanup = via_capture_pcm_cleanup,
3325 .close = via_pcm_open_close
2107 }, 3326 },
2108}; 3327};
2109 3328
@@ -2260,6 +3479,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2260 return 0; 3479 return 0;
2261 3480
2262 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ 3481 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3482 spec->hp_independent_mode_index = 1;
2263 3483
2264 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2265 "Headphone Playback Volume", 3485 "Headphone Playback Volume",
@@ -2313,8 +3533,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2313 idx = 1; 3533 idx = 1;
2314 break; 3534 break;
2315 } 3535 }
2316 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 3536 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2317 idx, 0x16);
2318 if (err < 0) 3537 if (err < 0)
2319 return err; 3538 return err;
2320 imux->items[imux->num_items].label = labels[i]; 3539 imux->items[imux->num_items].label = labels[i];
@@ -2364,6 +3583,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2364 if (spec->hp_mux) 3583 if (spec->hp_mux)
2365 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3584 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2366 3585
3586 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2367 return 1; 3587 return 1;
2368} 3588}
2369 3589
@@ -2376,12 +3596,14 @@ static struct hda_amp_list vt1708B_loopbacks[] = {
2376 { } /* end */ 3596 { } /* end */
2377}; 3597};
2378#endif 3598#endif
2379 3599static int patch_vt1708S(struct hda_codec *codec);
2380static int patch_vt1708B_8ch(struct hda_codec *codec) 3600static int patch_vt1708B_8ch(struct hda_codec *codec)
2381{ 3601{
2382 struct via_spec *spec; 3602 struct via_spec *spec;
2383 int err; 3603 int err;
2384 3604
3605 if (get_codec_type(codec) == VT1708BCE)
3606 return patch_vt1708S(codec);
2385 /* create a codec specific record */ 3607 /* create a codec specific record */
2386 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3608 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2387 if (spec == NULL) 3609 if (spec == NULL)
@@ -2483,29 +3705,15 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
2483 3705
2484/* Patch for VT1708S */ 3706/* Patch for VT1708S */
2485 3707
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 */ 3708/* capture mixer elements */
2502static struct snd_kcontrol_new vt1708S_capture_mixer[] = { 3709static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2503 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), 3710 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2504 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), 3711 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2505 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), 3712 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2506 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), 3713 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2507 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A), 3714 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
2508 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E), 3715 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3716 HDA_INPUT),
2509 { 3717 {
2510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2511 /* The multiple "Capture Source" controls confuse alsamixer 3719 /* The multiple "Capture Source" controls confuse alsamixer
@@ -2542,11 +3750,21 @@ static struct hda_verb vt1708S_volume_init_verbs[] = {
2542 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3750 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2543 /* Enable Mic Boost Volume backdoor */ 3751 /* Enable Mic Boost Volume backdoor */
2544 {0x1, 0xf98, 0x1}, 3752 {0x1, 0xf98, 0x1},
3753 /* don't bybass mixer */
3754 {0x1, 0xf88, 0xc0},
2545 { } 3755 { }
2546}; 3756};
2547 3757
2548static struct hda_verb vt1708S_uniwill_init_verbs[] = { 3758static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2549 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3759 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3760 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3761 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3762 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3763 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3764 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3765 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3766 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3767 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2550 { } 3768 { }
2551}; 3769};
2552 3770
@@ -2557,8 +3775,9 @@ static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2557 .nid = 0x10, /* NID to query formats and rates */ 3775 .nid = 0x10, /* NID to query formats and rates */
2558 .ops = { 3776 .ops = {
2559 .open = via_playback_pcm_open, 3777 .open = via_playback_pcm_open,
2560 .prepare = via_playback_pcm_prepare, 3778 .prepare = via_playback_multi_pcm_prepare,
2561 .cleanup = via_playback_pcm_cleanup 3779 .cleanup = via_playback_multi_pcm_cleanup,
3780 .close = via_pcm_open_close
2562 }, 3781 },
2563}; 3782};
2564 3783
@@ -2568,8 +3787,10 @@ static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2568 .channels_max = 2, 3787 .channels_max = 2,
2569 .nid = 0x13, /* NID to query formats and rates */ 3788 .nid = 0x13, /* NID to query formats and rates */
2570 .ops = { 3789 .ops = {
3790 .open = via_pcm_open_close,
2571 .prepare = via_capture_pcm_prepare, 3791 .prepare = via_capture_pcm_prepare,
2572 .cleanup = via_capture_pcm_cleanup 3792 .cleanup = via_capture_pcm_cleanup,
3793 .close = via_pcm_open_close
2573 }, 3794 },
2574}; 3795};
2575 3796
@@ -2726,6 +3947,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2726 return 0; 3947 return 0;
2727 3948
2728 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ 3949 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3950 spec->hp_independent_mode_index = 1;
2729 3951
2730 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3952 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2731 "Headphone Playback Volume", 3953 "Headphone Playback Volume",
@@ -2780,8 +4002,7 @@ static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2780 idx = 1; 4002 idx = 1;
2781 break; 4003 break;
2782 } 4004 }
2783 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 4005 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2784 idx, 0x16);
2785 if (err < 0) 4006 if (err < 0)
2786 return err; 4007 return err;
2787 imux->items[imux->num_items].label = labels[i]; 4008 imux->items[imux->num_items].label = labels[i];
@@ -2852,6 +4073,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
2852 if (spec->hp_mux) 4073 if (spec->hp_mux)
2853 spec->mixers[spec->num_mixers++] = via_hp_mixer; 4074 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2854 4075
4076 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2855 return 1; 4077 return 1;
2856} 4078}
2857 4079
@@ -2865,6 +4087,16 @@ static struct hda_amp_list vt1708S_loopbacks[] = {
2865}; 4087};
2866#endif 4088#endif
2867 4089
4090static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4091 int offset, int num_steps, int step_size)
4092{
4093 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4094 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4095 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4096 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4097 (0 << AC_AMPCAP_MUTE_SHIFT));
4098}
4099
2868static int patch_vt1708S(struct hda_codec *codec) 4100static int patch_vt1708S(struct hda_codec *codec)
2869{ 4101{
2870 struct via_spec *spec; 4102 struct via_spec *spec;
@@ -2890,17 +4122,25 @@ static int patch_vt1708S(struct hda_codec *codec)
2890 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; 4122 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2891 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; 4123 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2892 4124
2893 spec->stream_name_analog = "VT1708S Analog"; 4125 if (codec->vendor_id == 0x11060440)
4126 spec->stream_name_analog = "VT1818S Analog";
4127 else
4128 spec->stream_name_analog = "VT1708S Analog";
2894 spec->stream_analog_playback = &vt1708S_pcm_analog_playback; 4129 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2895 spec->stream_analog_capture = &vt1708S_pcm_analog_capture; 4130 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2896 4131
2897 spec->stream_name_digital = "VT1708S Digital"; 4132 if (codec->vendor_id == 0x11060440)
4133 spec->stream_name_digital = "VT1818S Digital";
4134 else
4135 spec->stream_name_digital = "VT1708S Digital";
2898 spec->stream_digital_playback = &vt1708S_pcm_digital_playback; 4136 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2899 4137
2900 if (!spec->adc_nids && spec->input_mux) { 4138 if (!spec->adc_nids && spec->input_mux) {
2901 spec->adc_nids = vt1708S_adc_nids; 4139 spec->adc_nids = vt1708S_adc_nids;
2902 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); 4140 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2903 get_mux_nids(codec); 4141 get_mux_nids(codec);
4142 override_mic_boost(codec, 0x1a, 0, 3, 40);
4143 override_mic_boost(codec, 0x1e, 0, 3, 40);
2904 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; 4144 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2905 spec->num_mixers++; 4145 spec->num_mixers++;
2906 } 4146 }
@@ -2913,6 +4153,16 @@ static int patch_vt1708S(struct hda_codec *codec)
2913 spec->loopback.amplist = vt1708S_loopbacks; 4153 spec->loopback.amplist = vt1708S_loopbacks;
2914#endif 4154#endif
2915 4155
4156 /* correct names for VT1708BCE */
4157 if (get_codec_type(codec) == VT1708BCE) {
4158 kfree(codec->chip_name);
4159 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4160 snprintf(codec->bus->card->mixername,
4161 sizeof(codec->bus->card->mixername),
4162 "%s %s", codec->vendor_name, codec->chip_name);
4163 spec->stream_name_analog = "VT1708BCE Analog";
4164 spec->stream_name_digital = "VT1708BCE Digital";
4165 }
2916 return 0; 4166 return 0;
2917} 4167}
2918 4168
@@ -2967,12 +4217,20 @@ static struct hda_verb vt1702_volume_init_verbs[] = {
2967 /* PW6 PW7 Output enable */ 4217 /* PW6 PW7 Output enable */
2968 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4218 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2969 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4219 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4220 /* mixer enable */
4221 {0x1, 0xF88, 0x3},
4222 /* GPIO 0~2 */
4223 {0x1, 0xF82, 0x3F},
2970 { } 4224 { }
2971}; 4225};
2972 4226
2973static struct hda_verb vt1702_uniwill_init_verbs[] = { 4227static struct hda_verb vt1702_uniwill_init_verbs[] = {
2974 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT}, 4228 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
2975 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 4229 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4230 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4231 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4232 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4233 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2976 { } 4234 { }
2977}; 4235};
2978 4236
@@ -2984,7 +4242,8 @@ static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2984 .ops = { 4242 .ops = {
2985 .open = via_playback_pcm_open, 4243 .open = via_playback_pcm_open,
2986 .prepare = via_playback_multi_pcm_prepare, 4244 .prepare = via_playback_multi_pcm_prepare,
2987 .cleanup = via_playback_multi_pcm_cleanup 4245 .cleanup = via_playback_multi_pcm_cleanup,
4246 .close = via_pcm_open_close
2988 }, 4247 },
2989}; 4248};
2990 4249
@@ -2994,8 +4253,10 @@ static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2994 .channels_max = 2, 4253 .channels_max = 2,
2995 .nid = 0x12, /* NID to query formats and rates */ 4254 .nid = 0x12, /* NID to query formats and rates */
2996 .ops = { 4255 .ops = {
4256 .open = via_pcm_open_close,
2997 .prepare = via_capture_pcm_prepare, 4257 .prepare = via_capture_pcm_prepare,
2998 .cleanup = via_capture_pcm_cleanup 4258 .cleanup = via_capture_pcm_cleanup,
4259 .close = via_pcm_open_close
2999 }, 4260 },
3000}; 4261};
3001 4262
@@ -3065,12 +4326,13 @@ static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3065 4326
3066static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) 4327static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3067{ 4328{
3068 int err; 4329 int err, i;
3069 4330 struct hda_input_mux *imux;
4331 static const char *texts[] = { "ON", "OFF", NULL};
3070 if (!pin) 4332 if (!pin)
3071 return 0; 4333 return 0;
3072
3073 spec->multiout.hp_nid = 0x1D; 4334 spec->multiout.hp_nid = 0x1D;
4335 spec->hp_independent_mode_index = 0;
3074 4336
3075 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 4337 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3076 "Headphone Playback Volume", 4338 "Headphone Playback Volume",
@@ -3084,8 +4346,18 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3084 if (err < 0) 4346 if (err < 0)
3085 return err; 4347 return err;
3086 4348
3087 create_hp_imux(spec); 4349 imux = &spec->private_imux[1];
3088 4350
4351 /* for hp mode select */
4352 i = 0;
4353 while (texts[i] != NULL) {
4354 imux->items[imux->num_items].label = texts[i];
4355 imux->items[imux->num_items].index = i;
4356 imux->num_items++;
4357 i++;
4358 }
4359
4360 spec->hp_mux = &spec->private_imux[1];
3089 return 0; 4361 return 0;
3090} 4362}
3091 4363
@@ -3121,8 +4393,7 @@ static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3121 idx = 3; 4393 idx = 3;
3122 break; 4394 break;
3123 } 4395 }
3124 err = via_new_analog_input(spec, cfg->input_pins[i], 4396 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
3125 labels[i], idx, 0x1A);
3126 if (err < 0) 4397 if (err < 0)
3127 return err; 4398 return err;
3128 imux->items[imux->num_items].label = labels[i]; 4399 imux->items[imux->num_items].label = labels[i];
@@ -3152,6 +4423,12 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3152 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); 4423 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3153 if (err < 0) 4424 if (err < 0)
3154 return err; 4425 return err;
4426 /* limit AA path volume to 0 dB */
4427 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4428 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4429 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4430 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4431 (1 << AC_AMPCAP_MUTE_SHIFT));
3155 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); 4432 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3156 if (err < 0) 4433 if (err < 0)
3157 return err; 4434 return err;
@@ -3185,8 +4462,6 @@ static int patch_vt1702(struct hda_codec *codec)
3185{ 4462{
3186 struct via_spec *spec; 4463 struct via_spec *spec;
3187 int err; 4464 int err;
3188 unsigned int response;
3189 unsigned char control;
3190 4465
3191 /* create a codec specific record */ 4466 /* create a codec specific record */
3192 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4467 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -3231,17 +4506,1638 @@ static int patch_vt1702(struct hda_codec *codec)
3231 spec->loopback.amplist = vt1702_loopbacks; 4506 spec->loopback.amplist = vt1702_loopbacks;
3232#endif 4507#endif
3233 4508
3234 /* Open backdoor */ 4509 return 0;
3235 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0); 4510}
3236 control = (unsigned char)(response & 0xff); 4511
3237 control |= 0x3; 4512/* Patch for VT1718S */
3238 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control); 4513
4514/* capture mixer elements */
4515static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4516 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4517 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4518 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4519 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4520 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4521 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4522 HDA_INPUT),
4523 {
4524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4525 /* The multiple "Capture Source" controls confuse alsamixer
4526 * So call somewhat different..
4527 */
4528 .name = "Input Source",
4529 .count = 2,
4530 .info = via_mux_enum_info,
4531 .get = via_mux_enum_get,
4532 .put = via_mux_enum_put,
4533 },
4534 { } /* end */
4535};
4536
4537static struct hda_verb vt1718S_volume_init_verbs[] = {
4538 /*
4539 * Unmute ADC0-1 and set the default input to mic-in
4540 */
4541 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4542 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4543
4544
4545 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4546 * mixer widget
4547 */
4548 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4549 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4550 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4552 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4554
4555 /* Setup default input of Front HP to MW9 */
4556 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4557 /* PW9 PW10 Output enable */
4558 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4559 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4560 /* PW11 Input enable */
4561 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4562 /* Enable Boost Volume backdoor */
4563 {0x1, 0xf88, 0x8},
4564 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4565 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4566 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4567 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4568 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4569 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4570 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4571 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4572 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4573 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4574 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4575 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4576 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4577 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4578 /* Unmute MW4's index 0 */
4579 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4580 { }
4581};
4582
4583
4584static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4585 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4586 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4587 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4588 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4589 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4590 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4591 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4592 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4593 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4594 { }
4595};
4596
4597static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4598 .substreams = 2,
4599 .channels_min = 2,
4600 .channels_max = 10,
4601 .nid = 0x8, /* NID to query formats and rates */
4602 .ops = {
4603 .open = via_playback_pcm_open,
4604 .prepare = via_playback_multi_pcm_prepare,
4605 .cleanup = via_playback_multi_pcm_cleanup,
4606 .close = via_pcm_open_close,
4607 },
4608};
4609
4610static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4611 .substreams = 2,
4612 .channels_min = 2,
4613 .channels_max = 2,
4614 .nid = 0x10, /* NID to query formats and rates */
4615 .ops = {
4616 .open = via_pcm_open_close,
4617 .prepare = via_capture_pcm_prepare,
4618 .cleanup = via_capture_pcm_cleanup,
4619 .close = via_pcm_open_close,
4620 },
4621};
4622
4623static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4624 .substreams = 2,
4625 .channels_min = 2,
4626 .channels_max = 2,
4627 /* NID is set in via_build_pcms */
4628 .ops = {
4629 .open = via_dig_playback_pcm_open,
4630 .close = via_dig_playback_pcm_close,
4631 .prepare = via_dig_playback_pcm_prepare,
4632 .cleanup = via_dig_playback_pcm_cleanup
4633 },
4634};
4635
4636static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4637 .substreams = 1,
4638 .channels_min = 2,
4639 .channels_max = 2,
4640};
4641
4642/* fill in the dac_nids table from the parsed pin configuration */
4643static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4644 const struct auto_pin_cfg *cfg)
4645{
4646 int i;
4647 hda_nid_t nid;
4648
4649 spec->multiout.num_dacs = cfg->line_outs;
4650
4651 spec->multiout.dac_nids = spec->private_dac_nids;
4652
4653 for (i = 0; i < 4; i++) {
4654 nid = cfg->line_out_pins[i];
4655 if (nid) {
4656 /* config dac list */
4657 switch (i) {
4658 case AUTO_SEQ_FRONT:
4659 spec->multiout.dac_nids[i] = 0x8;
4660 break;
4661 case AUTO_SEQ_CENLFE:
4662 spec->multiout.dac_nids[i] = 0xa;
4663 break;
4664 case AUTO_SEQ_SURROUND:
4665 spec->multiout.dac_nids[i] = 0x9;
4666 break;
4667 case AUTO_SEQ_SIDE:
4668 spec->multiout.dac_nids[i] = 0xb;
4669 break;
4670 }
4671 }
4672 }
4673
4674 return 0;
4675}
4676
4677/* add playback controls from the parsed DAC table */
4678static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4679 const struct auto_pin_cfg *cfg)
4680{
4681 char name[32];
4682 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4683 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4684 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4685 hda_nid_t nid, nid_vol, nid_mute = 0;
4686 int i, err;
4687
4688 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4689 nid = cfg->line_out_pins[i];
4690
4691 if (!nid)
4692 continue;
4693 nid_vol = nid_vols[i];
4694 nid_mute = nid_mutes[i];
4695
4696 if (i == AUTO_SEQ_CENLFE) {
4697 /* Center/LFE */
4698 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4699 "Center Playback Volume",
4700 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4701 HDA_OUTPUT));
4702 if (err < 0)
4703 return err;
4704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4705 "LFE Playback Volume",
4706 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4707 HDA_OUTPUT));
4708 if (err < 0)
4709 return err;
4710 err = via_add_control(
4711 spec, VIA_CTL_WIDGET_MUTE,
4712 "Center Playback Switch",
4713 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4714 HDA_OUTPUT));
4715 if (err < 0)
4716 return err;
4717 err = via_add_control(
4718 spec, VIA_CTL_WIDGET_MUTE,
4719 "LFE Playback Switch",
4720 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4721 HDA_OUTPUT));
4722 if (err < 0)
4723 return err;
4724 } else if (i == AUTO_SEQ_FRONT) {
4725 /* Front */
4726 sprintf(name, "%s Playback Volume", chname[i]);
4727 err = via_add_control(
4728 spec, VIA_CTL_WIDGET_VOL, name,
4729 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4730 if (err < 0)
4731 return err;
4732 sprintf(name, "%s Playback Switch", chname[i]);
4733 err = via_add_control(
4734 spec, VIA_CTL_WIDGET_MUTE, name,
4735 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4736 HDA_OUTPUT));
4737 if (err < 0)
4738 return err;
4739 } else {
4740 sprintf(name, "%s Playback Volume", chname[i]);
4741 err = via_add_control(
4742 spec, VIA_CTL_WIDGET_VOL, name,
4743 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4744 if (err < 0)
4745 return err;
4746 sprintf(name, "%s Playback Switch", chname[i]);
4747 err = via_add_control(
4748 spec, VIA_CTL_WIDGET_MUTE, name,
4749 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4750 HDA_OUTPUT));
4751 if (err < 0)
4752 return err;
4753 }
4754 }
4755 return 0;
4756}
4757
4758static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4759{
4760 int err;
4761
4762 if (!pin)
4763 return 0;
4764
4765 spec->multiout.hp_nid = 0xc; /* AOW4 */
4766 spec->hp_independent_mode_index = 1;
4767
4768 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4769 "Headphone Playback Volume",
4770 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4771 if (err < 0)
4772 return err;
4773
4774 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4775 "Headphone Playback Switch",
4776 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4777 if (err < 0)
4778 return err;
4779
4780 create_hp_imux(spec);
4781 return 0;
4782}
4783
4784/* create playback/capture controls for input pins */
4785static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4786 const struct auto_pin_cfg *cfg)
4787{
4788 static char *labels[] = {
4789 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4790 };
4791 struct hda_input_mux *imux = &spec->private_imux[0];
4792 int i, err, idx = 0;
4793
4794 /* for internal loopback recording select */
4795 imux->items[imux->num_items].label = "Stereo Mixer";
4796 imux->items[imux->num_items].index = 5;
4797 imux->num_items++;
4798
4799 for (i = 0; i < AUTO_PIN_LAST; i++) {
4800 if (!cfg->input_pins[i])
4801 continue;
4802
4803 switch (cfg->input_pins[i]) {
4804 case 0x2b: /* Mic */
4805 idx = 1;
4806 break;
4807
4808 case 0x2a: /* Line In */
4809 idx = 2;
4810 break;
4811
4812 case 0x29: /* Front Mic */
4813 idx = 3;
4814 break;
4815
4816 case 0x2c: /* CD */
4817 idx = 0;
4818 break;
4819 }
4820 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4821 if (err < 0)
4822 return err;
4823 imux->items[imux->num_items].label = labels[i];
4824 imux->items[imux->num_items].index = idx;
4825 imux->num_items++;
4826 }
4827 return 0;
4828}
4829
4830static int vt1718S_parse_auto_config(struct hda_codec *codec)
4831{
4832 struct via_spec *spec = codec->spec;
4833 int err;
4834
4835 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4836
4837 if (err < 0)
4838 return err;
4839 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4840 if (err < 0)
4841 return err;
4842 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4843 return 0; /* can't find valid BIOS pin config */
4844
4845 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4846 if (err < 0)
4847 return err;
4848 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4849 if (err < 0)
4850 return err;
4851 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4852 if (err < 0)
4853 return err;
4854
4855 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4856
4857 fill_dig_outs(codec);
4858
4859 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4860 spec->dig_in_nid = 0x13;
4861
4862 if (spec->kctls.list)
4863 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4864
4865 spec->input_mux = &spec->private_imux[0];
4866
4867 if (spec->hp_mux)
4868 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4869
4870 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4871
4872 return 1;
4873}
4874
4875#ifdef CONFIG_SND_HDA_POWER_SAVE
4876static struct hda_amp_list vt1718S_loopbacks[] = {
4877 { 0x21, HDA_INPUT, 1 },
4878 { 0x21, HDA_INPUT, 2 },
4879 { 0x21, HDA_INPUT, 3 },
4880 { 0x21, HDA_INPUT, 4 },
4881 { } /* end */
4882};
4883#endif
4884
4885static int patch_vt1718S(struct hda_codec *codec)
4886{
4887 struct via_spec *spec;
4888 int err;
3239 4889
3240 /* Enable GPIO 0&1 for volume&mute control */ 4890 /* create a codec specific record */
3241 /* Enable GPIO 2 for DMIC-DATA */ 4891 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3242 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0); 4892 if (spec == NULL)
3243 control = (unsigned char)((response >> 16) & 0x3f); 4893 return -ENOMEM;
3244 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control); 4894
4895 codec->spec = spec;
4896
4897 /* automatic parse from the BIOS config */
4898 err = vt1718S_parse_auto_config(codec);
4899 if (err < 0) {
4900 via_free(codec);
4901 return err;
4902 } else if (!err) {
4903 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4904 "from BIOS. Using genenic mode...\n");
4905 }
4906
4907 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4908 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4909
4910 if (codec->vendor_id == 0x11060441)
4911 spec->stream_name_analog = "VT2020 Analog";
4912 else if (codec->vendor_id == 0x11064441)
4913 spec->stream_name_analog = "VT1828S Analog";
4914 else
4915 spec->stream_name_analog = "VT1718S Analog";
4916 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4917 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4918
4919 if (codec->vendor_id == 0x11060441)
4920 spec->stream_name_digital = "VT2020 Digital";
4921 else if (codec->vendor_id == 0x11064441)
4922 spec->stream_name_digital = "VT1828S Digital";
4923 else
4924 spec->stream_name_digital = "VT1718S Digital";
4925 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4926 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4927 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4928
4929 if (!spec->adc_nids && spec->input_mux) {
4930 spec->adc_nids = vt1718S_adc_nids;
4931 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4932 get_mux_nids(codec);
4933 override_mic_boost(codec, 0x2b, 0, 3, 40);
4934 override_mic_boost(codec, 0x29, 0, 3, 40);
4935 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4936 spec->num_mixers++;
4937 }
4938
4939 codec->patch_ops = via_patch_ops;
4940
4941 codec->patch_ops.init = via_auto_init;
4942 codec->patch_ops.unsol_event = via_unsol_event;
4943
4944#ifdef CONFIG_SND_HDA_POWER_SAVE
4945 spec->loopback.amplist = vt1718S_loopbacks;
4946#endif
4947
4948 return 0;
4949}
4950
4951/* Patch for VT1716S */
4952
4953static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4954 struct snd_ctl_elem_info *uinfo)
4955{
4956 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4957 uinfo->count = 1;
4958 uinfo->value.integer.min = 0;
4959 uinfo->value.integer.max = 1;
4960 return 0;
4961}
4962
4963static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4964 struct snd_ctl_elem_value *ucontrol)
4965{
4966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4967 int index = 0;
4968
4969 index = snd_hda_codec_read(codec, 0x26, 0,
4970 AC_VERB_GET_CONNECT_SEL, 0);
4971 if (index != -1)
4972 *ucontrol->value.integer.value = index;
4973
4974 return 0;
4975}
4976
4977static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4978 struct snd_ctl_elem_value *ucontrol)
4979{
4980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4981 struct via_spec *spec = codec->spec;
4982 int index = *ucontrol->value.integer.value;
4983
4984 snd_hda_codec_write(codec, 0x26, 0,
4985 AC_VERB_SET_CONNECT_SEL, index);
4986 spec->dmic_enabled = index;
4987 set_jack_power_state(codec);
4988
4989 return 1;
4990}
4991
4992/* capture mixer elements */
4993static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4994 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4995 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4996 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4997 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4998 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4999 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5000 HDA_INPUT),
5001 {
5002 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5003 .name = "Input Source",
5004 .count = 1,
5005 .info = via_mux_enum_info,
5006 .get = via_mux_enum_get,
5007 .put = via_mux_enum_put,
5008 },
5009 { } /* end */
5010};
5011
5012static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5013 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5014 {
5015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5016 .name = "Digital Mic Capture Switch",
5017 .count = 1,
5018 .info = vt1716s_dmic_info,
5019 .get = vt1716s_dmic_get,
5020 .put = vt1716s_dmic_put,
5021 },
5022 {} /* end */
5023};
5024
5025
5026/* mono-out mixer elements */
5027static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5028 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5029 { } /* end */
5030};
5031
5032static struct hda_verb vt1716S_volume_init_verbs[] = {
5033 /*
5034 * Unmute ADC0-1 and set the default input to mic-in
5035 */
5036 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5037 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5038
5039
5040 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5041 * mixer widget
5042 */
5043 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5044 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5045 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5046 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5049
5050 /* MUX Indices: Stereo Mixer = 5 */
5051 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5052
5053 /* Setup default input of PW4 to MW0 */
5054 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5055
5056 /* Setup default input of SW1 as MW0 */
5057 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5058
5059 /* Setup default input of SW4 as AOW0 */
5060 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5061
5062 /* PW9 PW10 Output enable */
5063 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5064 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5065
5066 /* Unmute SW1, PW12 */
5067 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5068 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5069 /* PW12 Output enable */
5070 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5071 /* Enable Boost Volume backdoor */
5072 {0x1, 0xf8a, 0x80},
5073 /* don't bybass mixer */
5074 {0x1, 0xf88, 0xc0},
5075 /* Enable mono output */
5076 {0x1, 0xf90, 0x08},
5077 { }
5078};
5079
5080
5081static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5082 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5083 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5084 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5085 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5086 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5087 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5088 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5089 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5090 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5091 { }
5092};
5093
5094static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5095 .substreams = 2,
5096 .channels_min = 2,
5097 .channels_max = 6,
5098 .nid = 0x10, /* NID to query formats and rates */
5099 .ops = {
5100 .open = via_playback_pcm_open,
5101 .prepare = via_playback_multi_pcm_prepare,
5102 .cleanup = via_playback_multi_pcm_cleanup,
5103 .close = via_pcm_open_close,
5104 },
5105};
5106
5107static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5108 .substreams = 2,
5109 .channels_min = 2,
5110 .channels_max = 2,
5111 .nid = 0x13, /* NID to query formats and rates */
5112 .ops = {
5113 .open = via_pcm_open_close,
5114 .prepare = via_capture_pcm_prepare,
5115 .cleanup = via_capture_pcm_cleanup,
5116 .close = via_pcm_open_close,
5117 },
5118};
5119
5120static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5121 .substreams = 2,
5122 .channels_min = 2,
5123 .channels_max = 2,
5124 /* NID is set in via_build_pcms */
5125 .ops = {
5126 .open = via_dig_playback_pcm_open,
5127 .close = via_dig_playback_pcm_close,
5128 .prepare = via_dig_playback_pcm_prepare,
5129 .cleanup = via_dig_playback_pcm_cleanup
5130 },
5131};
5132
5133/* fill in the dac_nids table from the parsed pin configuration */
5134static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5135 const struct auto_pin_cfg *cfg)
5136{ int i;
5137 hda_nid_t nid;
5138
5139 spec->multiout.num_dacs = cfg->line_outs;
5140
5141 spec->multiout.dac_nids = spec->private_dac_nids;
5142
5143 for (i = 0; i < 3; i++) {
5144 nid = cfg->line_out_pins[i];
5145 if (nid) {
5146 /* config dac list */
5147 switch (i) {
5148 case AUTO_SEQ_FRONT:
5149 spec->multiout.dac_nids[i] = 0x10;
5150 break;
5151 case AUTO_SEQ_CENLFE:
5152 spec->multiout.dac_nids[i] = 0x25;
5153 break;
5154 case AUTO_SEQ_SURROUND:
5155 spec->multiout.dac_nids[i] = 0x11;
5156 break;
5157 }
5158 }
5159 }
5160
5161 return 0;
5162}
5163
5164/* add playback controls from the parsed DAC table */
5165static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5166 const struct auto_pin_cfg *cfg)
5167{
5168 char name[32];
5169 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5170 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5171 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5172 hda_nid_t nid, nid_vol, nid_mute;
5173 int i, err;
5174
5175 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5176 nid = cfg->line_out_pins[i];
5177
5178 if (!nid)
5179 continue;
5180
5181 nid_vol = nid_vols[i];
5182 nid_mute = nid_mutes[i];
5183
5184 if (i == AUTO_SEQ_CENLFE) {
5185 err = via_add_control(
5186 spec, VIA_CTL_WIDGET_VOL,
5187 "Center Playback Volume",
5188 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5189 if (err < 0)
5190 return err;
5191 err = via_add_control(
5192 spec, VIA_CTL_WIDGET_VOL,
5193 "LFE Playback Volume",
5194 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5195 if (err < 0)
5196 return err;
5197 err = via_add_control(
5198 spec, VIA_CTL_WIDGET_MUTE,
5199 "Center Playback Switch",
5200 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5201 HDA_OUTPUT));
5202 if (err < 0)
5203 return err;
5204 err = via_add_control(
5205 spec, VIA_CTL_WIDGET_MUTE,
5206 "LFE Playback Switch",
5207 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5208 HDA_OUTPUT));
5209 if (err < 0)
5210 return err;
5211 } else if (i == AUTO_SEQ_FRONT) {
5212
5213 err = via_add_control(
5214 spec, VIA_CTL_WIDGET_VOL,
5215 "Master Front Playback Volume",
5216 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5217 if (err < 0)
5218 return err;
5219 err = via_add_control(
5220 spec, VIA_CTL_WIDGET_MUTE,
5221 "Master Front Playback Switch",
5222 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5223 if (err < 0)
5224 return err;
5225
5226 sprintf(name, "%s Playback Volume", chname[i]);
5227 err = via_add_control(
5228 spec, VIA_CTL_WIDGET_VOL, name,
5229 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5230 if (err < 0)
5231 return err;
5232 sprintf(name, "%s Playback Switch", chname[i]);
5233 err = via_add_control(
5234 spec, VIA_CTL_WIDGET_MUTE, name,
5235 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5236 HDA_OUTPUT));
5237 if (err < 0)
5238 return err;
5239 } else {
5240 sprintf(name, "%s Playback Volume", chname[i]);
5241 err = via_add_control(
5242 spec, VIA_CTL_WIDGET_VOL, name,
5243 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5244 if (err < 0)
5245 return err;
5246 sprintf(name, "%s Playback Switch", chname[i]);
5247 err = via_add_control(
5248 spec, VIA_CTL_WIDGET_MUTE, name,
5249 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5250 HDA_OUTPUT));
5251 if (err < 0)
5252 return err;
5253 }
5254 }
5255 return 0;
5256}
5257
5258static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5259{
5260 int err;
5261
5262 if (!pin)
5263 return 0;
5264
5265 spec->multiout.hp_nid = 0x25; /* AOW3 */
5266 spec->hp_independent_mode_index = 1;
5267
5268 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5269 "Headphone Playback Volume",
5270 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5271 if (err < 0)
5272 return err;
5273
5274 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5275 "Headphone Playback Switch",
5276 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5277 if (err < 0)
5278 return err;
5279
5280 create_hp_imux(spec);
5281 return 0;
5282}
5283
5284/* create playback/capture controls for input pins */
5285static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5286 const struct auto_pin_cfg *cfg)
5287{
5288 static char *labels[] = {
5289 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5290 };
5291 struct hda_input_mux *imux = &spec->private_imux[0];
5292 int i, err, idx = 0;
5293
5294 /* for internal loopback recording select */
5295 imux->items[imux->num_items].label = "Stereo Mixer";
5296 imux->items[imux->num_items].index = 5;
5297 imux->num_items++;
5298
5299 for (i = 0; i < AUTO_PIN_LAST; i++) {
5300 if (!cfg->input_pins[i])
5301 continue;
5302
5303 switch (cfg->input_pins[i]) {
5304 case 0x1a: /* Mic */
5305 idx = 2;
5306 break;
5307
5308 case 0x1b: /* Line In */
5309 idx = 3;
5310 break;
5311
5312 case 0x1e: /* Front Mic */
5313 idx = 4;
5314 break;
5315
5316 case 0x1f: /* CD */
5317 idx = 1;
5318 break;
5319 }
5320 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5321 if (err < 0)
5322 return err;
5323 imux->items[imux->num_items].label = labels[i];
5324 imux->items[imux->num_items].index = idx-1;
5325 imux->num_items++;
5326 }
5327 return 0;
5328}
5329
5330static int vt1716S_parse_auto_config(struct hda_codec *codec)
5331{
5332 struct via_spec *spec = codec->spec;
5333 int err;
5334
5335 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5336 if (err < 0)
5337 return err;
5338 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5339 if (err < 0)
5340 return err;
5341 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5342 return 0; /* can't find valid BIOS pin config */
5343
5344 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5345 if (err < 0)
5346 return err;
5347 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5348 if (err < 0)
5349 return err;
5350 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5351 if (err < 0)
5352 return err;
5353
5354 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5355
5356 fill_dig_outs(codec);
5357
5358 if (spec->kctls.list)
5359 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5360
5361 spec->input_mux = &spec->private_imux[0];
5362
5363 if (spec->hp_mux)
5364 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5365
5366 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5367
5368 return 1;
5369}
5370
5371#ifdef CONFIG_SND_HDA_POWER_SAVE
5372static struct hda_amp_list vt1716S_loopbacks[] = {
5373 { 0x16, HDA_INPUT, 1 },
5374 { 0x16, HDA_INPUT, 2 },
5375 { 0x16, HDA_INPUT, 3 },
5376 { 0x16, HDA_INPUT, 4 },
5377 { } /* end */
5378};
5379#endif
5380
5381static int patch_vt1716S(struct hda_codec *codec)
5382{
5383 struct via_spec *spec;
5384 int err;
5385
5386 /* create a codec specific record */
5387 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5388 if (spec == NULL)
5389 return -ENOMEM;
5390
5391 codec->spec = spec;
5392
5393 /* automatic parse from the BIOS config */
5394 err = vt1716S_parse_auto_config(codec);
5395 if (err < 0) {
5396 via_free(codec);
5397 return err;
5398 } else if (!err) {
5399 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5400 "from BIOS. Using genenic mode...\n");
5401 }
5402
5403 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5404 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5405
5406 spec->stream_name_analog = "VT1716S Analog";
5407 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5408 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5409
5410 spec->stream_name_digital = "VT1716S Digital";
5411 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5412
5413 if (!spec->adc_nids && spec->input_mux) {
5414 spec->adc_nids = vt1716S_adc_nids;
5415 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5416 get_mux_nids(codec);
5417 override_mic_boost(codec, 0x1a, 0, 3, 40);
5418 override_mic_boost(codec, 0x1e, 0, 3, 40);
5419 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5420 spec->num_mixers++;
5421 }
5422
5423 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5424 spec->num_mixers++;
5425
5426 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5427
5428 codec->patch_ops = via_patch_ops;
5429
5430 codec->patch_ops.init = via_auto_init;
5431 codec->patch_ops.unsol_event = via_unsol_event;
5432
5433#ifdef CONFIG_SND_HDA_POWER_SAVE
5434 spec->loopback.amplist = vt1716S_loopbacks;
5435#endif
5436
5437 return 0;
5438}
5439
5440/* for vt2002P */
5441
5442/* capture mixer elements */
5443static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5444 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5445 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5446 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5447 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5448 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5449 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5450 HDA_INPUT),
5451 {
5452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5453 /* The multiple "Capture Source" controls confuse alsamixer
5454 * So call somewhat different..
5455 */
5456 /* .name = "Capture Source", */
5457 .name = "Input Source",
5458 .count = 2,
5459 .info = via_mux_enum_info,
5460 .get = via_mux_enum_get,
5461 .put = via_mux_enum_put,
5462 },
5463 { } /* end */
5464};
5465
5466static struct hda_verb vt2002P_volume_init_verbs[] = {
5467 /*
5468 * Unmute ADC0-1 and set the default input to mic-in
5469 */
5470 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5471 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5472
5473
5474 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5475 * mixer widget
5476 */
5477 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5478 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5479 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5480 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5481 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5483
5484 /* MUX Indices: Mic = 0 */
5485 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5486 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5487
5488 /* PW9 Output enable */
5489 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5490
5491 /* Enable Boost Volume backdoor */
5492 {0x1, 0xfb9, 0x24},
5493
5494 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5495 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5497 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5498 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5501 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5502 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5503
5504 /* set MUX0/1/4/8 = 0 (AOW0) */
5505 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5506 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5507 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5508 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5509
5510 /* set PW0 index=0 (MW0) */
5511 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5512
5513 /* Enable AOW0 to MW9 */
5514 {0x1, 0xfb8, 0x88},
5515 { }
5516};
5517
5518
5519static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5520 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5521 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5522 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5523 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5524 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5525 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5526 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5527 { }
5528};
5529
5530static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5531 .substreams = 2,
5532 .channels_min = 2,
5533 .channels_max = 2,
5534 .nid = 0x8, /* NID to query formats and rates */
5535 .ops = {
5536 .open = via_playback_pcm_open,
5537 .prepare = via_playback_multi_pcm_prepare,
5538 .cleanup = via_playback_multi_pcm_cleanup,
5539 .close = via_pcm_open_close,
5540 },
5541};
5542
5543static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5544 .substreams = 2,
5545 .channels_min = 2,
5546 .channels_max = 2,
5547 .nid = 0x10, /* NID to query formats and rates */
5548 .ops = {
5549 .open = via_pcm_open_close,
5550 .prepare = via_capture_pcm_prepare,
5551 .cleanup = via_capture_pcm_cleanup,
5552 .close = via_pcm_open_close,
5553 },
5554};
5555
5556static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5557 .substreams = 1,
5558 .channels_min = 2,
5559 .channels_max = 2,
5560 /* NID is set in via_build_pcms */
5561 .ops = {
5562 .open = via_dig_playback_pcm_open,
5563 .close = via_dig_playback_pcm_close,
5564 .prepare = via_dig_playback_pcm_prepare,
5565 .cleanup = via_dig_playback_pcm_cleanup
5566 },
5567};
5568
5569/* fill in the dac_nids table from the parsed pin configuration */
5570static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5571 const struct auto_pin_cfg *cfg)
5572{
5573 spec->multiout.num_dacs = 1;
5574 spec->multiout.dac_nids = spec->private_dac_nids;
5575 if (cfg->line_out_pins[0])
5576 spec->multiout.dac_nids[0] = 0x8;
5577 return 0;
5578}
5579
5580/* add playback controls from the parsed DAC table */
5581static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5582 const struct auto_pin_cfg *cfg)
5583{
5584 int err;
5585
5586 if (!cfg->line_out_pins[0])
5587 return -1;
5588
5589
5590 /* Line-Out: PortE */
5591 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5592 "Master Front Playback Volume",
5593 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5594 if (err < 0)
5595 return err;
5596 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5597 "Master Front Playback Switch",
5598 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5599 if (err < 0)
5600 return err;
5601
5602 return 0;
5603}
5604
5605static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5606{
5607 int err;
5608
5609 if (!pin)
5610 return 0;
5611
5612 spec->multiout.hp_nid = 0x9;
5613 spec->hp_independent_mode_index = 1;
5614
5615 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5616 "Headphone Playback Volume",
5617 HDA_COMPOSE_AMP_VAL(
5618 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5619 if (err < 0)
5620 return err;
5621
5622 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5623 "Headphone Playback Switch",
5624 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5625 if (err < 0)
5626 return err;
5627
5628 create_hp_imux(spec);
5629 return 0;
5630}
5631
5632/* create playback/capture controls for input pins */
5633static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5634 const struct auto_pin_cfg *cfg)
5635{
5636 static char *labels[] = {
5637 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5638 };
5639 struct hda_input_mux *imux = &spec->private_imux[0];
5640 int i, err, idx = 0;
5641
5642 for (i = 0; i < AUTO_PIN_LAST; i++) {
5643 if (!cfg->input_pins[i])
5644 continue;
5645
5646 switch (cfg->input_pins[i]) {
5647 case 0x2b: /* Mic */
5648 idx = 0;
5649 break;
5650
5651 case 0x2a: /* Line In */
5652 idx = 1;
5653 break;
5654
5655 case 0x29: /* Front Mic */
5656 idx = 2;
5657 break;
5658 }
5659 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5660 if (err < 0)
5661 return err;
5662 imux->items[imux->num_items].label = labels[i];
5663 imux->items[imux->num_items].index = idx;
5664 imux->num_items++;
5665 }
5666
5667 /* build volume/mute control of loopback */
5668 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5669 if (err < 0)
5670 return err;
5671
5672 /* for internal loopback recording select */
5673 imux->items[imux->num_items].label = "Stereo Mixer";
5674 imux->items[imux->num_items].index = 3;
5675 imux->num_items++;
5676
5677 /* for digital mic select */
5678 imux->items[imux->num_items].label = "Digital Mic";
5679 imux->items[imux->num_items].index = 4;
5680 imux->num_items++;
5681
5682 return 0;
5683}
5684
5685static int vt2002P_parse_auto_config(struct hda_codec *codec)
5686{
5687 struct via_spec *spec = codec->spec;
5688 int err;
5689
5690
5691 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5692 if (err < 0)
5693 return err;
5694
5695 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5696 if (err < 0)
5697 return err;
5698
5699 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5700 return 0; /* can't find valid BIOS pin config */
5701
5702 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5703 if (err < 0)
5704 return err;
5705 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5706 if (err < 0)
5707 return err;
5708 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5709 if (err < 0)
5710 return err;
5711
5712 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5713
5714 fill_dig_outs(codec);
5715
5716 if (spec->kctls.list)
5717 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5718
5719 spec->input_mux = &spec->private_imux[0];
5720
5721 if (spec->hp_mux)
5722 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5723
5724 return 1;
5725}
5726
5727#ifdef CONFIG_SND_HDA_POWER_SAVE
5728static struct hda_amp_list vt2002P_loopbacks[] = {
5729 { 0x21, HDA_INPUT, 0 },
5730 { 0x21, HDA_INPUT, 1 },
5731 { 0x21, HDA_INPUT, 2 },
5732 { } /* end */
5733};
5734#endif
5735
5736
5737/* patch for vt2002P */
5738static int patch_vt2002P(struct hda_codec *codec)
5739{
5740 struct via_spec *spec;
5741 int err;
5742
5743 /* create a codec specific record */
5744 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5745 if (spec == NULL)
5746 return -ENOMEM;
5747
5748 codec->spec = spec;
5749
5750 /* automatic parse from the BIOS config */
5751 err = vt2002P_parse_auto_config(codec);
5752 if (err < 0) {
5753 via_free(codec);
5754 return err;
5755 } else if (!err) {
5756 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5757 "from BIOS. Using genenic mode...\n");
5758 }
5759
5760 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5761 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5762
5763 spec->stream_name_analog = "VT2002P Analog";
5764 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5765 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5766
5767 spec->stream_name_digital = "VT2002P Digital";
5768 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5769
5770 if (!spec->adc_nids && spec->input_mux) {
5771 spec->adc_nids = vt2002P_adc_nids;
5772 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5773 get_mux_nids(codec);
5774 override_mic_boost(codec, 0x2b, 0, 3, 40);
5775 override_mic_boost(codec, 0x29, 0, 3, 40);
5776 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5777 spec->num_mixers++;
5778 }
5779
5780 codec->patch_ops = via_patch_ops;
5781
5782 codec->patch_ops.init = via_auto_init;
5783 codec->patch_ops.unsol_event = via_unsol_event;
5784
5785#ifdef CONFIG_SND_HDA_POWER_SAVE
5786 spec->loopback.amplist = vt2002P_loopbacks;
5787#endif
5788
5789 return 0;
5790}
5791
5792/* for vt1812 */
5793
5794/* capture mixer elements */
5795static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5796 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5797 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5798 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5799 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5800 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5801 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5802 HDA_INPUT),
5803 {
5804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5805 /* The multiple "Capture Source" controls confuse alsamixer
5806 * So call somewhat different..
5807 */
5808 .name = "Input Source",
5809 .count = 2,
5810 .info = via_mux_enum_info,
5811 .get = via_mux_enum_get,
5812 .put = via_mux_enum_put,
5813 },
5814 { } /* end */
5815};
5816
5817static struct hda_verb vt1812_volume_init_verbs[] = {
5818 /*
5819 * Unmute ADC0-1 and set the default input to mic-in
5820 */
5821 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5822 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5823
5824
5825 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5826 * mixer widget
5827 */
5828 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5829 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5830 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5831 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5832 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5833 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5834
5835 /* MUX Indices: Mic = 0 */
5836 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5837 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5838
5839 /* PW9 Output enable */
5840 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5841
5842 /* Enable Boost Volume backdoor */
5843 {0x1, 0xfb9, 0x24},
5844
5845 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5848 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5849 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5850 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5854 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5856
5857 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5858 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5859 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5860 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5861 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5862 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5863
5864 /* Enable AOW0 to MW9 */
5865 {0x1, 0xfb8, 0xa8},
5866 { }
5867};
5868
5869
5870static struct hda_verb vt1812_uniwill_init_verbs[] = {
5871 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5872 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5873 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5874 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5875 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5876 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5877 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5878 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5879 { }
5880};
5881
5882static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5883 .substreams = 2,
5884 .channels_min = 2,
5885 .channels_max = 2,
5886 .nid = 0x8, /* NID to query formats and rates */
5887 .ops = {
5888 .open = via_playback_pcm_open,
5889 .prepare = via_playback_multi_pcm_prepare,
5890 .cleanup = via_playback_multi_pcm_cleanup,
5891 .close = via_pcm_open_close,
5892 },
5893};
5894
5895static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5896 .substreams = 2,
5897 .channels_min = 2,
5898 .channels_max = 2,
5899 .nid = 0x10, /* NID to query formats and rates */
5900 .ops = {
5901 .open = via_pcm_open_close,
5902 .prepare = via_capture_pcm_prepare,
5903 .cleanup = via_capture_pcm_cleanup,
5904 .close = via_pcm_open_close,
5905 },
5906};
5907
5908static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5909 .substreams = 1,
5910 .channels_min = 2,
5911 .channels_max = 2,
5912 /* NID is set in via_build_pcms */
5913 .ops = {
5914 .open = via_dig_playback_pcm_open,
5915 .close = via_dig_playback_pcm_close,
5916 .prepare = via_dig_playback_pcm_prepare,
5917 .cleanup = via_dig_playback_pcm_cleanup
5918 },
5919};
5920/* fill in the dac_nids table from the parsed pin configuration */
5921static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5922 const struct auto_pin_cfg *cfg)
5923{
5924 spec->multiout.num_dacs = 1;
5925 spec->multiout.dac_nids = spec->private_dac_nids;
5926 if (cfg->line_out_pins[0])
5927 spec->multiout.dac_nids[0] = 0x8;
5928 return 0;
5929}
5930
5931
5932/* add playback controls from the parsed DAC table */
5933static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5934 const struct auto_pin_cfg *cfg)
5935{
5936 int err;
5937
5938 if (!cfg->line_out_pins[0])
5939 return -1;
5940
5941 /* Line-Out: PortE */
5942 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5943 "Master Front Playback Volume",
5944 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5945 if (err < 0)
5946 return err;
5947 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5948 "Master Front Playback Switch",
5949 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5950 if (err < 0)
5951 return err;
5952
5953 return 0;
5954}
5955
5956static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5957{
5958 int err;
5959
5960 if (!pin)
5961 return 0;
5962
5963 spec->multiout.hp_nid = 0x9;
5964 spec->hp_independent_mode_index = 1;
5965
5966
5967 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5968 "Headphone Playback Volume",
5969 HDA_COMPOSE_AMP_VAL(
5970 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5971 if (err < 0)
5972 return err;
5973
5974 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5975 "Headphone Playback Switch",
5976 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5977 if (err < 0)
5978 return err;
5979
5980 create_hp_imux(spec);
5981 return 0;
5982}
5983
5984/* create playback/capture controls for input pins */
5985static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5986 const struct auto_pin_cfg *cfg)
5987{
5988 static char *labels[] = {
5989 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5990 };
5991 struct hda_input_mux *imux = &spec->private_imux[0];
5992 int i, err, idx = 0;
5993
5994 for (i = 0; i < AUTO_PIN_LAST; i++) {
5995 if (!cfg->input_pins[i])
5996 continue;
5997
5998 switch (cfg->input_pins[i]) {
5999 case 0x2b: /* Mic */
6000 idx = 0;
6001 break;
6002
6003 case 0x2a: /* Line In */
6004 idx = 1;
6005 break;
6006
6007 case 0x29: /* Front Mic */
6008 idx = 2;
6009 break;
6010 }
6011 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6012 if (err < 0)
6013 return err;
6014 imux->items[imux->num_items].label = labels[i];
6015 imux->items[imux->num_items].index = idx;
6016 imux->num_items++;
6017 }
6018 /* build volume/mute control of loopback */
6019 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6020 if (err < 0)
6021 return err;
6022
6023 /* for internal loopback recording select */
6024 imux->items[imux->num_items].label = "Stereo Mixer";
6025 imux->items[imux->num_items].index = 5;
6026 imux->num_items++;
6027
6028 /* for digital mic select */
6029 imux->items[imux->num_items].label = "Digital Mic";
6030 imux->items[imux->num_items].index = 6;
6031 imux->num_items++;
6032
6033 return 0;
6034}
6035
6036static int vt1812_parse_auto_config(struct hda_codec *codec)
6037{
6038 struct via_spec *spec = codec->spec;
6039 int err;
6040
6041
6042 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6043 if (err < 0)
6044 return err;
6045 fill_dig_outs(codec);
6046 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6047 if (err < 0)
6048 return err;
6049
6050 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6051 return 0; /* can't find valid BIOS pin config */
6052
6053 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6054 if (err < 0)
6055 return err;
6056 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6057 if (err < 0)
6058 return err;
6059 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6060 if (err < 0)
6061 return err;
6062
6063 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6064
6065 fill_dig_outs(codec);
6066
6067 if (spec->kctls.list)
6068 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6069
6070 spec->input_mux = &spec->private_imux[0];
6071
6072 if (spec->hp_mux)
6073 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6074
6075 return 1;
6076}
6077
6078#ifdef CONFIG_SND_HDA_POWER_SAVE
6079static struct hda_amp_list vt1812_loopbacks[] = {
6080 { 0x21, HDA_INPUT, 0 },
6081 { 0x21, HDA_INPUT, 1 },
6082 { 0x21, HDA_INPUT, 2 },
6083 { } /* end */
6084};
6085#endif
6086
6087
6088/* patch for vt1812 */
6089static int patch_vt1812(struct hda_codec *codec)
6090{
6091 struct via_spec *spec;
6092 int err;
6093
6094 /* create a codec specific record */
6095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6096 if (spec == NULL)
6097 return -ENOMEM;
6098
6099 codec->spec = spec;
6100
6101 /* automatic parse from the BIOS config */
6102 err = vt1812_parse_auto_config(codec);
6103 if (err < 0) {
6104 via_free(codec);
6105 return err;
6106 } else if (!err) {
6107 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6108 "from BIOS. Using genenic mode...\n");
6109 }
6110
6111
6112 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6113 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6114
6115 spec->stream_name_analog = "VT1812 Analog";
6116 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6117 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6118
6119 spec->stream_name_digital = "VT1812 Digital";
6120 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6121
6122
6123 if (!spec->adc_nids && spec->input_mux) {
6124 spec->adc_nids = vt1812_adc_nids;
6125 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6126 get_mux_nids(codec);
6127 override_mic_boost(codec, 0x2b, 0, 3, 40);
6128 override_mic_boost(codec, 0x29, 0, 3, 40);
6129 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6130 spec->num_mixers++;
6131 }
6132
6133 codec->patch_ops = via_patch_ops;
6134
6135 codec->patch_ops.init = via_auto_init;
6136 codec->patch_ops.unsol_event = via_unsol_event;
6137
6138#ifdef CONFIG_SND_HDA_POWER_SAVE
6139 spec->loopback.amplist = vt1812_loopbacks;
6140#endif
3245 6141
3246 return 0; 6142 return 0;
3247} 6143}
@@ -3318,6 +6214,23 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
3318 .patch = patch_vt1702}, 6214 .patch = patch_vt1702},
3319 { .id = 0x11067398, .name = "VT1702", 6215 { .id = 0x11067398, .name = "VT1702",
3320 .patch = patch_vt1702}, 6216 .patch = patch_vt1702},
6217 { .id = 0x11060428, .name = "VT1718S",
6218 .patch = patch_vt1718S},
6219 { .id = 0x11064428, .name = "VT1718S",
6220 .patch = patch_vt1718S},
6221 { .id = 0x11060441, .name = "VT2020",
6222 .patch = patch_vt1718S},
6223 { .id = 0x11064441, .name = "VT1828S",
6224 .patch = patch_vt1718S},
6225 { .id = 0x11060433, .name = "VT1716S",
6226 .patch = patch_vt1716S},
6227 { .id = 0x1106a721, .name = "VT1716S",
6228 .patch = patch_vt1716S},
6229 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6230 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6231 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6232 { .id = 0x11060440, .name = "VT1818S",
6233 .patch = patch_vt1708S},
3321 {} /* terminator */ 6234 {} /* terminator */
3322}; 6235};
3323 6236