]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
4 | * HD audio interface patch for C-Media CMI9880 | |
5 | * | |
6 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> | |
7 | * | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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 | |
22 | */ | |
23 | ||
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" | |
f953eff2 | 32 | #define NUM_PINS 11 |
1da177e4 LT |
33 | |
34 | ||
35 | /* board config type */ | |
36 | enum { | |
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 */ | |
f953eff2 | 42 | CMI_AUTO, /* let driver guess it */ |
1da177e4 LT |
43 | }; |
44 | ||
45 | struct cmi_spec { | |
46 | int board_config; | |
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 */ | |
50 | ||
51 | /* playback */ | |
52 | struct hda_multi_out multiout; | |
f953eff2 | 53 | hda_nid_t dac_nids[4]; /* NID for each DAC */ |
e9edcee0 | 54 | int num_dacs; |
1da177e4 LT |
55 | |
56 | /* capture */ | |
57 | hda_nid_t *adc_nids; | |
58 | hda_nid_t dig_in_nid; | |
59 | ||
60 | /* capture source */ | |
61 | const struct hda_input_mux *input_mux; | |
62 | unsigned int cur_mux[2]; | |
63 | ||
64 | /* channel mode */ | |
65 | unsigned int num_ch_modes; | |
66 | unsigned int cur_ch_mode; | |
67 | const struct cmi_channel_mode *channel_modes; | |
68 | ||
69 | struct hda_pcm pcm_rec[2]; /* PCM information */ | |
f953eff2 TI |
70 | |
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; | |
75 | ||
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 */ | |
1da177e4 LT |
79 | }; |
80 | ||
e9edcee0 TI |
81 | /* amp values */ |
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 | |
87 | /* pinctl values */ | |
88 | #define PIN_IN 0x20 | |
89 | #define PIN_VREF80 0x24 | |
90 | #define PIN_VREF50 0x21 | |
91 | #define PIN_OUT 0x40 | |
92 | #define PIN_HP 0xc0 | |
93 | ||
1da177e4 LT |
94 | /* |
95 | * input MUX | |
96 | */ | |
97 | static int cmi_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) | |
98 | { | |
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); | |
102 | } | |
103 | ||
104 | static int cmi_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | |
105 | { | |
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); | |
109 | ||
110 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
111 | return 0; | |
112 | } | |
113 | ||
114 | static int cmi_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | |
115 | { | |
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); | |
119 | ||
120 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
121 | spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]); | |
122 | } | |
123 | ||
124 | /* | |
125 | * shared line-in, mic for surrounds | |
126 | */ | |
127 | ||
128 | /* 3-stack / 2 channel */ | |
129 | static struct hda_verb cmi9880_ch2_init[] = { | |
130 | /* set line-in PIN for input */ | |
e9edcee0 | 131 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
1da177e4 | 132 | /* set mic PIN for input, also enable vref */ |
e9edcee0 | 133 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
1da177e4 LT |
134 | /* route front PCM (DAC1) to HP */ |
135 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, | |
136 | {} | |
137 | }; | |
138 | ||
139 | /* 3-stack / 6 channel */ | |
140 | static struct hda_verb cmi9880_ch6_init[] = { | |
141 | /* set line-in PIN for output */ | |
e9edcee0 | 142 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
1da177e4 | 143 | /* set mic PIN for output */ |
e9edcee0 | 144 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
1da177e4 LT |
145 | /* route front PCM (DAC1) to HP */ |
146 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, | |
147 | {} | |
148 | }; | |
149 | ||
150 | /* 3-stack+front / 8 channel */ | |
151 | static struct hda_verb cmi9880_ch8_init[] = { | |
152 | /* set line-in PIN for output */ | |
e9edcee0 | 153 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
1da177e4 | 154 | /* set mic PIN for output */ |
e9edcee0 | 155 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
1da177e4 LT |
156 | /* route rear-surround PCM (DAC4) to HP */ |
157 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 }, | |
158 | {} | |
159 | }; | |
160 | ||
161 | struct cmi_channel_mode { | |
162 | unsigned int channels; | |
163 | const struct hda_verb *sequence; | |
164 | }; | |
165 | ||
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 }, | |
170 | }; | |
171 | ||
172 | static int cmi_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) | |
173 | { | |
174 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
175 | struct cmi_spec *spec = codec->spec; | |
176 | ||
177 | snd_assert(spec->channel_modes, return -EINVAL); | |
178 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
179 | uinfo->count = 1; | |
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); | |
185 | return 0; | |
186 | } | |
187 | ||
188 | static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | |
189 | { | |
190 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
191 | struct cmi_spec *spec = codec->spec; | |
192 | ||
193 | ucontrol->value.enumerated.item[0] = spec->cur_ch_mode; | |
194 | return 0; | |
195 | } | |
196 | ||
197 | static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) | |
198 | { | |
199 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
200 | struct cmi_spec *spec = codec->spec; | |
201 | ||
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 && | |
206 | ! codec->in_resume) | |
207 | return 0; | |
208 | ||
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; | |
212 | return 1; | |
213 | } | |
214 | ||
215 | /* | |
216 | */ | |
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), | |
224 | { | |
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! | |
229 | */ | |
230 | /* .name = "Capture Source", */ | |
231 | .name = "Input Source", | |
232 | .count = 2, | |
233 | .info = cmi_mux_enum_info, | |
234 | .get = cmi_mux_enum_get, | |
235 | .put = cmi_mux_enum_put, | |
236 | }, | |
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), | |
243 | { } /* end */ | |
244 | }; | |
245 | ||
246 | /* | |
247 | * shared I/O pins | |
248 | */ | |
249 | static snd_kcontrol_new_t cmi9880_ch_mode_mixer[] = { | |
250 | { | |
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, | |
256 | }, | |
257 | { } /* end */ | |
258 | }; | |
259 | ||
260 | /* AUD-in selections: | |
261 | * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20 | |
262 | */ | |
263 | static struct hda_input_mux cmi9880_basic_mux = { | |
264 | .num_items = 4, | |
265 | .items = { | |
266 | { "Front Mic", 0x5 }, | |
267 | { "Rear Mic", 0x2 }, | |
268 | { "Line", 0x1 }, | |
269 | { "CD", 0x7 }, | |
270 | } | |
271 | }; | |
272 | ||
273 | static struct hda_input_mux cmi9880_no_line_mux = { | |
274 | .num_items = 3, | |
275 | .items = { | |
276 | { "Front Mic", 0x5 }, | |
277 | { "Rear Mic", 0x2 }, | |
278 | { "CD", 0x7 }, | |
279 | } | |
280 | }; | |
281 | ||
282 | /* front, rear, clfe, rear_surr */ | |
283 | static hda_nid_t cmi9880_dac_nids[4] = { | |
284 | 0x03, 0x04, 0x05, 0x06 | |
285 | }; | |
286 | /* ADC0, ADC1 */ | |
287 | static hda_nid_t cmi9880_adc_nids[2] = { | |
288 | 0x08, 0x09 | |
289 | }; | |
290 | ||
291 | #define CMI_DIG_OUT_NID 0x07 | |
292 | #define CMI_DIG_IN_NID 0x0a | |
293 | ||
294 | /* | |
295 | */ | |
296 | static struct hda_verb cmi9880_basic_init[] = { | |
297 | /* port-D for line out (rear panel) */ | |
e9edcee0 | 298 | { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 | 299 | /* port-E for HP out (front panel) */ |
e9edcee0 | 300 | { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 LT |
301 | /* route front PCM to HP */ |
302 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, | |
303 | /* port-A for surround (rear panel) */ | |
e9edcee0 | 304 | { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 | 305 | /* port-G for CLFE (rear panel) */ |
e9edcee0 | 306 | { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
d05b2817 | 307 | { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 }, |
1da177e4 | 308 | /* port-H for side (rear panel) */ |
e9edcee0 | 309 | { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
d05b2817 | 310 | { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 }, |
1da177e4 | 311 | /* port-C for line-in (rear panel) */ |
e9edcee0 | 312 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
1da177e4 | 313 | /* port-B for mic-in (rear panel) with vref */ |
e9edcee0 | 314 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
1da177e4 | 315 | /* port-F for mic-in (front panel) with vref */ |
e9edcee0 | 316 | { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
1da177e4 | 317 | /* CD-in */ |
e9edcee0 | 318 | { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
1da177e4 LT |
319 | /* route front mic to ADC1/2 */ |
320 | { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 }, | |
321 | { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 }, | |
322 | {} /* terminator */ | |
323 | }; | |
324 | ||
325 | static struct hda_verb cmi9880_allout_init[] = { | |
326 | /* port-D for line out (rear panel) */ | |
e9edcee0 | 327 | { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 | 328 | /* port-E for HP out (front panel) */ |
e9edcee0 | 329 | { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 LT |
330 | /* route front PCM to HP */ |
331 | { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 }, | |
332 | /* port-A for side (rear panel) */ | |
e9edcee0 | 333 | { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 | 334 | /* port-G for CLFE (rear panel) */ |
e9edcee0 | 335 | { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
d05b2817 CT |
336 | { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 }, |
337 | /* port-H for side (rear panel) */ | |
e9edcee0 | 338 | { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
d05b2817 | 339 | { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 }, |
1da177e4 | 340 | /* port-C for surround (rear panel) */ |
e9edcee0 | 341 | { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, |
1da177e4 | 342 | /* port-B for mic-in (rear panel) with vref */ |
e9edcee0 | 343 | { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
1da177e4 | 344 | /* port-F for mic-in (front panel) with vref */ |
e9edcee0 | 345 | { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, |
1da177e4 | 346 | /* CD-in */ |
e9edcee0 | 347 | { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, |
1da177e4 LT |
348 | /* route front mic to ADC1/2 */ |
349 | { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 }, | |
350 | { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 }, | |
351 | {} /* terminator */ | |
352 | }; | |
353 | ||
354 | /* | |
355 | */ | |
356 | static int cmi9880_build_controls(struct hda_codec *codec) | |
357 | { | |
358 | struct cmi_spec *spec = codec->spec; | |
359 | int err; | |
360 | ||
361 | err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer); | |
362 | if (err < 0) | |
363 | return err; | |
364 | if (spec->surr_switch) { | |
365 | err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer); | |
366 | if (err < 0) | |
367 | return err; | |
368 | } | |
369 | if (spec->multiout.dig_out_nid) { | |
370 | err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); | |
371 | if (err < 0) | |
372 | return err; | |
373 | } | |
374 | if (spec->dig_in_nid) { | |
375 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
376 | if (err < 0) | |
377 | return err; | |
378 | } | |
379 | return 0; | |
380 | } | |
381 | ||
f953eff2 TI |
382 | /* fill in the multi_dac_nids table, which will decide |
383 | which audio widget to use for each channel */ | |
e9edcee0 | 384 | static int cmi9880_fill_multi_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg) |
f953eff2 TI |
385 | { |
386 | struct cmi_spec *spec = codec->spec; | |
387 | hda_nid_t nid; | |
388 | int assigned[4]; | |
389 | int i, j; | |
390 | ||
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 */ | |
e9edcee0 TI |
395 | for (i = 0; i < cfg->line_outs; i++) { |
396 | nid = cfg->line_out_pins[i]; | |
f953eff2 | 397 | /* nid 0x0b~0x0e is hardwired to audio widget 0x3~0x6 */ |
e9edcee0 TI |
398 | if (nid >= 0x0b && nid <= 0x0e) { |
399 | spec->dac_nids[i] = (nid - 0x0b) + 0x03; | |
f953eff2 TI |
400 | assigned[nid - 0x0b] = 1; |
401 | } | |
402 | } | |
403 | /* left pin can be connect to any audio widget */ | |
e9edcee0 TI |
404 | for (i = 0; i < cfg->line_outs; i++) { |
405 | nid = cfg->line_out_pins[i]; | |
406 | if (nid <= 0x0e) | |
407 | continue; | |
408 | /* search for an empty channel */ | |
409 | for (j = 0; j < cfg->line_outs; j++) { | |
410 | if (! assigned[j]) { | |
411 | spec->dac_nids[i] = i + 0x03; | |
412 | assigned[j] = 1; | |
413 | break; | |
414 | } | |
f953eff2 TI |
415 | } |
416 | } | |
e9edcee0 | 417 | spec->num_dacs = cfg->line_outs; |
f953eff2 TI |
418 | return 0; |
419 | } | |
420 | ||
421 | /* create multi_init table, which is used for multichannel initialization */ | |
e9edcee0 | 422 | static int cmi9880_fill_multi_init(struct hda_codec *codec, const struct auto_pin_cfg *cfg) |
f953eff2 TI |
423 | { |
424 | struct cmi_spec *spec = codec->spec; | |
425 | hda_nid_t nid; | |
426 | int i, j, k, len; | |
427 | ||
428 | /* clear the table, only one c-media dac assumed here */ | |
429 | memset(spec->multi_init, 0, sizeof(spec->multi_init)); | |
e9edcee0 | 430 | for (j = 0, i = 0; i < cfg->line_outs; i++) { |
f953eff2 | 431 | hda_nid_t conn[4]; |
e9edcee0 | 432 | nid = cfg->line_out_pins[i]; |
f953eff2 TI |
433 | /* set as output */ |
434 | spec->multi_init[j].nid = nid; | |
435 | spec->multi_init[j].verb = AC_VERB_SET_PIN_WIDGET_CONTROL; | |
e9edcee0 | 436 | spec->multi_init[j].param = PIN_OUT; |
f953eff2 | 437 | j++; |
e9edcee0 | 438 | if (nid > 0x0e) { |
f953eff2 TI |
439 | /* set connection */ |
440 | spec->multi_init[j].nid = nid; | |
441 | spec->multi_init[j].verb = AC_VERB_SET_CONNECT_SEL; | |
e9edcee0 | 442 | spec->multi_init[j].param = 0; |
f953eff2 TI |
443 | /* find the index in connect list */ |
444 | len = snd_hda_get_connections(codec, nid, conn, 4); | |
445 | for (k = 0; k < len; k++) | |
e9edcee0 TI |
446 | if (conn[k] == spec->dac_nids[i]) { |
447 | spec->multi_init[j].param = j; | |
f953eff2 | 448 | break; |
e9edcee0 | 449 | } |
f953eff2 TI |
450 | j++; |
451 | break; | |
452 | } | |
453 | } | |
454 | return 0; | |
455 | } | |
456 | ||
1da177e4 LT |
457 | static int cmi9880_init(struct hda_codec *codec) |
458 | { | |
459 | struct cmi_spec *spec = codec->spec; | |
460 | if (spec->board_config == CMI_ALLOUT) | |
461 | snd_hda_sequence_write(codec, cmi9880_allout_init); | |
462 | else | |
463 | snd_hda_sequence_write(codec, cmi9880_basic_init); | |
f953eff2 TI |
464 | if (spec->board_config == CMI_AUTO) |
465 | snd_hda_sequence_write(codec, spec->multi_init); | |
1da177e4 LT |
466 | return 0; |
467 | } | |
468 | ||
469 | #ifdef CONFIG_PM | |
470 | /* | |
471 | * resume | |
472 | */ | |
473 | static int cmi9880_resume(struct hda_codec *codec) | |
474 | { | |
475 | struct cmi_spec *spec = codec->spec; | |
476 | ||
477 | cmi9880_init(codec); | |
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); | |
485 | ||
486 | return 0; | |
487 | } | |
488 | #endif | |
489 | ||
490 | /* | |
491 | * Analog playback callbacks | |
492 | */ | |
493 | static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
494 | struct hda_codec *codec, | |
495 | snd_pcm_substream_t *substream) | |
496 | { | |
497 | struct cmi_spec *spec = codec->spec; | |
498 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); | |
499 | } | |
500 | ||
501 | static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
502 | struct hda_codec *codec, | |
503 | unsigned int stream_tag, | |
504 | unsigned int format, | |
505 | snd_pcm_substream_t *substream) | |
506 | { | |
507 | struct cmi_spec *spec = codec->spec; | |
508 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, | |
509 | format, substream); | |
510 | } | |
511 | ||
512 | static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
513 | struct hda_codec *codec, | |
514 | snd_pcm_substream_t *substream) | |
515 | { | |
516 | struct cmi_spec *spec = codec->spec; | |
517 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
518 | } | |
519 | ||
520 | /* | |
521 | * Digital out | |
522 | */ | |
523 | static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
524 | struct hda_codec *codec, | |
525 | snd_pcm_substream_t *substream) | |
526 | { | |
527 | struct cmi_spec *spec = codec->spec; | |
528 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
529 | } | |
530 | ||
531 | static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
532 | struct hda_codec *codec, | |
533 | snd_pcm_substream_t *substream) | |
534 | { | |
535 | struct cmi_spec *spec = codec->spec; | |
536 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
537 | } | |
538 | ||
539 | /* | |
540 | * Analog capture | |
541 | */ | |
542 | static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
543 | struct hda_codec *codec, | |
544 | unsigned int stream_tag, | |
545 | unsigned int format, | |
546 | snd_pcm_substream_t *substream) | |
547 | { | |
548 | struct cmi_spec *spec = codec->spec; | |
549 | ||
550 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
551 | stream_tag, 0, format); | |
552 | return 0; | |
553 | } | |
554 | ||
555 | static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
556 | struct hda_codec *codec, | |
557 | snd_pcm_substream_t *substream) | |
558 | { | |
559 | struct cmi_spec *spec = codec->spec; | |
560 | ||
561 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); | |
562 | return 0; | |
563 | } | |
564 | ||
565 | ||
566 | /* | |
567 | */ | |
568 | static struct hda_pcm_stream cmi9880_pcm_analog_playback = { | |
569 | .substreams = 1, | |
570 | .channels_min = 2, | |
571 | .channels_max = 8, | |
572 | .nid = 0x03, /* NID to query formats and rates */ | |
573 | .ops = { | |
574 | .open = cmi9880_playback_pcm_open, | |
575 | .prepare = cmi9880_playback_pcm_prepare, | |
576 | .cleanup = cmi9880_playback_pcm_cleanup | |
577 | }, | |
578 | }; | |
579 | ||
580 | static struct hda_pcm_stream cmi9880_pcm_analog_capture = { | |
581 | .substreams = 2, | |
582 | .channels_min = 2, | |
583 | .channels_max = 2, | |
584 | .nid = 0x08, /* NID to query formats and rates */ | |
585 | .ops = { | |
586 | .prepare = cmi9880_capture_pcm_prepare, | |
587 | .cleanup = cmi9880_capture_pcm_cleanup | |
588 | }, | |
589 | }; | |
590 | ||
591 | static struct hda_pcm_stream cmi9880_pcm_digital_playback = { | |
592 | .substreams = 1, | |
593 | .channels_min = 2, | |
594 | .channels_max = 2, | |
595 | /* NID is set in cmi9880_build_pcms */ | |
596 | .ops = { | |
597 | .open = cmi9880_dig_playback_pcm_open, | |
598 | .close = cmi9880_dig_playback_pcm_close | |
599 | }, | |
600 | }; | |
601 | ||
602 | static struct hda_pcm_stream cmi9880_pcm_digital_capture = { | |
603 | .substreams = 1, | |
604 | .channels_min = 2, | |
605 | .channels_max = 2, | |
606 | /* NID is set in cmi9880_build_pcms */ | |
607 | }; | |
608 | ||
609 | static int cmi9880_build_pcms(struct hda_codec *codec) | |
610 | { | |
611 | struct cmi_spec *spec = codec->spec; | |
612 | struct hda_pcm *info = spec->pcm_rec; | |
613 | ||
614 | codec->num_pcms = 1; | |
615 | codec->pcm_info = info; | |
616 | ||
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; | |
620 | ||
621 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | |
622 | codec->num_pcms++; | |
623 | info++; | |
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; | |
628 | } | |
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; | |
632 | } | |
633 | } | |
634 | ||
635 | return 0; | |
636 | } | |
637 | ||
638 | static void cmi9880_free(struct hda_codec *codec) | |
639 | { | |
640 | kfree(codec->spec); | |
641 | } | |
642 | ||
643 | /* | |
644 | */ | |
645 | ||
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 }, | |
f953eff2 | 652 | { .modelname = "auto", .config = CMI_AUTO }, |
1da177e4 LT |
653 | {} /* terminator */ |
654 | }; | |
655 | ||
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, | |
661 | #ifdef CONFIG_PM | |
662 | .resume = cmi9880_resume, | |
663 | #endif | |
664 | }; | |
665 | ||
666 | static int patch_cmi9880(struct hda_codec *codec) | |
667 | { | |
668 | struct cmi_spec *spec; | |
669 | ||
670 | spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); | |
671 | if (spec == NULL) | |
672 | return -ENOMEM; | |
673 | ||
674 | codec->spec = spec; | |
675 | spec->board_config = snd_hda_check_board_config(codec, cmi9880_cfg_tbl); | |
676 | if (spec->board_config < 0) { | |
f953eff2 TI |
677 | snd_printdd(KERN_INFO "hda_codec: Unknown model for CMI9880\n"); |
678 | spec->board_config = CMI_AUTO; /* try everything */ | |
1da177e4 LT |
679 | } |
680 | ||
f953eff2 TI |
681 | /* copy default DAC NIDs */ |
682 | memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids)); | |
e9edcee0 | 683 | spec->num_dacs = 4; |
f953eff2 | 684 | |
1da177e4 LT |
685 | switch (spec->board_config) { |
686 | case CMI_MINIMAL: | |
687 | case CMI_MIN_FP: | |
688 | spec->surr_switch = 1; | |
689 | if (spec->board_config == CMI_MINIMAL) | |
690 | spec->num_ch_modes = 2; | |
691 | else { | |
692 | spec->front_panel = 1; | |
693 | spec->num_ch_modes = 3; | |
694 | } | |
695 | spec->channel_modes = cmi9880_channel_modes; | |
696 | spec->multiout.max_channels = cmi9880_channel_modes[0].channels; | |
697 | spec->input_mux = &cmi9880_basic_mux; | |
698 | break; | |
699 | case CMI_FULL: | |
700 | case CMI_FULL_DIG: | |
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; | |
707 | } | |
708 | break; | |
709 | case CMI_ALLOUT: | |
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; | |
715 | break; | |
f953eff2 TI |
716 | case CMI_AUTO: |
717 | { | |
718 | unsigned int port_e, port_f, port_g, port_h; | |
719 | unsigned int port_spdifi, port_spdifo; | |
e9edcee0 TI |
720 | struct auto_pin_cfg cfg; |
721 | ||
f953eff2 | 722 | /* collect pin default configuration */ |
e9edcee0 TI |
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); | |
f953eff2 | 725 | spec->front_panel = 1; |
d21b37ea TI |
726 | if (get_defcfg_connect(port_e) == AC_JACK_PORT_NONE || |
727 | get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) { | |
e9edcee0 TI |
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); | |
f953eff2 TI |
730 | spec->surr_switch = 1; |
731 | /* no front panel */ | |
d21b37ea TI |
732 | if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE || |
733 | get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) { | |
f953eff2 TI |
734 | /* no optional rear panel */ |
735 | spec->board_config = CMI_MINIMAL; | |
736 | spec->front_panel = 0; | |
737 | spec->num_ch_modes = 2; | |
d21b37ea | 738 | } else { |
f953eff2 TI |
739 | spec->board_config = CMI_MIN_FP; |
740 | spec->num_ch_modes = 3; | |
d21b37ea | 741 | } |
f953eff2 TI |
742 | spec->channel_modes = cmi9880_channel_modes; |
743 | spec->input_mux = &cmi9880_basic_mux; | |
d21b37ea | 744 | spec->multiout.max_channels = cmi9880_channel_modes[0].channels; |
f953eff2 TI |
745 | } else { |
746 | spec->input_mux = &cmi9880_basic_mux; | |
e9edcee0 TI |
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); | |
d21b37ea | 749 | if (get_defcfg_connect(port_spdifo) != AC_JACK_PORT_NONE) |
f953eff2 | 750 | spec->multiout.dig_out_nid = CMI_DIG_OUT_NID; |
d21b37ea | 751 | if (get_defcfg_connect(port_spdifi) != AC_JACK_PORT_NONE) |
f953eff2 | 752 | spec->dig_in_nid = CMI_DIG_IN_NID; |
d21b37ea | 753 | spec->multiout.max_channels = 8; |
f953eff2 | 754 | } |
e9edcee0 TI |
755 | snd_hda_parse_pin_def_config(codec, &cfg); |
756 | if (cfg.line_outs) { | |
757 | spec->multiout.max_channels = cfg.line_outs * 2; | |
758 | cmi9880_fill_multi_dac_nids(codec, &cfg); | |
759 | cmi9880_fill_multi_init(codec, &cfg); | |
d21b37ea TI |
760 | } else |
761 | snd_printd("patch_cmedia: cannot detect association in defcfg\n"); | |
f953eff2 | 762 | break; |
d21b37ea | 763 | } |
1da177e4 LT |
764 | } |
765 | ||
e9edcee0 | 766 | spec->multiout.num_dacs = spec->num_dacs; |
f953eff2 | 767 | spec->multiout.dac_nids = spec->dac_nids; |
1da177e4 LT |
768 | |
769 | spec->adc_nids = cmi9880_adc_nids; | |
770 | ||
771 | codec->patch_ops = cmi9880_patch_ops; | |
772 | ||
773 | return 0; | |
774 | } | |
775 | ||
776 | /* | |
777 | * patch entries | |
778 | */ | |
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 }, | |
782 | {} /* terminator */ | |
783 | }; |