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 */
61 const struct hda_input_mux
*input_mux
;
62 unsigned int cur_mux
[2];
65 unsigned int num_ch_modes
;
66 unsigned int cur_ch_mode
;
67 const struct cmi_channel_mode
*channel_modes
;
69 struct hda_pcm pcm_rec
[2]; /* PCM information */
71 /* pin deafault configuration */
72 hda_nid_t pin_nid
[NUM_PINS
];
73 unsigned int def_conf
[NUM_PINS
];
74 unsigned int pin_def_confs
;
76 /* multichannel pins */
77 hda_nid_t multich_pin
[4]; /* max 8-channel */
78 struct hda_verb multi_init
[9]; /* 2 verbs for each pin + terminator */
82 #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
83 #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
84 #define AMP_OUT_MUTE 0xb080
85 #define AMP_OUT_UNMUTE 0xb000
86 #define AMP_OUT_ZERO 0xb000
89 #define PIN_VREF80 0x24
90 #define PIN_VREF50 0x21
97 static int cmi_mux_enum_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
99 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
100 struct cmi_spec
*spec
= codec
->spec
;
101 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
104 static int cmi_mux_enum_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
106 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
107 struct cmi_spec
*spec
= codec
->spec
;
108 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
110 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
114 static int cmi_mux_enum_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
116 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
117 struct cmi_spec
*spec
= codec
->spec
;
118 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
120 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
121 spec
->adc_nids
[adc_idx
], &spec
->cur_mux
[adc_idx
]);
125 * shared line-in, mic for surrounds
128 /* 3-stack / 2 channel */
129 static struct hda_verb cmi9880_ch2_init
[] = {
130 /* set line-in PIN for input */
131 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
132 /* set mic PIN for input, also enable vref */
133 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
134 /* route front PCM (DAC1) to HP */
135 { 0x0f, AC_VERB_SET_CONNECT_SEL
, 0x00 },
139 /* 3-stack / 6 channel */
140 static struct hda_verb cmi9880_ch6_init
[] = {
141 /* set line-in PIN for output */
142 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
143 /* set mic PIN for output */
144 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
145 /* route front PCM (DAC1) to HP */
146 { 0x0f, AC_VERB_SET_CONNECT_SEL
, 0x00 },
150 /* 3-stack+front / 8 channel */
151 static struct hda_verb cmi9880_ch8_init
[] = {
152 /* set line-in PIN for output */
153 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
154 /* set mic PIN for output */
155 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
156 /* route rear-surround PCM (DAC4) to HP */
157 { 0x0f, AC_VERB_SET_CONNECT_SEL
, 0x03 },
161 struct cmi_channel_mode
{
162 unsigned int channels
;
163 const struct hda_verb
*sequence
;
166 static struct cmi_channel_mode cmi9880_channel_modes
[3] = {
167 { 2, cmi9880_ch2_init
},
168 { 6, cmi9880_ch6_init
},
169 { 8, cmi9880_ch8_init
},
172 static int cmi_ch_mode_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
174 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
175 struct cmi_spec
*spec
= codec
->spec
;
177 snd_assert(spec
->channel_modes
, return -EINVAL
);
178 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
180 uinfo
->value
.enumerated
.items
= spec
->num_ch_modes
;
181 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
182 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
183 sprintf(uinfo
->value
.enumerated
.name
, "%dch",
184 spec
->channel_modes
[uinfo
->value
.enumerated
.item
].channels
);
188 static int cmi_ch_mode_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
190 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
191 struct cmi_spec
*spec
= codec
->spec
;
193 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_ch_mode
;
197 static int cmi_ch_mode_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
199 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
200 struct cmi_spec
*spec
= codec
->spec
;
202 snd_assert(spec
->channel_modes
, return -EINVAL
);
203 if (ucontrol
->value
.enumerated
.item
[0] >= spec
->num_ch_modes
)
204 ucontrol
->value
.enumerated
.item
[0] = spec
->num_ch_modes
;
205 if (ucontrol
->value
.enumerated
.item
[0] == spec
->cur_ch_mode
&&
209 spec
->cur_ch_mode
= ucontrol
->value
.enumerated
.item
[0];
210 snd_hda_sequence_write(codec
, spec
->channel_modes
[spec
->cur_ch_mode
].sequence
);
211 spec
->multiout
.max_channels
= spec
->channel_modes
[spec
->cur_ch_mode
].channels
;
217 static snd_kcontrol_new_t cmi9880_basic_mixer
[] = {
218 /* CMI9880 has no playback volumes! */
219 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT
), /* front */
220 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT
),
221 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT
),
222 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT
),
223 HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT
),
225 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
226 /* The multiple "Capture Source" controls confuse alsamixer
227 * So call somewhat different..
228 * FIXME: the controls appear in the "playback" view!
230 /* .name = "Capture Source", */
231 .name
= "Input Source",
233 .info
= cmi_mux_enum_info
,
234 .get
= cmi_mux_enum_get
,
235 .put
= cmi_mux_enum_put
,
237 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT
),
238 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT
),
239 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT
),
240 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT
),
241 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT
),
242 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT
),
249 static snd_kcontrol_new_t cmi9880_ch_mode_mixer
[] = {
251 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
252 .name
= "Channel Mode",
253 .info
= cmi_ch_mode_info
,
254 .get
= cmi_ch_mode_get
,
255 .put
= cmi_ch_mode_put
,
260 /* AUD-in selections:
261 * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20
263 static struct hda_input_mux cmi9880_basic_mux
= {
266 { "Front Mic", 0x5 },
273 static struct hda_input_mux cmi9880_no_line_mux
= {
276 { "Front Mic", 0x5 },
282 /* front, rear, clfe, rear_surr */
283 static hda_nid_t cmi9880_dac_nids
[4] = {
284 0x03, 0x04, 0x05, 0x06
287 static hda_nid_t cmi9880_adc_nids
[2] = {
291 #define CMI_DIG_OUT_NID 0x07
292 #define CMI_DIG_IN_NID 0x0a
296 static struct hda_verb cmi9880_basic_init
[] = {
297 /* port-D for line out (rear panel) */
298 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
299 /* port-E for HP out (front panel) */
300 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
301 /* route front PCM to HP */
302 { 0x0f, AC_VERB_SET_CONNECT_SEL
, 0x00 },
303 /* port-A for surround (rear panel) */
304 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
305 /* port-G for CLFE (rear panel) */
306 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
307 { 0x1f, AC_VERB_SET_CONNECT_SEL
, 0x02 },
308 /* port-H for side (rear panel) */
309 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
310 { 0x20, AC_VERB_SET_CONNECT_SEL
, 0x01 },
311 /* port-C for line-in (rear panel) */
312 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
313 /* port-B for mic-in (rear panel) with vref */
314 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
315 /* port-F for mic-in (front panel) with vref */
316 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
318 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
319 /* route front mic to ADC1/2 */
320 { 0x08, AC_VERB_SET_CONNECT_SEL
, 0x05 },
321 { 0x09, AC_VERB_SET_CONNECT_SEL
, 0x05 },
325 static struct hda_verb cmi9880_allout_init
[] = {
326 /* port-D for line out (rear panel) */
327 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
328 /* port-E for HP out (front panel) */
329 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
330 /* route front PCM to HP */
331 { 0x0f, AC_VERB_SET_CONNECT_SEL
, 0x00 },
332 /* port-A for side (rear panel) */
333 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
334 /* port-G for CLFE (rear panel) */
335 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
336 { 0x1f, AC_VERB_SET_CONNECT_SEL
, 0x02 },
337 /* port-H for side (rear panel) */
338 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
339 { 0x20, AC_VERB_SET_CONNECT_SEL
, 0x01 },
340 /* port-C for surround (rear panel) */
341 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
342 /* port-B for mic-in (rear panel) with vref */
343 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
344 /* port-F for mic-in (front panel) with vref */
345 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
347 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
348 /* route front mic to ADC1/2 */
349 { 0x08, AC_VERB_SET_CONNECT_SEL
, 0x05 },
350 { 0x09, AC_VERB_SET_CONNECT_SEL
, 0x05 },
356 static int cmi9880_build_controls(struct hda_codec
*codec
)
358 struct cmi_spec
*spec
= codec
->spec
;
361 err
= snd_hda_add_new_ctls(codec
, cmi9880_basic_mixer
);
364 if (spec
->surr_switch
) {
365 err
= snd_hda_add_new_ctls(codec
, cmi9880_ch_mode_mixer
);
369 if (spec
->multiout
.dig_out_nid
) {
370 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->multiout
.dig_out_nid
);
374 if (spec
->dig_in_nid
) {
375 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
382 /* fill in the multi_dac_nids table, which will decide
383 which audio widget to use for each channel */
384 static int cmi9880_fill_multi_dac_nids(struct hda_codec
*codec
, const struct auto_pin_cfg
*cfg
)
386 struct cmi_spec
*spec
= codec
->spec
;
391 /* clear the table, only one c-media dac assumed here */
392 memset(spec
->dac_nids
, 0, sizeof(spec
->dac_nids
));
393 memset(assigned
, 0, sizeof(assigned
));
394 /* check the pins we found */
395 for (i
= 0; i
< cfg
->line_outs
; i
++) {
396 nid
= cfg
->line_out_pins
[i
];
397 /* nid 0x0b~0x0e is hardwired to audio widget 0x3~0x6 */
398 if (nid
>= 0x0b && nid
<= 0x0e) {
399 spec
->dac_nids
[i
] = (nid
- 0x0b) + 0x03;
400 assigned
[nid
- 0x0b] = 1;
403 /* left pin can be connect to any audio widget */
404 for (i
= 0; i
< cfg
->line_outs
; i
++) {
405 nid
= cfg
->line_out_pins
[i
];
408 /* search for an empty channel */
409 for (j
= 0; j
< cfg
->line_outs
; j
++) {
411 spec
->dac_nids
[i
] = i
+ 0x03;
417 spec
->num_dacs
= cfg
->line_outs
;
421 /* create multi_init table, which is used for multichannel initialization */
422 static int cmi9880_fill_multi_init(struct hda_codec
*codec
, const struct auto_pin_cfg
*cfg
)
424 struct cmi_spec
*spec
= codec
->spec
;
428 /* clear the table, only one c-media dac assumed here */
429 memset(spec
->multi_init
, 0, sizeof(spec
->multi_init
));
430 for (j
= 0, i
= 0; i
< cfg
->line_outs
; i
++) {
432 nid
= cfg
->line_out_pins
[i
];
434 spec
->multi_init
[j
].nid
= nid
;
435 spec
->multi_init
[j
].verb
= AC_VERB_SET_PIN_WIDGET_CONTROL
;
436 spec
->multi_init
[j
].param
= PIN_OUT
;
440 spec
->multi_init
[j
].nid
= nid
;
441 spec
->multi_init
[j
].verb
= AC_VERB_SET_CONNECT_SEL
;
442 spec
->multi_init
[j
].param
= 0;
443 /* find the index in connect list */
444 len
= snd_hda_get_connections(codec
, nid
, conn
, 4);
445 for (k
= 0; k
< len
; k
++)
446 if (conn
[k
] == spec
->dac_nids
[i
]) {
447 spec
->multi_init
[j
].param
= j
;
457 static int cmi9880_init(struct hda_codec
*codec
)
459 struct cmi_spec
*spec
= codec
->spec
;
460 if (spec
->board_config
== CMI_ALLOUT
)
461 snd_hda_sequence_write(codec
, cmi9880_allout_init
);
463 snd_hda_sequence_write(codec
, cmi9880_basic_init
);
464 if (spec
->board_config
== CMI_AUTO
)
465 snd_hda_sequence_write(codec
, spec
->multi_init
);
473 static int cmi9880_resume(struct hda_codec
*codec
)
475 struct cmi_spec
*spec
= codec
->spec
;
478 snd_hda_resume_ctls(codec
, cmi9880_basic_mixer
);
479 if (spec
->surr_switch
)
480 snd_hda_resume_ctls(codec
, cmi9880_ch_mode_mixer
);
481 if (spec
->multiout
.dig_out_nid
)
482 snd_hda_resume_spdif_out(codec
);
483 if (spec
->dig_in_nid
)
484 snd_hda_resume_spdif_in(codec
);
491 * Analog playback callbacks
493 static int cmi9880_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
494 struct hda_codec
*codec
,
495 snd_pcm_substream_t
*substream
)
497 struct cmi_spec
*spec
= codec
->spec
;
498 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
);
501 static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
502 struct hda_codec
*codec
,
503 unsigned int stream_tag
,
505 snd_pcm_substream_t
*substream
)
507 struct cmi_spec
*spec
= codec
->spec
;
508 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
, stream_tag
,
512 static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
513 struct hda_codec
*codec
,
514 snd_pcm_substream_t
*substream
)
516 struct cmi_spec
*spec
= codec
->spec
;
517 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
523 static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
524 struct hda_codec
*codec
,
525 snd_pcm_substream_t
*substream
)
527 struct cmi_spec
*spec
= codec
->spec
;
528 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
531 static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
532 struct hda_codec
*codec
,
533 snd_pcm_substream_t
*substream
)
535 struct cmi_spec
*spec
= codec
->spec
;
536 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
542 static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
543 struct hda_codec
*codec
,
544 unsigned int stream_tag
,
546 snd_pcm_substream_t
*substream
)
548 struct cmi_spec
*spec
= codec
->spec
;
550 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
551 stream_tag
, 0, format
);
555 static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
556 struct hda_codec
*codec
,
557 snd_pcm_substream_t
*substream
)
559 struct cmi_spec
*spec
= codec
->spec
;
561 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
], 0, 0, 0);
568 static struct hda_pcm_stream cmi9880_pcm_analog_playback
= {
572 .nid
= 0x03, /* NID to query formats and rates */
574 .open
= cmi9880_playback_pcm_open
,
575 .prepare
= cmi9880_playback_pcm_prepare
,
576 .cleanup
= cmi9880_playback_pcm_cleanup
580 static struct hda_pcm_stream cmi9880_pcm_analog_capture
= {
584 .nid
= 0x08, /* NID to query formats and rates */
586 .prepare
= cmi9880_capture_pcm_prepare
,
587 .cleanup
= cmi9880_capture_pcm_cleanup
591 static struct hda_pcm_stream cmi9880_pcm_digital_playback
= {
595 /* NID is set in cmi9880_build_pcms */
597 .open
= cmi9880_dig_playback_pcm_open
,
598 .close
= cmi9880_dig_playback_pcm_close
602 static struct hda_pcm_stream cmi9880_pcm_digital_capture
= {
606 /* NID is set in cmi9880_build_pcms */
609 static int cmi9880_build_pcms(struct hda_codec
*codec
)
611 struct cmi_spec
*spec
= codec
->spec
;
612 struct hda_pcm
*info
= spec
->pcm_rec
;
615 codec
->pcm_info
= info
;
617 info
->name
= "CMI9880";
618 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = cmi9880_pcm_analog_playback
;
619 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = cmi9880_pcm_analog_capture
;
621 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
624 info
->name
= "CMI9880 Digital";
625 if (spec
->multiout
.dig_out_nid
) {
626 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = cmi9880_pcm_digital_playback
;
627 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
629 if (spec
->dig_in_nid
) {
630 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = cmi9880_pcm_digital_capture
;
631 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
638 static void cmi9880_free(struct hda_codec
*codec
)
646 static struct hda_board_config cmi9880_cfg_tbl
[] = {
647 { .modelname
= "minimal", .config
= CMI_MINIMAL
},
648 { .modelname
= "min_fp", .config
= CMI_MIN_FP
},
649 { .modelname
= "full", .config
= CMI_FULL
},
650 { .modelname
= "full_dig", .config
= CMI_FULL_DIG
},
651 { .modelname
= "allout", .config
= CMI_ALLOUT
},
652 { .modelname
= "auto", .config
= CMI_AUTO
},
656 static struct hda_codec_ops cmi9880_patch_ops
= {
657 .build_controls
= cmi9880_build_controls
,
658 .build_pcms
= cmi9880_build_pcms
,
659 .init
= cmi9880_init
,
660 .free
= cmi9880_free
,
662 .resume
= cmi9880_resume
,
666 static int patch_cmi9880(struct hda_codec
*codec
)
668 struct cmi_spec
*spec
;
670 spec
= kcalloc(1, sizeof(*spec
), GFP_KERNEL
);
675 spec
->board_config
= snd_hda_check_board_config(codec
, cmi9880_cfg_tbl
);
676 if (spec
->board_config
< 0) {
677 snd_printdd(KERN_INFO
"hda_codec: Unknown model for CMI9880\n");
678 spec
->board_config
= CMI_AUTO
; /* try everything */
681 /* copy default DAC NIDs */
682 memcpy(spec
->dac_nids
, cmi9880_dac_nids
, sizeof(spec
->dac_nids
));
685 switch (spec
->board_config
) {
688 spec
->surr_switch
= 1;
689 if (spec
->board_config
== CMI_MINIMAL
)
690 spec
->num_ch_modes
= 2;
692 spec
->front_panel
= 1;
693 spec
->num_ch_modes
= 3;
695 spec
->channel_modes
= cmi9880_channel_modes
;
696 spec
->multiout
.max_channels
= cmi9880_channel_modes
[0].channels
;
697 spec
->input_mux
= &cmi9880_basic_mux
;
701 spec
->front_panel
= 1;
702 spec
->multiout
.max_channels
= 8;
703 spec
->input_mux
= &cmi9880_basic_mux
;
704 if (spec
->board_config
== CMI_FULL_DIG
) {
705 spec
->multiout
.dig_out_nid
= CMI_DIG_OUT_NID
;
706 spec
->dig_in_nid
= CMI_DIG_IN_NID
;
710 spec
->front_panel
= 1;
711 spec
->multiout
.max_channels
= 8;
712 spec
->no_line_in
= 1;
713 spec
->input_mux
= &cmi9880_no_line_mux
;
714 spec
->multiout
.dig_out_nid
= CMI_DIG_OUT_NID
;
718 unsigned int port_e
, port_f
, port_g
, port_h
;
719 unsigned int port_spdifi
, port_spdifo
;
720 struct auto_pin_cfg cfg
;
722 /* collect pin default configuration */
723 port_e
= snd_hda_codec_read(codec
, 0x0f, 0, AC_VERB_GET_CONFIG_DEFAULT
, 0);
724 port_f
= snd_hda_codec_read(codec
, 0x10, 0, AC_VERB_GET_CONFIG_DEFAULT
, 0);
725 spec
->front_panel
= 1;
726 if (get_defcfg_connect(port_e
) == AC_JACK_PORT_NONE
||
727 get_defcfg_connect(port_f
) == AC_JACK_PORT_NONE
) {
728 port_g
= snd_hda_codec_read(codec
, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT
, 0);
729 port_h
= snd_hda_codec_read(codec
, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT
, 0);
730 spec
->surr_switch
= 1;
732 if (get_defcfg_connect(port_g
) == AC_JACK_PORT_NONE
||
733 get_defcfg_connect(port_h
) == AC_JACK_PORT_NONE
) {
734 /* no optional rear panel */
735 spec
->board_config
= CMI_MINIMAL
;
736 spec
->front_panel
= 0;
737 spec
->num_ch_modes
= 2;
739 spec
->board_config
= CMI_MIN_FP
;
740 spec
->num_ch_modes
= 3;
742 spec
->channel_modes
= cmi9880_channel_modes
;
743 spec
->input_mux
= &cmi9880_basic_mux
;
744 spec
->multiout
.max_channels
= cmi9880_channel_modes
[0].channels
;
746 spec
->input_mux
= &cmi9880_basic_mux
;
747 port_spdifi
= snd_hda_codec_read(codec
, 0x13, 0, AC_VERB_GET_CONFIG_DEFAULT
, 0);
748 port_spdifo
= snd_hda_codec_read(codec
, 0x12, 0, AC_VERB_GET_CONFIG_DEFAULT
, 0);
749 if (get_defcfg_connect(port_spdifo
) != AC_JACK_PORT_NONE
)
750 spec
->multiout
.dig_out_nid
= CMI_DIG_OUT_NID
;
751 if (get_defcfg_connect(port_spdifi
) != AC_JACK_PORT_NONE
)
752 spec
->dig_in_nid
= CMI_DIG_IN_NID
;
753 spec
->multiout
.max_channels
= 8;
755 snd_hda_parse_pin_def_config(codec
, &cfg
);
757 spec
->multiout
.max_channels
= cfg
.line_outs
* 2;
758 cmi9880_fill_multi_dac_nids(codec
, &cfg
);
759 cmi9880_fill_multi_init(codec
, &cfg
);
761 snd_printd("patch_cmedia: cannot detect association in defcfg\n");
766 spec
->multiout
.num_dacs
= spec
->num_dacs
;
767 spec
->multiout
.dac_nids
= spec
->dac_nids
;
769 spec
->adc_nids
= cmi9880_adc_nids
;
771 codec
->patch_ops
= cmi9880_patch_ops
;
779 struct hda_codec_preset snd_hda_preset_cmedia
[] = {
780 { .id
= 0x13f69880, .name
= "CMI9880", .patch
= patch_cmi9880
},
781 { .id
= 0x434d4980, .name
= "CMI9880", .patch
= patch_cmi9880
},