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