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