blob: 92f48a72585345d597d26adf7b0e4ef5db79942c [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
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.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
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>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
36
Matt4e550962005-07-04 17:51:39 +020037#define NUM_CONTROL_ALLOC 32
38#define STAC_HP_EVENT 0x37
Matt4e550962005-07-04 17:51:39 +020039
Matt Porter403d1942005-11-29 15:00:51 +010040#define STAC_REF 0
41#define STAC_D945GTP3 1
42#define STAC_D945GTP5 2
Sam Revitch62fe78e2006-05-10 15:09:17 +020043#define STAC_MACMINI 3
Tobin Davis93ed1502006-09-01 21:03:12 +020044#define STAC_922X_MODELS 4 /* number of 922x models */
45#define STAC_D965_3ST 4
46#define STAC_D965_5ST 5
47#define STAC_927X_MODELS 6 /* number of 922x models */
Matt Porter403d1942005-11-29 15:00:51 +010048
Matt2f2f4252005-04-13 14:45:30 +020049struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010050 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +020051 unsigned int num_mixers;
52
Matt Porter403d1942005-11-29 15:00:51 +010053 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +020054 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +010055 unsigned int line_switch: 1;
56 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +010057 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +010058 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +020059 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +020060
Matt2f2f4252005-04-13 14:45:30 +020061 /* playback */
62 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +010063 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +020064
65 /* capture */
66 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +020067 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +020068 hda_nid_t *mux_nids;
69 unsigned int num_muxes;
Mattdabbed62005-06-14 10:19:34 +020070 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +020071
Matt2f2f4252005-04-13 14:45:30 +020072 /* pin widgets */
73 hda_nid_t *pin_nids;
74 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +020075 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +020076 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +020077
78 /* codec specific stuff */
79 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010080 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +020081
82 /* capture source */
Mattc7d4b2f2005-06-27 14:59:41 +020083 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +010084 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +020085
Matt Porter403d1942005-11-29 15:00:51 +010086 /* i/o switches */
87 unsigned int io_switch[2];
Matt2f2f4252005-04-13 14:45:30 +020088
Mattc7d4b2f2005-06-27 14:59:41 +020089 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;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010094 struct snd_kcontrol_new *kctl_alloc;
Mattc7d4b2f2005-06-27 14:59:41 +020095 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +020096};
97
98static hda_nid_t stac9200_adc_nids[1] = {
99 0x03,
100};
101
102static hda_nid_t stac9200_mux_nids[1] = {
103 0x0c,
104};
105
106static hda_nid_t stac9200_dac_nids[1] = {
107 0x02,
108};
109
Matt2f2f4252005-04-13 14:45:30 +0200110static hda_nid_t stac922x_adc_nids[2] = {
111 0x06, 0x07,
112};
113
114static hda_nid_t stac922x_mux_nids[2] = {
115 0x12, 0x13,
116};
117
Matt Porter3cc08dc2006-01-23 15:27:49 +0100118static hda_nid_t stac927x_adc_nids[3] = {
119 0x07, 0x08, 0x09
120};
121
122static hda_nid_t stac927x_mux_nids[3] = {
123 0x15, 0x16, 0x17
124};
125
Matt Porterf3302a52006-07-31 12:49:34 +0200126static hda_nid_t stac9205_adc_nids[2] = {
127 0x12, 0x13
128};
129
130static hda_nid_t stac9205_mux_nids[2] = {
131 0x19, 0x1a
132};
133
Mattc7d4b2f2005-06-27 14:59:41 +0200134static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200135 0x08, 0x09, 0x0d, 0x0e,
136 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200137};
138
139static hda_nid_t stac922x_pin_nids[10] = {
140 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
141 0x0f, 0x10, 0x11, 0x15, 0x1b,
142};
143
Matt Porter3cc08dc2006-01-23 15:27:49 +0100144static hda_nid_t stac927x_pin_nids[14] = {
145 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
146 0x0f, 0x10, 0x11, 0x12, 0x13,
147 0x14, 0x21, 0x22, 0x23,
148};
149
Matt Porterf3302a52006-07-31 12:49:34 +0200150static hda_nid_t stac9205_pin_nids[12] = {
151 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
152 0x0f, 0x14, 0x16, 0x17, 0x18,
153 0x21, 0x22,
154
155};
156
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100157static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200158{
159 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
160 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200161 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200162}
163
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100164static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200165{
166 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
167 struct sigmatel_spec *spec = codec->spec;
168 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
169
170 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
171 return 0;
172}
173
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100174static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200175{
176 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
177 struct sigmatel_spec *spec = codec->spec;
178 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
179
Mattc7d4b2f2005-06-27 14:59:41 +0200180 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200181 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
182}
183
Mattc7d4b2f2005-06-27 14:59:41 +0200184static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200185 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200186 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200187 {}
188};
189
Mattc7d4b2f2005-06-27 14:59:41 +0200190static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200191 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200192 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200193 {}
194};
195
Tobin Davis93ed1502006-09-01 21:03:12 +0200196static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200197 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200198 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200199 /* unmute node 0x1b */
200 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
201 /* select node 0x03 as DAC */
202 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
203 {}
204};
205
Matt Porter3cc08dc2006-01-23 15:27:49 +0100206static struct hda_verb stac927x_core_init[] = {
207 /* set master volume and direct control */
208 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
209 {}
210};
211
Matt Porterf3302a52006-07-31 12:49:34 +0200212static struct hda_verb stac9205_core_init[] = {
213 /* set master volume and direct control */
214 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
215 {}
216};
217
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100218static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200219 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
220 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
221 {
222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
223 .name = "Input Source",
224 .count = 1,
225 .info = stac92xx_mux_enum_info,
226 .get = stac92xx_mux_enum_get,
227 .put = stac92xx_mux_enum_put,
228 },
229 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
230 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200231 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200232 { } /* end */
233};
234
Mattc7d4b2f2005-06-27 14:59:41 +0200235/* This needs to be generated dynamically based on sequence */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100236static struct snd_kcontrol_new stac922x_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200237 {
238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
239 .name = "Input Source",
240 .count = 1,
241 .info = stac92xx_mux_enum_info,
242 .get = stac92xx_mux_enum_get,
243 .put = stac92xx_mux_enum_put,
244 },
245 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwai0fd17082006-01-13 18:46:21 +0100246 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
Matt2f2f4252005-04-13 14:45:30 +0200247 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
248 { } /* end */
249};
250
Takashi Iwai19039bd2006-06-28 15:52:16 +0200251/* This needs to be generated dynamically based on sequence */
252static struct snd_kcontrol_new stac9227_mixer[] = {
253 {
254 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
255 .name = "Input Source",
256 .count = 1,
257 .info = stac92xx_mux_enum_info,
258 .get = stac92xx_mux_enum_get,
259 .put = stac92xx_mux_enum_put,
260 },
261 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
262 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
263 { } /* end */
264};
265
Matt Porter3cc08dc2006-01-23 15:27:49 +0100266static snd_kcontrol_new_t stac927x_mixer[] = {
267 {
268 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
269 .name = "Input Source",
270 .count = 1,
271 .info = stac92xx_mux_enum_info,
272 .get = stac92xx_mux_enum_get,
273 .put = stac92xx_mux_enum_put,
274 },
275 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
276 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
277 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
278 { } /* end */
279};
280
Matt Porterf3302a52006-07-31 12:49:34 +0200281static snd_kcontrol_new_t stac9205_mixer[] = {
282 {
283 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
284 .name = "Input Source",
285 .count = 1,
286 .info = stac92xx_mux_enum_info,
287 .get = stac92xx_mux_enum_get,
288 .put = stac92xx_mux_enum_put,
289 },
290 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
291 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
292 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
293 { } /* end */
294};
295
Matt2f2f4252005-04-13 14:45:30 +0200296static int stac92xx_build_controls(struct hda_codec *codec)
297{
298 struct sigmatel_spec *spec = codec->spec;
299 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200300 int i;
Matt2f2f4252005-04-13 14:45:30 +0200301
302 err = snd_hda_add_new_ctls(codec, spec->mixer);
303 if (err < 0)
304 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200305
306 for (i = 0; i < spec->num_mixers; i++) {
307 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
308 if (err < 0)
309 return err;
310 }
311
Mattdabbed62005-06-14 10:19:34 +0200312 if (spec->multiout.dig_out_nid) {
313 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
314 if (err < 0)
315 return err;
316 }
317 if (spec->dig_in_nid) {
318 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
319 if (err < 0)
320 return err;
321 }
322 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200323}
324
Matt Porter403d1942005-11-29 15:00:51 +0100325static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200326 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200327 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
328};
329
Matt Porter403d1942005-11-29 15:00:51 +0100330static unsigned int *stac9200_brd_tbl[] = {
331 ref9200_pin_configs,
332};
333
334static struct hda_board_config stac9200_cfg_tbl[] = {
335 { .modelname = "ref",
336 .pci_subvendor = PCI_VENDOR_ID_INTEL,
337 .pci_subdevice = 0x2668, /* DFI LanParty */
338 .config = STAC_REF },
339 {} /* terminator */
340};
341
342static unsigned int ref922x_pin_configs[10] = {
343 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
344 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200345 0x40000100, 0x40000100,
346};
347
Matt Porter403d1942005-11-29 15:00:51 +0100348static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100349 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100350 0x40000100, 0x40000100, 0x40000100, 0x40000100,
351 0x02a19120, 0x40000100,
352};
353
354static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100355 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
356 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100357 0x02a19320, 0x40000100,
358};
359
Takashi Iwai19039bd2006-06-28 15:52:16 +0200360static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
361 [STAC_REF] = ref922x_pin_configs,
362 [STAC_D945GTP3] = d945gtp3_pin_configs,
363 [STAC_D945GTP5] = d945gtp5_pin_configs,
Linus Torvalds7c3dec02006-07-10 22:21:43 -0700364 [STAC_MACMINI] = d945gtp5_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100365};
366
367static struct hda_board_config stac922x_cfg_tbl[] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200368 { .modelname = "5stack", .config = STAC_D945GTP5 },
369 { .modelname = "3stack", .config = STAC_D945GTP3 },
Matt Porter403d1942005-11-29 15:00:51 +0100370 { .modelname = "ref",
371 .pci_subvendor = PCI_VENDOR_ID_INTEL,
372 .pci_subdevice = 0x2668, /* DFI LanParty */
373 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis948a4db2006-08-22 19:43:46 +0200374 /* Intel 945G based systems */
Matt Porter403d1942005-11-29 15:00:51 +0100375 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
376 .pci_subdevice = 0x0101,
377 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
378 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Takashi Iwai353b9e62006-02-16 18:16:17 +0100379 .pci_subdevice = 0x0202,
Tobin Davis948a4db2006-08-22 19:43:46 +0200380 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100381 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200382 .pci_subdevice = 0x0606,
383 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
Takashi Iwai353b9e62006-02-16 18:16:17 +0100384 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Tobin Davis948a4db2006-08-22 19:43:46 +0200385 .pci_subdevice = 0x0601,
386 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
387 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
388 .pci_subdevice = 0x0111,
389 .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */
390 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
391 .pci_subdevice = 0x1115,
392 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
393 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
394 .pci_subdevice = 0x1116,
395 .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */
396 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
397 .pci_subdevice = 0x1117,
398 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
399 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
400 .pci_subdevice = 0x1118,
401 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
402 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
403 .pci_subdevice = 0x1119,
404 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
405 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
406 .pci_subdevice = 0x8826,
407 .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
408 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
409 .pci_subdevice = 0x5049,
410 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
411 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
412 .pci_subdevice = 0x5055,
413 .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
414 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
415 .pci_subdevice = 0x5048,
416 .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */
417 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
418 .pci_subdevice = 0x0110,
419 .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */
420 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
Matt Porter403d1942005-11-29 15:00:51 +0100421 .pci_subdevice = 0x0404,
422 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
423 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
424 .pci_subdevice = 0x0303,
425 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
426 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
427 .pci_subdevice = 0x0013,
428 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
Matt Porterd62c40e2006-01-23 15:26:27 +0100429 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
430 .pci_subdevice = 0x0417,
431 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
Tobin Davis948a4db2006-08-22 19:43:46 +0200432 /* Intel 945P based systems */
433 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
434 .pci_subdevice = 0x0b0b,
435 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */
436 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
437 .pci_subdevice = 0x0112,
438 .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */
439 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
440 .pci_subdevice = 0x0d0d,
441 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
442 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
443 .pci_subdevice = 0x0909,
444 .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */
445 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
446 .pci_subdevice = 0x0505,
447 .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
448 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
449 .pci_subdevice = 0x0707,
450 .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
451 /* other systems */
Sam Revitch62fe78e2006-05-10 15:09:17 +0200452 { .pci_subvendor = 0x8384,
453 .pci_subdevice = 0x7680,
454 .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
Matt Porter403d1942005-11-29 15:00:51 +0100455 {} /* terminator */
456};
457
Matt Porter3cc08dc2006-01-23 15:27:49 +0100458static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200459 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
460 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
461 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
462 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100463};
464
Tobin Davis93ed1502006-09-01 21:03:12 +0200465static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200466 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
467 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
468 0x40000100, 0x40000100, 0x40000100, 0x40000100,
469 0x40000100, 0x40000100
470};
471
Tobin Davis93ed1502006-09-01 21:03:12 +0200472static unsigned int d965_5st_pin_configs[14] = {
473 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
474 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
475 0x40000100, 0x40000100, 0x40000100, 0x01442070,
476 0x40000100, 0x40000100
477};
478
479static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200480 [STAC_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +0200481 [STAC_D965_3ST] = d965_3st_pin_configs,
482 [STAC_D965_5ST] = d965_5st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100483};
484
485static struct hda_board_config stac927x_cfg_tbl[] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200486 { .modelname = "5stack", .config = STAC_D965_5ST },
487 { .modelname = "3stack", .config = STAC_D965_3ST },
Matt Porter3cc08dc2006-01-23 15:27:49 +0100488 { .modelname = "ref",
489 .pci_subvendor = PCI_VENDOR_ID_INTEL,
490 .pci_subdevice = 0x2668, /* DFI LanParty */
491 .config = STAC_REF }, /* SigmaTel reference board */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200492 /* Intel 946 based systems */
493 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
494 .pci_subdevice = 0x3d01,
Tobin Davis93ed1502006-09-01 21:03:12 +0200495 .config = STAC_D965_3ST }, /* D946 configuration */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200496 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
497 .pci_subdevice = 0xa301,
Tobin Davis93ed1502006-09-01 21:03:12 +0200498 .config = STAC_D965_3ST }, /* Intel D946GZT - 3 stack */
499 /* 965 based 3 stack systems */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200500 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
501 .pci_subdevice = 0x2116,
Tobin Davis93ed1502006-09-01 21:03:12 +0200502 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200503 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
504 .pci_subdevice = 0x2115,
Tobin Davis93ed1502006-09-01 21:03:12 +0200505 .config = STAC_D965_3ST }, /* Intel DQ965WC - 3 Stack */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200506 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
507 .pci_subdevice = 0x2114,
Tobin Davis93ed1502006-09-01 21:03:12 +0200508 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200509 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
510 .pci_subdevice = 0x2113,
Tobin Davis93ed1502006-09-01 21:03:12 +0200511 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200512 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
513 .pci_subdevice = 0x2112,
Tobin Davis93ed1502006-09-01 21:03:12 +0200514 .config = STAC_D965_3ST }, /* Intel DG965MS - 3 Stack */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200515 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
516 .pci_subdevice = 0x2111,
Tobin Davis93ed1502006-09-01 21:03:12 +0200517 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200518 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
519 .pci_subdevice = 0x2110,
Tobin Davis93ed1502006-09-01 21:03:12 +0200520 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200521 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
522 .pci_subdevice = 0x2009,
Tobin Davis93ed1502006-09-01 21:03:12 +0200523 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200524 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
525 .pci_subdevice = 0x2008,
Tobin Davis93ed1502006-09-01 21:03:12 +0200526 .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200527 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
528 .pci_subdevice = 0x2007,
Tobin Davis93ed1502006-09-01 21:03:12 +0200529 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200530 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
531 .pci_subdevice = 0x2006,
Tobin Davis93ed1502006-09-01 21:03:12 +0200532 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200533 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
534 .pci_subdevice = 0x2005,
Tobin Davis93ed1502006-09-01 21:03:12 +0200535 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200536 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
537 .pci_subdevice = 0x2004,
Tobin Davis93ed1502006-09-01 21:03:12 +0200538 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200539 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
540 .pci_subdevice = 0x2003,
Tobin Davis93ed1502006-09-01 21:03:12 +0200541 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200542 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
543 .pci_subdevice = 0x2002,
Tobin Davis93ed1502006-09-01 21:03:12 +0200544 .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
Tobin Davis81d3dbd2006-08-22 19:44:45 +0200545 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
546 .pci_subdevice = 0x2001,
Tobin Davis93ed1502006-09-01 21:03:12 +0200547 .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
548 /* 965 based 5 stack systems */
549 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
550 .pci_subdevice = 0x2301,
551 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
552 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
553 .pci_subdevice = 0x2302,
554 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
555 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
556 .pci_subdevice = 0x2303,
557 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
558 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
559 .pci_subdevice = 0x2304,
560 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
561 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
562 .pci_subdevice = 0x2305,
563 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
564 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
565 .pci_subdevice = 0x2501,
566 .config = STAC_D965_5ST }, /* Intel DG965MQ - 5 Stack */
567 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
568 .pci_subdevice = 0x2502,
569 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
570 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
571 .pci_subdevice = 0x2503,
572 .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
573 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
574 .pci_subdevice = 0x2504,
575 .config = STAC_D965_5ST }, /* Intel DQ965GF - 5 Stack */
Matt Porter3cc08dc2006-01-23 15:27:49 +0100576 {} /* terminator */
577};
578
Matt Porterf3302a52006-07-31 12:49:34 +0200579static unsigned int ref9205_pin_configs[12] = {
580 0x40000100, 0x40000100, 0x01016011, 0x01014010,
581 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
582 0x40000100, 0x40000100, 0x01441030, 0x01c41030
583};
584
585static unsigned int *stac9205_brd_tbl[] = {
586 ref9205_pin_configs,
587};
588
589static struct hda_board_config stac9205_cfg_tbl[] = {
590 { .modelname = "ref",
591 .pci_subvendor = PCI_VENDOR_ID_INTEL,
592 .pci_subdevice = 0x2668, /* DFI LanParty */
593 .config = STAC_REF }, /* SigmaTel reference board */
Takashi Iwai2c7782b2006-08-25 13:11:26 +0200594 /* Dell laptops have BIOS problem */
595 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5,
596 .config = STAC_REF }, /* Dell Inspiron 630m */
597 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2,
598 .config = STAC_REF }, /* Dell Latitude D620 */
599 { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb,
600 .config = STAC_REF }, /* Dell Latitude 120L */
Matt Porterf3302a52006-07-31 12:49:34 +0200601 {} /* terminator */
602};
603
Richard Fish11b44bb2006-08-23 18:31:34 +0200604static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
605{
606 int i;
607 struct sigmatel_spec *spec = codec->spec;
608
609 if (! spec->bios_pin_configs) {
610 spec->bios_pin_configs = kcalloc(spec->num_pins,
611 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
612 if (! spec->bios_pin_configs)
613 return -ENOMEM;
614 }
615
616 for (i = 0; i < spec->num_pins; i++) {
617 hda_nid_t nid = spec->pin_nids[i];
618 unsigned int pin_cfg;
619
620 pin_cfg = snd_hda_codec_read(codec, nid, 0,
621 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
622 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
623 nid, pin_cfg);
624 spec->bios_pin_configs[i] = pin_cfg;
625 }
626
627 return 0;
628}
629
Matt2f2f4252005-04-13 14:45:30 +0200630static void stac92xx_set_config_regs(struct hda_codec *codec)
631{
632 int i;
633 struct sigmatel_spec *spec = codec->spec;
634 unsigned int pin_cfg;
635
Richard Fish11b44bb2006-08-23 18:31:34 +0200636 if (! spec->pin_nids || ! spec->pin_configs)
637 return;
638
639 for (i = 0; i < spec->num_pins; i++) {
Matt2f2f4252005-04-13 14:45:30 +0200640 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
641 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
642 spec->pin_configs[i] & 0x000000ff);
643 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
644 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
645 (spec->pin_configs[i] & 0x0000ff00) >> 8);
646 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
647 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
648 (spec->pin_configs[i] & 0x00ff0000) >> 16);
649 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
650 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
651 spec->pin_configs[i] >> 24);
652 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
653 AC_VERB_GET_CONFIG_DEFAULT,
654 0x00);
Matt Porter403d1942005-11-29 15:00:51 +0100655 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
Matt2f2f4252005-04-13 14:45:30 +0200656 }
657}
Matt2f2f4252005-04-13 14:45:30 +0200658
Matt2f2f4252005-04-13 14:45:30 +0200659/*
660 * Analog playback callbacks
661 */
662static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
663 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100664 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200665{
666 struct sigmatel_spec *spec = codec->spec;
667 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
668}
669
670static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
671 struct hda_codec *codec,
672 unsigned int stream_tag,
673 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100674 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200675{
676 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +0100677 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +0200678}
679
680static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
681 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100682 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200683{
684 struct sigmatel_spec *spec = codec->spec;
685 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
686}
687
688/*
Mattdabbed62005-06-14 10:19:34 +0200689 * Digital playback callbacks
690 */
691static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
692 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100693 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200694{
695 struct sigmatel_spec *spec = codec->spec;
696 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
697}
698
699static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
700 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100701 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +0200702{
703 struct sigmatel_spec *spec = codec->spec;
704 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
705}
706
707
708/*
Matt2f2f4252005-04-13 14:45:30 +0200709 * Analog capture callbacks
710 */
711static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
712 struct hda_codec *codec,
713 unsigned int stream_tag,
714 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100715 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200716{
717 struct sigmatel_spec *spec = codec->spec;
718
719 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
720 stream_tag, 0, format);
721 return 0;
722}
723
724static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
725 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100726 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +0200727{
728 struct sigmatel_spec *spec = codec->spec;
729
730 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
731 return 0;
732}
733
Mattdabbed62005-06-14 10:19:34 +0200734static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
735 .substreams = 1,
736 .channels_min = 2,
737 .channels_max = 2,
738 /* NID is set in stac92xx_build_pcms */
739 .ops = {
740 .open = stac92xx_dig_playback_pcm_open,
741 .close = stac92xx_dig_playback_pcm_close
742 },
743};
744
745static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
746 .substreams = 1,
747 .channels_min = 2,
748 .channels_max = 2,
749 /* NID is set in stac92xx_build_pcms */
750};
751
Matt2f2f4252005-04-13 14:45:30 +0200752static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
753 .substreams = 1,
754 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +0200755 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +0200756 .nid = 0x02, /* NID to query formats and rates */
757 .ops = {
758 .open = stac92xx_playback_pcm_open,
759 .prepare = stac92xx_playback_pcm_prepare,
760 .cleanup = stac92xx_playback_pcm_cleanup
761 },
762};
763
Matt Porter3cc08dc2006-01-23 15:27:49 +0100764static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
765 .substreams = 1,
766 .channels_min = 2,
767 .channels_max = 2,
768 .nid = 0x06, /* NID to query formats and rates */
769 .ops = {
770 .open = stac92xx_playback_pcm_open,
771 .prepare = stac92xx_playback_pcm_prepare,
772 .cleanup = stac92xx_playback_pcm_cleanup
773 },
774};
775
Matt2f2f4252005-04-13 14:45:30 +0200776static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
777 .substreams = 2,
778 .channels_min = 2,
779 .channels_max = 2,
Matt Porter3cc08dc2006-01-23 15:27:49 +0100780 /* NID is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +0200781 .ops = {
782 .prepare = stac92xx_capture_pcm_prepare,
783 .cleanup = stac92xx_capture_pcm_cleanup
784 },
785};
786
787static int stac92xx_build_pcms(struct hda_codec *codec)
788{
789 struct sigmatel_spec *spec = codec->spec;
790 struct hda_pcm *info = spec->pcm_rec;
791
792 codec->num_pcms = 1;
793 codec->pcm_info = info;
794
Mattc7d4b2f2005-06-27 14:59:41 +0200795 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +0200796 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +0200797 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100798 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
799
800 if (spec->alt_switch) {
801 codec->num_pcms++;
802 info++;
803 info->name = "STAC92xx Analog Alt";
804 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
805 }
Matt2f2f4252005-04-13 14:45:30 +0200806
Mattdabbed62005-06-14 10:19:34 +0200807 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
808 codec->num_pcms++;
809 info++;
810 info->name = "STAC92xx Digital";
811 if (spec->multiout.dig_out_nid) {
812 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
813 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
814 }
815 if (spec->dig_in_nid) {
816 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
817 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
818 }
819 }
820
Matt2f2f4252005-04-13 14:45:30 +0200821 return 0;
822}
823
Takashi Iwaic960a032006-03-23 17:06:28 +0100824static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
825{
826 unsigned int pincap = snd_hda_param_read(codec, nid,
827 AC_PAR_PIN_CAP);
828 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
829 if (pincap & AC_PINCAP_VREF_100)
830 return AC_PINCTL_VREF_100;
831 if (pincap & AC_PINCAP_VREF_80)
832 return AC_PINCTL_VREF_80;
833 if (pincap & AC_PINCAP_VREF_50)
834 return AC_PINCTL_VREF_50;
835 if (pincap & AC_PINCAP_VREF_GRD)
836 return AC_PINCTL_VREF_GRD;
837 return 0;
838}
839
Matt Porter403d1942005-11-29 15:00:51 +0100840static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
841
842{
843 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
844}
845
846static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
847{
848 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
849 uinfo->count = 1;
850 uinfo->value.integer.min = 0;
851 uinfo->value.integer.max = 1;
852 return 0;
853}
854
855static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
856{
857 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
858 struct sigmatel_spec *spec = codec->spec;
859 int io_idx = kcontrol-> private_value & 0xff;
860
861 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
862 return 0;
863}
864
865static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
866{
867 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
868 struct sigmatel_spec *spec = codec->spec;
869 hda_nid_t nid = kcontrol->private_value >> 8;
870 int io_idx = kcontrol-> private_value & 0xff;
871 unsigned short val = ucontrol->value.integer.value[0];
872
873 spec->io_switch[io_idx] = val;
874
875 if (val)
876 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +0100877 else {
878 unsigned int pinctl = AC_PINCTL_IN_EN;
879 if (io_idx) /* set VREF for mic */
880 pinctl |= stac92xx_get_vref(codec, nid);
881 stac92xx_auto_set_pinctl(codec, nid, pinctl);
882 }
Matt Porter403d1942005-11-29 15:00:51 +0100883 return 1;
884}
885
886#define STAC_CODEC_IO_SWITCH(xname, xpval) \
887 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
888 .name = xname, \
889 .index = 0, \
890 .info = stac92xx_io_switch_info, \
891 .get = stac92xx_io_switch_get, \
892 .put = stac92xx_io_switch_put, \
893 .private_value = xpval, \
894 }
895
896
Mattc7d4b2f2005-06-27 14:59:41 +0200897enum {
898 STAC_CTL_WIDGET_VOL,
899 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +0100900 STAC_CTL_WIDGET_IO_SWITCH,
Mattc7d4b2f2005-06-27 14:59:41 +0200901};
902
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100903static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +0200904 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
905 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +0100906 STAC_CODEC_IO_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +0200907};
908
909/* add dynamic controls */
910static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
911{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100912 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +0200913
914 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
915 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
916
917 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
918 if (! knew)
919 return -ENOMEM;
920 if (spec->kctl_alloc) {
921 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
922 kfree(spec->kctl_alloc);
923 }
924 spec->kctl_alloc = knew;
925 spec->num_kctl_alloc = num;
926 }
927
928 knew = &spec->kctl_alloc[spec->num_kctl_used];
929 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +0200930 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +0200931 if (! knew->name)
932 return -ENOMEM;
933 knew->private_value = val;
934 spec->num_kctl_used++;
935 return 0;
936}
937
Matt Porter403d1942005-11-29 15:00:51 +0100938/* flag inputs as additional dynamic lineouts */
939static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
940{
941 struct sigmatel_spec *spec = codec->spec;
942
943 switch (cfg->line_outs) {
944 case 3:
945 /* add line-in as side */
946 if (cfg->input_pins[AUTO_PIN_LINE]) {
947 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
948 spec->line_switch = 1;
949 cfg->line_outs++;
950 }
951 break;
952 case 2:
953 /* add line-in as clfe and mic as side */
954 if (cfg->input_pins[AUTO_PIN_LINE]) {
955 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
956 spec->line_switch = 1;
957 cfg->line_outs++;
958 }
959 if (cfg->input_pins[AUTO_PIN_MIC]) {
960 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
961 spec->mic_switch = 1;
962 cfg->line_outs++;
963 }
964 break;
965 case 1:
966 /* add line-in as surr and mic as clfe */
967 if (cfg->input_pins[AUTO_PIN_LINE]) {
968 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
969 spec->line_switch = 1;
970 cfg->line_outs++;
971 }
972 if (cfg->input_pins[AUTO_PIN_MIC]) {
973 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
974 spec->mic_switch = 1;
975 cfg->line_outs++;
976 }
977 break;
978 }
979
980 return 0;
981}
982
Matt Porter3cc08dc2006-01-23 15:27:49 +0100983/*
984 * XXX The line_out pin widget connection list may not be set to the
985 * desired DAC nid. This is the case on 927x where ports A and B can
986 * be routed to several DACs.
987 *
988 * This requires an analysis of the line-out/hp pin configuration
989 * to provide a best fit for pin/DAC configurations that are routable.
990 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
991 * A and B is not supported.
992 */
Mattc7d4b2f2005-06-27 14:59:41 +0200993/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai19039bd2006-06-28 15:52:16 +0200994static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
995 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +0200996{
997 struct sigmatel_spec *spec = codec->spec;
998 hda_nid_t nid;
999 int i;
1000
1001 /* check the pins hardwired to audio widget */
1002 for (i = 0; i < cfg->line_outs; i++) {
1003 nid = cfg->line_out_pins[i];
1004 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1005 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1006 }
1007
Takashi Iwai82bc9552006-03-21 11:24:42 +01001008 spec->multiout.num_dacs = cfg->line_outs;
Mattc7d4b2f2005-06-27 14:59:41 +02001009
1010 return 0;
1011}
1012
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001013/* create volume control/switch for the given prefx type */
1014static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1015{
1016 char name[32];
1017 int err;
1018
1019 sprintf(name, "%s Playback Volume", pfx);
1020 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1021 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1022 if (err < 0)
1023 return err;
1024 sprintf(name, "%s Playback Switch", pfx);
1025 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1026 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1027 if (err < 0)
1028 return err;
1029 return 0;
1030}
1031
Mattc7d4b2f2005-06-27 14:59:41 +02001032/* add playback controls from the parsed DAC table */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001033static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1034 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001035{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001036 static const char *chname[4] = {
1037 "Front", "Surround", NULL /*CLFE*/, "Side"
1038 };
Mattc7d4b2f2005-06-27 14:59:41 +02001039 hda_nid_t nid;
1040 int i, err;
1041
1042 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001043 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001044 continue;
1045
1046 nid = spec->multiout.dac_nids[i];
1047
1048 if (i == 2) {
1049 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001050 err = create_controls(spec, "Center", nid, 1);
1051 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001052 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001053 err = create_controls(spec, "LFE", nid, 2);
1054 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001055 return err;
1056 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001057 err = create_controls(spec, chname[i], nid, 3);
1058 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001059 return err;
1060 }
1061 }
1062
Matt Porter403d1942005-11-29 15:00:51 +01001063 if (spec->line_switch)
1064 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1065 return err;
1066
1067 if (spec->mic_switch)
1068 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1069 return err;
1070
Mattc7d4b2f2005-06-27 14:59:41 +02001071 return 0;
1072}
1073
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001074static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1075{
1076 int i;
1077
1078 for (i = 0; i < spec->multiout.num_dacs; i++) {
1079 if (spec->multiout.dac_nids[i] == nid)
1080 return 1;
1081 }
1082 if (spec->multiout.hp_nid == nid)
1083 return 1;
1084 return 0;
1085}
1086
1087static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1088{
1089 if (!spec->multiout.hp_nid)
1090 spec->multiout.hp_nid = nid;
1091 else if (spec->multiout.num_dacs > 4) {
1092 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1093 return 1;
1094 } else {
1095 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1096 spec->multiout.num_dacs++;
1097 }
1098 return 0;
1099}
1100
1101/* add playback controls for Speaker and HP outputs */
1102static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1103 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001104{
1105 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001106 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001107 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001108
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001109 old_num_dacs = spec->multiout.num_dacs;
1110 for (i = 0; i < cfg->hp_outs; i++) {
1111 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1112 if (wid_caps & AC_WCAP_UNSOL_CAP)
1113 spec->hp_detect = 1;
1114 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1115 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1116 if (check_in_dac_nids(spec, nid))
1117 nid = 0;
1118 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001119 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001120 add_spec_dacs(spec, nid);
1121 }
1122 for (i = 0; i < cfg->speaker_outs; i++) {
1123 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1124 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1125 if (check_in_dac_nids(spec, nid))
1126 nid = 0;
1127 if (check_in_dac_nids(spec, nid))
1128 nid = 0;
1129 if (! nid)
1130 continue;
1131 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001132 }
1133
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001134 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1135 static const char *pfxs[] = {
1136 "Speaker", "External Speaker", "Speaker2",
1137 };
1138 err = create_controls(spec, pfxs[i - old_num_dacs],
1139 spec->multiout.dac_nids[i], 3);
1140 if (err < 0)
1141 return err;
1142 }
1143 if (spec->multiout.hp_nid) {
1144 const char *pfx;
1145 if (old_num_dacs == spec->multiout.num_dacs)
1146 pfx = "Master";
1147 else
1148 pfx = "Headphone";
1149 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1150 if (err < 0)
1151 return err;
1152 }
Mattc7d4b2f2005-06-27 14:59:41 +02001153
1154 return 0;
1155}
1156
1157/* create playback/capture controls for input pins */
1158static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1159{
1160 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001161 struct hda_input_mux *imux = &spec->private_imux;
1162 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1163 int i, j, k;
1164
1165 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001166 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02001167
Takashi Iwai314634b2006-09-21 11:56:18 +02001168 if (!cfg->input_pins[i])
1169 continue;
1170 index = -1;
1171 for (j = 0; j < spec->num_muxes; j++) {
1172 int num_cons;
1173 num_cons = snd_hda_get_connections(codec,
1174 spec->mux_nids[j],
1175 con_lst,
1176 HDA_MAX_NUM_INPUTS);
1177 for (k = 0; k < num_cons; k++)
1178 if (con_lst[k] == cfg->input_pins[i]) {
1179 index = k;
1180 goto found;
1181 }
Mattc7d4b2f2005-06-27 14:59:41 +02001182 }
Takashi Iwai314634b2006-09-21 11:56:18 +02001183 continue;
1184 found:
1185 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1186 imux->items[imux->num_items].index = index;
1187 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02001188 }
1189
Sam Revitch62fe78e2006-05-10 15:09:17 +02001190 if (imux->num_items == 1) {
1191 /*
1192 * Set the current input for the muxes.
1193 * The STAC9221 has two input muxes with identical source
1194 * NID lists. Hopefully this won't get confused.
1195 */
1196 for (i = 0; i < spec->num_muxes; i++) {
1197 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1198 AC_VERB_SET_CONNECT_SEL,
1199 imux->items[0].index);
1200 }
1201 }
1202
Mattc7d4b2f2005-06-27 14:59:41 +02001203 return 0;
1204}
1205
Mattc7d4b2f2005-06-27 14:59:41 +02001206static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1207{
1208 struct sigmatel_spec *spec = codec->spec;
1209 int i;
1210
1211 for (i = 0; i < spec->autocfg.line_outs; i++) {
1212 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1213 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1214 }
1215}
1216
1217static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1218{
1219 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001220 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001221
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001222 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1223 hda_nid_t pin;
1224 pin = spec->autocfg.hp_pins[i];
1225 if (pin) /* connect to front */
1226 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1227 }
1228 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1229 hda_nid_t pin;
1230 pin = spec->autocfg.speaker_pins[i];
1231 if (pin) /* connect to front */
1232 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1233 }
Mattc7d4b2f2005-06-27 14:59:41 +02001234}
1235
Matt Porter3cc08dc2006-01-23 15:27:49 +01001236static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
Mattc7d4b2f2005-06-27 14:59:41 +02001237{
1238 struct sigmatel_spec *spec = codec->spec;
1239 int err;
1240
Kailang Yangdf694da2005-12-05 19:42:22 +01001241 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001242 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001243 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01001244 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001245
Matt Porter403d1942005-11-29 15:00:51 +01001246 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1247 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001248 if (spec->multiout.num_dacs == 0)
1249 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1250 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001251
1252 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1253 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1254 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1255 return err;
1256
1257 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01001258 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02001259 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001260
Takashi Iwai82bc9552006-03-21 11:24:42 +01001261 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001262 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001263 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01001264 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02001265
1266 if (spec->kctl_alloc)
1267 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1268
1269 spec->input_mux = &spec->private_imux;
1270
1271 return 1;
1272}
1273
Takashi Iwai82bc9552006-03-21 11:24:42 +01001274/* add playback controls for HP output */
1275static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1276 struct auto_pin_cfg *cfg)
1277{
1278 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001279 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01001280 unsigned int wid_caps;
1281
1282 if (! pin)
1283 return 0;
1284
1285 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02001286 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01001287 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001288
1289 return 0;
1290}
1291
Richard Fish160ea0d2006-09-06 13:58:25 +02001292/* add playback controls for LFE output */
1293static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1294 struct auto_pin_cfg *cfg)
1295{
1296 struct sigmatel_spec *spec = codec->spec;
1297 int err;
1298 hda_nid_t lfe_pin = 0x0;
1299 int i;
1300
1301 /*
1302 * search speaker outs and line outs for a mono speaker pin
1303 * with an amp. If one is found, add LFE controls
1304 * for it.
1305 */
1306 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1307 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1308 unsigned long wcaps = get_wcaps(codec, pin);
1309 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1310 if (wcaps == AC_WCAP_OUT_AMP)
1311 /* found a mono speaker with an amp, must be lfe */
1312 lfe_pin = pin;
1313 }
1314
1315 /* if speaker_outs is 0, then speakers may be in line_outs */
1316 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1317 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1318 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1319 unsigned long cfg;
1320 cfg = snd_hda_codec_read(codec, pin, 0,
1321 AC_VERB_GET_CONFIG_DEFAULT,
1322 0x00);
1323 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1324 unsigned long wcaps = get_wcaps(codec, pin);
1325 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1326 if (wcaps == AC_WCAP_OUT_AMP)
1327 /* found a mono speaker with an amp,
1328 must be lfe */
1329 lfe_pin = pin;
1330 }
1331 }
1332 }
1333
1334 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001335 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02001336 if (err < 0)
1337 return err;
1338 }
1339
1340 return 0;
1341}
1342
Mattc7d4b2f2005-06-27 14:59:41 +02001343static int stac9200_parse_auto_config(struct hda_codec *codec)
1344{
1345 struct sigmatel_spec *spec = codec->spec;
1346 int err;
1347
Kailang Yangdf694da2005-12-05 19:42:22 +01001348 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001349 return err;
1350
1351 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1352 return err;
1353
Takashi Iwai82bc9552006-03-21 11:24:42 +01001354 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1355 return err;
1356
Richard Fish160ea0d2006-09-06 13:58:25 +02001357 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1358 return err;
1359
Takashi Iwai82bc9552006-03-21 11:24:42 +01001360 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001361 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001362 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02001363 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02001364
1365 if (spec->kctl_alloc)
1366 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1367
1368 spec->input_mux = &spec->private_imux;
1369
1370 return 1;
1371}
1372
Sam Revitch62fe78e2006-05-10 15:09:17 +02001373/*
1374 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1375 * funky external mute control using GPIO pins.
1376 */
1377
1378static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1379{
1380 unsigned int gpiostate, gpiomask, gpiodir;
1381
1382 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1383 AC_VERB_GET_GPIO_DATA, 0);
1384
1385 if (!muted)
1386 gpiostate |= (1 << pin);
1387 else
1388 gpiostate &= ~(1 << pin);
1389
1390 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1391 AC_VERB_GET_GPIO_MASK, 0);
1392 gpiomask |= (1 << pin);
1393
1394 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1395 AC_VERB_GET_GPIO_DIRECTION, 0);
1396 gpiodir |= (1 << pin);
1397
1398 /* AppleHDA seems to do this -- WTF is this verb?? */
1399 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1400
1401 snd_hda_codec_write(codec, codec->afg, 0,
1402 AC_VERB_SET_GPIO_MASK, gpiomask);
1403 snd_hda_codec_write(codec, codec->afg, 0,
1404 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1405
1406 msleep(1);
1407
1408 snd_hda_codec_write(codec, codec->afg, 0,
1409 AC_VERB_SET_GPIO_DATA, gpiostate);
1410}
1411
Takashi Iwai314634b2006-09-21 11:56:18 +02001412static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1413 unsigned int event)
1414{
1415 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1416 snd_hda_codec_write(codec, nid, 0,
1417 AC_VERB_SET_UNSOLICITED_ENABLE,
1418 (AC_USRSP_EN | event));
1419}
1420
Mattc7d4b2f2005-06-27 14:59:41 +02001421static int stac92xx_init(struct hda_codec *codec)
1422{
1423 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01001424 struct auto_pin_cfg *cfg = &spec->autocfg;
1425 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02001426
Mattc7d4b2f2005-06-27 14:59:41 +02001427 snd_hda_sequence_write(codec, spec->init);
1428
Takashi Iwai82bc9552006-03-21 11:24:42 +01001429 /* set up pins */
1430 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02001431 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001432 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02001433 enable_pin_detect(codec, cfg->hp_pins[i],
1434 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001435 /* fake event to set up pins */
1436 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Takashi Iwai314634b2006-09-21 11:56:18 +02001437 /* enable the headphones by default.
1438 * If/when unsol_event detection works, this will be ignored
1439 */
Tobin Davis68a6abd2006-08-21 19:02:10 +02001440 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01001441 } else {
1442 stac92xx_auto_init_multi_out(codec);
1443 stac92xx_auto_init_hp_out(codec);
1444 }
1445 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01001446 hda_nid_t nid = cfg->input_pins[i];
1447 if (nid) {
1448 unsigned int pinctl = AC_PINCTL_IN_EN;
1449 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1450 pinctl |= stac92xx_get_vref(codec, nid);
1451 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1452 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01001453 }
1454 if (cfg->dig_out_pin)
1455 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1456 AC_PINCTL_OUT_EN);
1457 if (cfg->dig_in_pin)
1458 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1459 AC_PINCTL_IN_EN);
1460
Sam Revitch62fe78e2006-05-10 15:09:17 +02001461 if (spec->gpio_mute) {
1462 stac922x_gpio_mute(codec, 0, 0);
1463 stac922x_gpio_mute(codec, 1, 0);
1464 }
1465
Mattc7d4b2f2005-06-27 14:59:41 +02001466 return 0;
1467}
1468
Matt2f2f4252005-04-13 14:45:30 +02001469static void stac92xx_free(struct hda_codec *codec)
1470{
Mattc7d4b2f2005-06-27 14:59:41 +02001471 struct sigmatel_spec *spec = codec->spec;
1472 int i;
1473
1474 if (! spec)
1475 return;
1476
1477 if (spec->kctl_alloc) {
1478 for (i = 0; i < spec->num_kctl_used; i++)
1479 kfree(spec->kctl_alloc[i].name);
1480 kfree(spec->kctl_alloc);
1481 }
1482
Richard Fish11b44bb2006-08-23 18:31:34 +02001483 if (spec->bios_pin_configs)
1484 kfree(spec->bios_pin_configs);
1485
Mattc7d4b2f2005-06-27 14:59:41 +02001486 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02001487}
1488
Matt4e550962005-07-04 17:51:39 +02001489static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1490 unsigned int flag)
1491{
1492 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1493 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai314634b2006-09-21 11:56:18 +02001494 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1495 return;
Matt4e550962005-07-04 17:51:39 +02001496 snd_hda_codec_write(codec, nid, 0,
1497 AC_VERB_SET_PIN_WIDGET_CONTROL,
1498 pin_ctl | flag);
1499}
1500
1501static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1502 unsigned int flag)
1503{
1504 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1505 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1506 snd_hda_codec_write(codec, nid, 0,
1507 AC_VERB_SET_PIN_WIDGET_CONTROL,
1508 pin_ctl & ~flag);
1509}
1510
Takashi Iwai314634b2006-09-21 11:56:18 +02001511static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1512{
1513 if (!nid)
1514 return 0;
1515 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1516 & (1 << 31))
1517 return 1;
1518 return 0;
1519}
1520
1521static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02001522{
1523 struct sigmatel_spec *spec = codec->spec;
1524 struct auto_pin_cfg *cfg = &spec->autocfg;
1525 int i, presence;
1526
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001527 presence = 0;
1528 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02001529 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1530 if (presence)
1531 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001532 }
Matt4e550962005-07-04 17:51:39 +02001533
1534 if (presence) {
1535 /* disable lineouts, enable hp */
1536 for (i = 0; i < cfg->line_outs; i++)
1537 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1538 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001539 for (i = 0; i < cfg->speaker_outs; i++)
1540 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1541 AC_PINCTL_OUT_EN);
1542 for (i = 0; i < cfg->hp_outs; i++)
1543 stac92xx_set_pinctl(codec, cfg->hp_pins[i],
1544 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001545 } else {
1546 /* enable lineouts, disable hp */
1547 for (i = 0; i < cfg->line_outs; i++)
1548 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1549 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001550 for (i = 0; i < cfg->speaker_outs; i++)
1551 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1552 AC_PINCTL_OUT_EN);
1553 for (i = 0; i < cfg->hp_outs; i++)
1554 stac92xx_reset_pinctl(codec, cfg->hp_pins[i],
1555 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02001556 }
1557}
1558
Takashi Iwai314634b2006-09-21 11:56:18 +02001559static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1560{
1561 switch (res >> 26) {
1562 case STAC_HP_EVENT:
1563 stac92xx_hp_detect(codec, res);
1564 break;
1565 }
1566}
1567
Mattff6fdc32005-06-27 15:06:52 +02001568#ifdef CONFIG_PM
1569static int stac92xx_resume(struct hda_codec *codec)
1570{
1571 struct sigmatel_spec *spec = codec->spec;
1572 int i;
1573
1574 stac92xx_init(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02001575 stac92xx_set_config_regs(codec);
Mattff6fdc32005-06-27 15:06:52 +02001576 for (i = 0; i < spec->num_mixers; i++)
1577 snd_hda_resume_ctls(codec, spec->mixers[i]);
1578 if (spec->multiout.dig_out_nid)
1579 snd_hda_resume_spdif_out(codec);
1580 if (spec->dig_in_nid)
1581 snd_hda_resume_spdif_in(codec);
1582
1583 return 0;
1584}
1585#endif
1586
Matt2f2f4252005-04-13 14:45:30 +02001587static struct hda_codec_ops stac92xx_patch_ops = {
1588 .build_controls = stac92xx_build_controls,
1589 .build_pcms = stac92xx_build_pcms,
1590 .init = stac92xx_init,
1591 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02001592 .unsol_event = stac92xx_unsol_event,
Mattff6fdc32005-06-27 15:06:52 +02001593#ifdef CONFIG_PM
1594 .resume = stac92xx_resume,
1595#endif
Matt2f2f4252005-04-13 14:45:30 +02001596};
1597
1598static int patch_stac9200(struct hda_codec *codec)
1599{
1600 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001601 int err;
Matt2f2f4252005-04-13 14:45:30 +02001602
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001603 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001604 if (spec == NULL)
1605 return -ENOMEM;
1606
1607 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001608 spec->num_pins = 8;
1609 spec->pin_nids = stac9200_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001610 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001611 if (spec->board_config < 0) {
1612 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1613 err = stac92xx_save_bios_config_regs(codec);
1614 if (err < 0) {
1615 stac92xx_free(codec);
1616 return err;
1617 }
1618 spec->pin_configs = spec->bios_pin_configs;
1619 } else {
Matt Porter403d1942005-11-29 15:00:51 +01001620 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1621 stac92xx_set_config_regs(codec);
1622 }
Matt2f2f4252005-04-13 14:45:30 +02001623
1624 spec->multiout.max_channels = 2;
1625 spec->multiout.num_dacs = 1;
1626 spec->multiout.dac_nids = stac9200_dac_nids;
1627 spec->adc_nids = stac9200_adc_nids;
1628 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001629 spec->num_muxes = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02001630
1631 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001632 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001633
1634 err = stac9200_parse_auto_config(codec);
1635 if (err < 0) {
1636 stac92xx_free(codec);
1637 return err;
1638 }
Matt2f2f4252005-04-13 14:45:30 +02001639
1640 codec->patch_ops = stac92xx_patch_ops;
1641
1642 return 0;
1643}
1644
1645static int patch_stac922x(struct hda_codec *codec)
1646{
1647 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001648 int err;
Matt2f2f4252005-04-13 14:45:30 +02001649
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001650 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02001651 if (spec == NULL)
1652 return -ENOMEM;
1653
1654 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001655 spec->num_pins = 10;
1656 spec->pin_nids = stac922x_pin_nids;
Matt Porter403d1942005-11-29 15:00:51 +01001657 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001658 if (spec->board_config < 0) {
1659 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1660 "using BIOS defaults\n");
1661 err = stac92xx_save_bios_config_regs(codec);
1662 if (err < 0) {
1663 stac92xx_free(codec);
1664 return err;
1665 }
1666 spec->pin_configs = spec->bios_pin_configs;
1667 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01001668 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1669 stac92xx_set_config_regs(codec);
1670 }
Matt2f2f4252005-04-13 14:45:30 +02001671
Matt2f2f4252005-04-13 14:45:30 +02001672 spec->adc_nids = stac922x_adc_nids;
1673 spec->mux_nids = stac922x_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02001674 spec->num_muxes = 2;
Mattc7d4b2f2005-06-27 14:59:41 +02001675
1676 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02001677 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02001678
1679 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02001680
Matt Porter3cc08dc2006-01-23 15:27:49 +01001681 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1682 if (err < 0) {
1683 stac92xx_free(codec);
1684 return err;
1685 }
1686
Sam Revitch62fe78e2006-05-10 15:09:17 +02001687 if (spec->board_config == STAC_MACMINI)
1688 spec->gpio_mute = 1;
1689
Matt Porter3cc08dc2006-01-23 15:27:49 +01001690 codec->patch_ops = stac92xx_patch_ops;
1691
1692 return 0;
1693}
1694
1695static int patch_stac927x(struct hda_codec *codec)
1696{
1697 struct sigmatel_spec *spec;
1698 int err;
1699
1700 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1701 if (spec == NULL)
1702 return -ENOMEM;
1703
1704 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001705 spec->num_pins = 14;
1706 spec->pin_nids = stac927x_pin_nids;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001707 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001708 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001709 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02001710 err = stac92xx_save_bios_config_regs(codec);
1711 if (err < 0) {
1712 stac92xx_free(codec);
1713 return err;
1714 }
1715 spec->pin_configs = spec->bios_pin_configs;
1716 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01001717 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1718 stac92xx_set_config_regs(codec);
1719 }
1720
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001721 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02001722 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001723 spec->adc_nids = stac927x_adc_nids;
1724 spec->mux_nids = stac927x_mux_nids;
1725 spec->num_muxes = 3;
Tobin Davis93ed1502006-09-01 21:03:12 +02001726 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001727 spec->mixer = stac9227_mixer;
1728 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02001729 case STAC_D965_5ST:
1730 spec->adc_nids = stac927x_adc_nids;
1731 spec->mux_nids = stac927x_mux_nids;
1732 spec->num_muxes = 3;
1733 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001734 spec->mixer = stac9227_mixer;
1735 break;
1736 default:
1737 spec->adc_nids = stac927x_adc_nids;
1738 spec->mux_nids = stac927x_mux_nids;
1739 spec->num_muxes = 3;
1740 spec->init = stac927x_core_init;
1741 spec->mixer = stac927x_mixer;
1742 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01001743
1744 spec->multiout.dac_nids = spec->dac_nids;
1745
1746 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Mattc7d4b2f2005-06-27 14:59:41 +02001747 if (err < 0) {
1748 stac92xx_free(codec);
1749 return err;
1750 }
Matt2f2f4252005-04-13 14:45:30 +02001751
1752 codec->patch_ops = stac92xx_patch_ops;
1753
1754 return 0;
1755}
1756
Matt Porterf3302a52006-07-31 12:49:34 +02001757static int patch_stac9205(struct hda_codec *codec)
1758{
1759 struct sigmatel_spec *spec;
1760 int err;
1761
1762 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1763 if (spec == NULL)
1764 return -ENOMEM;
1765
1766 codec->spec = spec;
Richard Fish11b44bb2006-08-23 18:31:34 +02001767 spec->num_pins = 14;
1768 spec->pin_nids = stac9205_pin_nids;
Matt Porterf3302a52006-07-31 12:49:34 +02001769 spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02001770 if (spec->board_config < 0) {
1771 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
1772 err = stac92xx_save_bios_config_regs(codec);
1773 if (err < 0) {
1774 stac92xx_free(codec);
1775 return err;
1776 }
1777 spec->pin_configs = spec->bios_pin_configs;
1778 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02001779 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
1780 stac92xx_set_config_regs(codec);
1781 }
1782
1783 spec->adc_nids = stac9205_adc_nids;
1784 spec->mux_nids = stac9205_mux_nids;
1785 spec->num_muxes = 3;
1786
1787 spec->init = stac9205_core_init;
1788 spec->mixer = stac9205_mixer;
1789
1790 spec->multiout.dac_nids = spec->dac_nids;
1791
1792 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
1793 if (err < 0) {
1794 stac92xx_free(codec);
1795 return err;
1796 }
1797
1798 codec->patch_ops = stac92xx_patch_ops;
1799
1800 return 0;
1801}
1802
Matt2f2f4252005-04-13 14:45:30 +02001803/*
Guillaume Munch6d859062006-08-22 17:15:47 +02001804 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01001805 */
1806
Guillaume Munch99ccc562006-08-16 19:35:12 +02001807/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01001808static hda_nid_t vaio_dacs[] = { 0x2 };
1809#define VAIO_HP_DAC 0x5
1810static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1811static hda_nid_t vaio_mux_nids[] = { 0x15 };
1812
1813static struct hda_input_mux vaio_mux = {
1814 .num_items = 2,
1815 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02001816 /* { "HP", 0x0 }, */
1817 { "Line", 0x1 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001818 { "Mic", 0x2 },
1819 { "PCM", 0x3 },
1820 }
1821};
1822
1823static struct hda_verb vaio_init[] = {
1824 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1825 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1826 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1827 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1828 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1829 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1830 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1831 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1832 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1833 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1834 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1835 {}
1836};
1837
Guillaume Munch6d859062006-08-22 17:15:47 +02001838static struct hda_verb vaio_ar_init[] = {
1839 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1840 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1841 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1842 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1843/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
1844 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1845 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1846 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1847 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1848/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
1849 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1850 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1852 {}
1853};
1854
Takashi Iwaidb064e52006-03-16 16:04:58 +01001855/* bind volumes of both NID 0x02 and 0x05 */
1856static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1857 struct snd_ctl_elem_value *ucontrol)
1858{
1859 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1860 long *valp = ucontrol->value.integer.value;
1861 int change;
1862
1863 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1864 0x7f, valp[0] & 0x7f);
1865 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1866 0x7f, valp[1] & 0x7f);
1867 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1868 0x7f, valp[0] & 0x7f);
1869 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1870 0x7f, valp[1] & 0x7f);
1871 return change;
1872}
1873
1874/* bind volumes of both NID 0x02 and 0x05 */
1875static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1876 struct snd_ctl_elem_value *ucontrol)
1877{
1878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1879 long *valp = ucontrol->value.integer.value;
1880 int change;
1881
1882 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001883 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001884 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001885 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001886 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001887 0x80, (valp[0] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001888 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwaia9393d72006-05-03 11:59:03 +02001889 0x80, (valp[1] ? 0 : 0x80));
Takashi Iwaidb064e52006-03-16 16:04:58 +01001890 return change;
1891}
1892
1893static struct snd_kcontrol_new vaio_mixer[] = {
1894 {
1895 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1896 .name = "Master Playback Volume",
1897 .info = snd_hda_mixer_amp_volume_info,
1898 .get = snd_hda_mixer_amp_volume_get,
1899 .put = vaio_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +02001900 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001901 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1902 },
1903 {
1904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1905 .name = "Master Playback Switch",
1906 .info = snd_hda_mixer_amp_switch_info,
1907 .get = snd_hda_mixer_amp_switch_get,
1908 .put = vaio_master_sw_put,
1909 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1910 },
1911 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1912 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1913 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1914 {
1915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1916 .name = "Capture Source",
1917 .count = 1,
1918 .info = stac92xx_mux_enum_info,
1919 .get = stac92xx_mux_enum_get,
1920 .put = stac92xx_mux_enum_put,
1921 },
1922 {}
1923};
1924
Guillaume Munch6d859062006-08-22 17:15:47 +02001925static struct snd_kcontrol_new vaio_ar_mixer[] = {
1926 {
1927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1928 .name = "Master Playback Volume",
1929 .info = snd_hda_mixer_amp_volume_info,
1930 .get = snd_hda_mixer_amp_volume_get,
1931 .put = vaio_master_vol_put,
1932 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1933 },
1934 {
1935 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1936 .name = "Master Playback Switch",
1937 .info = snd_hda_mixer_amp_switch_info,
1938 .get = snd_hda_mixer_amp_switch_get,
1939 .put = vaio_master_sw_put,
1940 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1941 },
1942 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1943 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1944 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1945 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
1946 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
1947 {
1948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1949 .name = "Capture Source",
1950 .count = 1,
1951 .info = stac92xx_mux_enum_info,
1952 .get = stac92xx_mux_enum_get,
1953 .put = stac92xx_mux_enum_put,
1954 },
1955 {}
1956};
1957
1958static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01001959 .build_controls = stac92xx_build_controls,
1960 .build_pcms = stac92xx_build_pcms,
1961 .init = stac92xx_init,
1962 .free = stac92xx_free,
1963#ifdef CONFIG_PM
1964 .resume = stac92xx_resume,
1965#endif
1966};
1967
Guillaume Munch6d859062006-08-22 17:15:47 +02001968enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
1969 CXD9872RD_VAIO,
1970 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
1971 STAC9872AK_VAIO,
1972 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
1973 STAC9872K_VAIO,
1974 /* AR Series. id=0x83847664 and subsys=104D1300 */
1975 CXD9872AKD_VAIO
1976 };
Takashi Iwaidb064e52006-03-16 16:04:58 +01001977
Guillaume Munch6d859062006-08-22 17:15:47 +02001978static struct hda_board_config stac9872_cfg_tbl[] = {
1979 { .modelname = "vaio", .config = CXD9872RD_VAIO },
1980 { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001981 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
Guillaume Munch6d859062006-08-22 17:15:47 +02001982 .config = CXD9872RD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001983 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
Guillaume Munch6d859062006-08-22 17:15:47 +02001984 .config = CXD9872RD_VAIO },
Guillaume Munch99ccc562006-08-16 19:35:12 +02001985 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
Guillaume Munch6d859062006-08-22 17:15:47 +02001986 .config = CXD9872AKD_VAIO },
Takashi Iwaidb064e52006-03-16 16:04:58 +01001987 {}
1988};
1989
Guillaume Munch6d859062006-08-22 17:15:47 +02001990static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01001991{
1992 struct sigmatel_spec *spec;
1993 int board_config;
1994
Guillaume Munch6d859062006-08-22 17:15:47 +02001995 board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01001996 if (board_config < 0)
1997 /* unknown config, let generic-parser do its job... */
1998 return snd_hda_parse_generic_codec(codec);
1999
2000 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2001 if (spec == NULL)
2002 return -ENOMEM;
2003
2004 codec->spec = spec;
2005 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02002006 case CXD9872RD_VAIO:
2007 case STAC9872AK_VAIO:
2008 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01002009 spec->mixer = vaio_mixer;
2010 spec->init = vaio_init;
2011 spec->multiout.max_channels = 2;
2012 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2013 spec->multiout.dac_nids = vaio_dacs;
2014 spec->multiout.hp_nid = VAIO_HP_DAC;
2015 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2016 spec->adc_nids = vaio_adcs;
2017 spec->input_mux = &vaio_mux;
2018 spec->mux_nids = vaio_mux_nids;
2019 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02002020
2021 case CXD9872AKD_VAIO:
2022 spec->mixer = vaio_ar_mixer;
2023 spec->init = vaio_ar_init;
2024 spec->multiout.max_channels = 2;
2025 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2026 spec->multiout.dac_nids = vaio_dacs;
2027 spec->multiout.hp_nid = VAIO_HP_DAC;
2028 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2029 spec->adc_nids = vaio_adcs;
2030 spec->input_mux = &vaio_mux;
2031 spec->mux_nids = vaio_mux_nids;
2032 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002033 }
2034
Guillaume Munch6d859062006-08-22 17:15:47 +02002035 codec->patch_ops = stac9872_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01002036 return 0;
2037}
2038
2039
2040/*
Matt2f2f4252005-04-13 14:45:30 +02002041 * patch entries
2042 */
2043struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2044 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2045 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2046 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2047 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2048 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2049 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2050 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02002051 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2052 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2053 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2054 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2055 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2056 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01002057 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2058 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2059 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2060 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2061 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2062 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2063 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2064 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2065 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2066 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02002067 /* The following does not take into account .id=0x83847661 when subsys =
2068 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2069 * currently not fully supported.
2070 */
2071 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2072 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2073 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02002074 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2075 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2076 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2077 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2078 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2079 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2080 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2081 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matt2f2f4252005-04-13 14:45:30 +02002082 {} /* terminator */
2083};