2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for C-Media CMI9880
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
35 /* board config type */
37 CMI_MINIMAL, /* back 3-jack */
38 CMI_MIN_FP, /* back 3-jack + front-panel 2-jack */
39 CMI_FULL, /* back 6-jack + front-panel 2-jack */
40 CMI_FULL_DIG, /* back 6-jack + front-panel 2-jack + digital I/O */
41 CMI_ALLOUT, /* back 5-jack + front-panel 2-jack + digital out */
42 CMI_AUTO, /* let driver guess it */
47 unsigned int surr_switch: 1; /* switchable line,mic */
48 unsigned int no_line_in: 1; /* no line-in (5-jack) */
49 unsigned int front_panel: 1; /* has front-panel 2-jack */
52 struct hda_multi_out multiout;
53 hda_nid_t dac_nids[4]; /* NID for each DAC */
60 const struct hda_input_mux *input_mux;
61 unsigned int cur_mux[2];
64 unsigned int num_ch_modes;
65 unsigned int cur_ch_mode;
66 const struct cmi_channel_mode *channel_modes;
68 struct hda_pcm pcm_rec[2]; /* PCM information */
70 /* pin deafault configuration */
71 hda_nid_t pin_nid[NUM_PINS];
72 unsigned int def_conf[NUM_PINS];
73 unsigned int pin_def_confs;
75 /* multichannel pins */
76 hda_nid_t multich_pin[4]; /* max 8-channel */
77 struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */
83 static int cmi_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
85 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
86 struct cmi_spec *spec = codec->spec;
87 return snd_hda_input_mux_info(spec->input_mux, uinfo);
90 static int cmi_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
92 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
93 struct cmi_spec *spec = codec->spec;
94 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
96 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
100 static int cmi_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
103 struct cmi_spec *spec = codec->spec;
104 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
106 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
107 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
111 * shared line-in, mic for surrounds
114 /* 3-stack / 2 channel */
115 static struct hda_verb cmi9880_ch2_init[] = {
116 /* set line-in PIN for input */
117 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
118 /* set mic PIN for input, also enable vref */
119 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
120 /* route front PCM (DAC1) to HP */
121 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
125 /* 3-stack / 6 channel */
126 static struct hda_verb cmi9880_ch6_init[] = {
127 /* set line-in PIN for output */
128 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
129 /* set mic PIN for output */
130 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
131 /* route front PCM (DAC1) to HP */
132 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
136 /* 3-stack+front / 8 channel */
137 static struct hda_verb cmi9880_ch8_init[] = {
138 /* set line-in PIN for output */
139 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
140 /* set mic PIN for output */
141 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
142 /* route rear-surround PCM (DAC4) to HP */
143 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 },
147 struct cmi_channel_mode {
148 unsigned int channels;
149 const struct hda_verb *sequence;
152 static struct cmi_channel_mode cmi9880_channel_modes[3] = {
153 { 2, cmi9880_ch2_init },
154 { 6, cmi9880_ch6_init },
155 { 8, cmi9880_ch8_init },
158 static int cmi_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
161 struct cmi_spec *spec = codec->spec;
163 snd_assert(spec->channel_modes, return -EINVAL);
164 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
166 uinfo->value.enumerated.items = spec->num_ch_modes;
167 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
168 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
169 sprintf(uinfo->value.enumerated.name, "%dch",
170 spec->channel_modes[uinfo->value.enumerated.item].channels);
174 static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
176 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
177 struct cmi_spec *spec = codec->spec;
179 ucontrol->value.enumerated.item[0] = spec->cur_ch_mode;
183 static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
186 struct cmi_spec *spec = codec->spec;
188 snd_assert(spec->channel_modes, return -EINVAL);
189 if (ucontrol->value.enumerated.item[0] >= spec->num_ch_modes)
190 ucontrol->value.enumerated.item[0] = spec->num_ch_modes;
191 if (ucontrol->value.enumerated.item[0] == spec->cur_ch_mode &&
195 spec->cur_ch_mode = ucontrol->value.enumerated.item[0];
196 snd_hda_sequence_write(codec, spec->channel_modes[spec->cur_ch_mode].sequence);
197 spec->multiout.max_channels = spec->channel_modes[spec->cur_ch_mode].channels;
203 static snd_kcontrol_new_t cmi9880_basic_mixer[] = {
204 /* CMI9880 has no playback volumes! */
205 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), /* front */
206 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT),
207 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
208 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
209 HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT),
211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
212 /* The multiple "Capture Source" controls confuse alsamixer
213 * So call somewhat different..
214 * FIXME: the controls appear in the "playback" view!
216 /* .name = "Capture Source", */
217 .name = "Input Source",
219 .info = cmi_mux_enum_info,
220 .get = cmi_mux_enum_get,
221 .put = cmi_mux_enum_put,
223 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT),
224 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
225 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
226 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
227 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT),
228 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT),
235 static snd_kcontrol_new_t cmi9880_ch_mode_mixer[] = {
237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
238 .name = "Channel Mode",
239 .info = cmi_ch_mode_info,
240 .get = cmi_ch_mode_get,
241 .put = cmi_ch_mode_put,
246 /* AUD-in selections:
247 * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20
249 static struct hda_input_mux cmi9880_basic_mux = {
252 { "Front Mic", 0x5 },
259 static struct hda_input_mux cmi9880_no_line_mux = {
262 { "Front Mic", 0x5 },
268 /* front, rear, clfe, rear_surr */
269 static hda_nid_t cmi9880_dac_nids[4] = {
270 0x03, 0x04, 0x05, 0x06
273 static hda_nid_t cmi9880_adc_nids[2] = {
277 #define CMI_DIG_OUT_NID 0x07
278 #define CMI_DIG_IN_NID 0x0a
282 static struct hda_verb cmi9880_basic_init[] = {
283 /* port-D for line out (rear panel) */
284 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
285 /* port-E for HP out (front panel) */
286 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
287 /* route front PCM to HP */
288 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
289 /* port-A for surround (rear panel) */
290 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
291 /* port-G for CLFE (rear panel) */
292 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
293 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
294 /* port-H for side (rear panel) */
295 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
296 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
297 /* port-C for line-in (rear panel) */
298 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
299 /* port-B for mic-in (rear panel) with vref */
300 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
301 /* port-F for mic-in (front panel) with vref */
302 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
304 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
305 /* route front mic to ADC1/2 */
306 { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
307 { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
311 static struct hda_verb cmi9880_allout_init[] = {
312 /* port-D for line out (rear panel) */
313 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
314 /* port-E for HP out (front panel) */
315 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
316 /* route front PCM to HP */
317 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
318 /* port-A for side (rear panel) */
319 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
320 /* port-G for CLFE (rear panel) */
321 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
322 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
323 /* port-H for side (rear panel) */
324 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
325 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
326 /* port-C for surround (rear panel) */
327 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
328 /* port-B for mic-in (rear panel) with vref */
329 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
330 /* port-F for mic-in (front panel) with vref */
331 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
333 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
334 /* route front mic to ADC1/2 */
335 { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
336 { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
342 static int cmi9880_build_controls(struct hda_codec *codec)
344 struct cmi_spec *spec = codec->spec;
347 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
350 if (spec->surr_switch) {
351 err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
355 if (spec->multiout.dig_out_nid) {
356 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
360 if (spec->dig_in_nid) {
361 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
368 #define get_defcfg_connect(cfg) ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
369 #define get_defcfg_association(cfg) ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
370 #define get_defcfg_sequence(cfg) (cfg & AC_DEFCFG_SEQUENCE)
372 /* get all pin default configuration in def_conf */
373 static int cmi9880_get_pin_def_config(struct hda_codec *codec)
375 struct cmi_spec *spec = codec->spec;
376 hda_nid_t nid, nid_start;
379 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid_start);
380 for (nid = nid_start; nid < nodes + nid_start; nid++) {
381 unsigned int wid_caps = snd_hda_param_read(codec, nid,
382 AC_PAR_AUDIO_WIDGET_CAP);
383 unsigned int wid_type = (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
384 /* read all default configuration for pin complex */
385 if (wid_type == AC_WID_PIN) {
386 spec->pin_nid[i] = nid;
388 snd_hda_codec_read(codec, nid, 0,
389 AC_VERB_GET_CONFIG_DEFAULT, 0);
393 spec->pin_def_confs = i;
397 /* get a pin default configuration of nid in def_conf */
398 static unsigned int cmi9880_get_def_config(struct hda_codec *codec, hda_nid_t nid)
400 struct cmi_spec *spec = codec->spec;
403 while (spec->pin_nid[i] != nid && i < spec->pin_def_confs)
405 if (i == spec->pin_def_confs)
406 return (unsigned int) -1;
408 return spec->def_conf[i];
411 /* decide what pins to use for multichannel playback */
412 static int cmi9880_get_multich_pins(struct hda_codec *codec)
414 struct cmi_spec *spec = codec->spec;
415 int i, j, pins, seq[4];
417 unsigned int def_conf, sequence;
420 memset(spec->multich_pin, 0, sizeof(spec->multich_pin));
421 for (pins = 0, i = 0; i < spec->pin_def_confs && pins < 4; i++) {
422 def_conf = spec->def_conf[i];
423 /* skip pin not connected */
424 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
426 /* get the sequence if association == 1 */
427 /* the other pins have association = 0, incorrect in spec 1.0 */
428 if (get_defcfg_association(def_conf) == 1) {
429 sequence = get_defcfg_sequence(def_conf);
430 seq[pins] = sequence;
431 spec->multich_pin[pins] = spec->pin_nid[i];
432 pins++; // ready for next slot
436 /* sort by sequence, data collected here will be for Windows */
437 for (i = 0; i < pins; i++) {
438 for (j = i + 1; j < pins; j++) {
439 if (seq[j] < seq[i]) {
441 nid = spec->multich_pin[j];
443 spec->multich_pin[j] = spec->multich_pin[i];
445 spec->multich_pin[i] = nid;
449 /* the pin assignment is for front, C/LFE, surround and back */
450 if (max_channel >= 6) {
452 /* exchange pin of C/LFE and surround */
453 temp = spec->multich_pin[1];
454 spec->multich_pin[1] = spec->multich_pin[2];
455 spec->multich_pin[2] = temp;
460 /* fill in the multi_dac_nids table, which will decide
461 which audio widget to use for each channel */
462 static int cmi9880_fill_multi_dac_nids(struct hda_codec *codec)
464 struct cmi_spec *spec = codec->spec;
469 /* clear the table, only one c-media dac assumed here */
470 memset(spec->dac_nids, 0, sizeof(spec->dac_nids));
471 memset(assigned, 0, sizeof(assigned));
472 /* check the pins we found */
473 for (i = 0; i < spec->multiout.max_channels / 2; i++) {
474 nid = spec->multich_pin[i];
475 /* nid 0x0b~0x0e is hardwired to audio widget 0x3~0x6 */
476 if (nid <= 0x0e && nid >= 0x0b) {
477 spec->dac_nids[i] = nid - 0x08;
478 assigned[nid - 0x0b] = 1;
481 /* left pin can be connect to any audio widget */
482 for (i = 0; i < spec->multiout.max_channels / 2; i++) {
484 /* search for an empty channel */
485 /* I should also check the pin type */
486 for (j = 0; j < ARRAY_SIZE(spec->dac_nids); j++)
487 if (! spec->dac_nids[j]) {
488 spec->dac_nids[j] = i + 3;
497 /* create multi_init table, which is used for multichannel initialization */
498 static int cmi9880_fill_multi_init(struct hda_codec *codec)
500 struct cmi_spec *spec = codec->spec;
504 /* clear the table, only one c-media dac assumed here */
505 memset(spec->multi_init, 0, sizeof(spec->multi_init));
506 for (j = 0, i = 0; i < spec->multiout.max_channels / 2; i++) {
508 nid = spec->multich_pin[i];
510 spec->multi_init[j].nid = nid;
511 spec->multi_init[j].verb = AC_VERB_SET_PIN_WIDGET_CONTROL;
512 spec->multi_init[j].param = 0xc0;
514 /* nid 0x0f,0x10,0x1f,0x20 are needed to set connection */
521 spec->multi_init[j].nid = nid;
522 spec->multi_init[j].verb = AC_VERB_SET_CONNECT_SEL;
523 /* find the index in connect list */
524 len = snd_hda_get_connections(codec, nid, conn, 4);
525 for (k = 0; k < len; k++)
526 if (conn[k] == spec->dac_nids[i])
528 spec->multi_init[j].param = k < len ? k : 0;
536 static int cmi9880_init(struct hda_codec *codec)
538 struct cmi_spec *spec = codec->spec;
539 if (spec->board_config == CMI_ALLOUT)
540 snd_hda_sequence_write(codec, cmi9880_allout_init);
542 snd_hda_sequence_write(codec, cmi9880_basic_init);
543 if (spec->board_config == CMI_AUTO)
544 snd_hda_sequence_write(codec, spec->multi_init);
552 static int cmi9880_resume(struct hda_codec *codec)
554 struct cmi_spec *spec = codec->spec;
557 snd_hda_resume_ctls(codec, cmi9880_basic_mixer);
558 if (spec->surr_switch)
559 snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer);
560 if (spec->multiout.dig_out_nid)
561 snd_hda_resume_spdif_out(codec);
562 if (spec->dig_in_nid)
563 snd_hda_resume_spdif_in(codec);
570 * Analog playback callbacks
572 static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
573 struct hda_codec *codec,
574 snd_pcm_substream_t *substream)
576 struct cmi_spec *spec = codec->spec;
577 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
580 static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
581 struct hda_codec *codec,
582 unsigned int stream_tag,
584 snd_pcm_substream_t *substream)
586 struct cmi_spec *spec = codec->spec;
587 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
591 static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
592 struct hda_codec *codec,
593 snd_pcm_substream_t *substream)
595 struct cmi_spec *spec = codec->spec;
596 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
602 static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
603 struct hda_codec *codec,
604 snd_pcm_substream_t *substream)
606 struct cmi_spec *spec = codec->spec;
607 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
610 static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
611 struct hda_codec *codec,
612 snd_pcm_substream_t *substream)
614 struct cmi_spec *spec = codec->spec;
615 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
621 static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
622 struct hda_codec *codec,
623 unsigned int stream_tag,
625 snd_pcm_substream_t *substream)
627 struct cmi_spec *spec = codec->spec;
629 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
630 stream_tag, 0, format);
634 static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
635 struct hda_codec *codec,
636 snd_pcm_substream_t *substream)
638 struct cmi_spec *spec = codec->spec;
640 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
647 static struct hda_pcm_stream cmi9880_pcm_analog_playback = {
651 .nid = 0x03, /* NID to query formats and rates */
653 .open = cmi9880_playback_pcm_open,
654 .prepare = cmi9880_playback_pcm_prepare,
655 .cleanup = cmi9880_playback_pcm_cleanup
659 static struct hda_pcm_stream cmi9880_pcm_analog_capture = {
663 .nid = 0x08, /* NID to query formats and rates */
665 .prepare = cmi9880_capture_pcm_prepare,
666 .cleanup = cmi9880_capture_pcm_cleanup
670 static struct hda_pcm_stream cmi9880_pcm_digital_playback = {
674 /* NID is set in cmi9880_build_pcms */
676 .open = cmi9880_dig_playback_pcm_open,
677 .close = cmi9880_dig_playback_pcm_close
681 static struct hda_pcm_stream cmi9880_pcm_digital_capture = {
685 /* NID is set in cmi9880_build_pcms */
688 static int cmi9880_build_pcms(struct hda_codec *codec)
690 struct cmi_spec *spec = codec->spec;
691 struct hda_pcm *info = spec->pcm_rec;
694 codec->pcm_info = info;
696 info->name = "CMI9880";
697 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_analog_playback;
698 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_analog_capture;
700 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
703 info->name = "CMI9880 Digital";
704 if (spec->multiout.dig_out_nid) {
705 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
706 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
708 if (spec->dig_in_nid) {
709 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_digital_capture;
710 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
717 static void cmi9880_free(struct hda_codec *codec)
725 static struct hda_board_config cmi9880_cfg_tbl[] = {
726 { .modelname = "minimal", .config = CMI_MINIMAL },
727 { .modelname = "min_fp", .config = CMI_MIN_FP },
728 { .modelname = "full", .config = CMI_FULL },
729 { .modelname = "full_dig", .config = CMI_FULL_DIG },
730 { .modelname = "allout", .config = CMI_ALLOUT },
731 { .modelname = "auto", .config = CMI_AUTO },
735 static struct hda_codec_ops cmi9880_patch_ops = {
736 .build_controls = cmi9880_build_controls,
737 .build_pcms = cmi9880_build_pcms,
738 .init = cmi9880_init,
739 .free = cmi9880_free,
741 .resume = cmi9880_resume,
745 static int patch_cmi9880(struct hda_codec *codec)
747 struct cmi_spec *spec;
749 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
754 spec->board_config = snd_hda_check_board_config(codec, cmi9880_cfg_tbl);
755 if (spec->board_config < 0) {
756 snd_printdd(KERN_INFO "hda_codec: Unknown model for CMI9880\n");
757 spec->board_config = CMI_AUTO; /* try everything */
760 /* copy default DAC NIDs */
761 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids));
763 switch (spec->board_config) {
766 spec->surr_switch = 1;
767 if (spec->board_config == CMI_MINIMAL)
768 spec->num_ch_modes = 2;
770 spec->front_panel = 1;
771 spec->num_ch_modes = 3;
773 spec->channel_modes = cmi9880_channel_modes;
774 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
775 spec->input_mux = &cmi9880_basic_mux;
779 spec->front_panel = 1;
780 spec->multiout.max_channels = 8;
781 spec->input_mux = &cmi9880_basic_mux;
782 if (spec->board_config == CMI_FULL_DIG) {
783 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
784 spec->dig_in_nid = CMI_DIG_IN_NID;
788 spec->front_panel = 1;
789 spec->multiout.max_channels = 8;
790 spec->no_line_in = 1;
791 spec->input_mux = &cmi9880_no_line_mux;
792 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
796 unsigned int port_e, port_f, port_g, port_h;
797 unsigned int port_spdifi, port_spdifo;
799 /* collect pin default configuration */
800 cmi9880_get_pin_def_config(codec);
801 port_e = cmi9880_get_def_config(codec, 0x0f);
802 port_f = cmi9880_get_def_config(codec, 0x10);
803 port_g = cmi9880_get_def_config(codec, 0x1f);
804 port_h = cmi9880_get_def_config(codec, 0x20);
805 port_spdifi = cmi9880_get_def_config(codec, 0x13);
806 port_spdifo = cmi9880_get_def_config(codec, 0x12);
807 spec->front_panel = 1;
808 if (get_defcfg_connect(port_e) == AC_JACK_PORT_NONE ||
809 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) {
810 spec->surr_switch = 1;
812 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
813 get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) {
814 /* no optional rear panel */
815 spec->board_config = CMI_MINIMAL;
816 spec->front_panel = 0;
817 spec->num_ch_modes = 2;
819 spec->board_config = CMI_MIN_FP;
820 spec->num_ch_modes = 3;
822 spec->channel_modes = cmi9880_channel_modes;
823 spec->input_mux = &cmi9880_basic_mux;
824 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
826 spec->input_mux = &cmi9880_basic_mux;
827 if (get_defcfg_connect(port_spdifo) != AC_JACK_PORT_NONE)
828 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
829 if (get_defcfg_connect(port_spdifi) != AC_JACK_PORT_NONE)
830 spec->dig_in_nid = CMI_DIG_IN_NID;
831 spec->multiout.max_channels = 8;
833 max_channels = cmi9880_get_multich_pins(codec);
834 if (max_channels > 0) {
835 spec->multiout.max_channels = max_channels;
836 cmi9880_fill_multi_dac_nids(codec);
837 cmi9880_fill_multi_init(codec);
839 snd_printd("patch_cmedia: cannot detect association in defcfg\n");
844 spec->multiout.num_dacs = 4;
845 spec->multiout.dac_nids = spec->dac_nids;
847 spec->adc_nids = cmi9880_adc_nids;
849 codec->patch_ops = cmi9880_patch_ops;
857 struct hda_codec_preset snd_hda_preset_cmedia[] = {
858 { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
859 { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },