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