]>
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 | |
39 | #define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT) | |
40 | ||
403d1944 MP |
41 | #define STAC_REF 0 |
42 | #define STAC_D945GTP3 1 | |
43 | #define STAC_D945GTP5 2 | |
62fe78e9 | 44 | #define STAC_MACMINI 3 |
19039bd0 TI |
45 | #define STAC_D965_2112 4 |
46 | #define STAC_D965_284B 5 | |
47 | #define STAC_922X_MODELS 6 /* number of 922x models */ | |
403d1944 | 48 | |
2f2f4251 | 49 | struct sigmatel_spec { |
c8b6bf9b | 50 | struct snd_kcontrol_new *mixers[4]; |
c7d4b2fa M |
51 | unsigned int num_mixers; |
52 | ||
403d1944 | 53 | int board_config; |
c7d4b2fa | 54 | unsigned int surr_switch: 1; |
403d1944 MP |
55 | unsigned int line_switch: 1; |
56 | unsigned int mic_switch: 1; | |
3cc08dc6 | 57 | unsigned int alt_switch: 1; |
82bc955f | 58 | unsigned int hp_detect: 1; |
62fe78e9 | 59 | unsigned int gpio_mute: 1; |
c7d4b2fa | 60 | |
2f2f4251 M |
61 | /* playback */ |
62 | struct hda_multi_out multiout; | |
3cc08dc6 | 63 | hda_nid_t dac_nids[5]; |
2f2f4251 M |
64 | |
65 | /* capture */ | |
66 | hda_nid_t *adc_nids; | |
2f2f4251 | 67 | unsigned int num_adcs; |
dabbed6f M |
68 | hda_nid_t *mux_nids; |
69 | unsigned int num_muxes; | |
dabbed6f | 70 | hda_nid_t dig_in_nid; |
2f2f4251 | 71 | |
2f2f4251 M |
72 | /* pin widgets */ |
73 | hda_nid_t *pin_nids; | |
74 | unsigned int num_pins; | |
2f2f4251 | 75 | unsigned int *pin_configs; |
11b44bbd | 76 | unsigned int *bios_pin_configs; |
2f2f4251 M |
77 | |
78 | /* codec specific stuff */ | |
79 | struct hda_verb *init; | |
c8b6bf9b | 80 | struct snd_kcontrol_new *mixer; |
2f2f4251 M |
81 | |
82 | /* capture source */ | |
c7d4b2fa | 83 | struct hda_input_mux *input_mux; |
3cc08dc6 | 84 | unsigned int cur_mux[3]; |
2f2f4251 | 85 | |
403d1944 MP |
86 | /* i/o switches */ |
87 | unsigned int io_switch[2]; | |
2f2f4251 | 88 | |
c7d4b2fa M |
89 | struct hda_pcm pcm_rec[2]; /* PCM information */ |
90 | ||
91 | /* dynamic controls and input_mux */ | |
92 | struct auto_pin_cfg autocfg; | |
93 | unsigned int num_kctl_alloc, num_kctl_used; | |
c8b6bf9b | 94 | struct snd_kcontrol_new *kctl_alloc; |
c7d4b2fa | 95 | struct hda_input_mux private_imux; |
2f2f4251 M |
96 | }; |
97 | ||
98 | static hda_nid_t stac9200_adc_nids[1] = { | |
99 | 0x03, | |
100 | }; | |
101 | ||
102 | static hda_nid_t stac9200_mux_nids[1] = { | |
103 | 0x0c, | |
104 | }; | |
105 | ||
106 | static hda_nid_t stac9200_dac_nids[1] = { | |
107 | 0x02, | |
108 | }; | |
109 | ||
2f2f4251 M |
110 | static hda_nid_t stac922x_adc_nids[2] = { |
111 | 0x06, 0x07, | |
112 | }; | |
113 | ||
19039bd0 TI |
114 | static hda_nid_t stac9227_adc_nids[2] = { |
115 | 0x07, 0x08, | |
116 | }; | |
117 | ||
118 | #if 0 | |
119 | static hda_nid_t d965_2112_dac_nids[3] = { | |
120 | 0x02, 0x03, 0x05, | |
121 | }; | |
122 | #endif | |
123 | ||
2f2f4251 M |
124 | static hda_nid_t stac922x_mux_nids[2] = { |
125 | 0x12, 0x13, | |
126 | }; | |
127 | ||
19039bd0 TI |
128 | static hda_nid_t stac9227_mux_nids[2] = { |
129 | 0x15, 0x16, | |
130 | }; | |
131 | ||
3cc08dc6 MP |
132 | static hda_nid_t stac927x_adc_nids[3] = { |
133 | 0x07, 0x08, 0x09 | |
134 | }; | |
135 | ||
136 | static hda_nid_t stac927x_mux_nids[3] = { | |
137 | 0x15, 0x16, 0x17 | |
138 | }; | |
139 | ||
f3302a59 MP |
140 | static hda_nid_t stac9205_adc_nids[2] = { |
141 | 0x12, 0x13 | |
142 | }; | |
143 | ||
144 | static hda_nid_t stac9205_mux_nids[2] = { | |
145 | 0x19, 0x1a | |
146 | }; | |
147 | ||
c7d4b2fa M |
148 | static hda_nid_t stac9200_pin_nids[8] = { |
149 | 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, | |
2f2f4251 M |
150 | }; |
151 | ||
152 | static hda_nid_t stac922x_pin_nids[10] = { | |
153 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, | |
154 | 0x0f, 0x10, 0x11, 0x15, 0x1b, | |
155 | }; | |
156 | ||
3cc08dc6 MP |
157 | static hda_nid_t stac927x_pin_nids[14] = { |
158 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, | |
159 | 0x0f, 0x10, 0x11, 0x12, 0x13, | |
160 | 0x14, 0x21, 0x22, 0x23, | |
161 | }; | |
162 | ||
f3302a59 MP |
163 | static hda_nid_t stac9205_pin_nids[12] = { |
164 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, | |
165 | 0x0f, 0x14, 0x16, 0x17, 0x18, | |
166 | 0x21, 0x22, | |
167 | ||
168 | }; | |
169 | ||
c8b6bf9b | 170 | static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
2f2f4251 M |
171 | { |
172 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
173 | struct sigmatel_spec *spec = codec->spec; | |
c7d4b2fa | 174 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
2f2f4251 M |
175 | } |
176 | ||
c8b6bf9b | 177 | static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
2f2f4251 M |
178 | { |
179 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
180 | struct sigmatel_spec *spec = codec->spec; | |
181 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
182 | ||
183 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
184 | return 0; | |
185 | } | |
186 | ||
c8b6bf9b | 187 | static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
2f2f4251 M |
188 | { |
189 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
190 | struct sigmatel_spec *spec = codec->spec; | |
191 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
192 | ||
c7d4b2fa | 193 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
2f2f4251 M |
194 | spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]); |
195 | } | |
196 | ||
c7d4b2fa | 197 | static struct hda_verb stac9200_core_init[] = { |
2f2f4251 | 198 | /* set dac0mux for dac converter */ |
c7d4b2fa | 199 | { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00}, |
2f2f4251 M |
200 | {} |
201 | }; | |
202 | ||
c7d4b2fa | 203 | static struct hda_verb stac922x_core_init[] = { |
2f2f4251 | 204 | /* set master volume and direct control */ |
c7d4b2fa | 205 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, |
2f2f4251 M |
206 | {} |
207 | }; | |
208 | ||
19039bd0 TI |
209 | static struct hda_verb stac9227_core_init[] = { |
210 | /* set master volume and direct control */ | |
211 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, | |
212 | /* unmute node 0x1b */ | |
213 | { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
214 | {} | |
215 | }; | |
216 | ||
217 | static struct hda_verb d965_2112_core_init[] = { | |
218 | /* set master volume and direct control */ | |
219 | { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, | |
220 | /* unmute node 0x1b */ | |
221 | { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
222 | /* select node 0x03 as DAC */ | |
223 | { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01}, | |
224 | {} | |
225 | }; | |
226 | ||
3cc08dc6 MP |
227 | static struct hda_verb stac927x_core_init[] = { |
228 | /* set master volume and direct control */ | |
229 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, | |
230 | {} | |
231 | }; | |
232 | ||
f3302a59 MP |
233 | static struct hda_verb stac9205_core_init[] = { |
234 | /* set master volume and direct control */ | |
235 | { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, | |
236 | {} | |
237 | }; | |
238 | ||
c8b6bf9b | 239 | static struct snd_kcontrol_new stac9200_mixer[] = { |
2f2f4251 M |
240 | HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT), |
241 | HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT), | |
242 | { | |
243 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
244 | .name = "Input Source", | |
245 | .count = 1, | |
246 | .info = stac92xx_mux_enum_info, | |
247 | .get = stac92xx_mux_enum_get, | |
248 | .put = stac92xx_mux_enum_put, | |
249 | }, | |
250 | HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT), | |
251 | HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT), | |
c7d4b2fa | 252 | HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT), |
2f2f4251 M |
253 | { } /* end */ |
254 | }; | |
255 | ||
c7d4b2fa | 256 | /* This needs to be generated dynamically based on sequence */ |
c8b6bf9b | 257 | static struct snd_kcontrol_new stac922x_mixer[] = { |
2f2f4251 M |
258 | { |
259 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
260 | .name = "Input Source", | |
261 | .count = 1, | |
262 | .info = stac92xx_mux_enum_info, | |
263 | .get = stac92xx_mux_enum_get, | |
264 | .put = stac92xx_mux_enum_put, | |
265 | }, | |
266 | HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT), | |
0fd1708a | 267 | HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT), |
2f2f4251 M |
268 | HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT), |
269 | { } /* end */ | |
270 | }; | |
271 | ||
19039bd0 TI |
272 | /* This needs to be generated dynamically based on sequence */ |
273 | static struct snd_kcontrol_new stac9227_mixer[] = { | |
274 | { | |
275 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
276 | .name = "Input Source", | |
277 | .count = 1, | |
278 | .info = stac92xx_mux_enum_info, | |
279 | .get = stac92xx_mux_enum_get, | |
280 | .put = stac92xx_mux_enum_put, | |
281 | }, | |
282 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
283 | HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT), | |
284 | { } /* end */ | |
285 | }; | |
286 | ||
3cc08dc6 MP |
287 | static snd_kcontrol_new_t stac927x_mixer[] = { |
288 | { | |
289 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
290 | .name = "Input Source", | |
291 | .count = 1, | |
292 | .info = stac92xx_mux_enum_info, | |
293 | .get = stac92xx_mux_enum_get, | |
294 | .put = stac92xx_mux_enum_put, | |
295 | }, | |
296 | HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
297 | HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT), | |
298 | HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT), | |
299 | { } /* end */ | |
300 | }; | |
301 | ||
f3302a59 MP |
302 | static snd_kcontrol_new_t stac9205_mixer[] = { |
303 | { | |
304 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
305 | .name = "Input Source", | |
306 | .count = 1, | |
307 | .info = stac92xx_mux_enum_info, | |
308 | .get = stac92xx_mux_enum_get, | |
309 | .put = stac92xx_mux_enum_put, | |
310 | }, | |
311 | HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT), | |
312 | HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT), | |
313 | HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT), | |
314 | { } /* end */ | |
315 | }; | |
316 | ||
2f2f4251 M |
317 | static int stac92xx_build_controls(struct hda_codec *codec) |
318 | { | |
319 | struct sigmatel_spec *spec = codec->spec; | |
320 | int err; | |
c7d4b2fa | 321 | int i; |
2f2f4251 M |
322 | |
323 | err = snd_hda_add_new_ctls(codec, spec->mixer); | |
324 | if (err < 0) | |
325 | return err; | |
c7d4b2fa M |
326 | |
327 | for (i = 0; i < spec->num_mixers; i++) { | |
328 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
329 | if (err < 0) | |
330 | return err; | |
331 | } | |
332 | ||
dabbed6f M |
333 | if (spec->multiout.dig_out_nid) { |
334 | err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); | |
335 | if (err < 0) | |
336 | return err; | |
337 | } | |
338 | if (spec->dig_in_nid) { | |
339 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
340 | if (err < 0) | |
341 | return err; | |
342 | } | |
343 | return 0; | |
2f2f4251 M |
344 | } |
345 | ||
403d1944 | 346 | static unsigned int ref9200_pin_configs[8] = { |
dabbed6f | 347 | 0x01c47010, 0x01447010, 0x0221401f, 0x01114010, |
2f2f4251 M |
348 | 0x02a19020, 0x01a19021, 0x90100140, 0x01813122, |
349 | }; | |
350 | ||
403d1944 MP |
351 | static unsigned int *stac9200_brd_tbl[] = { |
352 | ref9200_pin_configs, | |
353 | }; | |
354 | ||
355 | static struct hda_board_config stac9200_cfg_tbl[] = { | |
356 | { .modelname = "ref", | |
357 | .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
358 | .pci_subdevice = 0x2668, /* DFI LanParty */ | |
359 | .config = STAC_REF }, | |
360 | {} /* terminator */ | |
361 | }; | |
362 | ||
363 | static unsigned int ref922x_pin_configs[10] = { | |
364 | 0x01014010, 0x01016011, 0x01012012, 0x0221401f, | |
365 | 0x01813122, 0x01011014, 0x01441030, 0x01c41030, | |
2f2f4251 M |
366 | 0x40000100, 0x40000100, |
367 | }; | |
368 | ||
403d1944 | 369 | static unsigned int d945gtp3_pin_configs[10] = { |
869264c4 | 370 | 0x0221401f, 0x01a19022, 0x01813021, 0x01014010, |
403d1944 MP |
371 | 0x40000100, 0x40000100, 0x40000100, 0x40000100, |
372 | 0x02a19120, 0x40000100, | |
373 | }; | |
374 | ||
375 | static unsigned int d945gtp5_pin_configs[10] = { | |
869264c4 MP |
376 | 0x0221401f, 0x01011012, 0x01813024, 0x01014010, |
377 | 0x01a19021, 0x01016011, 0x01452130, 0x40000100, | |
403d1944 MP |
378 | 0x02a19320, 0x40000100, |
379 | }; | |
380 | ||
19039bd0 TI |
381 | static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = { |
382 | [STAC_REF] = ref922x_pin_configs, | |
383 | [STAC_D945GTP3] = d945gtp3_pin_configs, | |
384 | [STAC_D945GTP5] = d945gtp5_pin_configs, | |
7c3dec06 | 385 | [STAC_MACMINI] = d945gtp5_pin_configs, |
403d1944 MP |
386 | }; |
387 | ||
388 | static struct hda_board_config stac922x_cfg_tbl[] = { | |
389 | { .modelname = "ref", | |
390 | .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
391 | .pci_subdevice = 0x2668, /* DFI LanParty */ | |
392 | .config = STAC_REF }, /* SigmaTel reference board */ | |
948a4db2 | 393 | /* Intel 945G based systems */ |
403d1944 MP |
394 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
395 | .pci_subdevice = 0x0101, | |
396 | .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */ | |
353b9e66 TI |
397 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
398 | .pci_subdevice = 0x0202, | |
948a4db2 | 399 | .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */ |
353b9e66 | 400 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
948a4db2 TD |
401 | .pci_subdevice = 0x0606, |
402 | .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */ | |
403 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
404 | .pci_subdevice = 0x0601, | |
405 | .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */ | |
406 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
407 | .pci_subdevice = 0x0111, | |
408 | .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */ | |
409 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
410 | .pci_subdevice = 0x1115, | |
411 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ | |
412 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
413 | .pci_subdevice = 0x1116, | |
414 | .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */ | |
415 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
416 | .pci_subdevice = 0x1117, | |
417 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ | |
418 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
419 | .pci_subdevice = 0x1118, | |
420 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ | |
421 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
422 | .pci_subdevice = 0x1119, | |
423 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ | |
424 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
425 | .pci_subdevice = 0x8826, | |
426 | .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */ | |
427 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
428 | .pci_subdevice = 0x5049, | |
429 | .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */ | |
430 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
431 | .pci_subdevice = 0x5055, | |
432 | .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */ | |
433 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
434 | .pci_subdevice = 0x5048, | |
435 | .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */ | |
436 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
437 | .pci_subdevice = 0x0110, | |
438 | .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */ | |
403d1944 MP |
439 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
440 | .pci_subdevice = 0x0404, | |
441 | .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */ | |
442 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
443 | .pci_subdevice = 0x0303, | |
444 | .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */ | |
445 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
446 | .pci_subdevice = 0x0013, | |
447 | .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */ | |
d62c40e0 MP |
448 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
449 | .pci_subdevice = 0x0417, | |
450 | .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */ | |
948a4db2 TD |
451 | /* Intel 945P based systems */ |
452 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
453 | .pci_subdevice = 0x0b0b, | |
454 | .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */ | |
455 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
456 | .pci_subdevice = 0x0112, | |
457 | .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */ | |
458 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
459 | .pci_subdevice = 0x0d0d, | |
460 | .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */ | |
461 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
462 | .pci_subdevice = 0x0909, | |
463 | .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */ | |
464 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
465 | .pci_subdevice = 0x0505, | |
466 | .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */ | |
467 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
468 | .pci_subdevice = 0x0707, | |
469 | .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */ | |
470 | /* other systems */ | |
62fe78e9 SR |
471 | { .pci_subvendor = 0x8384, |
472 | .pci_subdevice = 0x7680, | |
473 | .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */ | |
19039bd0 TI |
474 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, |
475 | .pci_subdevice = 0x2112, | |
476 | .config = STAC_D965_2112 }, | |
477 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
478 | .pci_subdevice = 0x284b, | |
479 | .config = STAC_D965_284B }, | |
403d1944 MP |
480 | {} /* terminator */ |
481 | }; | |
482 | ||
3cc08dc6 MP |
483 | static unsigned int ref927x_pin_configs[14] = { |
484 | 0x01813122, 0x01a19021, 0x01014010, 0x01016011, | |
485 | 0x01012012, 0x01011014, 0x40000100, 0x40000100, | |
486 | 0x40000100, 0x40000100, 0x40000100, 0x01441030, | |
487 | 0x01c41030, 0x40000100, | |
488 | }; | |
489 | ||
81d3dbde TD |
490 | static unsigned int d965_2112_pin_configs[14] = { |
491 | 0x0221401f, 0x02a19120, 0x40000100, 0x01014011, | |
492 | 0x01a19021, 0x01813024, 0x40000100, 0x40000100, | |
493 | 0x40000100, 0x40000100, 0x40000100, 0x40000100, | |
494 | 0x40000100, 0x40000100 | |
495 | }; | |
496 | ||
3cc08dc6 | 497 | static unsigned int *stac927x_brd_tbl[] = { |
81d3dbde TD |
498 | [STAC_REF] = ref927x_pin_configs, |
499 | [STAC_D965_2112] = d965_2112_pin_configs, | |
3cc08dc6 MP |
500 | }; |
501 | ||
502 | static struct hda_board_config stac927x_cfg_tbl[] = { | |
503 | { .modelname = "ref", | |
504 | .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
505 | .pci_subdevice = 0x2668, /* DFI LanParty */ | |
506 | .config = STAC_REF }, /* SigmaTel reference board */ | |
81d3dbde TD |
507 | /* SigmaTel 9227 reference board */ |
508 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
509 | .pci_subdevice = 0x284b, | |
510 | .config = STAC_D965_284B }, | |
511 | /* Intel 946 based systems */ | |
512 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
513 | .pci_subdevice = 0x3d01, | |
514 | .config = STAC_D965_2112 }, /* D946 configuration */ | |
515 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
516 | .pci_subdevice = 0xa301, | |
517 | .config = STAC_D965_2112 }, /* Intel D946GZT - 3 stack */ | |
518 | /* 965 based systems */ | |
519 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
520 | .pci_subdevice = 0x2116, | |
521 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
522 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
523 | .pci_subdevice = 0x2115, | |
524 | .config = STAC_D965_2112 }, /* Intel DQ965WC - 3 Stack */ | |
525 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
526 | .pci_subdevice = 0x2114, | |
527 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
528 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
529 | .pci_subdevice = 0x2113, | |
530 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
531 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
532 | .pci_subdevice = 0x2112, | |
533 | .config = STAC_D965_2112 }, /* Intel DG965MS - 3 Stack */ | |
534 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
535 | .pci_subdevice = 0x2111, | |
536 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
537 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
538 | .pci_subdevice = 0x2110, | |
539 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
540 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
541 | .pci_subdevice = 0x2009, | |
542 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
543 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
544 | .pci_subdevice = 0x2008, | |
545 | .config = STAC_D965_2112 }, /* Intel DQ965GF - 3 Stack */ | |
546 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
547 | .pci_subdevice = 0x2007, | |
548 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
549 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
550 | .pci_subdevice = 0x2006, | |
551 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
552 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
553 | .pci_subdevice = 0x2005, | |
554 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
555 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
556 | .pci_subdevice = 0x2004, | |
557 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
558 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
559 | .pci_subdevice = 0x2003, | |
560 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
561 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
562 | .pci_subdevice = 0x2002, | |
563 | .config = STAC_D965_2112 }, /* Intel D965 3Stack config */ | |
564 | { .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
565 | .pci_subdevice = 0x2001, | |
566 | .config = STAC_D965_2112 }, /* Intel DQ965GF - 3 Stackg */ | |
3cc08dc6 MP |
567 | {} /* terminator */ |
568 | }; | |
569 | ||
f3302a59 MP |
570 | static unsigned int ref9205_pin_configs[12] = { |
571 | 0x40000100, 0x40000100, 0x01016011, 0x01014010, | |
572 | 0x01813122, 0x01a19021, 0x40000100, 0x40000100, | |
573 | 0x40000100, 0x40000100, 0x01441030, 0x01c41030 | |
574 | }; | |
575 | ||
576 | static unsigned int *stac9205_brd_tbl[] = { | |
577 | ref9205_pin_configs, | |
578 | }; | |
579 | ||
580 | static struct hda_board_config stac9205_cfg_tbl[] = { | |
581 | { .modelname = "ref", | |
582 | .pci_subvendor = PCI_VENDOR_ID_INTEL, | |
583 | .pci_subdevice = 0x2668, /* DFI LanParty */ | |
584 | .config = STAC_REF }, /* SigmaTel reference board */ | |
2c7782b4 TI |
585 | /* Dell laptops have BIOS problem */ |
586 | { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5, | |
587 | .config = STAC_REF }, /* Dell Inspiron 630m */ | |
588 | { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2, | |
589 | .config = STAC_REF }, /* Dell Latitude D620 */ | |
590 | { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb, | |
591 | .config = STAC_REF }, /* Dell Latitude 120L */ | |
f3302a59 MP |
592 | {} /* terminator */ |
593 | }; | |
594 | ||
11b44bbd RF |
595 | static int stac92xx_save_bios_config_regs(struct hda_codec *codec) |
596 | { | |
597 | int i; | |
598 | struct sigmatel_spec *spec = codec->spec; | |
599 | ||
600 | if (! spec->bios_pin_configs) { | |
601 | spec->bios_pin_configs = kcalloc(spec->num_pins, | |
602 | sizeof(*spec->bios_pin_configs), GFP_KERNEL); | |
603 | if (! spec->bios_pin_configs) | |
604 | return -ENOMEM; | |
605 | } | |
606 | ||
607 | for (i = 0; i < spec->num_pins; i++) { | |
608 | hda_nid_t nid = spec->pin_nids[i]; | |
609 | unsigned int pin_cfg; | |
610 | ||
611 | pin_cfg = snd_hda_codec_read(codec, nid, 0, | |
612 | AC_VERB_GET_CONFIG_DEFAULT, 0x00); | |
613 | snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n", | |
614 | nid, pin_cfg); | |
615 | spec->bios_pin_configs[i] = pin_cfg; | |
616 | } | |
617 | ||
618 | return 0; | |
619 | } | |
620 | ||
2f2f4251 M |
621 | static void stac92xx_set_config_regs(struct hda_codec *codec) |
622 | { | |
623 | int i; | |
624 | struct sigmatel_spec *spec = codec->spec; | |
625 | unsigned int pin_cfg; | |
626 | ||
11b44bbd RF |
627 | if (! spec->pin_nids || ! spec->pin_configs) |
628 | return; | |
629 | ||
630 | for (i = 0; i < spec->num_pins; i++) { | |
2f2f4251 M |
631 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, |
632 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_0, | |
633 | spec->pin_configs[i] & 0x000000ff); | |
634 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, | |
635 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, | |
636 | (spec->pin_configs[i] & 0x0000ff00) >> 8); | |
637 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, | |
638 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, | |
639 | (spec->pin_configs[i] & 0x00ff0000) >> 16); | |
640 | snd_hda_codec_write(codec, spec->pin_nids[i], 0, | |
641 | AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, | |
642 | spec->pin_configs[i] >> 24); | |
643 | pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0, | |
644 | AC_VERB_GET_CONFIG_DEFAULT, | |
645 | 0x00); | |
403d1944 | 646 | snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg); |
2f2f4251 M |
647 | } |
648 | } | |
2f2f4251 | 649 | |
dabbed6f | 650 | /* |
c7d4b2fa | 651 | * Analog playback callbacks |
dabbed6f | 652 | */ |
c7d4b2fa M |
653 | static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo, |
654 | struct hda_codec *codec, | |
c8b6bf9b | 655 | struct snd_pcm_substream *substream) |
2f2f4251 | 656 | { |
dabbed6f | 657 | struct sigmatel_spec *spec = codec->spec; |
c7d4b2fa | 658 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); |
2f2f4251 M |
659 | } |
660 | ||
2f2f4251 M |
661 | static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
662 | struct hda_codec *codec, | |
663 | unsigned int stream_tag, | |
664 | unsigned int format, | |
c8b6bf9b | 665 | struct snd_pcm_substream *substream) |
2f2f4251 M |
666 | { |
667 | struct sigmatel_spec *spec = codec->spec; | |
403d1944 | 668 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream); |
2f2f4251 M |
669 | } |
670 | ||
671 | static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
672 | struct hda_codec *codec, | |
c8b6bf9b | 673 | struct snd_pcm_substream *substream) |
2f2f4251 M |
674 | { |
675 | struct sigmatel_spec *spec = codec->spec; | |
676 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
677 | } | |
678 | ||
dabbed6f M |
679 | /* |
680 | * Digital playback callbacks | |
681 | */ | |
682 | static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
683 | struct hda_codec *codec, | |
c8b6bf9b | 684 | struct snd_pcm_substream *substream) |
dabbed6f M |
685 | { |
686 | struct sigmatel_spec *spec = codec->spec; | |
687 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
688 | } | |
689 | ||
690 | static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
691 | struct hda_codec *codec, | |
c8b6bf9b | 692 | struct snd_pcm_substream *substream) |
dabbed6f M |
693 | { |
694 | struct sigmatel_spec *spec = codec->spec; | |
695 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
696 | } | |
697 | ||
698 | ||
2f2f4251 M |
699 | /* |
700 | * Analog capture callbacks | |
701 | */ | |
702 | static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
703 | struct hda_codec *codec, | |
704 | unsigned int stream_tag, | |
705 | unsigned int format, | |
c8b6bf9b | 706 | struct snd_pcm_substream *substream) |
2f2f4251 M |
707 | { |
708 | struct sigmatel_spec *spec = codec->spec; | |
709 | ||
710 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
711 | stream_tag, 0, format); | |
712 | return 0; | |
713 | } | |
714 | ||
715 | static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
716 | struct hda_codec *codec, | |
c8b6bf9b | 717 | struct snd_pcm_substream *substream) |
2f2f4251 M |
718 | { |
719 | struct sigmatel_spec *spec = codec->spec; | |
720 | ||
721 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); | |
722 | return 0; | |
723 | } | |
724 | ||
dabbed6f M |
725 | static struct hda_pcm_stream stac92xx_pcm_digital_playback = { |
726 | .substreams = 1, | |
727 | .channels_min = 2, | |
728 | .channels_max = 2, | |
729 | /* NID is set in stac92xx_build_pcms */ | |
730 | .ops = { | |
731 | .open = stac92xx_dig_playback_pcm_open, | |
732 | .close = stac92xx_dig_playback_pcm_close | |
733 | }, | |
734 | }; | |
735 | ||
736 | static struct hda_pcm_stream stac92xx_pcm_digital_capture = { | |
737 | .substreams = 1, | |
738 | .channels_min = 2, | |
739 | .channels_max = 2, | |
740 | /* NID is set in stac92xx_build_pcms */ | |
741 | }; | |
742 | ||
2f2f4251 M |
743 | static struct hda_pcm_stream stac92xx_pcm_analog_playback = { |
744 | .substreams = 1, | |
745 | .channels_min = 2, | |
c7d4b2fa | 746 | .channels_max = 8, |
2f2f4251 M |
747 | .nid = 0x02, /* NID to query formats and rates */ |
748 | .ops = { | |
749 | .open = stac92xx_playback_pcm_open, | |
750 | .prepare = stac92xx_playback_pcm_prepare, | |
751 | .cleanup = stac92xx_playback_pcm_cleanup | |
752 | }, | |
753 | }; | |
754 | ||
3cc08dc6 MP |
755 | static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = { |
756 | .substreams = 1, | |
757 | .channels_min = 2, | |
758 | .channels_max = 2, | |
759 | .nid = 0x06, /* NID to query formats and rates */ | |
760 | .ops = { | |
761 | .open = stac92xx_playback_pcm_open, | |
762 | .prepare = stac92xx_playback_pcm_prepare, | |
763 | .cleanup = stac92xx_playback_pcm_cleanup | |
764 | }, | |
765 | }; | |
766 | ||
2f2f4251 M |
767 | static struct hda_pcm_stream stac92xx_pcm_analog_capture = { |
768 | .substreams = 2, | |
769 | .channels_min = 2, | |
770 | .channels_max = 2, | |
3cc08dc6 | 771 | /* NID is set in stac92xx_build_pcms */ |
2f2f4251 M |
772 | .ops = { |
773 | .prepare = stac92xx_capture_pcm_prepare, | |
774 | .cleanup = stac92xx_capture_pcm_cleanup | |
775 | }, | |
776 | }; | |
777 | ||
778 | static int stac92xx_build_pcms(struct hda_codec *codec) | |
779 | { | |
780 | struct sigmatel_spec *spec = codec->spec; | |
781 | struct hda_pcm *info = spec->pcm_rec; | |
782 | ||
783 | codec->num_pcms = 1; | |
784 | codec->pcm_info = info; | |
785 | ||
c7d4b2fa | 786 | info->name = "STAC92xx Analog"; |
2f2f4251 | 787 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback; |
2f2f4251 | 788 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture; |
3cc08dc6 MP |
789 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
790 | ||
791 | if (spec->alt_switch) { | |
792 | codec->num_pcms++; | |
793 | info++; | |
794 | info->name = "STAC92xx Analog Alt"; | |
795 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback; | |
796 | } | |
2f2f4251 | 797 | |
dabbed6f M |
798 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
799 | codec->num_pcms++; | |
800 | info++; | |
801 | info->name = "STAC92xx Digital"; | |
802 | if (spec->multiout.dig_out_nid) { | |
803 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; | |
804 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | |
805 | } | |
806 | if (spec->dig_in_nid) { | |
807 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture; | |
808 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; | |
809 | } | |
810 | } | |
811 | ||
2f2f4251 M |
812 | return 0; |
813 | } | |
814 | ||
c960a03b TI |
815 | static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid) |
816 | { | |
817 | unsigned int pincap = snd_hda_param_read(codec, nid, | |
818 | AC_PAR_PIN_CAP); | |
819 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; | |
820 | if (pincap & AC_PINCAP_VREF_100) | |
821 | return AC_PINCTL_VREF_100; | |
822 | if (pincap & AC_PINCAP_VREF_80) | |
823 | return AC_PINCTL_VREF_80; | |
824 | if (pincap & AC_PINCAP_VREF_50) | |
825 | return AC_PINCTL_VREF_50; | |
826 | if (pincap & AC_PINCAP_VREF_GRD) | |
827 | return AC_PINCTL_VREF_GRD; | |
828 | return 0; | |
829 | } | |
830 | ||
403d1944 MP |
831 | static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) |
832 | ||
833 | { | |
834 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); | |
835 | } | |
836 | ||
837 | static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | |
838 | { | |
839 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
840 | uinfo->count = 1; | |
841 | uinfo->value.integer.min = 0; | |
842 | uinfo->value.integer.max = 1; | |
843 | return 0; | |
844 | } | |
845 | ||
846 | static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
847 | { | |
848 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
849 | struct sigmatel_spec *spec = codec->spec; | |
850 | int io_idx = kcontrol-> private_value & 0xff; | |
851 | ||
852 | ucontrol->value.integer.value[0] = spec->io_switch[io_idx]; | |
853 | return 0; | |
854 | } | |
855 | ||
856 | static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | |
857 | { | |
858 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
859 | struct sigmatel_spec *spec = codec->spec; | |
860 | hda_nid_t nid = kcontrol->private_value >> 8; | |
861 | int io_idx = kcontrol-> private_value & 0xff; | |
862 | unsigned short val = ucontrol->value.integer.value[0]; | |
863 | ||
864 | spec->io_switch[io_idx] = val; | |
865 | ||
866 | if (val) | |
867 | stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); | |
c960a03b TI |
868 | else { |
869 | unsigned int pinctl = AC_PINCTL_IN_EN; | |
870 | if (io_idx) /* set VREF for mic */ | |
871 | pinctl |= stac92xx_get_vref(codec, nid); | |
872 | stac92xx_auto_set_pinctl(codec, nid, pinctl); | |
873 | } | |
403d1944 MP |
874 | return 1; |
875 | } | |
876 | ||
877 | #define STAC_CODEC_IO_SWITCH(xname, xpval) \ | |
878 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
879 | .name = xname, \ | |
880 | .index = 0, \ | |
881 | .info = stac92xx_io_switch_info, \ | |
882 | .get = stac92xx_io_switch_get, \ | |
883 | .put = stac92xx_io_switch_put, \ | |
884 | .private_value = xpval, \ | |
885 | } | |
886 | ||
887 | ||
c7d4b2fa M |
888 | enum { |
889 | STAC_CTL_WIDGET_VOL, | |
890 | STAC_CTL_WIDGET_MUTE, | |
403d1944 | 891 | STAC_CTL_WIDGET_IO_SWITCH, |
c7d4b2fa M |
892 | }; |
893 | ||
c8b6bf9b | 894 | static struct snd_kcontrol_new stac92xx_control_templates[] = { |
c7d4b2fa M |
895 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
896 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
403d1944 | 897 | STAC_CODEC_IO_SWITCH(NULL, 0), |
c7d4b2fa M |
898 | }; |
899 | ||
900 | /* add dynamic controls */ | |
901 | static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val) | |
902 | { | |
c8b6bf9b | 903 | struct snd_kcontrol_new *knew; |
c7d4b2fa M |
904 | |
905 | if (spec->num_kctl_used >= spec->num_kctl_alloc) { | |
906 | int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; | |
907 | ||
908 | knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */ | |
909 | if (! knew) | |
910 | return -ENOMEM; | |
911 | if (spec->kctl_alloc) { | |
912 | memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc); | |
913 | kfree(spec->kctl_alloc); | |
914 | } | |
915 | spec->kctl_alloc = knew; | |
916 | spec->num_kctl_alloc = num; | |
917 | } | |
918 | ||
919 | knew = &spec->kctl_alloc[spec->num_kctl_used]; | |
920 | *knew = stac92xx_control_templates[type]; | |
82fe0c58 | 921 | knew->name = kstrdup(name, GFP_KERNEL); |
c7d4b2fa M |
922 | if (! knew->name) |
923 | return -ENOMEM; | |
924 | knew->private_value = val; | |
925 | spec->num_kctl_used++; | |
926 | return 0; | |
927 | } | |
928 | ||
403d1944 MP |
929 | /* flag inputs as additional dynamic lineouts */ |
930 | static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg) | |
931 | { | |
932 | struct sigmatel_spec *spec = codec->spec; | |
933 | ||
934 | switch (cfg->line_outs) { | |
935 | case 3: | |
936 | /* add line-in as side */ | |
937 | if (cfg->input_pins[AUTO_PIN_LINE]) { | |
938 | cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE]; | |
939 | spec->line_switch = 1; | |
940 | cfg->line_outs++; | |
941 | } | |
942 | break; | |
943 | case 2: | |
944 | /* add line-in as clfe and mic as side */ | |
945 | if (cfg->input_pins[AUTO_PIN_LINE]) { | |
946 | cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE]; | |
947 | spec->line_switch = 1; | |
948 | cfg->line_outs++; | |
949 | } | |
950 | if (cfg->input_pins[AUTO_PIN_MIC]) { | |
951 | cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC]; | |
952 | spec->mic_switch = 1; | |
953 | cfg->line_outs++; | |
954 | } | |
955 | break; | |
956 | case 1: | |
957 | /* add line-in as surr and mic as clfe */ | |
958 | if (cfg->input_pins[AUTO_PIN_LINE]) { | |
959 | cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE]; | |
960 | spec->line_switch = 1; | |
961 | cfg->line_outs++; | |
962 | } | |
963 | if (cfg->input_pins[AUTO_PIN_MIC]) { | |
964 | cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC]; | |
965 | spec->mic_switch = 1; | |
966 | cfg->line_outs++; | |
967 | } | |
968 | break; | |
969 | } | |
970 | ||
971 | return 0; | |
972 | } | |
973 | ||
3cc08dc6 MP |
974 | /* |
975 | * XXX The line_out pin widget connection list may not be set to the | |
976 | * desired DAC nid. This is the case on 927x where ports A and B can | |
977 | * be routed to several DACs. | |
978 | * | |
979 | * This requires an analysis of the line-out/hp pin configuration | |
980 | * to provide a best fit for pin/DAC configurations that are routable. | |
981 | * For now, 927x DAC4 is not supported and 927x DAC1 output to ports | |
982 | * A and B is not supported. | |
983 | */ | |
c7d4b2fa | 984 | /* fill in the dac_nids table from the parsed pin configuration */ |
19039bd0 TI |
985 | static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, |
986 | const struct auto_pin_cfg *cfg) | |
c7d4b2fa M |
987 | { |
988 | struct sigmatel_spec *spec = codec->spec; | |
989 | hda_nid_t nid; | |
990 | int i; | |
991 | ||
992 | /* check the pins hardwired to audio widget */ | |
993 | for (i = 0; i < cfg->line_outs; i++) { | |
994 | nid = cfg->line_out_pins[i]; | |
995 | spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0, | |
996 | AC_VERB_GET_CONNECT_LIST, 0) & 0xff; | |
997 | } | |
998 | ||
82bc955f | 999 | spec->multiout.num_dacs = cfg->line_outs; |
c7d4b2fa M |
1000 | |
1001 | return 0; | |
1002 | } | |
1003 | ||
1004 | /* add playback controls from the parsed DAC table */ | |
19039bd0 TI |
1005 | static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, |
1006 | const struct auto_pin_cfg *cfg) | |
c7d4b2fa M |
1007 | { |
1008 | char name[32]; | |
19039bd0 TI |
1009 | static const char *chname[4] = { |
1010 | "Front", "Surround", NULL /*CLFE*/, "Side" | |
1011 | }; | |
c7d4b2fa M |
1012 | hda_nid_t nid; |
1013 | int i, err; | |
1014 | ||
1015 | for (i = 0; i < cfg->line_outs; i++) { | |
403d1944 | 1016 | if (!spec->multiout.dac_nids[i]) |
c7d4b2fa M |
1017 | continue; |
1018 | ||
1019 | nid = spec->multiout.dac_nids[i]; | |
1020 | ||
1021 | if (i == 2) { | |
1022 | /* Center/LFE */ | |
1023 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume", | |
1024 | HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0) | |
1025 | return err; | |
1026 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume", | |
1027 | HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0) | |
1028 | return err; | |
1029 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch", | |
1030 | HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0) | |
1031 | return err; | |
1032 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch", | |
1033 | HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0) | |
1034 | return err; | |
1035 | } else { | |
1036 | sprintf(name, "%s Playback Volume", chname[i]); | |
1037 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name, | |
1038 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) | |
1039 | return err; | |
1040 | sprintf(name, "%s Playback Switch", chname[i]); | |
1041 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name, | |
1042 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) | |
1043 | return err; | |
1044 | } | |
1045 | } | |
1046 | ||
403d1944 MP |
1047 | if (spec->line_switch) |
1048 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0) | |
1049 | return err; | |
1050 | ||
1051 | if (spec->mic_switch) | |
1052 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0) | |
1053 | return err; | |
1054 | ||
c7d4b2fa M |
1055 | return 0; |
1056 | } | |
1057 | ||
1058 | /* add playback controls for HP output */ | |
1059 | static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg) | |
1060 | { | |
1061 | struct sigmatel_spec *spec = codec->spec; | |
1062 | hda_nid_t pin = cfg->hp_pin; | |
1063 | hda_nid_t nid; | |
1064 | int i, err; | |
4e55096e | 1065 | unsigned int wid_caps; |
c7d4b2fa M |
1066 | |
1067 | if (! pin) | |
1068 | return 0; | |
1069 | ||
54d17403 | 1070 | wid_caps = get_wcaps(codec, pin); |
505cb341 | 1071 | if (wid_caps & AC_WCAP_UNSOL_CAP) |
82bc955f | 1072 | spec->hp_detect = 1; |
4e55096e | 1073 | |
c7d4b2fa M |
1074 | nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff; |
1075 | for (i = 0; i < cfg->line_outs; i++) { | |
1076 | if (! spec->multiout.dac_nids[i]) | |
1077 | continue; | |
1078 | if (spec->multiout.dac_nids[i] == nid) | |
1079 | return 0; | |
1080 | } | |
1081 | ||
1082 | spec->multiout.hp_nid = nid; | |
1083 | ||
1084 | /* control HP volume/switch on the output mixer amp */ | |
1085 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume", | |
1086 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) | |
1087 | return err; | |
1088 | if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch", | |
1089 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) | |
1090 | return err; | |
1091 | ||
1092 | return 0; | |
1093 | } | |
1094 | ||
1095 | /* create playback/capture controls for input pins */ | |
1096 | static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) | |
1097 | { | |
1098 | struct sigmatel_spec *spec = codec->spec; | |
c7d4b2fa M |
1099 | struct hda_input_mux *imux = &spec->private_imux; |
1100 | hda_nid_t con_lst[HDA_MAX_NUM_INPUTS]; | |
1101 | int i, j, k; | |
1102 | ||
1103 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
1104 | int index = -1; | |
1105 | if (cfg->input_pins[i]) { | |
4a471b7d | 1106 | imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; |
c7d4b2fa M |
1107 | |
1108 | for (j=0; j<spec->num_muxes; j++) { | |
1109 | int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS); | |
1110 | for (k=0; k<num_cons; k++) | |
1111 | if (con_lst[k] == cfg->input_pins[i]) { | |
1112 | index = k; | |
1113 | break; | |
1114 | } | |
1115 | if (index >= 0) | |
1116 | break; | |
1117 | } | |
1118 | imux->items[imux->num_items].index = index; | |
1119 | imux->num_items++; | |
1120 | } | |
1121 | } | |
1122 | ||
62fe78e9 SR |
1123 | if (imux->num_items == 1) { |
1124 | /* | |
1125 | * Set the current input for the muxes. | |
1126 | * The STAC9221 has two input muxes with identical source | |
1127 | * NID lists. Hopefully this won't get confused. | |
1128 | */ | |
1129 | for (i = 0; i < spec->num_muxes; i++) { | |
1130 | snd_hda_codec_write(codec, spec->mux_nids[i], 0, | |
1131 | AC_VERB_SET_CONNECT_SEL, | |
1132 | imux->items[0].index); | |
1133 | } | |
1134 | } | |
1135 | ||
c7d4b2fa M |
1136 | return 0; |
1137 | } | |
1138 | ||
c7d4b2fa M |
1139 | static void stac92xx_auto_init_multi_out(struct hda_codec *codec) |
1140 | { | |
1141 | struct sigmatel_spec *spec = codec->spec; | |
1142 | int i; | |
1143 | ||
1144 | for (i = 0; i < spec->autocfg.line_outs; i++) { | |
1145 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
1146 | stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | static void stac92xx_auto_init_hp_out(struct hda_codec *codec) | |
1151 | { | |
1152 | struct sigmatel_spec *spec = codec->spec; | |
1153 | hda_nid_t pin; | |
1154 | ||
1155 | pin = spec->autocfg.hp_pin; | |
1156 | if (pin) /* connect to front */ | |
1157 | stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); | |
1158 | } | |
1159 | ||
3cc08dc6 | 1160 | static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) |
c7d4b2fa M |
1161 | { |
1162 | struct sigmatel_spec *spec = codec->spec; | |
1163 | int err; | |
1164 | ||
df694daa | 1165 | if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) |
c7d4b2fa | 1166 | return err; |
82bc955f | 1167 | if (! spec->autocfg.line_outs) |
869264c4 | 1168 | return 0; /* can't find valid pin config */ |
19039bd0 | 1169 | |
403d1944 MP |
1170 | if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0) |
1171 | return err; | |
19039bd0 TI |
1172 | if (spec->multiout.num_dacs == 0) |
1173 | if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0) | |
1174 | return err; | |
c7d4b2fa M |
1175 | |
1176 | if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 || | |
1177 | (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 || | |
1178 | (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0) | |
1179 | return err; | |
1180 | ||
1181 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
403d1944 | 1182 | if (spec->multiout.max_channels > 2) |
c7d4b2fa | 1183 | spec->surr_switch = 1; |
c7d4b2fa | 1184 | |
82bc955f | 1185 | if (spec->autocfg.dig_out_pin) |
3cc08dc6 | 1186 | spec->multiout.dig_out_nid = dig_out; |
82bc955f | 1187 | if (spec->autocfg.dig_in_pin) |
3cc08dc6 | 1188 | spec->dig_in_nid = dig_in; |
c7d4b2fa M |
1189 | |
1190 | if (spec->kctl_alloc) | |
1191 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; | |
1192 | ||
1193 | spec->input_mux = &spec->private_imux; | |
1194 | ||
1195 | return 1; | |
1196 | } | |
1197 | ||
82bc955f TI |
1198 | /* add playback controls for HP output */ |
1199 | static int stac9200_auto_create_hp_ctls(struct hda_codec *codec, | |
1200 | struct auto_pin_cfg *cfg) | |
1201 | { | |
1202 | struct sigmatel_spec *spec = codec->spec; | |
1203 | hda_nid_t pin = cfg->hp_pin; | |
1204 | unsigned int wid_caps; | |
1205 | ||
1206 | if (! pin) | |
1207 | return 0; | |
1208 | ||
1209 | wid_caps = get_wcaps(codec, pin); | |
505cb341 | 1210 | if (wid_caps & AC_WCAP_UNSOL_CAP) |
82bc955f | 1211 | spec->hp_detect = 1; |
82bc955f TI |
1212 | |
1213 | return 0; | |
1214 | } | |
1215 | ||
c7d4b2fa M |
1216 | static int stac9200_parse_auto_config(struct hda_codec *codec) |
1217 | { | |
1218 | struct sigmatel_spec *spec = codec->spec; | |
1219 | int err; | |
1220 | ||
df694daa | 1221 | if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) |
c7d4b2fa M |
1222 | return err; |
1223 | ||
1224 | if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0) | |
1225 | return err; | |
1226 | ||
82bc955f TI |
1227 | if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0) |
1228 | return err; | |
1229 | ||
1230 | if (spec->autocfg.dig_out_pin) | |
c7d4b2fa | 1231 | spec->multiout.dig_out_nid = 0x05; |
82bc955f | 1232 | if (spec->autocfg.dig_in_pin) |
c7d4b2fa | 1233 | spec->dig_in_nid = 0x04; |
c7d4b2fa M |
1234 | |
1235 | if (spec->kctl_alloc) | |
1236 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; | |
1237 | ||
1238 | spec->input_mux = &spec->private_imux; | |
1239 | ||
1240 | return 1; | |
1241 | } | |
1242 | ||
62fe78e9 SR |
1243 | /* |
1244 | * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a | |
1245 | * funky external mute control using GPIO pins. | |
1246 | */ | |
1247 | ||
1248 | static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted) | |
1249 | { | |
1250 | unsigned int gpiostate, gpiomask, gpiodir; | |
1251 | ||
1252 | gpiostate = snd_hda_codec_read(codec, codec->afg, 0, | |
1253 | AC_VERB_GET_GPIO_DATA, 0); | |
1254 | ||
1255 | if (!muted) | |
1256 | gpiostate |= (1 << pin); | |
1257 | else | |
1258 | gpiostate &= ~(1 << pin); | |
1259 | ||
1260 | gpiomask = snd_hda_codec_read(codec, codec->afg, 0, | |
1261 | AC_VERB_GET_GPIO_MASK, 0); | |
1262 | gpiomask |= (1 << pin); | |
1263 | ||
1264 | gpiodir = snd_hda_codec_read(codec, codec->afg, 0, | |
1265 | AC_VERB_GET_GPIO_DIRECTION, 0); | |
1266 | gpiodir |= (1 << pin); | |
1267 | ||
1268 | /* AppleHDA seems to do this -- WTF is this verb?? */ | |
1269 | snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); | |
1270 | ||
1271 | snd_hda_codec_write(codec, codec->afg, 0, | |
1272 | AC_VERB_SET_GPIO_MASK, gpiomask); | |
1273 | snd_hda_codec_write(codec, codec->afg, 0, | |
1274 | AC_VERB_SET_GPIO_DIRECTION, gpiodir); | |
1275 | ||
1276 | msleep(1); | |
1277 | ||
1278 | snd_hda_codec_write(codec, codec->afg, 0, | |
1279 | AC_VERB_SET_GPIO_DATA, gpiostate); | |
1280 | } | |
1281 | ||
c7d4b2fa M |
1282 | static int stac92xx_init(struct hda_codec *codec) |
1283 | { | |
1284 | struct sigmatel_spec *spec = codec->spec; | |
82bc955f TI |
1285 | struct auto_pin_cfg *cfg = &spec->autocfg; |
1286 | int i; | |
c7d4b2fa | 1287 | |
c7d4b2fa M |
1288 | snd_hda_sequence_write(codec, spec->init); |
1289 | ||
82bc955f TI |
1290 | /* set up pins */ |
1291 | if (spec->hp_detect) { | |
505cb341 TI |
1292 | /* Enable unsolicited responses on the HP widget */ |
1293 | snd_hda_codec_write(codec, cfg->hp_pin, 0, | |
1294 | AC_VERB_SET_UNSOLICITED_ENABLE, | |
1295 | STAC_UNSOL_ENABLE); | |
82bc955f TI |
1296 | /* fake event to set up pins */ |
1297 | codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); | |
68a6abd9 TD |
1298 | /* enable the headphones by default. If/when unsol_event detection works, this will be ignored */ |
1299 | stac92xx_auto_init_hp_out(codec); | |
82bc955f TI |
1300 | } else { |
1301 | stac92xx_auto_init_multi_out(codec); | |
1302 | stac92xx_auto_init_hp_out(codec); | |
1303 | } | |
1304 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
c960a03b TI |
1305 | hda_nid_t nid = cfg->input_pins[i]; |
1306 | if (nid) { | |
1307 | unsigned int pinctl = AC_PINCTL_IN_EN; | |
1308 | if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) | |
1309 | pinctl |= stac92xx_get_vref(codec, nid); | |
1310 | stac92xx_auto_set_pinctl(codec, nid, pinctl); | |
1311 | } | |
82bc955f TI |
1312 | } |
1313 | if (cfg->dig_out_pin) | |
1314 | stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, | |
1315 | AC_PINCTL_OUT_EN); | |
1316 | if (cfg->dig_in_pin) | |
1317 | stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin, | |
1318 | AC_PINCTL_IN_EN); | |
1319 | ||
62fe78e9 SR |
1320 | if (spec->gpio_mute) { |
1321 | stac922x_gpio_mute(codec, 0, 0); | |
1322 | stac922x_gpio_mute(codec, 1, 0); | |
1323 | } | |
1324 | ||
c7d4b2fa M |
1325 | return 0; |
1326 | } | |
1327 | ||
2f2f4251 M |
1328 | static void stac92xx_free(struct hda_codec *codec) |
1329 | { | |
c7d4b2fa M |
1330 | struct sigmatel_spec *spec = codec->spec; |
1331 | int i; | |
1332 | ||
1333 | if (! spec) | |
1334 | return; | |
1335 | ||
1336 | if (spec->kctl_alloc) { | |
1337 | for (i = 0; i < spec->num_kctl_used; i++) | |
1338 | kfree(spec->kctl_alloc[i].name); | |
1339 | kfree(spec->kctl_alloc); | |
1340 | } | |
1341 | ||
11b44bbd RF |
1342 | if (spec->bios_pin_configs) |
1343 | kfree(spec->bios_pin_configs); | |
1344 | ||
c7d4b2fa | 1345 | kfree(spec); |
2f2f4251 M |
1346 | } |
1347 | ||
4e55096e M |
1348 | static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, |
1349 | unsigned int flag) | |
1350 | { | |
1351 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, | |
1352 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); | |
1353 | snd_hda_codec_write(codec, nid, 0, | |
1354 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1355 | pin_ctl | flag); | |
1356 | } | |
1357 | ||
1358 | static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, | |
1359 | unsigned int flag) | |
1360 | { | |
1361 | unsigned int pin_ctl = snd_hda_codec_read(codec, nid, | |
1362 | 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); | |
1363 | snd_hda_codec_write(codec, nid, 0, | |
1364 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1365 | pin_ctl & ~flag); | |
1366 | } | |
1367 | ||
1368 | static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res) | |
1369 | { | |
1370 | struct sigmatel_spec *spec = codec->spec; | |
1371 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
1372 | int i, presence; | |
1373 | ||
1374 | if ((res >> 26) != STAC_HP_EVENT) | |
1375 | return; | |
1376 | ||
1377 | presence = snd_hda_codec_read(codec, cfg->hp_pin, 0, | |
1378 | AC_VERB_GET_PIN_SENSE, 0x00) >> 31; | |
1379 | ||
1380 | if (presence) { | |
1381 | /* disable lineouts, enable hp */ | |
1382 | for (i = 0; i < cfg->line_outs; i++) | |
1383 | stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], | |
1384 | AC_PINCTL_OUT_EN); | |
1385 | stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN); | |
1386 | } else { | |
1387 | /* enable lineouts, disable hp */ | |
1388 | for (i = 0; i < cfg->line_outs; i++) | |
1389 | stac92xx_set_pinctl(codec, cfg->line_out_pins[i], | |
1390 | AC_PINCTL_OUT_EN); | |
1391 | stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN); | |
1392 | } | |
1393 | } | |
1394 | ||
ff6fdc37 M |
1395 | #ifdef CONFIG_PM |
1396 | static int stac92xx_resume(struct hda_codec *codec) | |
1397 | { | |
1398 | struct sigmatel_spec *spec = codec->spec; | |
1399 | int i; | |
1400 | ||
1401 | stac92xx_init(codec); | |
11b44bbd | 1402 | stac92xx_set_config_regs(codec); |
ff6fdc37 M |
1403 | for (i = 0; i < spec->num_mixers; i++) |
1404 | snd_hda_resume_ctls(codec, spec->mixers[i]); | |
1405 | if (spec->multiout.dig_out_nid) | |
1406 | snd_hda_resume_spdif_out(codec); | |
1407 | if (spec->dig_in_nid) | |
1408 | snd_hda_resume_spdif_in(codec); | |
1409 | ||
1410 | return 0; | |
1411 | } | |
1412 | #endif | |
1413 | ||
2f2f4251 M |
1414 | static struct hda_codec_ops stac92xx_patch_ops = { |
1415 | .build_controls = stac92xx_build_controls, | |
1416 | .build_pcms = stac92xx_build_pcms, | |
1417 | .init = stac92xx_init, | |
1418 | .free = stac92xx_free, | |
4e55096e | 1419 | .unsol_event = stac92xx_unsol_event, |
ff6fdc37 M |
1420 | #ifdef CONFIG_PM |
1421 | .resume = stac92xx_resume, | |
1422 | #endif | |
2f2f4251 M |
1423 | }; |
1424 | ||
1425 | static int patch_stac9200(struct hda_codec *codec) | |
1426 | { | |
1427 | struct sigmatel_spec *spec; | |
c7d4b2fa | 1428 | int err; |
2f2f4251 | 1429 | |
e560d8d8 | 1430 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
2f2f4251 M |
1431 | if (spec == NULL) |
1432 | return -ENOMEM; | |
1433 | ||
1434 | codec->spec = spec; | |
11b44bbd RF |
1435 | spec->num_pins = 8; |
1436 | spec->pin_nids = stac9200_pin_nids; | |
403d1944 | 1437 | spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl); |
11b44bbd RF |
1438 | if (spec->board_config < 0) { |
1439 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); | |
1440 | err = stac92xx_save_bios_config_regs(codec); | |
1441 | if (err < 0) { | |
1442 | stac92xx_free(codec); | |
1443 | return err; | |
1444 | } | |
1445 | spec->pin_configs = spec->bios_pin_configs; | |
1446 | } else { | |
403d1944 MP |
1447 | spec->pin_configs = stac9200_brd_tbl[spec->board_config]; |
1448 | stac92xx_set_config_regs(codec); | |
1449 | } | |
2f2f4251 M |
1450 | |
1451 | spec->multiout.max_channels = 2; | |
1452 | spec->multiout.num_dacs = 1; | |
1453 | spec->multiout.dac_nids = stac9200_dac_nids; | |
1454 | spec->adc_nids = stac9200_adc_nids; | |
1455 | spec->mux_nids = stac9200_mux_nids; | |
dabbed6f | 1456 | spec->num_muxes = 1; |
c7d4b2fa M |
1457 | |
1458 | spec->init = stac9200_core_init; | |
2f2f4251 | 1459 | spec->mixer = stac9200_mixer; |
c7d4b2fa M |
1460 | |
1461 | err = stac9200_parse_auto_config(codec); | |
1462 | if (err < 0) { | |
1463 | stac92xx_free(codec); | |
1464 | return err; | |
1465 | } | |
2f2f4251 M |
1466 | |
1467 | codec->patch_ops = stac92xx_patch_ops; | |
1468 | ||
1469 | return 0; | |
1470 | } | |
1471 | ||
1472 | static int patch_stac922x(struct hda_codec *codec) | |
1473 | { | |
1474 | struct sigmatel_spec *spec; | |
c7d4b2fa | 1475 | int err; |
2f2f4251 | 1476 | |
e560d8d8 | 1477 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
2f2f4251 M |
1478 | if (spec == NULL) |
1479 | return -ENOMEM; | |
1480 | ||
1481 | codec->spec = spec; | |
11b44bbd RF |
1482 | spec->num_pins = 10; |
1483 | spec->pin_nids = stac922x_pin_nids; | |
403d1944 | 1484 | spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl); |
11b44bbd RF |
1485 | if (spec->board_config < 0) { |
1486 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " | |
1487 | "using BIOS defaults\n"); | |
1488 | err = stac92xx_save_bios_config_regs(codec); | |
1489 | if (err < 0) { | |
1490 | stac92xx_free(codec); | |
1491 | return err; | |
1492 | } | |
1493 | spec->pin_configs = spec->bios_pin_configs; | |
1494 | } else if (stac922x_brd_tbl[spec->board_config] != NULL) { | |
403d1944 MP |
1495 | spec->pin_configs = stac922x_brd_tbl[spec->board_config]; |
1496 | stac92xx_set_config_regs(codec); | |
1497 | } | |
2f2f4251 | 1498 | |
c7d4b2fa M |
1499 | spec->adc_nids = stac922x_adc_nids; |
1500 | spec->mux_nids = stac922x_mux_nids; | |
1501 | spec->num_muxes = 2; | |
1502 | ||
1503 | spec->init = stac922x_core_init; | |
2f2f4251 | 1504 | spec->mixer = stac922x_mixer; |
c7d4b2fa M |
1505 | |
1506 | spec->multiout.dac_nids = spec->dac_nids; | |
19039bd0 | 1507 | |
3cc08dc6 MP |
1508 | err = stac92xx_parse_auto_config(codec, 0x08, 0x09); |
1509 | if (err < 0) { | |
1510 | stac92xx_free(codec); | |
1511 | return err; | |
1512 | } | |
1513 | ||
62fe78e9 SR |
1514 | if (spec->board_config == STAC_MACMINI) |
1515 | spec->gpio_mute = 1; | |
1516 | ||
3cc08dc6 MP |
1517 | codec->patch_ops = stac92xx_patch_ops; |
1518 | ||
1519 | return 0; | |
1520 | } | |
1521 | ||
1522 | static int patch_stac927x(struct hda_codec *codec) | |
1523 | { | |
1524 | struct sigmatel_spec *spec; | |
1525 | int err; | |
1526 | ||
1527 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1528 | if (spec == NULL) | |
1529 | return -ENOMEM; | |
1530 | ||
1531 | codec->spec = spec; | |
11b44bbd RF |
1532 | spec->num_pins = 14; |
1533 | spec->pin_nids = stac927x_pin_nids; | |
3cc08dc6 | 1534 | spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl); |
11b44bbd | 1535 | if (spec->board_config < 0) { |
3cc08dc6 | 1536 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n"); |
11b44bbd RF |
1537 | err = stac92xx_save_bios_config_regs(codec); |
1538 | if (err < 0) { | |
1539 | stac92xx_free(codec); | |
1540 | return err; | |
1541 | } | |
1542 | spec->pin_configs = spec->bios_pin_configs; | |
1543 | } else if (stac927x_brd_tbl[spec->board_config] != NULL) { | |
3cc08dc6 MP |
1544 | spec->pin_configs = stac927x_brd_tbl[spec->board_config]; |
1545 | stac92xx_set_config_regs(codec); | |
1546 | } | |
1547 | ||
81d3dbde TD |
1548 | switch (spec->board_config) { |
1549 | case STAC_D965_2112: | |
1550 | spec->adc_nids = stac927x_adc_nids; | |
1551 | spec->mux_nids = stac927x_mux_nids; | |
1552 | spec->num_muxes = 3; | |
1553 | spec->init = d965_2112_core_init; | |
1554 | spec->mixer = stac9227_mixer; | |
1555 | break; | |
1556 | case STAC_D965_284B: | |
1557 | spec->adc_nids = stac9227_adc_nids; | |
1558 | spec->mux_nids = stac9227_mux_nids; | |
1559 | spec->num_muxes = 2; | |
1560 | spec->init = stac9227_core_init; | |
1561 | spec->mixer = stac9227_mixer; | |
1562 | break; | |
1563 | default: | |
1564 | spec->adc_nids = stac927x_adc_nids; | |
1565 | spec->mux_nids = stac927x_mux_nids; | |
1566 | spec->num_muxes = 3; | |
1567 | spec->init = stac927x_core_init; | |
1568 | spec->mixer = stac927x_mixer; | |
1569 | } | |
3cc08dc6 MP |
1570 | |
1571 | spec->multiout.dac_nids = spec->dac_nids; | |
1572 | ||
1573 | err = stac92xx_parse_auto_config(codec, 0x1e, 0x20); | |
c7d4b2fa M |
1574 | if (err < 0) { |
1575 | stac92xx_free(codec); | |
1576 | return err; | |
1577 | } | |
2f2f4251 M |
1578 | |
1579 | codec->patch_ops = stac92xx_patch_ops; | |
1580 | ||
1581 | return 0; | |
1582 | } | |
1583 | ||
f3302a59 MP |
1584 | static int patch_stac9205(struct hda_codec *codec) |
1585 | { | |
1586 | struct sigmatel_spec *spec; | |
1587 | int err; | |
1588 | ||
1589 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1590 | if (spec == NULL) | |
1591 | return -ENOMEM; | |
1592 | ||
1593 | codec->spec = spec; | |
11b44bbd RF |
1594 | spec->num_pins = 14; |
1595 | spec->pin_nids = stac9205_pin_nids; | |
f3302a59 | 1596 | spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl); |
11b44bbd RF |
1597 | if (spec->board_config < 0) { |
1598 | snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); | |
1599 | err = stac92xx_save_bios_config_regs(codec); | |
1600 | if (err < 0) { | |
1601 | stac92xx_free(codec); | |
1602 | return err; | |
1603 | } | |
1604 | spec->pin_configs = spec->bios_pin_configs; | |
1605 | } else { | |
f3302a59 MP |
1606 | spec->pin_configs = stac9205_brd_tbl[spec->board_config]; |
1607 | stac92xx_set_config_regs(codec); | |
1608 | } | |
1609 | ||
1610 | spec->adc_nids = stac9205_adc_nids; | |
1611 | spec->mux_nids = stac9205_mux_nids; | |
1612 | spec->num_muxes = 3; | |
1613 | ||
1614 | spec->init = stac9205_core_init; | |
1615 | spec->mixer = stac9205_mixer; | |
1616 | ||
1617 | spec->multiout.dac_nids = spec->dac_nids; | |
1618 | ||
1619 | err = stac92xx_parse_auto_config(codec, 0x1f, 0x20); | |
1620 | if (err < 0) { | |
1621 | stac92xx_free(codec); | |
1622 | return err; | |
1623 | } | |
1624 | ||
1625 | codec->patch_ops = stac92xx_patch_ops; | |
1626 | ||
1627 | return 0; | |
1628 | } | |
1629 | ||
db064e50 | 1630 | /* |
6d859065 | 1631 | * STAC9872 hack |
db064e50 TI |
1632 | */ |
1633 | ||
99ccc560 | 1634 | /* static config for Sony VAIO FE550G and Sony VAIO AR */ |
db064e50 TI |
1635 | static hda_nid_t vaio_dacs[] = { 0x2 }; |
1636 | #define VAIO_HP_DAC 0x5 | |
1637 | static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ }; | |
1638 | static hda_nid_t vaio_mux_nids[] = { 0x15 }; | |
1639 | ||
1640 | static struct hda_input_mux vaio_mux = { | |
1641 | .num_items = 2, | |
1642 | .items = { | |
d773781c TI |
1643 | /* { "HP", 0x0 }, */ |
1644 | { "Line", 0x1 }, | |
db064e50 TI |
1645 | { "Mic", 0x2 }, |
1646 | { "PCM", 0x3 }, | |
1647 | } | |
1648 | }; | |
1649 | ||
1650 | static struct hda_verb vaio_init[] = { | |
1651 | {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */ | |
1652 | {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */ | |
1653 | {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */ | |
1654 | {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */ | |
1655 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */ | |
1656 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */ | |
1657 | {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */ | |
1658 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */ | |
1659 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */ | |
1660 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */ | |
1661 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ | |
1662 | {} | |
1663 | }; | |
1664 | ||
6d859065 GM |
1665 | static struct hda_verb vaio_ar_init[] = { |
1666 | {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */ | |
1667 | {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */ | |
1668 | {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */ | |
1669 | {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */ | |
1670 | /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */ | |
1671 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */ | |
1672 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */ | |
1673 | {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */ | |
1674 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */ | |
1675 | /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */ | |
1676 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */ | |
1677 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */ | |
1678 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ | |
1679 | {} | |
1680 | }; | |
1681 | ||
db064e50 TI |
1682 | /* bind volumes of both NID 0x02 and 0x05 */ |
1683 | static int vaio_master_vol_put(struct snd_kcontrol *kcontrol, | |
1684 | struct snd_ctl_elem_value *ucontrol) | |
1685 | { | |
1686 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1687 | long *valp = ucontrol->value.integer.value; | |
1688 | int change; | |
1689 | ||
1690 | change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0, | |
1691 | 0x7f, valp[0] & 0x7f); | |
1692 | change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0, | |
1693 | 0x7f, valp[1] & 0x7f); | |
1694 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, | |
1695 | 0x7f, valp[0] & 0x7f); | |
1696 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, | |
1697 | 0x7f, valp[1] & 0x7f); | |
1698 | return change; | |
1699 | } | |
1700 | ||
1701 | /* bind volumes of both NID 0x02 and 0x05 */ | |
1702 | static int vaio_master_sw_put(struct snd_kcontrol *kcontrol, | |
1703 | struct snd_ctl_elem_value *ucontrol) | |
1704 | { | |
1705 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1706 | long *valp = ucontrol->value.integer.value; | |
1707 | int change; | |
1708 | ||
1709 | change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0, | |
a9393d70 | 1710 | 0x80, (valp[0] ? 0 : 0x80)); |
db064e50 | 1711 | change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0, |
a9393d70 | 1712 | 0x80, (valp[1] ? 0 : 0x80)); |
db064e50 | 1713 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, |
a9393d70 | 1714 | 0x80, (valp[0] ? 0 : 0x80)); |
db064e50 | 1715 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, |
a9393d70 | 1716 | 0x80, (valp[1] ? 0 : 0x80)); |
db064e50 TI |
1717 | return change; |
1718 | } | |
1719 | ||
1720 | static struct snd_kcontrol_new vaio_mixer[] = { | |
1721 | { | |
1722 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1723 | .name = "Master Playback Volume", | |
1724 | .info = snd_hda_mixer_amp_volume_info, | |
1725 | .get = snd_hda_mixer_amp_volume_get, | |
1726 | .put = vaio_master_vol_put, | |
c2566524 | 1727 | .tlv = { .c = snd_hda_mixer_amp_tlv }, |
db064e50 TI |
1728 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), |
1729 | }, | |
1730 | { | |
1731 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1732 | .name = "Master Playback Switch", | |
1733 | .info = snd_hda_mixer_amp_switch_info, | |
1734 | .get = snd_hda_mixer_amp_switch_get, | |
1735 | .put = vaio_master_sw_put, | |
1736 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), | |
1737 | }, | |
1738 | /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ | |
1739 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), | |
1740 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), | |
1741 | { | |
1742 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1743 | .name = "Capture Source", | |
1744 | .count = 1, | |
1745 | .info = stac92xx_mux_enum_info, | |
1746 | .get = stac92xx_mux_enum_get, | |
1747 | .put = stac92xx_mux_enum_put, | |
1748 | }, | |
1749 | {} | |
1750 | }; | |
1751 | ||
6d859065 GM |
1752 | static struct snd_kcontrol_new vaio_ar_mixer[] = { |
1753 | { | |
1754 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1755 | .name = "Master Playback Volume", | |
1756 | .info = snd_hda_mixer_amp_volume_info, | |
1757 | .get = snd_hda_mixer_amp_volume_get, | |
1758 | .put = vaio_master_vol_put, | |
1759 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), | |
1760 | }, | |
1761 | { | |
1762 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1763 | .name = "Master Playback Switch", | |
1764 | .info = snd_hda_mixer_amp_switch_info, | |
1765 | .get = snd_hda_mixer_amp_switch_get, | |
1766 | .put = vaio_master_sw_put, | |
1767 | .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), | |
1768 | }, | |
1769 | /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */ | |
1770 | HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), | |
1771 | HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), | |
1772 | /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT), | |
1773 | HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/ | |
1774 | { | |
1775 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1776 | .name = "Capture Source", | |
1777 | .count = 1, | |
1778 | .info = stac92xx_mux_enum_info, | |
1779 | .get = stac92xx_mux_enum_get, | |
1780 | .put = stac92xx_mux_enum_put, | |
1781 | }, | |
1782 | {} | |
1783 | }; | |
1784 | ||
1785 | static struct hda_codec_ops stac9872_patch_ops = { | |
db064e50 TI |
1786 | .build_controls = stac92xx_build_controls, |
1787 | .build_pcms = stac92xx_build_pcms, | |
1788 | .init = stac92xx_init, | |
1789 | .free = stac92xx_free, | |
1790 | #ifdef CONFIG_PM | |
1791 | .resume = stac92xx_resume, | |
1792 | #endif | |
1793 | }; | |
1794 | ||
6d859065 GM |
1795 | enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */ |
1796 | CXD9872RD_VAIO, | |
1797 | /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */ | |
1798 | STAC9872AK_VAIO, | |
1799 | /* Unknown. id=0x83847661 and subsys=0x104D1200. */ | |
1800 | STAC9872K_VAIO, | |
1801 | /* AR Series. id=0x83847664 and subsys=104D1300 */ | |
1802 | CXD9872AKD_VAIO | |
1803 | }; | |
1804 | ||
1805 | static struct hda_board_config stac9872_cfg_tbl[] = { | |
1806 | { .modelname = "vaio", .config = CXD9872RD_VAIO }, | |
1807 | { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO }, | |
db064e50 | 1808 | { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6, |
6d859065 | 1809 | .config = CXD9872RD_VAIO }, |
db064e50 | 1810 | { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef, |
6d859065 | 1811 | .config = CXD9872RD_VAIO }, |
99ccc560 | 1812 | { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd, |
6d859065 | 1813 | .config = CXD9872AKD_VAIO }, |
db064e50 TI |
1814 | {} |
1815 | }; | |
1816 | ||
6d859065 | 1817 | static int patch_stac9872(struct hda_codec *codec) |
db064e50 TI |
1818 | { |
1819 | struct sigmatel_spec *spec; | |
1820 | int board_config; | |
1821 | ||
6d859065 | 1822 | board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl); |
db064e50 TI |
1823 | if (board_config < 0) |
1824 | /* unknown config, let generic-parser do its job... */ | |
1825 | return snd_hda_parse_generic_codec(codec); | |
1826 | ||
1827 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
1828 | if (spec == NULL) | |
1829 | return -ENOMEM; | |
1830 | ||
1831 | codec->spec = spec; | |
1832 | switch (board_config) { | |
6d859065 GM |
1833 | case CXD9872RD_VAIO: |
1834 | case STAC9872AK_VAIO: | |
1835 | case STAC9872K_VAIO: | |
db064e50 TI |
1836 | spec->mixer = vaio_mixer; |
1837 | spec->init = vaio_init; | |
1838 | spec->multiout.max_channels = 2; | |
1839 | spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs); | |
1840 | spec->multiout.dac_nids = vaio_dacs; | |
1841 | spec->multiout.hp_nid = VAIO_HP_DAC; | |
1842 | spec->num_adcs = ARRAY_SIZE(vaio_adcs); | |
1843 | spec->adc_nids = vaio_adcs; | |
1844 | spec->input_mux = &vaio_mux; | |
1845 | spec->mux_nids = vaio_mux_nids; | |
1846 | break; | |
6d859065 GM |
1847 | |
1848 | case CXD9872AKD_VAIO: | |
1849 | spec->mixer = vaio_ar_mixer; | |
1850 | spec->init = vaio_ar_init; | |
1851 | spec->multiout.max_channels = 2; | |
1852 | spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs); | |
1853 | spec->multiout.dac_nids = vaio_dacs; | |
1854 | spec->multiout.hp_nid = VAIO_HP_DAC; | |
1855 | spec->num_adcs = ARRAY_SIZE(vaio_adcs); | |
1856 | spec->adc_nids = vaio_adcs; | |
1857 | spec->input_mux = &vaio_mux; | |
1858 | spec->mux_nids = vaio_mux_nids; | |
1859 | break; | |
db064e50 TI |
1860 | } |
1861 | ||
6d859065 | 1862 | codec->patch_ops = stac9872_patch_ops; |
db064e50 TI |
1863 | return 0; |
1864 | } | |
1865 | ||
1866 | ||
2f2f4251 M |
1867 | /* |
1868 | * patch entries | |
1869 | */ | |
1870 | struct hda_codec_preset snd_hda_preset_sigmatel[] = { | |
1871 | { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 }, | |
1872 | { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x }, | |
1873 | { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x }, | |
1874 | { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x }, | |
1875 | { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x }, | |
1876 | { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x }, | |
1877 | { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x }, | |
22a27c7f MP |
1878 | { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x }, |
1879 | { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x }, | |
1880 | { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x }, | |
1881 | { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x }, | |
1882 | { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x }, | |
1883 | { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x }, | |
3cc08dc6 MP |
1884 | { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x }, |
1885 | { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x }, | |
1886 | { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x }, | |
1887 | { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x }, | |
1888 | { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x }, | |
1889 | { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x }, | |
1890 | { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x }, | |
1891 | { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x }, | |
1892 | { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x }, | |
1893 | { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x }, | |
6d859065 GM |
1894 | /* The following does not take into account .id=0x83847661 when subsys = |
1895 | * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are | |
1896 | * currently not fully supported. | |
1897 | */ | |
1898 | { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 }, | |
1899 | { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 }, | |
1900 | { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 }, | |
f3302a59 MP |
1901 | { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 }, |
1902 | { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 }, | |
1903 | { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 }, | |
1904 | { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 }, | |
1905 | { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 }, | |
1906 | { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 }, | |
1907 | { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 }, | |
1908 | { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 }, | |
2f2f4251 M |
1909 | {} /* terminator */ |
1910 | }; |