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