Commit | Line | Data |
---|---|---|
c9b443d4 TD |
1 | /* |
2 | * HD audio interface patch for Conexant HDA audio codec | |
3 | * | |
4 | * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> | |
5 | * Takashi Iwai <tiwai@suse.de> | |
6 | * Tobin Davis <tdavis@dsl-only.net> | |
7 | * | |
8 | * This driver is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This driver is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
22 | ||
c9b443d4 TD |
23 | #include <linux/init.h> |
24 | #include <linux/delay.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/pci.h> | |
27 | #include <sound/core.h> | |
bc7a166d UD |
28 | #include <sound/jack.h> |
29 | ||
c9b443d4 TD |
30 | #include "hda_codec.h" |
31 | #include "hda_local.h" | |
c0f8faf0 | 32 | #include "hda_beep.h" |
c9b443d4 TD |
33 | |
34 | #define CXT_PIN_DIR_IN 0x00 | |
35 | #define CXT_PIN_DIR_OUT 0x01 | |
36 | #define CXT_PIN_DIR_INOUT 0x02 | |
37 | #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 | |
38 | #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 | |
39 | ||
40 | #define CONEXANT_HP_EVENT 0x37 | |
41 | #define CONEXANT_MIC_EVENT 0x38 | |
42 | ||
bc7a166d UD |
43 | /* Conexant 5051 specific */ |
44 | ||
ecda0cff | 45 | #define CXT5051_SPDIF_OUT 0x12 |
bc7a166d UD |
46 | #define CXT5051_PORTB_EVENT 0x38 |
47 | #define CXT5051_PORTC_EVENT 0x39 | |
c9b443d4 | 48 | |
faddaa5d TI |
49 | #define AUTO_MIC_PORTB (1 << 1) |
50 | #define AUTO_MIC_PORTC (1 << 2) | |
c9b443d4 | 51 | |
f2e5731d TI |
52 | struct pin_dac_pair { |
53 | hda_nid_t pin; | |
54 | hda_nid_t dac; | |
55 | int type; | |
56 | }; | |
57 | ||
c9b443d4 TD |
58 | struct conexant_spec { |
59 | ||
34cbe3a6 | 60 | const struct snd_kcontrol_new *mixers[5]; |
c9b443d4 | 61 | int num_mixers; |
dd5746a8 | 62 | hda_nid_t vmaster_nid; |
c9b443d4 TD |
63 | |
64 | const struct hda_verb *init_verbs[5]; /* initialization verbs | |
65 | * don't forget NULL | |
66 | * termination! | |
67 | */ | |
68 | unsigned int num_init_verbs; | |
69 | ||
70 | /* playback */ | |
71 | struct hda_multi_out multiout; /* playback set-up | |
72 | * max_channels, dacs must be set | |
73 | * dig_out_nid and hp_nid are optional | |
74 | */ | |
75 | unsigned int cur_eapd; | |
82f30040 | 76 | unsigned int hp_present; |
faddaa5d | 77 | unsigned int auto_mic; |
f6100bb4 | 78 | int auto_mic_ext; /* imux_pins[] index for ext mic */ |
c9b443d4 | 79 | unsigned int need_dac_fix; |
f6a2491c | 80 | hda_nid_t slave_dig_outs[2]; |
c9b443d4 TD |
81 | |
82 | /* capture */ | |
83 | unsigned int num_adc_nids; | |
34cbe3a6 | 84 | const hda_nid_t *adc_nids; |
c9b443d4 TD |
85 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ |
86 | ||
461e2c78 TI |
87 | unsigned int cur_adc_idx; |
88 | hda_nid_t cur_adc; | |
89 | unsigned int cur_adc_stream_tag; | |
90 | unsigned int cur_adc_format; | |
91 | ||
6764bcef TI |
92 | const struct hda_pcm_stream *capture_stream; |
93 | ||
c9b443d4 TD |
94 | /* capture source */ |
95 | const struct hda_input_mux *input_mux; | |
34cbe3a6 | 96 | const hda_nid_t *capsrc_nids; |
c9b443d4 TD |
97 | unsigned int cur_mux[3]; |
98 | ||
99 | /* channel model */ | |
100 | const struct hda_channel_mode *channel_mode; | |
101 | int num_channel_mode; | |
102 | ||
103 | /* PCM information */ | |
104 | struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ | |
105 | ||
c9b443d4 TD |
106 | unsigned int spdif_route; |
107 | ||
108 | /* dynamic controls, init_verbs and input_mux */ | |
109 | struct auto_pin_cfg autocfg; | |
c9b443d4 | 110 | struct hda_input_mux private_imux; |
cf27f29a | 111 | int imux_cfg_idx[HDA_MAX_NUM_INPUTS]; /* corresponding autocfg.input */ |
f9759301 | 112 | hda_nid_t imux_boost_nid[HDA_MAX_NUM_INPUTS]; /* boost widget */ |
6764bcef | 113 | hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS]; |
f6100bb4 | 114 | hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; |
22ce5f74 | 115 | hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; |
41923e44 | 116 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
f2e5731d TI |
117 | struct pin_dac_pair dac_info[8]; |
118 | int dac_info_filled; | |
c9b443d4 | 119 | |
0fb67e98 | 120 | unsigned int port_d_mode; |
f2e5731d TI |
121 | unsigned int auto_mute:1; /* used in auto-parser */ |
122 | unsigned int dell_automute:1; | |
cfd3d8dc GA |
123 | unsigned int dell_vostro:1; |
124 | unsigned int ideapad:1; | |
7b2bfdbc | 125 | unsigned int thinkpad:1; |
048e78a5 | 126 | unsigned int hp_laptop:1; |
a1d6906e | 127 | unsigned int asus:1; |
75f8991d | 128 | |
6764bcef TI |
129 | unsigned int adc_switching:1; |
130 | ||
75f8991d DD |
131 | unsigned int ext_mic_present; |
132 | unsigned int recording; | |
133 | void (*capture_prepare)(struct hda_codec *codec); | |
134 | void (*capture_cleanup)(struct hda_codec *codec); | |
c4cfe66c DD |
135 | |
136 | /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) | |
137 | * through the microphone jack. | |
138 | * When the user enables this through a mixer switch, both internal and | |
139 | * external microphones are disabled. Gain is fixed at 0dB. In this mode, | |
140 | * we also allow the bias to be configured through a separate mixer | |
141 | * control. */ | |
142 | unsigned int dc_enable; | |
143 | unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ | |
144 | unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ | |
3507e2a8 TI |
145 | |
146 | unsigned int beep_amp; | |
c9b443d4 TD |
147 | }; |
148 | ||
149 | static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
150 | struct hda_codec *codec, | |
151 | struct snd_pcm_substream *substream) | |
152 | { | |
153 | struct conexant_spec *spec = codec->spec; | |
9a08160b TI |
154 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
155 | hinfo); | |
c9b443d4 TD |
156 | } |
157 | ||
158 | static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
159 | struct hda_codec *codec, | |
160 | unsigned int stream_tag, | |
161 | unsigned int format, | |
162 | struct snd_pcm_substream *substream) | |
163 | { | |
164 | struct conexant_spec *spec = codec->spec; | |
165 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | |
166 | stream_tag, | |
167 | format, substream); | |
168 | } | |
169 | ||
170 | static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
171 | struct hda_codec *codec, | |
172 | struct snd_pcm_substream *substream) | |
173 | { | |
174 | struct conexant_spec *spec = codec->spec; | |
175 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
176 | } | |
177 | ||
178 | /* | |
179 | * Digital out | |
180 | */ | |
181 | static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
182 | struct hda_codec *codec, | |
183 | struct snd_pcm_substream *substream) | |
184 | { | |
185 | struct conexant_spec *spec = codec->spec; | |
186 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
187 | } | |
188 | ||
189 | static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
190 | struct hda_codec *codec, | |
191 | struct snd_pcm_substream *substream) | |
192 | { | |
193 | struct conexant_spec *spec = codec->spec; | |
194 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
195 | } | |
196 | ||
6b97eb45 TI |
197 | static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
198 | struct hda_codec *codec, | |
199 | unsigned int stream_tag, | |
200 | unsigned int format, | |
201 | struct snd_pcm_substream *substream) | |
202 | { | |
203 | struct conexant_spec *spec = codec->spec; | |
204 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, | |
205 | stream_tag, | |
206 | format, substream); | |
207 | } | |
208 | ||
c9b443d4 TD |
209 | /* |
210 | * Analog capture | |
211 | */ | |
212 | static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
213 | struct hda_codec *codec, | |
214 | unsigned int stream_tag, | |
215 | unsigned int format, | |
216 | struct snd_pcm_substream *substream) | |
217 | { | |
218 | struct conexant_spec *spec = codec->spec; | |
75f8991d DD |
219 | if (spec->capture_prepare) |
220 | spec->capture_prepare(codec); | |
c9b443d4 TD |
221 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
222 | stream_tag, 0, format); | |
223 | return 0; | |
224 | } | |
225 | ||
226 | static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
227 | struct hda_codec *codec, | |
228 | struct snd_pcm_substream *substream) | |
229 | { | |
230 | struct conexant_spec *spec = codec->spec; | |
888afa15 | 231 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
75f8991d DD |
232 | if (spec->capture_cleanup) |
233 | spec->capture_cleanup(codec); | |
c9b443d4 TD |
234 | return 0; |
235 | } | |
236 | ||
237 | ||
238 | ||
34cbe3a6 | 239 | static const struct hda_pcm_stream conexant_pcm_analog_playback = { |
c9b443d4 TD |
240 | .substreams = 1, |
241 | .channels_min = 2, | |
242 | .channels_max = 2, | |
243 | .nid = 0, /* fill later */ | |
244 | .ops = { | |
245 | .open = conexant_playback_pcm_open, | |
246 | .prepare = conexant_playback_pcm_prepare, | |
247 | .cleanup = conexant_playback_pcm_cleanup | |
248 | }, | |
249 | }; | |
250 | ||
34cbe3a6 | 251 | static const struct hda_pcm_stream conexant_pcm_analog_capture = { |
c9b443d4 TD |
252 | .substreams = 1, |
253 | .channels_min = 2, | |
254 | .channels_max = 2, | |
255 | .nid = 0, /* fill later */ | |
256 | .ops = { | |
257 | .prepare = conexant_capture_pcm_prepare, | |
258 | .cleanup = conexant_capture_pcm_cleanup | |
259 | }, | |
260 | }; | |
261 | ||
262 | ||
34cbe3a6 | 263 | static const struct hda_pcm_stream conexant_pcm_digital_playback = { |
c9b443d4 TD |
264 | .substreams = 1, |
265 | .channels_min = 2, | |
266 | .channels_max = 2, | |
267 | .nid = 0, /* fill later */ | |
268 | .ops = { | |
269 | .open = conexant_dig_playback_pcm_open, | |
6b97eb45 TI |
270 | .close = conexant_dig_playback_pcm_close, |
271 | .prepare = conexant_dig_playback_pcm_prepare | |
c9b443d4 TD |
272 | }, |
273 | }; | |
274 | ||
34cbe3a6 | 275 | static const struct hda_pcm_stream conexant_pcm_digital_capture = { |
c9b443d4 TD |
276 | .substreams = 1, |
277 | .channels_min = 2, | |
278 | .channels_max = 2, | |
279 | /* NID is set in alc_build_pcms */ | |
280 | }; | |
281 | ||
461e2c78 TI |
282 | static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
283 | struct hda_codec *codec, | |
284 | unsigned int stream_tag, | |
285 | unsigned int format, | |
286 | struct snd_pcm_substream *substream) | |
287 | { | |
288 | struct conexant_spec *spec = codec->spec; | |
289 | spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; | |
290 | spec->cur_adc_stream_tag = stream_tag; | |
291 | spec->cur_adc_format = format; | |
292 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | |
293 | return 0; | |
294 | } | |
295 | ||
296 | static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
297 | struct hda_codec *codec, | |
298 | struct snd_pcm_substream *substream) | |
299 | { | |
300 | struct conexant_spec *spec = codec->spec; | |
888afa15 | 301 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
461e2c78 TI |
302 | spec->cur_adc = 0; |
303 | return 0; | |
304 | } | |
305 | ||
34cbe3a6 | 306 | static const struct hda_pcm_stream cx5051_pcm_analog_capture = { |
461e2c78 TI |
307 | .substreams = 1, |
308 | .channels_min = 2, | |
309 | .channels_max = 2, | |
310 | .nid = 0, /* fill later */ | |
311 | .ops = { | |
312 | .prepare = cx5051_capture_pcm_prepare, | |
313 | .cleanup = cx5051_capture_pcm_cleanup | |
314 | }, | |
315 | }; | |
316 | ||
c9b443d4 TD |
317 | static int conexant_build_pcms(struct hda_codec *codec) |
318 | { | |
319 | struct conexant_spec *spec = codec->spec; | |
320 | struct hda_pcm *info = spec->pcm_rec; | |
321 | ||
322 | codec->num_pcms = 1; | |
323 | codec->pcm_info = info; | |
324 | ||
325 | info->name = "CONEXANT Analog"; | |
326 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; | |
327 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
328 | spec->multiout.max_channels; | |
329 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
330 | spec->multiout.dac_nids[0]; | |
6764bcef TI |
331 | if (spec->capture_stream) |
332 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; | |
333 | else { | |
334 | if (codec->vendor_id == 0x14f15051) | |
335 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
336 | cx5051_pcm_analog_capture; | |
337 | else { | |
338 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
339 | conexant_pcm_analog_capture; | |
340 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | |
341 | spec->num_adc_nids; | |
342 | } | |
343 | } | |
c9b443d4 TD |
344 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
345 | ||
346 | if (spec->multiout.dig_out_nid) { | |
347 | info++; | |
348 | codec->num_pcms++; | |
349 | info->name = "Conexant Digital"; | |
7ba72ba1 | 350 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
c9b443d4 TD |
351 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
352 | conexant_pcm_digital_playback; | |
353 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
354 | spec->multiout.dig_out_nid; | |
355 | if (spec->dig_in_nid) { | |
356 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
357 | conexant_pcm_digital_capture; | |
358 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
359 | spec->dig_in_nid; | |
360 | } | |
f6a2491c AR |
361 | if (spec->slave_dig_outs[0]) |
362 | codec->slave_dig_outs = spec->slave_dig_outs; | |
c9b443d4 TD |
363 | } |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, | |
369 | struct snd_ctl_elem_info *uinfo) | |
370 | { | |
371 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
372 | struct conexant_spec *spec = codec->spec; | |
373 | ||
374 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
375 | } | |
376 | ||
377 | static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, | |
378 | struct snd_ctl_elem_value *ucontrol) | |
379 | { | |
380 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
381 | struct conexant_spec *spec = codec->spec; | |
382 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
383 | ||
384 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
385 | return 0; | |
386 | } | |
387 | ||
388 | static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, | |
389 | struct snd_ctl_elem_value *ucontrol) | |
390 | { | |
391 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
392 | struct conexant_spec *spec = codec->spec; | |
393 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
394 | ||
395 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
396 | spec->capsrc_nids[adc_idx], | |
397 | &spec->cur_mux[adc_idx]); | |
398 | } | |
399 | ||
bc7a166d UD |
400 | static int conexant_init_jacks(struct hda_codec *codec) |
401 | { | |
cd372fb3 | 402 | #ifdef CONFIG_SND_HDA_INPUT_JACK |
bc7a166d UD |
403 | struct conexant_spec *spec = codec->spec; |
404 | int i; | |
405 | ||
406 | for (i = 0; i < spec->num_init_verbs; i++) { | |
407 | const struct hda_verb *hv; | |
408 | ||
409 | hv = spec->init_verbs[i]; | |
410 | while (hv->nid) { | |
411 | int err = 0; | |
412 | switch (hv->param ^ AC_USRSP_EN) { | |
413 | case CONEXANT_HP_EVENT: | |
cd372fb3 TI |
414 | err = snd_hda_input_jack_add(codec, hv->nid, |
415 | SND_JACK_HEADPHONE, NULL); | |
416 | snd_hda_input_jack_report(codec, hv->nid); | |
bc7a166d UD |
417 | break; |
418 | case CXT5051_PORTC_EVENT: | |
419 | case CONEXANT_MIC_EVENT: | |
cd372fb3 TI |
420 | err = snd_hda_input_jack_add(codec, hv->nid, |
421 | SND_JACK_MICROPHONE, NULL); | |
422 | snd_hda_input_jack_report(codec, hv->nid); | |
bc7a166d UD |
423 | break; |
424 | } | |
425 | if (err < 0) | |
426 | return err; | |
427 | ++hv; | |
428 | } | |
429 | } | |
cd372fb3 | 430 | #endif /* CONFIG_SND_HDA_INPUT_JACK */ |
5801f992 TI |
431 | return 0; |
432 | } | |
bc7a166d | 433 | |
c9b443d4 TD |
434 | static int conexant_init(struct hda_codec *codec) |
435 | { | |
436 | struct conexant_spec *spec = codec->spec; | |
437 | int i; | |
438 | ||
439 | for (i = 0; i < spec->num_init_verbs; i++) | |
440 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
441 | return 0; | |
442 | } | |
443 | ||
444 | static void conexant_free(struct hda_codec *codec) | |
445 | { | |
cd372fb3 | 446 | snd_hda_input_jack_free(codec); |
c0f8faf0 | 447 | snd_hda_detach_beep_device(codec); |
c9b443d4 TD |
448 | kfree(codec->spec); |
449 | } | |
450 | ||
34cbe3a6 | 451 | static const struct snd_kcontrol_new cxt_capture_mixers[] = { |
b880c74a TI |
452 | { |
453 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
454 | .name = "Capture Source", | |
455 | .info = conexant_mux_enum_info, | |
456 | .get = conexant_mux_enum_get, | |
457 | .put = conexant_mux_enum_put | |
458 | }, | |
459 | {} | |
460 | }; | |
461 | ||
3507e2a8 TI |
462 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
463 | /* additional beep mixers; the actual parameters are overwritten at build */ | |
34cbe3a6 | 464 | static const struct snd_kcontrol_new cxt_beep_mixer[] = { |
3507e2a8 TI |
465 | HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), |
466 | HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), | |
467 | { } /* end */ | |
468 | }; | |
469 | #endif | |
470 | ||
ea734963 | 471 | static const char * const slave_vols[] = { |
dd5746a8 TI |
472 | "Headphone Playback Volume", |
473 | "Speaker Playback Volume", | |
474 | NULL | |
475 | }; | |
476 | ||
ea734963 | 477 | static const char * const slave_sws[] = { |
dd5746a8 TI |
478 | "Headphone Playback Switch", |
479 | "Speaker Playback Switch", | |
480 | NULL | |
481 | }; | |
482 | ||
c9b443d4 TD |
483 | static int conexant_build_controls(struct hda_codec *codec) |
484 | { | |
485 | struct conexant_spec *spec = codec->spec; | |
486 | unsigned int i; | |
487 | int err; | |
488 | ||
489 | for (i = 0; i < spec->num_mixers; i++) { | |
490 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
491 | if (err < 0) | |
492 | return err; | |
493 | } | |
494 | if (spec->multiout.dig_out_nid) { | |
495 | err = snd_hda_create_spdif_out_ctls(codec, | |
496 | spec->multiout.dig_out_nid); | |
497 | if (err < 0) | |
498 | return err; | |
9a08160b TI |
499 | err = snd_hda_create_spdif_share_sw(codec, |
500 | &spec->multiout); | |
501 | if (err < 0) | |
502 | return err; | |
503 | spec->multiout.share_spdif = 1; | |
c9b443d4 TD |
504 | } |
505 | if (spec->dig_in_nid) { | |
506 | err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); | |
507 | if (err < 0) | |
508 | return err; | |
509 | } | |
dd5746a8 TI |
510 | |
511 | /* if we have no master control, let's create it */ | |
512 | if (spec->vmaster_nid && | |
513 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | |
514 | unsigned int vmaster_tlv[4]; | |
515 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, | |
516 | HDA_OUTPUT, vmaster_tlv); | |
517 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", | |
518 | vmaster_tlv, slave_vols); | |
519 | if (err < 0) | |
520 | return err; | |
521 | } | |
522 | if (spec->vmaster_nid && | |
523 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | |
524 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", | |
525 | NULL, slave_sws); | |
526 | if (err < 0) | |
527 | return err; | |
528 | } | |
529 | ||
b880c74a TI |
530 | if (spec->input_mux) { |
531 | err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); | |
532 | if (err < 0) | |
533 | return err; | |
534 | } | |
535 | ||
3507e2a8 TI |
536 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
537 | /* create beep controls if needed */ | |
538 | if (spec->beep_amp) { | |
34cbe3a6 | 539 | const struct snd_kcontrol_new *knew; |
3507e2a8 TI |
540 | for (knew = cxt_beep_mixer; knew->name; knew++) { |
541 | struct snd_kcontrol *kctl; | |
542 | kctl = snd_ctl_new1(knew, codec); | |
543 | if (!kctl) | |
544 | return -ENOMEM; | |
545 | kctl->private_value = spec->beep_amp; | |
546 | err = snd_hda_ctl_add(codec, 0, kctl); | |
547 | if (err < 0) | |
548 | return err; | |
549 | } | |
550 | } | |
551 | #endif | |
552 | ||
c9b443d4 TD |
553 | return 0; |
554 | } | |
555 | ||
697c373e TI |
556 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
557 | static int conexant_suspend(struct hda_codec *codec, pm_message_t state) | |
558 | { | |
559 | snd_hda_shutup_pins(codec); | |
560 | return 0; | |
561 | } | |
562 | #endif | |
563 | ||
34cbe3a6 | 564 | static const struct hda_codec_ops conexant_patch_ops = { |
c9b443d4 TD |
565 | .build_controls = conexant_build_controls, |
566 | .build_pcms = conexant_build_pcms, | |
567 | .init = conexant_init, | |
568 | .free = conexant_free, | |
697c373e TI |
569 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
570 | .suspend = conexant_suspend, | |
571 | #endif | |
572 | .reboot_notify = snd_hda_shutup_pins, | |
c9b443d4 TD |
573 | }; |
574 | ||
3507e2a8 TI |
575 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
576 | #define set_beep_amp(spec, nid, idx, dir) \ | |
577 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) | |
578 | #else | |
579 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ | |
580 | #endif | |
581 | ||
6764bcef | 582 | static int patch_conexant_auto(struct hda_codec *codec); |
c9b443d4 TD |
583 | /* |
584 | * EAPD control | |
585 | * the private value = nid | (invert << 8) | |
586 | */ | |
587 | ||
a5ce8890 | 588 | #define cxt_eapd_info snd_ctl_boolean_mono_info |
c9b443d4 | 589 | |
82f30040 | 590 | static int cxt_eapd_get(struct snd_kcontrol *kcontrol, |
c9b443d4 TD |
591 | struct snd_ctl_elem_value *ucontrol) |
592 | { | |
593 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
594 | struct conexant_spec *spec = codec->spec; | |
595 | int invert = (kcontrol->private_value >> 8) & 1; | |
596 | if (invert) | |
597 | ucontrol->value.integer.value[0] = !spec->cur_eapd; | |
598 | else | |
599 | ucontrol->value.integer.value[0] = spec->cur_eapd; | |
600 | return 0; | |
82f30040 | 601 | |
c9b443d4 TD |
602 | } |
603 | ||
82f30040 | 604 | static int cxt_eapd_put(struct snd_kcontrol *kcontrol, |
c9b443d4 TD |
605 | struct snd_ctl_elem_value *ucontrol) |
606 | { | |
607 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
608 | struct conexant_spec *spec = codec->spec; | |
609 | int invert = (kcontrol->private_value >> 8) & 1; | |
610 | hda_nid_t nid = kcontrol->private_value & 0xff; | |
611 | unsigned int eapd; | |
82f30040 | 612 | |
68ea7b2f | 613 | eapd = !!ucontrol->value.integer.value[0]; |
c9b443d4 TD |
614 | if (invert) |
615 | eapd = !eapd; | |
82beb8fd | 616 | if (eapd == spec->cur_eapd) |
c9b443d4 | 617 | return 0; |
82f30040 | 618 | |
c9b443d4 | 619 | spec->cur_eapd = eapd; |
82beb8fd TI |
620 | snd_hda_codec_write_cache(codec, nid, |
621 | 0, AC_VERB_SET_EAPD_BTLENABLE, | |
622 | eapd ? 0x02 : 0x00); | |
c9b443d4 TD |
623 | return 1; |
624 | } | |
625 | ||
86d72bdf TI |
626 | /* controls for test mode */ |
627 | #ifdef CONFIG_SND_DEBUG | |
628 | ||
82f30040 TD |
629 | #define CXT_EAPD_SWITCH(xname, nid, mask) \ |
630 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
631 | .info = cxt_eapd_info, \ | |
632 | .get = cxt_eapd_get, \ | |
633 | .put = cxt_eapd_put, \ | |
634 | .private_value = nid | (mask<<16) } | |
635 | ||
636 | ||
637 | ||
c9b443d4 TD |
638 | static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, |
639 | struct snd_ctl_elem_info *uinfo) | |
640 | { | |
641 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
642 | struct conexant_spec *spec = codec->spec; | |
643 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, | |
644 | spec->num_channel_mode); | |
645 | } | |
646 | ||
647 | static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, | |
648 | struct snd_ctl_elem_value *ucontrol) | |
649 | { | |
650 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
651 | struct conexant_spec *spec = codec->spec; | |
652 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, | |
653 | spec->num_channel_mode, | |
654 | spec->multiout.max_channels); | |
655 | } | |
656 | ||
657 | static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, | |
658 | struct snd_ctl_elem_value *ucontrol) | |
659 | { | |
660 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
661 | struct conexant_spec *spec = codec->spec; | |
662 | int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, | |
663 | spec->num_channel_mode, | |
664 | &spec->multiout.max_channels); | |
665 | if (err >= 0 && spec->need_dac_fix) | |
666 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; | |
667 | return err; | |
668 | } | |
669 | ||
670 | #define CXT_PIN_MODE(xname, nid, dir) \ | |
671 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
672 | .info = conexant_ch_mode_info, \ | |
673 | .get = conexant_ch_mode_get, \ | |
674 | .put = conexant_ch_mode_put, \ | |
675 | .private_value = nid | (dir<<16) } | |
676 | ||
86d72bdf TI |
677 | #endif /* CONFIG_SND_DEBUG */ |
678 | ||
c9b443d4 TD |
679 | /* Conexant 5045 specific */ |
680 | ||
34cbe3a6 TI |
681 | static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; |
682 | static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; | |
683 | static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; | |
cbef9789 | 684 | #define CXT5045_SPDIF_OUT 0x18 |
c9b443d4 | 685 | |
34cbe3a6 | 686 | static const struct hda_channel_mode cxt5045_modes[1] = { |
5cd57529 TD |
687 | { 2, NULL }, |
688 | }; | |
c9b443d4 | 689 | |
34cbe3a6 | 690 | static const struct hda_input_mux cxt5045_capture_source = { |
c9b443d4 TD |
691 | .num_items = 2, |
692 | .items = { | |
82f30040 | 693 | { "IntMic", 0x1 }, |
f4beee94 | 694 | { "ExtMic", 0x2 }, |
c9b443d4 TD |
695 | } |
696 | }; | |
697 | ||
34cbe3a6 | 698 | static const struct hda_input_mux cxt5045_capture_source_benq = { |
22e14130 | 699 | .num_items = 5, |
5218c892 JZ |
700 | .items = { |
701 | { "IntMic", 0x1 }, | |
702 | { "ExtMic", 0x2 }, | |
703 | { "LineIn", 0x3 }, | |
22e14130 LM |
704 | { "CD", 0x4 }, |
705 | { "Mixer", 0x0 }, | |
5218c892 JZ |
706 | } |
707 | }; | |
708 | ||
34cbe3a6 | 709 | static const struct hda_input_mux cxt5045_capture_source_hp530 = { |
2de3c232 J |
710 | .num_items = 2, |
711 | .items = { | |
712 | { "ExtMic", 0x1 }, | |
713 | { "IntMic", 0x2 }, | |
714 | } | |
715 | }; | |
716 | ||
c9b443d4 TD |
717 | /* turn on/off EAPD (+ mute HP) as a master switch */ |
718 | static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
719 | struct snd_ctl_elem_value *ucontrol) | |
720 | { | |
721 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
722 | struct conexant_spec *spec = codec->spec; | |
82f30040 | 723 | unsigned int bits; |
c9b443d4 | 724 | |
82f30040 | 725 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
c9b443d4 TD |
726 | return 0; |
727 | ||
82f30040 TD |
728 | /* toggle internal speakers mute depending of presence of |
729 | * the headphone jack | |
730 | */ | |
47fd830a TI |
731 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
732 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | |
733 | HDA_AMP_MUTE, bits); | |
7f29673b | 734 | |
47fd830a TI |
735 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; |
736 | snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, | |
737 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
738 | return 1; |
739 | } | |
740 | ||
741 | /* bind volumes of both NID 0x10 and 0x11 */ | |
34cbe3a6 | 742 | static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { |
cca3b371 TI |
743 | .ops = &snd_hda_bind_vol, |
744 | .values = { | |
745 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), | |
746 | HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), | |
747 | 0 | |
748 | }, | |
749 | }; | |
c9b443d4 | 750 | |
7f29673b TD |
751 | /* toggle input of built-in and mic jack appropriately */ |
752 | static void cxt5045_hp_automic(struct hda_codec *codec) | |
753 | { | |
34cbe3a6 | 754 | static const struct hda_verb mic_jack_on[] = { |
7f29673b TD |
755 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, |
756 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
757 | {} | |
758 | }; | |
34cbe3a6 | 759 | static const struct hda_verb mic_jack_off[] = { |
7f29673b TD |
760 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, |
761 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
762 | {} | |
763 | }; | |
764 | unsigned int present; | |
765 | ||
d56757ab | 766 | present = snd_hda_jack_detect(codec, 0x12); |
7f29673b TD |
767 | if (present) |
768 | snd_hda_sequence_write(codec, mic_jack_on); | |
769 | else | |
770 | snd_hda_sequence_write(codec, mic_jack_off); | |
771 | } | |
772 | ||
c9b443d4 TD |
773 | |
774 | /* mute internal speaker if HP is plugged */ | |
775 | static void cxt5045_hp_automute(struct hda_codec *codec) | |
776 | { | |
82f30040 | 777 | struct conexant_spec *spec = codec->spec; |
dd87da1c | 778 | unsigned int bits; |
c9b443d4 | 779 | |
d56757ab | 780 | spec->hp_present = snd_hda_jack_detect(codec, 0x11); |
dd87da1c | 781 | |
47fd830a TI |
782 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
783 | snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, | |
784 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
785 | } |
786 | ||
787 | /* unsolicited event for HP jack sensing */ | |
788 | static void cxt5045_hp_unsol_event(struct hda_codec *codec, | |
789 | unsigned int res) | |
790 | { | |
791 | res >>= 26; | |
792 | switch (res) { | |
793 | case CONEXANT_HP_EVENT: | |
794 | cxt5045_hp_automute(codec); | |
795 | break; | |
7f29673b TD |
796 | case CONEXANT_MIC_EVENT: |
797 | cxt5045_hp_automic(codec); | |
798 | break; | |
799 | ||
c9b443d4 TD |
800 | } |
801 | } | |
802 | ||
34cbe3a6 | 803 | static const struct snd_kcontrol_new cxt5045_mixers[] = { |
28c4edb7 DH |
804 | HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), |
805 | HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), | |
8607f7c4 DH |
806 | HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), |
807 | HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), | |
c8229c38 TI |
808 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), |
809 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), | |
28c4edb7 DH |
810 | HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), |
811 | HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), | |
8607f7c4 DH |
812 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), |
813 | HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), | |
cca3b371 | 814 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
c9b443d4 TD |
815 | { |
816 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
817 | .name = "Master Playback Switch", | |
82f30040 TD |
818 | .info = cxt_eapd_info, |
819 | .get = cxt_eapd_get, | |
c9b443d4 | 820 | .put = cxt5045_hp_master_sw_put, |
82f30040 | 821 | .private_value = 0x10, |
c9b443d4 TD |
822 | }, |
823 | ||
824 | {} | |
825 | }; | |
826 | ||
34cbe3a6 | 827 | static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { |
22e14130 LM |
828 | HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), |
829 | HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), | |
830 | HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), | |
831 | HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), | |
832 | ||
5218c892 JZ |
833 | HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), |
834 | HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), | |
835 | HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), | |
836 | HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), | |
837 | ||
22e14130 LM |
838 | HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), |
839 | HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), | |
840 | ||
5218c892 JZ |
841 | {} |
842 | }; | |
843 | ||
34cbe3a6 | 844 | static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { |
28c4edb7 DH |
845 | HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), |
846 | HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), | |
8607f7c4 DH |
847 | HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), |
848 | HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), | |
2de3c232 J |
849 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), |
850 | HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), | |
28c4edb7 DH |
851 | HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), |
852 | HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), | |
8607f7c4 DH |
853 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), |
854 | HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), | |
2de3c232 J |
855 | HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), |
856 | { | |
857 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
858 | .name = "Master Playback Switch", | |
859 | .info = cxt_eapd_info, | |
860 | .get = cxt_eapd_get, | |
861 | .put = cxt5045_hp_master_sw_put, | |
862 | .private_value = 0x10, | |
863 | }, | |
864 | ||
865 | {} | |
866 | }; | |
867 | ||
34cbe3a6 | 868 | static const struct hda_verb cxt5045_init_verbs[] = { |
c9b443d4 | 869 | /* Line in, Mic */ |
4090dffb | 870 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
7f29673b | 871 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
c9b443d4 | 872 | /* HP, Amp */ |
c8229c38 TI |
873 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
874 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
875 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
876 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
877 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
878 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
879 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
880 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
881 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
28c4edb7 | 882 | /* Record selector: Internal mic */ |
7f29673b | 883 | {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, |
82f30040 | 884 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, |
c9b443d4 TD |
885 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, |
886 | /* SPDIF route: PCM */ | |
cbef9789 | 887 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
c9b443d4 | 888 | { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, |
c9b443d4 | 889 | /* EAPD */ |
82f30040 | 890 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ |
c9b443d4 TD |
891 | { } /* end */ |
892 | }; | |
893 | ||
34cbe3a6 | 894 | static const struct hda_verb cxt5045_benq_init_verbs[] = { |
28c4edb7 | 895 | /* Internal Mic, Mic */ |
5218c892 JZ |
896 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, |
897 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, | |
898 | /* Line In,HP, Amp */ | |
899 | {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
900 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
901 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
902 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
903 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
904 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
905 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
906 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
907 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
28c4edb7 | 908 | /* Record selector: Internal mic */ |
5218c892 JZ |
909 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, |
910 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, | |
911 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
912 | /* SPDIF route: PCM */ | |
cbef9789 | 913 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
5218c892 JZ |
914 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, |
915 | /* EAPD */ | |
916 | {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
917 | { } /* end */ | |
918 | }; | |
7f29673b | 919 | |
34cbe3a6 | 920 | static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { |
7f29673b TD |
921 | /* pin sensing on HP jack */ |
922 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
d3091fad | 923 | { } /* end */ |
7f29673b TD |
924 | }; |
925 | ||
34cbe3a6 | 926 | static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { |
7f29673b TD |
927 | /* pin sensing on HP jack */ |
928 | {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
d3091fad | 929 | { } /* end */ |
7f29673b TD |
930 | }; |
931 | ||
c9b443d4 TD |
932 | #ifdef CONFIG_SND_DEBUG |
933 | /* Test configuration for debugging, modelled after the ALC260 test | |
934 | * configuration. | |
935 | */ | |
34cbe3a6 | 936 | static const struct hda_input_mux cxt5045_test_capture_source = { |
c9b443d4 TD |
937 | .num_items = 5, |
938 | .items = { | |
939 | { "MIXER", 0x0 }, | |
940 | { "MIC1 pin", 0x1 }, | |
941 | { "LINE1 pin", 0x2 }, | |
942 | { "HP-OUT pin", 0x3 }, | |
943 | { "CD pin", 0x4 }, | |
944 | }, | |
945 | }; | |
946 | ||
34cbe3a6 | 947 | static const struct snd_kcontrol_new cxt5045_test_mixer[] = { |
c9b443d4 TD |
948 | |
949 | /* Output controls */ | |
c9b443d4 TD |
950 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), |
951 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
7f29673b TD |
952 | HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), |
953 | HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), | |
954 | HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), | |
955 | HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
956 | |
957 | /* Modes for retasking pin widgets */ | |
958 | CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), | |
959 | CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), | |
960 | ||
82f30040 TD |
961 | /* EAPD Switch Control */ |
962 | CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), | |
963 | ||
c9b443d4 | 964 | /* Loopback mixer controls */ |
7f29673b TD |
965 | |
966 | HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), | |
967 | HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), | |
968 | HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), | |
969 | HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), | |
970 | HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), | |
971 | HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), | |
972 | HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), | |
973 | HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), | |
974 | HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), | |
975 | HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), | |
c9b443d4 TD |
976 | { |
977 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
978 | .name = "Input Source", | |
979 | .info = conexant_mux_enum_info, | |
980 | .get = conexant_mux_enum_get, | |
981 | .put = conexant_mux_enum_put, | |
982 | }, | |
fb3409e7 TD |
983 | /* Audio input controls */ |
984 | HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), | |
985 | HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), | |
986 | HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), | |
987 | HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), | |
988 | HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), | |
989 | HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), | |
990 | HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), | |
991 | HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), | |
992 | HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), | |
993 | HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), | |
c9b443d4 TD |
994 | { } /* end */ |
995 | }; | |
996 | ||
34cbe3a6 | 997 | static const struct hda_verb cxt5045_test_init_verbs[] = { |
7f29673b TD |
998 | /* Set connections */ |
999 | { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
1000 | { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
1001 | { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
c9b443d4 TD |
1002 | /* Enable retasking pins as output, initially without power amp */ |
1003 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
7f29673b | 1004 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
c9b443d4 TD |
1005 | |
1006 | /* Disable digital (SPDIF) pins initially, but users can enable | |
1007 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
1008 | * payload also sets the generation to 0, output to be in "consumer" | |
1009 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
1010 | * control. | |
1011 | */ | |
cbef9789 TI |
1012 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
1013 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
c9b443d4 TD |
1014 | |
1015 | /* Start with output sum widgets muted and their output gains at min */ | |
1016 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1017 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1018 | ||
1019 | /* Unmute retasking pin widget output buffers since the default | |
1020 | * state appears to be output. As the pin mode is changed by the | |
1021 | * user the pin mode control will take care of enabling the pin's | |
1022 | * input/output buffers as needed. | |
1023 | */ | |
1024 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1025 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1026 | ||
1027 | /* Mute capture amp left and right */ | |
1028 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1029 | ||
1030 | /* Set ADC connection select to match default mixer setting (mic1 | |
1031 | * pin) | |
1032 | */ | |
1033 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
7f29673b | 1034 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, |
c9b443d4 TD |
1035 | |
1036 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
1037 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ | |
1038 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ | |
1039 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ | |
1040 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ | |
1041 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
1042 | ||
1043 | { } | |
1044 | }; | |
1045 | #endif | |
1046 | ||
1047 | ||
1048 | /* initialize jack-sensing, too */ | |
1049 | static int cxt5045_init(struct hda_codec *codec) | |
1050 | { | |
1051 | conexant_init(codec); | |
1052 | cxt5045_hp_automute(codec); | |
1053 | return 0; | |
1054 | } | |
1055 | ||
1056 | ||
1057 | enum { | |
15908c36 MB |
1058 | CXT5045_LAPTOP_HPSENSE, |
1059 | CXT5045_LAPTOP_MICSENSE, | |
1060 | CXT5045_LAPTOP_HPMICSENSE, | |
5218c892 | 1061 | CXT5045_BENQ, |
2de3c232 | 1062 | CXT5045_LAPTOP_HP530, |
c9b443d4 TD |
1063 | #ifdef CONFIG_SND_DEBUG |
1064 | CXT5045_TEST, | |
1065 | #endif | |
1f8458a2 | 1066 | CXT5045_AUTO, |
f5fcc13c | 1067 | CXT5045_MODELS |
c9b443d4 TD |
1068 | }; |
1069 | ||
ea734963 | 1070 | static const char * const cxt5045_models[CXT5045_MODELS] = { |
15908c36 MB |
1071 | [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", |
1072 | [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", | |
1073 | [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", | |
1074 | [CXT5045_BENQ] = "benq", | |
2de3c232 | 1075 | [CXT5045_LAPTOP_HP530] = "laptop-hp530", |
c9b443d4 | 1076 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 1077 | [CXT5045_TEST] = "test", |
c9b443d4 | 1078 | #endif |
1f8458a2 | 1079 | [CXT5045_AUTO] = "auto", |
f5fcc13c TI |
1080 | }; |
1081 | ||
34cbe3a6 | 1082 | static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { |
2de3c232 | 1083 | SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), |
dea0a509 TI |
1084 | SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", |
1085 | CXT5045_LAPTOP_HPSENSE), | |
6a9dccd6 | 1086 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), |
5218c892 | 1087 | SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), |
15908c36 MB |
1088 | SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), |
1089 | SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), | |
9e464154 TI |
1090 | SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", |
1091 | CXT5045_LAPTOP_HPMICSENSE), | |
15908c36 MB |
1092 | SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), |
1093 | SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), | |
1094 | SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), | |
dea0a509 TI |
1095 | SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", |
1096 | CXT5045_LAPTOP_HPMICSENSE), | |
15908c36 | 1097 | SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), |
c9b443d4 TD |
1098 | {} |
1099 | }; | |
1100 | ||
1101 | static int patch_cxt5045(struct hda_codec *codec) | |
1102 | { | |
1103 | struct conexant_spec *spec; | |
1104 | int board_config; | |
1105 | ||
1f8458a2 TI |
1106 | board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, |
1107 | cxt5045_models, | |
1108 | cxt5045_cfg_tbl); | |
9b842cd8 | 1109 | #if 0 /* use the old method just for safety */ |
1f8458a2 TI |
1110 | if (board_config < 0) |
1111 | board_config = CXT5045_AUTO; | |
9b842cd8 | 1112 | #endif |
1f8458a2 TI |
1113 | if (board_config == CXT5045_AUTO) |
1114 | return patch_conexant_auto(codec); | |
1115 | ||
c9b443d4 TD |
1116 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
1117 | if (!spec) | |
1118 | return -ENOMEM; | |
c9b443d4 | 1119 | codec->spec = spec; |
9421f954 | 1120 | codec->pin_amp_workaround = 1; |
c9b443d4 TD |
1121 | |
1122 | spec->multiout.max_channels = 2; | |
1123 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); | |
1124 | spec->multiout.dac_nids = cxt5045_dac_nids; | |
1125 | spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; | |
1126 | spec->num_adc_nids = 1; | |
1127 | spec->adc_nids = cxt5045_adc_nids; | |
1128 | spec->capsrc_nids = cxt5045_capsrc_nids; | |
1129 | spec->input_mux = &cxt5045_capture_source; | |
1130 | spec->num_mixers = 1; | |
1131 | spec->mixers[0] = cxt5045_mixers; | |
1132 | spec->num_init_verbs = 1; | |
1133 | spec->init_verbs[0] = cxt5045_init_verbs; | |
1134 | spec->spdif_route = 0; | |
3507e2a8 TI |
1135 | spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); |
1136 | spec->channel_mode = cxt5045_modes; | |
5cd57529 | 1137 | |
3507e2a8 | 1138 | set_beep_amp(spec, 0x16, 0, 1); |
c9b443d4 TD |
1139 | |
1140 | codec->patch_ops = conexant_patch_ops; | |
c9b443d4 | 1141 | |
c9b443d4 | 1142 | switch (board_config) { |
15908c36 | 1143 | case CXT5045_LAPTOP_HPSENSE: |
7f29673b TD |
1144 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
1145 | spec->input_mux = &cxt5045_capture_source; | |
1146 | spec->num_init_verbs = 2; | |
1147 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
1148 | spec->mixers[0] = cxt5045_mixers; | |
1149 | codec->patch_ops.init = cxt5045_init; | |
1150 | break; | |
15908c36 | 1151 | case CXT5045_LAPTOP_MICSENSE: |
86376df6 | 1152 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; |
c9b443d4 TD |
1153 | spec->input_mux = &cxt5045_capture_source; |
1154 | spec->num_init_verbs = 2; | |
7f29673b | 1155 | spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; |
c9b443d4 TD |
1156 | spec->mixers[0] = cxt5045_mixers; |
1157 | codec->patch_ops.init = cxt5045_init; | |
1158 | break; | |
15908c36 MB |
1159 | default: |
1160 | case CXT5045_LAPTOP_HPMICSENSE: | |
1161 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
1162 | spec->input_mux = &cxt5045_capture_source; | |
1163 | spec->num_init_verbs = 3; | |
1164 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
1165 | spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; | |
1166 | spec->mixers[0] = cxt5045_mixers; | |
1167 | codec->patch_ops.init = cxt5045_init; | |
1168 | break; | |
5218c892 JZ |
1169 | case CXT5045_BENQ: |
1170 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
1171 | spec->input_mux = &cxt5045_capture_source_benq; | |
1172 | spec->num_init_verbs = 1; | |
1173 | spec->init_verbs[0] = cxt5045_benq_init_verbs; | |
1174 | spec->mixers[0] = cxt5045_mixers; | |
1175 | spec->mixers[1] = cxt5045_benq_mixers; | |
1176 | spec->num_mixers = 2; | |
1177 | codec->patch_ops.init = cxt5045_init; | |
1178 | break; | |
2de3c232 J |
1179 | case CXT5045_LAPTOP_HP530: |
1180 | codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; | |
1181 | spec->input_mux = &cxt5045_capture_source_hp530; | |
1182 | spec->num_init_verbs = 2; | |
1183 | spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; | |
1184 | spec->mixers[0] = cxt5045_mixers_hp530; | |
1185 | codec->patch_ops.init = cxt5045_init; | |
1186 | break; | |
c9b443d4 TD |
1187 | #ifdef CONFIG_SND_DEBUG |
1188 | case CXT5045_TEST: | |
1189 | spec->input_mux = &cxt5045_test_capture_source; | |
1190 | spec->mixers[0] = cxt5045_test_mixer; | |
1191 | spec->init_verbs[0] = cxt5045_test_init_verbs; | |
15908c36 MB |
1192 | break; |
1193 | ||
c9b443d4 TD |
1194 | #endif |
1195 | } | |
48ecb7e8 | 1196 | |
031005f7 TI |
1197 | switch (codec->subsystem_id >> 16) { |
1198 | case 0x103c: | |
8f0f5ff6 | 1199 | case 0x1631: |
0b587fc4 | 1200 | case 0x1734: |
0ebf9e36 DC |
1201 | case 0x17aa: |
1202 | /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have | |
1203 | * really bad sound over 0dB on NID 0x17. Fix max PCM level to | |
1204 | * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) | |
031005f7 TI |
1205 | */ |
1206 | snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, | |
1207 | (0x14 << AC_AMPCAP_OFFSET_SHIFT) | | |
1208 | (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
1209 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
1210 | (1 << AC_AMPCAP_MUTE_SHIFT)); | |
1211 | break; | |
1212 | } | |
48ecb7e8 | 1213 | |
3507e2a8 TI |
1214 | if (spec->beep_amp) |
1215 | snd_hda_attach_beep_device(codec, spec->beep_amp); | |
1216 | ||
c9b443d4 TD |
1217 | return 0; |
1218 | } | |
1219 | ||
1220 | ||
1221 | /* Conexant 5047 specific */ | |
82f30040 | 1222 | #define CXT5047_SPDIF_OUT 0x11 |
c9b443d4 | 1223 | |
34cbe3a6 TI |
1224 | static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ |
1225 | static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; | |
1226 | static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; | |
c9b443d4 | 1227 | |
34cbe3a6 | 1228 | static const struct hda_channel_mode cxt5047_modes[1] = { |
5cd57529 TD |
1229 | { 2, NULL }, |
1230 | }; | |
c9b443d4 | 1231 | |
34cbe3a6 | 1232 | static const struct hda_input_mux cxt5047_toshiba_capture_source = { |
82f30040 TD |
1233 | .num_items = 2, |
1234 | .items = { | |
1235 | { "ExtMic", 0x2 }, | |
1236 | { "Line-In", 0x1 }, | |
c9b443d4 TD |
1237 | } |
1238 | }; | |
1239 | ||
1240 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
1241 | static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
1242 | struct snd_ctl_elem_value *ucontrol) | |
1243 | { | |
1244 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1245 | struct conexant_spec *spec = codec->spec; | |
82f30040 | 1246 | unsigned int bits; |
c9b443d4 | 1247 | |
82f30040 | 1248 | if (!cxt_eapd_put(kcontrol, ucontrol)) |
c9b443d4 TD |
1249 | return 0; |
1250 | ||
82f30040 TD |
1251 | /* toggle internal speakers mute depending of presence of |
1252 | * the headphone jack | |
1253 | */ | |
47fd830a | 1254 | bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; |
3b7523fc TI |
1255 | /* NOTE: Conexat codec needs the index for *OUTPUT* amp of |
1256 | * pin widgets unlike other codecs. In this case, we need to | |
1257 | * set index 0x01 for the volume from the mixer amp 0x19. | |
1258 | */ | |
5d75bc55 | 1259 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, |
47fd830a TI |
1260 | HDA_AMP_MUTE, bits); |
1261 | bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; | |
1262 | snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, | |
1263 | HDA_AMP_MUTE, bits); | |
c9b443d4 TD |
1264 | return 1; |
1265 | } | |
1266 | ||
c9b443d4 TD |
1267 | /* mute internal speaker if HP is plugged */ |
1268 | static void cxt5047_hp_automute(struct hda_codec *codec) | |
1269 | { | |
82f30040 | 1270 | struct conexant_spec *spec = codec->spec; |
dd87da1c | 1271 | unsigned int bits; |
c9b443d4 | 1272 | |
d56757ab | 1273 | spec->hp_present = snd_hda_jack_detect(codec, 0x13); |
dd87da1c | 1274 | |
47fd830a | 1275 | bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; |
3b7523fc | 1276 | /* See the note in cxt5047_hp_master_sw_put */ |
5d75bc55 | 1277 | snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, |
47fd830a | 1278 | HDA_AMP_MUTE, bits); |
c9b443d4 TD |
1279 | } |
1280 | ||
1281 | /* toggle input of built-in and mic jack appropriately */ | |
1282 | static void cxt5047_hp_automic(struct hda_codec *codec) | |
1283 | { | |
34cbe3a6 | 1284 | static const struct hda_verb mic_jack_on[] = { |
9f113e0e MB |
1285 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
1286 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
c9b443d4 TD |
1287 | {} |
1288 | }; | |
34cbe3a6 | 1289 | static const struct hda_verb mic_jack_off[] = { |
9f113e0e MB |
1290 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, |
1291 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
c9b443d4 TD |
1292 | {} |
1293 | }; | |
1294 | unsigned int present; | |
1295 | ||
d56757ab | 1296 | present = snd_hda_jack_detect(codec, 0x15); |
c9b443d4 TD |
1297 | if (present) |
1298 | snd_hda_sequence_write(codec, mic_jack_on); | |
1299 | else | |
1300 | snd_hda_sequence_write(codec, mic_jack_off); | |
1301 | } | |
1302 | ||
1303 | /* unsolicited event for HP jack sensing */ | |
1304 | static void cxt5047_hp_unsol_event(struct hda_codec *codec, | |
1305 | unsigned int res) | |
1306 | { | |
9f113e0e | 1307 | switch (res >> 26) { |
c9b443d4 TD |
1308 | case CONEXANT_HP_EVENT: |
1309 | cxt5047_hp_automute(codec); | |
1310 | break; | |
1311 | case CONEXANT_MIC_EVENT: | |
1312 | cxt5047_hp_automic(codec); | |
1313 | break; | |
1314 | } | |
1315 | } | |
1316 | ||
34cbe3a6 | 1317 | static const struct snd_kcontrol_new cxt5047_base_mixers[] = { |
df481e41 TI |
1318 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), |
1319 | HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), | |
5f99f86a | 1320 | HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), |
c9b443d4 TD |
1321 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), |
1322 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), | |
1323 | HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), | |
1324 | HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), | |
82f30040 TD |
1325 | { |
1326 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1327 | .name = "Master Playback Switch", | |
1328 | .info = cxt_eapd_info, | |
1329 | .get = cxt_eapd_get, | |
c9b443d4 TD |
1330 | .put = cxt5047_hp_master_sw_put, |
1331 | .private_value = 0x13, | |
1332 | }, | |
1333 | ||
1334 | {} | |
1335 | }; | |
1336 | ||
34cbe3a6 | 1337 | static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { |
3b7523fc | 1338 | /* See the note in cxt5047_hp_master_sw_put */ |
5d75bc55 | 1339 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), |
df481e41 TI |
1340 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), |
1341 | {} | |
1342 | }; | |
1343 | ||
34cbe3a6 | 1344 | static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { |
c9b443d4 | 1345 | HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), |
c9b443d4 TD |
1346 | { } /* end */ |
1347 | }; | |
1348 | ||
34cbe3a6 | 1349 | static const struct hda_verb cxt5047_init_verbs[] = { |
c9b443d4 TD |
1350 | /* Line in, Mic, Built-in Mic */ |
1351 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
1352 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
1353 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, | |
7f29673b | 1354 | /* HP, Speaker */ |
b7589ceb | 1355 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
5b3a7440 TI |
1356 | {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ |
1357 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ | |
7f29673b | 1358 | /* Record selector: Mic */ |
c9b443d4 TD |
1359 | {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, |
1360 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, | |
1361 | AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, | |
7f29673b TD |
1362 | {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, |
1363 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1364 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, | |
1365 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, | |
1366 | AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, | |
c9b443d4 TD |
1367 | /* SPDIF route: PCM */ |
1368 | { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, | |
82f30040 TD |
1369 | /* Enable unsolicited events */ |
1370 | {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
1371 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
c9b443d4 TD |
1372 | { } /* end */ |
1373 | }; | |
1374 | ||
1375 | /* configuration for Toshiba Laptops */ | |
34cbe3a6 | 1376 | static const struct hda_verb cxt5047_toshiba_init_verbs[] = { |
3b628867 | 1377 | {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ |
c9b443d4 TD |
1378 | {} |
1379 | }; | |
1380 | ||
1381 | /* Test configuration for debugging, modelled after the ALC260 test | |
1382 | * configuration. | |
1383 | */ | |
1384 | #ifdef CONFIG_SND_DEBUG | |
34cbe3a6 | 1385 | static const struct hda_input_mux cxt5047_test_capture_source = { |
82f30040 | 1386 | .num_items = 4, |
c9b443d4 | 1387 | .items = { |
82f30040 TD |
1388 | { "LINE1 pin", 0x0 }, |
1389 | { "MIC1 pin", 0x1 }, | |
1390 | { "MIC2 pin", 0x2 }, | |
1391 | { "CD pin", 0x3 }, | |
c9b443d4 TD |
1392 | }, |
1393 | }; | |
1394 | ||
34cbe3a6 | 1395 | static const struct snd_kcontrol_new cxt5047_test_mixer[] = { |
c9b443d4 TD |
1396 | |
1397 | /* Output only controls */ | |
82f30040 TD |
1398 | HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), |
1399 | HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), | |
1400 | HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), | |
1401 | HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1402 | HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), |
1403 | HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | |
1404 | HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
1405 | HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
82f30040 TD |
1406 | HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), |
1407 | HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), | |
1408 | HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), | |
1409 | HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), | |
c9b443d4 TD |
1410 | |
1411 | /* Modes for retasking pin widgets */ | |
1412 | CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), | |
1413 | CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), | |
1414 | ||
82f30040 TD |
1415 | /* EAPD Switch Control */ |
1416 | CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), | |
c9b443d4 | 1417 | |
82f30040 TD |
1418 | /* Loopback mixer controls */ |
1419 | HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), | |
1420 | HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), | |
1421 | HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), | |
1422 | HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), | |
1423 | HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), | |
1424 | HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), | |
1425 | HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), | |
1426 | HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), | |
1427 | ||
1428 | HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), | |
1429 | HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), | |
1430 | HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), | |
1431 | HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), | |
1432 | HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), | |
1433 | HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), | |
1434 | HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), | |
1435 | HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), | |
c9b443d4 TD |
1436 | { |
1437 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1438 | .name = "Input Source", | |
1439 | .info = conexant_mux_enum_info, | |
1440 | .get = conexant_mux_enum_get, | |
1441 | .put = conexant_mux_enum_put, | |
1442 | }, | |
854206b0 | 1443 | HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), |
9f113e0e | 1444 | |
c9b443d4 TD |
1445 | { } /* end */ |
1446 | }; | |
1447 | ||
34cbe3a6 | 1448 | static const struct hda_verb cxt5047_test_init_verbs[] = { |
c9b443d4 TD |
1449 | /* Enable retasking pins as output, initially without power amp */ |
1450 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1451 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1452 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1453 | ||
1454 | /* Disable digital (SPDIF) pins initially, but users can enable | |
1455 | * them via a mixer switch. In the case of SPDIF-out, this initverb | |
1456 | * payload also sets the generation to 0, output to be in "consumer" | |
1457 | * PCM format, copyright asserted, no pre-emphasis and no validity | |
1458 | * control. | |
1459 | */ | |
1460 | {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, | |
1461 | ||
1462 | /* Ensure mic1, mic2, line1 pin widgets take input from the | |
1463 | * OUT1 sum bus when acting as an output. | |
1464 | */ | |
1465 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, | |
1466 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, | |
1467 | ||
1468 | /* Start with output sum widgets muted and their output gains at min */ | |
1469 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1470 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1471 | ||
1472 | /* Unmute retasking pin widget output buffers since the default | |
1473 | * state appears to be output. As the pin mode is changed by the | |
1474 | * user the pin mode control will take care of enabling the pin's | |
1475 | * input/output buffers as needed. | |
1476 | */ | |
1477 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1478 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1479 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1480 | ||
1481 | /* Mute capture amp left and right */ | |
1482 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1483 | ||
1484 | /* Set ADC connection select to match default mixer setting (mic1 | |
1485 | * pin) | |
1486 | */ | |
1487 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1488 | ||
1489 | /* Mute all inputs to mixer widget (even unconnected ones) */ | |
1490 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ | |
1491 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ | |
1492 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ | |
1493 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ | |
1494 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ | |
1495 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ | |
1496 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ | |
1497 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ | |
1498 | ||
1499 | { } | |
1500 | }; | |
1501 | #endif | |
1502 | ||
1503 | ||
1504 | /* initialize jack-sensing, too */ | |
1505 | static int cxt5047_hp_init(struct hda_codec *codec) | |
1506 | { | |
1507 | conexant_init(codec); | |
1508 | cxt5047_hp_automute(codec); | |
c9b443d4 TD |
1509 | return 0; |
1510 | } | |
1511 | ||
1512 | ||
1513 | enum { | |
f5fcc13c TI |
1514 | CXT5047_LAPTOP, /* Laptops w/o EAPD support */ |
1515 | CXT5047_LAPTOP_HP, /* Some HP laptops */ | |
1516 | CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ | |
c9b443d4 TD |
1517 | #ifdef CONFIG_SND_DEBUG |
1518 | CXT5047_TEST, | |
1519 | #endif | |
fa5dadcb | 1520 | CXT5047_AUTO, |
f5fcc13c | 1521 | CXT5047_MODELS |
c9b443d4 TD |
1522 | }; |
1523 | ||
ea734963 | 1524 | static const char * const cxt5047_models[CXT5047_MODELS] = { |
f5fcc13c TI |
1525 | [CXT5047_LAPTOP] = "laptop", |
1526 | [CXT5047_LAPTOP_HP] = "laptop-hp", | |
1527 | [CXT5047_LAPTOP_EAPD] = "laptop-eapd", | |
c9b443d4 | 1528 | #ifdef CONFIG_SND_DEBUG |
f5fcc13c | 1529 | [CXT5047_TEST] = "test", |
c9b443d4 | 1530 | #endif |
fa5dadcb | 1531 | [CXT5047_AUTO] = "auto", |
f5fcc13c TI |
1532 | }; |
1533 | ||
34cbe3a6 | 1534 | static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { |
ac3e3741 | 1535 | SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), |
dea0a509 TI |
1536 | SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", |
1537 | CXT5047_LAPTOP), | |
f5fcc13c | 1538 | SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), |
c9b443d4 TD |
1539 | {} |
1540 | }; | |
1541 | ||
1542 | static int patch_cxt5047(struct hda_codec *codec) | |
1543 | { | |
1544 | struct conexant_spec *spec; | |
1545 | int board_config; | |
1546 | ||
fa5dadcb TI |
1547 | board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, |
1548 | cxt5047_models, | |
1549 | cxt5047_cfg_tbl); | |
1550 | #if 0 /* not enabled as default, as BIOS often broken for this codec */ | |
1551 | if (board_config < 0) | |
1552 | board_config = CXT5047_AUTO; | |
1553 | #endif | |
1554 | if (board_config == CXT5047_AUTO) | |
1555 | return patch_conexant_auto(codec); | |
1556 | ||
c9b443d4 TD |
1557 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
1558 | if (!spec) | |
1559 | return -ENOMEM; | |
c9b443d4 | 1560 | codec->spec = spec; |
9421f954 | 1561 | codec->pin_amp_workaround = 1; |
c9b443d4 TD |
1562 | |
1563 | spec->multiout.max_channels = 2; | |
1564 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); | |
1565 | spec->multiout.dac_nids = cxt5047_dac_nids; | |
1566 | spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; | |
1567 | spec->num_adc_nids = 1; | |
1568 | spec->adc_nids = cxt5047_adc_nids; | |
1569 | spec->capsrc_nids = cxt5047_capsrc_nids; | |
c9b443d4 | 1570 | spec->num_mixers = 1; |
df481e41 | 1571 | spec->mixers[0] = cxt5047_base_mixers; |
c9b443d4 TD |
1572 | spec->num_init_verbs = 1; |
1573 | spec->init_verbs[0] = cxt5047_init_verbs; | |
1574 | spec->spdif_route = 0; | |
5cd57529 TD |
1575 | spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), |
1576 | spec->channel_mode = cxt5047_modes, | |
c9b443d4 TD |
1577 | |
1578 | codec->patch_ops = conexant_patch_ops; | |
c9b443d4 | 1579 | |
c9b443d4 TD |
1580 | switch (board_config) { |
1581 | case CXT5047_LAPTOP: | |
df481e41 TI |
1582 | spec->num_mixers = 2; |
1583 | spec->mixers[1] = cxt5047_hp_spk_mixers; | |
1584 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; | |
c9b443d4 TD |
1585 | break; |
1586 | case CXT5047_LAPTOP_HP: | |
df481e41 TI |
1587 | spec->num_mixers = 2; |
1588 | spec->mixers[1] = cxt5047_hp_only_mixers; | |
fb3409e7 | 1589 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1590 | codec->patch_ops.init = cxt5047_hp_init; |
1591 | break; | |
1592 | case CXT5047_LAPTOP_EAPD: | |
82f30040 | 1593 | spec->input_mux = &cxt5047_toshiba_capture_source; |
df481e41 TI |
1594 | spec->num_mixers = 2; |
1595 | spec->mixers[1] = cxt5047_hp_spk_mixers; | |
c9b443d4 TD |
1596 | spec->num_init_verbs = 2; |
1597 | spec->init_verbs[1] = cxt5047_toshiba_init_verbs; | |
fb3409e7 | 1598 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1599 | break; |
1600 | #ifdef CONFIG_SND_DEBUG | |
1601 | case CXT5047_TEST: | |
1602 | spec->input_mux = &cxt5047_test_capture_source; | |
1603 | spec->mixers[0] = cxt5047_test_mixer; | |
1604 | spec->init_verbs[0] = cxt5047_test_init_verbs; | |
fb3409e7 | 1605 | codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; |
c9b443d4 TD |
1606 | #endif |
1607 | } | |
dd5746a8 | 1608 | spec->vmaster_nid = 0x13; |
025f206c DC |
1609 | |
1610 | switch (codec->subsystem_id >> 16) { | |
1611 | case 0x103c: | |
1612 | /* HP laptops have really bad sound over 0 dB on NID 0x10. | |
1613 | * Fix max PCM level to 0 dB (originally it has 0x1e steps | |
1614 | * with 0 dB offset 0x17) | |
1615 | */ | |
1616 | snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, | |
1617 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | | |
1618 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
1619 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
1620 | (1 << AC_AMPCAP_MUTE_SHIFT)); | |
1621 | break; | |
1622 | } | |
1623 | ||
c9b443d4 TD |
1624 | return 0; |
1625 | } | |
1626 | ||
461e2c78 | 1627 | /* Conexant 5051 specific */ |
34cbe3a6 TI |
1628 | static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; |
1629 | static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; | |
461e2c78 | 1630 | |
34cbe3a6 | 1631 | static const struct hda_channel_mode cxt5051_modes[1] = { |
461e2c78 TI |
1632 | { 2, NULL }, |
1633 | }; | |
1634 | ||
1635 | static void cxt5051_update_speaker(struct hda_codec *codec) | |
1636 | { | |
1637 | struct conexant_spec *spec = codec->spec; | |
1638 | unsigned int pinctl; | |
23d2df5b TI |
1639 | /* headphone pin */ |
1640 | pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; | |
1641 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1642 | pinctl); | |
1643 | /* speaker pin */ | |
461e2c78 TI |
1644 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; |
1645 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1646 | pinctl); | |
f7154de2 HRK |
1647 | /* on ideapad there is an aditional speaker (subwoofer) to mute */ |
1648 | if (spec->ideapad) | |
1649 | snd_hda_codec_write(codec, 0x1b, 0, | |
1650 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1651 | pinctl); | |
461e2c78 TI |
1652 | } |
1653 | ||
1654 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
1655 | static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
1656 | struct snd_ctl_elem_value *ucontrol) | |
1657 | { | |
1658 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1659 | ||
1660 | if (!cxt_eapd_put(kcontrol, ucontrol)) | |
1661 | return 0; | |
1662 | cxt5051_update_speaker(codec); | |
1663 | return 1; | |
1664 | } | |
1665 | ||
1666 | /* toggle input of built-in and mic jack appropriately */ | |
1667 | static void cxt5051_portb_automic(struct hda_codec *codec) | |
1668 | { | |
79d7d533 | 1669 | struct conexant_spec *spec = codec->spec; |
461e2c78 TI |
1670 | unsigned int present; |
1671 | ||
faddaa5d | 1672 | if (!(spec->auto_mic & AUTO_MIC_PORTB)) |
79d7d533 | 1673 | return; |
d56757ab | 1674 | present = snd_hda_jack_detect(codec, 0x17); |
461e2c78 TI |
1675 | snd_hda_codec_write(codec, 0x14, 0, |
1676 | AC_VERB_SET_CONNECT_SEL, | |
1677 | present ? 0x01 : 0x00); | |
1678 | } | |
1679 | ||
1680 | /* switch the current ADC according to the jack state */ | |
1681 | static void cxt5051_portc_automic(struct hda_codec *codec) | |
1682 | { | |
1683 | struct conexant_spec *spec = codec->spec; | |
1684 | unsigned int present; | |
1685 | hda_nid_t new_adc; | |
1686 | ||
faddaa5d | 1687 | if (!(spec->auto_mic & AUTO_MIC_PORTC)) |
79d7d533 | 1688 | return; |
d56757ab | 1689 | present = snd_hda_jack_detect(codec, 0x18); |
461e2c78 TI |
1690 | if (present) |
1691 | spec->cur_adc_idx = 1; | |
1692 | else | |
1693 | spec->cur_adc_idx = 0; | |
1694 | new_adc = spec->adc_nids[spec->cur_adc_idx]; | |
1695 | if (spec->cur_adc && spec->cur_adc != new_adc) { | |
1696 | /* stream is running, let's swap the current ADC */ | |
f0cea797 | 1697 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
461e2c78 TI |
1698 | spec->cur_adc = new_adc; |
1699 | snd_hda_codec_setup_stream(codec, new_adc, | |
1700 | spec->cur_adc_stream_tag, 0, | |
1701 | spec->cur_adc_format); | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | /* mute internal speaker if HP is plugged */ | |
1706 | static void cxt5051_hp_automute(struct hda_codec *codec) | |
1707 | { | |
1708 | struct conexant_spec *spec = codec->spec; | |
1709 | ||
d56757ab | 1710 | spec->hp_present = snd_hda_jack_detect(codec, 0x16); |
461e2c78 TI |
1711 | cxt5051_update_speaker(codec); |
1712 | } | |
1713 | ||
1714 | /* unsolicited event for HP jack sensing */ | |
1715 | static void cxt5051_hp_unsol_event(struct hda_codec *codec, | |
1716 | unsigned int res) | |
1717 | { | |
acf26c0c | 1718 | int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; |
461e2c78 TI |
1719 | switch (res >> 26) { |
1720 | case CONEXANT_HP_EVENT: | |
1721 | cxt5051_hp_automute(codec); | |
1722 | break; | |
1723 | case CXT5051_PORTB_EVENT: | |
1724 | cxt5051_portb_automic(codec); | |
1725 | break; | |
1726 | case CXT5051_PORTC_EVENT: | |
1727 | cxt5051_portc_automic(codec); | |
1728 | break; | |
1729 | } | |
cd372fb3 | 1730 | snd_hda_input_jack_report(codec, nid); |
461e2c78 TI |
1731 | } |
1732 | ||
34cbe3a6 | 1733 | static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { |
461e2c78 TI |
1734 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), |
1735 | { | |
1736 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1737 | .name = "Master Playback Switch", | |
1738 | .info = cxt_eapd_info, | |
1739 | .get = cxt_eapd_get, | |
1740 | .put = cxt5051_hp_master_sw_put, | |
1741 | .private_value = 0x1a, | |
1742 | }, | |
2c7a3fb3 TI |
1743 | {} |
1744 | }; | |
461e2c78 | 1745 | |
34cbe3a6 | 1746 | static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { |
2c7a3fb3 TI |
1747 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
1748 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | |
8607f7c4 DH |
1749 | HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), |
1750 | HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), | |
2c7a3fb3 TI |
1751 | HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), |
1752 | HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), | |
461e2c78 TI |
1753 | {} |
1754 | }; | |
1755 | ||
34cbe3a6 | 1756 | static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { |
461e2c78 TI |
1757 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
1758 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | |
8607f7c4 DH |
1759 | HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), |
1760 | HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), | |
461e2c78 TI |
1761 | {} |
1762 | }; | |
1763 | ||
34cbe3a6 | 1764 | static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { |
4e4ac600 TI |
1765 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), |
1766 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), | |
79d7d533 TI |
1767 | {} |
1768 | }; | |
1769 | ||
34cbe3a6 | 1770 | static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { |
5f6c3de6 TI |
1771 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), |
1772 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), | |
cd9d95a5 KP |
1773 | {} |
1774 | }; | |
1775 | ||
34cbe3a6 | 1776 | static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { |
faddaa5d TI |
1777 | HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), |
1778 | HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), | |
8607f7c4 DH |
1779 | HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), |
1780 | HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), | |
faddaa5d TI |
1781 | {} |
1782 | }; | |
1783 | ||
34cbe3a6 | 1784 | static const struct hda_verb cxt5051_init_verbs[] = { |
461e2c78 TI |
1785 | /* Line in, Mic */ |
1786 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1787 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1788 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1789 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1790 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
1791 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1792 | /* SPK */ | |
1793 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1794 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1795 | /* HP, Amp */ | |
1796 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1797 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1798 | /* DAC1 */ | |
1799 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
28c4edb7 | 1800 | /* Record selector: Internal mic */ |
461e2c78 TI |
1801 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, |
1802 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, | |
1803 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, | |
1804 | /* SPDIF route: PCM */ | |
1965c441 | 1805 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
461e2c78 TI |
1806 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, |
1807 | /* EAPD */ | |
1808 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
1809 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | |
461e2c78 TI |
1810 | { } /* end */ |
1811 | }; | |
1812 | ||
34cbe3a6 | 1813 | static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { |
79d7d533 TI |
1814 | /* Line in, Mic */ |
1815 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1816 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1817 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | |
1818 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | |
1819 | /* SPK */ | |
1820 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1821 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1822 | /* HP, Amp */ | |
1823 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1824 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1825 | /* DAC1 */ | |
1826 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
28c4edb7 | 1827 | /* Record selector: Internal mic */ |
79d7d533 TI |
1828 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, |
1829 | {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1830 | /* SPDIF route: PCM */ | |
1831 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1832 | /* EAPD */ | |
1833 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
1834 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | |
79d7d533 TI |
1835 | { } /* end */ |
1836 | }; | |
1837 | ||
34cbe3a6 | 1838 | static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { |
27e08988 ASRF |
1839 | /* Line in, Mic */ |
1840 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1841 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1842 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1843 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1844 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
1845 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, | |
1846 | /* SPK */ | |
1847 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1848 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1849 | /* HP, Amp */ | |
1850 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1851 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1852 | /* Docking HP */ | |
1853 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1854 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1855 | /* DAC1 */ | |
1856 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
28c4edb7 | 1857 | /* Record selector: Internal mic */ |
27e08988 ASRF |
1858 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, |
1859 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, | |
1860 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, | |
1861 | /* SPDIF route: PCM */ | |
1965c441 | 1862 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */ |
27e08988 ASRF |
1863 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, |
1864 | /* EAPD */ | |
1865 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
1866 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | |
27e08988 ASRF |
1867 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, |
1868 | { } /* end */ | |
1869 | }; | |
1870 | ||
34cbe3a6 | 1871 | static const struct hda_verb cxt5051_f700_init_verbs[] = { |
cd9d95a5 | 1872 | /* Line in, Mic */ |
30ed7ed1 | 1873 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, |
cd9d95a5 KP |
1874 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
1875 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | |
1876 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, | |
1877 | /* SPK */ | |
1878 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1879 | {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1880 | /* HP, Amp */ | |
1881 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1882 | {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1883 | /* DAC1 */ | |
1884 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
28c4edb7 | 1885 | /* Record selector: Internal mic */ |
cd9d95a5 KP |
1886 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, |
1887 | {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1888 | /* SPDIF route: PCM */ | |
1889 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1890 | /* EAPD */ | |
1891 | {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
1892 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, | |
cd9d95a5 KP |
1893 | { } /* end */ |
1894 | }; | |
1895 | ||
6953e552 TI |
1896 | static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, |
1897 | unsigned int event) | |
1898 | { | |
1899 | snd_hda_codec_write(codec, nid, 0, | |
1900 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
1901 | AC_USRSP_EN | event); | |
cd372fb3 TI |
1902 | snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL); |
1903 | snd_hda_input_jack_report(codec, nid); | |
6953e552 TI |
1904 | } |
1905 | ||
34cbe3a6 | 1906 | static const struct hda_verb cxt5051_ideapad_init_verbs[] = { |
f7154de2 HRK |
1907 | /* Subwoofer */ |
1908 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1909 | {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1910 | { } /* end */ | |
1911 | }; | |
1912 | ||
461e2c78 TI |
1913 | /* initialize jack-sensing, too */ |
1914 | static int cxt5051_init(struct hda_codec *codec) | |
1915 | { | |
6953e552 TI |
1916 | struct conexant_spec *spec = codec->spec; |
1917 | ||
461e2c78 | 1918 | conexant_init(codec); |
acf26c0c | 1919 | conexant_init_jacks(codec); |
6953e552 TI |
1920 | |
1921 | if (spec->auto_mic & AUTO_MIC_PORTB) | |
1922 | cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); | |
1923 | if (spec->auto_mic & AUTO_MIC_PORTC) | |
1924 | cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); | |
1925 | ||
461e2c78 TI |
1926 | if (codec->patch_ops.unsol_event) { |
1927 | cxt5051_hp_automute(codec); | |
1928 | cxt5051_portb_automic(codec); | |
1929 | cxt5051_portc_automic(codec); | |
1930 | } | |
1931 | return 0; | |
1932 | } | |
1933 | ||
1934 | ||
1935 | enum { | |
1936 | CXT5051_LAPTOP, /* Laptops w/ EAPD support */ | |
1937 | CXT5051_HP, /* no docking */ | |
79d7d533 | 1938 | CXT5051_HP_DV6736, /* HP without mic switch */ |
1965c441 | 1939 | CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */ |
cd9d95a5 | 1940 | CXT5051_F700, /* HP Compaq Presario F700 */ |
faddaa5d | 1941 | CXT5051_TOSHIBA, /* Toshiba M300 & co */ |
f7154de2 | 1942 | CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ |
6764bcef | 1943 | CXT5051_AUTO, /* auto-parser */ |
461e2c78 TI |
1944 | CXT5051_MODELS |
1945 | }; | |
1946 | ||
ea734963 | 1947 | static const char *const cxt5051_models[CXT5051_MODELS] = { |
461e2c78 TI |
1948 | [CXT5051_LAPTOP] = "laptop", |
1949 | [CXT5051_HP] = "hp", | |
79d7d533 | 1950 | [CXT5051_HP_DV6736] = "hp-dv6736", |
27e08988 | 1951 | [CXT5051_LENOVO_X200] = "lenovo-x200", |
5f6c3de6 | 1952 | [CXT5051_F700] = "hp-700", |
faddaa5d | 1953 | [CXT5051_TOSHIBA] = "toshiba", |
f7154de2 | 1954 | [CXT5051_IDEAPAD] = "ideapad", |
6764bcef | 1955 | [CXT5051_AUTO] = "auto", |
461e2c78 TI |
1956 | }; |
1957 | ||
34cbe3a6 | 1958 | static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { |
79d7d533 | 1959 | SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), |
1812e67c | 1960 | SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), |
5f6c3de6 | 1961 | SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), |
faddaa5d | 1962 | SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), |
461e2c78 TI |
1963 | SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", |
1964 | CXT5051_LAPTOP), | |
1965 | SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), | |
27e08988 | 1966 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), |
f7154de2 | 1967 | SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), |
461e2c78 TI |
1968 | {} |
1969 | }; | |
1970 | ||
1971 | static int patch_cxt5051(struct hda_codec *codec) | |
1972 | { | |
1973 | struct conexant_spec *spec; | |
1974 | int board_config; | |
1975 | ||
6764bcef TI |
1976 | board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, |
1977 | cxt5051_models, | |
1978 | cxt5051_cfg_tbl); | |
9b842cd8 | 1979 | #if 0 /* use the old method just for safety */ |
6764bcef TI |
1980 | if (board_config < 0) |
1981 | board_config = CXT5051_AUTO; | |
9b842cd8 | 1982 | #endif |
1f8458a2 | 1983 | if (board_config == CXT5051_AUTO) |
6764bcef | 1984 | return patch_conexant_auto(codec); |
6764bcef | 1985 | |
461e2c78 TI |
1986 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
1987 | if (!spec) | |
1988 | return -ENOMEM; | |
461e2c78 | 1989 | codec->spec = spec; |
9421f954 | 1990 | codec->pin_amp_workaround = 1; |
461e2c78 TI |
1991 | |
1992 | codec->patch_ops = conexant_patch_ops; | |
1993 | codec->patch_ops.init = cxt5051_init; | |
1994 | ||
1995 | spec->multiout.max_channels = 2; | |
1996 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); | |
1997 | spec->multiout.dac_nids = cxt5051_dac_nids; | |
1998 | spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; | |
1999 | spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ | |
2000 | spec->adc_nids = cxt5051_adc_nids; | |
2c7a3fb3 TI |
2001 | spec->num_mixers = 2; |
2002 | spec->mixers[0] = cxt5051_capture_mixers; | |
2003 | spec->mixers[1] = cxt5051_playback_mixers; | |
461e2c78 TI |
2004 | spec->num_init_verbs = 1; |
2005 | spec->init_verbs[0] = cxt5051_init_verbs; | |
2006 | spec->spdif_route = 0; | |
2007 | spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); | |
2008 | spec->channel_mode = cxt5051_modes; | |
2009 | spec->cur_adc = 0; | |
2010 | spec->cur_adc_idx = 0; | |
2011 | ||
3507e2a8 TI |
2012 | set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); |
2013 | ||
79d7d533 TI |
2014 | codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; |
2015 | ||
faddaa5d | 2016 | spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; |
461e2c78 TI |
2017 | switch (board_config) { |
2018 | case CXT5051_HP: | |
461e2c78 TI |
2019 | spec->mixers[0] = cxt5051_hp_mixers; |
2020 | break; | |
79d7d533 TI |
2021 | case CXT5051_HP_DV6736: |
2022 | spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; | |
2023 | spec->mixers[0] = cxt5051_hp_dv6736_mixers; | |
faddaa5d | 2024 | spec->auto_mic = 0; |
79d7d533 | 2025 | break; |
27e08988 ASRF |
2026 | case CXT5051_LENOVO_X200: |
2027 | spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; | |
607bc3e4 JY |
2028 | /* Thinkpad X301 does not have S/PDIF wired and no ability |
2029 | to use a docking station. */ | |
2030 | if (codec->subsystem_id == 0x17aa211f) | |
2031 | spec->multiout.dig_out_nid = 0; | |
461e2c78 | 2032 | break; |
cd9d95a5 KP |
2033 | case CXT5051_F700: |
2034 | spec->init_verbs[0] = cxt5051_f700_init_verbs; | |
2035 | spec->mixers[0] = cxt5051_f700_mixers; | |
faddaa5d TI |
2036 | spec->auto_mic = 0; |
2037 | break; | |
2038 | case CXT5051_TOSHIBA: | |
2039 | spec->mixers[0] = cxt5051_toshiba_mixers; | |
2040 | spec->auto_mic = AUTO_MIC_PORTB; | |
cd9d95a5 | 2041 | break; |
f7154de2 HRK |
2042 | case CXT5051_IDEAPAD: |
2043 | spec->init_verbs[spec->num_init_verbs++] = | |
2044 | cxt5051_ideapad_init_verbs; | |
2045 | spec->ideapad = 1; | |
2046 | break; | |
461e2c78 TI |
2047 | } |
2048 | ||
3507e2a8 TI |
2049 | if (spec->beep_amp) |
2050 | snd_hda_attach_beep_device(codec, spec->beep_amp); | |
2051 | ||
461e2c78 TI |
2052 | return 0; |
2053 | } | |
2054 | ||
0fb67e98 DD |
2055 | /* Conexant 5066 specific */ |
2056 | ||
34cbe3a6 TI |
2057 | static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; |
2058 | static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; | |
2059 | static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; | |
2060 | static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; | |
0fb67e98 | 2061 | |
dbaccc0c DD |
2062 | /* OLPC's microphone port is DC coupled for use with external sensors, |
2063 | * therefore we use a 50% mic bias in order to center the input signal with | |
2064 | * the DC input range of the codec. */ | |
2065 | #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 | |
2066 | ||
34cbe3a6 | 2067 | static const struct hda_channel_mode cxt5066_modes[1] = { |
0fb67e98 DD |
2068 | { 2, NULL }, |
2069 | }; | |
2070 | ||
a3de8ab8 TI |
2071 | #define HP_PRESENT_PORT_A (1 << 0) |
2072 | #define HP_PRESENT_PORT_D (1 << 1) | |
2073 | #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) | |
2074 | #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) | |
2075 | ||
0fb67e98 DD |
2076 | static void cxt5066_update_speaker(struct hda_codec *codec) |
2077 | { | |
2078 | struct conexant_spec *spec = codec->spec; | |
2079 | unsigned int pinctl; | |
2080 | ||
3a253445 JB |
2081 | snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", |
2082 | spec->hp_present, spec->cur_eapd); | |
0fb67e98 DD |
2083 | |
2084 | /* Port A (HP) */ | |
a3de8ab8 | 2085 | pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; |
0fb67e98 DD |
2086 | snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
2087 | pinctl); | |
2088 | ||
2089 | /* Port D (HP/LO) */ | |
a3de8ab8 TI |
2090 | pinctl = spec->cur_eapd ? spec->port_d_mode : 0; |
2091 | if (spec->dell_automute || spec->thinkpad) { | |
2092 | /* Mute if Port A is connected */ | |
2093 | if (hp_port_a_present(spec)) | |
3a253445 JB |
2094 | pinctl = 0; |
2095 | } else { | |
a3de8ab8 TI |
2096 | /* Thinkpad/Dell doesn't give pin-D status */ |
2097 | if (!hp_port_d_present(spec)) | |
2098 | pinctl = 0; | |
3a253445 | 2099 | } |
0fb67e98 DD |
2100 | snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
2101 | pinctl); | |
2102 | ||
2103 | /* CLASS_D AMP */ | |
2104 | pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; | |
2105 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
2106 | pinctl); | |
0fb67e98 DD |
2107 | } |
2108 | ||
2109 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
2110 | static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
2111 | struct snd_ctl_elem_value *ucontrol) | |
2112 | { | |
2113 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2114 | ||
2115 | if (!cxt_eapd_put(kcontrol, ucontrol)) | |
2116 | return 0; | |
2117 | ||
2118 | cxt5066_update_speaker(codec); | |
2119 | return 1; | |
2120 | } | |
2121 | ||
c4cfe66c DD |
2122 | static const struct hda_input_mux cxt5066_olpc_dc_bias = { |
2123 | .num_items = 3, | |
2124 | .items = { | |
2125 | { "Off", PIN_IN }, | |
2126 | { "50%", PIN_VREF50 }, | |
2127 | { "80%", PIN_VREF80 }, | |
2128 | }, | |
2129 | }; | |
2130 | ||
2131 | static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) | |
2132 | { | |
2133 | struct conexant_spec *spec = codec->spec; | |
2134 | /* Even though port F is the DC input, the bias is controlled on port B. | |
2135 | * we also leave that port as an active input (but unselected) in DC mode | |
2136 | * just in case that is necessary to make the bias setting take effect. */ | |
2137 | return snd_hda_codec_write_cache(codec, 0x1a, 0, | |
2138 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
2139 | cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); | |
2140 | } | |
2141 | ||
75f8991d DD |
2142 | /* OLPC defers mic widget control until when capture is started because the |
2143 | * microphone LED comes on as soon as these settings are put in place. if we | |
2144 | * did this before recording, it would give the false indication that recording | |
2145 | * is happening when it is not. */ | |
2146 | static void cxt5066_olpc_select_mic(struct hda_codec *codec) | |
0fb67e98 | 2147 | { |
dbaccc0c | 2148 | struct conexant_spec *spec = codec->spec; |
75f8991d DD |
2149 | if (!spec->recording) |
2150 | return; | |
0fb67e98 | 2151 | |
c4cfe66c DD |
2152 | if (spec->dc_enable) { |
2153 | /* in DC mode we ignore presence detection and just use the jack | |
2154 | * through our special DC port */ | |
2155 | const struct hda_verb enable_dc_mode[] = { | |
2156 | /* disble internal mic, port C */ | |
2157 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2158 | ||
2159 | /* enable DC capture, port F */ | |
2160 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
2161 | {}, | |
2162 | }; | |
2163 | ||
2164 | snd_hda_sequence_write(codec, enable_dc_mode); | |
2165 | /* port B input disabled (and bias set) through the following call */ | |
2166 | cxt5066_set_olpc_dc_bias(codec); | |
2167 | return; | |
2168 | } | |
2169 | ||
2170 | /* disable DC (port F) */ | |
2171 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); | |
2172 | ||
75f8991d DD |
2173 | /* external mic, port B */ |
2174 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
2175 | spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); | |
0fb67e98 | 2176 | |
75f8991d DD |
2177 | /* internal mic, port C */ |
2178 | snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
2179 | spec->ext_mic_present ? 0 : PIN_VREF80); | |
2180 | } | |
0fb67e98 | 2181 | |
75f8991d DD |
2182 | /* toggle input of built-in and mic jack appropriately */ |
2183 | static void cxt5066_olpc_automic(struct hda_codec *codec) | |
2184 | { | |
2185 | struct conexant_spec *spec = codec->spec; | |
0fb67e98 DD |
2186 | unsigned int present; |
2187 | ||
c4cfe66c DD |
2188 | if (spec->dc_enable) /* don't do presence detection in DC mode */ |
2189 | return; | |
2190 | ||
75f8991d DD |
2191 | present = snd_hda_codec_read(codec, 0x1a, 0, |
2192 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
2193 | if (present) | |
0fb67e98 | 2194 | snd_printdd("CXT5066: external microphone detected\n"); |
75f8991d | 2195 | else |
0fb67e98 | 2196 | snd_printdd("CXT5066: external microphone absent\n"); |
75f8991d DD |
2197 | |
2198 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, | |
2199 | present ? 0 : 1); | |
2200 | spec->ext_mic_present = !!present; | |
2201 | ||
2202 | cxt5066_olpc_select_mic(codec); | |
0fb67e98 DD |
2203 | } |
2204 | ||
95a618bd ER |
2205 | /* toggle input of built-in digital mic and mic jack appropriately */ |
2206 | static void cxt5066_vostro_automic(struct hda_codec *codec) | |
2207 | { | |
95a618bd ER |
2208 | unsigned int present; |
2209 | ||
2210 | struct hda_verb ext_mic_present[] = { | |
2211 | /* enable external mic, port B */ | |
75f8991d | 2212 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, |
95a618bd ER |
2213 | |
2214 | /* switch to external mic input */ | |
2215 | {0x17, AC_VERB_SET_CONNECT_SEL, 0}, | |
2216 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, | |
2217 | ||
2218 | /* disable internal digital mic */ | |
2219 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2220 | {} | |
2221 | }; | |
34cbe3a6 | 2222 | static const struct hda_verb ext_mic_absent[] = { |
95a618bd ER |
2223 | /* enable internal mic, port C */ |
2224 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
2225 | ||
2226 | /* switch to internal mic input */ | |
2227 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, | |
2228 | ||
2229 | /* disable external mic, port B */ | |
2230 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2231 | {} | |
2232 | }; | |
2233 | ||
2234 | present = snd_hda_jack_detect(codec, 0x1a); | |
2235 | if (present) { | |
2236 | snd_printdd("CXT5066: external microphone detected\n"); | |
2237 | snd_hda_sequence_write(codec, ext_mic_present); | |
2238 | } else { | |
2239 | snd_printdd("CXT5066: external microphone absent\n"); | |
2240 | snd_hda_sequence_write(codec, ext_mic_absent); | |
2241 | } | |
2242 | } | |
2243 | ||
cfd3d8dc GA |
2244 | /* toggle input of built-in digital mic and mic jack appropriately */ |
2245 | static void cxt5066_ideapad_automic(struct hda_codec *codec) | |
2246 | { | |
2247 | unsigned int present; | |
2248 | ||
2249 | struct hda_verb ext_mic_present[] = { | |
2250 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, | |
2251 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
2252 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2253 | {} | |
2254 | }; | |
34cbe3a6 | 2255 | static const struct hda_verb ext_mic_absent[] = { |
cfd3d8dc GA |
2256 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, |
2257 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
2258 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2259 | {} | |
2260 | }; | |
2261 | ||
2262 | present = snd_hda_jack_detect(codec, 0x1b); | |
2263 | if (present) { | |
2264 | snd_printdd("CXT5066: external microphone detected\n"); | |
2265 | snd_hda_sequence_write(codec, ext_mic_present); | |
2266 | } else { | |
2267 | snd_printdd("CXT5066: external microphone absent\n"); | |
2268 | snd_hda_sequence_write(codec, ext_mic_absent); | |
2269 | } | |
2270 | } | |
2271 | ||
a1d6906e DH |
2272 | |
2273 | /* toggle input of built-in digital mic and mic jack appropriately */ | |
2274 | static void cxt5066_asus_automic(struct hda_codec *codec) | |
2275 | { | |
2276 | unsigned int present; | |
2277 | ||
2278 | present = snd_hda_jack_detect(codec, 0x1b); | |
2279 | snd_printdd("CXT5066: external microphone present=%d\n", present); | |
2280 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, | |
2281 | present ? 1 : 0); | |
2282 | } | |
2283 | ||
2284 | ||
048e78a5 DH |
2285 | /* toggle input of built-in digital mic and mic jack appropriately */ |
2286 | static void cxt5066_hp_laptop_automic(struct hda_codec *codec) | |
2287 | { | |
2288 | unsigned int present; | |
2289 | ||
2290 | present = snd_hda_jack_detect(codec, 0x1b); | |
2291 | snd_printdd("CXT5066: external microphone present=%d\n", present); | |
2292 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, | |
2293 | present ? 1 : 3); | |
2294 | } | |
2295 | ||
2296 | ||
7b2bfdbc JT |
2297 | /* toggle input of built-in digital mic and mic jack appropriately |
2298 | order is: external mic -> dock mic -> interal mic */ | |
2299 | static void cxt5066_thinkpad_automic(struct hda_codec *codec) | |
2300 | { | |
2301 | unsigned int ext_present, dock_present; | |
2302 | ||
34cbe3a6 | 2303 | static const struct hda_verb ext_mic_present[] = { |
7b2bfdbc JT |
2304 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, |
2305 | {0x17, AC_VERB_SET_CONNECT_SEL, 1}, | |
2306 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
2307 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2308 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2309 | {} | |
2310 | }; | |
34cbe3a6 | 2311 | static const struct hda_verb dock_mic_present[] = { |
7b2bfdbc JT |
2312 | {0x14, AC_VERB_SET_CONNECT_SEL, 0}, |
2313 | {0x17, AC_VERB_SET_CONNECT_SEL, 0}, | |
2314 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
2315 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2316 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2317 | {} | |
2318 | }; | |
34cbe3a6 | 2319 | static const struct hda_verb ext_mic_absent[] = { |
7b2bfdbc JT |
2320 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, |
2321 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
2322 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2323 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2324 | {} | |
2325 | }; | |
2326 | ||
2327 | ext_present = snd_hda_jack_detect(codec, 0x1b); | |
2328 | dock_present = snd_hda_jack_detect(codec, 0x1a); | |
2329 | if (ext_present) { | |
2330 | snd_printdd("CXT5066: external microphone detected\n"); | |
2331 | snd_hda_sequence_write(codec, ext_mic_present); | |
2332 | } else if (dock_present) { | |
2333 | snd_printdd("CXT5066: dock microphone detected\n"); | |
2334 | snd_hda_sequence_write(codec, dock_mic_present); | |
2335 | } else { | |
2336 | snd_printdd("CXT5066: external microphone absent\n"); | |
2337 | snd_hda_sequence_write(codec, ext_mic_absent); | |
2338 | } | |
2339 | } | |
2340 | ||
0fb67e98 DD |
2341 | /* mute internal speaker if HP is plugged */ |
2342 | static void cxt5066_hp_automute(struct hda_codec *codec) | |
2343 | { | |
2344 | struct conexant_spec *spec = codec->spec; | |
2345 | unsigned int portA, portD; | |
2346 | ||
2347 | /* Port A */ | |
d56757ab | 2348 | portA = snd_hda_jack_detect(codec, 0x19); |
0fb67e98 DD |
2349 | |
2350 | /* Port D */ | |
d56757ab | 2351 | portD = snd_hda_jack_detect(codec, 0x1c); |
0fb67e98 | 2352 | |
a3de8ab8 TI |
2353 | spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; |
2354 | spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; | |
0fb67e98 DD |
2355 | snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", |
2356 | portA, portD, spec->hp_present); | |
2357 | cxt5066_update_speaker(codec); | |
2358 | } | |
2359 | ||
02b6b5b6 DH |
2360 | /* Dispatch the right mic autoswitch function */ |
2361 | static void cxt5066_automic(struct hda_codec *codec) | |
0fb67e98 | 2362 | { |
c4cfe66c | 2363 | struct conexant_spec *spec = codec->spec; |
0fb67e98 | 2364 | |
02b6b5b6 | 2365 | if (spec->dell_vostro) |
95a618bd | 2366 | cxt5066_vostro_automic(codec); |
02b6b5b6 | 2367 | else if (spec->ideapad) |
cfd3d8dc | 2368 | cxt5066_ideapad_automic(codec); |
02b6b5b6 DH |
2369 | else if (spec->thinkpad) |
2370 | cxt5066_thinkpad_automic(codec); | |
2371 | else if (spec->hp_laptop) | |
2372 | cxt5066_hp_laptop_automic(codec); | |
a1d6906e DH |
2373 | else if (spec->asus) |
2374 | cxt5066_asus_automic(codec); | |
cfd3d8dc GA |
2375 | } |
2376 | ||
048e78a5 | 2377 | /* unsolicited event for jack sensing */ |
02b6b5b6 | 2378 | static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) |
048e78a5 | 2379 | { |
02b6b5b6 DH |
2380 | struct conexant_spec *spec = codec->spec; |
2381 | snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); | |
048e78a5 DH |
2382 | switch (res >> 26) { |
2383 | case CONEXANT_HP_EVENT: | |
2384 | cxt5066_hp_automute(codec); | |
2385 | break; | |
2386 | case CONEXANT_MIC_EVENT: | |
02b6b5b6 DH |
2387 | /* ignore mic events in DC mode; we're always using the jack */ |
2388 | if (!spec->dc_enable) | |
2389 | cxt5066_olpc_automic(codec); | |
048e78a5 DH |
2390 | break; |
2391 | } | |
2392 | } | |
2393 | ||
7b2bfdbc | 2394 | /* unsolicited event for jack sensing */ |
02b6b5b6 | 2395 | static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) |
7b2bfdbc | 2396 | { |
02b6b5b6 | 2397 | snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); |
7b2bfdbc JT |
2398 | switch (res >> 26) { |
2399 | case CONEXANT_HP_EVENT: | |
2400 | cxt5066_hp_automute(codec); | |
2401 | break; | |
2402 | case CONEXANT_MIC_EVENT: | |
02b6b5b6 | 2403 | cxt5066_automic(codec); |
7b2bfdbc JT |
2404 | break; |
2405 | } | |
2406 | } | |
2407 | ||
02b6b5b6 | 2408 | |
0fb67e98 DD |
2409 | static const struct hda_input_mux cxt5066_analog_mic_boost = { |
2410 | .num_items = 5, | |
2411 | .items = { | |
2412 | { "0dB", 0 }, | |
2413 | { "10dB", 1 }, | |
2414 | { "20dB", 2 }, | |
2415 | { "30dB", 3 }, | |
2416 | { "40dB", 4 }, | |
2417 | }, | |
2418 | }; | |
2419 | ||
cfd3d8dc | 2420 | static void cxt5066_set_mic_boost(struct hda_codec *codec) |
c4cfe66c DD |
2421 | { |
2422 | struct conexant_spec *spec = codec->spec; | |
cfd3d8dc | 2423 | snd_hda_codec_write_cache(codec, 0x17, 0, |
c4cfe66c DD |
2424 | AC_VERB_SET_AMP_GAIN_MUTE, |
2425 | AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | | |
2426 | cxt5066_analog_mic_boost.items[spec->mic_boost].index); | |
7b2bfdbc | 2427 | if (spec->ideapad || spec->thinkpad) { |
cfd3d8dc GA |
2428 | /* adjust the internal mic as well...it is not through 0x17 */ |
2429 | snd_hda_codec_write_cache(codec, 0x23, 0, | |
2430 | AC_VERB_SET_AMP_GAIN_MUTE, | |
2431 | AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | | |
2432 | cxt5066_analog_mic_boost. | |
2433 | items[spec->mic_boost].index); | |
2434 | } | |
c4cfe66c DD |
2435 | } |
2436 | ||
0fb67e98 DD |
2437 | static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, |
2438 | struct snd_ctl_elem_info *uinfo) | |
2439 | { | |
2440 | return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); | |
2441 | } | |
2442 | ||
2443 | static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, | |
2444 | struct snd_ctl_elem_value *ucontrol) | |
2445 | { | |
2446 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
c4cfe66c DD |
2447 | struct conexant_spec *spec = codec->spec; |
2448 | ucontrol->value.enumerated.item[0] = spec->mic_boost; | |
0fb67e98 DD |
2449 | return 0; |
2450 | } | |
2451 | ||
2452 | static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, | |
2453 | struct snd_ctl_elem_value *ucontrol) | |
2454 | { | |
2455 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
c4cfe66c | 2456 | struct conexant_spec *spec = codec->spec; |
0fb67e98 DD |
2457 | const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; |
2458 | unsigned int idx; | |
c4cfe66c DD |
2459 | idx = ucontrol->value.enumerated.item[0]; |
2460 | if (idx >= imux->num_items) | |
2461 | idx = imux->num_items - 1; | |
2462 | ||
2463 | spec->mic_boost = idx; | |
2464 | if (!spec->dc_enable) | |
2465 | cxt5066_set_mic_boost(codec); | |
2466 | return 1; | |
2467 | } | |
2468 | ||
2469 | static void cxt5066_enable_dc(struct hda_codec *codec) | |
2470 | { | |
2471 | const struct hda_verb enable_dc_mode[] = { | |
2472 | /* disable gain */ | |
2473 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2474 | ||
2475 | /* switch to DC input */ | |
2476 | {0x17, AC_VERB_SET_CONNECT_SEL, 3}, | |
2477 | {} | |
2478 | }; | |
2479 | ||
2480 | /* configure as input source */ | |
2481 | snd_hda_sequence_write(codec, enable_dc_mode); | |
2482 | cxt5066_olpc_select_mic(codec); /* also sets configured bias */ | |
2483 | } | |
2484 | ||
2485 | static void cxt5066_disable_dc(struct hda_codec *codec) | |
2486 | { | |
2487 | /* reconfigure input source */ | |
2488 | cxt5066_set_mic_boost(codec); | |
2489 | /* automic also selects the right mic if we're recording */ | |
2490 | cxt5066_olpc_automic(codec); | |
2491 | } | |
2492 | ||
2493 | static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, | |
2494 | struct snd_ctl_elem_value *ucontrol) | |
2495 | { | |
2496 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2497 | struct conexant_spec *spec = codec->spec; | |
2498 | ucontrol->value.integer.value[0] = spec->dc_enable; | |
2499 | return 0; | |
2500 | } | |
0fb67e98 | 2501 | |
c4cfe66c DD |
2502 | static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, |
2503 | struct snd_ctl_elem_value *ucontrol) | |
2504 | { | |
2505 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2506 | struct conexant_spec *spec = codec->spec; | |
2507 | int dc_enable = !!ucontrol->value.integer.value[0]; | |
2508 | ||
2509 | if (dc_enable == spec->dc_enable) | |
0fb67e98 | 2510 | return 0; |
c4cfe66c DD |
2511 | |
2512 | spec->dc_enable = dc_enable; | |
2513 | if (dc_enable) | |
2514 | cxt5066_enable_dc(codec); | |
2515 | else | |
2516 | cxt5066_disable_dc(codec); | |
2517 | ||
2518 | return 1; | |
2519 | } | |
2520 | ||
2521 | static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, | |
2522 | struct snd_ctl_elem_info *uinfo) | |
2523 | { | |
2524 | return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); | |
2525 | } | |
2526 | ||
2527 | static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, | |
2528 | struct snd_ctl_elem_value *ucontrol) | |
2529 | { | |
2530 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2531 | struct conexant_spec *spec = codec->spec; | |
2532 | ucontrol->value.enumerated.item[0] = spec->dc_input_bias; | |
2533 | return 0; | |
2534 | } | |
2535 | ||
2536 | static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, | |
2537 | struct snd_ctl_elem_value *ucontrol) | |
2538 | { | |
2539 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2540 | struct conexant_spec *spec = codec->spec; | |
2541 | const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; | |
2542 | unsigned int idx; | |
2543 | ||
0fb67e98 DD |
2544 | idx = ucontrol->value.enumerated.item[0]; |
2545 | if (idx >= imux->num_items) | |
2546 | idx = imux->num_items - 1; | |
2547 | ||
c4cfe66c DD |
2548 | spec->dc_input_bias = idx; |
2549 | if (spec->dc_enable) | |
2550 | cxt5066_set_olpc_dc_bias(codec); | |
0fb67e98 DD |
2551 | return 1; |
2552 | } | |
2553 | ||
75f8991d DD |
2554 | static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) |
2555 | { | |
2556 | struct conexant_spec *spec = codec->spec; | |
2557 | /* mark as recording and configure the microphone widget so that the | |
2558 | * recording LED comes on. */ | |
2559 | spec->recording = 1; | |
2560 | cxt5066_olpc_select_mic(codec); | |
2561 | } | |
2562 | ||
2563 | static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) | |
2564 | { | |
2565 | struct conexant_spec *spec = codec->spec; | |
2566 | const struct hda_verb disable_mics[] = { | |
2567 | /* disable external mic, port B */ | |
2568 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2569 | ||
2570 | /* disble internal mic, port C */ | |
2571 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
c4cfe66c DD |
2572 | |
2573 | /* disable DC capture, port F */ | |
2574 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
75f8991d DD |
2575 | {}, |
2576 | }; | |
2577 | ||
2578 | snd_hda_sequence_write(codec, disable_mics); | |
2579 | spec->recording = 0; | |
2580 | } | |
2581 | ||
f6a2491c | 2582 | static void conexant_check_dig_outs(struct hda_codec *codec, |
34cbe3a6 | 2583 | const hda_nid_t *dig_pins, |
f6a2491c AR |
2584 | int num_pins) |
2585 | { | |
2586 | struct conexant_spec *spec = codec->spec; | |
2587 | hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; | |
2588 | int i; | |
2589 | ||
2590 | for (i = 0; i < num_pins; i++, dig_pins++) { | |
2591 | unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); | |
2592 | if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) | |
2593 | continue; | |
2594 | if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) | |
2595 | continue; | |
2596 | if (spec->slave_dig_outs[0]) | |
2597 | nid_loc++; | |
2598 | else | |
2599 | nid_loc = spec->slave_dig_outs; | |
2600 | } | |
2601 | } | |
2602 | ||
34cbe3a6 | 2603 | static const struct hda_input_mux cxt5066_capture_source = { |
0fb67e98 DD |
2604 | .num_items = 4, |
2605 | .items = { | |
2606 | { "Mic B", 0 }, | |
2607 | { "Mic C", 1 }, | |
2608 | { "Mic E", 2 }, | |
2609 | { "Mic F", 3 }, | |
2610 | }, | |
2611 | }; | |
2612 | ||
34cbe3a6 | 2613 | static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { |
0fb67e98 DD |
2614 | .ops = &snd_hda_bind_vol, |
2615 | .values = { | |
2616 | HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), | |
2617 | HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), | |
2618 | 0 | |
2619 | }, | |
2620 | }; | |
2621 | ||
34cbe3a6 | 2622 | static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { |
0fb67e98 DD |
2623 | .ops = &snd_hda_bind_sw, |
2624 | .values = { | |
2625 | HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), | |
2626 | HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), | |
2627 | 0 | |
2628 | }, | |
2629 | }; | |
2630 | ||
34cbe3a6 | 2631 | static const struct snd_kcontrol_new cxt5066_mixer_master[] = { |
0fb67e98 DD |
2632 | HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), |
2633 | {} | |
2634 | }; | |
2635 | ||
34cbe3a6 | 2636 | static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { |
0fb67e98 DD |
2637 | { |
2638 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2639 | .name = "Master Playback Volume", | |
2640 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | |
2641 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | | |
2642 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, | |
5e26dfd0 | 2643 | .subdevice = HDA_SUBDEV_AMP_FLAG, |
0fb67e98 DD |
2644 | .info = snd_hda_mixer_amp_volume_info, |
2645 | .get = snd_hda_mixer_amp_volume_get, | |
2646 | .put = snd_hda_mixer_amp_volume_put, | |
2647 | .tlv = { .c = snd_hda_mixer_amp_tlv }, | |
2648 | /* offset by 28 volume steps to limit minimum gain to -46dB */ | |
2649 | .private_value = | |
2650 | HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), | |
2651 | }, | |
2652 | {} | |
2653 | }; | |
2654 | ||
34cbe3a6 | 2655 | static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { |
c4cfe66c DD |
2656 | { |
2657 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2658 | .name = "DC Mode Enable Switch", | |
2659 | .info = snd_ctl_boolean_mono_info, | |
2660 | .get = cxt5066_olpc_dc_get, | |
2661 | .put = cxt5066_olpc_dc_put, | |
2662 | }, | |
2663 | { | |
2664 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2665 | .name = "DC Input Bias Enum", | |
2666 | .info = cxt5066_olpc_dc_bias_enum_info, | |
2667 | .get = cxt5066_olpc_dc_bias_enum_get, | |
2668 | .put = cxt5066_olpc_dc_bias_enum_put, | |
2669 | }, | |
2670 | {} | |
2671 | }; | |
2672 | ||
34cbe3a6 | 2673 | static const struct snd_kcontrol_new cxt5066_mixers[] = { |
0fb67e98 DD |
2674 | { |
2675 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2676 | .name = "Master Playback Switch", | |
2677 | .info = cxt_eapd_info, | |
2678 | .get = cxt_eapd_get, | |
2679 | .put = cxt5066_hp_master_sw_put, | |
2680 | .private_value = 0x1d, | |
2681 | }, | |
2682 | ||
2683 | { | |
2684 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
c4cfe66c | 2685 | .name = "Analog Mic Boost Capture Enum", |
0fb67e98 DD |
2686 | .info = cxt5066_mic_boost_mux_enum_info, |
2687 | .get = cxt5066_mic_boost_mux_enum_get, | |
2688 | .put = cxt5066_mic_boost_mux_enum_put, | |
2689 | }, | |
2690 | ||
2691 | HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), | |
2692 | HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), | |
2693 | {} | |
2694 | }; | |
2695 | ||
34cbe3a6 | 2696 | static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { |
254bba6a ER |
2697 | { |
2698 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
28c4edb7 | 2699 | .name = "Internal Mic Boost Capture Enum", |
254bba6a ER |
2700 | .info = cxt5066_mic_boost_mux_enum_info, |
2701 | .get = cxt5066_mic_boost_mux_enum_get, | |
2702 | .put = cxt5066_mic_boost_mux_enum_put, | |
2703 | .private_value = 0x23 | 0x100, | |
2704 | }, | |
2705 | {} | |
2706 | }; | |
2707 | ||
34cbe3a6 | 2708 | static const struct hda_verb cxt5066_init_verbs[] = { |
0fb67e98 DD |
2709 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ |
2710 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ | |
2711 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ | |
2712 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ | |
2713 | ||
2714 | /* Speakers */ | |
2715 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2716 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2717 | ||
2718 | /* HP, Amp */ | |
2719 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
2720 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2721 | ||
2722 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
2723 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2724 | ||
2725 | /* DAC1 */ | |
2726 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2727 | ||
2728 | /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ | |
2729 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | |
2730 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2731 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, | |
2732 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2733 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
2734 | ||
2735 | /* no digital microphone support yet */ | |
2736 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2737 | ||
2738 | /* Audio input selector */ | |
2739 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, | |
2740 | ||
2741 | /* SPDIF route: PCM */ | |
2742 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2743 | {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2744 | ||
2745 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2746 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2747 | ||
2748 | /* EAPD */ | |
2749 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
2750 | ||
2751 | /* not handling these yet */ | |
2752 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2753 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2754 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2755 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2756 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2757 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2758 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2759 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, | |
2760 | { } /* end */ | |
2761 | }; | |
2762 | ||
34cbe3a6 | 2763 | static const struct hda_verb cxt5066_init_verbs_olpc[] = { |
0fb67e98 DD |
2764 | /* Port A: headphones */ |
2765 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
2766 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2767 | ||
2768 | /* Port B: external microphone */ | |
75f8991d | 2769 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
0fb67e98 DD |
2770 | |
2771 | /* Port C: internal microphone */ | |
75f8991d | 2772 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
0fb67e98 DD |
2773 | |
2774 | /* Port D: unused */ | |
2775 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2776 | ||
2777 | /* Port E: unused, but has primary EAPD */ | |
2778 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2779 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
2780 | ||
c4cfe66c | 2781 | /* Port F: external DC input through microphone port */ |
0fb67e98 DD |
2782 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, |
2783 | ||
2784 | /* Port G: internal speakers */ | |
2785 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2786 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2787 | ||
2788 | /* DAC1 */ | |
2789 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2790 | ||
2791 | /* DAC2: unused */ | |
2792 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
2793 | ||
2794 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | |
2795 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2796 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2797 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2798 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2799 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2800 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2801 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2802 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2803 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2804 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2805 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2806 | ||
2807 | /* Disable digital microphone port */ | |
2808 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2809 | ||
2810 | /* Audio input selectors */ | |
2811 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, | |
2812 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | |
2813 | ||
2814 | /* Disable SPDIF */ | |
2815 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2816 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2817 | ||
2818 | /* enable unsolicited events for Port A and B */ | |
2819 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
2820 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
2821 | { } /* end */ | |
2822 | }; | |
2823 | ||
34cbe3a6 | 2824 | static const struct hda_verb cxt5066_init_verbs_vostro[] = { |
95a618bd ER |
2825 | /* Port A: headphones */ |
2826 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2827 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2828 | ||
2829 | /* Port B: external microphone */ | |
2830 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2831 | ||
2832 | /* Port C: unused */ | |
2833 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2834 | ||
2835 | /* Port D: unused */ | |
2836 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2837 | ||
2838 | /* Port E: unused, but has primary EAPD */ | |
2839 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2840 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
2841 | ||
2842 | /* Port F: unused */ | |
2843 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2844 | ||
2845 | /* Port G: internal speakers */ | |
2846 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2847 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2848 | ||
2849 | /* DAC1 */ | |
2850 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2851 | ||
2852 | /* DAC2: unused */ | |
2853 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
2854 | ||
2855 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2856 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2857 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2858 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2859 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2860 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2861 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2862 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2863 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2864 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2865 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2866 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2867 | ||
2868 | /* Digital microphone port */ | |
2869 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
2870 | ||
2871 | /* Audio input selectors */ | |
2872 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, | |
2873 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | |
2874 | ||
2875 | /* Disable SPDIF */ | |
2876 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2877 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2878 | ||
2879 | /* enable unsolicited events for Port A and B */ | |
2880 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
2881 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
2882 | { } /* end */ | |
2883 | }; | |
2884 | ||
34cbe3a6 | 2885 | static const struct hda_verb cxt5066_init_verbs_ideapad[] = { |
cfd3d8dc GA |
2886 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ |
2887 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ | |
2888 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ | |
2889 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ | |
2890 | ||
2891 | /* Speakers */ | |
2892 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2893 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2894 | ||
2895 | /* HP, Amp */ | |
2896 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
2897 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2898 | ||
2899 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
2900 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2901 | ||
2902 | /* DAC1 */ | |
2903 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2904 | ||
2905 | /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ | |
2906 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | |
2907 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2908 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, | |
2909 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2910 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
2911 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ | |
2912 | ||
2913 | /* Audio input selector */ | |
2914 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, | |
2915 | {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ | |
2916 | ||
2917 | /* SPDIF route: PCM */ | |
2918 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2919 | {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2920 | ||
2921 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2922 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2923 | ||
2924 | /* internal microphone */ | |
28c4edb7 | 2925 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ |
cfd3d8dc GA |
2926 | |
2927 | /* EAPD */ | |
2928 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
2929 | ||
2930 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
2931 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
2932 | { } /* end */ | |
2933 | }; | |
2934 | ||
34cbe3a6 | 2935 | static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { |
7b2bfdbc JT |
2936 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ |
2937 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ | |
2938 | ||
2939 | /* Port G: internal speakers */ | |
2940 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2941 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2942 | ||
2943 | /* Port A: HP, Amp */ | |
2944 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2945 | {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2946 | ||
2947 | /* Port B: Mic Dock */ | |
2948 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2949 | ||
2950 | /* Port C: Mic */ | |
2951 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2952 | ||
2953 | /* Port D: HP Dock, Amp */ | |
2954 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, | |
2955 | {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ | |
2956 | ||
2957 | /* DAC1 */ | |
2958 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2959 | ||
2960 | /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ | |
2961 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, | |
2962 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2963 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, | |
2964 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2965 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
2966 | {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ | |
2967 | ||
2968 | /* Audio input selector */ | |
2969 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, | |
2970 | {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ | |
2971 | ||
2972 | /* SPDIF route: PCM */ | |
2973 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2974 | {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2975 | ||
2976 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2977 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2978 | ||
2979 | /* internal microphone */ | |
28c4edb7 | 2980 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ |
7b2bfdbc JT |
2981 | |
2982 | /* EAPD */ | |
2983 | {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ | |
2984 | ||
2985 | /* enable unsolicited events for Port A, B, C and D */ | |
2986 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
2987 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
2988 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
2989 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
2990 | { } /* end */ | |
2991 | }; | |
2992 | ||
34cbe3a6 | 2993 | static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { |
0fb67e98 DD |
2994 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, |
2995 | { } /* end */ | |
2996 | }; | |
2997 | ||
048e78a5 | 2998 | |
34cbe3a6 | 2999 | static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { |
048e78a5 DH |
3000 | {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, |
3001 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, | |
3002 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, | |
3003 | { } /* end */ | |
3004 | }; | |
3005 | ||
0fb67e98 DD |
3006 | /* initialize jack-sensing, too */ |
3007 | static int cxt5066_init(struct hda_codec *codec) | |
3008 | { | |
3009 | snd_printdd("CXT5066: init\n"); | |
3010 | conexant_init(codec); | |
3011 | if (codec->patch_ops.unsol_event) { | |
3012 | cxt5066_hp_automute(codec); | |
02b6b5b6 | 3013 | cxt5066_automic(codec); |
0fb67e98 | 3014 | } |
c4cfe66c | 3015 | cxt5066_set_mic_boost(codec); |
0fb67e98 DD |
3016 | return 0; |
3017 | } | |
3018 | ||
75f8991d DD |
3019 | static int cxt5066_olpc_init(struct hda_codec *codec) |
3020 | { | |
c4cfe66c | 3021 | struct conexant_spec *spec = codec->spec; |
75f8991d DD |
3022 | snd_printdd("CXT5066: init\n"); |
3023 | conexant_init(codec); | |
3024 | cxt5066_hp_automute(codec); | |
c4cfe66c DD |
3025 | if (!spec->dc_enable) { |
3026 | cxt5066_set_mic_boost(codec); | |
3027 | cxt5066_olpc_automic(codec); | |
3028 | } else { | |
3029 | cxt5066_enable_dc(codec); | |
3030 | } | |
75f8991d DD |
3031 | return 0; |
3032 | } | |
3033 | ||
0fb67e98 | 3034 | enum { |
7b2bfdbc | 3035 | CXT5066_LAPTOP, /* Laptops w/ EAPD support */ |
0fb67e98 DD |
3036 | CXT5066_DELL_LAPTOP, /* Dell Laptop */ |
3037 | CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ | |
1feba3b7 | 3038 | CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ |
cfd3d8dc | 3039 | CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ |
7b2bfdbc | 3040 | CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ |
a1d6906e | 3041 | CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ |
048e78a5 | 3042 | CXT5066_HP_LAPTOP, /* HP Laptop */ |
0fb67e98 DD |
3043 | CXT5066_MODELS |
3044 | }; | |
3045 | ||
ea734963 | 3046 | static const char * const cxt5066_models[CXT5066_MODELS] = { |
7b2bfdbc | 3047 | [CXT5066_LAPTOP] = "laptop", |
0fb67e98 DD |
3048 | [CXT5066_DELL_LAPTOP] = "dell-laptop", |
3049 | [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", | |
1feba3b7 | 3050 | [CXT5066_DELL_VOSTRO] = "dell-vostro", |
cfd3d8dc | 3051 | [CXT5066_IDEAPAD] = "ideapad", |
7b2bfdbc | 3052 | [CXT5066_THINKPAD] = "thinkpad", |
a1d6906e | 3053 | [CXT5066_ASUS] = "asus", |
048e78a5 | 3054 | [CXT5066_HP_LAPTOP] = "hp-laptop", |
0fb67e98 DD |
3055 | }; |
3056 | ||
34cbe3a6 | 3057 | static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { |
00cd0bb7 | 3058 | SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), |
1feba3b7 | 3059 | SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), |
8a96b1e0 | 3060 | SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), |
ca6cd851 | 3061 | SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), |
1feba3b7 | 3062 | SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), |
231f50bc | 3063 | SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), |
ebbd224c DH |
3064 | SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), |
3065 | SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), | |
048e78a5 | 3066 | SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), |
f6a2491c | 3067 | SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), |
a1d6906e | 3068 | SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), |
f6a2491c | 3069 | SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), |
2ca9cac9 | 3070 | SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), |
c5366681 | 3071 | SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), |
4442dd46 | 3072 | SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), |
5637edb2 DH |
3073 | SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", |
3074 | CXT5066_LAPTOP), | |
3075 | SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), | |
4d155641 | 3076 | SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), |
ef61d4e6 | 3077 | SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), |
19593875 | 3078 | SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), |
ab85457f | 3079 | SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), |
84012657 | 3080 | SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), |
b2cb1292 | 3081 | SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), |
a1d6906e | 3082 | SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), |
22f21d51 | 3083 | SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ |
0fb67e98 DD |
3084 | {} |
3085 | }; | |
3086 | ||
3087 | static int patch_cxt5066(struct hda_codec *codec) | |
3088 | { | |
3089 | struct conexant_spec *spec; | |
3090 | int board_config; | |
3091 | ||
3092 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
3093 | if (!spec) | |
3094 | return -ENOMEM; | |
3095 | codec->spec = spec; | |
3096 | ||
3097 | codec->patch_ops = conexant_patch_ops; | |
75f8991d | 3098 | codec->patch_ops.init = conexant_init; |
0fb67e98 DD |
3099 | |
3100 | spec->dell_automute = 0; | |
3101 | spec->multiout.max_channels = 2; | |
3102 | spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); | |
3103 | spec->multiout.dac_nids = cxt5066_dac_nids; | |
f6a2491c AR |
3104 | conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, |
3105 | ARRAY_SIZE(cxt5066_digout_pin_nids)); | |
0fb67e98 DD |
3106 | spec->num_adc_nids = 1; |
3107 | spec->adc_nids = cxt5066_adc_nids; | |
3108 | spec->capsrc_nids = cxt5066_capsrc_nids; | |
3109 | spec->input_mux = &cxt5066_capture_source; | |
3110 | ||
3111 | spec->port_d_mode = PIN_HP; | |
3112 | ||
3113 | spec->num_init_verbs = 1; | |
3114 | spec->init_verbs[0] = cxt5066_init_verbs; | |
3115 | spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); | |
3116 | spec->channel_mode = cxt5066_modes; | |
3117 | spec->cur_adc = 0; | |
3118 | spec->cur_adc_idx = 0; | |
3119 | ||
3507e2a8 TI |
3120 | set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); |
3121 | ||
0fb67e98 DD |
3122 | board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, |
3123 | cxt5066_models, cxt5066_cfg_tbl); | |
3124 | switch (board_config) { | |
3125 | default: | |
3126 | case CXT5066_LAPTOP: | |
3127 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | |
3128 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; | |
3129 | break; | |
3130 | case CXT5066_DELL_LAPTOP: | |
3131 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; | |
3132 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; | |
3133 | ||
3134 | spec->port_d_mode = PIN_OUT; | |
3135 | spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; | |
3136 | spec->num_init_verbs++; | |
3137 | spec->dell_automute = 1; | |
3138 | break; | |
a1d6906e | 3139 | case CXT5066_ASUS: |
048e78a5 DH |
3140 | case CXT5066_HP_LAPTOP: |
3141 | codec->patch_ops.init = cxt5066_init; | |
02b6b5b6 | 3142 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
048e78a5 DH |
3143 | spec->init_verbs[spec->num_init_verbs] = |
3144 | cxt5066_init_verbs_hp_laptop; | |
3145 | spec->num_init_verbs++; | |
a1d6906e DH |
3146 | spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; |
3147 | spec->asus = board_config == CXT5066_ASUS; | |
048e78a5 DH |
3148 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
3149 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; | |
3150 | /* no S/PDIF out */ | |
f6a2491c AR |
3151 | if (board_config == CXT5066_HP_LAPTOP) |
3152 | spec->multiout.dig_out_nid = 0; | |
048e78a5 DH |
3153 | /* input source automatically selected */ |
3154 | spec->input_mux = NULL; | |
3155 | spec->port_d_mode = 0; | |
3156 | spec->mic_boost = 3; /* default 30dB gain */ | |
3157 | break; | |
3158 | ||
0fb67e98 | 3159 | case CXT5066_OLPC_XO_1_5: |
75f8991d DD |
3160 | codec->patch_ops.init = cxt5066_olpc_init; |
3161 | codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; | |
0fb67e98 DD |
3162 | spec->init_verbs[0] = cxt5066_init_verbs_olpc; |
3163 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; | |
c4cfe66c | 3164 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; |
0fb67e98 DD |
3165 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; |
3166 | spec->port_d_mode = 0; | |
c4cfe66c | 3167 | spec->mic_boost = 3; /* default 30dB gain */ |
0fb67e98 DD |
3168 | |
3169 | /* no S/PDIF out */ | |
3170 | spec->multiout.dig_out_nid = 0; | |
3171 | ||
95a618bd ER |
3172 | /* input source automatically selected */ |
3173 | spec->input_mux = NULL; | |
75f8991d DD |
3174 | |
3175 | /* our capture hooks which allow us to turn on the microphone LED | |
3176 | * at the right time */ | |
3177 | spec->capture_prepare = cxt5066_olpc_capture_prepare; | |
3178 | spec->capture_cleanup = cxt5066_olpc_capture_cleanup; | |
95a618bd | 3179 | break; |
1feba3b7 | 3180 | case CXT5066_DELL_VOSTRO: |
75f8991d | 3181 | codec->patch_ops.init = cxt5066_init; |
02b6b5b6 | 3182 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
95a618bd ER |
3183 | spec->init_verbs[0] = cxt5066_init_verbs_vostro; |
3184 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; | |
3185 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; | |
254bba6a | 3186 | spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; |
95a618bd | 3187 | spec->port_d_mode = 0; |
254bba6a | 3188 | spec->dell_vostro = 1; |
c4cfe66c | 3189 | spec->mic_boost = 3; /* default 30dB gain */ |
95a618bd ER |
3190 | |
3191 | /* no S/PDIF out */ | |
3192 | spec->multiout.dig_out_nid = 0; | |
3193 | ||
cfd3d8dc GA |
3194 | /* input source automatically selected */ |
3195 | spec->input_mux = NULL; | |
3196 | break; | |
3197 | case CXT5066_IDEAPAD: | |
3198 | codec->patch_ops.init = cxt5066_init; | |
02b6b5b6 | 3199 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
cfd3d8dc GA |
3200 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
3201 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; | |
3202 | spec->init_verbs[0] = cxt5066_init_verbs_ideapad; | |
3203 | spec->port_d_mode = 0; | |
3204 | spec->ideapad = 1; | |
3205 | spec->mic_boost = 2; /* default 20dB gain */ | |
3206 | ||
3207 | /* no S/PDIF out */ | |
3208 | spec->multiout.dig_out_nid = 0; | |
3209 | ||
7b2bfdbc JT |
3210 | /* input source automatically selected */ |
3211 | spec->input_mux = NULL; | |
3212 | break; | |
3213 | case CXT5066_THINKPAD: | |
3214 | codec->patch_ops.init = cxt5066_init; | |
02b6b5b6 | 3215 | codec->patch_ops.unsol_event = cxt5066_unsol_event; |
7b2bfdbc JT |
3216 | spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; |
3217 | spec->mixers[spec->num_mixers++] = cxt5066_mixers; | |
3218 | spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; | |
3219 | spec->thinkpad = 1; | |
3220 | spec->port_d_mode = PIN_OUT; | |
3221 | spec->mic_boost = 2; /* default 20dB gain */ | |
3222 | ||
3223 | /* no S/PDIF out */ | |
3224 | spec->multiout.dig_out_nid = 0; | |
3225 | ||
0fb67e98 DD |
3226 | /* input source automatically selected */ |
3227 | spec->input_mux = NULL; | |
3228 | break; | |
3229 | } | |
3230 | ||
3507e2a8 TI |
3231 | if (spec->beep_amp) |
3232 | snd_hda_attach_beep_device(codec, spec->beep_amp); | |
3233 | ||
0fb67e98 DD |
3234 | return 0; |
3235 | } | |
461e2c78 | 3236 | |
f2e5731d TI |
3237 | /* |
3238 | * Automatic parser for CX20641 & co | |
3239 | */ | |
3240 | ||
6764bcef TI |
3241 | static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
3242 | struct hda_codec *codec, | |
3243 | unsigned int stream_tag, | |
3244 | unsigned int format, | |
3245 | struct snd_pcm_substream *substream) | |
3246 | { | |
3247 | struct conexant_spec *spec = codec->spec; | |
3248 | hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]]; | |
3249 | if (spec->adc_switching) { | |
3250 | spec->cur_adc = adc; | |
3251 | spec->cur_adc_stream_tag = stream_tag; | |
3252 | spec->cur_adc_format = format; | |
3253 | } | |
3254 | snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); | |
3255 | return 0; | |
3256 | } | |
3257 | ||
3258 | static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
3259 | struct hda_codec *codec, | |
3260 | struct snd_pcm_substream *substream) | |
3261 | { | |
3262 | struct conexant_spec *spec = codec->spec; | |
3263 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | |
3264 | spec->cur_adc = 0; | |
3265 | return 0; | |
3266 | } | |
3267 | ||
3268 | static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { | |
3269 | .substreams = 1, | |
3270 | .channels_min = 2, | |
3271 | .channels_max = 2, | |
3272 | .nid = 0, /* fill later */ | |
3273 | .ops = { | |
3274 | .prepare = cx_auto_capture_pcm_prepare, | |
3275 | .cleanup = cx_auto_capture_pcm_cleanup | |
3276 | }, | |
3277 | }; | |
3278 | ||
34cbe3a6 | 3279 | static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; |
f2e5731d TI |
3280 | |
3281 | /* get the connection index of @nid in the widget @mux */ | |
3282 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, | |
3283 | hda_nid_t nid) | |
3284 | { | |
3285 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; | |
3286 | int i, nums; | |
3287 | ||
3288 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); | |
3289 | for (i = 0; i < nums; i++) | |
3290 | if (conn[i] == nid) | |
3291 | return i; | |
3292 | return -1; | |
3293 | } | |
3294 | ||
3295 | /* get an unassigned DAC from the given list. | |
3296 | * Return the nid if found and reduce the DAC list, or return zero if | |
3297 | * not found | |
3298 | */ | |
3299 | static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, | |
3300 | hda_nid_t *dacs, int *num_dacs) | |
3301 | { | |
3302 | int i, nums = *num_dacs; | |
3303 | hda_nid_t ret = 0; | |
3304 | ||
3305 | for (i = 0; i < nums; i++) { | |
3306 | if (get_connection_index(codec, pin, dacs[i]) >= 0) { | |
3307 | ret = dacs[i]; | |
3308 | break; | |
3309 | } | |
3310 | } | |
3311 | if (!ret) | |
3312 | return 0; | |
3313 | if (--nums > 0) | |
3314 | memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); | |
3315 | *num_dacs = nums; | |
3316 | return ret; | |
3317 | } | |
3318 | ||
3319 | #define MAX_AUTO_DACS 5 | |
3320 | ||
3321 | /* fill analog DAC list from the widget tree */ | |
3322 | static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) | |
3323 | { | |
3324 | hda_nid_t nid, end_nid; | |
3325 | int nums = 0; | |
3326 | ||
3327 | end_nid = codec->start_nid + codec->num_nodes; | |
3328 | for (nid = codec->start_nid; nid < end_nid; nid++) { | |
3329 | unsigned int wcaps = get_wcaps(codec, nid); | |
3330 | unsigned int type = get_wcaps_type(wcaps); | |
3331 | if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { | |
3332 | dacs[nums++] = nid; | |
3333 | if (nums >= MAX_AUTO_DACS) | |
3334 | break; | |
3335 | } | |
3336 | } | |
3337 | return nums; | |
3338 | } | |
3339 | ||
3340 | /* fill pin_dac_pair list from the pin and dac list */ | |
3341 | static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, | |
3342 | int num_pins, hda_nid_t *dacs, int *rest, | |
3343 | struct pin_dac_pair *filled, int type) | |
3344 | { | |
3345 | int i, nums; | |
3346 | ||
3347 | nums = 0; | |
3348 | for (i = 0; i < num_pins; i++) { | |
3349 | filled[nums].pin = pins[i]; | |
3350 | filled[nums].type = type; | |
3351 | filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); | |
3352 | nums++; | |
3353 | } | |
3354 | return nums; | |
3355 | } | |
3356 | ||
3357 | /* parse analog output paths */ | |
3358 | static void cx_auto_parse_output(struct hda_codec *codec) | |
3359 | { | |
3360 | struct conexant_spec *spec = codec->spec; | |
3361 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3362 | hda_nid_t dacs[MAX_AUTO_DACS]; | |
3363 | int i, j, nums, rest; | |
3364 | ||
3365 | rest = fill_cx_auto_dacs(codec, dacs); | |
3366 | /* parse all analog output pins */ | |
3367 | nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, | |
3368 | dacs, &rest, spec->dac_info, | |
3369 | AUTO_PIN_LINE_OUT); | |
3370 | nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, | |
3371 | dacs, &rest, spec->dac_info + nums, | |
3372 | AUTO_PIN_HP_OUT); | |
3373 | nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, | |
3374 | dacs, &rest, spec->dac_info + nums, | |
3375 | AUTO_PIN_SPEAKER_OUT); | |
3376 | spec->dac_info_filled = nums; | |
3377 | /* fill multiout struct */ | |
3378 | for (i = 0; i < nums; i++) { | |
3379 | hda_nid_t dac = spec->dac_info[i].dac; | |
3380 | if (!dac) | |
3381 | continue; | |
3382 | switch (spec->dac_info[i].type) { | |
3383 | case AUTO_PIN_LINE_OUT: | |
3384 | spec->private_dac_nids[spec->multiout.num_dacs] = dac; | |
3385 | spec->multiout.num_dacs++; | |
3386 | break; | |
3387 | case AUTO_PIN_HP_OUT: | |
3388 | case AUTO_PIN_SPEAKER_OUT: | |
3389 | if (!spec->multiout.hp_nid) { | |
3390 | spec->multiout.hp_nid = dac; | |
3391 | break; | |
3392 | } | |
3393 | for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) | |
3394 | if (!spec->multiout.extra_out_nid[j]) { | |
3395 | spec->multiout.extra_out_nid[j] = dac; | |
3396 | break; | |
3397 | } | |
3398 | break; | |
3399 | } | |
3400 | } | |
3401 | spec->multiout.dac_nids = spec->private_dac_nids; | |
89724958 | 3402 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
f2e5731d TI |
3403 | |
3404 | if (cfg->hp_outs > 0) | |
3405 | spec->auto_mute = 1; | |
3406 | spec->vmaster_nid = spec->private_dac_nids[0]; | |
3407 | } | |
3408 | ||
da339866 TI |
3409 | static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, |
3410 | hda_nid_t *pins, bool on); | |
3411 | ||
f2e5731d TI |
3412 | /* auto-mute/unmute speaker and line outs according to headphone jack */ |
3413 | static void cx_auto_hp_automute(struct hda_codec *codec) | |
3414 | { | |
3415 | struct conexant_spec *spec = codec->spec; | |
3416 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3417 | int i, present; | |
3418 | ||
3419 | if (!spec->auto_mute) | |
3420 | return; | |
3421 | present = 0; | |
3422 | for (i = 0; i < cfg->hp_outs; i++) { | |
3423 | if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) { | |
3424 | present = 1; | |
3425 | break; | |
3426 | } | |
3427 | } | |
da339866 | 3428 | cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present); |
f2e5731d TI |
3429 | for (i = 0; i < cfg->line_outs; i++) { |
3430 | snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, | |
3431 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
3432 | present ? 0 : PIN_OUT); | |
3433 | } | |
da339866 | 3434 | cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present); |
fbb5bb56 TI |
3435 | for (i = 0; !present && i < cfg->line_outs; i++) |
3436 | if (snd_hda_jack_detect(codec, cfg->line_out_pins[i])) | |
3437 | present = 1; | |
f2e5731d TI |
3438 | for (i = 0; i < cfg->speaker_outs; i++) { |
3439 | snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, | |
3440 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
3441 | present ? 0 : PIN_OUT); | |
3442 | } | |
da339866 | 3443 | cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present); |
f2e5731d TI |
3444 | } |
3445 | ||
6764bcef TI |
3446 | static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, |
3447 | struct snd_ctl_elem_info *uinfo) | |
3448 | { | |
3449 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3450 | struct conexant_spec *spec = codec->spec; | |
3451 | ||
3452 | return snd_hda_input_mux_info(&spec->private_imux, uinfo); | |
3453 | } | |
3454 | ||
3455 | static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, | |
3456 | struct snd_ctl_elem_value *ucontrol) | |
3457 | { | |
3458 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3459 | struct conexant_spec *spec = codec->spec; | |
3460 | ||
3461 | ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; | |
3462 | return 0; | |
3463 | } | |
3464 | ||
5c9887e0 TI |
3465 | /* look for the route the given pin from mux and return the index; |
3466 | * if do_select is set, actually select the route. | |
3467 | */ | |
3468 | static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, | |
cf27f29a TI |
3469 | hda_nid_t pin, hda_nid_t *srcp, |
3470 | bool do_select, int depth) | |
5c9887e0 TI |
3471 | { |
3472 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; | |
3473 | int i, nums; | |
3474 | ||
cf27f29a TI |
3475 | switch (get_wcaps_type(get_wcaps(codec, mux))) { |
3476 | case AC_WID_AUD_IN: | |
3477 | case AC_WID_AUD_SEL: | |
3478 | case AC_WID_AUD_MIX: | |
3479 | break; | |
3480 | default: | |
3481 | return -1; | |
3482 | } | |
3483 | ||
5c9887e0 TI |
3484 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); |
3485 | for (i = 0; i < nums; i++) | |
3486 | if (conn[i] == pin) { | |
3487 | if (do_select) | |
3488 | snd_hda_codec_write(codec, mux, 0, | |
3489 | AC_VERB_SET_CONNECT_SEL, i); | |
cf27f29a TI |
3490 | if (srcp) |
3491 | *srcp = mux; | |
5c9887e0 TI |
3492 | return i; |
3493 | } | |
3494 | depth++; | |
3495 | if (depth == 2) | |
3496 | return -1; | |
3497 | for (i = 0; i < nums; i++) { | |
cf27f29a | 3498 | int ret = __select_input_connection(codec, conn[i], pin, srcp, |
5c9887e0 TI |
3499 | do_select, depth); |
3500 | if (ret >= 0) { | |
3501 | if (do_select) | |
3502 | snd_hda_codec_write(codec, mux, 0, | |
3503 | AC_VERB_SET_CONNECT_SEL, i); | |
cf27f29a | 3504 | return i; |
5c9887e0 TI |
3505 | } |
3506 | } | |
3507 | return -1; | |
3508 | } | |
3509 | ||
3510 | static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, | |
3511 | hda_nid_t pin) | |
3512 | { | |
cf27f29a | 3513 | __select_input_connection(codec, mux, pin, NULL, true, 0); |
5c9887e0 TI |
3514 | } |
3515 | ||
3516 | static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, | |
3517 | hda_nid_t pin) | |
3518 | { | |
cf27f29a | 3519 | return __select_input_connection(codec, mux, pin, NULL, false, 0); |
5c9887e0 TI |
3520 | } |
3521 | ||
6764bcef TI |
3522 | static int cx_auto_mux_enum_update(struct hda_codec *codec, |
3523 | const struct hda_input_mux *imux, | |
3524 | unsigned int idx) | |
3525 | { | |
3526 | struct conexant_spec *spec = codec->spec; | |
3527 | hda_nid_t adc; | |
3528 | ||
3529 | if (!imux->num_items) | |
3530 | return 0; | |
3531 | if (idx >= imux->num_items) | |
3532 | idx = imux->num_items - 1; | |
3533 | if (spec->cur_mux[0] == idx) | |
3534 | return 0; | |
3535 | adc = spec->imux_adcs[idx]; | |
5c9887e0 TI |
3536 | select_input_connection(codec, spec->imux_adcs[idx], |
3537 | spec->imux_pins[idx]); | |
6764bcef TI |
3538 | if (spec->cur_adc && spec->cur_adc != adc) { |
3539 | /* stream is running, let's swap the current ADC */ | |
3540 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | |
3541 | spec->cur_adc = adc; | |
3542 | snd_hda_codec_setup_stream(codec, adc, | |
3543 | spec->cur_adc_stream_tag, 0, | |
3544 | spec->cur_adc_format); | |
3545 | } | |
3546 | spec->cur_mux[0] = idx; | |
3547 | return 1; | |
3548 | } | |
3549 | ||
3550 | static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, | |
3551 | struct snd_ctl_elem_value *ucontrol) | |
3552 | { | |
3553 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3554 | struct conexant_spec *spec = codec->spec; | |
3555 | ||
3556 | return cx_auto_mux_enum_update(codec, &spec->private_imux, | |
3557 | ucontrol->value.enumerated.item[0]); | |
3558 | } | |
3559 | ||
3560 | static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { | |
3561 | { | |
3562 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3563 | .name = "Capture Source", | |
3564 | .info = cx_auto_mux_enum_info, | |
3565 | .get = cx_auto_mux_enum_get, | |
3566 | .put = cx_auto_mux_enum_put | |
3567 | }, | |
3568 | {} | |
3569 | }; | |
3570 | ||
f2e5731d TI |
3571 | /* automatic switch internal and external mic */ |
3572 | static void cx_auto_automic(struct hda_codec *codec) | |
3573 | { | |
3574 | struct conexant_spec *spec = codec->spec; | |
f2e5731d TI |
3575 | int ext_idx = spec->auto_mic_ext; |
3576 | ||
3577 | if (!spec->auto_mic) | |
3578 | return; | |
f6100bb4 | 3579 | if (snd_hda_jack_detect(codec, spec->imux_pins[ext_idx])) |
6764bcef TI |
3580 | cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx); |
3581 | else | |
3582 | cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx); | |
f2e5731d TI |
3583 | } |
3584 | ||
3585 | static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) | |
3586 | { | |
3587 | int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; | |
3588 | switch (res >> 26) { | |
3589 | case CONEXANT_HP_EVENT: | |
3590 | cx_auto_hp_automute(codec); | |
cd372fb3 | 3591 | snd_hda_input_jack_report(codec, nid); |
f2e5731d TI |
3592 | break; |
3593 | case CONEXANT_MIC_EVENT: | |
3594 | cx_auto_automic(codec); | |
cd372fb3 | 3595 | snd_hda_input_jack_report(codec, nid); |
f2e5731d TI |
3596 | break; |
3597 | } | |
3598 | } | |
3599 | ||
f2e5731d TI |
3600 | /* return true if it's an internal-mic pin */ |
3601 | static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) | |
3602 | { | |
3603 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); | |
3604 | return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && | |
99ae28be | 3605 | snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT; |
f2e5731d TI |
3606 | } |
3607 | ||
3608 | /* return true if it's an external-mic pin */ | |
3609 | static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin) | |
3610 | { | |
3611 | unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); | |
3612 | return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && | |
f68b3b29 TI |
3613 | snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL && |
3614 | (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT); | |
f2e5731d TI |
3615 | } |
3616 | ||
3617 | /* check whether the pin config is suitable for auto-mic switching; | |
3618 | * auto-mic is enabled only when one int-mic and one-ext mic exist | |
3619 | */ | |
3620 | static void cx_auto_check_auto_mic(struct hda_codec *codec) | |
3621 | { | |
3622 | struct conexant_spec *spec = codec->spec; | |
f2e5731d | 3623 | |
f6100bb4 TI |
3624 | if (is_ext_mic(codec, spec->imux_pins[0]) && |
3625 | is_int_mic(codec, spec->imux_pins[1])) { | |
f2e5731d | 3626 | spec->auto_mic = 1; |
2557f742 | 3627 | spec->auto_mic_ext = 0; |
f2e5731d TI |
3628 | return; |
3629 | } | |
f6100bb4 TI |
3630 | if (is_int_mic(codec, spec->imux_pins[0]) && |
3631 | is_ext_mic(codec, spec->imux_pins[1])) { | |
f2e5731d | 3632 | spec->auto_mic = 1; |
2557f742 | 3633 | spec->auto_mic_ext = 1; |
f2e5731d TI |
3634 | return; |
3635 | } | |
3636 | } | |
3637 | ||
3638 | static void cx_auto_parse_input(struct hda_codec *codec) | |
3639 | { | |
3640 | struct conexant_spec *spec = codec->spec; | |
3641 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3642 | struct hda_input_mux *imux; | |
6764bcef | 3643 | int i, j; |
f2e5731d TI |
3644 | |
3645 | imux = &spec->private_imux; | |
3646 | for (i = 0; i < cfg->num_inputs; i++) { | |
6764bcef TI |
3647 | for (j = 0; j < spec->num_adc_nids; j++) { |
3648 | hda_nid_t adc = spec->adc_nids[j]; | |
5c9887e0 TI |
3649 | int idx = get_input_connection(codec, adc, |
3650 | cfg->inputs[i].pin); | |
6764bcef TI |
3651 | if (idx >= 0) { |
3652 | const char *label; | |
3653 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
cf27f29a | 3654 | spec->imux_cfg_idx[imux->num_items] = i; |
f9759301 | 3655 | spec->imux_boost_nid[imux->num_items] = 0; |
f6100bb4 TI |
3656 | spec->imux_adcs[imux->num_items] = adc; |
3657 | spec->imux_pins[imux->num_items] = | |
3658 | cfg->inputs[i].pin; | |
6764bcef | 3659 | snd_hda_add_imux_item(imux, label, idx, NULL); |
6764bcef TI |
3660 | break; |
3661 | } | |
f2e5731d TI |
3662 | } |
3663 | } | |
3664 | if (imux->num_items == 2 && cfg->num_inputs == 2) | |
3665 | cx_auto_check_auto_mic(codec); | |
6764bcef TI |
3666 | if (imux->num_items > 1 && !spec->auto_mic) { |
3667 | for (i = 1; i < imux->num_items; i++) { | |
3668 | if (spec->imux_adcs[i] != spec->imux_adcs[0]) { | |
3669 | spec->adc_switching = 1; | |
3670 | break; | |
3671 | } | |
3672 | } | |
3673 | } | |
f2e5731d TI |
3674 | } |
3675 | ||
3676 | /* get digital-input audio widget corresponding to the given pin */ | |
3677 | static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) | |
3678 | { | |
3679 | hda_nid_t nid, end_nid; | |
3680 | ||
3681 | end_nid = codec->start_nid + codec->num_nodes; | |
3682 | for (nid = codec->start_nid; nid < end_nid; nid++) { | |
3683 | unsigned int wcaps = get_wcaps(codec, nid); | |
3684 | unsigned int type = get_wcaps_type(wcaps); | |
3685 | if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { | |
3686 | if (get_connection_index(codec, nid, pin) >= 0) | |
3687 | return nid; | |
3688 | } | |
3689 | } | |
3690 | return 0; | |
3691 | } | |
3692 | ||
3693 | static void cx_auto_parse_digital(struct hda_codec *codec) | |
3694 | { | |
3695 | struct conexant_spec *spec = codec->spec; | |
3696 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3697 | hda_nid_t nid; | |
3698 | ||
3699 | if (cfg->dig_outs && | |
3700 | snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) | |
3701 | spec->multiout.dig_out_nid = nid; | |
3702 | if (cfg->dig_in_pin) | |
3703 | spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); | |
3704 | } | |
3705 | ||
3706 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | |
3707 | static void cx_auto_parse_beep(struct hda_codec *codec) | |
3708 | { | |
3709 | struct conexant_spec *spec = codec->spec; | |
3710 | hda_nid_t nid, end_nid; | |
3711 | ||
3712 | end_nid = codec->start_nid + codec->num_nodes; | |
3713 | for (nid = codec->start_nid; nid < end_nid; nid++) | |
3714 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { | |
3715 | set_beep_amp(spec, nid, 0, HDA_OUTPUT); | |
3716 | break; | |
3717 | } | |
3718 | } | |
3719 | #else | |
3720 | #define cx_auto_parse_beep(codec) | |
3721 | #endif | |
3722 | ||
3723 | static int cx_auto_parse_auto_config(struct hda_codec *codec) | |
3724 | { | |
3725 | struct conexant_spec *spec = codec->spec; | |
3726 | int err; | |
3727 | ||
3728 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
3729 | if (err < 0) | |
3730 | return err; | |
3731 | ||
3732 | cx_auto_parse_output(codec); | |
3733 | cx_auto_parse_input(codec); | |
3734 | cx_auto_parse_digital(codec); | |
3735 | cx_auto_parse_beep(codec); | |
3736 | return 0; | |
3737 | } | |
3738 | ||
da339866 TI |
3739 | static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, |
3740 | hda_nid_t *pins, bool on) | |
f2e5731d TI |
3741 | { |
3742 | int i; | |
3743 | for (i = 0; i < num_pins; i++) { | |
3744 | if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) | |
3745 | snd_hda_codec_write(codec, pins[i], 0, | |
da339866 TI |
3746 | AC_VERB_SET_EAPD_BTLENABLE, |
3747 | on ? 0x02 : 0); | |
f2e5731d TI |
3748 | } |
3749 | } | |
3750 | ||
3751 | static void select_connection(struct hda_codec *codec, hda_nid_t pin, | |
3752 | hda_nid_t src) | |
3753 | { | |
3754 | int idx = get_connection_index(codec, pin, src); | |
3755 | if (idx >= 0) | |
3756 | snd_hda_codec_write(codec, pin, 0, | |
3757 | AC_VERB_SET_CONNECT_SEL, idx); | |
3758 | } | |
3759 | ||
1f8458a2 TI |
3760 | static void mute_outputs(struct hda_codec *codec, int num_nids, |
3761 | const hda_nid_t *nids) | |
f2e5731d | 3762 | { |
0ad1b5b6 | 3763 | int i, val; |
f2e5731d | 3764 | |
1f8458a2 TI |
3765 | for (i = 0; i < num_nids; i++) { |
3766 | hda_nid_t nid = nids[i]; | |
3767 | if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) | |
3768 | continue; | |
0ad1b5b6 TI |
3769 | if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
3770 | val = AMP_OUT_MUTE; | |
3771 | else | |
3772 | val = AMP_OUT_ZERO; | |
3773 | snd_hda_codec_write(codec, nid, 0, | |
3774 | AC_VERB_SET_AMP_GAIN_MUTE, val); | |
3775 | } | |
1f8458a2 | 3776 | } |
f2e5731d | 3777 | |
1f8458a2 TI |
3778 | static void cx_auto_init_output(struct hda_codec *codec) |
3779 | { | |
3780 | struct conexant_spec *spec = codec->spec; | |
3781 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3782 | hda_nid_t nid; | |
3783 | int i; | |
3784 | ||
3785 | mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); | |
f2e5731d TI |
3786 | for (i = 0; i < cfg->hp_outs; i++) |
3787 | snd_hda_codec_write(codec, cfg->hp_pins[i], 0, | |
3788 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); | |
1f8458a2 TI |
3789 | mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); |
3790 | mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); | |
3791 | mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); | |
f2e5731d TI |
3792 | if (spec->auto_mute) { |
3793 | for (i = 0; i < cfg->hp_outs; i++) { | |
3794 | snd_hda_codec_write(codec, cfg->hp_pins[i], 0, | |
3795 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
3796 | AC_USRSP_EN | CONEXANT_HP_EVENT); | |
3797 | } | |
3798 | cx_auto_hp_automute(codec); | |
3799 | } else { | |
3800 | for (i = 0; i < cfg->line_outs; i++) | |
3801 | snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, | |
3802 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | |
3803 | for (i = 0; i < cfg->speaker_outs; i++) | |
3804 | snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, | |
3805 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | |
da339866 TI |
3806 | /* turn on EAPD */ |
3807 | cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, | |
3808 | true); | |
3809 | cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, | |
3810 | true); | |
3811 | cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, | |
3812 | true); | |
f2e5731d TI |
3813 | } |
3814 | ||
3815 | for (i = 0; i < spec->dac_info_filled; i++) { | |
3816 | nid = spec->dac_info[i].dac; | |
3817 | if (!nid) | |
3818 | nid = spec->multiout.dac_nids[0]; | |
3819 | select_connection(codec, spec->dac_info[i].pin, nid); | |
3820 | } | |
f2e5731d TI |
3821 | } |
3822 | ||
3823 | static void cx_auto_init_input(struct hda_codec *codec) | |
3824 | { | |
3825 | struct conexant_spec *spec = codec->spec; | |
3826 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
0ad1b5b6 | 3827 | int i, val; |
f2e5731d | 3828 | |
0ad1b5b6 TI |
3829 | for (i = 0; i < spec->num_adc_nids; i++) { |
3830 | hda_nid_t nid = spec->adc_nids[i]; | |
1f8458a2 TI |
3831 | if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) |
3832 | continue; | |
0ad1b5b6 TI |
3833 | if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) |
3834 | val = AMP_IN_MUTE(0); | |
3835 | else | |
3836 | val = AMP_IN_UNMUTE(0); | |
3837 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
3838 | val); | |
3839 | } | |
f2e5731d TI |
3840 | |
3841 | for (i = 0; i < cfg->num_inputs; i++) { | |
3842 | unsigned int type; | |
3843 | if (cfg->inputs[i].type == AUTO_PIN_MIC) | |
3844 | type = PIN_VREF80; | |
3845 | else | |
3846 | type = PIN_IN; | |
3847 | snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, | |
3848 | AC_VERB_SET_PIN_WIDGET_CONTROL, type); | |
3849 | } | |
3850 | ||
3851 | if (spec->auto_mic) { | |
3852 | int ext_idx = spec->auto_mic_ext; | |
3853 | snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0, | |
3854 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
3855 | AC_USRSP_EN | CONEXANT_MIC_EVENT); | |
3856 | cx_auto_automic(codec); | |
3857 | } else { | |
5c9887e0 TI |
3858 | select_input_connection(codec, spec->imux_adcs[0], |
3859 | spec->imux_pins[0]); | |
f2e5731d TI |
3860 | } |
3861 | } | |
3862 | ||
3863 | static void cx_auto_init_digital(struct hda_codec *codec) | |
3864 | { | |
3865 | struct conexant_spec *spec = codec->spec; | |
3866 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
3867 | ||
3868 | if (spec->multiout.dig_out_nid) | |
3869 | snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, | |
3870 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | |
3871 | if (spec->dig_in_nid) | |
3872 | snd_hda_codec_write(codec, cfg->dig_in_pin, 0, | |
3873 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | |
3874 | } | |
3875 | ||
3876 | static int cx_auto_init(struct hda_codec *codec) | |
3877 | { | |
3878 | /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ | |
3879 | cx_auto_init_output(codec); | |
3880 | cx_auto_init_input(codec); | |
3881 | cx_auto_init_digital(codec); | |
3882 | return 0; | |
3883 | } | |
3884 | ||
983345e5 | 3885 | static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, |
f2e5731d | 3886 | const char *dir, int cidx, |
983345e5 | 3887 | hda_nid_t nid, int hda_dir, int amp_idx) |
f2e5731d TI |
3888 | { |
3889 | static char name[32]; | |
3890 | static struct snd_kcontrol_new knew[] = { | |
3891 | HDA_CODEC_VOLUME(name, 0, 0, 0), | |
3892 | HDA_CODEC_MUTE(name, 0, 0, 0), | |
3893 | }; | |
34cbe3a6 | 3894 | static const char * const sfx[2] = { "Volume", "Switch" }; |
f2e5731d TI |
3895 | int i, err; |
3896 | ||
3897 | for (i = 0; i < 2; i++) { | |
3898 | struct snd_kcontrol *kctl; | |
983345e5 DH |
3899 | knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, |
3900 | hda_dir); | |
f2e5731d TI |
3901 | knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; |
3902 | knew[i].index = cidx; | |
3903 | snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); | |
3904 | kctl = snd_ctl_new1(&knew[i], codec); | |
3905 | if (!kctl) | |
3906 | return -ENOMEM; | |
3907 | err = snd_hda_ctl_add(codec, nid, kctl); | |
3908 | if (err < 0) | |
3909 | return err; | |
3910 | if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) | |
3911 | break; | |
3912 | } | |
3913 | return 0; | |
3914 | } | |
3915 | ||
983345e5 DH |
3916 | #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ |
3917 | cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) | |
3918 | ||
f2e5731d TI |
3919 | #define cx_auto_add_pb_volume(codec, nid, str, idx) \ |
3920 | cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) | |
3921 | ||
1f8458a2 TI |
3922 | static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, |
3923 | hda_nid_t pin, const char *name, int idx) | |
3924 | { | |
3925 | unsigned int caps; | |
3926 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); | |
3927 | if (caps & AC_AMPCAP_NUM_STEPS) | |
3928 | return cx_auto_add_pb_volume(codec, dac, name, idx); | |
3929 | caps = query_amp_caps(codec, pin, HDA_OUTPUT); | |
3930 | if (caps & AC_AMPCAP_NUM_STEPS) | |
3931 | return cx_auto_add_pb_volume(codec, pin, name, idx); | |
3932 | return 0; | |
3933 | } | |
3934 | ||
f2e5731d TI |
3935 | static int cx_auto_build_output_controls(struct hda_codec *codec) |
3936 | { | |
3937 | struct conexant_spec *spec = codec->spec; | |
3938 | int i, err; | |
3939 | int num_line = 0, num_hp = 0, num_spk = 0; | |
ea734963 | 3940 | static const char * const texts[3] = { "Front", "Surround", "CLFE" }; |
f2e5731d TI |
3941 | |
3942 | if (spec->dac_info_filled == 1) | |
1f8458a2 TI |
3943 | return try_add_pb_volume(codec, spec->dac_info[0].dac, |
3944 | spec->dac_info[0].pin, | |
3945 | "Master", 0); | |
3946 | ||
f2e5731d TI |
3947 | for (i = 0; i < spec->dac_info_filled; i++) { |
3948 | const char *label; | |
3949 | int idx, type; | |
3950 | if (!spec->dac_info[i].dac) | |
3951 | continue; | |
3952 | type = spec->dac_info[i].type; | |
3953 | if (type == AUTO_PIN_LINE_OUT) | |
3954 | type = spec->autocfg.line_out_type; | |
3955 | switch (type) { | |
3956 | case AUTO_PIN_LINE_OUT: | |
3957 | default: | |
3958 | label = texts[num_line++]; | |
3959 | idx = 0; | |
3960 | break; | |
3961 | case AUTO_PIN_HP_OUT: | |
3962 | label = "Headphone"; | |
3963 | idx = num_hp++; | |
3964 | break; | |
3965 | case AUTO_PIN_SPEAKER_OUT: | |
3966 | label = "Speaker"; | |
3967 | idx = num_spk++; | |
3968 | break; | |
3969 | } | |
1f8458a2 TI |
3970 | err = try_add_pb_volume(codec, spec->dac_info[i].dac, |
3971 | spec->dac_info[i].pin, | |
3972 | label, idx); | |
f2e5731d TI |
3973 | if (err < 0) |
3974 | return err; | |
3975 | } | |
3976 | return 0; | |
3977 | } | |
3978 | ||
6764bcef TI |
3979 | static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, |
3980 | const char *label, const char *pfx, | |
3981 | int cidx) | |
3982 | { | |
3983 | struct conexant_spec *spec = codec->spec; | |
3984 | int i; | |
3985 | ||
3986 | for (i = 0; i < spec->num_adc_nids; i++) { | |
3987 | hda_nid_t adc_nid = spec->adc_nids[i]; | |
5c9887e0 | 3988 | int idx = get_input_connection(codec, adc_nid, nid); |
6764bcef TI |
3989 | if (idx < 0) |
3990 | continue; | |
3991 | return cx_auto_add_volume_idx(codec, label, pfx, | |
3992 | cidx, adc_nid, HDA_INPUT, idx); | |
3993 | } | |
3994 | return 0; | |
3995 | } | |
3996 | ||
cf27f29a TI |
3997 | static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, |
3998 | const char *label, int cidx) | |
3999 | { | |
4000 | struct conexant_spec *spec = codec->spec; | |
4001 | hda_nid_t mux, nid; | |
f9759301 | 4002 | int i, con; |
cf27f29a TI |
4003 | |
4004 | nid = spec->imux_pins[idx]; | |
4005 | if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) | |
4006 | return cx_auto_add_volume(codec, label, " Boost", cidx, | |
4007 | nid, HDA_INPUT); | |
4008 | con = __select_input_connection(codec, spec->imux_adcs[idx], nid, &mux, | |
4009 | false, 0); | |
4010 | if (con < 0) | |
4011 | return 0; | |
f9759301 TI |
4012 | for (i = 0; i < idx; i++) { |
4013 | if (spec->imux_boost_nid[i] == mux) | |
4014 | return 0; /* already present */ | |
4015 | } | |
4016 | ||
4017 | if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { | |
4018 | spec->imux_boost_nid[idx] = mux; | |
cf27f29a TI |
4019 | return cx_auto_add_volume(codec, label, " Boost", 0, |
4020 | mux, HDA_OUTPUT); | |
f9759301 | 4021 | } |
cf27f29a TI |
4022 | return 0; |
4023 | } | |
4024 | ||
f2e5731d TI |
4025 | static int cx_auto_build_input_controls(struct hda_codec *codec) |
4026 | { | |
4027 | struct conexant_spec *spec = codec->spec; | |
cf27f29a TI |
4028 | struct hda_input_mux *imux = &spec->private_imux; |
4029 | const char *prev_label; | |
4030 | int input_conn[HDA_MAX_NUM_INPUTS]; | |
6764bcef | 4031 | int i, err, cidx; |
cf27f29a TI |
4032 | int multi_connection; |
4033 | ||
4034 | multi_connection = 0; | |
4035 | for (i = 0; i < imux->num_items; i++) { | |
4036 | cidx = get_input_connection(codec, spec->imux_adcs[i], | |
4037 | spec->imux_pins[i]); | |
4038 | input_conn[i] = (spec->imux_adcs[i] << 8) | cidx; | |
4039 | if (i > 0 && input_conn[i] != input_conn[0]) | |
4040 | multi_connection = 1; | |
4041 | } | |
f2e5731d | 4042 | |
f2e5731d TI |
4043 | prev_label = NULL; |
4044 | cidx = 0; | |
cf27f29a TI |
4045 | for (i = 0; i < imux->num_items; i++) { |
4046 | hda_nid_t nid = spec->imux_pins[i]; | |
f2e5731d | 4047 | const char *label; |
983345e5 | 4048 | |
cf27f29a TI |
4049 | label = hda_get_autocfg_input_label(codec, &spec->autocfg, |
4050 | spec->imux_cfg_idx[i]); | |
f2e5731d TI |
4051 | if (label == prev_label) |
4052 | cidx++; | |
4053 | else | |
4054 | cidx = 0; | |
4055 | prev_label = label; | |
983345e5 | 4056 | |
cf27f29a TI |
4057 | err = cx_auto_add_boost_volume(codec, i, label, cidx); |
4058 | if (err < 0) | |
4059 | return err; | |
983345e5 | 4060 | |
cf27f29a | 4061 | if (!multi_connection) { |
f9759301 TI |
4062 | if (i > 0) |
4063 | continue; | |
6764bcef TI |
4064 | err = cx_auto_add_capture_volume(codec, nid, |
4065 | "Capture", "", cidx); | |
4066 | } else { | |
4067 | err = cx_auto_add_capture_volume(codec, nid, | |
4068 | label, " Capture", cidx); | |
983345e5 | 4069 | } |
6764bcef TI |
4070 | if (err < 0) |
4071 | return err; | |
4072 | } | |
4073 | ||
4074 | if (spec->private_imux.num_items > 1 && !spec->auto_mic) { | |
4075 | err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); | |
4076 | if (err < 0) | |
4077 | return err; | |
f2e5731d | 4078 | } |
6764bcef | 4079 | |
f2e5731d TI |
4080 | return 0; |
4081 | } | |
4082 | ||
4083 | static int cx_auto_build_controls(struct hda_codec *codec) | |
4084 | { | |
4085 | int err; | |
4086 | ||
4087 | err = cx_auto_build_output_controls(codec); | |
4088 | if (err < 0) | |
4089 | return err; | |
4090 | err = cx_auto_build_input_controls(codec); | |
4091 | if (err < 0) | |
4092 | return err; | |
4093 | return conexant_build_controls(codec); | |
4094 | } | |
4095 | ||
22ce5f74 TI |
4096 | static int cx_auto_search_adcs(struct hda_codec *codec) |
4097 | { | |
4098 | struct conexant_spec *spec = codec->spec; | |
4099 | hda_nid_t nid, end_nid; | |
4100 | ||
4101 | end_nid = codec->start_nid + codec->num_nodes; | |
4102 | for (nid = codec->start_nid; nid < end_nid; nid++) { | |
4103 | unsigned int caps = get_wcaps(codec, nid); | |
4104 | if (get_wcaps_type(caps) != AC_WID_AUD_IN) | |
4105 | continue; | |
4106 | if (caps & AC_WCAP_DIGITAL) | |
4107 | continue; | |
4108 | if (snd_BUG_ON(spec->num_adc_nids >= | |
4109 | ARRAY_SIZE(spec->private_adc_nids))) | |
4110 | break; | |
4111 | spec->private_adc_nids[spec->num_adc_nids++] = nid; | |
4112 | } | |
4113 | spec->adc_nids = spec->private_adc_nids; | |
4114 | return 0; | |
4115 | } | |
4116 | ||
4117 | ||
34cbe3a6 | 4118 | static const struct hda_codec_ops cx_auto_patch_ops = { |
f2e5731d TI |
4119 | .build_controls = cx_auto_build_controls, |
4120 | .build_pcms = conexant_build_pcms, | |
4121 | .init = cx_auto_init, | |
4122 | .free = conexant_free, | |
4123 | .unsol_event = cx_auto_unsol_event, | |
4124 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4125 | .suspend = conexant_suspend, | |
4126 | #endif | |
4127 | .reboot_notify = snd_hda_shutup_pins, | |
4128 | }; | |
4129 | ||
4130 | static int patch_conexant_auto(struct hda_codec *codec) | |
4131 | { | |
4132 | struct conexant_spec *spec; | |
4133 | int err; | |
4134 | ||
1f8458a2 TI |
4135 | printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", |
4136 | codec->chip_name); | |
4137 | ||
f2e5731d TI |
4138 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
4139 | if (!spec) | |
4140 | return -ENOMEM; | |
4141 | codec->spec = spec; | |
1387cde5 | 4142 | codec->pin_amp_workaround = 1; |
22ce5f74 TI |
4143 | err = cx_auto_search_adcs(codec); |
4144 | if (err < 0) | |
4145 | return err; | |
f2e5731d TI |
4146 | err = cx_auto_parse_auto_config(codec); |
4147 | if (err < 0) { | |
4148 | kfree(codec->spec); | |
4149 | codec->spec = NULL; | |
4150 | return err; | |
4151 | } | |
6764bcef | 4152 | spec->capture_stream = &cx_auto_pcm_analog_capture; |
f2e5731d TI |
4153 | codec->patch_ops = cx_auto_patch_ops; |
4154 | if (spec->beep_amp) | |
4155 | snd_hda_attach_beep_device(codec, spec->beep_amp); | |
4156 | return 0; | |
4157 | } | |
4158 | ||
461e2c78 TI |
4159 | /* |
4160 | */ | |
4161 | ||
34cbe3a6 | 4162 | static const struct hda_codec_preset snd_hda_preset_conexant[] = { |
82f30040 TD |
4163 | { .id = 0x14f15045, .name = "CX20549 (Venice)", |
4164 | .patch = patch_cxt5045 }, | |
4165 | { .id = 0x14f15047, .name = "CX20551 (Waikiki)", | |
4166 | .patch = patch_cxt5047 }, | |
461e2c78 TI |
4167 | { .id = 0x14f15051, .name = "CX20561 (Hermosa)", |
4168 | .patch = patch_cxt5051 }, | |
0fb67e98 DD |
4169 | { .id = 0x14f15066, .name = "CX20582 (Pebble)", |
4170 | .patch = patch_cxt5066 }, | |
95a618bd ER |
4171 | { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", |
4172 | .patch = patch_cxt5066 }, | |
850eab9d TI |
4173 | { .id = 0x14f15068, .name = "CX20584", |
4174 | .patch = patch_cxt5066 }, | |
7b2bfdbc JT |
4175 | { .id = 0x14f15069, .name = "CX20585", |
4176 | .patch = patch_cxt5066 }, | |
6da8b516 DH |
4177 | { .id = 0x14f1506e, .name = "CX20590", |
4178 | .patch = patch_cxt5066 }, | |
f2e5731d TI |
4179 | { .id = 0x14f15097, .name = "CX20631", |
4180 | .patch = patch_conexant_auto }, | |
4181 | { .id = 0x14f15098, .name = "CX20632", | |
4182 | .patch = patch_conexant_auto }, | |
4183 | { .id = 0x14f150a1, .name = "CX20641", | |
4184 | .patch = patch_conexant_auto }, | |
4185 | { .id = 0x14f150a2, .name = "CX20642", | |
4186 | .patch = patch_conexant_auto }, | |
4187 | { .id = 0x14f150ab, .name = "CX20651", | |
4188 | .patch = patch_conexant_auto }, | |
4189 | { .id = 0x14f150ac, .name = "CX20652", | |
4190 | .patch = patch_conexant_auto }, | |
4191 | { .id = 0x14f150b8, .name = "CX20664", | |
4192 | .patch = patch_conexant_auto }, | |
4193 | { .id = 0x14f150b9, .name = "CX20665", | |
4194 | .patch = patch_conexant_auto }, | |
c9b443d4 TD |
4195 | {} /* terminator */ |
4196 | }; | |
1289e9e8 TI |
4197 | |
4198 | MODULE_ALIAS("snd-hda-codec-id:14f15045"); | |
4199 | MODULE_ALIAS("snd-hda-codec-id:14f15047"); | |
4200 | MODULE_ALIAS("snd-hda-codec-id:14f15051"); | |
0fb67e98 | 4201 | MODULE_ALIAS("snd-hda-codec-id:14f15066"); |
95a618bd | 4202 | MODULE_ALIAS("snd-hda-codec-id:14f15067"); |
850eab9d | 4203 | MODULE_ALIAS("snd-hda-codec-id:14f15068"); |
7b2bfdbc | 4204 | MODULE_ALIAS("snd-hda-codec-id:14f15069"); |
6da8b516 | 4205 | MODULE_ALIAS("snd-hda-codec-id:14f1506e"); |
f2e5731d TI |
4206 | MODULE_ALIAS("snd-hda-codec-id:14f15097"); |
4207 | MODULE_ALIAS("snd-hda-codec-id:14f15098"); | |
4208 | MODULE_ALIAS("snd-hda-codec-id:14f150a1"); | |
4209 | MODULE_ALIAS("snd-hda-codec-id:14f150a2"); | |
4210 | MODULE_ALIAS("snd-hda-codec-id:14f150ab"); | |
4211 | MODULE_ALIAS("snd-hda-codec-id:14f150ac"); | |
4212 | MODULE_ALIAS("snd-hda-codec-id:14f150b8"); | |
4213 | MODULE_ALIAS("snd-hda-codec-id:14f150b9"); | |
1289e9e8 TI |
4214 | |
4215 | MODULE_LICENSE("GPL"); | |
4216 | MODULE_DESCRIPTION("Conexant HD-audio codec"); | |
4217 | ||
4218 | static struct hda_codec_preset_list conexant_list = { | |
4219 | .preset = snd_hda_preset_conexant, | |
4220 | .owner = THIS_MODULE, | |
4221 | }; | |
4222 | ||
4223 | static int __init patch_conexant_init(void) | |
4224 | { | |
4225 | return snd_hda_add_codec_preset(&conexant_list); | |
4226 | } | |
4227 | ||
4228 | static void __exit patch_conexant_exit(void) | |
4229 | { | |
4230 | snd_hda_delete_codec_preset(&conexant_list); | |
4231 | } | |
4232 | ||
4233 | module_init(patch_conexant_init) | |
4234 | module_exit(patch_conexant_exit) |