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