]>
Commit | Line | Data |
---|---|---|
2f2f4251 M |
1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
4 | * HD audio interface patch for SigmaTel STAC92xx | |
5 | * | |
6 | * Copyright (c) 2005 Embedded Alley Solutions, Inc. | |
403d1944 | 7 | * Matt Porter <mporter@embeddedalley.com> |
2f2f4251 M |
8 | * |
9 | * Based on patch_cmedia.c and patch_realtek.c | |
10 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> | |
11 | * | |
12 | * This driver is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This driver is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 | */ | |
26 | ||
27 | #include <sound/driver.h> | |
28 | #include <linux/init.h> | |
29 | #include <linux/delay.h> | |
30 | #include <linux/slab.h> | |
31 | #include <linux/pci.h> | |
32 | #include <sound/core.h> | |
c7d4b2fa | 33 | #include <sound/asoundef.h> |
2f2f4251 M |
34 | #include "hda_codec.h" |
35 | #include "hda_local.h" | |
36 | ||
4e55096e M |
37 | #define NUM_CONTROL_ALLOC 32 |
38 | #define STAC_HP_EVENT 0x37 | |
4e55096e | 39 | |
f5fcc13c TI |
40 | enum { |
41 | STAC_REF, | |
42 | STAC_9200_MODELS | |
43 | }; | |
44 | ||
45 | enum { | |
46 | STAC_9205_REF, | |
47 | STAC_9205_MODELS | |
48 | }; | |
49 | ||
8e21c34c TD |
50 | enum { |
51 | STAC_925x_REF, | |
52 | STAC_M2_2, | |
53 | STAC_MA6, | |
2c11f955 | 54 | STAC_PA6, |
8e21c34c TD |
55 | STAC_925x_MODELS |
56 | }; | |
57 | ||
f5fcc13c TI |
58 | enum { |
59 | STAC_D945_REF, | |
60 | STAC_D945GTP3, | |
61 | STAC_D945GTP5, | |
62 | STAC_MACMINI, | |
3fc24d85 | 63 | STAC_MACBOOK, |
6f0778d8 NB |
64 | STAC_MACBOOK_PRO_V1, |
65 | STAC_MACBOOK_PRO_V2, | |
f16928fb | 66 | STAC_IMAC_INTEL, |
0dae0f83 | 67 | STAC_IMAC_INTEL_20, |
f5fcc13c TI |
68 | STAC_922X_MODELS |
69 | }; | |
70 | ||
71 | enum { | |
72 | STAC_D965_REF, | |
73 | STAC_D965_3ST, | |
74 | STAC_D965_5ST, | |
75 | STAC_927X_MODELS | |
76 | }; | |
403d1944 | 77 | |
2f2f4251 | 78 | struct sigmatel_spec { |
c8b6bf9b | 79 | struct snd_kcontrol_new *mixers[4]; |
c7d4b2fa M |
80 | unsigned int num_mixers; |
81 | ||
403d1944 | 82 | int board_config; |
c7d4b2fa | 83 | unsigned int surr_switch: 1; |
403d1944 MP |
84 | unsigned int line_switch: 1; |
85 | unsigned int mic_switch: 1; | |
3cc08dc6 | 86 | unsigned int alt_switch: 1; |
82bc955f | 87 | unsigned int hp_detect: 1; |
62fe78e9 | 88 | unsigned int gpio_mute: 1; |
c7d4b2fa | 89 | |
2f2f4251 M |
90 | /* playback */ |
91 | struct hda_multi_out multiout; | |
3cc08dc6 | 92 | hda_nid_t dac_nids[5]; |
2f2f4251 M |
93 | |
94 | /* capture */ | |
95 | hda_nid_t *adc_nids; | |
2f2f4251 | 96 | unsigned int num_adcs; |
dabbed6f M |
97 | hda_nid_t *mux_nids; |
98 | unsigned int num_muxes; | |
8b65727b MP |
99 | hda_nid_t *dmic_nids; |
100 | unsigned int num_dmics; | |
101 | hda_nid_t dmux_nid; | |
dabbed6f | 102 | hda_nid_t dig_in_nid; |
2f2f4251 | 103 | |
2f2f4251 M |
104 | /* pin widgets */ |
105 | hda_nid_t *pin_nids; | |
106 | unsigned int num_pins; | |
2f2f4251 | 107 | unsigned int *pin_configs; |
11b44bbd | 108 | unsigned int *bios_pin_configs; |
2f2f4251 M |
109 | |
110 | /* codec specific stuff */ | |
111 | struct hda_verb *init; | |
c8b6bf9b | 112 | struct snd_kcontrol_new *mixer; |
2f2f4251 M |
113 | |
114 | /* capture source */ | |
8b65727b MP |
115 | struct hda_input_mux *dinput_mux; |
116 | unsigned int cur_dmux; | |
c7d4b2fa | 117 | struct hda_input_mux *input_mux; |
3cc08dc6 | 118 | unsigned int cur_mux[3]; |
2f2f4251 | 119 | |
403d1944 MP |
120 | /* i/o switches */ |
121 | unsigned int io_switch[2]; | |
2f2f4251 | 122 | |
c7d4b2fa M |
123 | struct hda_pcm pcm_rec[2]; /* PCM information */ |
124 | ||
125 | /* dynamic controls and input_mux */ | |
126 | struct auto_pin_cfg autocfg; | |
127 | unsigned int num_kctl_alloc, num_kctl_used; | |
c8b6bf9b | 128 | struct snd_kcontrol_new *kctl_alloc; |
8b65727b | 129 | struct hda_input_mux private_dimux; |
c7d4b2fa | 130 | struct hda_input_mux private_imux; |
2f2f4251 M |
131 | }; |
132 | ||
133 | static hda_nid_t stac9200_adc_nids[1] = { | |
134 | 0x03, | |
135 | }; | |
136 | ||
137 | static hda_nid_t stac9200_mux_nids[1] = { | |
138 | 0x0c, | |
139 | }; | |
140 | ||
141 | static hda_nid_t stac9200_dac_nids[1] = { | |
142 | 0x02, | |
143 | }; | |
144 | ||
8e21c34c TD |
145 | static hda_nid_t stac925x_adc_nids[1] = { |
146 | 0x03, | |
147 | }; | |
148 | ||
149 | static hda_nid_t stac925x_mux_nids[1] = { | |
150 | 0x0f, | |
151 | }; | |
152 | ||
153 | static hda_nid_t stac925x_dac_nids[1] = { | |
154 | 0x02, | |
155 | }; | |
156 | ||
2c11f955 TD |
157 | static hda_nid_t stac925x_dmic_nids[1] = { |
158 | 0x15, | |
159 | }; | |
160 | ||
2f2f4251 M |
161 | static hda_nid_t stac922x_adc_nids[2] = { |
162 | 0x06, 0x07, | |
163 | }; | |
164 | ||
165 | static hda_nid_t stac922x_mux_nids[2] = { | |
166 | 0x12, 0x13, | |
167 | }; | |
168 | ||
3cc08dc6 MP |
169 | static hda_nid_t stac927x_adc_nids[3] = { |
170 | 0x07, 0x08, 0x09 | |
171 | }; | |
172 | ||
173 | static hda_nid_t stac927x_mux_nids[3] = { | |
174 | 0x15, 0x16, 0x17 | |
175 | }; | |
176 | ||
f3302a59 MP |
177 | static hda_nid_t stac9205_adc_nids[2] = { |
178 | 0x12, 0x13 | |
179 | }; | |
180 | ||
181 | static hda_nid_t stac9205_mux_nids[2] = { | |
182 | 0x19, 0x1a | |
183 | }; | |
184 | ||
2549413e TI |
185 | static hda_nid_t stac9205_dmic_nids[2] = { |
186 | 0x17, 0x18, | |
8b65727b MP |
187 | }; |
188 | ||
c7d4b2fa | 189 | static hda_nid_t stac9200_pin_nids[8] = { |
93ed1503 TD |
190 | 0x08, 0x09, 0x0d, 0x0e, |
191 | 0x0f, 0x10, 0x11, 0x12, | |
2f2f4251 M |
192 | }; |
193 | ||
8e21c34c TD |
194 | static hda_nid_t stac925x_pin_nids[8] = { |
195 | 0x07, 0x08, 0x0a, 0x0b, | |
196 | 0x0c, 0x0d, 0x10, 0x11, | |
197 | }; | |
198 | ||
2f2f4251 M |
199 | static hda_nid_t stac922x_pin_nids[10] = { |
200 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, | |
201 | 0x0f, 0x10, 0x11, 0x15, 0x1b, | |
202 | }; | |
203 | ||
3cc08dc6 MP |
204 | static hda_nid_t stac927x_pin_nids[14] = { |
205 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, | |
206 | 0x0f, 0x10, 0x11, 0x12, 0x13, | |
207 | 0x14, 0x21, 0x22, 0x23, | |
208 | }; | |
209 | ||
f3302a59 MP |
210 | static hda_nid_t stac9205_pin_nids[12] = { |
211 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, | |
212 | 0x0f, 0x14, 0x16, 0x17, 0x18, | |
213 | 0x21, 0x22, | |
214 | ||
215 | }; | |
216 | ||
8b65727b MP |
217 | static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol, |
218 | struct snd_ctl_elem_info *uinfo) | |
219 | { | |
220 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
221 | struct sigmatel_spec *spec = codec->spec; | |
222 | return snd_hda_input_mux_info(spec->dinput_mux, uinfo); | |
223 | } | |
224 | ||
225 | static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol, | |
226 | struct snd_ctl_elem_value *ucontrol) | |
227 | { | |
228 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
229 | struct sigmatel_spec *spec = codec->spec; | |
230 | ||
231 | ucontrol->value.enumerated.item[0] = spec->cur_dmux; | |
232 | return 0; | |
233 | } | |
234 | ||
235 | static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol, | |
236 | struct snd_ctl_elem_value *ucontrol) | |
237 | { | |
238 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
239 | struct sigmatel_spec *spec = codec->spec; | |
240 | ||
241 | return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol, | |
242 | spec->dmux_nid, &spec->cur_dmux); | |
243 | } | |
244 | ||
c8b6bf9b | 245 | static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
2f2f4251 M |
246 | { |
247 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
248 | struct sigmatel_spec *spec = codec->spec; | |
c7d4b2fa | 249 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
2f2f4251 M |
250 | } |
251 | ||
c8b6bf9b | 252 | static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
2f2f4251 M |
253 | { |
254 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
255 | struct sigmatel_spec *spec = codec->spec; | |
256 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
257 | ||
258 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
259 | return 0; | |
260 | } | |
261 | ||
c8b6bf9b | 262 | static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
2f2f4251 M |
263 | { |
264 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
265 | struct sigmatel_spec *spec = codec->spec; | |
266 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
267 | ||
c7d4b2fa | 268 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
2f2f4251 M |
269 | spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]); |
270 | } | |
271 | ||
c7d4b2fa | 272 | static struct hda_verb stac9200_core_init[] = { |
2f2f4251 | 273 | /* set dac0mux for dac converter */ |
c7d4b2fa | 274 | { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00}, |
2f2f4251 M |
275 | {} |
276 | }; | |
277 | ||
8e21c34c TD |
278 | static struct hda_verb stac925x_core_init[] = { |
279 | /* set dac0mux for dac converter */ | |
280 | { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
281 | {} | |
282 | }; | |
283 | ||
c7d4b2fa | 284 | static struct hda_verb stac922x_core_init[] = { |
2f2f4251 | 285 | /* set master volume and direct control */ |
c7d4b2fa | 286 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
2f2f4251 M |
287 | {} |
288 | }; | |
289 | ||
93ed1503 | 290 | static struct hda_verb d965_core_init[] = { |
19039bd0 | 291 | /* set master volume and direct control */ |
93ed1503 | 292 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
19039bd0 TI |
293 | /* unmute node 0x1b */ |
294 | { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
295 | /* select node 0x03 as DAC */ | |
296 | { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01}, | |
297 | {} | |
298 | }; | |
299 | ||
3cc08dc6 MP |
300 | static struct hda_verb stac927x_core_init[] = { |
301 | /* set master volume and direct control */ | |
302 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, | |
303 | {} | |
304 | }; | |
305 | ||
f3302a59 MP |
306 | static struct hda_verb stac9205_core_init[] = { |
307 | /* set master volume and direct control */ | |
308 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, | |
309 | {} | |
310 | }; | |
311 | ||
c8b6bf9b | 312 | static struct snd_kcontrol_new stac9200_mixer[] = { |
2f2f4251 M |
313 | HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT), |
314 | HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT), | |
315 | { | |
316 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
317 | .name = "Input Source", | |
318 | .count = 1, | |
319 | .info = stac92xx_mux_enum_info, | |
320 | .get = stac92xx_mux_enum_get, | |
321 | .put = stac92xx_mux_enum_put, | |
322 | }, | |
323 | HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT), | |
324 | HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT), | |
c7d4b2fa | 325 | HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT), |
2f2f4251 M |
326 | { } /* end */ |
327 | }; | |
328 | ||
8e21c34c TD |
329 | static struct snd_kcontrol_new stac925x_mixer[] = { |
330 | HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT), | |
331 | HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT), | |
332 | { | |
333 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
334 | .name = "Input Source", | |
335 | .count = 1, | |
336 | .info = stac92xx_mux_enum_info, | |
337 | .get = stac92xx_mux_enum_get, | |
338 | .put = stac92xx_mux_enum_put, | |
339 | }, | |
340 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT), | |
341 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT), | |
342 | HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT), | |
343 | { } /* end */ | |
344 | }; | |
345 | ||
c7d4b2fa | 346 | /* This needs to be generated dynamically based on sequence */ |
c8b6bf9b | 347 | static struct snd_kcontrol_new stac922x_mixer[] = { |
2f2f4251 M |
348 | { |
349 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
350 | .name = "Input Source", | |
351 | .count = 1, | |
352 | .info = stac92xx_mux_enum_info, | |
353 | .get = stac92xx_mux_enum_get, | |
354 | .put = stac92xx_mux_enum_put, | |
355 | }, | |
356 | HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT), | |
0fd1708a | 357 | HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT), |
2f2f4251 M |
358 | HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT), |
359 | { } /* end */ | |
360 | }; | |
361 | ||
19039bd0 TI |
362 | /* This needs to be generated dynamically based on sequence */ |
363 | static struct snd_kcontrol_new stac9227_mixer[] = { | |
364 | { | |
365 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
366 | .name = "Input Source", | |
367 | .count = 1, | |
368 | .info = stac92xx_mux_enum_info, | |
369 | .get = stac92xx_mux_enum_get, | |
370 | .put = stac92xx_mux_enum_put, | |
371 | }, | |
372 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
373 | HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT), | |
374 | { } /* end */ | |
375 | }; | |
376 | ||
d1d985f0 | 377 | static struct snd_kcontrol_new stac927x_mixer[] = { |
3cc08dc6 MP |
378 | { |
379 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
380 | .name = "Input Source", | |
381 | .count = 1, | |
382 | .info = stac92xx_mux_enum_info, | |
383 | .get = stac92xx_mux_enum_get, | |
384 | .put = stac92xx_mux_enum_put, | |
385 | }, | |
386 | HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
387 | HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT), | |
388 | HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT), | |
389 | { } /* end */ | |
390 | }; | |
391 | ||
d1d985f0 | 392 | static struct snd_kcontrol_new stac9205_mixer[] = { |
8b65727b MP |
393 | { |
394 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
395 | .name = "Digital Input Source", | |
396 | .count = 1, | |
397 | .info = stac92xx_dmux_enum_info, | |
398 | .get = stac92xx_dmux_enum_get, | |
399 | .put = stac92xx_dmux_enum_put, | |
400 | }, | |
f3302a59 MP |
401 | { |
402 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
403 | .name = "Input Source", | |
404 | .count = 1, | |
405 | .info = stac92xx_mux_enum_info, | |
406 | .get = stac92xx_mux_enum_get, | |
407 | .put = stac92xx_mux_enum_put, | |
408 | }, | |
409 | HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT), | |
410 | HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT), | |
411 | HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT), | |
412 | { } /* end */ | |
413 | }; | |
414 | ||
2f2f4251 M |
415 | static int stac92xx_build_controls(struct hda_codec *codec) |
416 | { | |
417 | struct sigmatel_spec *spec = codec->spec; | |
418 | int err; | |
c7d4b2fa | 419 | int i; |
2f2f4251 M |
420 | |
421 | err = snd_hda_add_new_ctls(codec, spec->mixer); | |
422 | if (err < 0) | |
423 | return err; | |
c7d4b2fa M |
424 | |
425 | for (i = 0; i < spec->num_mixers; i++) { | |
426 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
427 | if (err < 0) | |
428 | return err; | |
429 | } | |
430 | ||
dabbed6f M |
431 | if (spec->multiout.dig_out_nid) { |
432 | err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); | |
433 | if (err < 0) | |
434 | return err; | |
435 | } | |
436 | if (spec->dig_in_nid) { | |
437 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
438 | if (err < 0) | |
439 | return err; | |
440 | } | |
441 | return 0; | |
2f2f4251 M |
442 | } |
443 | ||
403d1944 | 444 | static unsigned int ref9200_pin_configs[8] = { |
dabbed6f | 445 | 0x01c47010, 0x01447010, 0x0221401f, 0x01114010, |
2f2f4251 M |
446 | 0x02a19020, 0x01a19021, 0x90100140, 0x01813122, |
447 | }; | |
448 | ||
f5fcc13c TI |
449 | static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = { |
450 | [STAC_REF] = ref9200_pin_configs, | |
403d1944 MP |
451 | }; |
452 | ||
f5fcc13c TI |
453 | static const char *stac9200_models[STAC_9200_MODELS] = { |
454 | [STAC_REF] = "ref", | |
455 | }; | |
456 | ||
457 | static struct snd_pci_quirk stac9200_cfg_tbl[] = { | |
458 | /* SigmaTel reference board */ | |
459 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, | |
460 | "DFI LanParty", STAC_REF), | |
e7377071 | 461 | /* Dell laptops have BIOS problem */ |
f5fcc13c TI |
462 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5, |
463 | "Dell Inspiron 630m", STAC_REF), | |
464 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2, | |
465 | "Dell Latitude D620", STAC_REF), | |
466 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb, | |
467 | "Dell Latitude 120L", STAC_REF), | |
877b866d CT |
468 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc, |
469 | "Dell Latitude D820", STAC_REF), | |
46f02ca3 MN |
470 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd, |
471 | "Dell Inspiron E1705/9400", STAC_REF), | |
472 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce, | |
473 | "Dell XPS M1710", STAC_REF), | |
f0f96745 TI |
474 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf, |
475 | "Dell Precision M90", STAC_REF), | |
8286c53e DC |
476 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6, |
477 | "unknown Dell", STAC_REF), | |
49c605db TD |
478 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8, |
479 | "Dell Inspiron 640m", STAC_REF), | |
480 | SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5, | |
481 | "Dell Inspiron 1501", STAC_REF), | |
482 | ||
483 | /* Panasonic */ | |
484 | SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF), | |
485 | ||
403d1944 MP |
486 | {} /* terminator */ |
487 | }; | |
488 | ||
8e21c34c TD |
489 | static unsigned int ref925x_pin_configs[8] = { |
490 | 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021, | |
491 | 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e, | |
492 | }; | |
493 | ||
494 | static unsigned int stac925x_MA6_pin_configs[8] = { | |
495 | 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021, | |
496 | 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e, | |
497 | }; | |
498 | ||
2c11f955 TD |
499 | static unsigned int stac925x_PA6_pin_configs[8] = { |
500 | 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021, | |
501 | 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e, | |
502 | }; | |
503 | ||
8e21c34c | 504 | static unsigned int stac925xM2_2_pin_configs[8] = { |
7353e14d SL |
505 | 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020, |
506 | 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e, | |
8e21c34c TD |
507 | }; |
508 | ||
509 | static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = { | |
510 | [STAC_REF] = ref925x_pin_configs, | |
511 | [STAC_M2_2] = stac925xM2_2_pin_configs, | |
512 | [STAC_MA6] = stac925x_MA6_pin_configs, | |
2c11f955 | 513 | [STAC_PA6] = stac925x_PA6_pin_configs, |
8e21c34c TD |
514 | }; |
515 | ||
516 | static const char *stac925x_models[STAC_925x_MODELS] = { | |
517 | [STAC_REF] = "ref", | |
518 | [STAC_M2_2] = "m2-2", | |
519 | [STAC_MA6] = "m6", | |
2c11f955 | 520 | [STAC_PA6] = "pa6", |
8e21c34c TD |
521 | }; |
522 | ||
523 | static struct snd_pci_quirk stac925x_cfg_tbl[] = { | |
524 | /* SigmaTel reference board */ | |
525 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF), | |
2c11f955 | 526 | SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF), |
8e21c34c TD |
527 | SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF), |
528 | SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF), | |
529 | SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6), | |
2c11f955 | 530 | SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6), |
8e21c34c TD |
531 | SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2), |
532 | {} /* terminator */ | |
533 | }; | |
534 | ||
403d1944 MP |
535 | static unsigned int ref922x_pin_configs[10] = { |
536 | 0x01014010, 0x01016011, 0x01012012, 0x0221401f, | |
537 | 0x01813122, 0x01011014, 0x01441030, 0x01c41030, | |
2f2f4251 M |
538 | 0x40000100, 0x40000100, |
539 | }; | |
540 | ||
403d1944 | 541 | static unsigned int d945gtp3_pin_configs[10] = { |
869264c4 | 542 | 0x0221401f, 0x01a19022, 0x01813021, 0x01014010, |
403d1944 MP |
543 | 0x40000100, 0x40000100, 0x40000100, 0x40000100, |
544 | 0x02a19120, 0x40000100, | |
545 | }; | |
546 | ||
547 | static unsigned int d945gtp5_pin_configs[10] = { | |
869264c4 MP |
548 | 0x0221401f, 0x01011012, 0x01813024, 0x01014010, |
549 | 0x01a19021, 0x01016011, 0x01452130, 0x40000100, | |
403d1944 MP |
550 | 0x02a19320, 0x40000100, |
551 | }; | |
552 | ||
6f0778d8 NB |
553 | static unsigned int macbook_pro_v1_pin_configs[10] = { |
554 | 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010, | |
555 | 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e, | |
556 | 0x02a19320, 0x400000fb | |
557 | }; | |
558 | ||
559 | static unsigned int macbook_pro_v2_pin_configs[10] = { | |
3fc24d85 TI |
560 | 0x0221401f, 0x90a70120, 0x01813024, 0x01014010, |
561 | 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e, | |
562 | 0x400000fc, 0x400000fb, | |
563 | }; | |
564 | ||
f16928fb SF |
565 | static unsigned int imac_intel_pin_configs[10] = { |
566 | 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe, | |
567 | 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa, | |
568 | 0x400000fc, 0x400000fb, | |
569 | }; | |
570 | ||
0dae0f83 TI |
571 | static unsigned int imac_intel_20_pin_configs[10] = { |
572 | 0x0121E21F, 0x90A7012E, 0x9017E110, 0x400000FD, | |
573 | 0x400000FE, 0x0181E020, 0x1145E230, 0x11C5E240, | |
574 | 0x400000FC, 0x400000FB, | |
575 | }; | |
576 | ||
19039bd0 | 577 | static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = { |
f5fcc13c | 578 | [STAC_D945_REF] = ref922x_pin_configs, |
19039bd0 TI |
579 | [STAC_D945GTP3] = d945gtp3_pin_configs, |
580 | [STAC_D945GTP5] = d945gtp5_pin_configs, | |
02a5039f TI |
581 | [STAC_MACMINI] = macbook_pro_v1_pin_configs, |
582 | [STAC_MACBOOK] = macbook_pro_v1_pin_configs, | |
6f0778d8 NB |
583 | [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs, |
584 | [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs, | |
f16928fb | 585 | [STAC_IMAC_INTEL] = imac_intel_pin_configs, |
0dae0f83 | 586 | [STAC_IMAC_INTEL_20] = imac_intel_20_pin_configs, |
403d1944 MP |
587 | }; |
588 | ||
f5fcc13c TI |
589 | static const char *stac922x_models[STAC_922X_MODELS] = { |
590 | [STAC_D945_REF] = "ref", | |
591 | [STAC_D945GTP5] = "5stack", | |
592 | [STAC_D945GTP3] = "3stack", | |
593 | [STAC_MACMINI] = "macmini", | |
3fc24d85 | 594 | [STAC_MACBOOK] = "macbook", |
6f0778d8 NB |
595 | [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1", |
596 | [STAC_MACBOOK_PRO_V2] = "macbook-pro", | |
f16928fb | 597 | [STAC_IMAC_INTEL] = "imac-intel", |
0dae0f83 | 598 | [STAC_IMAC_INTEL_20] = "imac-intel-20", |
f5fcc13c TI |
599 | }; |
600 | ||
601 | static struct snd_pci_quirk stac922x_cfg_tbl[] = { | |
602 | /* SigmaTel reference board */ | |
603 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, | |
604 | "DFI LanParty", STAC_D945_REF), | |
605 | /* Intel 945G based systems */ | |
606 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101, | |
607 | "Intel D945G", STAC_D945GTP3), | |
608 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202, | |
609 | "Intel D945G", STAC_D945GTP3), | |
610 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606, | |
611 | "Intel D945G", STAC_D945GTP3), | |
612 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601, | |
613 | "Intel D945G", STAC_D945GTP3), | |
614 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111, | |
615 | "Intel D945G", STAC_D945GTP3), | |
616 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115, | |
617 | "Intel D945G", STAC_D945GTP3), | |
618 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116, | |
619 | "Intel D945G", STAC_D945GTP3), | |
620 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117, | |
621 | "Intel D945G", STAC_D945GTP3), | |
622 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118, | |
623 | "Intel D945G", STAC_D945GTP3), | |
624 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119, | |
625 | "Intel D945G", STAC_D945GTP3), | |
626 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826, | |
627 | "Intel D945G", STAC_D945GTP3), | |
628 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049, | |
629 | "Intel D945G", STAC_D945GTP3), | |
630 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055, | |
631 | "Intel D945G", STAC_D945GTP3), | |
632 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048, | |
633 | "Intel D945G", STAC_D945GTP3), | |
634 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110, | |
635 | "Intel D945G", STAC_D945GTP3), | |
636 | /* Intel D945G 5-stack systems */ | |
637 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404, | |
638 | "Intel D945G", STAC_D945GTP5), | |
639 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303, | |
640 | "Intel D945G", STAC_D945GTP5), | |
641 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013, | |
642 | "Intel D945G", STAC_D945GTP5), | |
643 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417, | |
644 | "Intel D945G", STAC_D945GTP5), | |
645 | /* Intel 945P based systems */ | |
646 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b, | |
647 | "Intel D945P", STAC_D945GTP3), | |
648 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112, | |
649 | "Intel D945P", STAC_D945GTP3), | |
650 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d, | |
651 | "Intel D945P", STAC_D945GTP3), | |
652 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909, | |
653 | "Intel D945P", STAC_D945GTP3), | |
654 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505, | |
655 | "Intel D945P", STAC_D945GTP3), | |
656 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707, | |
657 | "Intel D945P", STAC_D945GTP5), | |
658 | /* other systems */ | |
659 | /* Apple Mac Mini (early 2006) */ | |
660 | SND_PCI_QUIRK(0x8384, 0x7680, | |
661 | "Mac Mini", STAC_MACMINI), | |
403d1944 MP |
662 | {} /* terminator */ |
663 | }; | |
664 | ||
3cc08dc6 | 665 | static unsigned int ref927x_pin_configs[14] = { |
93ed1503 TD |
666 | 0x02214020, 0x02a19080, 0x0181304e, 0x01014010, |
667 | 0x01a19040, 0x01011012, 0x01016011, 0x0101201f, | |
668 | 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070, | |
669 | 0x01c42190, 0x40000100, | |
3cc08dc6 MP |
670 | }; |
671 | ||
93ed1503 | 672 | static unsigned int d965_3st_pin_configs[14] = { |
81d3dbde TD |
673 | 0x0221401f, 0x02a19120, 0x40000100, 0x01014011, |
674 | 0x01a19021, 0x01813024, 0x40000100, 0x40000100, | |
675 | 0x40000100, 0x40000100, 0x40000100, 0x40000100, | |
676 | 0x40000100, 0x40000100 | |
677 | }; | |
678 | ||
93ed1503 TD |
679 | static unsigned int d965_5st_pin_configs[14] = { |
680 | 0x02214020, 0x02a19080, 0x0181304e, 0x01014010, | |
681 | 0x01a19040, 0x01011012, 0x01016011, 0x40000100, | |
682 | 0x40000100, 0x40000100, 0x40000100, 0x01442070, | |
683 | 0x40000100, 0x40000100 | |
684 | }; | |
685 | ||
686 | static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = { | |
f5fcc13c | 687 | [STAC_D965_REF] = ref927x_pin_configs, |
93ed1503 TD |
688 | [STAC_D965_3ST] = d965_3st_pin_configs, |
689 | [STAC_D965_5ST] = d965_5st_pin_configs, | |
3cc08dc6 MP |
690 | }; |
691 | ||
f5fcc13c TI |
692 | static const char *stac927x_models[STAC_927X_MODELS] = { |
693 | [STAC_D965_REF] = "ref", | |
694 | [STAC_D965_3ST] = "3stack", | |
695 | [STAC_D965_5ST] = "5stack", | |
696 | }; | |
697 | ||
698 | static struct snd_pci_quirk stac927x_cfg_tbl[] = { | |
699 | /* SigmaTel reference board */ | |
700 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, | |
701 | "DFI LanParty", STAC_D965_REF), | |
81d3dbde | 702 | /* Intel 946 based systems */ |
f5fcc13c TI |
703 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST), |
704 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST), | |
93ed1503 | 705 | /* 965 based 3 stack systems */ |
f5fcc13c TI |
706 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST), |
707 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST), | |
708 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST), | |
709 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST), | |
710 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST), | |
711 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST), | |
712 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST), | |
713 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST), | |
714 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST), | |
715 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST), | |
716 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST), | |
717 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST), | |
718 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST), | |
719 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST), | |
720 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST), | |
721 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST), | |
93ed1503 | 722 | /* 965 based 5 stack systems */ |
f5fcc13c TI |
723 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST), |
724 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST), | |
725 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST), | |
726 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST), | |
727 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST), | |
728 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST), | |
729 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST), | |
730 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST), | |
731 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST), | |
3cc08dc6 MP |
732 | {} /* terminator */ |
733 | }; | |
734 | ||
f3302a59 MP |
735 | static unsigned int ref9205_pin_configs[12] = { |
736 | 0x40000100, 0x40000100, 0x01016011, 0x01014010, | |
8b65727b MP |
737 | 0x01813122, 0x01a19021, 0x40000100, 0x40000100, |
738 | 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030 | |
f3302a59 MP |
739 | }; |
740 | ||
f5fcc13c | 741 | static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = { |
f3302a59 MP |
742 | ref9205_pin_configs, |
743 | }; | |
744 | ||
f5fcc13c TI |
745 | static const char *stac9205_models[STAC_9205_MODELS] = { |
746 | [STAC_9205_REF] = "ref", | |
747 | }; | |
748 | ||
749 | static struct snd_pci_quirk stac9205_cfg_tbl[] = { | |
750 | /* SigmaTel reference board */ | |
751 | SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, | |
752 | "DFI LanParty", STAC_9205_REF), | |
f3302a59 MP |
753 | {} /* terminator */ |
754 | }; | |
755 | ||
11b44bbd RF |
756 | static int stac92xx_save_bios_config_regs(struct hda_codec *codec) |
757 | { | |
758 | int i; | |
759 | struct sigmatel_spec *spec = codec->spec; | |
760 | ||
761 | if (! spec->bios_pin_configs) { | |
762 | spec->bios_pin_configs = kcalloc(spec->num_pins, | |
763 | sizeof(*spec->bios_pin_configs), GFP_KERNEL); | |
764 | if (! spec->bios_pin_configs) | |
765 | return -ENOMEM; | |
766 | } | |
767 | ||
768 | for (i = 0; i < spec->num_pins; i++) { | |
769 | hda_nid_t nid = spec->pin_nids[i]; | |
770 | unsigned int pin_cfg; | |
771 | ||
772 | pin_cfg = snd_hda_codec_read(codec, nid, 0, | |
773 | AC_VERB_GET_CONFIG_DEFAULT, 0x00); | |
774 | snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n", | |
775 | nid, pin_cfg); | |
776 | spec->bios_pin_configs[i] = pin_cfg; | |
777 | } | |
778 | ||
779 | return 0; | |
780 | } | |
781 | ||
2f2f4251 M |
782 | static void stac92xx_set_config_regs(struct hda_codec *codec) |
783 | { | |
784 | int i; | |
785 | struct sigmatel_spec *spec = codec->spec; | |
786 | unsigned int pin_cfg; | |
787 | ||
11b44bbd RF |
788 | if (! spec->pin_nids || ! spec->pin_configs) |
789 | return; | |
790 | ||
791 | for (i = 0; i < spec->num_pins; i++) { | |
2f2f4251 M |
792 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, |
793 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_0, | |
794 | spec->pin_configs[i] & 0x000000ff); | |
795 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, | |
796 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, | |
797 | (spec->pin_configs[i] & 0x0000ff00) >> 8); | |
798 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, | |
799 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, | |
800 | (spec->pin_configs[i] & 0x00ff0000) >> 16); | |
801 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, | |
802 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, | |
803 | spec->pin_configs[i] >> 24); | |
804 | pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0, | |
805 | AC_VERB_GET_CONFIG_DEFAULT, | |
806 | 0x00); | |
403d1944 | 807 | snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg); |
2f2f4251 M |
808 | } |
809 | } | |
2f2f4251 | 810 | |
dabbed6f | 811 | /* |
c7d4b2fa | 812 | * Analog playback callbacks |
dabbed6f | 813 | */ |
c7d4b2fa M |
814 | static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo, |
815 | struct hda_codec *codec, | |
c8b6bf9b | 816 | struct snd_pcm_substream *substream) |
2f2f4251 | 817 | { |
dabbed6f | 818 | struct sigmatel_spec *spec = codec->spec; |
c7d4b2fa | 819 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); |
2f2f4251 M |
820 | } |
821 | ||
2f2f4251 M |
822 | static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
823 | struct hda_codec *codec, | |
824 | unsigned int stream_tag, | |
825 | unsigned int format, | |
c8b6bf9b | 826 | struct snd_pcm_substream *substream) |
2f2f4251 M |
827 | { |
828 | struct sigmatel_spec *spec = codec->spec; | |
403d1944 | 829 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream); |
2f2f4251 M |
830 | } |
831 | ||
832 | static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
833 | struct hda_codec *codec, | |
c8b6bf9b | 834 | struct snd_pcm_substream *substream) |
2f2f4251 M |
835 | { |
836 | struct sigmatel_spec *spec = codec->spec; | |
837 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
838 | } | |
839 | ||
dabbed6f M |
840 | /* |
841 | * Digital playback callbacks | |
842 | */ | |
843 | static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
844 | struct hda_codec *codec, | |
c8b6bf9b | 845 | struct snd_pcm_substream *substream) |
dabbed6f M |
846 | { |
847 | struct sigmatel_spec *spec = codec->spec; | |
848 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
849 | } | |
850 | ||
851 | static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
852 | struct hda_codec *codec, | |
c8b6bf9b | 853 | struct snd_pcm_substream *substream) |
dabbed6f M |
854 | { |
855 | struct sigmatel_spec *spec = codec->spec; | |
856 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
857 | } | |
858 | ||
6b97eb45 TI |
859 | static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
860 | struct hda_codec *codec, | |
861 | unsigned int stream_tag, | |
862 | unsigned int format, | |
863 | struct snd_pcm_substream *substream) | |
864 | { | |
865 | struct sigmatel_spec *spec = codec->spec; | |
866 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, | |
867 | stream_tag, format, substream); | |
868 | } | |
869 | ||
dabbed6f | 870 | |
2f2f4251 M |
871 | /* |
872 | * Analog capture callbacks | |
873 | */ | |
874 | static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
875 | struct hda_codec *codec, | |
876 | unsigned int stream_tag, | |
877 | unsigned int format, | |
c8b6bf9b | 878 | struct snd_pcm_substream *substream) |
2f2f4251 M |
879 | { |
880 | struct sigmatel_spec *spec = codec->spec; | |
881 | ||
882 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
883 | stream_tag, 0, format); | |
884 | return 0; | |
885 | } | |
886 | ||
887 | static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
888 | struct hda_codec *codec, | |
c8b6bf9b | 889 | struct snd_pcm_substream *substream) |
2f2f4251 M |
890 | { |
891 | struct sigmatel_spec *spec = codec->spec; | |
892 | ||
893 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); | |
894 | return 0; | |
895 | } | |
896 | ||
dabbed6f M |
897 | static struct hda_pcm_stream stac92xx_pcm_digital_playback = { |
898 | .substreams = 1, | |
899 | .channels_min = 2, | |
900 | .channels_max = 2, | |
901 | /* NID is set in stac92xx_build_pcms */ | |
902 | .ops = { | |
903 | .open = stac92xx_dig_playback_pcm_open, | |
6b97eb45 TI |
904 | .close = stac92xx_dig_playback_pcm_close, |
905 | .prepare = stac92xx_dig_playback_pcm_prepare | |
dabbed6f M |
906 | }, |
907 | }; | |
908 | ||
909 | static struct hda_pcm_stream stac92xx_pcm_digital_capture = { | |
910 | .substreams = 1, | |
911 | .channels_min = 2, | |
912 | .channels_max = 2, | |
913 | /* NID is set in stac92xx_build_pcms */ | |
914 | }; | |
915 | ||
2f2f4251 M |
916 | static struct hda_pcm_stream stac92xx_pcm_analog_playback = { |
917 | .substreams = 1, | |
918 | .channels_min = 2, | |
c7d4b2fa | 919 | .channels_max = 8, |
2f2f4251 M |
920 | .nid = 0x02, /* NID to query formats and rates */ |
921 | .ops = { | |
922 | .open = stac92xx_playback_pcm_open, | |
923 | .prepare = stac92xx_playback_pcm_prepare, | |
924 | .cleanup = stac92xx_playback_pcm_cleanup | |
925 | }, | |
926 | }; | |
927 | ||
3cc08dc6 MP |
928 | static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = { |
929 | .substreams = 1, | |
930 | .channels_min = 2, | |
931 | .channels_max = 2, | |
932 | .nid = 0x06, /* NID to query formats and rates */ | |
933 | .ops = { | |
934 | .open = stac92xx_playback_pcm_open, | |
935 | .prepare = stac92xx_playback_pcm_prepare, | |
936 | .cleanup = stac92xx_playback_pcm_cleanup | |
937 | }, | |
938 | }; | |
939 | ||
2f2f4251 M |
940 | static struct hda_pcm_stream stac92xx_pcm_analog_capture = { |
941 | .substreams = 2, | |
942 | .channels_min = 2, | |
943 | .channels_max = 2, | |
3cc08dc6 | 944 | /* NID is set in stac92xx_build_pcms */ |
2f2f4251 M |
945 | .ops = { |
946 | .prepare = stac92xx_capture_pcm_prepare, | |
947 | .cleanup = stac92xx_capture_pcm_cleanup | |
948 | }, | |
949 | }; | |
950 | ||
951 | static int stac92xx_build_pcms(struct hda_codec *codec) | |
952 | { | |
953 | struct sigmatel_spec *spec = codec->spec; | |
954 | struct hda_pcm *info = spec->pcm_rec; | |
955 | ||
956 | codec->num_pcms = 1; | |
957 | codec->pcm_info = info; | |
958 | ||
c7d4b2fa | 959 | info->name = "STAC92xx Analog"; |
2f2f4251 | 960 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback; |
2f2f4251 | 961 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture; |
3cc08dc6 MP |
962 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
963 | ||
964 | if (spec->alt_switch) { | |
965 | codec->num_pcms++; | |
966 | info++; | |
967 | info->name = "STAC92xx Analog Alt"; | |
968 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback; | |
969 | } | |
2f2f4251 | 970 | |
dabbed6f M |
971 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
972 | codec->num_pcms++; | |
973 | info++; | |
974 | info->name = "STAC92xx Digital"; | |
975 | if (spec->multiout.dig_out_nid) { | |
976 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; | |
977 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | |
978 | } | |
979 | if (spec->dig_in_nid) { | |
980 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture; | |
981 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; | |
982 | } | |
983 | } | |
984 | ||
2f2f4251 M |
985 | return 0; |
986 | } | |
987 | ||
c960a03b TI |
988 | static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid) |
989 | { | |
990 | unsigned int pincap = snd_hda_param_read(codec, nid, | |
991 | AC_PAR_PIN_CAP); | |
992 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; | |
993 | if (pincap & AC_PINCAP_VREF_100) | |
994 | return AC_PINCTL_VREF_100; | |
995 | if (pincap & AC_PINCAP_VREF_80) | |
996 | return AC_PINCTL_VREF_80; | |
997 | if (pincap & AC_PINCAP_VREF_50) | |
998 | return AC_PINCTL_VREF_50; | |
999 | if (pincap & AC_PINCAP_VREF_GRD) | |
1000 | return AC_PINCTL_VREF_GRD; | |
1001 | return 0; | |
1002 | } | |
1003 | ||
403d1944 MP |
1004 | static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) |
1005 | ||
1006 | { | |
1007 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); | |
1008 | } | |
1009 | ||
1010 | static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | |
1011 | { | |
1012 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
1013 | uinfo->count = 1; | |
1014 | uinfo->value.integer.min = 0; | |
1015 | uinfo->value.integer.max = 1; | |
1016 | return 0; | |
1017 | } | |
1018 | ||
1019 | static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
1020 | { | |
1021 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1022 | struct sigmatel_spec *spec = codec->spec; | |
1023 | int io_idx = kcontrol-> private_value & 0xff; | |
1024 | ||
1025 | ucontrol->value.integer.value[0] = spec->io_switch[io_idx]; | |
1026 | return 0; | |
1027 | } | |
1028 | ||
1029 | static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
1030 | { | |
1031 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1032 | struct sigmatel_spec *spec = codec->spec; | |
1033 | hda_nid_t nid = kcontrol->private_value >> 8; | |
1034 | int io_idx = kcontrol-> private_value & 0xff; | |
1035 | unsigned short val = ucontrol->value.integer.value[0]; | |
1036 | ||
1037 | spec->io_switch[io_idx] = val; | |
1038 | ||
1039 | if (val) | |
1040 | stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); | |
c960a03b TI |
1041 | else { |
1042 | unsigned int pinctl = AC_PINCTL_IN_EN; | |
1043 | if (io_idx) /* set VREF for mic */ | |
1044 | pinctl |= stac92xx_get_vref(codec, nid); | |
1045 | stac92xx_auto_set_pinctl(codec, nid, pinctl); | |
1046 | } | |
403d1944 MP |
1047 | return 1; |
1048 | } | |
1049 | ||
1050 | #define STAC_CODEC_IO_SWITCH(xname, xpval) \ | |
1051 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
1052 | .name = xname, \ | |
1053 | .index = 0, \ | |
1054 | .info = stac92xx_io_switch_info, \ | |
1055 | .get = stac92xx_io_switch_get, \ | |
1056 | .put = stac92xx_io_switch_put, \ | |
1057 | .private_value = xpval, \ | |
1058 | } | |
1059 | ||
1060 | ||
c7d4b2fa M |
1061 | enum { |
1062 | STAC_CTL_WIDGET_VOL, | |
1063 | STAC_CTL_WIDGET_MUTE, | |
403d1944 | 1064 | STAC_CTL_WIDGET_IO_SWITCH, |
c7d4b2fa M |
1065 | }; |
1066 | ||
c8b6bf9b | 1067 | static struct snd_kcontrol_new stac92xx_control_templates[] = { |
c7d4b2fa M |
1068 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
1069 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
403d1944 | 1070 | STAC_CODEC_IO_SWITCH(NULL, 0), |
c7d4b2fa M |
1071 | }; |
1072 | ||
1073 | /* add dynamic controls */ | |
1074 | static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val) | |
1075 | { | |
c8b6bf9b | 1076 | struct snd_kcontrol_new *knew; |
c7d4b2fa M |
1077 | |
1078 | if (spec->num_kctl_used >= spec->num_kctl_alloc) { | |
1079 | int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; | |
1080 | ||
1081 | knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */ | |
1082 | if (! knew) | |
1083 | return -ENOMEM; | |
1084 | if (spec->kctl_alloc) { | |
1085 | memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc); | |
1086 | kfree(spec->kctl_alloc); | |
1087 | } | |
1088 | spec->kctl_alloc = knew; | |
1089 | spec->num_kctl_alloc = num; | |
1090 | } | |
1091 | ||
1092 | knew = &spec->kctl_alloc[spec->num_kctl_used]; | |
1093 | *knew = stac92xx_control_templates[type]; | |
82fe0c58 | 1094 | knew->name = kstrdup(name, GFP_KERNEL); |
c7d4b2fa M |
1095 | if (! knew->name) |
1096 | return -ENOMEM; | |
1097 | knew->private_value = val; | |
1098 | spec->num_kctl_used++; | |
1099 | return 0; | |
1100 | } | |
1101 | ||
403d1944 MP |
1102 | /* flag inputs as additional dynamic lineouts */ |
1103 | static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg) | |
1104 | { | |
1105 | struct sigmatel_spec *spec = codec->spec; | |
7b043899 SL |
1106 | unsigned int wcaps, wtype; |
1107 | int i, num_dacs = 0; | |
1108 | ||
1109 | /* use the wcaps cache to count all DACs available for line-outs */ | |
1110 | for (i = 0; i < codec->num_nodes; i++) { | |
1111 | wcaps = codec->wcaps[i]; | |
1112 | wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; | |
1113 | if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) | |
1114 | num_dacs++; | |
1115 | } | |
403d1944 | 1116 | |
7b043899 SL |
1117 | snd_printdd("%s: total dac count=%d\n", __func__, num_dacs); |
1118 | ||
403d1944 MP |
1119 | switch (cfg->line_outs) { |
1120 | case 3: | |
1121 | /* add line-in as side */ | |
7b043899 | 1122 | if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) { |
403d1944 MP |
1123 | cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE]; |
1124 | spec->line_switch = 1; | |
1125 | cfg->line_outs++; | |
1126 | } | |
1127 | break; | |
1128 | case 2: | |
1129 | /* add line-in as clfe and mic as side */ | |
7b043899 | 1130 | if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) { |
403d1944 MP |
1131 | cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE]; |
1132 | spec->line_switch = 1; | |
1133 | cfg->line_outs++; | |
1134 | } | |
7b043899 | 1135 | if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) { |
403d1944 MP |
1136 | cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC]; |
1137 | spec->mic_switch = 1; | |
1138 | cfg->line_outs++; | |
1139 | } | |
1140 | break; | |
1141 | case 1: | |
1142 | /* add line-in as surr and mic as clfe */ | |
7b043899 | 1143 | if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) { |
403d1944 MP |
1144 | cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE]; |
1145 | spec->line_switch = 1; | |
1146 | cfg->line_outs++; | |
1147 | } | |
7b043899 | 1148 | if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) { |
403d1944 MP |
1149 | cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC]; |
1150 | spec->mic_switch = 1; | |
1151 | cfg->line_outs++; | |
1152 | } | |
1153 | break; | |
1154 | } | |
1155 | ||
1156 | return 0; | |
1157 | } | |
1158 | ||
7b043899 SL |
1159 | |
1160 | static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid) | |
1161 | { | |
1162 | int i; | |
1163 | ||
1164 | for (i = 0; i < spec->multiout.num_dacs; i++) { | |
1165 | if (spec->multiout.dac_nids[i] == nid) | |
1166 | return 1; | |
1167 | } | |
1168 | ||
1169 | return 0; | |
1170 | } | |
1171 | ||
3cc08dc6 | 1172 | /* |
7b043899 SL |
1173 | * Fill in the dac_nids table from the parsed pin configuration |
1174 | * This function only works when every pin in line_out_pins[] | |
1175 | * contains atleast one DAC in its connection list. Some 92xx | |
1176 | * codecs are not connected directly to a DAC, such as the 9200 | |
1177 | * and 9202/925x. For those, dac_nids[] must be hard-coded. | |
3cc08dc6 | 1178 | */ |
19039bd0 TI |
1179 | static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, |
1180 | const struct auto_pin_cfg *cfg) | |
c7d4b2fa M |
1181 | { |
1182 | struct sigmatel_spec *spec = codec->spec; | |
7b043899 SL |
1183 | int i, j, conn_len = 0; |
1184 | hda_nid_t nid, conn[HDA_MAX_CONNECTIONS]; | |
1185 | unsigned int wcaps, wtype; | |
1186 | ||
c7d4b2fa M |
1187 | for (i = 0; i < cfg->line_outs; i++) { |
1188 | nid = cfg->line_out_pins[i]; | |
7b043899 SL |
1189 | conn_len = snd_hda_get_connections(codec, nid, conn, |
1190 | HDA_MAX_CONNECTIONS); | |
1191 | for (j = 0; j < conn_len; j++) { | |
1192 | wcaps = snd_hda_param_read(codec, conn[j], | |
1193 | AC_PAR_AUDIO_WIDGET_CAP); | |
1194 | wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; | |
1195 | ||
1196 | if (wtype != AC_WID_AUD_OUT || | |
1197 | (wcaps & AC_WCAP_DIGITAL)) | |
1198 | continue; | |
1199 | /* conn[j] is a DAC routed to this line-out */ | |
1200 | if (!is_in_dac_nids(spec, conn[j])) | |
1201 | break; | |
1202 | } | |
1203 | ||
1204 | if (j == conn_len) { | |
1205 | /* error out, no available DAC found */ | |
1206 | snd_printk(KERN_ERR | |
1207 | "%s: No available DAC for pin 0x%x\n", | |
1208 | __func__, nid); | |
1209 | return -ENODEV; | |
1210 | } | |
1211 | ||
1212 | spec->multiout.dac_nids[i] = conn[j]; | |
1213 | spec->multiout.num_dacs++; | |
1214 | if (conn_len > 1) { | |
1215 | /* select this DAC in the pin's input mux */ | |
1216 | snd_hda_codec_write(codec, nid, 0, | |
1217 | AC_VERB_SET_CONNECT_SEL, j); | |
c7d4b2fa | 1218 | |
7b043899 SL |
1219 | } |
1220 | } | |
c7d4b2fa | 1221 | |
7b043899 SL |
1222 | snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", |
1223 | spec->multiout.num_dacs, | |
1224 | spec->multiout.dac_nids[0], | |
1225 | spec->multiout.dac_nids[1], | |
1226 | spec->multiout.dac_nids[2], | |
1227 | spec->multiout.dac_nids[3], | |
1228 | spec->multiout.dac_nids[4]); | |
c7d4b2fa M |
1229 | return 0; |
1230 | } | |
1231 | ||
eb06ed8f TI |
1232 | /* create volume control/switch for the given prefx type */ |
1233 | static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs) | |
1234 | { | |
1235 | char name[32]; | |
1236 | int err; | |
1237 | ||
1238 | sprintf(name, "%s Playback Volume", pfx); | |
1239 | err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name, | |
1240 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); | |
1241 | if (err < 0) | |
1242 | return err; | |
1243 | sprintf(name, "%s Playback Switch", pfx); | |
1244 | err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name, | |
1245 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); | |
1246 | if (err < 0) | |
1247 | return err; | |
1248 | return 0; | |
1249 | } | |
1250 | ||
c7d4b2fa | 1251 | /* add playback controls from the parsed DAC table */ |
19039bd0 TI |
1252 | static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, |
1253 | const struct auto_pin_cfg *cfg) | |
c7d4b2fa | 1254 | { |
19039bd0 TI |
1255 | static const char *chname[4] = { |
1256 | "Front", "Surround", NULL /*CLFE*/, "Side" | |
1257 | }; | |
c7d4b2fa M |
1258 | hda_nid_t nid; |
1259 | int i, err; | |
1260 | ||
1261 | for (i = 0; i < cfg->line_outs; i++) { | |
403d1944 | 1262 | if (!spec->multiout.dac_nids[i]) |
c7d4b2fa M |
1263 | continue; |
1264 | ||
1265 | nid = spec->multiout.dac_nids[i]; | |
1266 | ||
1267 | if (i == 2) { | |
1268 | /* Center/LFE */ | |
eb06ed8f TI |
1269 | err = create_controls(spec, "Center", nid, 1); |
1270 | if (err < 0) | |
c7d4b2fa | 1271 | return err; |
eb06ed8f TI |
1272 | err = create_controls(spec, "LFE", nid, 2); |
1273 | if (err < 0) | |
c7d4b2fa M |
1274 | return err; |
1275 | } else { | |
eb06ed8f TI |
1276 | err = create_controls(spec, chname[i], nid, 3); |
1277 | if (err < 0) | |
c7d4b2fa M |
1278 | return err; |
1279 | } | |
1280 | } | |
1281 | ||
403d1944 MP |
1282 | if (spec->line_switch) |
1283 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0) | |
1284 | return err; | |
1285 | ||
1286 | if (spec->mic_switch) | |
1287 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0) | |
1288 | return err; | |
1289 | ||
c7d4b2fa M |
1290 | return 0; |
1291 | } | |
1292 | ||
eb06ed8f | 1293 | static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid) |
c7d4b2fa | 1294 | { |
7b043899 SL |
1295 | if (is_in_dac_nids(spec, nid)) |
1296 | return 1; | |
eb06ed8f TI |
1297 | if (spec->multiout.hp_nid == nid) |
1298 | return 1; | |
1299 | return 0; | |
1300 | } | |
c7d4b2fa | 1301 | |
eb06ed8f TI |
1302 | static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid) |
1303 | { | |
1304 | if (!spec->multiout.hp_nid) | |
1305 | spec->multiout.hp_nid = nid; | |
1306 | else if (spec->multiout.num_dacs > 4) { | |
1307 | printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid); | |
1308 | return 1; | |
1309 | } else { | |
1310 | spec->multiout.dac_nids[spec->multiout.num_dacs] = nid; | |
1311 | spec->multiout.num_dacs++; | |
1312 | } | |
1313 | return 0; | |
1314 | } | |
4e55096e | 1315 | |
eb06ed8f TI |
1316 | /* add playback controls for Speaker and HP outputs */ |
1317 | static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, | |
1318 | struct auto_pin_cfg *cfg) | |
1319 | { | |
1320 | struct sigmatel_spec *spec = codec->spec; | |
1321 | hda_nid_t nid; | |
1322 | int i, old_num_dacs, err; | |
1323 | ||
1324 | old_num_dacs = spec->multiout.num_dacs; | |
1325 | for (i = 0; i < cfg->hp_outs; i++) { | |
1326 | unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]); | |
1327 | if (wid_caps & AC_WCAP_UNSOL_CAP) | |
1328 | spec->hp_detect = 1; | |
1329 | nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0, | |
1330 | AC_VERB_GET_CONNECT_LIST, 0) & 0xff; | |
1331 | if (check_in_dac_nids(spec, nid)) | |
1332 | nid = 0; | |
1333 | if (! nid) | |
c7d4b2fa | 1334 | continue; |
eb06ed8f TI |
1335 | add_spec_dacs(spec, nid); |
1336 | } | |
1337 | for (i = 0; i < cfg->speaker_outs; i++) { | |
7b043899 | 1338 | nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0, |
eb06ed8f TI |
1339 | AC_VERB_GET_CONNECT_LIST, 0) & 0xff; |
1340 | if (check_in_dac_nids(spec, nid)) | |
1341 | nid = 0; | |
eb06ed8f TI |
1342 | if (! nid) |
1343 | continue; | |
1344 | add_spec_dacs(spec, nid); | |
c7d4b2fa M |
1345 | } |
1346 | ||
eb06ed8f TI |
1347 | for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) { |
1348 | static const char *pfxs[] = { | |
1349 | "Speaker", "External Speaker", "Speaker2", | |
1350 | }; | |
1351 | err = create_controls(spec, pfxs[i - old_num_dacs], | |
1352 | spec->multiout.dac_nids[i], 3); | |
1353 | if (err < 0) | |
1354 | return err; | |
1355 | } | |
1356 | if (spec->multiout.hp_nid) { | |
1357 | const char *pfx; | |
1358 | if (old_num_dacs == spec->multiout.num_dacs) | |
1359 | pfx = "Master"; | |
1360 | else | |
1361 | pfx = "Headphone"; | |
1362 | err = create_controls(spec, pfx, spec->multiout.hp_nid, 3); | |
1363 | if (err < 0) | |
1364 | return err; | |
1365 | } | |
c7d4b2fa M |
1366 | |
1367 | return 0; | |
1368 | } | |
1369 | ||
8b65727b | 1370 | /* labels for dmic mux inputs */ |
ddc2cec4 | 1371 | static const char *stac92xx_dmic_labels[5] = { |
8b65727b MP |
1372 | "Analog Inputs", "Digital Mic 1", "Digital Mic 2", |
1373 | "Digital Mic 3", "Digital Mic 4" | |
1374 | }; | |
1375 | ||
1376 | /* create playback/capture controls for input pins on dmic capable codecs */ | |
1377 | static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec, | |
1378 | const struct auto_pin_cfg *cfg) | |
1379 | { | |
1380 | struct sigmatel_spec *spec = codec->spec; | |
1381 | struct hda_input_mux *dimux = &spec->private_dimux; | |
1382 | hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; | |
1383 | int i, j; | |
1384 | ||
1385 | dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0]; | |
1386 | dimux->items[dimux->num_items].index = 0; | |
1387 | dimux->num_items++; | |
1388 | ||
1389 | for (i = 0; i < spec->num_dmics; i++) { | |
1390 | int index; | |
1391 | int num_cons; | |
1392 | unsigned int def_conf; | |
1393 | ||
1394 | def_conf = snd_hda_codec_read(codec, | |
1395 | spec->dmic_nids[i], | |
1396 | 0, | |
1397 | AC_VERB_GET_CONFIG_DEFAULT, | |
1398 | 0); | |
1399 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) | |
1400 | continue; | |
1401 | ||
1402 | num_cons = snd_hda_get_connections(codec, | |
1403 | spec->dmux_nid, | |
1404 | con_lst, | |
1405 | HDA_MAX_NUM_INPUTS); | |
1406 | for (j = 0; j < num_cons; j++) | |
1407 | if (con_lst[j] == spec->dmic_nids[i]) { | |
1408 | index = j; | |
1409 | goto found; | |
1410 | } | |
1411 | continue; | |
1412 | found: | |
1413 | dimux->items[dimux->num_items].label = | |
1414 | stac92xx_dmic_labels[dimux->num_items]; | |
1415 | dimux->items[dimux->num_items].index = index; | |
1416 | dimux->num_items++; | |
1417 | } | |
1418 | ||
1419 | return 0; | |
1420 | } | |
1421 | ||
c7d4b2fa M |
1422 | /* create playback/capture controls for input pins */ |
1423 | static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) | |
1424 | { | |
1425 | struct sigmatel_spec *spec = codec->spec; | |
c7d4b2fa M |
1426 | struct hda_input_mux *imux = &spec->private_imux; |
1427 | hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; | |
1428 | int i, j, k; | |
1429 | ||
1430 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
314634bc TI |
1431 | int index; |
1432 | ||
1433 | if (!cfg->input_pins[i]) | |
1434 | continue; | |
1435 | index = -1; | |
1436 | for (j = 0; j < spec->num_muxes; j++) { | |
1437 | int num_cons; | |
1438 | num_cons = snd_hda_get_connections(codec, | |
1439 | spec->mux_nids[j], | |
1440 | con_lst, | |
1441 | HDA_MAX_NUM_INPUTS); | |
1442 | for (k = 0; k < num_cons; k++) | |
1443 | if (con_lst[k] == cfg->input_pins[i]) { | |
1444 | index = k; | |
1445 | goto found; | |
1446 | } | |
c7d4b2fa | 1447 | } |
314634bc TI |
1448 | continue; |
1449 | found: | |
1450 | imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; | |
1451 | imux->items[imux->num_items].index = index; | |
1452 | imux->num_items++; | |
c7d4b2fa M |
1453 | } |
1454 | ||
7b043899 | 1455 | if (imux->num_items) { |
62fe78e9 SR |
1456 | /* |
1457 | * Set the current input for the muxes. | |
1458 | * The STAC9221 has two input muxes with identical source | |
1459 | * NID lists. Hopefully this won't get confused. | |
1460 | */ | |
1461 | for (i = 0; i < spec->num_muxes; i++) { | |
1462 | snd_hda_codec_write(codec, spec->mux_nids[i], 0, | |
1463 | AC_VERB_SET_CONNECT_SEL, | |
1464 | imux->items[0].index); | |
1465 | } | |
1466 | } | |
1467 | ||
c7d4b2fa M |
1468 | return 0; |
1469 | } | |
1470 | ||
c7d4b2fa M |
1471 | static void stac92xx_auto_init_multi_out(struct hda_codec *codec) |
1472 | { | |
1473 | struct sigmatel_spec *spec = codec->spec; | |
1474 | int i; | |
1475 | ||
1476 | for (i = 0; i < spec->autocfg.line_outs; i++) { | |
1477 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
1478 | stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); | |
1479 | } | |
1480 | } | |
1481 | ||
1482 | static void stac92xx_auto_init_hp_out(struct hda_codec *codec) | |
1483 | { | |
1484 | struct sigmatel_spec *spec = codec->spec; | |
eb06ed8f | 1485 | int i; |
c7d4b2fa | 1486 | |
eb06ed8f TI |
1487 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
1488 | hda_nid_t pin; | |
1489 | pin = spec->autocfg.hp_pins[i]; | |
1490 | if (pin) /* connect to front */ | |
1491 | stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); | |
1492 | } | |
1493 | for (i = 0; i < spec->autocfg.speaker_outs; i++) { | |
1494 | hda_nid_t pin; | |
1495 | pin = spec->autocfg.speaker_pins[i]; | |
1496 | if (pin) /* connect to front */ | |
1497 | stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN); | |
1498 | } | |
c7d4b2fa M |
1499 | } |
1500 | ||
3cc08dc6 | 1501 | static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) |
c7d4b2fa M |
1502 | { |
1503 | struct sigmatel_spec *spec = codec->spec; | |
1504 | int err; | |
1505 | ||
8b65727b MP |
1506 | if ((err = snd_hda_parse_pin_def_config(codec, |
1507 | &spec->autocfg, | |
1508 | spec->dmic_nids)) < 0) | |
c7d4b2fa | 1509 | return err; |
82bc955f | 1510 | if (! spec->autocfg.line_outs) |
869264c4 | 1511 | return 0; /* can't find valid pin config */ |
19039bd0 | 1512 | |
403d1944 MP |
1513 | if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0) |
1514 | return err; | |
19039bd0 TI |
1515 | if (spec->multiout.num_dacs == 0) |
1516 | if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0) | |
1517 | return err; | |
c7d4b2fa M |
1518 | |
1519 | if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 || | |
1520 | (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 || | |
1521 | (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0) | |
1522 | return err; | |
1523 | ||
8b65727b MP |
1524 | if (spec->num_dmics > 0) |
1525 | if ((err = stac92xx_auto_create_dmic_input_ctls(codec, | |
1526 | &spec->autocfg)) < 0) | |
1527 | return err; | |
1528 | ||
c7d4b2fa | 1529 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
403d1944 | 1530 | if (spec->multiout.max_channels > 2) |
c7d4b2fa | 1531 | spec->surr_switch = 1; |
c7d4b2fa | 1532 | |
82bc955f | 1533 | if (spec->autocfg.dig_out_pin) |
3cc08dc6 | 1534 | spec->multiout.dig_out_nid = dig_out; |
82bc955f | 1535 | if (spec->autocfg.dig_in_pin) |
3cc08dc6 | 1536 | spec->dig_in_nid = dig_in; |
c7d4b2fa M |
1537 | |
1538 | if (spec->kctl_alloc) | |
1539 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; | |
1540 | ||
1541 | spec->input_mux = &spec->private_imux; | |
8b65727b | 1542 | spec->dinput_mux = &spec->private_dimux; |
c7d4b2fa M |
1543 | |
1544 | return 1; | |
1545 | } | |
1546 | ||
82bc955f TI |
1547 | /* add playback controls for HP output */ |
1548 | static int stac9200_auto_create_hp_ctls(struct hda_codec *codec, | |
1549 | struct auto_pin_cfg *cfg) | |
1550 | { | |
1551 | struct sigmatel_spec *spec = codec->spec; | |
eb06ed8f | 1552 | hda_nid_t pin = cfg->hp_pins[0]; |
82bc955f TI |
1553 | unsigned int wid_caps; |
1554 | ||
1555 | if (! pin) | |
1556 | return 0; | |
1557 | ||
1558 | wid_caps = get_wcaps(codec, pin); | |
505cb341 | 1559 | if (wid_caps & AC_WCAP_UNSOL_CAP) |
82bc955f | 1560 | spec->hp_detect = 1; |
82bc955f TI |
1561 | |
1562 | return 0; | |
1563 | } | |
1564 | ||
160ea0dc RF |
1565 | /* add playback controls for LFE output */ |
1566 | static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec, | |
1567 | struct auto_pin_cfg *cfg) | |
1568 | { | |
1569 | struct sigmatel_spec *spec = codec->spec; | |
1570 | int err; | |
1571 | hda_nid_t lfe_pin = 0x0; | |
1572 | int i; | |
1573 | ||
1574 | /* | |
1575 | * search speaker outs and line outs for a mono speaker pin | |
1576 | * with an amp. If one is found, add LFE controls | |
1577 | * for it. | |
1578 | */ | |
1579 | for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) { | |
1580 | hda_nid_t pin = spec->autocfg.speaker_pins[i]; | |
1581 | unsigned long wcaps = get_wcaps(codec, pin); | |
1582 | wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); | |
1583 | if (wcaps == AC_WCAP_OUT_AMP) | |
1584 | /* found a mono speaker with an amp, must be lfe */ | |
1585 | lfe_pin = pin; | |
1586 | } | |
1587 | ||
1588 | /* if speaker_outs is 0, then speakers may be in line_outs */ | |
1589 | if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) { | |
1590 | for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) { | |
1591 | hda_nid_t pin = spec->autocfg.line_out_pins[i]; | |
1592 | unsigned long cfg; | |
1593 | cfg = snd_hda_codec_read(codec, pin, 0, | |
1594 | AC_VERB_GET_CONFIG_DEFAULT, | |
1595 | 0x00); | |
1596 | if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) { | |
1597 | unsigned long wcaps = get_wcaps(codec, pin); | |
1598 | wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); | |
1599 | if (wcaps == AC_WCAP_OUT_AMP) | |
1600 | /* found a mono speaker with an amp, | |
1601 | must be lfe */ | |
1602 | lfe_pin = pin; | |
1603 | } | |
1604 | } | |
1605 | } | |
1606 | ||
1607 | if (lfe_pin) { | |
eb06ed8f | 1608 | err = create_controls(spec, "LFE", lfe_pin, 1); |
160ea0dc RF |
1609 | if (err < 0) |
1610 | return err; | |
1611 | } | |
1612 | ||
1613 | return 0; | |
1614 | } | |
1615 | ||
c7d4b2fa M |
1616 | static int stac9200_parse_auto_config(struct hda_codec *codec) |
1617 | { | |
1618 | struct sigmatel_spec *spec = codec->spec; | |
1619 | int err; | |
1620 | ||
df694daa | 1621 | if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) |
c7d4b2fa M |
1622 | return err; |
1623 | ||
1624 | if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0) | |
1625 | return err; | |
1626 | ||
82bc955f TI |
1627 | if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0) |
1628 | return err; | |
1629 | ||
160ea0dc RF |
1630 | if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0) |
1631 | return err; | |
1632 | ||
82bc955f | 1633 | if (spec->autocfg.dig_out_pin) |
c7d4b2fa | 1634 | spec->multiout.dig_out_nid = 0x05; |
82bc955f | 1635 | if (spec->autocfg.dig_in_pin) |
c7d4b2fa | 1636 | spec->dig_in_nid = 0x04; |
c7d4b2fa M |
1637 | |
1638 | if (spec->kctl_alloc) | |
1639 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; | |
1640 | ||
1641 | spec->input_mux = &spec->private_imux; | |
8b65727b | 1642 | spec->dinput_mux = &spec->private_dimux; |
c7d4b2fa M |
1643 | |
1644 | return 1; | |
1645 | } | |
1646 | ||
62fe78e9 SR |
1647 | /* |
1648 | * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a | |
1649 | * funky external mute control using GPIO pins. | |
1650 | */ | |
1651 | ||
1652 | static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted) | |
1653 | { | |
1654 | unsigned int gpiostate, gpiomask, gpiodir; | |
1655 | ||
1656 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, | |
1657 | AC_VERB_GET_GPIO_DATA, 0); | |
1658 | ||
1659 | if (!muted) | |
1660 | gpiostate |= (1 << pin); | |
1661 | else | |
1662 | gpiostate &= ~(1 << pin); | |
1663 | ||
1664 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, | |
1665 | AC_VERB_GET_GPIO_MASK, 0); | |
1666 | gpiomask |= (1 << pin); | |
1667 | ||
1668 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, | |
1669 | AC_VERB_GET_GPIO_DIRECTION, 0); | |
1670 | gpiodir |= (1 << pin); | |
1671 | ||
1672 | /* AppleHDA seems to do this -- WTF is this verb?? */ | |
1673 | snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); | |
1674 | ||
1675 | snd_hda_codec_write(codec, codec->afg, 0, | |
1676 | AC_VERB_SET_GPIO_MASK, gpiomask); | |
1677 | snd_hda_codec_write(codec, codec->afg, 0, | |
1678 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); | |
1679 | ||
1680 | msleep(1); | |
1681 | ||
1682 | snd_hda_codec_write(codec, codec->afg, 0, | |
1683 | AC_VERB_SET_GPIO_DATA, gpiostate); | |
1684 | } | |
1685 | ||
314634bc TI |
1686 | static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, |
1687 | unsigned int event) | |
1688 | { | |
1689 | if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) | |
1690 | snd_hda_codec_write(codec, nid, 0, | |
1691 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
1692 | (AC_USRSP_EN | event)); | |
1693 | } | |
1694 | ||
c7d4b2fa M |
1695 | static int stac92xx_init(struct hda_codec *codec) |
1696 | { | |
1697 | struct sigmatel_spec *spec = codec->spec; | |
82bc955f TI |
1698 | struct auto_pin_cfg *cfg = &spec->autocfg; |
1699 | int i; | |
c7d4b2fa | 1700 | |
c7d4b2fa M |
1701 | snd_hda_sequence_write(codec, spec->init); |
1702 | ||
82bc955f TI |
1703 | /* set up pins */ |
1704 | if (spec->hp_detect) { | |
505cb341 | 1705 | /* Enable unsolicited responses on the HP widget */ |
eb06ed8f | 1706 | for (i = 0; i < cfg->hp_outs; i++) |
314634bc TI |
1707 | enable_pin_detect(codec, cfg->hp_pins[i], |
1708 | STAC_HP_EVENT); | |
0a07acaf TI |
1709 | /* force to enable the first line-out; the others are set up |
1710 | * in unsol_event | |
1711 | */ | |
1712 | stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0], | |
1713 | AC_PINCTL_OUT_EN); | |
eb995a8c | 1714 | stac92xx_auto_init_hp_out(codec); |
82bc955f TI |
1715 | /* fake event to set up pins */ |
1716 | codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); | |
1717 | } else { | |
1718 | stac92xx_auto_init_multi_out(codec); | |
1719 | stac92xx_auto_init_hp_out(codec); | |
1720 | } | |
1721 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
c960a03b TI |
1722 | hda_nid_t nid = cfg->input_pins[i]; |
1723 | if (nid) { | |
1724 | unsigned int pinctl = AC_PINCTL_IN_EN; | |
1725 | if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) | |
1726 | pinctl |= stac92xx_get_vref(codec, nid); | |
1727 | stac92xx_auto_set_pinctl(codec, nid, pinctl); | |
1728 | } | |
82bc955f | 1729 | } |
8b65727b MP |
1730 | if (spec->num_dmics > 0) |
1731 | for (i = 0; i < spec->num_dmics; i++) | |
1732 | stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i], | |
1733 | AC_PINCTL_IN_EN); | |
1734 | ||
82bc955f TI |
1735 | if (cfg->dig_out_pin) |
1736 | stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, | |
1737 | AC_PINCTL_OUT_EN); | |
1738 | if (cfg->dig_in_pin) | |
1739 | stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin, | |
1740 | AC_PINCTL_IN_EN); | |
1741 | ||
62fe78e9 SR |
1742 | if (spec->gpio_mute) { |
1743 | stac922x_gpio_mute(codec, 0, 0); | |
1744 | stac922x_gpio_mute(codec, 1, 0); | |
1745 | } | |
1746 | ||
c7d4b2fa M |
1747 | return 0; |
1748 | } | |
1749 | ||
2f2f4251 M |
1750 | static void stac92xx_free(struct hda_codec *codec) |
1751 | { | |
c7d4b2fa M |
1752 | struct sigmatel_spec *spec = codec->spec; |
1753 | int i; | |
1754 | ||
1755 | if (! spec) | |
1756 | return; | |
1757 | ||
1758 | if (spec->kctl_alloc) { | |
1759 | for (i = 0; i < spec->num_kctl_used; i++) | |
1760 | kfree(spec->kctl_alloc[i].name); | |
1761 | kfree(spec->kctl_alloc); | |
1762 | } | |
1763 | ||
11b44bbd RF |
1764 | if (spec->bios_pin_configs) |
1765 | kfree(spec->bios_pin_configs); | |
1766 | ||
c7d4b2fa | 1767 | kfree(spec); |
2f2f4251 M |
1768 | } |
1769 | ||
4e55096e M |
1770 | static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, |
1771 | unsigned int flag) | |
1772 | { | |
1773 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, | |
1774 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); | |
7b043899 | 1775 | |
f9acba43 TI |
1776 | if (pin_ctl & AC_PINCTL_IN_EN) { |
1777 | /* | |
1778 | * we need to check the current set-up direction of | |
1779 | * shared input pins since they can be switched via | |
1780 | * "xxx as Output" mixer switch | |
1781 | */ | |
1782 | struct sigmatel_spec *spec = codec->spec; | |
1783 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
1784 | if ((nid == cfg->input_pins[AUTO_PIN_LINE] && | |
1785 | spec->line_switch) || | |
1786 | (nid == cfg->input_pins[AUTO_PIN_MIC] && | |
1787 | spec->mic_switch)) | |
1788 | return; | |
1789 | } | |
1790 | ||
7b043899 SL |
1791 | /* if setting pin direction bits, clear the current |
1792 | direction bits first */ | |
1793 | if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)) | |
1794 | pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); | |
1795 | ||
4e55096e M |
1796 | snd_hda_codec_write(codec, nid, 0, |
1797 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1798 | pin_ctl | flag); | |
1799 | } | |
1800 | ||
1801 | static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, | |
1802 | unsigned int flag) | |
1803 | { | |
1804 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, | |
1805 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); | |
1806 | snd_hda_codec_write(codec, nid, 0, | |
1807 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1808 | pin_ctl & ~flag); | |
1809 | } | |
1810 | ||
314634bc TI |
1811 | static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) |
1812 | { | |
1813 | if (!nid) | |
1814 | return 0; | |
1815 | if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00) | |
1816 | & (1 << 31)) | |
1817 | return 1; | |
1818 | return 0; | |
1819 | } | |
1820 | ||
1821 | static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res) | |
4e55096e M |
1822 | { |
1823 | struct sigmatel_spec *spec = codec->spec; | |
1824 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
1825 | int i, presence; | |
1826 | ||
eb06ed8f TI |
1827 | presence = 0; |
1828 | for (i = 0; i < cfg->hp_outs; i++) { | |
314634bc TI |
1829 | presence = get_pin_presence(codec, cfg->hp_pins[i]); |
1830 | if (presence) | |
1831 | break; | |
eb06ed8f | 1832 | } |
4e55096e M |
1833 | |
1834 | if (presence) { | |
1835 | /* disable lineouts, enable hp */ | |
1836 | for (i = 0; i < cfg->line_outs; i++) | |
1837 | stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], | |
1838 | AC_PINCTL_OUT_EN); | |
eb06ed8f TI |
1839 | for (i = 0; i < cfg->speaker_outs; i++) |
1840 | stac92xx_reset_pinctl(codec, cfg->speaker_pins[i], | |
1841 | AC_PINCTL_OUT_EN); | |
4e55096e M |
1842 | } else { |
1843 | /* enable lineouts, disable hp */ | |
1844 | for (i = 0; i < cfg->line_outs; i++) | |
1845 | stac92xx_set_pinctl(codec, cfg->line_out_pins[i], | |
1846 | AC_PINCTL_OUT_EN); | |
eb06ed8f TI |
1847 | for (i = 0; i < cfg->speaker_outs; i++) |
1848 | stac92xx_set_pinctl(codec, cfg->speaker_pins[i], | |
1849 | AC_PINCTL_OUT_EN); | |
4e55096e M |
1850 | } |
1851 | } | |
1852 | ||
314634bc TI |
1853 | static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res) |
1854 | { | |
1855 | switch (res >> 26) { | |
1856 | case STAC_HP_EVENT: | |
1857 | stac92xx_hp_detect(codec, res); | |
1858 | break; | |
1859 | } | |
1860 | } | |
1861 | ||
ff6fdc37 M |
1862 | #ifdef CONFIG_PM |
1863 | static int stac92xx_resume(struct hda_codec *codec) | |
1864 | { | |
1865 | struct sigmatel_spec *spec = codec->spec; | |
1866 | int i; | |
1867 | ||
1868 | stac92xx_init(codec); | |
11b44bbd | 1869 | stac92xx_set_config_regs(codec); |
5d403b19 | 1870 | snd_hda_resume_ctls(codec, spec->mixer); |
ff6fdc37 M |
1871 | for (i = 0; i < spec->num_mixers; i++) |
1872 | snd_hda_resume_ctls(codec, spec->mixers[i]); | |
1873 | if (spec->multiout.dig_out_nid) | |
1874 | snd_hda_resume_spdif_out(codec); | |
1875 | if (spec->dig_in_nid) | |
1876 | snd_hda_resume_spdif_in(codec); | |
1877 | ||
1878 | return 0; | |
1879 | } | |
1880 | #endif | |
1881 | ||
2f2f4251 M |
1882 | static struct hda_codec_ops stac92xx_patch_ops = { |
1883 | .build_controls = stac92xx_build_controls, | |
1884 | .build_pcms = stac92xx_build_pcms, | |
1885 | .init = stac92xx_init, | |
1886 | .free = stac92xx_free, | |
4e55096e | 1887 | .unsol_event = stac92xx_unsol_event, |
ff6fdc37 M |
1888 | #ifdef CONFIG_PM |
1889 | .resume = stac92xx_resume, | |
1890 | #endif | |
2f2f4251 M |
1891 | }; |
1892 | ||
1893 | static int patch_stac9200(struct hda_codec *codec) | |
1894 | { | |
1895 | struct sigmatel_spec *spec; | |
c7d4b2fa | 1896 | int err; |
2f2f4251 | 1897 | |
e560d8d8 | 1898 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
2f2f4251 M |
1899 | if (spec == NULL) |
1900 | return -ENOMEM; | |
1901 | ||
1902 | codec->spec = spec; | |
11b44bbd RF |
1903 | spec->num_pins = 8; |
1904 | spec->pin_nids = stac9200_pin_nids; | |
f5fcc13c TI |
1905 | spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS, |
1906 | stac9200_models, | |
1907 | stac9200_cfg_tbl); | |
11b44bbd RF |
1908 | if (spec->board_config < 0) { |
1909 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); | |
1910 | err = stac92xx_save_bios_config_regs(codec); | |
1911 | if (err < 0) { | |
1912 | stac92xx_free(codec); | |
1913 | return err; | |
1914 | } | |
1915 | spec->pin_configs = spec->bios_pin_configs; | |
1916 | } else { | |
403d1944 MP |
1917 | spec->pin_configs = stac9200_brd_tbl[spec->board_config]; |
1918 | stac92xx_set_config_regs(codec); | |
1919 | } | |
2f2f4251 M |
1920 | |
1921 | spec->multiout.max_channels = 2; | |
1922 | spec->multiout.num_dacs = 1; | |
1923 | spec->multiout.dac_nids = stac9200_dac_nids; | |
1924 | spec->adc_nids = stac9200_adc_nids; | |
1925 | spec->mux_nids = stac9200_mux_nids; | |
dabbed6f | 1926 | spec->num_muxes = 1; |
8b65727b | 1927 | spec->num_dmics = 0; |
c7d4b2fa M |
1928 | |
1929 | spec->init = stac9200_core_init; | |
2f2f4251 | 1930 | spec->mixer = stac9200_mixer; |
c7d4b2fa M |
1931 | |
1932 | err = stac9200_parse_auto_config(codec); | |
1933 | if (err < 0) { | |
1934 | stac92xx_free(codec); | |
1935 | return err; | |
1936 | } | |
2f2f4251 M |
1937 | |
1938 | codec->patch_ops = stac92xx_patch_ops; | |
1939 | ||
1940 | return 0; | |
1941 | } | |
1942 | ||
8e21c34c TD |
1943 | static int patch_stac925x(struct hda_codec *codec) |
1944 | { | |
1945 | struct sigmatel_spec *spec; | |
1946 | int err; | |
1947 | ||
1948 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1949 | if (spec == NULL) | |
1950 | return -ENOMEM; | |
1951 | ||
1952 | codec->spec = spec; | |
1953 | spec->num_pins = 8; | |
1954 | spec->pin_nids = stac925x_pin_nids; | |
1955 | spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS, | |
1956 | stac925x_models, | |
1957 | stac925x_cfg_tbl); | |
9e507abd | 1958 | again: |
8e21c34c | 1959 | if (spec->board_config < 0) { |
2c11f955 TD |
1960 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x," |
1961 | "using BIOS defaults\n"); | |
8e21c34c TD |
1962 | err = stac92xx_save_bios_config_regs(codec); |
1963 | if (err < 0) { | |
1964 | stac92xx_free(codec); | |
1965 | return err; | |
1966 | } | |
1967 | spec->pin_configs = spec->bios_pin_configs; | |
1968 | } else if (stac925x_brd_tbl[spec->board_config] != NULL){ | |
1969 | spec->pin_configs = stac925x_brd_tbl[spec->board_config]; | |
1970 | stac92xx_set_config_regs(codec); | |
1971 | } | |
1972 | ||
1973 | spec->multiout.max_channels = 2; | |
1974 | spec->multiout.num_dacs = 1; | |
1975 | spec->multiout.dac_nids = stac925x_dac_nids; | |
1976 | spec->adc_nids = stac925x_adc_nids; | |
1977 | spec->mux_nids = stac925x_mux_nids; | |
1978 | spec->num_muxes = 1; | |
2c11f955 TD |
1979 | switch (codec->vendor_id) { |
1980 | case 0x83847632: /* STAC9202 */ | |
1981 | case 0x83847633: /* STAC9202D */ | |
1982 | case 0x83847636: /* STAC9251 */ | |
1983 | case 0x83847637: /* STAC9251D */ | |
1984 | spec->num_dmics = 1; | |
1985 | spec->dmic_nids = stac925x_dmic_nids; | |
1986 | break; | |
1987 | default: | |
1988 | spec->num_dmics = 0; | |
1989 | break; | |
1990 | } | |
8e21c34c TD |
1991 | |
1992 | spec->init = stac925x_core_init; | |
1993 | spec->mixer = stac925x_mixer; | |
1994 | ||
1995 | err = stac92xx_parse_auto_config(codec, 0x8, 0x7); | |
9e507abd TI |
1996 | if (!err) { |
1997 | if (spec->board_config < 0) { | |
1998 | printk(KERN_WARNING "hda_codec: No auto-config is " | |
1999 | "available, default to model=ref\n"); | |
2000 | spec->board_config = STAC_925x_REF; | |
2001 | goto again; | |
2002 | } | |
2003 | err = -EINVAL; | |
2004 | } | |
8e21c34c TD |
2005 | if (err < 0) { |
2006 | stac92xx_free(codec); | |
2007 | return err; | |
2008 | } | |
2009 | ||
2010 | codec->patch_ops = stac92xx_patch_ops; | |
2011 | ||
2012 | return 0; | |
2013 | } | |
2014 | ||
2f2f4251 M |
2015 | static int patch_stac922x(struct hda_codec *codec) |
2016 | { | |
2017 | struct sigmatel_spec *spec; | |
c7d4b2fa | 2018 | int err; |
2f2f4251 | 2019 | |
e560d8d8 | 2020 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
2f2f4251 M |
2021 | if (spec == NULL) |
2022 | return -ENOMEM; | |
2023 | ||
2024 | codec->spec = spec; | |
11b44bbd RF |
2025 | spec->num_pins = 10; |
2026 | spec->pin_nids = stac922x_pin_nids; | |
f5fcc13c TI |
2027 | spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS, |
2028 | stac922x_models, | |
2029 | stac922x_cfg_tbl); | |
3fc24d85 TI |
2030 | if (spec->board_config == STAC_MACMINI) { |
2031 | spec->gpio_mute = 1; | |
2032 | /* Intel Macs have all same PCI SSID, so we need to check | |
2033 | * codec SSID to distinguish the exact models | |
2034 | */ | |
6f0778d8 | 2035 | printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id); |
3fc24d85 | 2036 | switch (codec->subsystem_id) { |
c45e20eb AB |
2037 | case 0x106b0a00: /* MacBook First generatoin */ |
2038 | spec->board_config = STAC_MACBOOK; | |
2039 | break; | |
6f0778d8 NB |
2040 | case 0x106b0200: /* MacBook Pro first generation */ |
2041 | spec->board_config = STAC_MACBOOK_PRO_V1; | |
2042 | break; | |
2043 | case 0x106b1e00: /* MacBook Pro second generation */ | |
2044 | spec->board_config = STAC_MACBOOK_PRO_V2; | |
3fc24d85 | 2045 | break; |
f16928fb SF |
2046 | case 0x106b0700: /* Intel-based iMac */ |
2047 | spec->board_config = STAC_IMAC_INTEL; | |
2048 | break; | |
0dae0f83 TI |
2049 | case 0x106b1700: /* Intel iMac 20 */ |
2050 | spec->board_config = STAC_IMAC_INTEL_20; | |
2051 | break; | |
3fc24d85 TI |
2052 | } |
2053 | } | |
2054 | ||
9e507abd | 2055 | again: |
11b44bbd RF |
2056 | if (spec->board_config < 0) { |
2057 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " | |
2058 | "using BIOS defaults\n"); | |
2059 | err = stac92xx_save_bios_config_regs(codec); | |
2060 | if (err < 0) { | |
2061 | stac92xx_free(codec); | |
2062 | return err; | |
2063 | } | |
2064 | spec->pin_configs = spec->bios_pin_configs; | |
2065 | } else if (stac922x_brd_tbl[spec->board_config] != NULL) { | |
403d1944 MP |
2066 | spec->pin_configs = stac922x_brd_tbl[spec->board_config]; |
2067 | stac92xx_set_config_regs(codec); | |
2068 | } | |
2f2f4251 | 2069 | |
c7d4b2fa M |
2070 | spec->adc_nids = stac922x_adc_nids; |
2071 | spec->mux_nids = stac922x_mux_nids; | |
2549413e | 2072 | spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids); |
8b65727b | 2073 | spec->num_dmics = 0; |
c7d4b2fa M |
2074 | |
2075 | spec->init = stac922x_core_init; | |
2f2f4251 | 2076 | spec->mixer = stac922x_mixer; |
c7d4b2fa M |
2077 | |
2078 | spec->multiout.dac_nids = spec->dac_nids; | |
19039bd0 | 2079 | |
3cc08dc6 | 2080 | err = stac92xx_parse_auto_config(codec, 0x08, 0x09); |
9e507abd TI |
2081 | if (!err) { |
2082 | if (spec->board_config < 0) { | |
2083 | printk(KERN_WARNING "hda_codec: No auto-config is " | |
2084 | "available, default to model=ref\n"); | |
2085 | spec->board_config = STAC_D945_REF; | |
2086 | goto again; | |
2087 | } | |
2088 | err = -EINVAL; | |
2089 | } | |
3cc08dc6 MP |
2090 | if (err < 0) { |
2091 | stac92xx_free(codec); | |
2092 | return err; | |
2093 | } | |
2094 | ||
2095 | codec->patch_ops = stac92xx_patch_ops; | |
2096 | ||
2097 | return 0; | |
2098 | } | |
2099 | ||
2100 | static int patch_stac927x(struct hda_codec *codec) | |
2101 | { | |
2102 | struct sigmatel_spec *spec; | |
2103 | int err; | |
2104 | ||
2105 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
2106 | if (spec == NULL) | |
2107 | return -ENOMEM; | |
2108 | ||
2109 | codec->spec = spec; | |
11b44bbd RF |
2110 | spec->num_pins = 14; |
2111 | spec->pin_nids = stac927x_pin_nids; | |
f5fcc13c TI |
2112 | spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS, |
2113 | stac927x_models, | |
2114 | stac927x_cfg_tbl); | |
9e507abd | 2115 | again: |
11b44bbd | 2116 | if (spec->board_config < 0) { |
3cc08dc6 | 2117 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n"); |
11b44bbd RF |
2118 | err = stac92xx_save_bios_config_regs(codec); |
2119 | if (err < 0) { | |
2120 | stac92xx_free(codec); | |
2121 | return err; | |
2122 | } | |
2123 | spec->pin_configs = spec->bios_pin_configs; | |
2124 | } else if (stac927x_brd_tbl[spec->board_config] != NULL) { | |
3cc08dc6 MP |
2125 | spec->pin_configs = stac927x_brd_tbl[spec->board_config]; |
2126 | stac92xx_set_config_regs(codec); | |
2127 | } | |
2128 | ||
81d3dbde | 2129 | switch (spec->board_config) { |
93ed1503 | 2130 | case STAC_D965_3ST: |
81d3dbde TD |
2131 | spec->adc_nids = stac927x_adc_nids; |
2132 | spec->mux_nids = stac927x_mux_nids; | |
2549413e | 2133 | spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); |
8b65727b | 2134 | spec->num_dmics = 0; |
93ed1503 | 2135 | spec->init = d965_core_init; |
81d3dbde TD |
2136 | spec->mixer = stac9227_mixer; |
2137 | break; | |
93ed1503 TD |
2138 | case STAC_D965_5ST: |
2139 | spec->adc_nids = stac927x_adc_nids; | |
2140 | spec->mux_nids = stac927x_mux_nids; | |
2549413e | 2141 | spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); |
8b65727b | 2142 | spec->num_dmics = 0; |
93ed1503 | 2143 | spec->init = d965_core_init; |
81d3dbde TD |
2144 | spec->mixer = stac9227_mixer; |
2145 | break; | |
2146 | default: | |
2147 | spec->adc_nids = stac927x_adc_nids; | |
2148 | spec->mux_nids = stac927x_mux_nids; | |
2549413e | 2149 | spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); |
8b65727b | 2150 | spec->num_dmics = 0; |
81d3dbde TD |
2151 | spec->init = stac927x_core_init; |
2152 | spec->mixer = stac927x_mixer; | |
2153 | } | |
3cc08dc6 MP |
2154 | |
2155 | spec->multiout.dac_nids = spec->dac_nids; | |
2156 | ||
2157 | err = stac92xx_parse_auto_config(codec, 0x1e, 0x20); | |
9e507abd TI |
2158 | if (!err) { |
2159 | if (spec->board_config < 0) { | |
2160 | printk(KERN_WARNING "hda_codec: No auto-config is " | |
2161 | "available, default to model=ref\n"); | |
2162 | spec->board_config = STAC_D965_REF; | |
2163 | goto again; | |
2164 | } | |
2165 | err = -EINVAL; | |
2166 | } | |
c7d4b2fa M |
2167 | if (err < 0) { |
2168 | stac92xx_free(codec); | |
2169 | return err; | |
2170 | } | |
2f2f4251 M |
2171 | |
2172 | codec->patch_ops = stac92xx_patch_ops; | |
2173 | ||
897cc188 TI |
2174 | /* Fix Mux capture level; max to 2 */ |
2175 | snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT, | |
2176 | (0 << AC_AMPCAP_OFFSET_SHIFT) | | |
2177 | (2 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
2178 | (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
2179 | (0 << AC_AMPCAP_MUTE_SHIFT)); | |
2180 | ||
2f2f4251 M |
2181 | return 0; |
2182 | } | |
2183 | ||
f3302a59 MP |
2184 | static int patch_stac9205(struct hda_codec *codec) |
2185 | { | |
2186 | struct sigmatel_spec *spec; | |
2187 | int err; | |
2188 | ||
2189 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
2190 | if (spec == NULL) | |
2191 | return -ENOMEM; | |
2192 | ||
2193 | codec->spec = spec; | |
11b44bbd RF |
2194 | spec->num_pins = 14; |
2195 | spec->pin_nids = stac9205_pin_nids; | |
f5fcc13c TI |
2196 | spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS, |
2197 | stac9205_models, | |
2198 | stac9205_cfg_tbl); | |
9e507abd | 2199 | again: |
11b44bbd RF |
2200 | if (spec->board_config < 0) { |
2201 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); | |
2202 | err = stac92xx_save_bios_config_regs(codec); | |
2203 | if (err < 0) { | |
2204 | stac92xx_free(codec); | |
2205 | return err; | |
2206 | } | |
2207 | spec->pin_configs = spec->bios_pin_configs; | |
2208 | } else { | |
f3302a59 MP |
2209 | spec->pin_configs = stac9205_brd_tbl[spec->board_config]; |
2210 | stac92xx_set_config_regs(codec); | |
2211 | } | |
2212 | ||
2213 | spec->adc_nids = stac9205_adc_nids; | |
2214 | spec->mux_nids = stac9205_mux_nids; | |
2549413e | 2215 | spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids); |
8b65727b | 2216 | spec->dmic_nids = stac9205_dmic_nids; |
2549413e | 2217 | spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids); |
8b65727b | 2218 | spec->dmux_nid = 0x1d; |
f3302a59 MP |
2219 | |
2220 | spec->init = stac9205_core_init; | |
2221 | spec->mixer = stac9205_mixer; | |
2222 | ||
2223 | spec->multiout.dac_nids = spec->dac_nids; | |
2224 | ||
33382403 MP |
2225 | /* Configure GPIO0 as EAPD output */ |
2226 | snd_hda_codec_write(codec, codec->afg, 0, | |
2227 | AC_VERB_SET_GPIO_DIRECTION, 0x00000001); | |
2228 | /* Configure GPIO0 as CMOS */ | |
2229 | snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000); | |
2230 | /* Assert GPIO0 high */ | |
2231 | snd_hda_codec_write(codec, codec->afg, 0, | |
2232 | AC_VERB_SET_GPIO_DATA, 0x00000001); | |
2233 | /* Enable GPIO0 */ | |
2234 | snd_hda_codec_write(codec, codec->afg, 0, | |
2235 | AC_VERB_SET_GPIO_MASK, 0x00000001); | |
2236 | ||
f3302a59 | 2237 | err = stac92xx_parse_auto_config(codec, 0x1f, 0x20); |
9e507abd TI |
2238 | if (!err) { |
2239 | if (spec->board_config < 0) { | |
2240 | printk(KERN_WARNING "hda_codec: No auto-config is " | |
2241 | "available, default to model=ref\n"); | |
2242 | spec->board_config = STAC_9205_REF; | |
2243 | goto again; | |
2244 | } | |
2245 | err = -EINVAL; | |
2246 | } | |
f3302a59 MP |
2247 | if (err < 0) { |
2248 | stac92xx_free(codec); | |
2249 | return err; | |
2250 | } | |
2251 | ||
2252 | codec->patch_ops = stac92xx_patch_ops; | |
2253 | ||
2254 | return 0; | |
2255 | } | |
2256 | ||
db064e50 | 2257 | /* |
6d859065 | 2258 | * STAC9872 hack |
db064e50 TI |
2259 | */ |
2260 | ||
99ccc560 | 2261 | /* static config for Sony VAIO FE550G and Sony VAIO AR */ |
db064e50 TI |
2262 | static hda_nid_t vaio_dacs[] = { 0x2 }; |
2263 | #define VAIO_HP_DAC 0x5 | |
2264 | static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ }; | |
2265 | static hda_nid_t vaio_mux_nids[] = { 0x15 }; | |
2266 | ||
2267 | static struct hda_input_mux vaio_mux = { | |
2268 | .num_items = 2, | |
2269 | .items = { | |
d773781c TI |
2270 | /* { "HP", 0x0 }, */ |
2271 | { "Line", 0x1 }, | |
db064e50 TI |
2272 | { "Mic", 0x2 }, |
2273 | { "PCM", 0x3 }, | |
2274 | } | |
2275 | }; | |
2276 | ||
2277 | static struct hda_verb vaio_init[] = { | |
2278 | {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */ | |
2279 | {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */ | |
2280 | {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */ | |
2281 | {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */ | |
2282 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */ | |
2283 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */ | |
2284 | {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */ | |
2285 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */ | |
2286 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */ | |
2287 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */ | |
2288 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ | |
2289 | {} | |
2290 | }; | |
2291 | ||
6d859065 GM |
2292 | static struct hda_verb vaio_ar_init[] = { |
2293 | {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */ | |
2294 | {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */ | |
2295 | {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */ | |
2296 | {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */ | |
2297 | /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */ | |
2298 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */ | |
2299 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */ | |
2300 | {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */ | |
2301 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */ | |
2302 | /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */ | |
2303 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */ | |
2304 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */ | |
2305 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ | |
2306 | {} | |
2307 | }; | |
2308 | ||
db064e50 TI |
2309 | /* bind volumes of both NID 0x02 and 0x05 */ |
2310 | static int vaio_master_vol_put(struct snd_kcontrol *kcontrol, | |
2311 | struct snd_ctl_elem_value *ucontrol) | |
2312 | { | |
2313 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2314 | long *valp = ucontrol->value.integer.value; | |
2315 | int change; | |
2316 | ||
2317 | change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0, | |
2318 | 0x7f, valp[0] & 0x7f); | |
2319 | change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0, | |
2320 | 0x7f, valp[1] & 0x7f); | |
2321 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, | |
2322 | 0x7f, valp[0] & 0x7f); | |
2323 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, | |
2324 | 0x7f, valp[1] & 0x7f); | |
2325 | return change; | |
2326 | } | |
2327 | ||
2328 | /* bind volumes of both NID 0x02 and 0x05 */ | |
2329 | static int vaio_master_sw_put(struct snd_kcontrol *kcontrol, | |
2330 | struct snd_ctl_elem_value *ucontrol) | |
2331 | { | |
2332 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2333 | long *valp = ucontrol->value.integer.value; | |
2334 | int change; | |
2335 | ||
2336 | change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0, | |
a9393d70 | 2337 | 0x80, (valp[0] ? 0 : 0x80)); |
db064e50 | 2338 | change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0, |
a9393d70 | 2339 | 0x80, (valp[1] ? 0 : 0x80)); |
db064e50 | 2340 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, |
a9393d70 | 2341 | 0x80, (valp[0] ? 0 : 0x80)); |
db064e50 | 2342 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, |
a9393d70 | 2343 | 0x80, (valp[1] ? 0 : 0x80)); |
db064e50 TI |
2344 | return change; |
2345 | } | |
2346 | ||
2347 | static struct snd_kcontrol_new vaio_mixer[] = { | |
2348 | { | |
2349 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2350 | .name = "Master Playback Volume", | |
2351 | .info = snd_hda_mixer_amp_volume_info, | |
2352 | .get = snd_hda_mixer_amp_volume_get, | |
2353 | .put = vaio_master_vol_put, | |
c2566524 | 2354 | .tlv = { .c = snd_hda_mixer_amp_tlv }, |
db064e50 TI |
2355 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), |
2356 | }, | |
2357 | { | |
2358 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2359 | .name = "Master Playback Switch", | |
2360 | .info = snd_hda_mixer_amp_switch_info, | |
2361 | .get = snd_hda_mixer_amp_switch_get, | |
2362 | .put = vaio_master_sw_put, | |
2363 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), | |
2364 | }, | |
2365 | /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ | |
2366 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), | |
2367 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), | |
2368 | { | |
2369 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2370 | .name = "Capture Source", | |
2371 | .count = 1, | |
2372 | .info = stac92xx_mux_enum_info, | |
2373 | .get = stac92xx_mux_enum_get, | |
2374 | .put = stac92xx_mux_enum_put, | |
2375 | }, | |
2376 | {} | |
2377 | }; | |
2378 | ||
6d859065 GM |
2379 | static struct snd_kcontrol_new vaio_ar_mixer[] = { |
2380 | { | |
2381 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2382 | .name = "Master Playback Volume", | |
2383 | .info = snd_hda_mixer_amp_volume_info, | |
2384 | .get = snd_hda_mixer_amp_volume_get, | |
2385 | .put = vaio_master_vol_put, | |
2386 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), | |
2387 | }, | |
2388 | { | |
2389 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2390 | .name = "Master Playback Switch", | |
2391 | .info = snd_hda_mixer_amp_switch_info, | |
2392 | .get = snd_hda_mixer_amp_switch_get, | |
2393 | .put = vaio_master_sw_put, | |
2394 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), | |
2395 | }, | |
2396 | /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ | |
2397 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), | |
2398 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), | |
2399 | /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT), | |
2400 | HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/ | |
2401 | { | |
2402 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2403 | .name = "Capture Source", | |
2404 | .count = 1, | |
2405 | .info = stac92xx_mux_enum_info, | |
2406 | .get = stac92xx_mux_enum_get, | |
2407 | .put = stac92xx_mux_enum_put, | |
2408 | }, | |
2409 | {} | |
2410 | }; | |
2411 | ||
2412 | static struct hda_codec_ops stac9872_patch_ops = { | |
db064e50 TI |
2413 | .build_controls = stac92xx_build_controls, |
2414 | .build_pcms = stac92xx_build_pcms, | |
2415 | .init = stac92xx_init, | |
2416 | .free = stac92xx_free, | |
2417 | #ifdef CONFIG_PM | |
2418 | .resume = stac92xx_resume, | |
2419 | #endif | |
2420 | }; | |
2421 | ||
6d859065 GM |
2422 | enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */ |
2423 | CXD9872RD_VAIO, | |
2424 | /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */ | |
2425 | STAC9872AK_VAIO, | |
2426 | /* Unknown. id=0x83847661 and subsys=0x104D1200. */ | |
2427 | STAC9872K_VAIO, | |
2428 | /* AR Series. id=0x83847664 and subsys=104D1300 */ | |
f5fcc13c TI |
2429 | CXD9872AKD_VAIO, |
2430 | STAC_9872_MODELS, | |
2431 | }; | |
2432 | ||
2433 | static const char *stac9872_models[STAC_9872_MODELS] = { | |
2434 | [CXD9872RD_VAIO] = "vaio", | |
2435 | [CXD9872AKD_VAIO] = "vaio-ar", | |
2436 | }; | |
2437 | ||
2438 | static struct snd_pci_quirk stac9872_cfg_tbl[] = { | |
2439 | SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO), | |
2440 | SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO), | |
2441 | SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO), | |
68e22543 | 2442 | SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO), |
db064e50 TI |
2443 | {} |
2444 | }; | |
2445 | ||
6d859065 | 2446 | static int patch_stac9872(struct hda_codec *codec) |
db064e50 TI |
2447 | { |
2448 | struct sigmatel_spec *spec; | |
2449 | int board_config; | |
2450 | ||
f5fcc13c TI |
2451 | board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS, |
2452 | stac9872_models, | |
2453 | stac9872_cfg_tbl); | |
db064e50 TI |
2454 | if (board_config < 0) |
2455 | /* unknown config, let generic-parser do its job... */ | |
2456 | return snd_hda_parse_generic_codec(codec); | |
2457 | ||
2458 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
2459 | if (spec == NULL) | |
2460 | return -ENOMEM; | |
2461 | ||
2462 | codec->spec = spec; | |
2463 | switch (board_config) { | |
6d859065 GM |
2464 | case CXD9872RD_VAIO: |
2465 | case STAC9872AK_VAIO: | |
2466 | case STAC9872K_VAIO: | |
db064e50 TI |
2467 | spec->mixer = vaio_mixer; |
2468 | spec->init = vaio_init; | |
2469 | spec->multiout.max_channels = 2; | |
2470 | spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs); | |
2471 | spec->multiout.dac_nids = vaio_dacs; | |
2472 | spec->multiout.hp_nid = VAIO_HP_DAC; | |
2473 | spec->num_adcs = ARRAY_SIZE(vaio_adcs); | |
2474 | spec->adc_nids = vaio_adcs; | |
2475 | spec->input_mux = &vaio_mux; | |
2476 | spec->mux_nids = vaio_mux_nids; | |
2477 | break; | |
6d859065 GM |
2478 | |
2479 | case CXD9872AKD_VAIO: | |
2480 | spec->mixer = vaio_ar_mixer; | |
2481 | spec->init = vaio_ar_init; | |
2482 | spec->multiout.max_channels = 2; | |
2483 | spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs); | |
2484 | spec->multiout.dac_nids = vaio_dacs; | |
2485 | spec->multiout.hp_nid = VAIO_HP_DAC; | |
2486 | spec->num_adcs = ARRAY_SIZE(vaio_adcs); | |
2487 | spec->adc_nids = vaio_adcs; | |
2488 | spec->input_mux = &vaio_mux; | |
2489 | spec->mux_nids = vaio_mux_nids; | |
2490 | break; | |
db064e50 TI |
2491 | } |
2492 | ||
6d859065 | 2493 | codec->patch_ops = stac9872_patch_ops; |
db064e50 TI |
2494 | return 0; |
2495 | } | |
2496 | ||
2497 | ||
2f2f4251 M |
2498 | /* |
2499 | * patch entries | |
2500 | */ | |
2501 | struct hda_codec_preset snd_hda_preset_sigmatel[] = { | |
2502 | { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 }, | |
2503 | { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x }, | |
2504 | { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x }, | |
2505 | { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x }, | |
2506 | { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x }, | |
2507 | { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x }, | |
2508 | { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x }, | |
22a27c7f MP |
2509 | { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x }, |
2510 | { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x }, | |
2511 | { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x }, | |
2512 | { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x }, | |
2513 | { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x }, | |
2514 | { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x }, | |
3cc08dc6 MP |
2515 | { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x }, |
2516 | { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x }, | |
2517 | { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x }, | |
2518 | { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x }, | |
2519 | { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x }, | |
2520 | { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x }, | |
2521 | { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x }, | |
2522 | { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x }, | |
2523 | { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x }, | |
2524 | { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x }, | |
8e21c34c TD |
2525 | { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x }, |
2526 | { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x }, | |
2527 | { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x }, | |
2528 | { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x }, | |
2529 | { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x }, | |
2530 | { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x }, | |
6d859065 GM |
2531 | /* The following does not take into account .id=0x83847661 when subsys = |
2532 | * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are | |
2533 | * currently not fully supported. | |
2534 | */ | |
2535 | { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 }, | |
2536 | { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 }, | |
2537 | { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 }, | |
f3302a59 MP |
2538 | { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 }, |
2539 | { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 }, | |
2540 | { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 }, | |
2541 | { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 }, | |
2542 | { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 }, | |
2543 | { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 }, | |
2544 | { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 }, | |
2545 | { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 }, | |
2f2f4251 M |
2546 | {} /* terminator */ |
2547 | }; |