diff options
author | Takashi Iwai <tiwai@suse.de> | 2012-12-19 10:39:18 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2013-01-12 02:44:55 -0500 |
commit | 1077a024812d3b2d76a7a371df75795a276d9dd8 (patch) | |
tree | 4718d75d6be614f8674f65b8798cf13a2edf469d | |
parent | 8fadf1da3f370dacbeb4c30fd015a6d2cc47f2fa (diff) |
ALSA: hda - Use generic parser for Cirrus codec driver
This time, the target is Cirrus codec. Its parser is a subset of
generic parser, so we can migrate fully with it now.
The only tricky part is the handling of SPDIF automute.
Cirrus driver sets the SPDIF out plug over the headphone. As a
workaround, set spec->gen.master_mute for toggling the headphone (and
other) mute.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/hda/Kconfig | 1 | ||||
-rw-r--r-- | sound/pci/hda/patch_cirrus.c | 1287 |
2 files changed, 99 insertions, 1189 deletions
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig index 9aff5cfafe2b..07025a9339ef 100644 --- a/sound/pci/hda/Kconfig +++ b/sound/pci/hda/Kconfig | |||
@@ -149,6 +149,7 @@ config SND_HDA_CODEC_HDMI | |||
149 | config SND_HDA_CODEC_CIRRUS | 149 | config SND_HDA_CODEC_CIRRUS |
150 | bool "Build Cirrus Logic codec support" | 150 | bool "Build Cirrus Logic codec support" |
151 | default y | 151 | default y |
152 | select SND_HDA_GENERIC | ||
152 | help | 153 | help |
153 | Say Y here to include Cirrus Logic codec support in | 154 | Say Y here to include Cirrus Logic codec support in |
154 | snd-hda-intel driver, such as CS4206. | 155 | snd-hda-intel driver, such as CS4206. |
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c index 7b0b8c305737..b9dfbd85d550 100644 --- a/sound/pci/hda/patch_cirrus.c +++ b/sound/pci/hda/patch_cirrus.c | |||
@@ -24,37 +24,18 @@ | |||
24 | #include <linux/pci.h> | 24 | #include <linux/pci.h> |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <sound/core.h> | 26 | #include <sound/core.h> |
27 | #include <sound/tlv.h> | ||
27 | #include "hda_codec.h" | 28 | #include "hda_codec.h" |
28 | #include "hda_local.h" | 29 | #include "hda_local.h" |
29 | #include "hda_auto_parser.h" | 30 | #include "hda_auto_parser.h" |
30 | #include "hda_jack.h" | 31 | #include "hda_jack.h" |
31 | #include <sound/tlv.h> | 32 | #include "hda_generic.h" |
32 | 33 | ||
33 | /* | 34 | /* |
34 | */ | 35 | */ |
35 | 36 | ||
36 | struct cs_spec { | 37 | struct cs_spec { |
37 | struct auto_pin_cfg autocfg; | 38 | struct hda_gen_spec gen; |
38 | struct hda_multi_out multiout; | ||
39 | struct snd_kcontrol *vmaster_sw; | ||
40 | struct snd_kcontrol *vmaster_vol; | ||
41 | |||
42 | hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS]; | ||
43 | hda_nid_t slave_dig_outs[2]; | ||
44 | |||
45 | unsigned int input_idx[AUTO_PIN_LAST]; | ||
46 | unsigned int capsrc_idx[AUTO_PIN_LAST]; | ||
47 | hda_nid_t adc_nid[AUTO_PIN_LAST]; | ||
48 | unsigned int adc_idx[AUTO_PIN_LAST]; | ||
49 | unsigned int num_inputs; | ||
50 | unsigned int cur_input; | ||
51 | unsigned int automic_idx; | ||
52 | hda_nid_t cur_adc; | ||
53 | unsigned int cur_adc_stream_tag; | ||
54 | unsigned int cur_adc_format; | ||
55 | hda_nid_t dig_in; | ||
56 | |||
57 | const struct hda_bind_ctls *capture_bind[2]; | ||
58 | 39 | ||
59 | unsigned int gpio_mask; | 40 | unsigned int gpio_mask; |
60 | unsigned int gpio_dir; | 41 | unsigned int gpio_dir; |
@@ -62,17 +43,11 @@ struct cs_spec { | |||
62 | unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */ | 43 | unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */ |
63 | unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */ | 44 | unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */ |
64 | 45 | ||
65 | struct hda_pcm pcm_rec[2]; /* PCM information */ | ||
66 | |||
67 | unsigned int hp_detect:1; | ||
68 | unsigned int mic_detect:1; | ||
69 | unsigned int speaker_2_1:1; | ||
70 | /* CS421x */ | 46 | /* CS421x */ |
71 | unsigned int spdif_detect:1; | 47 | unsigned int spdif_detect:1; |
48 | unsigned int spdif_present:1; | ||
72 | unsigned int sense_b:1; | 49 | unsigned int sense_b:1; |
73 | hda_nid_t vendor_nid; | 50 | hda_nid_t vendor_nid; |
74 | struct hda_input_mux input_mux; | ||
75 | unsigned int last_input; | ||
76 | }; | 51 | }; |
77 | 52 | ||
78 | /* available models with CS420x */ | 53 | /* available models with CS420x */ |
@@ -178,915 +153,43 @@ static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, | |||
178 | AC_VERB_SET_PROC_COEF, coef); | 153 | AC_VERB_SET_PROC_COEF, coef); |
179 | } | 154 | } |
180 | 155 | ||
181 | |||
182 | #define HP_EVENT 1 | ||
183 | #define MIC_EVENT 2 | ||
184 | |||
185 | /* | ||
186 | * PCM callbacks | ||
187 | */ | ||
188 | static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo, | ||
189 | struct hda_codec *codec, | ||
190 | struct snd_pcm_substream *substream) | ||
191 | { | ||
192 | struct cs_spec *spec = codec->spec; | ||
193 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | ||
194 | hinfo); | ||
195 | } | ||
196 | |||
197 | static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
198 | struct hda_codec *codec, | ||
199 | unsigned int stream_tag, | ||
200 | unsigned int format, | ||
201 | struct snd_pcm_substream *substream) | ||
202 | { | ||
203 | struct cs_spec *spec = codec->spec; | ||
204 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | ||
205 | stream_tag, format, substream); | ||
206 | } | ||
207 | |||
208 | static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
209 | struct hda_codec *codec, | ||
210 | struct snd_pcm_substream *substream) | ||
211 | { | ||
212 | struct cs_spec *spec = codec->spec; | ||
213 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | ||
214 | } | ||
215 | |||
216 | /* | ||
217 | * Digital out | ||
218 | */ | ||
219 | static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | ||
220 | struct hda_codec *codec, | ||
221 | struct snd_pcm_substream *substream) | ||
222 | { | ||
223 | struct cs_spec *spec = codec->spec; | ||
224 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | ||
225 | } | ||
226 | |||
227 | static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | ||
228 | struct hda_codec *codec, | ||
229 | struct snd_pcm_substream *substream) | ||
230 | { | ||
231 | struct cs_spec *spec = codec->spec; | ||
232 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | ||
233 | } | ||
234 | |||
235 | static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
236 | struct hda_codec *codec, | ||
237 | unsigned int stream_tag, | ||
238 | unsigned int format, | ||
239 | struct snd_pcm_substream *substream) | ||
240 | { | ||
241 | struct cs_spec *spec = codec->spec; | ||
242 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, | ||
243 | format, substream); | ||
244 | } | ||
245 | |||
246 | static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
247 | struct hda_codec *codec, | ||
248 | struct snd_pcm_substream *substream) | ||
249 | { | ||
250 | struct cs_spec *spec = codec->spec; | ||
251 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | ||
252 | } | ||
253 | |||
254 | static void cs_update_input_select(struct hda_codec *codec) | ||
255 | { | ||
256 | struct cs_spec *spec = codec->spec; | ||
257 | if (spec->cur_adc) | ||
258 | snd_hda_codec_write(codec, spec->cur_adc, 0, | ||
259 | AC_VERB_SET_CONNECT_SEL, | ||
260 | spec->adc_idx[spec->cur_input]); | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * Analog capture | ||
265 | */ | ||
266 | static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
267 | struct hda_codec *codec, | ||
268 | unsigned int stream_tag, | ||
269 | unsigned int format, | ||
270 | struct snd_pcm_substream *substream) | ||
271 | { | ||
272 | struct cs_spec *spec = codec->spec; | ||
273 | spec->cur_adc = spec->adc_nid[spec->cur_input]; | ||
274 | spec->cur_adc_stream_tag = stream_tag; | ||
275 | spec->cur_adc_format = format; | ||
276 | cs_update_input_select(codec); | ||
277 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | ||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
282 | struct hda_codec *codec, | ||
283 | struct snd_pcm_substream *substream) | ||
284 | { | ||
285 | struct cs_spec *spec = codec->spec; | ||
286 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | ||
287 | spec->cur_adc = 0; | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | /* | ||
292 | */ | ||
293 | static const struct hda_pcm_stream cs_pcm_analog_playback = { | ||
294 | .substreams = 1, | ||
295 | .channels_min = 2, | ||
296 | .channels_max = 2, | ||
297 | .ops = { | ||
298 | .open = cs_playback_pcm_open, | ||
299 | .prepare = cs_playback_pcm_prepare, | ||
300 | .cleanup = cs_playback_pcm_cleanup | ||
301 | }, | ||
302 | }; | ||
303 | |||
304 | static const struct hda_pcm_stream cs_pcm_analog_capture = { | ||
305 | .substreams = 1, | ||
306 | .channels_min = 2, | ||
307 | .channels_max = 2, | ||
308 | .ops = { | ||
309 | .prepare = cs_capture_pcm_prepare, | ||
310 | .cleanup = cs_capture_pcm_cleanup | ||
311 | }, | ||
312 | }; | ||
313 | |||
314 | static const struct hda_pcm_stream cs_pcm_digital_playback = { | ||
315 | .substreams = 1, | ||
316 | .channels_min = 2, | ||
317 | .channels_max = 2, | ||
318 | .ops = { | ||
319 | .open = cs_dig_playback_pcm_open, | ||
320 | .close = cs_dig_playback_pcm_close, | ||
321 | .prepare = cs_dig_playback_pcm_prepare, | ||
322 | .cleanup = cs_dig_playback_pcm_cleanup | ||
323 | }, | ||
324 | }; | ||
325 | |||
326 | static const struct hda_pcm_stream cs_pcm_digital_capture = { | ||
327 | .substreams = 1, | ||
328 | .channels_min = 2, | ||
329 | .channels_max = 2, | ||
330 | }; | ||
331 | |||
332 | static int cs_build_pcms(struct hda_codec *codec) | ||
333 | { | ||
334 | struct cs_spec *spec = codec->spec; | ||
335 | struct hda_pcm *info = spec->pcm_rec; | ||
336 | |||
337 | codec->pcm_info = info; | ||
338 | codec->num_pcms = 0; | ||
339 | |||
340 | info->name = "Cirrus Analog"; | ||
341 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback; | ||
342 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0]; | ||
343 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | ||
344 | spec->multiout.max_channels; | ||
345 | if (spec->speaker_2_1) | ||
346 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap = | ||
347 | snd_pcm_2_1_chmaps; | ||
348 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture; | ||
349 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | ||
350 | spec->adc_nid[spec->cur_input]; | ||
351 | codec->num_pcms++; | ||
352 | |||
353 | if (!spec->multiout.dig_out_nid && !spec->dig_in) | ||
354 | return 0; | ||
355 | |||
356 | info++; | ||
357 | info->name = "Cirrus Digital"; | ||
358 | info->pcm_type = spec->autocfg.dig_out_type[0]; | ||
359 | if (!info->pcm_type) | ||
360 | info->pcm_type = HDA_PCM_TYPE_SPDIF; | ||
361 | if (spec->multiout.dig_out_nid) { | ||
362 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | ||
363 | cs_pcm_digital_playback; | ||
364 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | ||
365 | spec->multiout.dig_out_nid; | ||
366 | } | ||
367 | if (spec->dig_in) { | ||
368 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | ||
369 | cs_pcm_digital_capture; | ||
370 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; | ||
371 | } | ||
372 | codec->num_pcms++; | ||
373 | |||
374 | return 0; | ||
375 | } | ||
376 | |||
377 | /* | ||
378 | * parse codec topology | ||
379 | */ | ||
380 | |||
381 | static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin) | ||
382 | { | ||
383 | hda_nid_t dac; | ||
384 | if (!pin) | ||
385 | return 0; | ||
386 | if (snd_hda_get_connections(codec, pin, &dac, 1) != 1) | ||
387 | return 0; | ||
388 | return dac; | ||
389 | } | ||
390 | |||
391 | static int is_ext_mic(struct hda_codec *codec, unsigned int idx) | ||
392 | { | ||
393 | struct cs_spec *spec = codec->spec; | ||
394 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
395 | hda_nid_t pin = cfg->inputs[idx].pin; | ||
396 | unsigned int val; | ||
397 | if (!is_jack_detectable(codec, pin)) | ||
398 | return 0; | ||
399 | val = snd_hda_codec_get_pincfg(codec, pin); | ||
400 | return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT); | ||
401 | } | ||
402 | |||
403 | static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin, | ||
404 | unsigned int *idxp) | ||
405 | { | ||
406 | int i, idx; | ||
407 | hda_nid_t nid; | ||
408 | |||
409 | nid = codec->start_nid; | ||
410 | for (i = 0; i < codec->num_nodes; i++, nid++) { | ||
411 | unsigned int type; | ||
412 | type = get_wcaps_type(get_wcaps(codec, nid)); | ||
413 | if (type != AC_WID_AUD_IN) | ||
414 | continue; | ||
415 | idx = snd_hda_get_conn_index(codec, nid, pin, false); | ||
416 | if (idx >= 0) { | ||
417 | *idxp = idx; | ||
418 | return nid; | ||
419 | } | ||
420 | } | ||
421 | return 0; | ||
422 | } | ||
423 | |||
424 | static int is_active_pin(struct hda_codec *codec, hda_nid_t nid) | ||
425 | { | ||
426 | unsigned int val; | ||
427 | val = snd_hda_codec_get_pincfg(codec, nid); | ||
428 | return (get_defcfg_connect(val) != AC_JACK_PORT_NONE); | ||
429 | } | ||
430 | |||
431 | static int parse_output(struct hda_codec *codec) | ||
432 | { | ||
433 | struct cs_spec *spec = codec->spec; | ||
434 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
435 | int i, extra_nids; | ||
436 | hda_nid_t dac; | ||
437 | |||
438 | for (i = 0; i < cfg->line_outs; i++) { | ||
439 | dac = get_dac(codec, cfg->line_out_pins[i]); | ||
440 | if (!dac) | ||
441 | break; | ||
442 | spec->dac_nid[i] = dac; | ||
443 | } | ||
444 | spec->multiout.num_dacs = i; | ||
445 | spec->multiout.dac_nids = spec->dac_nid; | ||
446 | spec->multiout.max_channels = i * 2; | ||
447 | |||
448 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && i == 2) | ||
449 | spec->speaker_2_1 = 1; /* assume 2.1 speakers */ | ||
450 | |||
451 | /* add HP and speakers */ | ||
452 | extra_nids = 0; | ||
453 | for (i = 0; i < cfg->hp_outs; i++) { | ||
454 | dac = get_dac(codec, cfg->hp_pins[i]); | ||
455 | if (!dac) | ||
456 | break; | ||
457 | if (!i) | ||
458 | spec->multiout.hp_nid = dac; | ||
459 | else | ||
460 | spec->multiout.extra_out_nid[extra_nids++] = dac; | ||
461 | } | ||
462 | for (i = 0; i < cfg->speaker_outs; i++) { | ||
463 | dac = get_dac(codec, cfg->speaker_pins[i]); | ||
464 | if (!dac) | ||
465 | break; | ||
466 | spec->multiout.extra_out_nid[extra_nids++] = dac; | ||
467 | } | ||
468 | |||
469 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { | ||
470 | cfg->speaker_outs = cfg->line_outs; | ||
471 | memcpy(cfg->speaker_pins, cfg->line_out_pins, | ||
472 | sizeof(cfg->speaker_pins)); | ||
473 | cfg->line_outs = 0; | ||
474 | memset(cfg->line_out_pins, 0, sizeof(cfg->line_out_pins)); | ||
475 | } | ||
476 | |||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | static int parse_input(struct hda_codec *codec) | ||
481 | { | ||
482 | struct cs_spec *spec = codec->spec; | ||
483 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
484 | int i; | ||
485 | |||
486 | for (i = 0; i < cfg->num_inputs; i++) { | ||
487 | hda_nid_t pin = cfg->inputs[i].pin; | ||
488 | spec->input_idx[spec->num_inputs] = i; | ||
489 | spec->capsrc_idx[i] = spec->num_inputs++; | ||
490 | spec->cur_input = i; | ||
491 | spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]); | ||
492 | } | ||
493 | if (!spec->num_inputs) | ||
494 | return 0; | ||
495 | |||
496 | /* check whether the automatic mic switch is available */ | ||
497 | if (spec->num_inputs == 2 && | ||
498 | cfg->inputs[0].type == AUTO_PIN_MIC && | ||
499 | cfg->inputs[1].type == AUTO_PIN_MIC) { | ||
500 | if (is_ext_mic(codec, cfg->inputs[0].pin)) { | ||
501 | if (!is_ext_mic(codec, cfg->inputs[1].pin)) { | ||
502 | spec->mic_detect = 1; | ||
503 | spec->automic_idx = 0; | ||
504 | } | ||
505 | } else { | ||
506 | if (is_ext_mic(codec, cfg->inputs[1].pin)) { | ||
507 | spec->mic_detect = 1; | ||
508 | spec->automic_idx = 1; | ||
509 | } | ||
510 | } | ||
511 | } | ||
512 | return 0; | ||
513 | } | ||
514 | |||
515 | |||
516 | static int parse_digital_output(struct hda_codec *codec) | ||
517 | { | ||
518 | struct cs_spec *spec = codec->spec; | ||
519 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
520 | hda_nid_t nid; | ||
521 | |||
522 | if (!cfg->dig_outs) | ||
523 | return 0; | ||
524 | if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1) | ||
525 | return 0; | ||
526 | spec->multiout.dig_out_nid = nid; | ||
527 | spec->multiout.share_spdif = 1; | ||
528 | if (cfg->dig_outs > 1 && | ||
529 | snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) { | ||
530 | spec->slave_dig_outs[0] = nid; | ||
531 | codec->slave_dig_outs = spec->slave_dig_outs; | ||
532 | } | ||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | static int parse_digital_input(struct hda_codec *codec) | ||
537 | { | ||
538 | struct cs_spec *spec = codec->spec; | ||
539 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
540 | int idx; | ||
541 | |||
542 | if (cfg->dig_in_pin) | ||
543 | spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx); | ||
544 | return 0; | ||
545 | } | ||
546 | |||
547 | /* | ||
548 | * create mixer controls | ||
549 | */ | ||
550 | |||
551 | static const char * const dir_sfx[2] = { "Playback", "Capture" }; | ||
552 | |||
553 | static int add_mute(struct hda_codec *codec, const char *name, int index, | ||
554 | unsigned int pval, int dir, struct snd_kcontrol **kctlp) | ||
555 | { | ||
556 | char tmp[44]; | ||
557 | struct snd_kcontrol_new knew = | ||
558 | HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT); | ||
559 | knew.private_value = pval; | ||
560 | snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]); | ||
561 | *kctlp = snd_ctl_new1(&knew, codec); | ||
562 | (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG; | ||
563 | return snd_hda_ctl_add(codec, 0, *kctlp); | ||
564 | } | ||
565 | |||
566 | static int add_volume(struct hda_codec *codec, const char *name, | ||
567 | int index, unsigned int pval, int dir, | ||
568 | struct snd_kcontrol **kctlp) | ||
569 | { | ||
570 | char tmp[44]; | ||
571 | struct snd_kcontrol_new knew = | ||
572 | HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT); | ||
573 | knew.private_value = pval; | ||
574 | snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]); | ||
575 | *kctlp = snd_ctl_new1(&knew, codec); | ||
576 | (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG; | ||
577 | return snd_hda_ctl_add(codec, 0, *kctlp); | ||
578 | } | ||
579 | |||
580 | static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) | ||
581 | { | ||
582 | unsigned int caps; | ||
583 | |||
584 | /* set the upper-limit for mixer amp to 0dB */ | ||
585 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); | ||
586 | caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT); | ||
587 | caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f) | ||
588 | << AC_AMPCAP_NUM_STEPS_SHIFT; | ||
589 | snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps); | ||
590 | } | ||
591 | |||
592 | static int add_vmaster(struct hda_codec *codec, hda_nid_t dac) | ||
593 | { | ||
594 | struct cs_spec *spec = codec->spec; | ||
595 | unsigned int tlv[4]; | ||
596 | int err; | ||
597 | |||
598 | spec->vmaster_sw = | ||
599 | snd_ctl_make_virtual_master("Master Playback Switch", NULL); | ||
600 | err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw); | ||
601 | if (err < 0) | ||
602 | return err; | ||
603 | |||
604 | snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv); | ||
605 | spec->vmaster_vol = | ||
606 | snd_ctl_make_virtual_master("Master Playback Volume", tlv); | ||
607 | err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol); | ||
608 | if (err < 0) | ||
609 | return err; | ||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx, | ||
614 | int num_ctls, int type) | ||
615 | { | ||
616 | struct cs_spec *spec = codec->spec; | ||
617 | const char *name; | ||
618 | int err, index; | ||
619 | struct snd_kcontrol *kctl; | ||
620 | static const char * const speakers[] = { | ||
621 | "Front Speaker", "Surround Speaker", "Bass Speaker" | ||
622 | }; | ||
623 | static const char * const line_outs[] = { | ||
624 | "Front Line Out", "Surround Line Out", "Bass Line Out" | ||
625 | }; | ||
626 | |||
627 | fix_volume_caps(codec, dac); | ||
628 | if (!spec->vmaster_sw) { | ||
629 | err = add_vmaster(codec, dac); | ||
630 | if (err < 0) | ||
631 | return err; | ||
632 | } | ||
633 | |||
634 | index = 0; | ||
635 | switch (type) { | ||
636 | case AUTO_PIN_HP_OUT: | ||
637 | name = "Headphone"; | ||
638 | index = idx; | ||
639 | break; | ||
640 | case AUTO_PIN_SPEAKER_OUT: | ||
641 | if (spec->speaker_2_1) | ||
642 | name = idx ? "Bass Speaker" : "Speaker"; | ||
643 | else if (num_ctls > 1) | ||
644 | name = speakers[idx]; | ||
645 | else | ||
646 | name = "Speaker"; | ||
647 | break; | ||
648 | default: | ||
649 | if (num_ctls > 1) | ||
650 | name = line_outs[idx]; | ||
651 | else | ||
652 | name = "Line Out"; | ||
653 | break; | ||
654 | } | ||
655 | |||
656 | err = add_mute(codec, name, index, | ||
657 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); | ||
658 | if (err < 0) | ||
659 | return err; | ||
660 | err = snd_ctl_add_slave(spec->vmaster_sw, kctl); | ||
661 | if (err < 0) | ||
662 | return err; | ||
663 | |||
664 | err = add_volume(codec, name, index, | ||
665 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); | ||
666 | if (err < 0) | ||
667 | return err; | ||
668 | err = snd_ctl_add_slave(spec->vmaster_vol, kctl); | ||
669 | if (err < 0) | ||
670 | return err; | ||
671 | |||
672 | return 0; | ||
673 | } | ||
674 | |||
675 | static int build_output(struct hda_codec *codec) | ||
676 | { | ||
677 | struct cs_spec *spec = codec->spec; | ||
678 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
679 | int i, err; | ||
680 | |||
681 | for (i = 0; i < cfg->line_outs; i++) { | ||
682 | err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]), | ||
683 | i, cfg->line_outs, cfg->line_out_type); | ||
684 | if (err < 0) | ||
685 | return err; | ||
686 | } | ||
687 | for (i = 0; i < cfg->hp_outs; i++) { | ||
688 | err = add_output(codec, get_dac(codec, cfg->hp_pins[i]), | ||
689 | i, cfg->hp_outs, AUTO_PIN_HP_OUT); | ||
690 | if (err < 0) | ||
691 | return err; | ||
692 | } | ||
693 | for (i = 0; i < cfg->speaker_outs; i++) { | ||
694 | err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]), | ||
695 | i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT); | ||
696 | if (err < 0) | ||
697 | return err; | ||
698 | } | ||
699 | return 0; | ||
700 | } | ||
701 | |||
702 | /* | ||
703 | */ | ||
704 | |||
705 | static const struct snd_kcontrol_new cs_capture_ctls[] = { | ||
706 | HDA_BIND_SW("Capture Switch", 0), | ||
707 | HDA_BIND_VOL("Capture Volume", 0), | ||
708 | }; | ||
709 | |||
710 | static int change_cur_input(struct hda_codec *codec, unsigned int idx, | ||
711 | int force) | ||
712 | { | ||
713 | struct cs_spec *spec = codec->spec; | ||
714 | |||
715 | if (spec->cur_input == idx && !force) | ||
716 | return 0; | ||
717 | if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) { | ||
718 | /* stream is running, let's swap the current ADC */ | ||
719 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | ||
720 | spec->cur_adc = spec->adc_nid[idx]; | ||
721 | snd_hda_codec_setup_stream(codec, spec->cur_adc, | ||
722 | spec->cur_adc_stream_tag, 0, | ||
723 | spec->cur_adc_format); | ||
724 | } | ||
725 | spec->cur_input = idx; | ||
726 | cs_update_input_select(codec); | ||
727 | return 1; | ||
728 | } | ||
729 | |||
730 | static int cs_capture_source_info(struct snd_kcontrol *kcontrol, | ||
731 | struct snd_ctl_elem_info *uinfo) | ||
732 | { | ||
733 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
734 | struct cs_spec *spec = codec->spec; | ||
735 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
736 | unsigned int idx; | ||
737 | |||
738 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
739 | uinfo->count = 1; | ||
740 | uinfo->value.enumerated.items = spec->num_inputs; | ||
741 | if (uinfo->value.enumerated.item >= spec->num_inputs) | ||
742 | uinfo->value.enumerated.item = spec->num_inputs - 1; | ||
743 | idx = spec->input_idx[uinfo->value.enumerated.item]; | ||
744 | snd_hda_get_pin_label(codec, cfg->inputs[idx].pin, cfg, | ||
745 | uinfo->value.enumerated.name, | ||
746 | sizeof(uinfo->value.enumerated.name), NULL); | ||
747 | return 0; | ||
748 | } | ||
749 | |||
750 | static int cs_capture_source_get(struct snd_kcontrol *kcontrol, | ||
751 | struct snd_ctl_elem_value *ucontrol) | ||
752 | { | ||
753 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
754 | struct cs_spec *spec = codec->spec; | ||
755 | ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input]; | ||
756 | return 0; | ||
757 | } | ||
758 | |||
759 | static int cs_capture_source_put(struct snd_kcontrol *kcontrol, | ||
760 | struct snd_ctl_elem_value *ucontrol) | ||
761 | { | ||
762 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
763 | struct cs_spec *spec = codec->spec; | ||
764 | unsigned int idx = ucontrol->value.enumerated.item[0]; | ||
765 | |||
766 | if (idx >= spec->num_inputs) | ||
767 | return -EINVAL; | ||
768 | idx = spec->input_idx[idx]; | ||
769 | return change_cur_input(codec, idx, 0); | ||
770 | } | ||
771 | |||
772 | static const struct snd_kcontrol_new cs_capture_source = { | ||
773 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
774 | .name = "Capture Source", | ||
775 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | ||
776 | .info = cs_capture_source_info, | ||
777 | .get = cs_capture_source_get, | ||
778 | .put = cs_capture_source_put, | ||
779 | }; | ||
780 | |||
781 | static const struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec, | ||
782 | struct hda_ctl_ops *ops) | ||
783 | { | ||
784 | struct cs_spec *spec = codec->spec; | ||
785 | struct hda_bind_ctls *bind; | ||
786 | int i, n; | ||
787 | |||
788 | bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1), | ||
789 | GFP_KERNEL); | ||
790 | if (!bind) | ||
791 | return NULL; | ||
792 | bind->ops = ops; | ||
793 | n = 0; | ||
794 | for (i = 0; i < AUTO_PIN_LAST; i++) { | ||
795 | if (!spec->adc_nid[i]) | ||
796 | continue; | ||
797 | bind->values[n++] = | ||
798 | HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3, | ||
799 | spec->adc_idx[i], HDA_INPUT); | ||
800 | } | ||
801 | return bind; | ||
802 | } | ||
803 | |||
804 | /* add a (input-boost) volume control to the given input pin */ | ||
805 | static int add_input_volume_control(struct hda_codec *codec, | ||
806 | struct auto_pin_cfg *cfg, | ||
807 | int item) | ||
808 | { | ||
809 | hda_nid_t pin = cfg->inputs[item].pin; | ||
810 | u32 caps; | ||
811 | const char *label; | ||
812 | struct snd_kcontrol *kctl; | ||
813 | |||
814 | if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP)) | ||
815 | return 0; | ||
816 | caps = query_amp_caps(codec, pin, HDA_INPUT); | ||
817 | caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; | ||
818 | if (caps <= 1) | ||
819 | return 0; | ||
820 | label = hda_get_autocfg_input_label(codec, cfg, item); | ||
821 | return add_volume(codec, label, 0, | ||
822 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl); | ||
823 | } | ||
824 | |||
825 | static int build_input(struct hda_codec *codec) | ||
826 | { | ||
827 | struct cs_spec *spec = codec->spec; | ||
828 | int i, err; | ||
829 | |||
830 | if (!spec->num_inputs) | ||
831 | return 0; | ||
832 | |||
833 | /* make bind-capture */ | ||
834 | spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw); | ||
835 | spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol); | ||
836 | for (i = 0; i < 2; i++) { | ||
837 | struct snd_kcontrol *kctl; | ||
838 | int n; | ||
839 | if (!spec->capture_bind[i]) | ||
840 | return -ENOMEM; | ||
841 | kctl = snd_ctl_new1(&cs_capture_ctls[i], codec); | ||
842 | if (!kctl) | ||
843 | return -ENOMEM; | ||
844 | kctl->private_value = (long)spec->capture_bind[i]; | ||
845 | err = snd_hda_ctl_add(codec, 0, kctl); | ||
846 | if (err < 0) | ||
847 | return err; | ||
848 | for (n = 0; n < AUTO_PIN_LAST; n++) { | ||
849 | if (!spec->adc_nid[n]) | ||
850 | continue; | ||
851 | err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]); | ||
852 | if (err < 0) | ||
853 | return err; | ||
854 | } | ||
855 | } | ||
856 | |||
857 | if (spec->num_inputs > 1 && !spec->mic_detect) { | ||
858 | err = snd_hda_ctl_add(codec, 0, | ||
859 | snd_ctl_new1(&cs_capture_source, codec)); | ||
860 | if (err < 0) | ||
861 | return err; | ||
862 | } | ||
863 | |||
864 | for (i = 0; i < spec->num_inputs; i++) { | ||
865 | err = add_input_volume_control(codec, &spec->autocfg, i); | ||
866 | if (err < 0) | ||
867 | return err; | ||
868 | } | ||
869 | |||
870 | return 0; | ||
871 | } | ||
872 | |||
873 | /* | ||
874 | */ | ||
875 | |||
876 | static int build_digital_output(struct hda_codec *codec) | ||
877 | { | ||
878 | struct cs_spec *spec = codec->spec; | ||
879 | int err; | ||
880 | |||
881 | if (!spec->multiout.dig_out_nid) | ||
882 | return 0; | ||
883 | |||
884 | err = snd_hda_create_dig_out_ctls(codec, spec->multiout.dig_out_nid, | ||
885 | spec->multiout.dig_out_nid, | ||
886 | spec->pcm_rec[1].pcm_type); | ||
887 | if (err < 0) | ||
888 | return err; | ||
889 | err = snd_hda_create_spdif_share_sw(codec, &spec->multiout); | ||
890 | if (err < 0) | ||
891 | return err; | ||
892 | return 0; | ||
893 | } | ||
894 | |||
895 | static int build_digital_input(struct hda_codec *codec) | ||
896 | { | ||
897 | struct cs_spec *spec = codec->spec; | ||
898 | if (spec->dig_in) | ||
899 | return snd_hda_create_spdif_in_ctls(codec, spec->dig_in); | ||
900 | return 0; | ||
901 | } | ||
902 | |||
903 | /* | 156 | /* |
904 | * auto-mute and auto-mic switching | 157 | * auto-mute and auto-mic switching |
905 | * CS421x auto-output redirecting | 158 | * CS421x auto-output redirecting |
906 | * HP/SPK/SPDIF | 159 | * HP/SPK/SPDIF |
907 | */ | 160 | */ |
908 | 161 | ||
909 | static void cs_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl) | 162 | static void cs_automute(struct hda_codec *codec) |
910 | { | 163 | { |
911 | struct cs_spec *spec = codec->spec; | 164 | struct cs_spec *spec = codec->spec; |
912 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
913 | unsigned int hp_present; | ||
914 | unsigned int spdif_present; | ||
915 | hda_nid_t nid; | ||
916 | int i; | ||
917 | 165 | ||
918 | spdif_present = 0; | 166 | /* mute HPs if spdif jack (SENSE_B) is present */ |
919 | if (cfg->dig_outs) { | 167 | spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b); |
920 | nid = cfg->dig_out_pins[0]; | ||
921 | if (is_jack_detectable(codec, nid)) { | ||
922 | /* | ||
923 | TODO: SPDIF output redirect when SENSE_B is enabled. | ||
924 | Shared (SENSE_A) jack (e.g HP/mini-TOSLINK) | ||
925 | assumed. | ||
926 | */ | ||
927 | if (snd_hda_jack_detect(codec, nid) | ||
928 | /* && spec->sense_b */) | ||
929 | spdif_present = 1; | ||
930 | } | ||
931 | } | ||
932 | |||
933 | hp_present = 0; | ||
934 | for (i = 0; i < cfg->hp_outs; i++) { | ||
935 | nid = cfg->hp_pins[i]; | ||
936 | if (!is_jack_detectable(codec, nid)) | ||
937 | continue; | ||
938 | hp_present = snd_hda_jack_detect(codec, nid); | ||
939 | if (hp_present) | ||
940 | break; | ||
941 | } | ||
942 | 168 | ||
943 | /* mute speakers if spdif or hp jack is plugged in */ | 169 | snd_hda_gen_update_outputs(codec); |
944 | for (i = 0; i < cfg->speaker_outs; i++) { | ||
945 | int pin_ctl = hp_present ? 0 : PIN_OUT; | ||
946 | /* detect on spdif is specific to CS4210 */ | ||
947 | if (spdif_present && (spec->vendor_nid == CS4210_VENDOR_NID)) | ||
948 | pin_ctl = 0; | ||
949 | 170 | ||
950 | nid = cfg->speaker_pins[i]; | ||
951 | snd_hda_set_pin_ctl(codec, nid, pin_ctl); | ||
952 | } | ||
953 | if (spec->gpio_eapd_hp) { | 171 | if (spec->gpio_eapd_hp) { |
954 | unsigned int gpio = hp_present ? | 172 | unsigned int gpio = spec->gen.hp_jack_present ? |
955 | spec->gpio_eapd_hp : spec->gpio_eapd_speaker; | 173 | spec->gpio_eapd_hp : spec->gpio_eapd_speaker; |
956 | snd_hda_codec_write(codec, 0x01, 0, | 174 | snd_hda_codec_write(codec, 0x01, 0, |
957 | AC_VERB_SET_GPIO_DATA, gpio); | 175 | AC_VERB_SET_GPIO_DATA, gpio); |
958 | } | 176 | } |
959 | |||
960 | /* specific to CS4210 */ | ||
961 | if (spec->vendor_nid == CS4210_VENDOR_NID) { | ||
962 | /* mute HPs if spdif jack (SENSE_B) is present */ | ||
963 | for (i = 0; i < cfg->hp_outs; i++) { | ||
964 | nid = cfg->hp_pins[i]; | ||
965 | snd_hda_set_pin_ctl(codec, nid, | ||
966 | (spdif_present && spec->sense_b) ? 0 : PIN_HP); | ||
967 | } | ||
968 | |||
969 | /* SPDIF TX on/off */ | ||
970 | if (cfg->dig_outs) { | ||
971 | nid = cfg->dig_out_pins[0]; | ||
972 | snd_hda_set_pin_ctl(codec, nid, | ||
973 | spdif_present ? PIN_OUT : 0); | ||
974 | |||
975 | } | ||
976 | /* Update board GPIOs if neccessary ... */ | ||
977 | } | ||
978 | } | ||
979 | |||
980 | /* | ||
981 | * Auto-input redirect for CS421x | ||
982 | * Switch max 3 inputs of a single ADC (nid 3) | ||
983 | */ | ||
984 | |||
985 | static void cs_automic(struct hda_codec *codec, struct hda_jack_tbl *tbl) | ||
986 | { | ||
987 | struct cs_spec *spec = codec->spec; | ||
988 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
989 | hda_nid_t nid; | ||
990 | unsigned int present; | ||
991 | |||
992 | nid = cfg->inputs[spec->automic_idx].pin; | ||
993 | present = snd_hda_jack_detect(codec, nid); | ||
994 | |||
995 | /* specific to CS421x, single ADC */ | ||
996 | if (spec->vendor_nid == CS420X_VENDOR_NID) { | ||
997 | if (present) | ||
998 | change_cur_input(codec, spec->automic_idx, 0); | ||
999 | else | ||
1000 | change_cur_input(codec, !spec->automic_idx, 0); | ||
1001 | } else { | ||
1002 | if (present) { | ||
1003 | if (spec->cur_input != spec->automic_idx) { | ||
1004 | spec->last_input = spec->cur_input; | ||
1005 | spec->cur_input = spec->automic_idx; | ||
1006 | } | ||
1007 | } else { | ||
1008 | spec->cur_input = spec->last_input; | ||
1009 | } | ||
1010 | cs_update_input_select(codec); | ||
1011 | } | ||
1012 | } | 177 | } |
1013 | 178 | ||
1014 | /* | 179 | static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid) |
1015 | */ | ||
1016 | |||
1017 | static void init_output(struct hda_codec *codec) | ||
1018 | { | 180 | { |
1019 | struct cs_spec *spec = codec->spec; | 181 | unsigned int val; |
1020 | struct auto_pin_cfg *cfg = &spec->autocfg; | 182 | val = snd_hda_codec_get_pincfg(codec, nid); |
1021 | int i; | 183 | return (get_defcfg_connect(val) != AC_JACK_PORT_NONE); |
1022 | |||
1023 | /* mute first */ | ||
1024 | for (i = 0; i < spec->multiout.num_dacs; i++) | ||
1025 | snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0, | ||
1026 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); | ||
1027 | if (spec->multiout.hp_nid) | ||
1028 | snd_hda_codec_write(codec, spec->multiout.hp_nid, 0, | ||
1029 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); | ||
1030 | for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) { | ||
1031 | if (!spec->multiout.extra_out_nid[i]) | ||
1032 | break; | ||
1033 | snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0, | ||
1034 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); | ||
1035 | } | ||
1036 | |||
1037 | /* set appropriate pin controls */ | ||
1038 | for (i = 0; i < cfg->line_outs; i++) | ||
1039 | snd_hda_set_pin_ctl(codec, cfg->line_out_pins[i], PIN_OUT); | ||
1040 | /* HP */ | ||
1041 | for (i = 0; i < cfg->hp_outs; i++) { | ||
1042 | hda_nid_t nid = cfg->hp_pins[i]; | ||
1043 | snd_hda_set_pin_ctl(codec, nid, PIN_HP); | ||
1044 | if (!cfg->speaker_outs) | ||
1045 | continue; | ||
1046 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { | ||
1047 | snd_hda_jack_detect_enable_callback(codec, nid, HP_EVENT, cs_automute); | ||
1048 | spec->hp_detect = 1; | ||
1049 | } | ||
1050 | } | ||
1051 | |||
1052 | /* Speaker */ | ||
1053 | for (i = 0; i < cfg->speaker_outs; i++) | ||
1054 | snd_hda_set_pin_ctl(codec, cfg->speaker_pins[i], PIN_OUT); | ||
1055 | |||
1056 | /* SPDIF is enabled on presence detect for CS421x */ | ||
1057 | if (spec->hp_detect || spec->spdif_detect) | ||
1058 | cs_automute(codec, NULL); | ||
1059 | } | 184 | } |
1060 | 185 | ||
1061 | static void init_input(struct hda_codec *codec) | 186 | static void init_input_coef(struct hda_codec *codec) |
1062 | { | 187 | { |
1063 | struct cs_spec *spec = codec->spec; | 188 | struct cs_spec *spec = codec->spec; |
1064 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
1065 | unsigned int coef; | 189 | unsigned int coef; |
1066 | int i; | ||
1067 | 190 | ||
1068 | for (i = 0; i < cfg->num_inputs; i++) { | ||
1069 | unsigned int ctl; | ||
1070 | hda_nid_t pin = cfg->inputs[i].pin; | ||
1071 | if (!spec->adc_nid[i]) | ||
1072 | continue; | ||
1073 | /* set appropriate pin control and mute first */ | ||
1074 | ctl = PIN_IN; | ||
1075 | if (cfg->inputs[i].type == AUTO_PIN_MIC) | ||
1076 | ctl |= snd_hda_get_default_vref(codec, pin); | ||
1077 | snd_hda_set_pin_ctl(codec, pin, ctl); | ||
1078 | snd_hda_codec_write(codec, spec->adc_nid[i], 0, | ||
1079 | AC_VERB_SET_AMP_GAIN_MUTE, | ||
1080 | AMP_IN_MUTE(spec->adc_idx[i])); | ||
1081 | if (spec->mic_detect && spec->automic_idx == i) | ||
1082 | snd_hda_jack_detect_enable_callback(codec, pin, MIC_EVENT, cs_automic); | ||
1083 | } | ||
1084 | /* CS420x has multiple ADC, CS421x has single ADC */ | 191 | /* CS420x has multiple ADC, CS421x has single ADC */ |
1085 | if (spec->vendor_nid == CS420X_VENDOR_NID) { | 192 | if (spec->vendor_nid == CS420X_VENDOR_NID) { |
1086 | change_cur_input(codec, spec->cur_input, 1); | ||
1087 | if (spec->mic_detect) | ||
1088 | cs_automic(codec, NULL); | ||
1089 | |||
1090 | coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); | 193 | coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG); |
1091 | if (is_active_pin(codec, CS_DMIC2_PIN_NID)) | 194 | if (is_active_pin(codec, CS_DMIC2_PIN_NID)) |
1092 | coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ | 195 | coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */ |
@@ -1097,13 +200,6 @@ static void init_input(struct hda_codec *codec) | |||
1097 | */ | 200 | */ |
1098 | 201 | ||
1099 | cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); | 202 | cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef); |
1100 | } else { | ||
1101 | if (spec->mic_detect) | ||
1102 | cs_automic(codec, NULL); | ||
1103 | else { | ||
1104 | spec->cur_adc = spec->adc_nid[spec->cur_input]; | ||
1105 | cs_update_input_select(codec); | ||
1106 | } | ||
1107 | } | 203 | } |
1108 | } | 204 | } |
1109 | 205 | ||
@@ -1176,7 +272,7 @@ static const struct hda_verb cs_errata_init_verbs[] = { | |||
1176 | }; | 272 | }; |
1177 | 273 | ||
1178 | /* SPDIF setup */ | 274 | /* SPDIF setup */ |
1179 | static void init_digital(struct hda_codec *codec) | 275 | static void init_digital_coef(struct hda_codec *codec) |
1180 | { | 276 | { |
1181 | unsigned int coef; | 277 | unsigned int coef; |
1182 | 278 | ||
@@ -1199,7 +295,7 @@ static int cs_init(struct hda_codec *codec) | |||
1199 | 295 | ||
1200 | snd_hda_sequence_write(codec, cs_coef_init_verbs); | 296 | snd_hda_sequence_write(codec, cs_coef_init_verbs); |
1201 | 297 | ||
1202 | snd_hda_apply_verbs(codec); | 298 | snd_hda_gen_init(codec); |
1203 | 299 | ||
1204 | if (spec->gpio_mask) { | 300 | if (spec->gpio_mask) { |
1205 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, | 301 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, |
@@ -1210,52 +306,17 @@ static int cs_init(struct hda_codec *codec) | |||
1210 | spec->gpio_data); | 306 | spec->gpio_data); |
1211 | } | 307 | } |
1212 | 308 | ||
1213 | init_output(codec); | 309 | init_input_coef(codec); |
1214 | init_input(codec); | 310 | init_digital_coef(codec); |
1215 | init_digital(codec); | ||
1216 | |||
1217 | return 0; | ||
1218 | } | ||
1219 | |||
1220 | static int cs_build_controls(struct hda_codec *codec) | ||
1221 | { | ||
1222 | struct cs_spec *spec = codec->spec; | ||
1223 | int err; | ||
1224 | |||
1225 | err = build_output(codec); | ||
1226 | if (err < 0) | ||
1227 | return err; | ||
1228 | err = build_input(codec); | ||
1229 | if (err < 0) | ||
1230 | return err; | ||
1231 | err = build_digital_output(codec); | ||
1232 | if (err < 0) | ||
1233 | return err; | ||
1234 | err = build_digital_input(codec); | ||
1235 | if (err < 0) | ||
1236 | return err; | ||
1237 | err = cs_init(codec); | ||
1238 | if (err < 0) | ||
1239 | return err; | ||
1240 | |||
1241 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); | ||
1242 | if (err < 0) | ||
1243 | return err; | ||
1244 | 311 | ||
1245 | return 0; | 312 | return 0; |
1246 | } | 313 | } |
1247 | 314 | ||
1248 | static void cs_free(struct hda_codec *codec) | 315 | #define cs_free snd_hda_gen_free |
1249 | { | ||
1250 | struct cs_spec *spec = codec->spec; | ||
1251 | kfree(spec->capture_bind[0]); | ||
1252 | kfree(spec->capture_bind[1]); | ||
1253 | kfree(codec->spec); | ||
1254 | } | ||
1255 | 316 | ||
1256 | static const struct hda_codec_ops cs_patch_ops = { | 317 | static const struct hda_codec_ops cs_patch_ops = { |
1257 | .build_controls = cs_build_controls, | 318 | .build_controls = snd_hda_gen_build_controls, |
1258 | .build_pcms = cs_build_pcms, | 319 | .build_pcms = snd_hda_gen_build_pcms, |
1259 | .init = cs_init, | 320 | .init = cs_init, |
1260 | .free = cs_free, | 321 | .free = cs_free, |
1261 | .unsol_event = snd_hda_jack_unsol_event, | 322 | .unsol_event = snd_hda_jack_unsol_event, |
@@ -1266,22 +327,14 @@ static int cs_parse_auto_config(struct hda_codec *codec) | |||
1266 | struct cs_spec *spec = codec->spec; | 327 | struct cs_spec *spec = codec->spec; |
1267 | int err; | 328 | int err; |
1268 | 329 | ||
1269 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | 330 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
1270 | if (err < 0) | 331 | if (err < 0) |
1271 | return err; | 332 | return err; |
1272 | 333 | ||
1273 | err = parse_output(codec); | 334 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
1274 | if (err < 0) | ||
1275 | return err; | ||
1276 | err = parse_input(codec); | ||
1277 | if (err < 0) | ||
1278 | return err; | ||
1279 | err = parse_digital_output(codec); | ||
1280 | if (err < 0) | ||
1281 | return err; | ||
1282 | err = parse_digital_input(codec); | ||
1283 | if (err < 0) | 335 | if (err < 0) |
1284 | return err; | 336 | return err; |
337 | |||
1285 | return 0; | 338 | return 0; |
1286 | } | 339 | } |
1287 | 340 | ||
@@ -1431,17 +484,28 @@ static const struct hda_fixup cs420x_fixups[] = { | |||
1431 | }, | 484 | }, |
1432 | }; | 485 | }; |
1433 | 486 | ||
1434 | static int patch_cs420x(struct hda_codec *codec) | 487 | static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid) |
1435 | { | 488 | { |
1436 | struct cs_spec *spec; | 489 | struct cs_spec *spec; |
1437 | int err; | ||
1438 | 490 | ||
1439 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 491 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
1440 | if (!spec) | 492 | if (!spec) |
1441 | return -ENOMEM; | 493 | return NULL; |
1442 | codec->spec = spec; | 494 | codec->spec = spec; |
495 | spec->vendor_nid = vendor_nid; | ||
496 | snd_hda_gen_spec_init(&spec->gen); | ||
497 | |||
498 | return spec; | ||
499 | } | ||
500 | |||
501 | static int patch_cs420x(struct hda_codec *codec) | ||
502 | { | ||
503 | struct cs_spec *spec; | ||
504 | int err; | ||
1443 | 505 | ||
1444 | spec->vendor_nid = CS420X_VENDOR_NID; | 506 | spec = cs_alloc_spec(codec, CS420X_VENDOR_NID); |
507 | if (!spec) | ||
508 | return -ENOMEM; | ||
1445 | 509 | ||
1446 | snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, | 510 | snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl, |
1447 | cs420x_fixups); | 511 | cs420x_fixups); |
@@ -1459,7 +523,6 @@ static int patch_cs420x(struct hda_codec *codec) | |||
1459 | 523 | ||
1460 | error: | 524 | error: |
1461 | cs_free(codec); | 525 | cs_free(codec); |
1462 | codec->spec = NULL; | ||
1463 | return err; | 526 | return err; |
1464 | } | 527 | } |
1465 | 528 | ||
@@ -1618,7 +681,7 @@ static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol, | |||
1618 | } | 681 | } |
1619 | } | 682 | } |
1620 | 683 | ||
1621 | static const struct snd_kcontrol_new cs421x_speaker_bost_ctl = { | 684 | static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = { |
1622 | 685 | ||
1623 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 686 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
1624 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | | 687 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
@@ -1663,20 +726,44 @@ static void cs4210_pinmux_init(struct hda_codec *codec) | |||
1663 | } | 726 | } |
1664 | } | 727 | } |
1665 | 728 | ||
1666 | static void init_cs421x_digital(struct hda_codec *codec) | 729 | static void cs4210_spdif_automute(struct hda_codec *codec, |
730 | struct hda_jack_tbl *tbl) | ||
1667 | { | 731 | { |
1668 | struct cs_spec *spec = codec->spec; | 732 | struct cs_spec *spec = codec->spec; |
1669 | struct auto_pin_cfg *cfg = &spec->autocfg; | 733 | bool spdif_present = false; |
1670 | int i; | 734 | hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0]; |
735 | |||
736 | /* detect on spdif is specific to CS4210 */ | ||
737 | if (!spec->spdif_detect || | ||
738 | spec->vendor_nid != CS4210_VENDOR_NID) | ||
739 | return; | ||
740 | |||
741 | spdif_present = snd_hda_jack_detect(codec, spdif_pin); | ||
742 | if (spdif_present == spec->spdif_present) | ||
743 | return; | ||
744 | |||
745 | spec->spdif_present = spdif_present; | ||
746 | /* SPDIF TX on/off */ | ||
747 | if (spdif_present) | ||
748 | snd_hda_set_pin_ctl(codec, spdif_pin, | ||
749 | spdif_present ? PIN_OUT : 0); | ||
1671 | 750 | ||
751 | cs_automute(codec); | ||
752 | } | ||
753 | |||
754 | static void parse_cs421x_digital(struct hda_codec *codec) | ||
755 | { | ||
756 | struct cs_spec *spec = codec->spec; | ||
757 | struct auto_pin_cfg *cfg = &spec->gen.autocfg; | ||
758 | int i; | ||
1672 | 759 | ||
1673 | for (i = 0; i < cfg->dig_outs; i++) { | 760 | for (i = 0; i < cfg->dig_outs; i++) { |
1674 | hda_nid_t nid = cfg->dig_out_pins[i]; | 761 | hda_nid_t nid = cfg->dig_out_pins[i]; |
1675 | if (!cfg->speaker_outs) | ||
1676 | continue; | ||
1677 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { | 762 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { |
1678 | snd_hda_jack_detect_enable_callback(codec, nid, SPDIF_EVENT, cs_automute); | ||
1679 | spec->spdif_detect = 1; | 763 | spec->spdif_detect = 1; |
764 | snd_hda_jack_detect_enable_callback(codec, nid, | ||
765 | SPDIF_EVENT, | ||
766 | cs4210_spdif_automute); | ||
1680 | } | 767 | } |
1681 | } | 768 | } |
1682 | } | 769 | } |
@@ -1691,6 +778,8 @@ static int cs421x_init(struct hda_codec *codec) | |||
1691 | cs4210_pinmux_init(codec); | 778 | cs4210_pinmux_init(codec); |
1692 | } | 779 | } |
1693 | 780 | ||
781 | snd_hda_gen_init(codec); | ||
782 | |||
1694 | if (spec->gpio_mask) { | 783 | if (spec->gpio_mask) { |
1695 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, | 784 | snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, |
1696 | spec->gpio_mask); | 785 | spec->gpio_mask); |
@@ -1700,233 +789,61 @@ static int cs421x_init(struct hda_codec *codec) | |||
1700 | spec->gpio_data); | 789 | spec->gpio_data); |
1701 | } | 790 | } |
1702 | 791 | ||
1703 | init_output(codec); | 792 | init_input_coef(codec); |
1704 | init_input(codec); | ||
1705 | init_cs421x_digital(codec); | ||
1706 | |||
1707 | return 0; | ||
1708 | } | ||
1709 | |||
1710 | /* | ||
1711 | * CS4210 Input MUX (1 ADC) | ||
1712 | */ | ||
1713 | static int cs421x_mux_enum_info(struct snd_kcontrol *kcontrol, | ||
1714 | struct snd_ctl_elem_info *uinfo) | ||
1715 | { | ||
1716 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1717 | struct cs_spec *spec = codec->spec; | ||
1718 | |||
1719 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); | ||
1720 | } | ||
1721 | |||
1722 | static int cs421x_mux_enum_get(struct snd_kcontrol *kcontrol, | ||
1723 | struct snd_ctl_elem_value *ucontrol) | ||
1724 | { | ||
1725 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1726 | struct cs_spec *spec = codec->spec; | ||
1727 | |||
1728 | ucontrol->value.enumerated.item[0] = spec->cur_input; | ||
1729 | return 0; | ||
1730 | } | ||
1731 | |||
1732 | static int cs421x_mux_enum_put(struct snd_kcontrol *kcontrol, | ||
1733 | struct snd_ctl_elem_value *ucontrol) | ||
1734 | { | ||
1735 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1736 | struct cs_spec *spec = codec->spec; | ||
1737 | |||
1738 | return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol, | ||
1739 | spec->adc_nid[0], &spec->cur_input); | ||
1740 | |||
1741 | } | ||
1742 | |||
1743 | static const struct snd_kcontrol_new cs421x_capture_source = { | ||
1744 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
1745 | .name = "Capture Source", | ||
1746 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | ||
1747 | .info = cs421x_mux_enum_info, | ||
1748 | .get = cs421x_mux_enum_get, | ||
1749 | .put = cs421x_mux_enum_put, | ||
1750 | }; | ||
1751 | |||
1752 | static int cs421x_add_input_volume_control(struct hda_codec *codec, int item) | ||
1753 | { | ||
1754 | struct cs_spec *spec = codec->spec; | ||
1755 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
1756 | const struct hda_input_mux *imux = &spec->input_mux; | ||
1757 | hda_nid_t pin = cfg->inputs[item].pin; | ||
1758 | struct snd_kcontrol *kctl; | ||
1759 | u32 caps; | ||
1760 | |||
1761 | if (!(get_wcaps(codec, pin) & AC_WCAP_IN_AMP)) | ||
1762 | return 0; | ||
1763 | |||
1764 | caps = query_amp_caps(codec, pin, HDA_INPUT); | ||
1765 | caps = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; | ||
1766 | if (caps <= 1) | ||
1767 | return 0; | ||
1768 | |||
1769 | return add_volume(codec, imux->items[item].label, 0, | ||
1770 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT), 1, &kctl); | ||
1771 | } | ||
1772 | |||
1773 | /* add a (input-boost) volume control to the given input pin */ | ||
1774 | static int build_cs421x_input(struct hda_codec *codec) | ||
1775 | { | ||
1776 | struct cs_spec *spec = codec->spec; | ||
1777 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
1778 | struct hda_input_mux *imux = &spec->input_mux; | ||
1779 | int i, err, type_idx; | ||
1780 | const char *label; | ||
1781 | |||
1782 | if (!spec->num_inputs) | ||
1783 | return 0; | ||
1784 | |||
1785 | /* make bind-capture */ | ||
1786 | spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw); | ||
1787 | spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol); | ||
1788 | for (i = 0; i < 2; i++) { | ||
1789 | struct snd_kcontrol *kctl; | ||
1790 | int n; | ||
1791 | if (!spec->capture_bind[i]) | ||
1792 | return -ENOMEM; | ||
1793 | kctl = snd_ctl_new1(&cs_capture_ctls[i], codec); | ||
1794 | if (!kctl) | ||
1795 | return -ENOMEM; | ||
1796 | kctl->private_value = (long)spec->capture_bind[i]; | ||
1797 | err = snd_hda_ctl_add(codec, 0, kctl); | ||
1798 | if (err < 0) | ||
1799 | return err; | ||
1800 | for (n = 0; n < AUTO_PIN_LAST; n++) { | ||
1801 | if (!spec->adc_nid[n]) | ||
1802 | continue; | ||
1803 | err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]); | ||
1804 | if (err < 0) | ||
1805 | return err; | ||
1806 | } | ||
1807 | } | ||
1808 | |||
1809 | /* Add Input MUX Items + Capture Volume/Switch */ | ||
1810 | for (i = 0; i < spec->num_inputs; i++) { | ||
1811 | label = hda_get_autocfg_input_label(codec, cfg, i); | ||
1812 | snd_hda_add_imux_item(imux, label, spec->adc_idx[i], &type_idx); | ||
1813 | |||
1814 | err = cs421x_add_input_volume_control(codec, i); | ||
1815 | if (err < 0) | ||
1816 | return err; | ||
1817 | } | ||
1818 | |||
1819 | /* | ||
1820 | Add 'Capture Source' Switch if | ||
1821 | * 2 inputs and no mic detec | ||
1822 | * 3 inputs | ||
1823 | */ | ||
1824 | if ((spec->num_inputs == 2 && !spec->mic_detect) || | ||
1825 | (spec->num_inputs == 3)) { | ||
1826 | 793 | ||
1827 | err = snd_hda_ctl_add(codec, spec->adc_nid[0], | 794 | cs4210_spdif_automute(codec, NULL); |
1828 | snd_ctl_new1(&cs421x_capture_source, codec)); | ||
1829 | if (err < 0) | ||
1830 | return err; | ||
1831 | } | ||
1832 | 795 | ||
1833 | return 0; | 796 | return 0; |
1834 | } | 797 | } |
1835 | 798 | ||
1836 | /* Single DAC (Mute/Gain) */ | 799 | static int cs421x_build_controls(struct hda_codec *codec) |
1837 | static int build_cs421x_output(struct hda_codec *codec) | ||
1838 | { | 800 | { |
1839 | hda_nid_t dac = CS4210_DAC_NID; | ||
1840 | struct cs_spec *spec = codec->spec; | 801 | struct cs_spec *spec = codec->spec; |
1841 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
1842 | struct snd_kcontrol *kctl; | ||
1843 | int err; | 802 | int err; |
1844 | char *name = "Master"; | ||
1845 | |||
1846 | fix_volume_caps(codec, dac); | ||
1847 | 803 | ||
1848 | err = add_mute(codec, name, 0, | 804 | err = snd_hda_gen_build_controls(codec); |
1849 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); | ||
1850 | if (err < 0) | 805 | if (err < 0) |
1851 | return err; | 806 | return err; |
1852 | 807 | ||
1853 | err = add_volume(codec, name, 0, | 808 | if (spec->gen.autocfg.speaker_outs && |
1854 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl); | 809 | spec->vendor_nid == CS4210_VENDOR_NID) { |
1855 | if (err < 0) | ||
1856 | return err; | ||
1857 | |||
1858 | if (cfg->speaker_outs && (spec->vendor_nid == CS4210_VENDOR_NID)) { | ||
1859 | err = snd_hda_ctl_add(codec, 0, | 810 | err = snd_hda_ctl_add(codec, 0, |
1860 | snd_ctl_new1(&cs421x_speaker_bost_ctl, codec)); | 811 | snd_ctl_new1(&cs421x_speaker_boost_ctl, codec)); |
1861 | if (err < 0) | 812 | if (err < 0) |
1862 | return err; | 813 | return err; |
1863 | } | 814 | } |
1864 | return err; | ||
1865 | } | ||
1866 | |||
1867 | static int cs421x_build_controls(struct hda_codec *codec) | ||
1868 | { | ||
1869 | struct cs_spec *spec = codec->spec; | ||
1870 | int err; | ||
1871 | |||
1872 | err = build_cs421x_output(codec); | ||
1873 | if (err < 0) | ||
1874 | return err; | ||
1875 | err = build_cs421x_input(codec); | ||
1876 | if (err < 0) | ||
1877 | return err; | ||
1878 | err = build_digital_output(codec); | ||
1879 | if (err < 0) | ||
1880 | return err; | ||
1881 | err = cs421x_init(codec); | ||
1882 | if (err < 0) | ||
1883 | return err; | ||
1884 | |||
1885 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); | ||
1886 | if (err < 0) | ||
1887 | return err; | ||
1888 | |||
1889 | return 0; | 815 | return 0; |
1890 | } | 816 | } |
1891 | 817 | ||
1892 | static int parse_cs421x_input(struct hda_codec *codec) | 818 | static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac) |
1893 | { | 819 | { |
1894 | struct cs_spec *spec = codec->spec; | 820 | unsigned int caps; |
1895 | struct auto_pin_cfg *cfg = &spec->autocfg; | ||
1896 | int i; | ||
1897 | |||
1898 | for (i = 0; i < cfg->num_inputs; i++) { | ||
1899 | hda_nid_t pin = cfg->inputs[i].pin; | ||
1900 | spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]); | ||
1901 | spec->cur_input = spec->last_input = i; | ||
1902 | spec->num_inputs++; | ||
1903 | 821 | ||
1904 | /* check whether the automatic mic switch is available */ | 822 | /* set the upper-limit for mixer amp to 0dB */ |
1905 | if (is_ext_mic(codec, i) && cfg->num_inputs >= 2) { | 823 | caps = query_amp_caps(codec, dac, HDA_OUTPUT); |
1906 | spec->mic_detect = 1; | 824 | caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT); |
1907 | spec->automic_idx = i; | 825 | caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f) |
1908 | } | 826 | << AC_AMPCAP_NUM_STEPS_SHIFT; |
1909 | } | 827 | snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps); |
1910 | return 0; | ||
1911 | } | 828 | } |
1912 | 829 | ||
1913 | static int cs421x_parse_auto_config(struct hda_codec *codec) | 830 | static int cs421x_parse_auto_config(struct hda_codec *codec) |
1914 | { | 831 | { |
1915 | struct cs_spec *spec = codec->spec; | 832 | struct cs_spec *spec = codec->spec; |
833 | hda_nid_t dac = CS4210_DAC_NID; | ||
1916 | int err; | 834 | int err; |
1917 | 835 | ||
1918 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | 836 | fix_volume_caps(codec, dac); |
1919 | if (err < 0) | 837 | |
1920 | return err; | 838 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
1921 | err = parse_output(codec); | ||
1922 | if (err < 0) | ||
1923 | return err; | ||
1924 | err = parse_cs421x_input(codec); | ||
1925 | if (err < 0) | 839 | if (err < 0) |
1926 | return err; | 840 | return err; |
1927 | err = parse_digital_output(codec); | 841 | |
842 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); | ||
1928 | if (err < 0) | 843 | if (err < 0) |
1929 | return err; | 844 | return err; |
845 | |||
846 | parse_cs421x_digital(codec); | ||
1930 | return 0; | 847 | return 0; |
1931 | } | 848 | } |
1932 | 849 | ||
@@ -1959,7 +876,7 @@ static int cs421x_suspend(struct hda_codec *codec) | |||
1959 | 876 | ||
1960 | static const struct hda_codec_ops cs421x_patch_ops = { | 877 | static const struct hda_codec_ops cs421x_patch_ops = { |
1961 | .build_controls = cs421x_build_controls, | 878 | .build_controls = cs421x_build_controls, |
1962 | .build_pcms = cs_build_pcms, | 879 | .build_pcms = snd_hda_gen_build_pcms, |
1963 | .init = cs421x_init, | 880 | .init = cs421x_init, |
1964 | .free = cs_free, | 881 | .free = cs_free, |
1965 | .unsol_event = snd_hda_jack_unsol_event, | 882 | .unsol_event = snd_hda_jack_unsol_event, |
@@ -1973,12 +890,9 @@ static int patch_cs4210(struct hda_codec *codec) | |||
1973 | struct cs_spec *spec; | 890 | struct cs_spec *spec; |
1974 | int err; | 891 | int err; |
1975 | 892 | ||
1976 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 893 | spec = cs_alloc_spec(codec, CS4210_VENDOR_NID); |
1977 | if (!spec) | 894 | if (!spec) |
1978 | return -ENOMEM; | 895 | return -ENOMEM; |
1979 | codec->spec = spec; | ||
1980 | |||
1981 | spec->vendor_nid = CS4210_VENDOR_NID; | ||
1982 | 896 | ||
1983 | snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, | 897 | snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl, |
1984 | cs421x_fixups); | 898 | cs421x_fixups); |
@@ -2003,7 +917,6 @@ static int patch_cs4210(struct hda_codec *codec) | |||
2003 | 917 | ||
2004 | error: | 918 | error: |
2005 | cs_free(codec); | 919 | cs_free(codec); |
2006 | codec->spec = NULL; | ||
2007 | return err; | 920 | return err; |
2008 | } | 921 | } |
2009 | 922 | ||
@@ -2012,12 +925,9 @@ static int patch_cs4213(struct hda_codec *codec) | |||
2012 | struct cs_spec *spec; | 925 | struct cs_spec *spec; |
2013 | int err; | 926 | int err; |
2014 | 927 | ||
2015 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 928 | spec = cs_alloc_spec(codec, CS4213_VENDOR_NID); |
2016 | if (!spec) | 929 | if (!spec) |
2017 | return -ENOMEM; | 930 | return -ENOMEM; |
2018 | codec->spec = spec; | ||
2019 | |||
2020 | spec->vendor_nid = CS4213_VENDOR_NID; | ||
2021 | 931 | ||
2022 | err = cs421x_parse_auto_config(codec); | 932 | err = cs421x_parse_auto_config(codec); |
2023 | if (err < 0) | 933 | if (err < 0) |
@@ -2028,7 +938,6 @@ static int patch_cs4213(struct hda_codec *codec) | |||
2028 | 938 | ||
2029 | error: | 939 | error: |
2030 | cs_free(codec); | 940 | cs_free(codec); |
2031 | codec->spec = NULL; | ||
2032 | return err; | 941 | return err; |
2033 | } | 942 | } |
2034 | 943 | ||