blob: 32f744d47da79e78ed6e6f721eaa0e0064e39206 [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
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +010031#include <linux/dmi.h>
Matt2f2f4252005-04-13 14:45:30 +020032#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040034#include <sound/jack.h>
Clemens Ladischa74ccea2010-10-22 15:52:34 +020035#include <sound/tlv.h>
Matt2f2f4252005-04-13 14:45:30 +020036#include "hda_codec.h"
37#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020038#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020039
Takashi Iwaic6e4c662008-11-25 11:58:19 +010040enum {
41 STAC_VREF_EVENT = 1,
42 STAC_INSERT_EVENT,
43 STAC_PWR_EVENT,
44 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020045 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020046 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010047};
Matt4e550962005-07-04 17:51:39 +020048
Takashi Iwaif5fcc132006-11-24 17:07:44 +010049enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010050 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010051 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010052 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020053 STAC_9200_DELL_D21,
54 STAC_9200_DELL_D22,
55 STAC_9200_DELL_D23,
56 STAC_9200_DELL_M21,
57 STAC_9200_DELL_M22,
58 STAC_9200_DELL_M23,
59 STAC_9200_DELL_M24,
60 STAC_9200_DELL_M25,
61 STAC_9200_DELL_M26,
62 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020063 STAC_9200_M4,
64 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010065 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010066 STAC_9200_MODELS
67};
68
69enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010070 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010071 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020072 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020073 STAC_9205_DELL_M43,
74 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010075 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010076 STAC_9205_MODELS
77};
78
79enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010080 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010081 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010082 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080083 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010084 STAC_DELL_M6_AMIC,
85 STAC_DELL_M6_DMIC,
86 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050087 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020088 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010089 STAC_92HD73XX_MODELS
90};
91
92enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010093 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020094 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050095 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050096 STAC_DELL_S14,
Takashi Iwaib4e81872009-11-18 17:20:24 +010097 STAC_92HD83XXX_HP,
Steven Eastland48315592010-08-06 15:07:35 -060098 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020099 STAC_92HD83XXX_MODELS
100};
101
102enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100103 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100104 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100105 STAC_DELL_M4_1,
106 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500107 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400108 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200109 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100110 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100111 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400112 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100113 STAC_92HD71BXX_MODELS
114};
115
116enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100117 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100118 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200119 STAC_M1,
120 STAC_M1_2,
121 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100122 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200123 STAC_M3,
124 STAC_M5,
125 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100126 STAC_925x_MODELS
127};
128
129enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100130 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100131 STAC_D945_REF,
132 STAC_D945GTP3,
133 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200134 STAC_INTEL_MAC_V1,
135 STAC_INTEL_MAC_V2,
136 STAC_INTEL_MAC_V3,
137 STAC_INTEL_MAC_V4,
138 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800139 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
140 * is given, one of the above models will be
141 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200142 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100143 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100144 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100145 STAC_MACBOOK_PRO_V1,
146 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200147 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200148 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300149 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200150 STAC_922X_DELL_D81,
151 STAC_922X_DELL_D82,
152 STAC_922X_DELL_M81,
153 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100154 STAC_922X_MODELS
155};
156
157enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100158 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100159 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100160 STAC_D965_REF,
161 STAC_D965_3ST,
162 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200163 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200164 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100165 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200166 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100167 STAC_927X_MODELS
168};
Matt Porter403d1942005-11-29 15:00:51 +0100169
Takashi Iwai307282c2009-03-12 18:17:58 +0100170enum {
171 STAC_9872_AUTO,
172 STAC_9872_VAIO,
173 STAC_9872_MODELS
174};
175
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400176struct sigmatel_event {
177 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100178 unsigned char type;
179 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400180 int data;
181};
182
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200183struct sigmatel_mic_route {
184 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200185 signed char mux_idx;
186 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200187};
188
Matt2f2f4252005-04-13 14:45:30 +0200189struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100190 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200191 unsigned int num_mixers;
192
Matt Porter403d1942005-11-29 15:00:51 +0100193 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500194 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200195 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100196 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100197 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400198 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100199 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200200 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100201 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200202
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100203 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200204 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100205 unsigned int gpio_mask;
206 unsigned int gpio_dir;
207 unsigned int gpio_data;
208 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200209 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100210 unsigned int gpio_led_polarity;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100211
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200212 /* stream */
213 unsigned int stream_delay;
214
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100215 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100216 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100217 unsigned char aloopback_mask;
218 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200219
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100220 /* power management */
221 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200222 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100223 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100224 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100225
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400226 /* events */
227 struct snd_array events;
228
Matt2f2f4252005-04-13 14:45:30 +0200229 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100230 struct hda_input_mux *mono_mux;
231 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200232 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100233 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100234 hda_nid_t hp_dacs[5];
235 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200236
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100237 int volume_offset;
238
Matt2f2f4252005-04-13 14:45:30 +0200239 /* capture */
240 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200241 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200242 hda_nid_t *mux_nids;
243 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200244 hda_nid_t *dmic_nids;
245 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100246 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100247 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200248 hda_nid_t *smux_nids;
249 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200250 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200251
252 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
253 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
254 unsigned int num_caps; /* number of capture volume/switch elements */
255
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200256 struct sigmatel_mic_route ext_mic;
257 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200258 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200259
Takashi Iwaiea734962011-01-17 11:29:34 +0100260 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200261
Mattdabbed62005-06-14 10:19:34 +0200262 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100263 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200264 hda_nid_t anabeep_nid;
265 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200266
Matt2f2f4252005-04-13 14:45:30 +0200267 /* pin widgets */
268 hda_nid_t *pin_nids;
269 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200270
271 /* codec specific stuff */
272 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100273 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200274
275 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200276 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100277 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200278 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100279 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200280 struct hda_input_mux *sinput_mux;
281 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400282 unsigned int cur_amux;
283 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200284 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200285
Matt Porter403d1942005-11-29 15:00:51 +0100286 /* i/o switches */
287 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200288 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100289 hda_nid_t line_switch; /* shared line-in for input and output */
290 hda_nid_t mic_switch; /* shared mic-in for input and output */
291 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200292 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200293
Mattc7d4b2f2005-06-27 14:59:41 +0200294 struct hda_pcm pcm_rec[2]; /* PCM information */
295
296 /* dynamic controls and input_mux */
297 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200298 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200299 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200300 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200301 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100302 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200303};
304
305static hda_nid_t stac9200_adc_nids[1] = {
306 0x03,
307};
308
309static hda_nid_t stac9200_mux_nids[1] = {
310 0x0c,
311};
312
313static hda_nid_t stac9200_dac_nids[1] = {
314 0x02,
315};
316
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100317static hda_nid_t stac92hd73xx_pwr_nids[8] = {
318 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
319 0x0f, 0x10, 0x11
320};
321
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400322static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
323 0x26, 0,
324};
325
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100326static hda_nid_t stac92hd73xx_adc_nids[2] = {
327 0x1a, 0x1b
328};
329
330#define STAC92HD73XX_NUM_DMICS 2
331static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
332 0x13, 0x14, 0
333};
334
335#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100336
Takashi Iwaie2aec172009-09-02 01:00:05 +0200337static hda_nid_t stac92hd73xx_mux_nids[2] = {
338 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100339};
340
341static hda_nid_t stac92hd73xx_dmux_nids[2] = {
342 0x20, 0x21,
343};
344
Matthew Ranostayd9737752008-09-07 12:03:41 +0200345static hda_nid_t stac92hd73xx_smux_nids[2] = {
346 0x22, 0x23,
347};
348
Takashi Iwai6479c632009-07-28 18:20:25 +0200349#define STAC92HD73XX_NUM_CAPS 2
350static unsigned long stac92hd73xx_capvols[] = {
351 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
352 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
353};
354#define stac92hd73xx_capsws stac92hd73xx_capvols
355
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200356#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200357
Takashi Iwai667067d2009-08-13 18:14:42 +0200358static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200359 0x17, 0x18,
360};
361
362static hda_nid_t stac92hd83xxx_adc_nids[2] = {
363 0x15, 0x16,
364};
365
366static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
367 0xa, 0xb, 0xd, 0xe,
368};
369
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400370static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
371 0x1e, 0,
372};
373
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200374static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500375 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200376};
377
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200378#define STAC92HD83XXX_NUM_DMICS 2
379static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
380 0x11, 0x20, 0
381};
382
David Henningssonbdfe6f42011-01-04 06:30:53 +0100383#define STAC92HD88XXX_NUM_DMICS STAC92HD83XXX_NUM_DMICS
384#define stac92hd88xxx_dmic_nids stac92hd83xxx_dmic_nids
385
David Henningsson89feca12010-10-13 15:48:24 +0200386#define STAC92HD87B_NUM_DMICS 1
387static hda_nid_t stac92hd87b_dmic_nids[STAC92HD87B_NUM_DMICS + 1] = {
388 0x11, 0
389};
390
Takashi Iwai6479c632009-07-28 18:20:25 +0200391#define STAC92HD83XXX_NUM_CAPS 2
392static unsigned long stac92hd83xxx_capvols[] = {
393 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
394 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
395};
396#define stac92hd83xxx_capsws stac92hd83xxx_capvols
397
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100398static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
399 0x0a, 0x0d, 0x0f
400};
401
Matthew Ranostaye035b842007-11-06 11:53:55 +0100402static hda_nid_t stac92hd71bxx_adc_nids[2] = {
403 0x12, 0x13,
404};
405
406static hda_nid_t stac92hd71bxx_mux_nids[2] = {
407 0x1a, 0x1b
408};
409
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400410static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
411 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100412};
413
Matthew Ranostayd9737752008-09-07 12:03:41 +0200414static hda_nid_t stac92hd71bxx_smux_nids[2] = {
415 0x24, 0x25,
416};
417
Matthew Ranostaye035b842007-11-06 11:53:55 +0100418#define STAC92HD71BXX_NUM_DMICS 2
419static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
420 0x18, 0x19, 0
421};
422
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400423static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
424 0x22, 0
425};
426
Takashi Iwai6479c632009-07-28 18:20:25 +0200427#define STAC92HD71BXX_NUM_CAPS 2
428static unsigned long stac92hd71bxx_capvols[] = {
429 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
430 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
431};
432#define stac92hd71bxx_capsws stac92hd71bxx_capvols
433
Tobin Davis8e21c342007-01-08 11:04:17 +0100434static hda_nid_t stac925x_adc_nids[1] = {
435 0x03,
436};
437
438static hda_nid_t stac925x_mux_nids[1] = {
439 0x0f,
440};
441
442static hda_nid_t stac925x_dac_nids[1] = {
443 0x02,
444};
445
Takashi Iwaif6e98522007-10-16 14:27:04 +0200446#define STAC925X_NUM_DMICS 1
447static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
448 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200449};
450
Takashi Iwai1697055e2007-12-18 18:05:52 +0100451static hda_nid_t stac925x_dmux_nids[1] = {
452 0x14,
453};
454
Takashi Iwai6479c632009-07-28 18:20:25 +0200455static unsigned long stac925x_capvols[] = {
456 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
457};
458static unsigned long stac925x_capsws[] = {
459 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
460};
461
Matt2f2f4252005-04-13 14:45:30 +0200462static hda_nid_t stac922x_adc_nids[2] = {
463 0x06, 0x07,
464};
465
466static hda_nid_t stac922x_mux_nids[2] = {
467 0x12, 0x13,
468};
469
Takashi Iwai6479c632009-07-28 18:20:25 +0200470#define STAC922X_NUM_CAPS 2
471static unsigned long stac922x_capvols[] = {
472 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
473 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
474};
475#define stac922x_capsws stac922x_capvols
476
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500477static hda_nid_t stac927x_slave_dig_outs[2] = {
478 0x1f, 0,
479};
480
Matt Porter3cc08dc2006-01-23 15:27:49 +0100481static hda_nid_t stac927x_adc_nids[3] = {
482 0x07, 0x08, 0x09
483};
484
485static hda_nid_t stac927x_mux_nids[3] = {
486 0x15, 0x16, 0x17
487};
488
Matthew Ranostayd9737752008-09-07 12:03:41 +0200489static hda_nid_t stac927x_smux_nids[1] = {
490 0x21,
491};
492
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100493static hda_nid_t stac927x_dac_nids[6] = {
494 0x02, 0x03, 0x04, 0x05, 0x06, 0
495};
496
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100497static hda_nid_t stac927x_dmux_nids[1] = {
498 0x1b,
499};
500
Matthew Ranostay7f168592007-10-18 17:38:17 +0200501#define STAC927X_NUM_DMICS 2
502static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
503 0x13, 0x14, 0
504};
505
Takashi Iwai6479c632009-07-28 18:20:25 +0200506#define STAC927X_NUM_CAPS 3
507static unsigned long stac927x_capvols[] = {
508 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
509 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
511};
512static unsigned long stac927x_capsws[] = {
513 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
514 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
516};
517
Takashi Iwaiea734962011-01-17 11:29:34 +0100518static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400519 "Digital Playback", "ADAT", "Analog Mux 1",
520 "Analog Mux 2", "Analog Mux 3"
521};
522
Matt Porterf3302a52006-07-31 12:49:34 +0200523static hda_nid_t stac9205_adc_nids[2] = {
524 0x12, 0x13
525};
526
527static hda_nid_t stac9205_mux_nids[2] = {
528 0x19, 0x1a
529};
530
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100531static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100532 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100533};
534
Matthew Ranostayd9737752008-09-07 12:03:41 +0200535static hda_nid_t stac9205_smux_nids[1] = {
536 0x21,
537};
538
Takashi Iwaif6e98522007-10-16 14:27:04 +0200539#define STAC9205_NUM_DMICS 2
540static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
541 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200542};
543
Takashi Iwai6479c632009-07-28 18:20:25 +0200544#define STAC9205_NUM_CAPS 2
545static unsigned long stac9205_capvols[] = {
546 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
547 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
548};
549static unsigned long stac9205_capsws[] = {
550 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
551 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
552};
553
Mattc7d4b2f2005-06-27 14:59:41 +0200554static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200555 0x08, 0x09, 0x0d, 0x0e,
556 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200557};
558
Tobin Davis8e21c342007-01-08 11:04:17 +0100559static hda_nid_t stac925x_pin_nids[8] = {
560 0x07, 0x08, 0x0a, 0x0b,
561 0x0c, 0x0d, 0x10, 0x11,
562};
563
Matt2f2f4252005-04-13 14:45:30 +0200564static hda_nid_t stac922x_pin_nids[10] = {
565 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566 0x0f, 0x10, 0x11, 0x15, 0x1b,
567};
568
Matthew Ranostaya7662642008-02-21 07:51:14 +0100569static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100570 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
571 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200572 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100573};
574
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500575static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200576 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500577 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200578};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500579
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -0600580static hda_nid_t stac92hd87xxx_pin_nids[6] = {
581 0x0a, 0x0b, 0x0c, 0x0d,
582 0x0f, 0x11,
583};
584
585static hda_nid_t stac92hd88xxx_pin_nids[8] = {
Charles Chin36706002010-01-29 12:05:51 +0100586 0x0a, 0x0b, 0x0c, 0x0d,
587 0x0f, 0x11, 0x1f, 0x20,
588};
589
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500590#define STAC92HD71BXX_NUM_PINS 13
591static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
592 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
593 0x00, 0x14, 0x18, 0x19, 0x1e,
594 0x1f, 0x20, 0x27
595};
596static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100597 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
598 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500599 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100600};
601
Matt Porter3cc08dc2006-01-23 15:27:49 +0100602static hda_nid_t stac927x_pin_nids[14] = {
603 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
604 0x0f, 0x10, 0x11, 0x12, 0x13,
605 0x14, 0x21, 0x22, 0x23,
606};
607
Matt Porterf3302a52006-07-31 12:49:34 +0200608static hda_nid_t stac9205_pin_nids[12] = {
609 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
610 0x0f, 0x14, 0x16, 0x17, 0x18,
611 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200612};
613
Matt Porter8b657272006-10-26 17:12:59 +0200614static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_info *uinfo)
616{
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct sigmatel_spec *spec = codec->spec;
619 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
620}
621
622static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
623 struct snd_ctl_elem_value *ucontrol)
624{
625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100627 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200628
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100629 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200630 return 0;
631}
632
633static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_value *ucontrol)
635{
636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
637 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100638 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200639
640 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100641 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200642}
643
Matthew Ranostayd9737752008-09-07 12:03:41 +0200644static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_info *uinfo)
646{
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct sigmatel_spec *spec = codec->spec;
649 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
650}
651
652static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_value *ucontrol)
654{
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct sigmatel_spec *spec = codec->spec;
657 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
658
659 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
660 return 0;
661}
662
663static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_value *ucontrol)
665{
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400668 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200669 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400670 int err, val;
671 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200672
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400673 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200674 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400675 if (err < 0)
676 return err;
677
678 if (spec->spdif_mute) {
679 if (smux_idx == 0)
680 nid = spec->multiout.dig_out_nid;
681 else
682 nid = codec->slave_dig_outs[smux_idx - 1];
683 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100684 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400685 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100686 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400687 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100688 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
689 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400690 }
691 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200692}
693
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200694static unsigned int stac92xx_vref_set(struct hda_codec *codec,
695 hda_nid_t nid, unsigned int new_vref)
696{
Takashi Iwaib8621512009-06-22 08:00:10 +0200697 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200698 unsigned int pincfg;
699 pincfg = snd_hda_codec_read(codec, nid, 0,
700 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
701
702 pincfg &= 0xff;
703 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
704 pincfg |= new_vref;
705
706 if (new_vref == AC_PINCTL_VREF_HIZ)
707 pincfg |= AC_PINCTL_OUT_EN;
708 else
709 pincfg |= AC_PINCTL_IN_EN;
710
711 error = snd_hda_codec_write_cache(codec, nid, 0,
712 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
713 if (error < 0)
714 return error;
715 else
716 return 1;
717}
718
719static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
720{
721 unsigned int vref;
722 vref = snd_hda_codec_read(codec, nid, 0,
723 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
724 vref &= AC_PINCTL_VREFEN;
725 return vref;
726}
727
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100728static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200729{
730 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
731 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200732 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200733}
734
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100735static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200736{
737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738 struct sigmatel_spec *spec = codec->spec;
739 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
740
741 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
742 return 0;
743}
744
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100745static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200746{
747 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
748 struct sigmatel_spec *spec = codec->spec;
749 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200750 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600751 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200752
Takashi Iwai5207e102009-07-30 13:09:08 +0200753 idx = ucontrol->value.enumerated.item[0];
754 if (idx >= imux->num_items)
755 idx = imux->num_items - 1;
756 prev_idx = spec->cur_mux[adc_idx];
757 if (prev_idx == idx)
758 return 0;
759 if (idx < spec->num_analog_muxes) {
760 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
761 AC_VERB_SET_CONNECT_SEL,
762 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600763 if (prev_idx >= spec->num_analog_muxes &&
764 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200765 imux = spec->dinput_mux;
766 /* 0 = analog */
767 snd_hda_codec_write_cache(codec,
768 spec->dmux_nids[adc_idx], 0,
769 AC_VERB_SET_CONNECT_SEL,
770 imux->items[0].index);
771 }
772 } else {
773 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600774 /* first dimux item is hardcoded to select analog imux,
775 * so lets skip it
776 */
777 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200778 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
779 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600780 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200781 }
782 spec->cur_mux[adc_idx] = idx;
783 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200784}
785
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100786static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_info *uinfo)
788{
789 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
790 struct sigmatel_spec *spec = codec->spec;
791 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
792}
793
794static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_value *ucontrol)
796{
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct sigmatel_spec *spec = codec->spec;
799
800 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
801 return 0;
802}
803
804static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
805 struct snd_ctl_elem_value *ucontrol)
806{
807 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
808 struct sigmatel_spec *spec = codec->spec;
809
810 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
811 spec->mono_nid, &spec->cur_mmux);
812}
813
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200814#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
815
816static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
817 struct snd_ctl_elem_value *ucontrol)
818{
819 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100820 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200821 struct sigmatel_spec *spec = codec->spec;
822
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100823 ucontrol->value.integer.value[0] = !!(spec->aloopback &
824 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200825 return 0;
826}
827
828static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_value *ucontrol)
830{
831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
832 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100833 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200834 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100835 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200836
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100837 idx_val = spec->aloopback_mask << idx;
838 if (ucontrol->value.integer.value[0])
839 val = spec->aloopback | idx_val;
840 else
841 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100842 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843 return 0;
844
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100845 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200846
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100847 /* Only return the bits defined by the shift value of the
848 * first two bytes of the mask
849 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200850 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100851 kcontrol->private_value & 0xFFFF, 0x0);
852 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200853
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100854 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200855 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100856 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200857 } else {
858 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100859 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200860 }
861
862 snd_hda_codec_write_cache(codec, codec->afg, 0,
863 kcontrol->private_value >> 16, dac_mode);
864
865 return 1;
866}
867
Mattc7d4b2f2005-06-27 14:59:41 +0200868static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200869 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200870 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200871 {}
872};
873
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200874static struct hda_verb stac9200_eapd_init[] = {
875 /* set dac0mux for dac converter */
876 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
877 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
878 {}
879};
880
Matthew Ranostayd654a662008-03-14 08:46:51 +0100881static struct hda_verb dell_eq_core_init[] = {
882 /* set master volume to max value without distortion
883 * and direct control */
884 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100885 {}
886};
887
Takashi Iwaie2aec172009-09-02 01:00:05 +0200888static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100889 /* set master volume and direct control */
890 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100891 {}
892};
893
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200894static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200895 /* power state controls amps */
896 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200897 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200898};
899
Matthew Ranostaye035b842007-11-06 11:53:55 +0100900static struct hda_verb stac92hd71bxx_core_init[] = {
901 /* set master volume and direct control */
902 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200903 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100904};
905
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500906static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
907 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
908 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100909 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
910 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100911 {}
912};
913
Tobin Davis8e21c342007-01-08 11:04:17 +0100914static struct hda_verb stac925x_core_init[] = {
915 /* set dac0mux for dac converter */
916 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100917 /* mute the master volume */
918 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100919 {}
920};
921
Mattc7d4b2f2005-06-27 14:59:41 +0200922static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200923 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200924 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200925 {}
926};
927
Tobin Davis93ed1502006-09-01 21:03:12 +0200928static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200929 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200930 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200931 /* unmute node 0x1b */
932 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
933 /* select node 0x03 as DAC */
934 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
935 {}
936};
937
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200938static struct hda_verb dell_3st_core_init[] = {
939 /* don't set delta bit */
940 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
941 /* unmute node 0x1b */
942 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
943 /* select node 0x03 as DAC */
944 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
945 {}
946};
947
Matt Porter3cc08dc2006-01-23 15:27:49 +0100948static struct hda_verb stac927x_core_init[] = {
949 /* set master volume and direct control */
950 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200951 /* enable analog pc beep path */
952 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100953 {}
954};
955
Takashi Iwai54930532009-10-11 17:38:29 +0200956static struct hda_verb stac927x_volknob_core_init[] = {
957 /* don't set delta bit */
958 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
959 /* enable analog pc beep path */
960 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
961 {}
962};
963
Matt Porterf3302a52006-07-31 12:49:34 +0200964static struct hda_verb stac9205_core_init[] = {
965 /* set master volume and direct control */
966 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200967 /* enable analog pc beep path */
968 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200969 {}
970};
971
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100972#define STAC_MONO_MUX \
973 { \
974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
975 .name = "Mono Mux", \
976 .count = 1, \
977 .info = stac92xx_mono_mux_enum_info, \
978 .get = stac92xx_mono_mux_enum_get, \
979 .put = stac92xx_mono_mux_enum_put, \
980 }
981
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100982#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200983 { \
984 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
985 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100986 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200987 .info = stac92xx_aloopback_info, \
988 .get = stac92xx_aloopback_get, \
989 .put = stac92xx_aloopback_put, \
990 .private_value = verb_read | (verb_write << 16), \
991 }
992
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200993#define DC_BIAS(xname, idx, nid) \
994 { \
995 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
996 .name = xname, \
997 .index = idx, \
998 .info = stac92xx_dc_bias_info, \
999 .get = stac92xx_dc_bias_get, \
1000 .put = stac92xx_dc_bias_put, \
1001 .private_value = nid, \
1002 }
1003
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001004static struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001005 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001006 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001007 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1008 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001009 { } /* end */
1010};
1011
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001012static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1013 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1014 {}
1015};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001016
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001017static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1018 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1019 {}
1020};
1021
1022static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1023 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1024 {}
1025};
1026
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001027
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001028static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1029 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1030};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001031
Tobin Davis8e21c342007-01-08 11:04:17 +01001032static struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001033 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001034 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001035 { } /* end */
1036};
1037
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001038static struct snd_kcontrol_new stac9205_loopback[] = {
1039 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1040 {}
1041};
1042
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001043static struct snd_kcontrol_new stac927x_loopback[] = {
1044 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1045 {}
1046};
1047
Takashi Iwai1697055e2007-12-18 18:05:52 +01001048static struct snd_kcontrol_new stac_dmux_mixer = {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 .name = "Digital Input Source",
1051 /* count set later */
1052 .info = stac92xx_dmux_enum_info,
1053 .get = stac92xx_dmux_enum_get,
1054 .put = stac92xx_dmux_enum_put,
1055};
1056
Matthew Ranostayd9737752008-09-07 12:03:41 +02001057static struct snd_kcontrol_new stac_smux_mixer = {
1058 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001059 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001060 /* count set later */
1061 .info = stac92xx_smux_enum_info,
1062 .get = stac92xx_smux_enum_get,
1063 .put = stac92xx_smux_enum_put,
1064};
1065
Takashi Iwaiea734962011-01-17 11:29:34 +01001066static const char * const slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001067 "Front Playback Volume",
1068 "Surround Playback Volume",
1069 "Center Playback Volume",
1070 "LFE Playback Volume",
1071 "Side Playback Volume",
1072 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001073 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001074 NULL
1075};
1076
Takashi Iwaiea734962011-01-17 11:29:34 +01001077static const char * const slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001078 "Front Playback Switch",
1079 "Surround Playback Switch",
1080 "Center Playback Switch",
1081 "LFE Playback Switch",
1082 "Side Playback Switch",
1083 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001084 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001085 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001086 NULL
1087};
1088
Takashi Iwai603c4012008-07-30 15:01:44 +02001089static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001090static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001091
Matt2f2f4252005-04-13 14:45:30 +02001092static int stac92xx_build_controls(struct hda_codec *codec)
1093{
1094 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001095 struct auto_pin_cfg *cfg = &spec->autocfg;
1096 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001097 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001098 int i;
Matt2f2f4252005-04-13 14:45:30 +02001099
Takashi Iwai6479c632009-07-28 18:20:25 +02001100 if (spec->mixer) {
1101 err = snd_hda_add_new_ctls(codec, spec->mixer);
1102 if (err < 0)
1103 return err;
1104 }
Mattc7d4b2f2005-06-27 14:59:41 +02001105
1106 for (i = 0; i < spec->num_mixers; i++) {
1107 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1108 if (err < 0)
1109 return err;
1110 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001111 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1112 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001113 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001114 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001115 snd_ctl_new1(&stac_dmux_mixer, codec));
1116 if (err < 0)
1117 return err;
1118 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001119 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001120 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1121 struct hda_input_mux *smux = &spec->private_smux;
1122 /* check for mute support on SPDIF out */
1123 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001124 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001125 spec->spdif_mute = 1;
1126 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001127 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001128 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001129 snd_ctl_new1(&stac_smux_mixer, codec));
1130 if (err < 0)
1131 return err;
1132 }
Mattc7d4b2f2005-06-27 14:59:41 +02001133
Mattdabbed62005-06-14 10:19:34 +02001134 if (spec->multiout.dig_out_nid) {
1135 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1136 if (err < 0)
1137 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001138 err = snd_hda_create_spdif_share_sw(codec,
1139 &spec->multiout);
1140 if (err < 0)
1141 return err;
1142 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001143 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001144 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001145 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1146 if (err < 0)
1147 return err;
1148 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001149
1150 /* if we have no master control, let's create it */
1151 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001152 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001153 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001154 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001155 /* correct volume offset */
1156 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001157 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001158 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001159 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001160 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001161 if (err < 0)
1162 return err;
1163 }
1164 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1165 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1166 NULL, slave_sws);
1167 if (err < 0)
1168 return err;
1169 }
1170
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001171 if (spec->aloopback_ctl &&
1172 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1173 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1174 if (err < 0)
1175 return err;
1176 }
1177
Takashi Iwai603c4012008-07-30 15:01:44 +02001178 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001179
1180 /* create jack input elements */
1181 if (spec->hp_detect) {
1182 for (i = 0; i < cfg->hp_outs; i++) {
1183 int type = SND_JACK_HEADPHONE;
1184 nid = cfg->hp_pins[i];
1185 /* jack detection */
1186 if (cfg->hp_outs == i)
1187 type |= SND_JACK_LINEOUT;
1188 err = stac92xx_add_jack(codec, nid, type);
1189 if (err < 0)
1190 return err;
1191 }
1192 }
1193 for (i = 0; i < cfg->line_outs; i++) {
1194 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1195 SND_JACK_LINEOUT);
1196 if (err < 0)
1197 return err;
1198 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001199 for (i = 0; i < cfg->num_inputs; i++) {
1200 nid = cfg->inputs[i].pin;
1201 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1202 if (err < 0)
1203 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001204 }
1205
Mattdabbed62005-06-14 10:19:34 +02001206 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001207}
1208
Matt Porter403d1942005-11-29 15:00:51 +01001209static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001210 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001211 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1212};
1213
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001214static unsigned int gateway9200_m4_pin_configs[8] = {
1215 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1216 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1217};
1218static unsigned int gateway9200_m4_2_pin_configs[8] = {
1219 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1220 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1221};
1222
1223/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001224 STAC 9200 pin configs for
1225 102801A8
1226 102801DE
1227 102801E8
1228*/
1229static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001230 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1231 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001232};
1233
1234/*
1235 STAC 9200 pin configs for
1236 102801C0
1237 102801C1
1238*/
1239static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001240 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1241 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001242};
1243
1244/*
1245 STAC 9200 pin configs for
1246 102801C4 (Dell Dimension E310)
1247 102801C5
1248 102801C7
1249 102801D9
1250 102801DA
1251 102801E3
1252*/
1253static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001254 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1255 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001256};
1257
1258
1259/*
1260 STAC 9200-32 pin configs for
1261 102801B5 (Dell Inspiron 630m)
1262 102801D8 (Dell Inspiron 640m)
1263*/
1264static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001265 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1266 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001267};
1268
1269/*
1270 STAC 9200-32 pin configs for
1271 102801C2 (Dell Latitude D620)
1272 102801C8
1273 102801CC (Dell Latitude D820)
1274 102801D4
1275 102801D6
1276*/
1277static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001278 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1279 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001280};
1281
1282/*
1283 STAC 9200-32 pin configs for
1284 102801CE (Dell XPS M1710)
1285 102801CF (Dell Precision M90)
1286*/
1287static unsigned int dell9200_m23_pin_configs[8] = {
1288 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1289 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1290};
1291
1292/*
1293 STAC 9200-32 pin configs for
1294 102801C9
1295 102801CA
1296 102801CB (Dell Latitude 120L)
1297 102801D3
1298*/
1299static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001300 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1301 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001302};
1303
1304/*
1305 STAC 9200-32 pin configs for
1306 102801BD (Dell Inspiron E1505n)
1307 102801EE
1308 102801EF
1309*/
1310static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001311 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1312 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001313};
1314
1315/*
1316 STAC 9200-32 pin configs for
1317 102801F5 (Dell Inspiron 1501)
1318 102801F6
1319*/
1320static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001321 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1322 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001323};
1324
1325/*
1326 STAC 9200-32
1327 102801CD (Dell Inspiron E1705/9400)
1328*/
1329static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001330 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1331 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001332};
1333
Tobin Davisbf277782008-02-03 20:31:47 +01001334static unsigned int oqo9200_pin_configs[8] = {
1335 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1336 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1337};
1338
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001339
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001340static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1341 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001342 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001343 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1344 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1345 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1346 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1347 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1348 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1349 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1350 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1351 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1352 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001353 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1354 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001355 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001356};
1357
Takashi Iwaiea734962011-01-17 11:29:34 +01001358static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001359 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001360 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001361 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001362 [STAC_9200_DELL_D21] = "dell-d21",
1363 [STAC_9200_DELL_D22] = "dell-d22",
1364 [STAC_9200_DELL_D23] = "dell-d23",
1365 [STAC_9200_DELL_M21] = "dell-m21",
1366 [STAC_9200_DELL_M22] = "dell-m22",
1367 [STAC_9200_DELL_M23] = "dell-m23",
1368 [STAC_9200_DELL_M24] = "dell-m24",
1369 [STAC_9200_DELL_M25] = "dell-m25",
1370 [STAC_9200_DELL_M26] = "dell-m26",
1371 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001372 [STAC_9200_M4] = "gateway-m4",
1373 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001374 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001375};
1376
1377static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1378 /* SigmaTel reference board */
1379 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1380 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001381 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1382 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001383 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1385 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001387 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1389 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1391 "unknown Dell", STAC_9200_DELL_D22),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1393 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001395 "Dell Latitude D620", STAC_9200_DELL_M22),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1397 "unknown Dell", STAC_9200_DELL_D23),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1399 "unknown Dell", STAC_9200_DELL_D23),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1401 "unknown Dell", STAC_9200_DELL_M22),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1403 "unknown Dell", STAC_9200_DELL_M24),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1405 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001407 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001409 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001411 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001413 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001415 "Dell Precision M90", STAC_9200_DELL_M23),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1417 "unknown Dell", STAC_9200_DELL_M22),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1419 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001421 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001423 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1425 "unknown Dell", STAC_9200_DELL_D23),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1427 "unknown Dell", STAC_9200_DELL_D23),
1428 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1429 "unknown Dell", STAC_9200_DELL_D21),
1430 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1431 "unknown Dell", STAC_9200_DELL_D23),
1432 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1433 "unknown Dell", STAC_9200_DELL_D21),
1434 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1435 "unknown Dell", STAC_9200_DELL_M25),
1436 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1437 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001438 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001439 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1440 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1441 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001442 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001443 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001444 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001445 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1446 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1447 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001448 /* OQO Mobile */
1449 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001450 {} /* terminator */
1451};
1452
Tobin Davis8e21c342007-01-08 11:04:17 +01001453static unsigned int ref925x_pin_configs[8] = {
1454 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001455 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001456};
1457
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001458static unsigned int stac925xM1_pin_configs[8] = {
1459 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1460 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001461};
1462
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001463static unsigned int stac925xM1_2_pin_configs[8] = {
1464 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1465 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1466};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001467
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001468static unsigned int stac925xM2_pin_configs[8] = {
1469 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1470 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001471};
1472
Tobin Davis8e21c342007-01-08 11:04:17 +01001473static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001474 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1475 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1476};
1477
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001478static unsigned int stac925xM3_pin_configs[8] = {
1479 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1480 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1481};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001482
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001483static unsigned int stac925xM5_pin_configs[8] = {
1484 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1485 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1486};
1487
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001488static unsigned int stac925xM6_pin_configs[8] = {
1489 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1490 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001491};
1492
1493static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1494 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001495 [STAC_M1] = stac925xM1_pin_configs,
1496 [STAC_M1_2] = stac925xM1_2_pin_configs,
1497 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001498 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001499 [STAC_M3] = stac925xM3_pin_configs,
1500 [STAC_M5] = stac925xM5_pin_configs,
1501 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001502};
1503
Takashi Iwaiea734962011-01-17 11:29:34 +01001504static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001505 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001506 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001507 [STAC_M1] = "m1",
1508 [STAC_M1_2] = "m1-2",
1509 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001510 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001511 [STAC_M3] = "m3",
1512 [STAC_M5] = "m5",
1513 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001514};
1515
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001516static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001517 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1518 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1519 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1520 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001521 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001522 /* Not sure about the brand name for those */
1523 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1524 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1525 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1526 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001527 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001528};
1529
1530static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1531 /* SigmaTel reference board */
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001533 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001534 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001535
1536 /* Default table for unknown ID */
1537 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1538
Tobin Davis8e21c342007-01-08 11:04:17 +01001539 {} /* terminator */
1540};
1541
Matthew Ranostaya7662642008-02-21 07:51:14 +01001542static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001543 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1544 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1545 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001546 0x01452050,
1547};
1548
1549static unsigned int dell_m6_pin_configs[13] = {
1550 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001551 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001552 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1553 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001554};
1555
Takashi Iwai842ae632009-09-02 07:43:08 +02001556static unsigned int alienware_m17x_pin_configs[13] = {
1557 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1558 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1559 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1560 0x904601b0,
1561};
1562
Wu Fengguang4d26f442010-05-07 08:47:54 +08001563static unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001564 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001565 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001566};
1567
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001568static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001569 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001570 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1571 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1572 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001573 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001574 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001575 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001576};
1577
Takashi Iwaiea734962011-01-17 11:29:34 +01001578static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001579 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001580 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001581 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001582 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001583 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1584 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1585 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001586 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001587 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001588};
1589
1590static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1591 /* SigmaTel reference board */
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001593 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001594 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1595 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1597 "Intel DG45ID", STAC_92HD73XX_INTEL),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1599 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001601 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001603 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001605 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001607 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001609 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001611 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001613 "unknown Dell", STAC_DELL_M6_DMIC),
1614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1615 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001617 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1619 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1621 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1623 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001624 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1625 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001626 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1627 "Dell Studio 1558", STAC_DELL_M6_BOTH),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001628 {} /* terminator */
1629};
1630
Takashi Iwai842ae632009-09-02 07:43:08 +02001631static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1633 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001634 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1635 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwai842ae632009-09-02 07:43:08 +02001636 {} /* terminator */
1637};
1638
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001639static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001640 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1641 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001642 0x01451160, 0x98560170,
1643};
1644
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001645static unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001646 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1647 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001648 0x40f000f0, 0x40f000f0,
1649};
1650
Steven Eastland48315592010-08-06 15:07:35 -06001651static unsigned int hp_dv7_4000_pin_configs[10] = {
1652 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1653 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1654 0x40f000f0, 0x40f000f0,
1655};
1656
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001657static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1658 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001659 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001660 [STAC_DELL_S14] = dell_s14_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001661 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001662};
1663
Takashi Iwaiea734962011-01-17 11:29:34 +01001664static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001665 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001666 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001667 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001668 [STAC_DELL_S14] = "dell-s14",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001669 [STAC_92HD83XXX_HP] = "hp",
Steven Eastland48315592010-08-06 15:07:35 -06001670 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001671};
1672
1673static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1674 /* SigmaTel reference board */
1675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001676 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001677 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1678 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001679 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1680 "unknown Dell", STAC_DELL_S14),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001681 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1682 "HP", STAC_92HD83XXX_HP),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001683 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001684};
1685
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001686static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001687 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001688 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001689 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1690 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001691};
1692
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001693static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001694 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001695 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001696 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1697 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001698};
1699
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001700static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001701 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1702 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001703 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1704 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001705};
1706
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001707static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001708 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1709 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001710 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1711 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001712};
1713
Matthew Ranostaye035b842007-11-06 11:53:55 +01001714static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1715 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001716 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1717 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001718 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001719 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001720 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001721 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001722 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001723 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001724};
1725
Takashi Iwaiea734962011-01-17 11:29:34 +01001726static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001727 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001728 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001729 [STAC_DELL_M4_1] = "dell-m4-1",
1730 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001731 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001732 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001733 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001734 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001735 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001736 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001737};
1738
1739static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1740 /* SigmaTel reference board */
1741 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1742 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001743 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1744 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001745 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1746 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001747 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1748 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001749 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1750 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001751 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001752 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001753 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1754 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001755 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1756 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001757 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001758 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001759 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001760 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001761 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1762 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301763 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1764 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001765 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1766 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001767 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1768 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1770 "unknown Dell", STAC_DELL_M4_1),
1771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1772 "unknown Dell", STAC_DELL_M4_1),
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1774 "unknown Dell", STAC_DELL_M4_1),
1775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1776 "unknown Dell", STAC_DELL_M4_1),
1777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1778 "unknown Dell", STAC_DELL_M4_1),
1779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1780 "unknown Dell", STAC_DELL_M4_1),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1782 "unknown Dell", STAC_DELL_M4_1),
1783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1784 "unknown Dell", STAC_DELL_M4_2),
1785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1786 "unknown Dell", STAC_DELL_M4_2),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1788 "unknown Dell", STAC_DELL_M4_2),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1790 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1792 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001793 {} /* terminator */
1794};
1795
Matt Porter403d1942005-11-29 15:00:51 +01001796static unsigned int ref922x_pin_configs[10] = {
1797 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1798 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001799 0x40000100, 0x40000100,
1800};
1801
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001802/*
1803 STAC 922X pin configs for
1804 102801A7
1805 102801AB
1806 102801A9
1807 102801D1
1808 102801D2
1809*/
1810static unsigned int dell_922x_d81_pin_configs[10] = {
1811 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1812 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1813 0x01813122, 0x400001f2,
1814};
1815
1816/*
1817 STAC 922X pin configs for
1818 102801AC
1819 102801D0
1820*/
1821static unsigned int dell_922x_d82_pin_configs[10] = {
1822 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1823 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1824 0x01813122, 0x400001f1,
1825};
1826
1827/*
1828 STAC 922X pin configs for
1829 102801BF
1830*/
1831static unsigned int dell_922x_m81_pin_configs[10] = {
1832 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1833 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1834 0x40C003f1, 0x405003f0,
1835};
1836
1837/*
1838 STAC 9221 A1 pin configs for
1839 102801D7 (Dell XPS M1210)
1840*/
1841static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001842 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1843 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001844 0x508003f3, 0x405003f4,
1845};
1846
Matt Porter403d1942005-11-29 15:00:51 +01001847static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001848 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001849 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1850 0x02a19120, 0x40000100,
1851};
1852
1853static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001854 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1855 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001856 0x02a19320, 0x40000100,
1857};
1858
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001859static unsigned int intel_mac_v1_pin_configs[10] = {
1860 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1861 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001862 0x400000fc, 0x400000fb,
1863};
1864
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001865static unsigned int intel_mac_v2_pin_configs[10] = {
1866 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1867 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001868 0x400000fc, 0x400000fb,
1869};
1870
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001871static unsigned int intel_mac_v3_pin_configs[10] = {
1872 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1873 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1874 0x400000fc, 0x400000fb,
1875};
1876
1877static unsigned int intel_mac_v4_pin_configs[10] = {
1878 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1879 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1880 0x400000fc, 0x400000fb,
1881};
1882
1883static unsigned int intel_mac_v5_pin_configs[10] = {
1884 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1885 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1886 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001887};
1888
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001889static unsigned int ecs202_pin_configs[10] = {
1890 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1891 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1892 0x9037012e, 0x40e000f2,
1893};
Takashi Iwai76c08822007-06-19 12:17:42 +02001894
Takashi Iwai19039bd2006-06-28 15:52:16 +02001895static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001896 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001897 [STAC_D945GTP3] = d945gtp3_pin_configs,
1898 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001899 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1900 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1901 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1902 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1903 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001904 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001905 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001906 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1907 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1908 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1909 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1910 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1911 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001912 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001913 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1914 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1915 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1916 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001917};
1918
Takashi Iwaiea734962011-01-17 11:29:34 +01001919static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001920 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001921 [STAC_D945_REF] = "ref",
1922 [STAC_D945GTP5] = "5stack",
1923 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001924 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1925 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1926 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1927 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1928 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001929 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001930 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001931 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001932 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001933 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1934 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001935 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001936 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001937 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001938 [STAC_922X_DELL_D81] = "dell-d81",
1939 [STAC_922X_DELL_D82] = "dell-d82",
1940 [STAC_922X_DELL_M81] = "dell-m81",
1941 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001942};
1943
1944static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1945 /* SigmaTel reference board */
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1947 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001948 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1949 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001950 /* Intel 945G based systems */
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1952 "Intel D945G", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1954 "Intel D945G", STAC_D945GTP3),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1956 "Intel D945G", STAC_D945GTP3),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1958 "Intel D945G", STAC_D945GTP3),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1960 "Intel D945G", STAC_D945GTP3),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1962 "Intel D945G", STAC_D945GTP3),
1963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1964 "Intel D945G", STAC_D945GTP3),
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1966 "Intel D945G", STAC_D945GTP3),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1968 "Intel D945G", STAC_D945GTP3),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1970 "Intel D945G", STAC_D945GTP3),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1972 "Intel D945G", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1974 "Intel D945G", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1976 "Intel D945G", STAC_D945GTP3),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1978 "Intel D945G", STAC_D945GTP3),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1980 "Intel D945G", STAC_D945GTP3),
1981 /* Intel D945G 5-stack systems */
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1983 "Intel D945G", STAC_D945GTP5),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1985 "Intel D945G", STAC_D945GTP5),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1987 "Intel D945G", STAC_D945GTP5),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1989 "Intel D945G", STAC_D945GTP5),
1990 /* Intel 945P based systems */
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1992 "Intel D945P", STAC_D945GTP3),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1994 "Intel D945P", STAC_D945GTP3),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1996 "Intel D945P", STAC_D945GTP3),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1998 "Intel D945P", STAC_D945GTP3),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2000 "Intel D945P", STAC_D945GTP3),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2002 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002003 /* other intel */
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2005 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002006 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002007 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002008 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002009 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002010 /* Dell systems */
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2012 "unknown Dell", STAC_922X_DELL_D81),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2014 "unknown Dell", STAC_922X_DELL_D81),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2016 "unknown Dell", STAC_922X_DELL_D81),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2018 "unknown Dell", STAC_922X_DELL_D82),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2020 "unknown Dell", STAC_922X_DELL_M81),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2022 "unknown Dell", STAC_922X_DELL_D82),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2024 "unknown Dell", STAC_922X_DELL_D81),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2026 "unknown Dell", STAC_922X_DELL_D81),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2028 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002029 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002030 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002031 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002032 {} /* terminator */
2033};
2034
Matt Porter3cc08dc2006-01-23 15:27:49 +01002035static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002036 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2037 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2038 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2039 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002040};
2041
Tobin Davis93ed1502006-09-01 21:03:12 +02002042static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002043 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2044 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2045 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2046 0x40000100, 0x40000100
2047};
2048
Tobin Davis93ed1502006-09-01 21:03:12 +02002049static unsigned int d965_5st_pin_configs[14] = {
2050 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2051 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2052 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2053 0x40000100, 0x40000100
2054};
2055
Takashi Iwai679d92e2009-05-24 19:00:08 +02002056static unsigned int d965_5st_no_fp_pin_configs[14] = {
2057 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2058 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2059 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2060 0x40000100, 0x40000100
2061};
2062
Tobin Davis4ff076e2007-08-07 11:48:12 +02002063static unsigned int dell_3st_pin_configs[14] = {
2064 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2065 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002066 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002067 0x40c003fc, 0x40000100
2068};
2069
Tobin Davis93ed1502006-09-01 21:03:12 +02002070static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002071 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002072 [STAC_D965_REF] = ref927x_pin_configs,
2073 [STAC_D965_3ST] = d965_3st_pin_configs,
2074 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002075 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002076 [STAC_DELL_3ST] = dell_3st_pin_configs,
2077 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002078 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002079};
2080
Takashi Iwaiea734962011-01-17 11:29:34 +01002081static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002082 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002083 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002084 [STAC_D965_REF] = "ref",
2085 [STAC_D965_3ST] = "3stack",
2086 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002087 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002088 [STAC_DELL_3ST] = "dell-3stack",
2089 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002090 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002091};
2092
2093static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2094 /* SigmaTel reference board */
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2096 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002097 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2098 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002099 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002102 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002103 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2104 "Intel D965", STAC_D965_3ST),
2105 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2106 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002107 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002108 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002109 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002111 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002112 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002113 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002115 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002117 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002121 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002122 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2123 "Intel D965", STAC_D965_5ST),
2124 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2125 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002126 /* volume-knob fixes */
2127 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002128 {} /* terminator */
2129};
2130
Matt Porterf3302a52006-07-31 12:49:34 +02002131static unsigned int ref9205_pin_configs[12] = {
2132 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002133 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002134 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002135};
2136
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002137/*
2138 STAC 9205 pin configs for
2139 102801F1
2140 102801F2
2141 102801FC
2142 102801FD
2143 10280204
2144 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002145 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002146 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002147*/
2148static unsigned int dell_9205_m42_pin_configs[12] = {
2149 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2150 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2151 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2152};
2153
2154/*
2155 STAC 9205 pin configs for
2156 102801F9
2157 102801FA
2158 102801FE
2159 102801FF (Dell Precision M4300)
2160 10280206
2161 10280200
2162 10280201
2163*/
2164static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002165 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2166 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2167 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2168};
2169
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002170static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002171 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2172 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2173 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2174};
2175
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002176static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002177 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002178 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2179 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2180 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002181 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002182};
2183
Takashi Iwaiea734962011-01-17 11:29:34 +01002184static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002185 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002186 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002187 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002188 [STAC_9205_DELL_M43] = "dell-m43",
2189 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002190 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002191};
2192
2193static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2194 /* SigmaTel reference board */
2195 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2196 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002197 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2198 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002199 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2200 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002201 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2203 "unknown Dell", STAC_9205_DELL_M42),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2205 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002207 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2209 "Dell Precision", STAC_9205_DELL_M43),
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2211 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2213 "unknown Dell", STAC_9205_DELL_M42),
2214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2215 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2217 "Dell Precision", STAC_9205_DELL_M43),
2218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002219 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2221 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2223 "Dell Precision", STAC_9205_DELL_M43),
2224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2225 "Dell Precision", STAC_9205_DELL_M43),
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2227 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2229 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2231 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2233 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002234 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002235 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002236 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002237 {} /* terminator */
2238};
2239
Takashi Iwai330ee992009-02-20 14:33:36 +01002240static void stac92xx_set_config_regs(struct hda_codec *codec,
2241 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002242{
2243 int i;
2244 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002245
Takashi Iwai330ee992009-02-20 14:33:36 +01002246 if (!pincfgs)
2247 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002248
Matthew Ranostay87d48362007-07-17 11:52:24 +02002249 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002250 if (spec->pin_nids[i] && pincfgs[i])
2251 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2252 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002253}
2254
Matt2f2f4252005-04-13 14:45:30 +02002255/*
2256 * Analog playback callbacks
2257 */
2258static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2259 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002260 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002261{
2262 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002263 if (spec->stream_delay)
2264 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002265 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2266 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002267}
2268
2269static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2270 struct hda_codec *codec,
2271 unsigned int stream_tag,
2272 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002273 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002274{
2275 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002276 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002277}
2278
2279static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2280 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002281 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002282{
2283 struct sigmatel_spec *spec = codec->spec;
2284 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2285}
2286
2287/*
Mattdabbed62005-06-14 10:19:34 +02002288 * Digital playback callbacks
2289 */
2290static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2291 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002292 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002293{
2294 struct sigmatel_spec *spec = codec->spec;
2295 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2296}
2297
2298static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2299 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002300 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002301{
2302 struct sigmatel_spec *spec = codec->spec;
2303 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2304}
2305
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002306static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2307 struct hda_codec *codec,
2308 unsigned int stream_tag,
2309 unsigned int format,
2310 struct snd_pcm_substream *substream)
2311{
2312 struct sigmatel_spec *spec = codec->spec;
2313 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2314 stream_tag, format, substream);
2315}
2316
Takashi Iwai9411e212009-02-13 11:32:28 +01002317static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2318 struct hda_codec *codec,
2319 struct snd_pcm_substream *substream)
2320{
2321 struct sigmatel_spec *spec = codec->spec;
2322 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2323}
2324
Mattdabbed62005-06-14 10:19:34 +02002325
2326/*
Matt2f2f4252005-04-13 14:45:30 +02002327 * Analog capture callbacks
2328 */
2329static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2330 struct hda_codec *codec,
2331 unsigned int stream_tag,
2332 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002333 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002334{
2335 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002336 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002337
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002338 if (spec->powerdown_adcs) {
2339 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002340 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002341 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2342 }
2343 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002344 return 0;
2345}
2346
2347static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2348 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002349 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002350{
2351 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002352 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002353
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002354 snd_hda_codec_cleanup_stream(codec, nid);
2355 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002356 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002357 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002358 return 0;
2359}
2360
Mattdabbed62005-06-14 10:19:34 +02002361static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2362 .substreams = 1,
2363 .channels_min = 2,
2364 .channels_max = 2,
2365 /* NID is set in stac92xx_build_pcms */
2366 .ops = {
2367 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002368 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002369 .prepare = stac92xx_dig_playback_pcm_prepare,
2370 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002371 },
2372};
2373
2374static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2375 .substreams = 1,
2376 .channels_min = 2,
2377 .channels_max = 2,
2378 /* NID is set in stac92xx_build_pcms */
2379};
2380
Matt2f2f4252005-04-13 14:45:30 +02002381static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2382 .substreams = 1,
2383 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002384 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002385 .nid = 0x02, /* NID to query formats and rates */
2386 .ops = {
2387 .open = stac92xx_playback_pcm_open,
2388 .prepare = stac92xx_playback_pcm_prepare,
2389 .cleanup = stac92xx_playback_pcm_cleanup
2390 },
2391};
2392
Matt Porter3cc08dc2006-01-23 15:27:49 +01002393static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2394 .substreams = 1,
2395 .channels_min = 2,
2396 .channels_max = 2,
2397 .nid = 0x06, /* NID to query formats and rates */
2398 .ops = {
2399 .open = stac92xx_playback_pcm_open,
2400 .prepare = stac92xx_playback_pcm_prepare,
2401 .cleanup = stac92xx_playback_pcm_cleanup
2402 },
2403};
2404
Matt2f2f4252005-04-13 14:45:30 +02002405static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002406 .channels_min = 2,
2407 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002408 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002409 .ops = {
2410 .prepare = stac92xx_capture_pcm_prepare,
2411 .cleanup = stac92xx_capture_pcm_cleanup
2412 },
2413};
2414
2415static int stac92xx_build_pcms(struct hda_codec *codec)
2416{
2417 struct sigmatel_spec *spec = codec->spec;
2418 struct hda_pcm *info = spec->pcm_rec;
2419
2420 codec->num_pcms = 1;
2421 codec->pcm_info = info;
2422
Mattc7d4b2f2005-06-27 14:59:41 +02002423 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002424 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002425 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2426 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002427 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002428 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002429 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002430
2431 if (spec->alt_switch) {
2432 codec->num_pcms++;
2433 info++;
2434 info->name = "STAC92xx Analog Alt";
2435 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2436 }
Matt2f2f4252005-04-13 14:45:30 +02002437
Mattdabbed62005-06-14 10:19:34 +02002438 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2439 codec->num_pcms++;
2440 info++;
2441 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002442 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002443 if (spec->multiout.dig_out_nid) {
2444 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2445 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2446 }
2447 if (spec->dig_in_nid) {
2448 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2449 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2450 }
2451 }
2452
Matt2f2f4252005-04-13 14:45:30 +02002453 return 0;
2454}
2455
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002456static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2457 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002458{
Takashi Iwai1327a322009-03-23 13:07:47 +01002459 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002460 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2461 if (pincap & AC_PINCAP_VREF_100)
2462 return AC_PINCTL_VREF_100;
2463 if (pincap & AC_PINCAP_VREF_80)
2464 return AC_PINCTL_VREF_80;
2465 if (pincap & AC_PINCAP_VREF_50)
2466 return AC_PINCTL_VREF_50;
2467 if (pincap & AC_PINCAP_VREF_GRD)
2468 return AC_PINCTL_VREF_GRD;
2469 return 0;
2470}
2471
Matt Porter403d1942005-11-29 15:00:51 +01002472static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2473
2474{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002475 snd_hda_codec_write_cache(codec, nid, 0,
2476 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002477}
2478
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002479#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2480
2481static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2482 struct snd_ctl_elem_value *ucontrol)
2483{
2484 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2485 struct sigmatel_spec *spec = codec->spec;
2486
Takashi Iwaid7a89432008-11-12 09:48:04 +01002487 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002488 return 0;
2489}
2490
Takashi Iwai62558ce2009-07-29 14:23:09 +02002491static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002492
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002493static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2494 struct snd_ctl_elem_value *ucontrol)
2495{
2496 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2497 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002498 int nid = kcontrol->private_value;
2499
2500 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002501
2502 /* check to be sure that the ports are upto date with
2503 * switch changes
2504 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002505 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002506
2507 return 1;
2508}
2509
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002510static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2511 struct snd_ctl_elem_info *uinfo)
2512{
2513 int i;
2514 static char *texts[] = {
2515 "Mic In", "Line In", "Line Out"
2516 };
2517
2518 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2519 struct sigmatel_spec *spec = codec->spec;
2520 hda_nid_t nid = kcontrol->private_value;
2521
2522 if (nid == spec->mic_switch || nid == spec->line_switch)
2523 i = 3;
2524 else
2525 i = 2;
2526
2527 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2528 uinfo->value.enumerated.items = i;
2529 uinfo->count = 1;
2530 if (uinfo->value.enumerated.item >= i)
2531 uinfo->value.enumerated.item = i-1;
2532 strcpy(uinfo->value.enumerated.name,
2533 texts[uinfo->value.enumerated.item]);
2534
2535 return 0;
2536}
2537
2538static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2539 struct snd_ctl_elem_value *ucontrol)
2540{
2541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2542 hda_nid_t nid = kcontrol->private_value;
2543 unsigned int vref = stac92xx_vref_get(codec, nid);
2544
2545 if (vref == stac92xx_get_default_vref(codec, nid))
2546 ucontrol->value.enumerated.item[0] = 0;
2547 else if (vref == AC_PINCTL_VREF_GRD)
2548 ucontrol->value.enumerated.item[0] = 1;
2549 else if (vref == AC_PINCTL_VREF_HIZ)
2550 ucontrol->value.enumerated.item[0] = 2;
2551
2552 return 0;
2553}
2554
2555static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2556 struct snd_ctl_elem_value *ucontrol)
2557{
2558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2559 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002560 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002561 hda_nid_t nid = kcontrol->private_value;
2562
2563 if (ucontrol->value.enumerated.item[0] == 0)
2564 new_vref = stac92xx_get_default_vref(codec, nid);
2565 else if (ucontrol->value.enumerated.item[0] == 1)
2566 new_vref = AC_PINCTL_VREF_GRD;
2567 else if (ucontrol->value.enumerated.item[0] == 2)
2568 new_vref = AC_PINCTL_VREF_HIZ;
2569 else
2570 return 0;
2571
2572 if (new_vref != stac92xx_vref_get(codec, nid)) {
2573 error = stac92xx_vref_set(codec, nid, new_vref);
2574 return error;
2575 }
2576
2577 return 0;
2578}
2579
2580static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2581 struct snd_ctl_elem_info *uinfo)
2582{
2583 static char *texts[2];
2584 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2585 struct sigmatel_spec *spec = codec->spec;
2586
2587 if (kcontrol->private_value == spec->line_switch)
2588 texts[0] = "Line In";
2589 else
2590 texts[0] = "Mic In";
2591 texts[1] = "Line Out";
2592 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2593 uinfo->value.enumerated.items = 2;
2594 uinfo->count = 1;
2595
2596 if (uinfo->value.enumerated.item >= 2)
2597 uinfo->value.enumerated.item = 1;
2598 strcpy(uinfo->value.enumerated.name,
2599 texts[uinfo->value.enumerated.item]);
2600
2601 return 0;
2602}
Matt Porter403d1942005-11-29 15:00:51 +01002603
2604static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2605{
2606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2607 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002608 hda_nid_t nid = kcontrol->private_value;
2609 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002610
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002611 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002612 return 0;
2613}
2614
2615static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2616{
2617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2618 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002619 hda_nid_t nid = kcontrol->private_value;
2620 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2621 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002622
2623 spec->io_switch[io_idx] = val;
2624
2625 if (val)
2626 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002627 else {
2628 unsigned int pinctl = AC_PINCTL_IN_EN;
2629 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002630 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002631 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2632 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002633
2634 /* check the auto-mute again: we need to mute/unmute the speaker
2635 * appropriately according to the pin direction
2636 */
2637 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002638 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002639
Matt Porter403d1942005-11-29 15:00:51 +01002640 return 1;
2641}
2642
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002643#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2644
2645static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2646 struct snd_ctl_elem_value *ucontrol)
2647{
2648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2649 struct sigmatel_spec *spec = codec->spec;
2650
2651 ucontrol->value.integer.value[0] = spec->clfe_swap;
2652 return 0;
2653}
2654
2655static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2656 struct snd_ctl_elem_value *ucontrol)
2657{
2658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2659 struct sigmatel_spec *spec = codec->spec;
2660 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002661 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002662
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002663 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002664 return 0;
2665
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002666 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002667
2668 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2669 spec->clfe_swap ? 0x4 : 0x0);
2670
2671 return 1;
2672}
2673
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002674#define STAC_CODEC_HP_SWITCH(xname) \
2675 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2676 .name = xname, \
2677 .index = 0, \
2678 .info = stac92xx_hp_switch_info, \
2679 .get = stac92xx_hp_switch_get, \
2680 .put = stac92xx_hp_switch_put, \
2681 }
2682
Matt Porter403d1942005-11-29 15:00:51 +01002683#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2684 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2685 .name = xname, \
2686 .index = 0, \
2687 .info = stac92xx_io_switch_info, \
2688 .get = stac92xx_io_switch_get, \
2689 .put = stac92xx_io_switch_put, \
2690 .private_value = xpval, \
2691 }
2692
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002693#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2694 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2695 .name = xname, \
2696 .index = 0, \
2697 .info = stac92xx_clfe_switch_info, \
2698 .get = stac92xx_clfe_switch_get, \
2699 .put = stac92xx_clfe_switch_put, \
2700 .private_value = xpval, \
2701 }
Matt Porter403d1942005-11-29 15:00:51 +01002702
Mattc7d4b2f2005-06-27 14:59:41 +02002703enum {
2704 STAC_CTL_WIDGET_VOL,
2705 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002706 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002707 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002708 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002709 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002710 STAC_CTL_WIDGET_CLFE_SWITCH,
2711 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002712};
2713
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002714static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002715 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2716 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002717 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002718 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002719 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002720 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002721 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002722 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002723};
2724
2725/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002726static struct snd_kcontrol_new *
2727stac_control_new(struct sigmatel_spec *spec,
2728 struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002729 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002730 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002731{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002732 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002733
Takashi Iwai603c4012008-07-30 15:01:44 +02002734 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2735 knew = snd_array_new(&spec->kctls);
2736 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002737 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002738 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002739 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002740 if (!knew->name) {
2741 /* roolback */
2742 memset(knew, 0, sizeof(*knew));
2743 spec->kctls.alloced--;
2744 return NULL;
2745 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002746 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002747 return knew;
2748}
2749
2750static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2751 struct snd_kcontrol_new *ktemp,
2752 int idx, const char *name,
2753 unsigned long val)
2754{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002755 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002756 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002757 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002758 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002759 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002760 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002761 return 0;
2762}
2763
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002764static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2765 int type, int idx, const char *name,
2766 unsigned long val)
2767{
2768 return stac92xx_add_control_temp(spec,
2769 &stac92xx_control_templates[type],
2770 idx, name, val);
2771}
2772
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002773
2774/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002775static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2776 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002777{
2778 return stac92xx_add_control_idx(spec, type, 0, name, val);
2779}
2780
Takashi Iwaie3c75962009-01-23 11:57:22 +01002781static struct snd_kcontrol_new stac_input_src_temp = {
2782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2783 .name = "Input Source",
2784 .info = stac92xx_mux_enum_info,
2785 .get = stac92xx_mux_enum_get,
2786 .put = stac92xx_mux_enum_put,
2787};
2788
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002789static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2790 hda_nid_t nid, int idx)
2791{
2792 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2793 int control = 0;
2794 struct sigmatel_spec *spec = codec->spec;
2795 char name[22];
2796
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002797 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002798 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2799 && nid == spec->line_switch)
2800 control = STAC_CTL_WIDGET_IO_SWITCH;
2801 else if (snd_hda_query_pin_caps(codec, nid)
2802 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2803 control = STAC_CTL_WIDGET_DC_BIAS;
2804 else if (nid == spec->mic_switch)
2805 control = STAC_CTL_WIDGET_IO_SWITCH;
2806 }
2807
2808 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002809 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002810 return stac92xx_add_control(codec->spec, control,
2811 strcat(name, " Jack Mode"), nid);
2812 }
2813
2814 return 0;
2815}
2816
Takashi Iwaie3c75962009-01-23 11:57:22 +01002817static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2818{
2819 struct snd_kcontrol_new *knew;
2820 struct hda_input_mux *imux = &spec->private_imux;
2821
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002822 if (spec->auto_mic)
2823 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002824 if (!spec->num_adcs || imux->num_items <= 1)
2825 return 0; /* no need for input source control */
2826 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002827 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002828 if (!knew)
2829 return -ENOMEM;
2830 knew->count = spec->num_adcs;
2831 return 0;
2832}
2833
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002834/* check whether the line-input can be used as line-out */
2835static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002836{
2837 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002838 struct auto_pin_cfg *cfg = &spec->autocfg;
2839 hda_nid_t nid;
2840 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002841 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002842
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002843 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2844 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002845 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002846 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002847 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002848 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002849 if (pincap & AC_PINCAP_OUT)
2850 return nid;
2851 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002852 }
Matt Porter403d1942005-11-29 15:00:51 +01002853 return 0;
2854}
2855
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002856static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2857
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002858/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002859static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002860{
2861 struct sigmatel_spec *spec = codec->spec;
2862 struct auto_pin_cfg *cfg = &spec->autocfg;
2863 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002864 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002865
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002866 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002867 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2868 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002869 for (i = 0; i < cfg->num_inputs; i++) {
2870 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002871 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002872 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002873 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2874 /* some laptops have an internal analog microphone
2875 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002876 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002877 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002878 if (pincap & AC_PINCAP_OUT) {
2879 *dac = get_unassigned_dac(codec, nid);
2880 if (*dac)
2881 return nid;
2882 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002883 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002884 }
2885 return 0;
2886}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002887
2888static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2889{
2890 int i;
2891
2892 for (i = 0; i < spec->multiout.num_dacs; i++) {
2893 if (spec->multiout.dac_nids[i] == nid)
2894 return 1;
2895 }
2896
2897 return 0;
2898}
2899
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002900static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2901{
2902 int i;
2903 if (is_in_dac_nids(spec, nid))
2904 return 1;
2905 for (i = 0; i < spec->autocfg.hp_outs; i++)
2906 if (spec->hp_dacs[i] == nid)
2907 return 1;
2908 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2909 if (spec->speaker_dacs[i] == nid)
2910 return 1;
2911 return 0;
2912}
2913
2914static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2915{
2916 struct sigmatel_spec *spec = codec->spec;
2917 int j, conn_len;
2918 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2919 unsigned int wcaps, wtype;
2920
2921 conn_len = snd_hda_get_connections(codec, nid, conn,
2922 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002923 /* 92HD88: trace back up the link of nids to find the DAC */
2924 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2925 != AC_WID_AUD_OUT)) {
2926 nid = conn[0];
2927 conn_len = snd_hda_get_connections(codec, nid, conn,
2928 HDA_MAX_CONNECTIONS);
2929 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002930 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002931 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002932 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002933 /* we check only analog outputs */
2934 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2935 continue;
2936 /* if this route has a free DAC, assign it */
2937 if (!check_all_dac_nids(spec, conn[j])) {
2938 if (conn_len > 1) {
2939 /* select this DAC in the pin's input mux */
2940 snd_hda_codec_write_cache(codec, nid, 0,
2941 AC_VERB_SET_CONNECT_SEL, j);
2942 }
2943 return conn[j];
2944 }
2945 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002946 /* if all DACs are already assigned, connect to the primary DAC */
2947 if (conn_len > 1) {
2948 for (j = 0; j < conn_len; j++) {
2949 if (conn[j] == spec->multiout.dac_nids[0]) {
2950 snd_hda_codec_write_cache(codec, nid, 0,
2951 AC_VERB_SET_CONNECT_SEL, j);
2952 break;
2953 }
2954 }
2955 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002956 return 0;
2957}
2958
2959static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2960static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2961
Matt Porter3cc08dc2006-01-23 15:27:49 +01002962/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002963 * Fill in the dac_nids table from the parsed pin configuration
2964 * This function only works when every pin in line_out_pins[]
2965 * contains atleast one DAC in its connection list. Some 92xx
2966 * codecs are not connected directly to a DAC, such as the 9200
2967 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002968 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002969static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002970{
2971 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002972 struct auto_pin_cfg *cfg = &spec->autocfg;
2973 int i;
2974 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002975
Mattc7d4b2f2005-06-27 14:59:41 +02002976 for (i = 0; i < cfg->line_outs; i++) {
2977 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002978 dac = get_unassigned_dac(codec, nid);
2979 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002980 if (spec->multiout.num_dacs > 0) {
2981 /* we have already working output pins,
2982 * so let's drop the broken ones again
2983 */
2984 cfg->line_outs = spec->multiout.num_dacs;
2985 break;
2986 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002987 /* error out, no available DAC found */
2988 snd_printk(KERN_ERR
2989 "%s: No available DAC for pin 0x%x\n",
2990 __func__, nid);
2991 return -ENODEV;
2992 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002993 add_spec_dacs(spec, dac);
2994 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002995
Takashi Iwai139e0712009-03-06 12:10:41 +01002996 for (i = 0; i < cfg->hp_outs; i++) {
2997 nid = cfg->hp_pins[i];
2998 dac = get_unassigned_dac(codec, nid);
2999 if (dac) {
3000 if (!spec->multiout.hp_nid)
3001 spec->multiout.hp_nid = dac;
3002 else
3003 add_spec_extra_dacs(spec, dac);
3004 }
3005 spec->hp_dacs[i] = dac;
3006 }
3007
3008 for (i = 0; i < cfg->speaker_outs; i++) {
3009 nid = cfg->speaker_pins[i];
3010 dac = get_unassigned_dac(codec, nid);
3011 if (dac)
3012 add_spec_extra_dacs(spec, dac);
3013 spec->speaker_dacs[i] = dac;
3014 }
3015
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003016 /* add line-in as output */
3017 nid = check_line_out_switch(codec);
3018 if (nid) {
3019 dac = get_unassigned_dac(codec, nid);
3020 if (dac) {
3021 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3022 nid, cfg->line_outs);
3023 cfg->line_out_pins[cfg->line_outs] = nid;
3024 cfg->line_outs++;
3025 spec->line_switch = nid;
3026 add_spec_dacs(spec, dac);
3027 }
3028 }
3029 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003030 nid = check_mic_out_switch(codec, &dac);
3031 if (nid && dac) {
3032 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3033 nid, cfg->line_outs);
3034 cfg->line_out_pins[cfg->line_outs] = nid;
3035 cfg->line_outs++;
3036 spec->mic_switch = nid;
3037 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003038 }
3039
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003040 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003041 spec->multiout.num_dacs,
3042 spec->multiout.dac_nids[0],
3043 spec->multiout.dac_nids[1],
3044 spec->multiout.dac_nids[2],
3045 spec->multiout.dac_nids[3],
3046 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003047
Mattc7d4b2f2005-06-27 14:59:41 +02003048 return 0;
3049}
3050
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003051/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003052static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3053 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003054{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003055 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003056 char name[32];
3057 int err;
3058
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003059 if (!spec->check_volume_offset) {
3060 unsigned int caps, step, nums, db_scale;
3061 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3062 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3063 AC_AMPCAP_STEP_SIZE_SHIFT;
3064 step = (step + 1) * 25; /* in .01dB unit */
3065 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3066 AC_AMPCAP_NUM_STEPS_SHIFT;
3067 db_scale = nums * step;
3068 /* if dB scale is over -64dB, and finer enough,
3069 * let's reduce it to half
3070 */
3071 if (db_scale > 6400 && nums >= 0x1f)
3072 spec->volume_offset = nums / 2;
3073 spec->check_volume_offset = 1;
3074 }
3075
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003076 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003077 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003078 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3079 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003080 if (err < 0)
3081 return err;
3082 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003083 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003084 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3085 if (err < 0)
3086 return err;
3087 return 0;
3088}
3089
Takashi Iwai668b9652009-03-06 10:13:24 +01003090#define create_controls(codec, pfx, nid, chs) \
3091 create_controls_idx(codec, pfx, 0, nid, chs)
3092
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003093static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3094{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003095 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003096 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3097 return 1;
3098 } else {
3099 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3100 spec->multiout.num_dacs++;
3101 }
3102 return 0;
3103}
3104
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003105static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003106{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003107 int i;
3108 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3109 if (!spec->multiout.extra_out_nid[i]) {
3110 spec->multiout.extra_out_nid[i] = nid;
3111 return 0;
3112 }
3113 }
3114 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3115 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003116}
3117
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003118/* Create output controls
3119 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3120 */
3121static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3122 const hda_nid_t *pins,
3123 const hda_nid_t *dac_nids,
3124 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003125{
Takashi Iwai76624532008-12-19 10:09:47 +01003126 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003127 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003128 "Front", "Surround", NULL /*CLFE*/, "Side"
3129 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003130 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003131 int i, err;
3132 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003133
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003134 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003135 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3136 wid_caps = get_wcaps(codec, pins[i]);
3137 if (wid_caps & AC_WCAP_UNSOL_CAP)
3138 spec->hp_detect = 1;
3139 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003140 nid = dac_nids[i];
3141 if (!nid)
3142 continue;
3143 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003144 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003145 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003146 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003147 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003148 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003149 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003150 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003151
3152 wid_caps = get_wcaps(codec, nid);
3153
3154 if (wid_caps & AC_WCAP_LR_SWAP) {
3155 err = stac92xx_add_control(spec,
3156 STAC_CTL_WIDGET_CLFE_SWITCH,
3157 "Swap Center/LFE Playback Switch", nid);
3158
3159 if (err < 0)
3160 return err;
3161 }
3162
Mattc7d4b2f2005-06-27 14:59:41 +02003163 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003164 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003165 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003166 switch (type) {
3167 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003168 name = "Headphone";
3169 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003170 break;
3171 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003172 name = "Speaker";
3173 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003174 break;
3175 default:
3176 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003177 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003178 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003179 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003180 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003181 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003182 return err;
3183 }
3184 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003185 return 0;
3186}
3187
Takashi Iwai6479c632009-07-28 18:20:25 +02003188static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3189 unsigned long sw, int idx)
3190{
3191 int err;
3192 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003193 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003194 if (err < 0)
3195 return err;
3196 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003197 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003198 if (err < 0)
3199 return err;
3200 return 0;
3201}
3202
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003203/* add playback controls from the parsed DAC table */
3204static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3205 const struct auto_pin_cfg *cfg)
3206{
3207 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003208 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003209 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003210 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003211
3212 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3213 spec->multiout.dac_nids,
3214 cfg->line_out_type);
3215 if (err < 0)
3216 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003217
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003218 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003219 err = stac92xx_add_control(spec,
3220 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003221 "Headphone as Line Out Switch",
3222 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003223 if (err < 0)
3224 return err;
3225 }
3226
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003227 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003228 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003229 break;
3230 nid = cfg->inputs[idx].pin;
3231 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3232 if (err < 0)
3233 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003234 }
Matt Porter403d1942005-11-29 15:00:51 +01003235
Mattc7d4b2f2005-06-27 14:59:41 +02003236 return 0;
3237}
3238
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003239/* add playback controls for Speaker and HP outputs */
3240static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3241 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003242{
3243 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003244 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003245
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003246 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3247 spec->hp_dacs, AUTO_PIN_HP_OUT);
3248 if (err < 0)
3249 return err;
3250
3251 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3252 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3253 if (err < 0)
3254 return err;
3255
Mattc7d4b2f2005-06-27 14:59:41 +02003256 return 0;
3257}
3258
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003259/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003260static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003261 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003262};
3263
3264/* create mono mux for mono out on capable codecs */
3265static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3266{
3267 struct sigmatel_spec *spec = codec->spec;
3268 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3269 int i, num_cons;
3270 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3271
3272 num_cons = snd_hda_get_connections(codec,
3273 spec->mono_nid,
3274 con_lst,
3275 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003276 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003277 return -EINVAL;
3278
Takashi Iwai10a20af2010-09-09 16:28:02 +02003279 for (i = 0; i < num_cons; i++)
3280 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3281 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003282
3283 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3284 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003285}
3286
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003287/* create PC beep volume controls */
3288static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3289 hda_nid_t nid)
3290{
3291 struct sigmatel_spec *spec = codec->spec;
3292 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003293 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3294
3295 if (spec->anabeep_nid == nid)
3296 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003297
3298 /* check for mute support for the the amp */
3299 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003300 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003301 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003302 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3303 if (err < 0)
3304 return err;
3305 }
3306
3307 /* check to see if there is volume support for the amp */
3308 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3309 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003310 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003311 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3312 if (err < 0)
3313 return err;
3314 }
3315 return 0;
3316}
3317
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003318#ifdef CONFIG_SND_HDA_INPUT_BEEP
3319#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3320
3321static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3322 struct snd_ctl_elem_value *ucontrol)
3323{
3324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3325 ucontrol->value.integer.value[0] = codec->beep->enabled;
3326 return 0;
3327}
3328
3329static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3330 struct snd_ctl_elem_value *ucontrol)
3331{
3332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003333 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003334}
3335
3336static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3338 .info = stac92xx_dig_beep_switch_info,
3339 .get = stac92xx_dig_beep_switch_get,
3340 .put = stac92xx_dig_beep_switch_put,
3341};
3342
3343static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3344{
3345 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003346 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003347}
3348#endif
3349
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003350static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3351{
3352 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003353 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003354
3355 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003356 hda_nid_t nid;
3357 unsigned int wcaps;
3358 unsigned long val;
3359
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003360 nid = spec->mux_nids[i];
3361 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003362 if (!(wcaps & AC_WCAP_OUT_AMP))
3363 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003364
Takashi Iwai667067d2009-08-13 18:14:42 +02003365 /* check whether already the same control was created as
3366 * normal Capture Volume.
3367 */
3368 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3369 for (j = 0; j < spec->num_caps; j++) {
3370 if (spec->capvols[j] == val)
3371 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003372 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003373 if (j < spec->num_caps)
3374 continue;
3375
3376 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3377 "Mux Capture Volume", val);
3378 if (err < 0)
3379 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003380 }
3381 return 0;
3382};
3383
Takashi Iwaiea734962011-01-17 11:29:34 +01003384static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003385 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003386};
3387
3388static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3389{
3390 struct sigmatel_spec *spec = codec->spec;
3391 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003392 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003393 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003394 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003395
3396 num_cons = snd_hda_get_connections(codec,
3397 spec->smux_nids[0],
3398 con_lst,
3399 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003400 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003401 return -EINVAL;
3402
Matthew Ranostay65973632008-09-16 10:39:37 -04003403 if (!labels)
3404 labels = stac92xx_spdif_labels;
3405
Takashi Iwai10a20af2010-09-09 16:28:02 +02003406 for (i = 0; i < num_cons; i++)
3407 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003408
3409 return 0;
3410}
3411
Matt Porter8b657272006-10-26 17:12:59 +02003412/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003413static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003414 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3415 "Digital Mic 3", "Digital Mic 4"
3416};
3417
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003418static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3419 hda_nid_t nid)
3420{
3421 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3422 int i, nums;
3423
3424 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3425 for (i = 0; i < nums; i++)
3426 if (conn[i] == nid)
3427 return i;
3428 return -1;
3429}
3430
Takashi Iwai667067d2009-08-13 18:14:42 +02003431/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003432/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003433static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003434 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003435{
3436 unsigned int caps, nums;
3437 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003438 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003439
Takashi Iwai96f845d2009-08-29 00:49:36 +02003440 if (direction == HDA_OUTPUT)
3441 caps = AC_WCAP_OUT_AMP;
3442 else
3443 caps = AC_WCAP_IN_AMP;
3444 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003445 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003446 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003447 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3448 if (!nums)
3449 return 0;
3450 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003451 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3452 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003453 if (err < 0)
3454 return err;
3455 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003456}
3457
Matt Porter8b657272006-10-26 17:12:59 +02003458/* create playback/capture controls for input pins on dmic capable codecs */
3459static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3460 const struct auto_pin_cfg *cfg)
3461{
3462 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003463 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003464 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003465 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003466 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003467
Takashi Iwai10a20af2010-09-09 16:28:02 +02003468 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003469
Matt Porter8b657272006-10-26 17:12:59 +02003470 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003471 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003472 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003473 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003474
Takashi Iwai667067d2009-08-13 18:14:42 +02003475 nid = spec->dmic_nids[i];
3476 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3477 continue;
3478 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003479 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3480 continue;
3481
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003482 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3483 if (index < 0)
3484 continue;
3485
Takashi Iwai10a20af2010-09-09 16:28:02 +02003486 label = hda_get_input_pin_label(codec, nid, 1);
3487 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003488 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3489 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003490
Takashi Iwai10a20af2010-09-09 16:28:02 +02003491 err = create_elem_capture_vol(codec, nid, label, type_idx,
3492 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003493 if (err < 0)
3494 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003495 if (!err) {
3496 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003497 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003498 if (err < 0)
3499 return err;
3500 }
Matt Porter8b657272006-10-26 17:12:59 +02003501 }
3502
3503 return 0;
3504}
3505
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003506static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003507 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003508{
3509 unsigned int cfg;
3510
3511 if (!nid)
3512 return 0;
3513 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003514 switch (snd_hda_get_input_pin_attr(cfg)) {
3515 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003516 if (*fixed)
3517 return 1; /* already occupied */
3518 *fixed = nid;
3519 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003520 case INPUT_PIN_ATTR_UNUSED:
3521 break;
3522 case INPUT_PIN_ATTR_DOCK:
3523 if (*dock)
3524 return 1; /* already occupied */
3525 *dock = nid;
3526 break;
3527 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003528 if (*ext)
3529 return 1; /* already occupied */
3530 *ext = nid;
3531 break;
3532 }
3533 return 0;
3534}
3535
3536static int set_mic_route(struct hda_codec *codec,
3537 struct sigmatel_mic_route *mic,
3538 hda_nid_t pin)
3539{
3540 struct sigmatel_spec *spec = codec->spec;
3541 struct auto_pin_cfg *cfg = &spec->autocfg;
3542 int i;
3543
3544 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003545 if (pin == 0)
3546 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003547 for (i = 0; i < cfg->num_inputs; i++) {
3548 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003549 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003550 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003551 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003552 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003553 i = get_connection_index(codec, spec->mux_nids[0], pin);
3554 if (i < 0)
3555 return -1;
3556 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003557 mic->dmux_idx = -1;
3558 if (spec->dmux_nids)
3559 mic->dmux_idx = get_connection_index(codec,
3560 spec->dmux_nids[0],
3561 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003562 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003563 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003564 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3565 if (i < 0)
3566 return -1;
3567 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003568 mic->mux_idx = -1;
3569 if (spec->mux_nids)
3570 mic->mux_idx = get_connection_index(codec,
3571 spec->mux_nids[0],
3572 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003573 }
3574 return 0;
3575}
3576
3577/* return non-zero if the device is for automatic mic switch */
3578static int stac_check_auto_mic(struct hda_codec *codec)
3579{
3580 struct sigmatel_spec *spec = codec->spec;
3581 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003582 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003583 int i;
3584
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003585 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003586 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003587 return 0; /* must be exclusively mics */
3588 }
Charles Chin99077902010-09-17 10:22:32 +02003589 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003590 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003591 if (check_mic_pin(codec, cfg->inputs[i].pin,
3592 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003593 return 0;
3594 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003595 if (check_mic_pin(codec, spec->dmic_nids[i],
3596 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003597 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003598 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003599 return 0; /* no input to switch */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003600 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3601 return 0; /* no unsol support */
3602 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003603 set_mic_route(codec, &spec->int_mic, fixed) ||
3604 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003605 return 0; /* something is wrong */
3606 return 1;
3607}
3608
Mattc7d4b2f2005-06-27 14:59:41 +02003609/* create playback/capture controls for input pins */
3610static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3611{
3612 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003613 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003614 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003615 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003616
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003617 for (i = 0; i < cfg->num_inputs; i++) {
3618 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003619 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003620
Takashi Iwai314634b2006-09-21 11:56:18 +02003621 index = -1;
3622 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003623 index = get_connection_index(codec, spec->mux_nids[j],
3624 nid);
3625 if (index >= 0)
3626 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003627 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003628 if (index < 0)
3629 continue;
3630
Takashi Iwai10a20af2010-09-09 16:28:02 +02003631 label = hda_get_autocfg_input_label(codec, cfg, i);
3632 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003633
Takashi Iwai667067d2009-08-13 18:14:42 +02003634 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003635 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003636 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003637 if (err < 0)
3638 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003639 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003640 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003641
Steve Longerbeam7b043892007-05-03 20:50:03 +02003642 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003643 /*
3644 * Set the current input for the muxes.
3645 * The STAC9221 has two input muxes with identical source
3646 * NID lists. Hopefully this won't get confused.
3647 */
3648 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003649 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3650 AC_VERB_SET_CONNECT_SEL,
3651 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003652 }
3653 }
3654
Mattc7d4b2f2005-06-27 14:59:41 +02003655 return 0;
3656}
3657
Mattc7d4b2f2005-06-27 14:59:41 +02003658static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3659{
3660 struct sigmatel_spec *spec = codec->spec;
3661 int i;
3662
3663 for (i = 0; i < spec->autocfg.line_outs; i++) {
3664 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3665 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3666 }
3667}
3668
3669static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3670{
3671 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003672 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003673
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003674 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3675 hda_nid_t pin;
3676 pin = spec->autocfg.hp_pins[i];
3677 if (pin) /* connect to front */
3678 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3679 }
3680 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3681 hda_nid_t pin;
3682 pin = spec->autocfg.speaker_pins[i];
3683 if (pin) /* connect to front */
3684 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3685 }
Mattc7d4b2f2005-06-27 14:59:41 +02003686}
3687
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003688static int is_dual_headphones(struct hda_codec *codec)
3689{
3690 struct sigmatel_spec *spec = codec->spec;
3691 int i, valid_hps;
3692
3693 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3694 spec->autocfg.hp_outs <= 1)
3695 return 0;
3696 valid_hps = 0;
3697 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3698 hda_nid_t nid = spec->autocfg.hp_pins[i];
3699 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3700 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3701 continue;
3702 valid_hps++;
3703 }
3704 return (valid_hps > 1);
3705}
3706
3707
Matt Porter3cc08dc2006-01-23 15:27:49 +01003708static 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 +02003709{
3710 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003711 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003712 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003713
Matt Porter8b657272006-10-26 17:12:59 +02003714 if ((err = snd_hda_parse_pin_def_config(codec,
3715 &spec->autocfg,
3716 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003717 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003718 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003719 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003720
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003721 /* If we have no real line-out pin and multiple hp-outs, HPs should
3722 * be set up as multi-channel outputs.
3723 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003724 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003725 /* Copy hp_outs to line_outs, backup line_outs in
3726 * speaker_outs so that the following routines can handle
3727 * HP pins as primary outputs.
3728 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003729 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003730 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3731 sizeof(spec->autocfg.line_out_pins));
3732 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3733 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3734 sizeof(spec->autocfg.hp_pins));
3735 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003736 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3737 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003738 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003739 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003740 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003741 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3742 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003743 u32 caps = query_amp_caps(codec,
3744 spec->autocfg.mono_out_pin, dir);
3745 hda_nid_t conn_list[1];
3746
3747 /* get the mixer node and then the mono mux if it exists */
3748 if (snd_hda_get_connections(codec,
3749 spec->autocfg.mono_out_pin, conn_list, 1) &&
3750 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003751 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003752
3753 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003754 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003755 /* LR swap check, some stac925x have a mux that
3756 * changes the DACs output path instead of the
3757 * mono-mux path.
3758 */
3759 if (wid_type == AC_WID_AUD_SEL &&
3760 !(wcaps & AC_WCAP_LR_SWAP))
3761 spec->mono_nid = conn_list[0];
3762 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003763 if (dir) {
3764 hda_nid_t nid = spec->autocfg.mono_out_pin;
3765
3766 /* most mono outs have a least a mute/unmute switch */
3767 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3768 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3769 "Mono Playback Switch",
3770 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003771 if (err < 0)
3772 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003773 /* check for volume support for the amp */
3774 if ((caps & AC_AMPCAP_NUM_STEPS)
3775 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3776 err = stac92xx_add_control(spec,
3777 STAC_CTL_WIDGET_VOL,
3778 "Mono Playback Volume",
3779 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3780 if (err < 0)
3781 return err;
3782 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003783 }
3784
3785 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3786 AC_PINCTL_OUT_EN);
3787 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003788
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003789 if (!spec->multiout.num_dacs) {
3790 err = stac92xx_auto_fill_dac_nids(codec);
3791 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003792 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003793 err = stac92xx_auto_create_multi_out_ctls(codec,
3794 &spec->autocfg);
3795 if (err < 0)
3796 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003797 }
Mattc7d4b2f2005-06-27 14:59:41 +02003798
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003799 /* setup analog beep controls */
3800 if (spec->anabeep_nid > 0) {
3801 err = stac92xx_auto_create_beep_ctls(codec,
3802 spec->anabeep_nid);
3803 if (err < 0)
3804 return err;
3805 }
3806
3807 /* setup digital beep controls and input device */
3808#ifdef CONFIG_SND_HDA_INPUT_BEEP
3809 if (spec->digbeep_nid > 0) {
3810 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003811 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003812
3813 err = stac92xx_auto_create_beep_ctls(codec, nid);
3814 if (err < 0)
3815 return err;
3816 err = snd_hda_attach_beep_device(codec, nid);
3817 if (err < 0)
3818 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003819 if (codec->beep) {
3820 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003821 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003822 /* if no beep switch is available, make its own one */
3823 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3824 if (!(caps & AC_AMPCAP_MUTE)) {
3825 err = stac92xx_beep_switch_ctl(codec);
3826 if (err < 0)
3827 return err;
3828 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003829 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003830 }
3831#endif
3832
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003833 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003834 if (err < 0)
3835 return err;
3836
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003837 /* All output parsing done, now restore the swapped hp pins */
3838 if (hp_swap) {
3839 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3840 sizeof(spec->autocfg.hp_pins));
3841 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3842 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3843 spec->autocfg.line_outs = 0;
3844 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003845
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003846 if (stac_check_auto_mic(codec)) {
3847 spec->auto_mic = 1;
3848 /* only one capture for auto-mic */
3849 spec->num_adcs = 1;
3850 spec->num_caps = 1;
3851 spec->num_muxes = 1;
3852 }
3853
Takashi Iwai6479c632009-07-28 18:20:25 +02003854 for (i = 0; i < spec->num_caps; i++) {
3855 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3856 spec->capsws[i], i);
3857 if (err < 0)
3858 return err;
3859 }
3860
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003861 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003862 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003863 return err;
3864
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003865 if (spec->mono_nid > 0) {
3866 err = stac92xx_auto_create_mono_output_ctls(codec);
3867 if (err < 0)
3868 return err;
3869 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003870 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003871 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3872 &spec->autocfg)) < 0)
3873 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003874 if (spec->num_muxes > 0) {
3875 err = stac92xx_auto_create_mux_input_ctls(codec);
3876 if (err < 0)
3877 return err;
3878 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003879 if (spec->num_smuxes > 0) {
3880 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3881 if (err < 0)
3882 return err;
3883 }
Matt Porter8b657272006-10-26 17:12:59 +02003884
Takashi Iwaie3c75962009-01-23 11:57:22 +01003885 err = stac92xx_add_input_source(spec);
3886 if (err < 0)
3887 return err;
3888
Mattc7d4b2f2005-06-27 14:59:41 +02003889 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003890 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003891 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003892
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003893 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003894 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003895 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003896 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003897
Takashi Iwai603c4012008-07-30 15:01:44 +02003898 if (spec->kctls.list)
3899 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003900
3901 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003902 if (!spec->dinput_mux)
3903 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003904 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003905 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003906 return 1;
3907}
3908
Takashi Iwai82bc9552006-03-21 11:24:42 +01003909/* add playback controls for HP output */
3910static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3911 struct auto_pin_cfg *cfg)
3912{
3913 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003914 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003915 unsigned int wid_caps;
3916
3917 if (! pin)
3918 return 0;
3919
3920 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003921 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003922 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003923
3924 return 0;
3925}
3926
Richard Fish160ea0d2006-09-06 13:58:25 +02003927/* add playback controls for LFE output */
3928static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3929 struct auto_pin_cfg *cfg)
3930{
3931 struct sigmatel_spec *spec = codec->spec;
3932 int err;
3933 hda_nid_t lfe_pin = 0x0;
3934 int i;
3935
3936 /*
3937 * search speaker outs and line outs for a mono speaker pin
3938 * with an amp. If one is found, add LFE controls
3939 * for it.
3940 */
3941 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3942 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003943 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003944 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3945 if (wcaps == AC_WCAP_OUT_AMP)
3946 /* found a mono speaker with an amp, must be lfe */
3947 lfe_pin = pin;
3948 }
3949
3950 /* if speaker_outs is 0, then speakers may be in line_outs */
3951 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3952 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3953 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003954 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003955 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003956 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003957 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003958 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3959 if (wcaps == AC_WCAP_OUT_AMP)
3960 /* found a mono speaker with an amp,
3961 must be lfe */
3962 lfe_pin = pin;
3963 }
3964 }
3965 }
3966
3967 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003968 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003969 if (err < 0)
3970 return err;
3971 }
3972
3973 return 0;
3974}
3975
Mattc7d4b2f2005-06-27 14:59:41 +02003976static int stac9200_parse_auto_config(struct hda_codec *codec)
3977{
3978 struct sigmatel_spec *spec = codec->spec;
3979 int err;
3980
Kailang Yangdf694da2005-12-05 19:42:22 +01003981 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003982 return err;
3983
3984 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3985 return err;
3986
Takashi Iwai82bc9552006-03-21 11:24:42 +01003987 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3988 return err;
3989
Richard Fish160ea0d2006-09-06 13:58:25 +02003990 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3991 return err;
3992
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003993 if (spec->num_muxes > 0) {
3994 err = stac92xx_auto_create_mux_input_ctls(codec);
3995 if (err < 0)
3996 return err;
3997 }
3998
Takashi Iwaie3c75962009-01-23 11:57:22 +01003999 err = stac92xx_add_input_source(spec);
4000 if (err < 0)
4001 return err;
4002
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004003 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004004 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004005 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004006 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004007
Takashi Iwai603c4012008-07-30 15:01:44 +02004008 if (spec->kctls.list)
4009 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004010
4011 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004012 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004013
4014 return 1;
4015}
4016
Sam Revitch62fe78e2006-05-10 15:09:17 +02004017/*
4018 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4019 * funky external mute control using GPIO pins.
4020 */
4021
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004022static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004023 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004024{
4025 unsigned int gpiostate, gpiomask, gpiodir;
4026
4027 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4028 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004029 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004030
4031 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4032 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004033 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004034
4035 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4036 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004037 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004038
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004039 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004040 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4041
4042 snd_hda_codec_write(codec, codec->afg, 0,
4043 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004044 snd_hda_codec_read(codec, codec->afg, 0,
4045 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004046
4047 msleep(1);
4048
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004049 snd_hda_codec_read(codec, codec->afg, 0,
4050 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004051}
4052
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004053static int stac92xx_add_jack(struct hda_codec *codec,
4054 hda_nid_t nid, int type)
4055{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004056#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai330ee992009-02-20 14:33:36 +01004057 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004058 int connectivity = get_defcfg_connect(def_conf);
4059 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004060 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004061
4062 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4063 return 0;
4064
Takashi Iwai86de7412009-07-22 16:02:46 +02004065 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004066 snd_hda_get_jack_type(def_conf),
4067 snd_hda_get_jack_connectivity(def_conf),
4068 snd_hda_get_jack_location(def_conf));
4069
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004070 err = snd_hda_input_jack_add(codec, nid, type, name);
4071 if (err < 0)
Takashi Iwai95c09092009-04-14 16:15:29 +02004072 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004073#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai95c09092009-04-14 16:15:29 +02004074 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004075}
4076
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004077static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4078 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004079{
4080 struct sigmatel_event *event;
4081
4082 snd_array_init(&spec->events, sizeof(*event), 32);
4083 event = snd_array_new(&spec->events);
4084 if (!event)
4085 return -ENOMEM;
4086 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004087 event->type = type;
4088 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004089 event->data = data;
4090
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004091 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004092}
4093
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004094static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004095 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004096{
4097 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004098 struct sigmatel_event *event = spec->events.list;
4099 int i;
4100
4101 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004102 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004103 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004104 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004105 return NULL;
4106}
4107
4108static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4109 unsigned char tag)
4110{
4111 struct sigmatel_spec *spec = codec->spec;
4112 struct sigmatel_event *event = spec->events.list;
4113 int i;
4114
4115 for (i = 0; i < spec->events.used; i++, event++) {
4116 if (event->tag == tag)
4117 return event;
4118 }
4119 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004120}
4121
Takashi Iwai62558ce2009-07-29 14:23:09 +02004122/* check if given nid is a valid pin and no other events are assigned
4123 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4124 * Otherwise, returns zero.
4125 */
4126static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4127 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004128{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004129 struct sigmatel_event *event;
4130 int tag;
4131
4132 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004133 return 0;
4134 event = stac_get_event(codec, nid);
4135 if (event) {
4136 if (event->type != type)
4137 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004138 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004139 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004140 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004141 if (tag < 0)
4142 return 0;
4143 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004144 snd_hda_codec_write_cache(codec, nid, 0,
4145 AC_VERB_SET_UNSOLICITED_ENABLE,
4146 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004147 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004148}
4149
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004150static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4151{
4152 int i;
4153 for (i = 0; i < cfg->hp_outs; i++)
4154 if (cfg->hp_pins[i] == nid)
4155 return 1; /* nid is a HP-Out */
4156
4157 return 0; /* nid is not a HP-Out */
4158};
4159
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004160static void stac92xx_power_down(struct hda_codec *codec)
4161{
4162 struct sigmatel_spec *spec = codec->spec;
4163
4164 /* power down inactive DACs */
4165 hda_nid_t *dac;
4166 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004167 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004168 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004169 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4170}
4171
Takashi Iwaif73d3582008-11-25 08:21:51 +01004172static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4173 int enable);
4174
Takashi Iwai014c41f2009-12-27 13:53:24 +01004175static inline int get_int_hint(struct hda_codec *codec, const char *key,
4176 int *valp)
4177{
4178 const char *p;
4179 p = snd_hda_get_hint(codec, key);
4180 if (p) {
4181 unsigned long val;
4182 if (!strict_strtoul(p, 0, &val)) {
4183 *valp = val;
4184 return 1;
4185 }
4186 }
4187 return 0;
4188}
4189
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004190/* override some hints from the hwdep entry */
4191static void stac_store_hints(struct hda_codec *codec)
4192{
4193 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004194 int val;
4195
4196 val = snd_hda_get_bool_hint(codec, "hp_detect");
4197 if (val >= 0)
4198 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004199 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004200 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4201 spec->gpio_mask;
4202 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004203 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4204 spec->gpio_mask &= spec->gpio_mask;
4205 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4206 spec->gpio_dir &= spec->gpio_mask;
4207 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4208 spec->eapd_mask &= spec->gpio_mask;
4209 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4210 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004211 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4212 if (val >= 0)
4213 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004214 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4215 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwai043958e2009-12-26 10:36:12 +01004216 spec->gpio_mask |= spec->gpio_led;
4217 spec->gpio_dir |= spec->gpio_led;
4218 if (spec->gpio_led_polarity)
4219 spec->gpio_data |= spec->gpio_led;
4220 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004221}
4222
Mattc7d4b2f2005-06-27 14:59:41 +02004223static int stac92xx_init(struct hda_codec *codec)
4224{
4225 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004226 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004227 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004228 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004229
Mattc7d4b2f2005-06-27 14:59:41 +02004230 snd_hda_sequence_write(codec, spec->init);
4231
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004232 /* power down adcs initially */
4233 if (spec->powerdown_adcs)
4234 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004235 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004236 spec->adc_nids[i], 0,
4237 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004238
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004239 /* override some hints */
4240 stac_store_hints(codec);
4241
Takashi Iwaif73d3582008-11-25 08:21:51 +01004242 /* set up GPIO */
4243 gpio = spec->gpio_data;
4244 /* turn on EAPD statically when spec->eapd_switch isn't set.
4245 * otherwise, unsol event will turn it on/off dynamically
4246 */
4247 if (!spec->eapd_switch)
4248 gpio |= spec->eapd_mask;
4249 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4250
Takashi Iwai82bc9552006-03-21 11:24:42 +01004251 /* set up pins */
4252 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004253 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004254 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004255 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004256 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004257 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004258 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4259 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004260 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004261 for (i = 0; i < cfg->line_outs; i++) {
4262 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004263 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4264 }
4265 }
4266
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004267 /* force to enable the first line-out; the others are set up
4268 * in unsol_event
4269 */
4270 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004271 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004272 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004273 if (cfg->hp_pins[0])
4274 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4275 else if (cfg->line_out_pins[0])
4276 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004277 } else {
4278 stac92xx_auto_init_multi_out(codec);
4279 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004280 for (i = 0; i < cfg->hp_outs; i++)
4281 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004282 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004283 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004284 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004285 if (spec->dmux_nids)
4286 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004287 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004288 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4289 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004290 if (enable_pin_detect(codec, spec->dock_mic.pin,
4291 STAC_MIC_EVENT))
4292 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004293 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004294 for (i = 0; i < cfg->num_inputs; i++) {
4295 hda_nid_t nid = cfg->inputs[i].pin;
4296 int type = cfg->inputs[i].type;
4297 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004298 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004299 /* for mic pins, force to initialize */
4300 pinctl = stac92xx_get_default_vref(codec, nid);
4301 pinctl |= AC_PINCTL_IN_EN;
4302 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4303 } else {
4304 pinctl = snd_hda_codec_read(codec, nid, 0,
4305 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4306 /* if PINCTL already set then skip */
4307 /* Also, if both INPUT and OUTPUT are set,
4308 * it must be a BIOS bug; need to override, too
4309 */
4310 if (!(pinctl & AC_PINCTL_IN_EN) ||
4311 (pinctl & AC_PINCTL_OUT_EN)) {
4312 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004313 pinctl |= AC_PINCTL_IN_EN;
4314 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004315 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004316 }
4317 conf = snd_hda_codec_get_pincfg(codec, nid);
4318 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4319 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4320 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004321 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004322 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004323 for (i = 0; i < spec->num_dmics; i++)
4324 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4325 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004326 if (cfg->dig_out_pins[0])
4327 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004328 AC_PINCTL_OUT_EN);
4329 if (cfg->dig_in_pin)
4330 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4331 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004332 for (i = 0; i < spec->num_pwrs; i++) {
4333 hda_nid_t nid = spec->pwr_nids[i];
4334 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004335
Takashi Iwaieb632122008-12-19 16:39:48 +01004336 /* power on when no jack detection is available */
4337 if (!spec->hp_detect) {
4338 stac_toggle_power_map(codec, nid, 1);
4339 continue;
4340 }
4341
4342 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004343 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004344
Takashi Iwaif73d3582008-11-25 08:21:51 +01004345 pinctl = snd_hda_codec_read(codec, nid, 0,
4346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4347 /* outputs are only ports capable of power management
4348 * any attempts on powering down a input port cause the
4349 * referenced VREF to act quirky.
4350 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004351 if (pinctl & AC_PINCTL_IN_EN) {
4352 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004353 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004354 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004355 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004356 def_conf = get_defcfg_connect(def_conf);
4357 /* skip any ports that don't have jacks since presence
4358 * detection is useless */
4359 if (def_conf != AC_JACK_PORT_COMPLEX) {
4360 if (def_conf != AC_JACK_PORT_NONE)
4361 stac_toggle_power_map(codec, nid, 1);
4362 continue;
4363 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004364 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4365 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004366 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004367
Takashi Iwaic21bd022010-02-08 15:16:08 +01004368 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004369 if (spec->gpio_led)
4370 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004371 if (spec->dac_list)
4372 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004373 return 0;
4374}
4375
Takashi Iwai603c4012008-07-30 15:01:44 +02004376static void stac92xx_free_kctls(struct hda_codec *codec)
4377{
4378 struct sigmatel_spec *spec = codec->spec;
4379
4380 if (spec->kctls.list) {
4381 struct snd_kcontrol_new *kctl = spec->kctls.list;
4382 int i;
4383 for (i = 0; i < spec->kctls.used; i++)
4384 kfree(kctl[i].name);
4385 }
4386 snd_array_free(&spec->kctls);
4387}
4388
Takashi Iwai167eae52009-11-06 15:47:50 +01004389static void stac92xx_shutup(struct hda_codec *codec)
4390{
4391 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004392
Takashi Iwai92ee6162009-12-27 11:18:59 +01004393 snd_hda_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004394
4395 if (spec->eapd_mask)
4396 stac_gpio_set(codec, spec->gpio_mask,
4397 spec->gpio_dir, spec->gpio_data &
4398 ~spec->eapd_mask);
4399}
4400
Matt2f2f4252005-04-13 14:45:30 +02004401static void stac92xx_free(struct hda_codec *codec)
4402{
Mattc7d4b2f2005-06-27 14:59:41 +02004403 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004404
4405 if (! spec)
4406 return;
4407
Takashi Iwai167eae52009-11-06 15:47:50 +01004408 stac92xx_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004409 snd_hda_input_jack_free(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004410 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004411
Mattc7d4b2f2005-06-27 14:59:41 +02004412 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004413 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004414}
4415
Matt4e550962005-07-04 17:51:39 +02004416static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4417 unsigned int flag)
4418{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004419 unsigned int old_ctl, pin_ctl;
4420
4421 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004422 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004423
Takashi Iwaif9acba42007-05-29 18:01:06 +02004424 if (pin_ctl & AC_PINCTL_IN_EN) {
4425 /*
4426 * we need to check the current set-up direction of
4427 * shared input pins since they can be switched via
4428 * "xxx as Output" mixer switch
4429 */
4430 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004431 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004432 return;
4433 }
4434
Takashi Iwai8ce84192009-01-22 16:59:20 +01004435 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004436 /* if setting pin direction bits, clear the current
4437 direction bits first */
4438 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4439 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4440
Takashi Iwai8ce84192009-01-22 16:59:20 +01004441 pin_ctl |= flag;
4442 if (old_ctl != pin_ctl)
4443 snd_hda_codec_write_cache(codec, nid, 0,
4444 AC_VERB_SET_PIN_WIDGET_CONTROL,
4445 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004446}
4447
4448static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4449 unsigned int flag)
4450{
4451 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4452 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004453 if (pin_ctl & flag)
4454 snd_hda_codec_write_cache(codec, nid, 0,
4455 AC_VERB_SET_PIN_WIDGET_CONTROL,
4456 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004457}
4458
Takashi Iwaid56757a2009-11-18 08:00:14 +01004459static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004460{
4461 if (!nid)
4462 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004463 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004464}
4465
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004466static void stac92xx_line_out_detect(struct hda_codec *codec,
4467 int presence)
4468{
4469 struct sigmatel_spec *spec = codec->spec;
4470 struct auto_pin_cfg *cfg = &spec->autocfg;
4471 int i;
4472
4473 for (i = 0; i < cfg->line_outs; i++) {
4474 if (presence)
4475 break;
4476 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4477 if (presence) {
4478 unsigned int pinctl;
4479 pinctl = snd_hda_codec_read(codec,
4480 cfg->line_out_pins[i], 0,
4481 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4482 if (pinctl & AC_PINCTL_IN_EN)
4483 presence = 0; /* mic- or line-input */
4484 }
4485 }
4486
4487 if (presence) {
4488 /* disable speakers */
4489 for (i = 0; i < cfg->speaker_outs; i++)
4490 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4491 AC_PINCTL_OUT_EN);
4492 if (spec->eapd_mask && spec->eapd_switch)
4493 stac_gpio_set(codec, spec->gpio_mask,
4494 spec->gpio_dir, spec->gpio_data &
4495 ~spec->eapd_mask);
4496 } else {
4497 /* enable speakers */
4498 for (i = 0; i < cfg->speaker_outs; i++)
4499 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4500 AC_PINCTL_OUT_EN);
4501 if (spec->eapd_mask && spec->eapd_switch)
4502 stac_gpio_set(codec, spec->gpio_mask,
4503 spec->gpio_dir, spec->gpio_data |
4504 spec->eapd_mask);
4505 }
4506}
4507
Takashi Iwaid7a89432008-11-12 09:48:04 +01004508/* return non-zero if the hp-pin of the given array index isn't
4509 * a jack-detection target
4510 */
4511static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4512{
4513 struct auto_pin_cfg *cfg = &spec->autocfg;
4514
4515 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004516 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004517 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004518 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004519 return 1;
4520 /* ignore if the pin is set as line-out */
4521 if (cfg->hp_pins[i] == spec->hp_switch)
4522 return 1;
4523 return 0;
4524}
4525
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004526static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004527{
4528 struct sigmatel_spec *spec = codec->spec;
4529 struct auto_pin_cfg *cfg = &spec->autocfg;
4530 int i, presence;
4531
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004532 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004533 if (spec->gpio_mute)
4534 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4535 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4536
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004537 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004538 if (presence)
4539 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004540 if (no_hp_sensing(spec, i))
4541 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004542 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4543 if (presence) {
4544 unsigned int pinctl;
4545 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4546 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4547 if (pinctl & AC_PINCTL_IN_EN)
4548 presence = 0; /* mic- or line-input */
4549 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004550 }
Matt4e550962005-07-04 17:51:39 +02004551
4552 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004553 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004554 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004555 stac92xx_reset_pinctl(codec, spec->hp_switch,
4556 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004557 for (i = 0; i < cfg->line_outs; i++)
4558 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4559 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004560 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004561 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004562 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004563 stac92xx_set_pinctl(codec, spec->hp_switch,
4564 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004565 for (i = 0; i < cfg->line_outs; i++)
4566 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4567 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004568 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004569 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004570 /* toggle hp outs */
4571 for (i = 0; i < cfg->hp_outs; i++) {
4572 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4573 if (no_hp_sensing(spec, i))
4574 continue;
4575 if (presence)
4576 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004577#if 0 /* FIXME */
4578/* Resetting the pinctl like below may lead to (a sort of) regressions
4579 * on some devices since they use the HP pin actually for line/speaker
4580 * outs although the default pin config shows a different pin (that is
4581 * wrong and useless).
4582 *
4583 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4584 * But, disabling the code below just works around it, and I'm too tired of
4585 * bug reports with such devices...
4586 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004587 else
4588 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004589#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004590 }
Matt4e550962005-07-04 17:51:39 +02004591}
4592
Takashi Iwaif73d3582008-11-25 08:21:51 +01004593static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4594 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004595{
4596 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004597 unsigned int idx, val;
4598
4599 for (idx = 0; idx < spec->num_pwrs; idx++) {
4600 if (spec->pwr_nids[idx] == nid)
4601 break;
4602 }
4603 if (idx >= spec->num_pwrs)
4604 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004605
4606 /* several codecs have two power down bits */
4607 if (spec->pwr_mapping)
4608 idx = spec->pwr_mapping[idx];
4609 else
4610 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004611
Takashi Iwaif73d3582008-11-25 08:21:51 +01004612 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4613 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004614 val &= ~idx;
4615 else
4616 val |= idx;
4617
4618 /* power down unused output ports */
4619 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004620}
4621
Takashi Iwaif73d3582008-11-25 08:21:51 +01004622static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4623{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004624 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004625}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004626
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004627/* get the pin connection (fixed, none, etc) */
4628static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4629{
4630 struct sigmatel_spec *spec = codec->spec;
4631 unsigned int cfg;
4632
4633 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4634 return get_defcfg_connect(cfg);
4635}
4636
4637static int stac92xx_connected_ports(struct hda_codec *codec,
4638 hda_nid_t *nids, int num_nids)
4639{
4640 struct sigmatel_spec *spec = codec->spec;
4641 int idx, num;
4642 unsigned int def_conf;
4643
4644 for (num = 0; num < num_nids; num++) {
4645 for (idx = 0; idx < spec->num_pins; idx++)
4646 if (spec->pin_nids[idx] == nids[num])
4647 break;
4648 if (idx >= spec->num_pins)
4649 break;
4650 def_conf = stac_get_defcfg_connect(codec, idx);
4651 if (def_conf == AC_JACK_PORT_NONE)
4652 break;
4653 }
4654 return num;
4655}
4656
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004657static void stac92xx_mic_detect(struct hda_codec *codec)
4658{
4659 struct sigmatel_spec *spec = codec->spec;
4660 struct sigmatel_mic_route *mic;
4661
4662 if (get_pin_presence(codec, spec->ext_mic.pin))
4663 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004664 else if (get_pin_presence(codec, spec->dock_mic.pin))
4665 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004666 else
4667 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004668 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004669 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4670 AC_VERB_SET_CONNECT_SEL,
4671 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004672 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004673 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4674 AC_VERB_SET_CONNECT_SEL,
4675 mic->mux_idx);
4676}
4677
Takashi Iwai62558ce2009-07-29 14:23:09 +02004678static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004679{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004680 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004681 if (!event)
4682 return;
4683 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4684}
4685
Takashi Iwai314634b2006-09-21 11:56:18 +02004686static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4687{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004688 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004689 struct sigmatel_event *event;
4690 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004691
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004692 tag = (res >> 26) & 0x7f;
4693 event = stac_get_event_from_tag(codec, tag);
4694 if (!event)
4695 return;
4696
4697 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004698 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004699 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004700 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004701 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004702 case STAC_MIC_EVENT:
4703 stac92xx_mic_detect(codec);
4704 break;
4705 }
4706
4707 switch (event->type) {
4708 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004709 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004710 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004711 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004712 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004713 if (spec->num_pwrs > 0)
4714 stac92xx_pin_sense(codec, event->nid);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004715 snd_hda_input_jack_report(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004716
4717 switch (codec->subsystem_id) {
4718 case 0x103c308f:
4719 if (event->nid == 0xb) {
4720 int pin = AC_PINCTL_IN_EN;
4721
4722 if (get_pin_presence(codec, 0xa)
4723 && get_pin_presence(codec, 0xb))
4724 pin |= AC_PINCTL_VREF_80;
4725 if (!get_pin_presence(codec, 0xb))
4726 pin |= AC_PINCTL_VREF_80;
4727
4728 /* toggle VREF state based on mic + hp pin
4729 * status
4730 */
4731 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4732 }
4733 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004734 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004735 case STAC_VREF_EVENT:
4736 data = snd_hda_codec_read(codec, codec->afg, 0,
4737 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004738 /* toggle VREF state based on GPIOx status */
4739 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004740 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004741 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004742 }
4743}
4744
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304745static int hp_blike_system(u32 subsystem_id);
4746
4747static void set_hp_led_gpio(struct hda_codec *codec)
4748{
4749 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004750 unsigned int gpio;
4751
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004752 if (spec->gpio_led)
4753 return;
4754
Takashi Iwai07f80442010-02-08 15:06:13 +01004755 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4756 gpio &= AC_GPIO_IO_COUNT;
4757 if (gpio > 3)
4758 spec->gpio_led = 0x08; /* GPIO 3 */
4759 else
4760 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304761}
4762
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004763/*
4764 * This method searches for the mute LED GPIO configuration
4765 * provided as OEM string in SMBIOS. The format of that string
4766 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4767 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4768 * that corresponds to the NOT muted state of the master volume
4769 * and G is the index of the GPIO to use as the mute LED control (0..9)
4770 * If _G portion is missing it is assigned based on the codec ID
4771 *
4772 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4773 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304774 *
4775 *
4776 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4777 * SMBIOS - at least the ones I have seen do not have them - which include
4778 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4779 * HP Pavilion dv9500t CTO.
4780 * Need more information on whether it is true across the entire series.
4781 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004782 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004783static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004784{
4785 struct sigmatel_spec *spec = codec->spec;
4786 const struct dmi_device *dev = NULL;
4787
4788 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4789 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4790 NULL, dev))) {
4791 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304792 &spec->gpio_led_polarity,
4793 &spec->gpio_led) == 2) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004794 spec->gpio_led = 1 << spec->gpio_led;
4795 return 1;
4796 }
4797 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304798 &spec->gpio_led_polarity) == 1) {
4799 set_hp_led_gpio(codec);
4800 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004801 }
4802 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304803
4804 /*
4805 * Fallback case - if we don't find the DMI strings,
4806 * we statically set the GPIO - if not a B-series system.
4807 */
4808 if (!hp_blike_system(codec->subsystem_id)) {
4809 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004810 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304811 return 1;
4812 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004813 }
4814 return 0;
4815}
4816
4817static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004818{
4819 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004820 case 0x103c1520:
4821 case 0x103c1521:
4822 case 0x103c1523:
4823 case 0x103c1524:
4824 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004825 case 0x103c1722:
4826 case 0x103c1723:
4827 case 0x103c1724:
4828 case 0x103c1725:
4829 case 0x103c1726:
4830 case 0x103c1727:
4831 case 0x103c1728:
4832 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004833 case 0x103c172a:
4834 case 0x103c172b:
4835 case 0x103c307e:
4836 case 0x103c307f:
4837 case 0x103c3080:
4838 case 0x103c3081:
4839 case 0x103c7007:
4840 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004841 return 1;
4842 }
4843 return 0;
4844}
4845
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004846#ifdef CONFIG_PROC_FS
4847static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4848 struct hda_codec *codec, hda_nid_t nid)
4849{
4850 if (nid == codec->afg)
4851 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4852 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4853}
4854
4855static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4856 struct hda_codec *codec,
4857 unsigned int verb)
4858{
4859 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4860 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4861}
4862
4863/* stac92hd71bxx, stac92hd73xx */
4864static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4865 struct hda_codec *codec, hda_nid_t nid)
4866{
4867 stac92hd_proc_hook(buffer, codec, nid);
4868 if (nid == codec->afg)
4869 analog_loop_proc_hook(buffer, codec, 0xfa0);
4870}
4871
4872static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4873 struct hda_codec *codec, hda_nid_t nid)
4874{
4875 if (nid == codec->afg)
4876 analog_loop_proc_hook(buffer, codec, 0xfe0);
4877}
4878
4879static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4880 struct hda_codec *codec, hda_nid_t nid)
4881{
4882 if (nid == codec->afg)
4883 analog_loop_proc_hook(buffer, codec, 0xfeb);
4884}
4885#else
4886#define stac92hd_proc_hook NULL
4887#define stac92hd7x_proc_hook NULL
4888#define stac9205_proc_hook NULL
4889#define stac927x_proc_hook NULL
4890#endif
4891
Takashi Iwaicb53c622007-08-10 17:21:45 +02004892#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004893static int stac92xx_resume(struct hda_codec *codec)
4894{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004895 struct sigmatel_spec *spec = codec->spec;
4896
Takashi Iwai2c885872008-11-18 09:36:55 +01004897 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004898 snd_hda_codec_resume_amp(codec);
4899 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004900 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004901 if (spec->hp_detect) {
4902 if (spec->autocfg.hp_pins[0])
4903 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4904 else if (spec->autocfg.line_out_pins[0])
4905 stac_issue_unsol_event(codec,
4906 spec->autocfg.line_out_pins[0]);
4907 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004908 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004909 if (spec->gpio_led)
4910 hda_call_check_power_status(codec, 0x01);
Mattff6fdc32005-06-27 15:06:52 +02004911 return 0;
4912}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004913
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004914/*
James Gardiner514bf542009-05-03 04:00:44 -04004915 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004916 * check for mute state only on Speakers (nid = 0x10)
4917 *
4918 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4919 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004920 *
4921 * Changed name to reflect that it now works for any designated
4922 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004923 */
4924
4925#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004926static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004927 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004928{
4929 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21bd022010-02-08 15:16:08 +01004930 int i, muted = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004931
Takashi Iwaic21bd022010-02-08 15:16:08 +01004932 for (i = 0; i < spec->multiout.num_dacs; i++) {
4933 nid = spec->multiout.dac_nids[i];
4934 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4935 HDA_AMP_MUTE)) {
4936 muted = 0; /* something heard */
4937 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004938 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004939 }
4940 if (muted)
4941 spec->gpio_data &= ~spec->gpio_led; /* orange */
4942 else
4943 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004944
Takashi Iwaic21bd022010-02-08 15:16:08 +01004945 if (!spec->gpio_led_polarity) {
4946 /* LED state is inverted on these systems */
4947 spec->gpio_data ^= spec->gpio_led;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004948 }
4949
Takashi Iwaib4e81872009-11-18 17:20:24 +01004950 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
Takashi Iwaib4e81872009-11-18 17:20:24 +01004951 return 0;
4952}
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004953#endif
4954
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004955static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4956{
Takashi Iwai167eae52009-11-06 15:47:50 +01004957 stac92xx_shutup(codec);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004958 return 0;
4959}
Mattff6fdc32005-06-27 15:06:52 +02004960#endif
4961
Matt2f2f4252005-04-13 14:45:30 +02004962static struct hda_codec_ops stac92xx_patch_ops = {
4963 .build_controls = stac92xx_build_controls,
4964 .build_pcms = stac92xx_build_pcms,
4965 .init = stac92xx_init,
4966 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004967 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004968#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004969 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004970 .resume = stac92xx_resume,
4971#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01004972 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02004973};
4974
4975static int patch_stac9200(struct hda_codec *codec)
4976{
4977 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004978 int err;
Matt2f2f4252005-04-13 14:45:30 +02004979
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004980 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004981 if (spec == NULL)
4982 return -ENOMEM;
4983
Takashi Iwaia252c812009-12-25 22:56:20 +01004984 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02004985 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01004986 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004987 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004988 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004989 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4990 stac9200_models,
4991 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004992 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004993 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4994 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004995 else
4996 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004997 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004998
4999 spec->multiout.max_channels = 2;
5000 spec->multiout.num_dacs = 1;
5001 spec->multiout.dac_nids = stac9200_dac_nids;
5002 spec->adc_nids = stac9200_adc_nids;
5003 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005004 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005005 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005006 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005007 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005008
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005009 if (spec->board_config == STAC_9200_M4 ||
5010 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005011 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005012 spec->init = stac9200_eapd_init;
5013 else
5014 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005015 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005016
Takashi Iwai117f2572008-03-18 09:53:23 +01005017 if (spec->board_config == STAC_9200_PANASONIC) {
5018 spec->gpio_mask = spec->gpio_dir = 0x09;
5019 spec->gpio_data = 0x00;
5020 }
5021
Mattc7d4b2f2005-06-27 14:59:41 +02005022 err = stac9200_parse_auto_config(codec);
5023 if (err < 0) {
5024 stac92xx_free(codec);
5025 return err;
5026 }
Matt2f2f4252005-04-13 14:45:30 +02005027
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005028 /* CF-74 has no headphone detection, and the driver should *NOT*
5029 * do detection and HP/speaker toggle because the hardware does it.
5030 */
5031 if (spec->board_config == STAC_9200_PANASONIC)
5032 spec->hp_detect = 0;
5033
Matt2f2f4252005-04-13 14:45:30 +02005034 codec->patch_ops = stac92xx_patch_ops;
5035
5036 return 0;
5037}
5038
Tobin Davis8e21c342007-01-08 11:04:17 +01005039static int patch_stac925x(struct hda_codec *codec)
5040{
5041 struct sigmatel_spec *spec;
5042 int err;
5043
5044 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5045 if (spec == NULL)
5046 return -ENOMEM;
5047
Takashi Iwaia252c812009-12-25 22:56:20 +01005048 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005049 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005050 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005051 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005052 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005053
5054 /* Check first for codec ID */
5055 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5056 STAC_925x_MODELS,
5057 stac925x_models,
5058 stac925x_codec_id_cfg_tbl);
5059
5060 /* Now checks for PCI ID, if codec ID is not found */
5061 if (spec->board_config < 0)
5062 spec->board_config = snd_hda_check_board_config(codec,
5063 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005064 stac925x_models,
5065 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005066 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005067 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005068 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5069 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005070 else
5071 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005072 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005073
5074 spec->multiout.max_channels = 2;
5075 spec->multiout.num_dacs = 1;
5076 spec->multiout.dac_nids = stac925x_dac_nids;
5077 spec->adc_nids = stac925x_adc_nids;
5078 spec->mux_nids = stac925x_mux_nids;
5079 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005080 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005081 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005082 switch (codec->vendor_id) {
5083 case 0x83847632: /* STAC9202 */
5084 case 0x83847633: /* STAC9202D */
5085 case 0x83847636: /* STAC9251 */
5086 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005087 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005088 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005089 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5090 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005091 break;
5092 default:
5093 spec->num_dmics = 0;
5094 break;
5095 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005096
5097 spec->init = stac925x_core_init;
5098 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005099 spec->num_caps = 1;
5100 spec->capvols = stac925x_capvols;
5101 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005102
5103 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005104 if (!err) {
5105 if (spec->board_config < 0) {
5106 printk(KERN_WARNING "hda_codec: No auto-config is "
5107 "available, default to model=ref\n");
5108 spec->board_config = STAC_925x_REF;
5109 goto again;
5110 }
5111 err = -EINVAL;
5112 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005113 if (err < 0) {
5114 stac92xx_free(codec);
5115 return err;
5116 }
5117
5118 codec->patch_ops = stac92xx_patch_ops;
5119
5120 return 0;
5121}
5122
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005123static int patch_stac92hd73xx(struct hda_codec *codec)
5124{
5125 struct sigmatel_spec *spec;
5126 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5127 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005128 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005129
5130 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5131 if (spec == NULL)
5132 return -ENOMEM;
5133
Takashi Iwaia252c812009-12-25 22:56:20 +01005134 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005135 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005136 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005137 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005138 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5139 spec->pin_nids = stac92hd73xx_pin_nids;
5140 spec->board_config = snd_hda_check_board_config(codec,
5141 STAC_92HD73XX_MODELS,
5142 stac92hd73xx_models,
5143 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005144 /* check codec subsystem id if not found */
5145 if (spec->board_config < 0)
5146 spec->board_config =
5147 snd_hda_check_board_codec_sid_config(codec,
5148 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5149 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005150again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005151 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005152 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5153 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005154 else
5155 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005156 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005157
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005158 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005159 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5160
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005161 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005162 printk(KERN_WARNING "hda_codec: Could not determine "
5163 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005164 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005165 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005166 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005167 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005168 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005169 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005170 break;
5171 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005172 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005173 break;
5174 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005175 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5176 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005177 }
5178 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005179
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005180 spec->aloopback_mask = 0x01;
5181 spec->aloopback_shift = 8;
5182
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005183 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005184 spec->mux_nids = stac92hd73xx_mux_nids;
5185 spec->adc_nids = stac92hd73xx_adc_nids;
5186 spec->dmic_nids = stac92hd73xx_dmic_nids;
5187 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005188 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005189
5190 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5191 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005192 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005193
Takashi Iwai6479c632009-07-28 18:20:25 +02005194 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5195 spec->capvols = stac92hd73xx_capvols;
5196 spec->capsws = stac92hd73xx_capsws;
5197
Matthew Ranostaya7662642008-02-21 07:51:14 +01005198 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005199 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005200 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005201 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005202 case STAC_DELL_M6_AMIC:
5203 case STAC_DELL_M6_DMIC:
5204 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005205 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005206 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005207
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005208 switch (spec->board_config) {
5209 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005210 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005211 spec->num_dmics = 0;
5212 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005213 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005214 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005215 spec->num_dmics = 1;
5216 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005217 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005218 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5219 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005220 spec->num_dmics = 1;
5221 break;
5222 }
5223 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005224 case STAC_ALIENWARE_M17X:
5225 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5226 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5227 spec->eapd_switch = 0;
5228 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005229 default:
5230 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005231 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005232 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005233 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005234 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005235 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005236 /* GPIO0 High = Enable EAPD */
5237 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5238 spec->gpio_data = 0x01;
5239 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005240
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005241 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5242 spec->pwr_nids = stac92hd73xx_pwr_nids;
5243
Matthew Ranostayd9737752008-09-07 12:03:41 +02005244 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005245
5246 if (!err) {
5247 if (spec->board_config < 0) {
5248 printk(KERN_WARNING "hda_codec: No auto-config is "
5249 "available, default to model=ref\n");
5250 spec->board_config = STAC_92HD73XX_REF;
5251 goto again;
5252 }
5253 err = -EINVAL;
5254 }
5255
5256 if (err < 0) {
5257 stac92xx_free(codec);
5258 return err;
5259 }
5260
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005261 if (spec->board_config == STAC_92HD73XX_NO_JD)
5262 spec->hp_detect = 0;
5263
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005264 codec->patch_ops = stac92xx_patch_ops;
5265
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005266 codec->proc_widget_hook = stac92hd7x_proc_hook;
5267
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005268 return 0;
5269}
5270
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005271static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005272{
5273 if (codec->vendor_id != 0x111d7605 &&
5274 codec->vendor_id != 0x111d76d1)
5275 return 0;
5276
5277 switch (codec->subsystem_id) {
5278 case 0x103c1618:
5279 case 0x103c1619:
5280 case 0x103c161a:
5281 case 0x103c161b:
5282 case 0x103c161c:
5283 case 0x103c161d:
5284 case 0x103c161e:
5285 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005286
5287 case 0x103c162a:
5288 case 0x103c162b:
5289
5290 case 0x103c1630:
5291 case 0x103c1631:
5292
5293 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005294 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005295 case 0x103c1635:
5296
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005297 case 0x103c3587:
5298 case 0x103c3588:
5299 case 0x103c3589:
5300 case 0x103c358a:
5301
5302 case 0x103c3667:
5303 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005304 case 0x103c3669:
5305
5306 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005307 }
5308 return 0;
5309}
5310
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005311static int patch_stac92hd83xxx(struct hda_codec *codec)
5312{
5313 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005314 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005315 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005316 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005317
5318 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5319 if (spec == NULL)
5320 return -ENOMEM;
5321
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005322 if (hp_bnb2011_with_dock(codec)) {
5323 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5324 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5325 }
5326
Charles1cc9e8f2010-10-18 16:22:00 +08005327 /* reset pin power-down; Windows may leave these bits after reboot */
5328 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7EC, 0);
5329 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
Takashi Iwaia252c812009-12-25 22:56:20 +01005330 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005331 codec->spec = spec;
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005332 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005333 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005334 spec->digbeep_nid = 0x21;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005335 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5336 spec->dmux_nids = stac92hd83xxx_mux_nids;
Takashi Iwai667067d2009-08-13 18:14:42 +02005337 spec->mux_nids = stac92hd83xxx_mux_nids;
5338 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005339 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005340 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005341 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5342 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5343 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005344 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005345
5346 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005347 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005348 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005349 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5350 spec->capvols = stac92hd83xxx_capvols;
5351 spec->capsws = stac92hd83xxx_capsws;
5352
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005353 spec->board_config = snd_hda_check_board_config(codec,
5354 STAC_92HD83XXX_MODELS,
5355 stac92hd83xxx_models,
5356 stac92hd83xxx_cfg_tbl);
5357again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005358 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005359 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5360 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005361 else
5362 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005363 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005364
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005365 switch (codec->vendor_id) {
David Henningsson89feca12010-10-13 15:48:24 +02005366 case 0x111d76d1:
5367 case 0x111d76d9:
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06005368 case 0x111d76e5:
David Henningsson89feca12010-10-13 15:48:24 +02005369 spec->dmic_nids = stac92hd87b_dmic_nids;
5370 spec->num_dmics = stac92xx_connected_ports(codec,
5371 stac92hd87b_dmic_nids,
5372 STAC92HD87B_NUM_DMICS);
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06005373 spec->num_pins = ARRAY_SIZE(stac92hd87xxx_pin_nids);
5374 spec->pin_nids = stac92hd87xxx_pin_nids;
David Henningssonbdfe6f42011-01-04 06:30:53 +01005375 spec->mono_nid = 0;
5376 spec->num_pwrs = 0;
5377 break;
Charles Chin36706002010-01-29 12:05:51 +01005378 case 0x111d7666:
5379 case 0x111d7667:
5380 case 0x111d7668:
5381 case 0x111d7669:
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06005382 case 0x111d76e3:
David Henningssonbdfe6f42011-01-04 06:30:53 +01005383 spec->num_dmics = stac92xx_connected_ports(codec,
5384 stac92hd88xxx_dmic_nids,
5385 STAC92HD88XXX_NUM_DMICS);
Charles Chin36706002010-01-29 12:05:51 +01005386 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5387 spec->pin_nids = stac92hd88xxx_pin_nids;
5388 spec->mono_nid = 0;
Charles Chin36706002010-01-29 12:05:51 +01005389 spec->num_pwrs = 0;
5390 break;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005391 case 0x111d7604:
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01005392 case 0x111d76d4:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005393 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005394 case 0x111d76d5:
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005395 case 0x111d76e7:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005396 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5397 break;
5398 spec->num_pwrs = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005399 spec->num_dmics = stac92xx_connected_ports(codec,
5400 stac92hd83xxx_dmic_nids,
5401 STAC92HD83XXX_NUM_DMICS);
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005402 break;
5403 }
5404
Takashi Iwaib4e81872009-11-18 17:20:24 +01005405 codec->patch_ops = stac92xx_patch_ops;
5406
Takashi Iwaidce17d42010-02-09 09:25:26 +01005407 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005408 snd_printd("mute LED gpio %d polarity %d\n",
5409 spec->gpio_led,
5410 spec->gpio_led_polarity);
5411
Takashi Iwaib4e81872009-11-18 17:20:24 +01005412#ifdef CONFIG_SND_HDA_POWER_SAVE
5413 if (spec->gpio_led) {
5414 spec->gpio_mask |= spec->gpio_led;
5415 spec->gpio_dir |= spec->gpio_led;
5416 spec->gpio_data |= spec->gpio_led;
5417 /* register check_power_status callback. */
5418 codec->patch_ops.check_power_status =
Takashi Iwaic21bd022010-02-08 15:16:08 +01005419 stac92xx_hp_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005420 }
5421#endif
5422
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005423 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5424 if (!err) {
5425 if (spec->board_config < 0) {
5426 printk(KERN_WARNING "hda_codec: No auto-config is "
5427 "available, default to model=ref\n");
5428 spec->board_config = STAC_92HD83XXX_REF;
5429 goto again;
5430 }
5431 err = -EINVAL;
5432 }
5433
5434 if (err < 0) {
5435 stac92xx_free(codec);
5436 return err;
5437 }
5438
Charles Chin04b5efe2010-02-04 10:28:02 +01005439 /* docking output support */
5440 num_dacs = snd_hda_get_connections(codec, 0xF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005441 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Charles Chin04b5efe2010-02-04 10:28:02 +01005442 /* skip non-DAC connections */
5443 while (num_dacs >= 0 &&
5444 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5445 != AC_WID_AUD_OUT))
5446 num_dacs--;
5447 /* set port E and F to select the last DAC */
5448 if (num_dacs >= 0) {
5449 snd_hda_codec_write_cache(codec, 0xE, 0,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005450 AC_VERB_SET_CONNECT_SEL, num_dacs);
Charles Chin04b5efe2010-02-04 10:28:02 +01005451 snd_hda_codec_write_cache(codec, 0xF, 0,
5452 AC_VERB_SET_CONNECT_SEL, num_dacs);
5453 }
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005454
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005455 codec->proc_widget_hook = stac92hd_proc_hook;
5456
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005457 return 0;
5458}
5459
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005460static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5461 hda_nid_t dig0pin)
5462{
5463 struct sigmatel_spec *spec = codec->spec;
5464 int idx;
5465
5466 for (idx = 0; idx < spec->num_pins; idx++)
5467 if (spec->pin_nids[idx] == dig0pin)
5468 break;
5469 if ((idx + 2) >= spec->num_pins)
5470 return 0;
5471
5472 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005473 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005474 return 2;
5475
5476 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005477 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005478 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005479 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005480 return 1;
5481 else
5482 return 0;
5483}
5484
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005485/* HP dv7 bass switch - GPIO5 */
5486#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5487static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5488 struct snd_ctl_elem_value *ucontrol)
5489{
5490 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5491 struct sigmatel_spec *spec = codec->spec;
5492 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5493 return 0;
5494}
5495
5496static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5497 struct snd_ctl_elem_value *ucontrol)
5498{
5499 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5500 struct sigmatel_spec *spec = codec->spec;
5501 unsigned int gpio_data;
5502
5503 gpio_data = (spec->gpio_data & ~0x20) |
5504 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5505 if (gpio_data == spec->gpio_data)
5506 return 0;
5507 spec->gpio_data = gpio_data;
5508 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5509 return 1;
5510}
5511
5512static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5514 .info = stac_hp_bass_gpio_info,
5515 .get = stac_hp_bass_gpio_get,
5516 .put = stac_hp_bass_gpio_put,
5517};
5518
5519static int stac_add_hp_bass_switch(struct hda_codec *codec)
5520{
5521 struct sigmatel_spec *spec = codec->spec;
5522
5523 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5524 "Bass Speaker Playback Switch", 0))
5525 return -ENOMEM;
5526
5527 spec->gpio_mask |= 0x20;
5528 spec->gpio_dir |= 0x20;
5529 spec->gpio_data |= 0x20;
5530 return 0;
5531}
5532
Matthew Ranostaye035b842007-11-06 11:53:55 +01005533static int patch_stac92hd71bxx(struct hda_codec *codec)
5534{
5535 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005536 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005537 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005538 int err = 0;
5539
5540 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5541 if (spec == NULL)
5542 return -ENOMEM;
5543
Takashi Iwaia252c812009-12-25 22:56:20 +01005544 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005545 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005546 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005547 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005548 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5549 switch (codec->vendor_id) {
5550 case 0x111d76b6:
5551 case 0x111d76b7:
5552 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5553 break;
5554 case 0x111d7603:
5555 case 0x111d7608:
5556 /* On 92HD75Bx 0x27 isn't a pin nid */
5557 spec->num_pins--;
5558 /* fallthrough */
5559 default:
5560 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5561 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005562 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005563 spec->board_config = snd_hda_check_board_config(codec,
5564 STAC_92HD71BXX_MODELS,
5565 stac92hd71bxx_models,
5566 stac92hd71bxx_cfg_tbl);
5567again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005568 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005569 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5570 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005571 else
5572 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005573 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005574
Takashi Iwaifc64b262009-09-14 15:33:01 +02005575 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005576 /* GPIO0 = EAPD */
5577 spec->gpio_mask = 0x01;
5578 spec->gpio_dir = 0x01;
5579 spec->gpio_data = 0x01;
5580 }
5581
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005582 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5583 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5584
Takashi Iwai6479c632009-07-28 18:20:25 +02005585 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5586 spec->capvols = stac92hd71bxx_capvols;
5587 spec->capsws = stac92hd71bxx_capsws;
5588
Matthew Ranostay541eee82007-12-14 12:08:04 +01005589 switch (codec->vendor_id) {
5590 case 0x111d76b6: /* 4 Port without Analog Mixer */
5591 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005592 unmute_init++;
5593 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005594 case 0x111d76b4: /* 6 Port without Analog Mixer */
5595 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005596 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005597 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005598 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005599 stac92hd71bxx_dmic_nids,
5600 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005601 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005602 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005603 switch (spec->board_config) {
5604 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005605 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005606 err = stac_add_event(spec, codec->afg,
5607 STAC_VREF_EVENT, 0x02);
5608 if (err < 0)
5609 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005610 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005611 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5612 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005613 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005614 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005615 spec->gpio_mask |= 0x02;
5616 break;
5617 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005618 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005619 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005620 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005621
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005622 /* no output amps */
5623 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005624 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005625 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005626 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005627 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5628 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005629 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005630 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005631 stac92hd71bxx_dmic_nids,
5632 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005633 break;
5634 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005635 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005636 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005637
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005638 /* no output amps */
5639 spec->num_pwrs = 0;
5640 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005641 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005642 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005643 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005644 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005645 stac92hd71bxx_dmic_nids,
5646 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005647 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005648 }
5649
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005650 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5651 snd_hda_sequence_write_cache(codec, unmute_init);
5652
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005653 /* Some HP machines seem to have unstable codec communications
5654 * especially with ATI fglrx driver. For recovering from the
5655 * CORB/RIRB stall, allow the BUS reset and keep always sync
5656 */
5657 if (spec->board_config == STAC_HP_DV5) {
5658 codec->bus->sync_write = 1;
5659 codec->bus->allow_bus_reset = 1;
5660 }
5661
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005662 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005663 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005664 spec->aloopback_shift = 0;
5665
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005666 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005667 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005668 spec->mux_nids = stac92hd71bxx_mux_nids;
5669 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005670 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005671 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005672
5673 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5674 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005675 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005676 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005677
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305678 snd_printdd("Found board config: %d\n", spec->board_config);
5679
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005680 switch (spec->board_config) {
5681 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005682 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005683 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005684 stac92xx_auto_set_pinctl(codec, 0x0e,
5685 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005686 /* fallthru */
5687 case STAC_DELL_M4_2:
5688 spec->num_dmics = 0;
5689 spec->num_smuxes = 0;
5690 spec->num_dmuxes = 0;
5691 break;
5692 case STAC_DELL_M4_1:
5693 case STAC_DELL_M4_3:
5694 spec->num_dmics = 1;
5695 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005696 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005697 break;
James Gardiner514bf542009-05-03 04:00:44 -04005698 case STAC_HP_DV4_1222NR:
5699 spec->num_dmics = 1;
5700 /* I don't know if it needs 1 or 2 smuxes - will wait for
5701 * bug reports to fix if needed
5702 */
5703 spec->num_smuxes = 1;
5704 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005705 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005706 case STAC_HP_DV4:
5707 spec->gpio_led = 0x01;
5708 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005709 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005710 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005711 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005712 /* HP dv6 gives the headphone pin as a line-out. Thus we
5713 * need to set hp_detect flag here to force to enable HP
5714 * detection.
5715 */
5716 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005717 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005718 case STAC_HP_HDX:
5719 spec->num_dmics = 1;
5720 spec->num_dmuxes = 1;
5721 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005722 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005723 break;
5724 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005725
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005726 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005727 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5728 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5729 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5730 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5731 /* It was changed in the BIOS to just satisfy MS DTM.
5732 * Lets turn it back into slaved HP
5733 */
5734 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5735 | (AC_JACK_HP_OUT <<
5736 AC_DEFCFG_DEVICE_SHIFT);
5737 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5738 | AC_DEFCFG_SEQUENCE)))
5739 | 0x1f;
5740 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5741 }
5742 }
5743
Takashi Iwaidce17d42010-02-09 09:25:26 +01005744 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005745 snd_printd("mute LED gpio %d polarity %d\n",
5746 spec->gpio_led,
5747 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005748
Takashi Iwai86d190e2009-05-26 15:18:58 +02005749#ifdef CONFIG_SND_HDA_POWER_SAVE
5750 if (spec->gpio_led) {
5751 spec->gpio_mask |= spec->gpio_led;
5752 spec->gpio_dir |= spec->gpio_led;
5753 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005754 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005755 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005756 stac92xx_hp_check_power_status;
5757 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005758#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005759
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005760 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005761
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005762 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005763 if (!err) {
5764 if (spec->board_config < 0) {
5765 printk(KERN_WARNING "hda_codec: No auto-config is "
5766 "available, default to model=ref\n");
5767 spec->board_config = STAC_92HD71BXX_REF;
5768 goto again;
5769 }
5770 err = -EINVAL;
5771 }
5772
5773 if (err < 0) {
5774 stac92xx_free(codec);
5775 return err;
5776 }
5777
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005778 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005779 if (spec->board_config == STAC_HP_DV4 ||
5780 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005781 unsigned int cap;
5782 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5783 cap &= AC_GPIO_IO_COUNT;
5784 if (cap >= 6)
5785 stac_add_hp_bass_switch(codec);
5786 }
5787
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005788 codec->proc_widget_hook = stac92hd7x_proc_hook;
5789
Matthew Ranostaye035b842007-11-06 11:53:55 +01005790 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005791}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005792
Matt2f2f4252005-04-13 14:45:30 +02005793static int patch_stac922x(struct hda_codec *codec)
5794{
5795 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005796 int err;
Matt2f2f4252005-04-13 14:45:30 +02005797
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005798 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005799 if (spec == NULL)
5800 return -ENOMEM;
5801
Takashi Iwaia252c812009-12-25 22:56:20 +01005802 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005803 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005804 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005805 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005806 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005807 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5808 stac922x_models,
5809 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005810 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005811 spec->gpio_mask = spec->gpio_dir = 0x03;
5812 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005813 /* Intel Macs have all same PCI SSID, so we need to check
5814 * codec SSID to distinguish the exact models
5815 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005816 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005817 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005818
5819 case 0x106b0800:
5820 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005821 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005822 case 0x106b0600:
5823 case 0x106b0700:
5824 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005825 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005826 case 0x106b0e00:
5827 case 0x106b0f00:
5828 case 0x106b1600:
5829 case 0x106b1700:
5830 case 0x106b0200:
5831 case 0x106b1e00:
5832 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005833 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005834 case 0x106b1a00:
5835 case 0x00000100:
5836 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005837 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005838 case 0x106b0a00:
5839 case 0x106b2200:
5840 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005841 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005842 default:
5843 spec->board_config = STAC_INTEL_MAC_V3;
5844 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005845 }
5846 }
5847
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005848 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005849 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005850 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5851 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005852 else
5853 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005854 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005855
Matt2f2f4252005-04-13 14:45:30 +02005856 spec->adc_nids = stac922x_adc_nids;
5857 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005858 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005859 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005860 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005861 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005862
5863 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005864
5865 spec->num_caps = STAC922X_NUM_CAPS;
5866 spec->capvols = stac922x_capvols;
5867 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005868
5869 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005870
Matt Porter3cc08dc2006-01-23 15:27:49 +01005871 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005872 if (!err) {
5873 if (spec->board_config < 0) {
5874 printk(KERN_WARNING "hda_codec: No auto-config is "
5875 "available, default to model=ref\n");
5876 spec->board_config = STAC_D945_REF;
5877 goto again;
5878 }
5879 err = -EINVAL;
5880 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005881 if (err < 0) {
5882 stac92xx_free(codec);
5883 return err;
5884 }
5885
5886 codec->patch_ops = stac92xx_patch_ops;
5887
Takashi Iwai807a46362007-05-29 19:01:37 +02005888 /* Fix Mux capture level; max to 2 */
5889 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5890 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5891 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5892 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5893 (0 << AC_AMPCAP_MUTE_SHIFT));
5894
Matt Porter3cc08dc2006-01-23 15:27:49 +01005895 return 0;
5896}
5897
5898static int patch_stac927x(struct hda_codec *codec)
5899{
5900 struct sigmatel_spec *spec;
5901 int err;
5902
5903 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5904 if (spec == NULL)
5905 return -ENOMEM;
5906
Takashi Iwaia252c812009-12-25 22:56:20 +01005907 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005908 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005909 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005910 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005911 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005912 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005913 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5914 stac927x_models,
5915 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005916 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005917 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005918 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5919 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005920 else
5921 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005922 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005923
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005924 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005925 spec->adc_nids = stac927x_adc_nids;
5926 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5927 spec->mux_nids = stac927x_mux_nids;
5928 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005929 spec->smux_nids = stac927x_smux_nids;
5930 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005931 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005932 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005933 spec->multiout.dac_nids = spec->dac_nids;
5934
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005935 if (spec->board_config != STAC_D965_REF) {
5936 /* GPIO0 High = Enable EAPD */
5937 spec->eapd_mask = spec->gpio_mask = 0x01;
5938 spec->gpio_dir = spec->gpio_data = 0x01;
5939 }
5940
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005941 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005942 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005943 case STAC_D965_5ST:
5944 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005945 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02005946 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005947 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005948 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005949 switch (codec->subsystem_id) {
5950 case 0x10280209:
5951 case 0x1028022e:
5952 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005953 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005954 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005955 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005956 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005957 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005958 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005959 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005960 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005961 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005962 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005963 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005964 if (codec->subsystem_id != 0x1028022f) {
5965 /* GPIO2 High = Enable EAPD */
5966 spec->eapd_mask = spec->gpio_mask = 0x04;
5967 spec->gpio_dir = spec->gpio_data = 0x04;
5968 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005969 spec->dmic_nids = stac927x_dmic_nids;
5970 spec->num_dmics = STAC927X_NUM_DMICS;
5971
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02005972 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005973 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005974 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005975 break;
Takashi Iwai54930532009-10-11 17:38:29 +02005976 case STAC_927X_VOLKNOB:
5977 spec->num_dmics = 0;
5978 spec->init = stac927x_volknob_core_init;
5979 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005980 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005981 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005982 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005983 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005984 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005985
Takashi Iwai6479c632009-07-28 18:20:25 +02005986 spec->num_caps = STAC927X_NUM_CAPS;
5987 spec->capvols = stac927x_capvols;
5988 spec->capsws = stac927x_capsws;
5989
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005990 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005991 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005992 spec->aloopback_mask = 0x40;
5993 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005994 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005995
Matt Porter3cc08dc2006-01-23 15:27:49 +01005996 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005997 if (!err) {
5998 if (spec->board_config < 0) {
5999 printk(KERN_WARNING "hda_codec: No auto-config is "
6000 "available, default to model=ref\n");
6001 spec->board_config = STAC_D965_REF;
6002 goto again;
6003 }
6004 err = -EINVAL;
6005 }
Mattc7d4b2f2005-06-27 14:59:41 +02006006 if (err < 0) {
6007 stac92xx_free(codec);
6008 return err;
6009 }
Matt2f2f4252005-04-13 14:45:30 +02006010
6011 codec->patch_ops = stac92xx_patch_ops;
6012
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006013 codec->proc_widget_hook = stac927x_proc_hook;
6014
Takashi Iwai52987652008-01-16 16:09:47 +01006015 /*
6016 * !!FIXME!!
6017 * The STAC927x seem to require fairly long delays for certain
6018 * command sequences. With too short delays (even if the answer
6019 * is set to RIRB properly), it results in the silence output
6020 * on some hardwares like Dell.
6021 *
6022 * The below flag enables the longer delay (see get_response
6023 * in hda_intel.c).
6024 */
6025 codec->bus->needs_damn_long_delay = 1;
6026
Takashi Iwaie28d8322008-12-17 13:48:29 +01006027 /* no jack detecion for ref-no-jd model */
6028 if (spec->board_config == STAC_D965_REF_NO_JD)
6029 spec->hp_detect = 0;
6030
Matt2f2f4252005-04-13 14:45:30 +02006031 return 0;
6032}
6033
Matt Porterf3302a52006-07-31 12:49:34 +02006034static int patch_stac9205(struct hda_codec *codec)
6035{
6036 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006037 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006038
6039 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6040 if (spec == NULL)
6041 return -ENOMEM;
6042
Takashi Iwaia252c812009-12-25 22:56:20 +01006043 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006044 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006045 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006046 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006047 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006048 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6049 stac9205_models,
6050 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006051 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006052 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006053 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6054 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006055 else
6056 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006057 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006058
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006059 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006060 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006061 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006062 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006063 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006064 spec->smux_nids = stac9205_smux_nids;
6065 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006066 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006067 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006068 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006069 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006070 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006071
6072 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006073 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006074
Takashi Iwai6479c632009-07-28 18:20:25 +02006075 spec->num_caps = STAC9205_NUM_CAPS;
6076 spec->capvols = stac9205_capvols;
6077 spec->capsws = stac9205_capsws;
6078
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006079 spec->aloopback_mask = 0x40;
6080 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006081 /* Turn on/off EAPD per HP plugging */
6082 if (spec->board_config != STAC_9205_EAPD)
6083 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006084 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006085
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006086 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006087 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006088 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006089 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6090 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006091
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006092 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006093 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6094 if (err < 0)
6095 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006096 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006097 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6098 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006099 AC_VERB_SET_UNSOLICITED_ENABLE,
6100 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006101
6102 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006103 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006104 spec->gpio_mask = 0x1b;
6105 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006106 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006107 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006108 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006109 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006110 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006111 case STAC_9205_REF:
6112 /* SPDIF-In enabled */
6113 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006114 default:
6115 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006116 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006117 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006118 break;
6119 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006120
Matt Porterf3302a52006-07-31 12:49:34 +02006121 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006122 if (!err) {
6123 if (spec->board_config < 0) {
6124 printk(KERN_WARNING "hda_codec: No auto-config is "
6125 "available, default to model=ref\n");
6126 spec->board_config = STAC_9205_REF;
6127 goto again;
6128 }
6129 err = -EINVAL;
6130 }
Matt Porterf3302a52006-07-31 12:49:34 +02006131 if (err < 0) {
6132 stac92xx_free(codec);
6133 return err;
6134 }
6135
6136 codec->patch_ops = stac92xx_patch_ops;
6137
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006138 codec->proc_widget_hook = stac9205_proc_hook;
6139
Matt Porterf3302a52006-07-31 12:49:34 +02006140 return 0;
6141}
6142
Matt2f2f4252005-04-13 14:45:30 +02006143/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006144 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006145 */
6146
Takashi Iwai1e137f92009-01-21 07:41:22 +01006147static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006148 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006149 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6150 {}
6151};
6152
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006153static hda_nid_t stac9872_pin_nids[] = {
6154 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6155 0x11, 0x13, 0x14,
6156};
6157
6158static hda_nid_t stac9872_adc_nids[] = {
6159 0x8 /*,0x6*/
6160};
6161
6162static hda_nid_t stac9872_mux_nids[] = {
6163 0x15
6164};
6165
Takashi Iwai6479c632009-07-28 18:20:25 +02006166static unsigned long stac9872_capvols[] = {
6167 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6168};
6169#define stac9872_capsws stac9872_capvols
6170
Takashi Iwai307282c2009-03-12 18:17:58 +01006171static unsigned int stac9872_vaio_pin_configs[9] = {
6172 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6173 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6174 0x90a7013e
6175};
6176
Takashi Iwaiea734962011-01-17 11:29:34 +01006177static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006178 [STAC_9872_AUTO] = "auto",
6179 [STAC_9872_VAIO] = "vaio",
6180};
6181
6182static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6183 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6184};
6185
6186static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006187 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6188 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006189 {} /* terminator */
6190};
6191
Guillaume Munch6d859062006-08-22 17:15:47 +02006192static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006193{
6194 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006195 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006196
Takashi Iwaidb064e52006-03-16 16:04:58 +01006197 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6198 if (spec == NULL)
6199 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006200 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006201 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006202 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006203 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6204 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006205
6206 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6207 stac9872_models,
6208 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006209 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006210 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6211 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006212 else
6213 stac92xx_set_config_regs(codec,
6214 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006215
Takashi Iwai1e137f92009-01-21 07:41:22 +01006216 spec->multiout.dac_nids = spec->dac_nids;
6217 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6218 spec->adc_nids = stac9872_adc_nids;
6219 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6220 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006221 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006222 spec->num_caps = 1;
6223 spec->capvols = stac9872_capvols;
6224 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006225
Takashi Iwai1e137f92009-01-21 07:41:22 +01006226 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6227 if (err < 0) {
6228 stac92xx_free(codec);
6229 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006230 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006231 spec->input_mux = &spec->private_imux;
6232 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006233 return 0;
6234}
6235
6236
6237/*
Matt2f2f4252005-04-13 14:45:30 +02006238 * patch entries
6239 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006240static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006241 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6242 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6243 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6244 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6245 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6246 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6247 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006248 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6249 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6250 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6251 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6252 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6253 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006254 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6255 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6256 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6257 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6258 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6259 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6260 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6261 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6262 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6263 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006264 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6265 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6266 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6267 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6268 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6269 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006270 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6271 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006272 /* The following does not take into account .id=0x83847661 when subsys =
6273 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6274 * currently not fully supported.
6275 */
6276 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6277 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6278 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006279 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006280 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6281 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6282 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6283 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6284 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6285 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6286 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6287 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006288 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006289 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006290 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006291 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006292 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006293 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6294 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006295 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6296 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6297 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6298 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006299 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006300 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6301 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006302 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006303 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6304 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6305 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6306 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6307 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6308 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6309 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6310 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006311 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6312 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6313 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6314 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6315 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6316 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6317 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6318 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6319 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6320 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6321 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6322 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6323 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6324 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6325 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006326 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006327 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6328 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006329 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006330 {} /* terminator */
6331};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006332
6333MODULE_ALIAS("snd-hda-codec-id:8384*");
6334MODULE_ALIAS("snd-hda-codec-id:111d*");
6335
6336MODULE_LICENSE("GPL");
6337MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6338
6339static struct hda_codec_preset_list sigmatel_list = {
6340 .preset = snd_hda_preset_sigmatel,
6341 .owner = THIS_MODULE,
6342};
6343
6344static int __init patch_sigmatel_init(void)
6345{
6346 return snd_hda_add_codec_preset(&sigmatel_list);
6347}
6348
6349static void __exit patch_sigmatel_exit(void)
6350{
6351 snd_hda_delete_codec_preset(&sigmatel_list);
6352}
6353
6354module_init(patch_sigmatel_init)
6355module_exit(patch_sigmatel_exit)