blob: e035cf6de278c365910e5c34b5d090aeef86eb41 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040032#include <linux/module.h>
Matt2f2f4252005-04-13 14:45:30 +020033#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020034#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040035#include <sound/jack.h>
Clemens Ladischa74ccea2010-10-22 15:52:34 +020036#include <sound/tlv.h>
Matt2f2f4252005-04-13 14:45:30 +020037#include "hda_codec.h"
38#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020039#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020040
Takashi Iwaic6e4c662008-11-25 11:58:19 +010041enum {
42 STAC_VREF_EVENT = 1,
43 STAC_INSERT_EVENT,
44 STAC_PWR_EVENT,
45 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020046 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020047 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010048};
Matt4e550962005-07-04 17:51:39 +020049
Takashi Iwaif5fcc132006-11-24 17:07:44 +010050enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010051 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010052 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010053 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020054 STAC_9200_DELL_D21,
55 STAC_9200_DELL_D22,
56 STAC_9200_DELL_D23,
57 STAC_9200_DELL_M21,
58 STAC_9200_DELL_M22,
59 STAC_9200_DELL_M23,
60 STAC_9200_DELL_M24,
61 STAC_9200_DELL_M25,
62 STAC_9200_DELL_M26,
63 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020064 STAC_9200_M4,
65 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010066 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010067 STAC_9200_MODELS
68};
69
70enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010071 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010072 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020073 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020074 STAC_9205_DELL_M43,
75 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010076 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010077 STAC_9205_MODELS
78};
79
80enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010081 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010082 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010083 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080084 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010085 STAC_DELL_M6_AMIC,
86 STAC_DELL_M6_DMIC,
87 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050088 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020089 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010090 STAC_92HD73XX_MODELS
91};
92
93enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010094 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020095 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050096 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050097 STAC_DELL_S14,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +010098 STAC_DELL_VOSTRO_3500,
Takashi Iwaib4e81872009-11-18 17:20:24 +010099 STAC_92HD83XXX_HP,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -0500100 STAC_92HD83XXX_HP_cNB11_INTQUAD,
Steven Eastland48315592010-08-06 15:07:35 -0600101 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200102 STAC_92HD83XXX_MODELS
103};
104
105enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100106 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100107 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100108 STAC_DELL_M4_1,
109 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500110 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400111 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200112 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100113 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100114 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400115 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100116 STAC_92HD71BXX_MODELS
117};
118
119enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100120 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100121 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200122 STAC_M1,
123 STAC_M1_2,
124 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100125 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200126 STAC_M3,
127 STAC_M5,
128 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100129 STAC_925x_MODELS
130};
131
132enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100133 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100134 STAC_D945_REF,
135 STAC_D945GTP3,
136 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200137 STAC_INTEL_MAC_V1,
138 STAC_INTEL_MAC_V2,
139 STAC_INTEL_MAC_V3,
140 STAC_INTEL_MAC_V4,
141 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800142 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
143 * is given, one of the above models will be
144 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200145 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100146 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100147 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100148 STAC_MACBOOK_PRO_V1,
149 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200150 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200151 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300152 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200153 STAC_922X_DELL_D81,
154 STAC_922X_DELL_D82,
155 STAC_922X_DELL_M81,
156 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100157 STAC_922X_MODELS
158};
159
160enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100161 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100162 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100163 STAC_D965_REF,
164 STAC_D965_3ST,
165 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200166 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200167 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100168 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200169 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100170 STAC_927X_MODELS
171};
Matt Porter403d1942005-11-29 15:00:51 +0100172
Takashi Iwai307282c2009-03-12 18:17:58 +0100173enum {
174 STAC_9872_AUTO,
175 STAC_9872_VAIO,
176 STAC_9872_MODELS
177};
178
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400179struct sigmatel_event {
180 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100181 unsigned char type;
182 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400183 int data;
184};
185
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200186struct sigmatel_mic_route {
187 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200188 signed char mux_idx;
189 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200190};
191
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600192#define MAX_PINS_NUM 16
193#define MAX_ADCS_NUM 4
194#define MAX_DMICS_NUM 4
195
Matt2f2f4252005-04-13 14:45:30 +0200196struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100197 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200198 unsigned int num_mixers;
199
Matt Porter403d1942005-11-29 15:00:51 +0100200 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500201 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200202 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100203 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100204 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400205 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100206 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200207 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100208 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200209
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100210 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200211 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100212 unsigned int gpio_mask;
213 unsigned int gpio_dir;
214 unsigned int gpio_data;
215 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200216 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100217 unsigned int gpio_led_polarity;
Takashi Iwaif1a73742011-12-04 13:44:06 +0100218 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500219 unsigned int vref_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100220
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200221 /* stream */
222 unsigned int stream_delay;
223
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100224 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200225 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100226 unsigned char aloopback_mask;
227 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200228
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100229 /* power management */
230 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200231 const hda_nid_t *pwr_nids;
232 const hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100233
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400234 /* events */
235 struct snd_array events;
236
Matt2f2f4252005-04-13 14:45:30 +0200237 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100238 struct hda_input_mux *mono_mux;
239 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200240 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100241 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100242 hda_nid_t hp_dacs[5];
243 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200244
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100245 int volume_offset;
246
Matt2f2f4252005-04-13 14:45:30 +0200247 /* capture */
Takashi Iwai2b635362011-05-02 12:33:43 +0200248 const hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200249 unsigned int num_adcs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200250 const hda_nid_t *mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200251 unsigned int num_muxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200252 const hda_nid_t *dmic_nids;
Matt Porter8b657272006-10-26 17:12:59 +0200253 unsigned int num_dmics;
Takashi Iwai2b635362011-05-02 12:33:43 +0200254 const hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100255 unsigned int num_dmuxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200256 const hda_nid_t *smux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200257 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200258 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200259
Takashi Iwai2b635362011-05-02 12:33:43 +0200260 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
261 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
Takashi Iwai6479c632009-07-28 18:20:25 +0200262 unsigned int num_caps; /* number of capture volume/switch elements */
263
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200264 struct sigmatel_mic_route ext_mic;
265 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200266 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200267
Takashi Iwaiea734962011-01-17 11:29:34 +0100268 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200269
Mattdabbed62005-06-14 10:19:34 +0200270 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100271 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200272 hda_nid_t anabeep_nid;
273 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200274
Matt2f2f4252005-04-13 14:45:30 +0200275 /* pin widgets */
Takashi Iwai2b635362011-05-02 12:33:43 +0200276 const hda_nid_t *pin_nids;
Matt2f2f4252005-04-13 14:45:30 +0200277 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200278
279 /* codec specific stuff */
Takashi Iwai2b635362011-05-02 12:33:43 +0200280 const struct hda_verb *init;
281 const struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200282
283 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200284 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100285 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200286 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100287 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200288 struct hda_input_mux *sinput_mux;
289 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400290 unsigned int cur_amux;
291 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200292 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200293
Matt Porter403d1942005-11-29 15:00:51 +0100294 /* i/o switches */
295 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200296 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100297 hda_nid_t line_switch; /* shared line-in for input and output */
298 hda_nid_t mic_switch; /* shared mic-in for input and output */
299 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200300 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200301
Mattc7d4b2f2005-06-27 14:59:41 +0200302 struct hda_pcm pcm_rec[2]; /* PCM information */
303
304 /* dynamic controls and input_mux */
305 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200306 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200307 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200308 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200309 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100310 struct hda_input_mux private_mono_mux;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600311
312 /* auto spec */
313 unsigned auto_pin_cnt;
314 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
315 unsigned auto_adc_cnt;
316 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
317 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
318 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
319 unsigned long auto_capvols[MAX_ADCS_NUM];
320 unsigned auto_dmic_cnt;
321 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
Matt2f2f4252005-04-13 14:45:30 +0200322};
323
Takashi Iwai2b635362011-05-02 12:33:43 +0200324static const hda_nid_t stac9200_adc_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200325 0x03,
326};
327
Takashi Iwai2b635362011-05-02 12:33:43 +0200328static const hda_nid_t stac9200_mux_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200329 0x0c,
330};
331
Takashi Iwai2b635362011-05-02 12:33:43 +0200332static const hda_nid_t stac9200_dac_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200333 0x02,
334};
335
Takashi Iwai2b635362011-05-02 12:33:43 +0200336static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100337 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
338 0x0f, 0x10, 0x11
339};
340
Takashi Iwai2b635362011-05-02 12:33:43 +0200341static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400342 0x26, 0,
343};
344
Takashi Iwai2b635362011-05-02 12:33:43 +0200345static const hda_nid_t stac92hd73xx_adc_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100346 0x1a, 0x1b
347};
348
349#define STAC92HD73XX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200350static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100351 0x13, 0x14, 0
352};
353
354#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100355
Takashi Iwai2b635362011-05-02 12:33:43 +0200356static const hda_nid_t stac92hd73xx_mux_nids[2] = {
Takashi Iwaie2aec172009-09-02 01:00:05 +0200357 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100358};
359
Takashi Iwai2b635362011-05-02 12:33:43 +0200360static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100361 0x20, 0x21,
362};
363
Takashi Iwai2b635362011-05-02 12:33:43 +0200364static const hda_nid_t stac92hd73xx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200365 0x22, 0x23,
366};
367
Takashi Iwai6479c632009-07-28 18:20:25 +0200368#define STAC92HD73XX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200369static const unsigned long stac92hd73xx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200370 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
371 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
372};
373#define stac92hd73xx_capsws stac92hd73xx_capvols
374
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200375#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200376
Charles Chinafef2cf2011-11-11 08:05:28 +0100377static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
378 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
379 0x0f, 0x10
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200380};
381
Takashi Iwai2b635362011-05-02 12:33:43 +0200382static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400383 0x1e, 0,
384};
385
Takashi Iwai2b635362011-05-02 12:33:43 +0200386static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600387 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200388};
389
Takashi Iwai2b635362011-05-02 12:33:43 +0200390static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100391 0x0a, 0x0d, 0x0f
392};
393
Takashi Iwai2b635362011-05-02 12:33:43 +0200394static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100395 0x12, 0x13,
396};
397
Takashi Iwai2b635362011-05-02 12:33:43 +0200398static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100399 0x1a, 0x1b
400};
401
Takashi Iwai2b635362011-05-02 12:33:43 +0200402static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400403 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100404};
405
Takashi Iwai2b635362011-05-02 12:33:43 +0200406static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200407 0x24, 0x25,
408};
409
Matthew Ranostaye035b842007-11-06 11:53:55 +0100410#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200411static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100412 0x18, 0x19, 0
413};
414
Takashi Iwai2b635362011-05-02 12:33:43 +0200415static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
416 0x18, 0
417};
418
419static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400420 0x22, 0
421};
422
Takashi Iwai6479c632009-07-28 18:20:25 +0200423#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200424static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200425 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
426 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
427};
428#define stac92hd71bxx_capsws stac92hd71bxx_capvols
429
Takashi Iwai2b635362011-05-02 12:33:43 +0200430static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100431 0x03,
432};
433
Takashi Iwai2b635362011-05-02 12:33:43 +0200434static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100435 0x0f,
436};
437
Takashi Iwai2b635362011-05-02 12:33:43 +0200438static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100439 0x02,
440};
441
Takashi Iwaif6e98522007-10-16 14:27:04 +0200442#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200443static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200444 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200445};
446
Takashi Iwai2b635362011-05-02 12:33:43 +0200447static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100448 0x14,
449};
450
Takashi Iwai2b635362011-05-02 12:33:43 +0200451static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200452 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
453};
Takashi Iwai2b635362011-05-02 12:33:43 +0200454static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200455 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
456};
457
Takashi Iwai2b635362011-05-02 12:33:43 +0200458static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200459 0x06, 0x07,
460};
461
Takashi Iwai2b635362011-05-02 12:33:43 +0200462static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200463 0x12, 0x13,
464};
465
Takashi Iwai6479c632009-07-28 18:20:25 +0200466#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200467static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200468 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
469 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
470};
471#define stac922x_capsws stac922x_capvols
472
Takashi Iwai2b635362011-05-02 12:33:43 +0200473static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500474 0x1f, 0,
475};
476
Takashi Iwai2b635362011-05-02 12:33:43 +0200477static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100478 0x07, 0x08, 0x09
479};
480
Takashi Iwai2b635362011-05-02 12:33:43 +0200481static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100482 0x15, 0x16, 0x17
483};
484
Takashi Iwai2b635362011-05-02 12:33:43 +0200485static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200486 0x21,
487};
488
Takashi Iwai2b635362011-05-02 12:33:43 +0200489static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100490 0x02, 0x03, 0x04, 0x05, 0x06, 0
491};
492
Takashi Iwai2b635362011-05-02 12:33:43 +0200493static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100494 0x1b,
495};
496
Matthew Ranostay7f168592007-10-18 17:38:17 +0200497#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200498static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200499 0x13, 0x14, 0
500};
501
Takashi Iwai6479c632009-07-28 18:20:25 +0200502#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200503static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200504 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
505 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
506 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
507};
Takashi Iwai2b635362011-05-02 12:33:43 +0200508static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200509 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
510 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
511 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
512};
513
Takashi Iwaiea734962011-01-17 11:29:34 +0100514static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400515 "Digital Playback", "ADAT", "Analog Mux 1",
516 "Analog Mux 2", "Analog Mux 3"
517};
518
Takashi Iwai2b635362011-05-02 12:33:43 +0200519static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200520 0x12, 0x13
521};
522
Takashi Iwai2b635362011-05-02 12:33:43 +0200523static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200524 0x19, 0x1a
525};
526
Takashi Iwai2b635362011-05-02 12:33:43 +0200527static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100528 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100529};
530
Takashi Iwai2b635362011-05-02 12:33:43 +0200531static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200532 0x21,
533};
534
Takashi Iwaif6e98522007-10-16 14:27:04 +0200535#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200536static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200537 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200538};
539
Takashi Iwai6479c632009-07-28 18:20:25 +0200540#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200541static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200542 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
543 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
544};
Takashi Iwai2b635362011-05-02 12:33:43 +0200545static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200546 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
547 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
548};
549
Takashi Iwai2b635362011-05-02 12:33:43 +0200550static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200551 0x08, 0x09, 0x0d, 0x0e,
552 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200553};
554
Takashi Iwai2b635362011-05-02 12:33:43 +0200555static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100556 0x07, 0x08, 0x0a, 0x0b,
557 0x0c, 0x0d, 0x10, 0x11,
558};
559
Takashi Iwai2b635362011-05-02 12:33:43 +0200560static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200561 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
562 0x0f, 0x10, 0x11, 0x15, 0x1b,
563};
564
Takashi Iwai2b635362011-05-02 12:33:43 +0200565static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100566 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
567 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200568 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100569};
570
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500571#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200572static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500573 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
574 0x00, 0x14, 0x18, 0x19, 0x1e,
575 0x1f, 0x20, 0x27
576};
Takashi Iwai2b635362011-05-02 12:33:43 +0200577static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100578 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
579 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500580 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100581};
582
Takashi Iwai2b635362011-05-02 12:33:43 +0200583static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100584 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
585 0x0f, 0x10, 0x11, 0x12, 0x13,
586 0x14, 0x21, 0x22, 0x23,
587};
588
Takashi Iwai2b635362011-05-02 12:33:43 +0200589static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200590 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
591 0x0f, 0x14, 0x16, 0x17, 0x18,
592 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200593};
594
Matt Porter8b657272006-10-26 17:12:59 +0200595static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_info *uinfo)
597{
598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599 struct sigmatel_spec *spec = codec->spec;
600 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
601}
602
603static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
604 struct snd_ctl_elem_value *ucontrol)
605{
606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
607 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100608 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200609
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100610 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200611 return 0;
612}
613
614static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
616{
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100619 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200620
621 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100622 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200623}
624
Matthew Ranostayd9737752008-09-07 12:03:41 +0200625static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
626 struct snd_ctl_elem_info *uinfo)
627{
628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
629 struct sigmatel_spec *spec = codec->spec;
630 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
631}
632
633static int stac92xx_smux_enum_get(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;
638 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
639
640 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
641 return 0;
642}
643
644static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_value *ucontrol)
646{
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400649 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200650 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400651 int err, val;
652 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200653
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400654 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200655 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400656 if (err < 0)
657 return err;
658
659 if (spec->spdif_mute) {
660 if (smux_idx == 0)
661 nid = spec->multiout.dig_out_nid;
662 else
663 nid = codec->slave_dig_outs[smux_idx - 1];
664 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100665 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400666 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100667 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400668 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100669 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
670 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400671 }
672 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200673}
674
Wang Shaoyan96b63592011-08-10 16:01:04 +0800675#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500676static int stac_vrefout_set(struct hda_codec *codec,
677 hda_nid_t nid, unsigned int new_vref)
678{
679 int error, pinctl;
680
681 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
682 pinctl = snd_hda_codec_read(codec, nid, 0,
683 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
684
685 if (pinctl < 0)
686 return pinctl;
687
688 pinctl &= 0xff;
689 pinctl &= ~AC_PINCTL_VREFEN;
690 pinctl |= (new_vref & AC_PINCTL_VREFEN);
691
692 error = snd_hda_codec_write_cache(codec, nid, 0,
693 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
694 if (error < 0)
695 return error;
696
697 return 1;
698}
Wang Shaoyan96b63592011-08-10 16:01:04 +0800699#endif
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500700
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200701static unsigned int stac92xx_vref_set(struct hda_codec *codec,
702 hda_nid_t nid, unsigned int new_vref)
703{
Takashi Iwaib8621512009-06-22 08:00:10 +0200704 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200705 unsigned int pincfg;
706 pincfg = snd_hda_codec_read(codec, nid, 0,
707 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
708
709 pincfg &= 0xff;
710 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
711 pincfg |= new_vref;
712
713 if (new_vref == AC_PINCTL_VREF_HIZ)
714 pincfg |= AC_PINCTL_OUT_EN;
715 else
716 pincfg |= AC_PINCTL_IN_EN;
717
718 error = snd_hda_codec_write_cache(codec, nid, 0,
719 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
720 if (error < 0)
721 return error;
722 else
723 return 1;
724}
725
726static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
727{
728 unsigned int vref;
729 vref = snd_hda_codec_read(codec, nid, 0,
730 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
731 vref &= AC_PINCTL_VREFEN;
732 return vref;
733}
734
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100735static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200736{
737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200739 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200740}
741
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100742static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200743{
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 struct sigmatel_spec *spec = codec->spec;
746 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
747
748 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
749 return 0;
750}
751
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100752static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200753{
754 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
755 struct sigmatel_spec *spec = codec->spec;
756 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200757 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600758 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200759
Takashi Iwai5207e102009-07-30 13:09:08 +0200760 idx = ucontrol->value.enumerated.item[0];
761 if (idx >= imux->num_items)
762 idx = imux->num_items - 1;
763 prev_idx = spec->cur_mux[adc_idx];
764 if (prev_idx == idx)
765 return 0;
766 if (idx < spec->num_analog_muxes) {
767 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
768 AC_VERB_SET_CONNECT_SEL,
769 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600770 if (prev_idx >= spec->num_analog_muxes &&
771 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200772 imux = spec->dinput_mux;
773 /* 0 = analog */
774 snd_hda_codec_write_cache(codec,
775 spec->dmux_nids[adc_idx], 0,
776 AC_VERB_SET_CONNECT_SEL,
777 imux->items[0].index);
778 }
779 } else {
780 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600781 /* first dimux item is hardcoded to select analog imux,
782 * so lets skip it
783 */
784 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200785 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
786 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600787 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200788 }
789 spec->cur_mux[adc_idx] = idx;
790 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200791}
792
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100793static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_info *uinfo)
795{
796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
797 struct sigmatel_spec *spec = codec->spec;
798 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
799}
800
801static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_value *ucontrol)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct sigmatel_spec *spec = codec->spec;
806
807 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
808 return 0;
809}
810
811static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct sigmatel_spec *spec = codec->spec;
816
817 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
818 spec->mono_nid, &spec->cur_mmux);
819}
820
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200821#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
822
823static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825{
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100827 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200828 struct sigmatel_spec *spec = codec->spec;
829
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100830 ucontrol->value.integer.value[0] = !!(spec->aloopback &
831 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200832 return 0;
833}
834
835static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
836 struct snd_ctl_elem_value *ucontrol)
837{
838 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
839 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100840 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200841 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100842 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100844 idx_val = spec->aloopback_mask << idx;
845 if (ucontrol->value.integer.value[0])
846 val = spec->aloopback | idx_val;
847 else
848 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100849 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200850 return 0;
851
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100852 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200853
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100854 /* Only return the bits defined by the shift value of the
855 * first two bytes of the mask
856 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200857 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100858 kcontrol->private_value & 0xFFFF, 0x0);
859 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200860
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100861 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200862 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100863 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200864 } else {
865 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100866 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200867 }
868
869 snd_hda_codec_write_cache(codec, codec->afg, 0,
870 kcontrol->private_value >> 16, dac_mode);
871
872 return 1;
873}
874
Takashi Iwai2b635362011-05-02 12:33:43 +0200875static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200876 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200877 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200878 {}
879};
880
Takashi Iwai2b635362011-05-02 12:33:43 +0200881static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200882 /* set dac0mux for dac converter */
883 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
884 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
885 {}
886};
887
Takashi Iwai2b635362011-05-02 12:33:43 +0200888static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100889 /* set master volume to max value without distortion
890 * and direct control */
891 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100892 {}
893};
894
Takashi Iwai2b635362011-05-02 12:33:43 +0200895static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100896 /* set master volume and direct control */
897 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100898 {}
899};
900
Takashi Iwai2b635362011-05-02 12:33:43 +0200901static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200902 /* power state controls amps */
903 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200904 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200905};
906
Takashi Iwai2b635362011-05-02 12:33:43 +0200907static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100908 /* set master volume and direct control */
909 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200910 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100911};
912
Takashi Iwai2b635362011-05-02 12:33:43 +0200913static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500914 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
915 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100916 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
917 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100918 {}
919};
920
Takashi Iwai2b635362011-05-02 12:33:43 +0200921static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100922 /* set dac0mux for dac converter */
923 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100924 /* mute the master volume */
925 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100926 {}
927};
928
Takashi Iwai2b635362011-05-02 12:33:43 +0200929static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200930 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200931 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200932 {}
933};
934
Takashi Iwai2b635362011-05-02 12:33:43 +0200935static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200936 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200937 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200938 /* unmute node 0x1b */
939 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
940 /* select node 0x03 as DAC */
941 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
942 {}
943};
944
Takashi Iwai2b635362011-05-02 12:33:43 +0200945static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200946 /* don't set delta bit */
947 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
948 /* unmute node 0x1b */
949 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
950 /* select node 0x03 as DAC */
951 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
952 {}
953};
954
Takashi Iwai2b635362011-05-02 12:33:43 +0200955static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100956 /* set master volume and direct control */
957 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200958 /* enable analog pc beep path */
959 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100960 {}
961};
962
Takashi Iwai2b635362011-05-02 12:33:43 +0200963static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200964 /* don't set delta bit */
965 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
966 /* enable analog pc beep path */
967 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
968 {}
969};
970
Takashi Iwai2b635362011-05-02 12:33:43 +0200971static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200972 /* set master volume and direct control */
973 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200974 /* enable analog pc beep path */
975 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200976 {}
977};
978
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100979#define STAC_MONO_MUX \
980 { \
981 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
982 .name = "Mono Mux", \
983 .count = 1, \
984 .info = stac92xx_mono_mux_enum_info, \
985 .get = stac92xx_mono_mux_enum_get, \
986 .put = stac92xx_mono_mux_enum_put, \
987 }
988
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100989#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200990 { \
991 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
992 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100993 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200994 .info = stac92xx_aloopback_info, \
995 .get = stac92xx_aloopback_get, \
996 .put = stac92xx_aloopback_put, \
997 .private_value = verb_read | (verb_write << 16), \
998 }
999
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001000#define DC_BIAS(xname, idx, nid) \
1001 { \
1002 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1003 .name = xname, \
1004 .index = idx, \
1005 .info = stac92xx_dc_bias_info, \
1006 .get = stac92xx_dc_bias_get, \
1007 .put = stac92xx_dc_bias_put, \
1008 .private_value = nid, \
1009 }
1010
Takashi Iwai2b635362011-05-02 12:33:43 +02001011static const struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001012 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001013 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001014 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1015 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001016 { } /* end */
1017};
1018
Takashi Iwai2b635362011-05-02 12:33:43 +02001019static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001020 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1021 {}
1022};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001023
Takashi Iwai2b635362011-05-02 12:33:43 +02001024static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001025 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1026 {}
1027};
1028
Takashi Iwai2b635362011-05-02 12:33:43 +02001029static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001030 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1031 {}
1032};
1033
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001034
Takashi Iwai2b635362011-05-02 12:33:43 +02001035static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001036 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1037};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001038
Takashi Iwai2b635362011-05-02 12:33:43 +02001039static const struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001040 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001041 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001042 { } /* end */
1043};
1044
Takashi Iwai2b635362011-05-02 12:33:43 +02001045static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001046 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1047 {}
1048};
1049
Takashi Iwai2b635362011-05-02 12:33:43 +02001050static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001051 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1052 {}
1053};
1054
Takashi Iwai1697055e2007-12-18 18:05:52 +01001055static struct snd_kcontrol_new stac_dmux_mixer = {
1056 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1057 .name = "Digital Input Source",
1058 /* count set later */
1059 .info = stac92xx_dmux_enum_info,
1060 .get = stac92xx_dmux_enum_get,
1061 .put = stac92xx_dmux_enum_put,
1062};
1063
Matthew Ranostayd9737752008-09-07 12:03:41 +02001064static struct snd_kcontrol_new stac_smux_mixer = {
1065 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001066 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001067 /* count set later */
1068 .info = stac92xx_smux_enum_info,
1069 .get = stac92xx_smux_enum_get,
1070 .put = stac92xx_smux_enum_put,
1071};
1072
Takashi Iwaiea734962011-01-17 11:29:34 +01001073static const char * const slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001074 "Front Playback Volume",
1075 "Surround Playback Volume",
1076 "Center Playback Volume",
1077 "LFE Playback Volume",
1078 "Side Playback Volume",
1079 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001080 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001081 NULL
1082};
1083
Takashi Iwaiea734962011-01-17 11:29:34 +01001084static const char * const slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001085 "Front Playback Switch",
1086 "Surround Playback Switch",
1087 "Center Playback Switch",
1088 "LFE Playback Switch",
1089 "Side Playback Switch",
1090 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001091 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001092 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001093 NULL
1094};
1095
Takashi Iwai603c4012008-07-30 15:01:44 +02001096static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001097static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001098
Matt2f2f4252005-04-13 14:45:30 +02001099static int stac92xx_build_controls(struct hda_codec *codec)
1100{
1101 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001102 struct auto_pin_cfg *cfg = &spec->autocfg;
1103 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001104 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001105 int i;
Matt2f2f4252005-04-13 14:45:30 +02001106
Takashi Iwai6479c632009-07-28 18:20:25 +02001107 if (spec->mixer) {
1108 err = snd_hda_add_new_ctls(codec, spec->mixer);
1109 if (err < 0)
1110 return err;
1111 }
Mattc7d4b2f2005-06-27 14:59:41 +02001112
1113 for (i = 0; i < spec->num_mixers; i++) {
1114 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1115 if (err < 0)
1116 return err;
1117 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001118 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1119 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001120 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001121 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001122 snd_ctl_new1(&stac_dmux_mixer, codec));
1123 if (err < 0)
1124 return err;
1125 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001126 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001127 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1128 struct hda_input_mux *smux = &spec->private_smux;
1129 /* check for mute support on SPDIF out */
1130 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001131 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001132 spec->spdif_mute = 1;
1133 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001134 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001135 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001136 snd_ctl_new1(&stac_smux_mixer, codec));
1137 if (err < 0)
1138 return err;
1139 }
Mattc7d4b2f2005-06-27 14:59:41 +02001140
Mattdabbed62005-06-14 10:19:34 +02001141 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -06001142 err = snd_hda_create_spdif_out_ctls(codec,
1143 spec->multiout.dig_out_nid,
1144 spec->multiout.dig_out_nid);
Mattdabbed62005-06-14 10:19:34 +02001145 if (err < 0)
1146 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001147 err = snd_hda_create_spdif_share_sw(codec,
1148 &spec->multiout);
1149 if (err < 0)
1150 return err;
1151 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001152 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001153 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001154 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1155 if (err < 0)
1156 return err;
1157 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001158
1159 /* if we have no master control, let's create it */
1160 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001161 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001162 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001163 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001164 /* correct volume offset */
1165 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001166 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001167 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001168 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001169 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001170 if (err < 0)
1171 return err;
1172 }
1173 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1174 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1175 NULL, slave_sws);
1176 if (err < 0)
1177 return err;
1178 }
1179
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001180 if (spec->aloopback_ctl &&
1181 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1182 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1183 if (err < 0)
1184 return err;
1185 }
1186
Takashi Iwai603c4012008-07-30 15:01:44 +02001187 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001188
1189 /* create jack input elements */
1190 if (spec->hp_detect) {
1191 for (i = 0; i < cfg->hp_outs; i++) {
1192 int type = SND_JACK_HEADPHONE;
1193 nid = cfg->hp_pins[i];
1194 /* jack detection */
1195 if (cfg->hp_outs == i)
1196 type |= SND_JACK_LINEOUT;
1197 err = stac92xx_add_jack(codec, nid, type);
1198 if (err < 0)
1199 return err;
1200 }
1201 }
1202 for (i = 0; i < cfg->line_outs; i++) {
1203 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1204 SND_JACK_LINEOUT);
1205 if (err < 0)
1206 return err;
1207 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001208 for (i = 0; i < cfg->num_inputs; i++) {
1209 nid = cfg->inputs[i].pin;
1210 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1211 if (err < 0)
1212 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001213 }
1214
Mattdabbed62005-06-14 10:19:34 +02001215 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001216}
1217
Takashi Iwai2b635362011-05-02 12:33:43 +02001218static const unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001219 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001220 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1221};
1222
Takashi Iwai2b635362011-05-02 12:33:43 +02001223static const unsigned int gateway9200_m4_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001224 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1225 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1226};
Takashi Iwai2b635362011-05-02 12:33:43 +02001227static const unsigned int gateway9200_m4_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001228 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1229 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1230};
1231
1232/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001233 STAC 9200 pin configs for
1234 102801A8
1235 102801DE
1236 102801E8
1237*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001238static const unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001239 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1240 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001241};
1242
1243/*
1244 STAC 9200 pin configs for
1245 102801C0
1246 102801C1
1247*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001248static const unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001249 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1250 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001251};
1252
1253/*
1254 STAC 9200 pin configs for
1255 102801C4 (Dell Dimension E310)
1256 102801C5
1257 102801C7
1258 102801D9
1259 102801DA
1260 102801E3
1261*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001262static const unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001263 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1264 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001265};
1266
1267
1268/*
1269 STAC 9200-32 pin configs for
1270 102801B5 (Dell Inspiron 630m)
1271 102801D8 (Dell Inspiron 640m)
1272*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001273static const unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001274 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1275 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001276};
1277
1278/*
1279 STAC 9200-32 pin configs for
1280 102801C2 (Dell Latitude D620)
1281 102801C8
1282 102801CC (Dell Latitude D820)
1283 102801D4
1284 102801D6
1285*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001286static const unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001287 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1288 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001289};
1290
1291/*
1292 STAC 9200-32 pin configs for
1293 102801CE (Dell XPS M1710)
1294 102801CF (Dell Precision M90)
1295*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001296static const unsigned int dell9200_m23_pin_configs[8] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001297 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1298 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1299};
1300
1301/*
1302 STAC 9200-32 pin configs for
1303 102801C9
1304 102801CA
1305 102801CB (Dell Latitude 120L)
1306 102801D3
1307*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001308static const unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001309 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1310 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001311};
1312
1313/*
1314 STAC 9200-32 pin configs for
1315 102801BD (Dell Inspiron E1505n)
1316 102801EE
1317 102801EF
1318*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001319static const unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001320 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1321 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001322};
1323
1324/*
1325 STAC 9200-32 pin configs for
1326 102801F5 (Dell Inspiron 1501)
1327 102801F6
1328*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001329static const unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001330 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1331 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001332};
1333
1334/*
1335 STAC 9200-32
1336 102801CD (Dell Inspiron E1705/9400)
1337*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001338static const unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001339 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1340 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001341};
1342
Takashi Iwai2b635362011-05-02 12:33:43 +02001343static const unsigned int oqo9200_pin_configs[8] = {
Tobin Davisbf277782008-02-03 20:31:47 +01001344 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1345 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1346};
1347
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001348
Takashi Iwai2b635362011-05-02 12:33:43 +02001349static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001350 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001351 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001352 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1353 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1354 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1355 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1356 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1357 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1358 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1359 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1360 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1361 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001362 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1363 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001364 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001365};
1366
Takashi Iwaiea734962011-01-17 11:29:34 +01001367static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001368 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001369 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001370 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001371 [STAC_9200_DELL_D21] = "dell-d21",
1372 [STAC_9200_DELL_D22] = "dell-d22",
1373 [STAC_9200_DELL_D23] = "dell-d23",
1374 [STAC_9200_DELL_M21] = "dell-m21",
1375 [STAC_9200_DELL_M22] = "dell-m22",
1376 [STAC_9200_DELL_M23] = "dell-m23",
1377 [STAC_9200_DELL_M24] = "dell-m24",
1378 [STAC_9200_DELL_M25] = "dell-m25",
1379 [STAC_9200_DELL_M26] = "dell-m26",
1380 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001381 [STAC_9200_M4] = "gateway-m4",
1382 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001383 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001384};
1385
Takashi Iwai2b635362011-05-02 12:33:43 +02001386static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001387 /* SigmaTel reference board */
1388 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1389 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001390 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1391 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001392 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1394 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001396 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1398 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1400 "unknown Dell", STAC_9200_DELL_D22),
1401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1402 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001403 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001404 "Dell Latitude D620", STAC_9200_DELL_M22),
1405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1406 "unknown Dell", STAC_9200_DELL_D23),
1407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1408 "unknown Dell", STAC_9200_DELL_D23),
1409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1410 "unknown Dell", STAC_9200_DELL_M22),
1411 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1412 "unknown Dell", STAC_9200_DELL_M24),
1413 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1414 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001415 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001416 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001417 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001418 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001419 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001420 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001421 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001422 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001423 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001424 "Dell Precision M90", STAC_9200_DELL_M23),
1425 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1426 "unknown Dell", STAC_9200_DELL_M22),
1427 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1428 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001429 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001430 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001431 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001432 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1433 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1434 "unknown Dell", STAC_9200_DELL_D23),
1435 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1436 "unknown Dell", STAC_9200_DELL_D23),
1437 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1438 "unknown Dell", STAC_9200_DELL_D21),
1439 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1440 "unknown Dell", STAC_9200_DELL_D23),
1441 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1442 "unknown Dell", STAC_9200_DELL_D21),
1443 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1444 "unknown Dell", STAC_9200_DELL_M25),
1445 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1446 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001447 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001448 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1449 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1450 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001451 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001452 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001453 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001454 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1455 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1456 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001457 /* OQO Mobile */
1458 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001459 {} /* terminator */
1460};
1461
Takashi Iwai2b635362011-05-02 12:33:43 +02001462static const unsigned int ref925x_pin_configs[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001463 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001464 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001465};
1466
Takashi Iwai2b635362011-05-02 12:33:43 +02001467static const unsigned int stac925xM1_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001468 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1469 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001470};
1471
Takashi Iwai2b635362011-05-02 12:33:43 +02001472static const unsigned int stac925xM1_2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001473 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1474 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1475};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001476
Takashi Iwai2b635362011-05-02 12:33:43 +02001477static const unsigned int stac925xM2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001478 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1479 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001480};
1481
Takashi Iwai2b635362011-05-02 12:33:43 +02001482static const unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001483 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1484 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1485};
1486
Takashi Iwai2b635362011-05-02 12:33:43 +02001487static const unsigned int stac925xM3_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001488 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1489 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1490};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001491
Takashi Iwai2b635362011-05-02 12:33:43 +02001492static const unsigned int stac925xM5_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001493 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1494 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1495};
1496
Takashi Iwai2b635362011-05-02 12:33:43 +02001497static const unsigned int stac925xM6_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001498 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1499 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001500};
1501
Takashi Iwai2b635362011-05-02 12:33:43 +02001502static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001503 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001504 [STAC_M1] = stac925xM1_pin_configs,
1505 [STAC_M1_2] = stac925xM1_2_pin_configs,
1506 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001507 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001508 [STAC_M3] = stac925xM3_pin_configs,
1509 [STAC_M5] = stac925xM5_pin_configs,
1510 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001511};
1512
Takashi Iwaiea734962011-01-17 11:29:34 +01001513static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001514 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001515 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001516 [STAC_M1] = "m1",
1517 [STAC_M1_2] = "m1-2",
1518 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001519 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001520 [STAC_M3] = "m3",
1521 [STAC_M5] = "m5",
1522 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001523};
1524
Takashi Iwai2b635362011-05-02 12:33:43 +02001525static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001526 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1527 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1528 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1529 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001530 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001531 /* Not sure about the brand name for those */
1532 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1533 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1534 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1535 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001536 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001537};
1538
Takashi Iwai2b635362011-05-02 12:33:43 +02001539static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001540 /* SigmaTel reference board */
1541 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001542 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001543 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001544
1545 /* Default table for unknown ID */
1546 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1547
Tobin Davis8e21c342007-01-08 11:04:17 +01001548 {} /* terminator */
1549};
1550
Takashi Iwai2b635362011-05-02 12:33:43 +02001551static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001552 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1553 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1554 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001555 0x01452050,
1556};
1557
Takashi Iwai2b635362011-05-02 12:33:43 +02001558static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001559 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001560 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001561 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1562 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001563};
1564
Takashi Iwai2b635362011-05-02 12:33:43 +02001565static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001566 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1567 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1568 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1569 0x904601b0,
1570};
1571
Takashi Iwai2b635362011-05-02 12:33:43 +02001572static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001573 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001574 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001575};
1576
Takashi Iwai2b635362011-05-02 12:33:43 +02001577static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001578 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001579 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1580 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1581 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001582 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001583 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001584 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001585};
1586
Takashi Iwaiea734962011-01-17 11:29:34 +01001587static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001588 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001589 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001590 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001591 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001592 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1593 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1594 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001595 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001596 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001597};
1598
Takashi Iwai2b635362011-05-02 12:33:43 +02001599static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001600 /* SigmaTel reference board */
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001602 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001603 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1604 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1606 "Intel DG45ID", STAC_92HD73XX_INTEL),
1607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1608 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001610 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001612 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001614 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001616 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001618 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001619 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001620 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001622 "unknown Dell", STAC_DELL_M6_DMIC),
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1624 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001626 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1628 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1630 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1632 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1634 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001636 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001637 {} /* terminator */
1638};
1639
Takashi Iwai2b635362011-05-02 12:33:43 +02001640static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001641 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1642 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1644 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwaidbd1b542011-11-19 11:41:30 +01001645 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
1646 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwai842ae632009-09-02 07:43:08 +02001647 {} /* terminator */
1648};
1649
Takashi Iwai2b635362011-05-02 12:33:43 +02001650static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001651 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1652 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001653 0x01451160, 0x98560170,
1654};
1655
Takashi Iwai2b635362011-05-02 12:33:43 +02001656static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001657 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1658 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001659 0x40f000f0, 0x40f000f0,
1660};
1661
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001662static const unsigned int dell_vostro_3500_pin_configs[10] = {
1663 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1664 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1665 0x400000f4, 0x400000f5,
1666};
1667
Takashi Iwai2b635362011-05-02 12:33:43 +02001668static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001669 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1670 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1671 0x40f000f0, 0x40f000f0,
1672};
1673
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001674static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1675 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1676 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1677 0x40f000f0, 0x40f000f0,
1678};
1679
Takashi Iwai2b635362011-05-02 12:33:43 +02001680static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001681 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001682 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001683 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001684 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001685 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001686 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001687};
1688
Takashi Iwaiea734962011-01-17 11:29:34 +01001689static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001690 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001691 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001692 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001693 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001694 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001695 [STAC_92HD83XXX_HP] = "hp",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001696 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001697 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001698};
1699
Takashi Iwai2b635362011-05-02 12:33:43 +02001700static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001701 /* SigmaTel reference board */
1702 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001703 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001704 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1705 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001706 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1707 "unknown Dell", STAC_DELL_S14),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001708 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1709 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001710 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001711 "HP", STAC_92HD83XXX_HP),
1712 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1713 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1714 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1715 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1717 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1718 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1719 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1720 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1721 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1722 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1723 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1724 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1725 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1726 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1727 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1728 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1729 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1730 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1731 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1733 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1735 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1736 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1737 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1739 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1740 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1741 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1742 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1743 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1744 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1745 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1746 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1747 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1748 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1749 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1750 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1751 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001752 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001753};
1754
Takashi Iwai2b635362011-05-02 12:33:43 +02001755static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001756 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001757 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001758 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1759 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001760};
1761
Takashi Iwai2b635362011-05-02 12:33:43 +02001762static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001763 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001764 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001765 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1766 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001767};
1768
Takashi Iwai2b635362011-05-02 12:33:43 +02001769static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001770 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1771 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001772 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1773 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001774};
1775
Takashi Iwai2b635362011-05-02 12:33:43 +02001776static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001777 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1778 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001779 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1780 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001781};
1782
Takashi Iwai2b635362011-05-02 12:33:43 +02001783static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001784 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001785 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1786 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001787 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001788 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001789 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001790 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001791 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001792 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001793};
1794
Takashi Iwaiea734962011-01-17 11:29:34 +01001795static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001796 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001797 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001798 [STAC_DELL_M4_1] = "dell-m4-1",
1799 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001800 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001801 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001802 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001803 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001804 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001805 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001806};
1807
Takashi Iwai2b635362011-05-02 12:33:43 +02001808static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001809 /* SigmaTel reference board */
1810 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1811 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001812 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1813 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001814 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1815 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001816 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1817 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001818 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1819 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001820 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001821 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001822 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1823 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001824 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1825 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001826 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001827 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001828 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001829 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001830 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1831 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301832 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1833 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001834 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1835 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001836 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1837 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001838 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1839 "unknown Dell", STAC_DELL_M4_1),
1840 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1841 "unknown Dell", STAC_DELL_M4_1),
1842 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1843 "unknown Dell", STAC_DELL_M4_1),
1844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1845 "unknown Dell", STAC_DELL_M4_1),
1846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1847 "unknown Dell", STAC_DELL_M4_1),
1848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1849 "unknown Dell", STAC_DELL_M4_1),
1850 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1851 "unknown Dell", STAC_DELL_M4_1),
1852 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1853 "unknown Dell", STAC_DELL_M4_2),
1854 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1855 "unknown Dell", STAC_DELL_M4_2),
1856 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1857 "unknown Dell", STAC_DELL_M4_2),
1858 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1859 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001860 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1861 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001862 {} /* terminator */
1863};
1864
Takashi Iwai2b635362011-05-02 12:33:43 +02001865static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01001866 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1867 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001868 0x40000100, 0x40000100,
1869};
1870
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001871/*
1872 STAC 922X pin configs for
1873 102801A7
1874 102801AB
1875 102801A9
1876 102801D1
1877 102801D2
1878*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001879static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001880 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1881 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1882 0x01813122, 0x400001f2,
1883};
1884
1885/*
1886 STAC 922X pin configs for
1887 102801AC
1888 102801D0
1889*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001890static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001891 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1892 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1893 0x01813122, 0x400001f1,
1894};
1895
1896/*
1897 STAC 922X pin configs for
1898 102801BF
1899*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001900static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001901 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1902 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1903 0x40C003f1, 0x405003f0,
1904};
1905
1906/*
1907 STAC 9221 A1 pin configs for
1908 102801D7 (Dell XPS M1210)
1909*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001910static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001911 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1912 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001913 0x508003f3, 0x405003f4,
1914};
1915
Takashi Iwai2b635362011-05-02 12:33:43 +02001916static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001917 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001918 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1919 0x02a19120, 0x40000100,
1920};
1921
Takashi Iwai2b635362011-05-02 12:33:43 +02001922static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001923 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1924 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001925 0x02a19320, 0x40000100,
1926};
1927
Takashi Iwai2b635362011-05-02 12:33:43 +02001928static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001929 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1930 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001931 0x400000fc, 0x400000fb,
1932};
1933
Takashi Iwai2b635362011-05-02 12:33:43 +02001934static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001935 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1936 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001937 0x400000fc, 0x400000fb,
1938};
1939
Takashi Iwai2b635362011-05-02 12:33:43 +02001940static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001941 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1942 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1943 0x400000fc, 0x400000fb,
1944};
1945
Takashi Iwai2b635362011-05-02 12:33:43 +02001946static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001947 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1948 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1949 0x400000fc, 0x400000fb,
1950};
1951
Takashi Iwai2b635362011-05-02 12:33:43 +02001952static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001953 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1954 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1955 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001956};
1957
Takashi Iwai2b635362011-05-02 12:33:43 +02001958static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001959 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1960 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1961 0x9037012e, 0x40e000f2,
1962};
Takashi Iwai76c08822007-06-19 12:17:42 +02001963
Takashi Iwai2b635362011-05-02 12:33:43 +02001964static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001965 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001966 [STAC_D945GTP3] = d945gtp3_pin_configs,
1967 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001968 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1969 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1970 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1971 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1972 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001973 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001974 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001975 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1976 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1977 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1978 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1979 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1980 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001981 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001982 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1983 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1984 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1985 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001986};
1987
Takashi Iwaiea734962011-01-17 11:29:34 +01001988static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001989 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001990 [STAC_D945_REF] = "ref",
1991 [STAC_D945GTP5] = "5stack",
1992 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001993 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1994 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1995 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1996 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1997 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001998 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001999 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002000 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002001 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002002 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2003 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002004 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002005 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002006 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002007 [STAC_922X_DELL_D81] = "dell-d81",
2008 [STAC_922X_DELL_D82] = "dell-d82",
2009 [STAC_922X_DELL_M81] = "dell-m81",
2010 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002011};
2012
Takashi Iwai2b635362011-05-02 12:33:43 +02002013static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002014 /* SigmaTel reference board */
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2016 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002017 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2018 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002019 /* Intel 945G based systems */
2020 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2021 "Intel D945G", STAC_D945GTP3),
2022 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2023 "Intel D945G", STAC_D945GTP3),
2024 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2025 "Intel D945G", STAC_D945GTP3),
2026 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2027 "Intel D945G", STAC_D945GTP3),
2028 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2029 "Intel D945G", STAC_D945GTP3),
2030 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2031 "Intel D945G", STAC_D945GTP3),
2032 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2033 "Intel D945G", STAC_D945GTP3),
2034 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2035 "Intel D945G", STAC_D945GTP3),
2036 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2037 "Intel D945G", STAC_D945GTP3),
2038 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2039 "Intel D945G", STAC_D945GTP3),
2040 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2041 "Intel D945G", STAC_D945GTP3),
2042 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2043 "Intel D945G", STAC_D945GTP3),
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2045 "Intel D945G", STAC_D945GTP3),
2046 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2047 "Intel D945G", STAC_D945GTP3),
2048 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2049 "Intel D945G", STAC_D945GTP3),
2050 /* Intel D945G 5-stack systems */
2051 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2052 "Intel D945G", STAC_D945GTP5),
2053 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2054 "Intel D945G", STAC_D945GTP5),
2055 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2056 "Intel D945G", STAC_D945GTP5),
2057 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2058 "Intel D945G", STAC_D945GTP5),
2059 /* Intel 945P based systems */
2060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2061 "Intel D945P", STAC_D945GTP3),
2062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2063 "Intel D945P", STAC_D945GTP3),
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2065 "Intel D945P", STAC_D945GTP3),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2067 "Intel D945P", STAC_D945GTP3),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2069 "Intel D945P", STAC_D945GTP3),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2071 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002072 /* other intel */
2073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2074 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002075 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002076 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002077 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002078 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002079 /* Dell systems */
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2081 "unknown Dell", STAC_922X_DELL_D81),
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2083 "unknown Dell", STAC_922X_DELL_D81),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2085 "unknown Dell", STAC_922X_DELL_D81),
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2087 "unknown Dell", STAC_922X_DELL_D82),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2089 "unknown Dell", STAC_922X_DELL_M81),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2091 "unknown Dell", STAC_922X_DELL_D82),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2093 "unknown Dell", STAC_922X_DELL_D81),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2095 "unknown Dell", STAC_922X_DELL_D81),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2097 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002098 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002099 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002100 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002101 {} /* terminator */
2102};
2103
Takashi Iwai2b635362011-05-02 12:33:43 +02002104static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002105 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2106 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2107 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2108 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002109};
2110
Takashi Iwai2b635362011-05-02 12:33:43 +02002111static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002112 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2113 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2114 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2115 0x40000100, 0x40000100
2116};
2117
Takashi Iwai2b635362011-05-02 12:33:43 +02002118static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002119 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2120 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2121 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2122 0x40000100, 0x40000100
2123};
2124
Takashi Iwai2b635362011-05-02 12:33:43 +02002125static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002126 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2127 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2128 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2129 0x40000100, 0x40000100
2130};
2131
Takashi Iwai2b635362011-05-02 12:33:43 +02002132static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002133 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2134 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002135 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002136 0x40c003fc, 0x40000100
2137};
2138
Takashi Iwai2b635362011-05-02 12:33:43 +02002139static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002140 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002141 [STAC_D965_REF] = ref927x_pin_configs,
2142 [STAC_D965_3ST] = d965_3st_pin_configs,
2143 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002144 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002145 [STAC_DELL_3ST] = dell_3st_pin_configs,
2146 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002147 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002148};
2149
Takashi Iwaiea734962011-01-17 11:29:34 +01002150static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002151 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002152 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002153 [STAC_D965_REF] = "ref",
2154 [STAC_D965_3ST] = "3stack",
2155 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002156 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002157 [STAC_DELL_3ST] = "dell-3stack",
2158 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002159 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002160};
2161
Takashi Iwai2b635362011-05-02 12:33:43 +02002162static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002163 /* SigmaTel reference board */
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2165 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002166 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2167 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002168 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002171 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002172 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2173 "Intel D965", STAC_D965_3ST),
2174 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2175 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002176 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002180 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002190 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002191 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2192 "Intel D965", STAC_D965_5ST),
2193 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2194 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002195 /* volume-knob fixes */
2196 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002197 {} /* terminator */
2198};
2199
Takashi Iwai2b635362011-05-02 12:33:43 +02002200static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002201 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002202 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002203 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002204};
2205
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002206/*
2207 STAC 9205 pin configs for
2208 102801F1
2209 102801F2
2210 102801FC
2211 102801FD
2212 10280204
2213 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002214 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002215 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002216*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002217static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002218 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2219 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2220 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2221};
2222
2223/*
2224 STAC 9205 pin configs for
2225 102801F9
2226 102801FA
2227 102801FE
2228 102801FF (Dell Precision M4300)
2229 10280206
2230 10280200
2231 10280201
2232*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002233static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002234 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2235 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2236 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2237};
2238
Takashi Iwai2b635362011-05-02 12:33:43 +02002239static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002240 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2241 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2242 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2243};
2244
Takashi Iwai2b635362011-05-02 12:33:43 +02002245static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002246 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002247 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2248 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2249 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002250 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002251};
2252
Takashi Iwaiea734962011-01-17 11:29:34 +01002253static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002254 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002255 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002256 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002257 [STAC_9205_DELL_M43] = "dell-m43",
2258 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002259 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002260};
2261
Takashi Iwai2b635362011-05-02 12:33:43 +02002262static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002263 /* SigmaTel reference board */
2264 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2265 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002266 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2267 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002268 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2269 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002270 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002271 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2272 "unknown Dell", STAC_9205_DELL_M42),
2273 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2274 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002275 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002276 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002277 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2278 "Dell Precision", STAC_9205_DELL_M43),
2279 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2280 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002281 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2282 "unknown Dell", STAC_9205_DELL_M42),
2283 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2284 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002285 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2286 "Dell Precision", STAC_9205_DELL_M43),
2287 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002288 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002289 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2290 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002291 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2292 "Dell Precision", STAC_9205_DELL_M43),
2293 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2294 "Dell Precision", STAC_9205_DELL_M43),
2295 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2296 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2298 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2300 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2302 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002303 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002304 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002305 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002306 {} /* terminator */
2307};
2308
Takashi Iwai330ee992009-02-20 14:33:36 +01002309static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002310 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002311{
2312 int i;
2313 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002314
Takashi Iwai330ee992009-02-20 14:33:36 +01002315 if (!pincfgs)
2316 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002317
Matthew Ranostay87d48362007-07-17 11:52:24 +02002318 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002319 if (spec->pin_nids[i] && pincfgs[i])
2320 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2321 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002322}
2323
Matt2f2f4252005-04-13 14:45:30 +02002324/*
2325 * Analog playback callbacks
2326 */
2327static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2328 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002329 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002330{
2331 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002332 if (spec->stream_delay)
2333 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002334 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2335 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002336}
2337
2338static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2339 struct hda_codec *codec,
2340 unsigned int stream_tag,
2341 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002342 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002343{
2344 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002345 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002346}
2347
2348static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2349 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002350 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002351{
2352 struct sigmatel_spec *spec = codec->spec;
2353 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2354}
2355
2356/*
Mattdabbed62005-06-14 10:19:34 +02002357 * Digital playback callbacks
2358 */
2359static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2360 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002361 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002362{
2363 struct sigmatel_spec *spec = codec->spec;
2364 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2365}
2366
2367static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2368 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002369 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002370{
2371 struct sigmatel_spec *spec = codec->spec;
2372 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2373}
2374
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002375static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2376 struct hda_codec *codec,
2377 unsigned int stream_tag,
2378 unsigned int format,
2379 struct snd_pcm_substream *substream)
2380{
2381 struct sigmatel_spec *spec = codec->spec;
2382 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2383 stream_tag, format, substream);
2384}
2385
Takashi Iwai9411e212009-02-13 11:32:28 +01002386static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2387 struct hda_codec *codec,
2388 struct snd_pcm_substream *substream)
2389{
2390 struct sigmatel_spec *spec = codec->spec;
2391 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2392}
2393
Mattdabbed62005-06-14 10:19:34 +02002394
2395/*
Matt2f2f4252005-04-13 14:45:30 +02002396 * Analog capture callbacks
2397 */
2398static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2399 struct hda_codec *codec,
2400 unsigned int stream_tag,
2401 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002402 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002403{
2404 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002405 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002406
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002407 if (spec->powerdown_adcs) {
2408 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002409 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002410 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2411 }
2412 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002413 return 0;
2414}
2415
2416static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2417 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002418 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002419{
2420 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002421 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002422
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002423 snd_hda_codec_cleanup_stream(codec, nid);
2424 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002425 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002426 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002427 return 0;
2428}
2429
Takashi Iwai2b635362011-05-02 12:33:43 +02002430static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002431 .substreams = 1,
2432 .channels_min = 2,
2433 .channels_max = 2,
2434 /* NID is set in stac92xx_build_pcms */
2435 .ops = {
2436 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002437 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002438 .prepare = stac92xx_dig_playback_pcm_prepare,
2439 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002440 },
2441};
2442
Takashi Iwai2b635362011-05-02 12:33:43 +02002443static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002444 .substreams = 1,
2445 .channels_min = 2,
2446 .channels_max = 2,
2447 /* NID is set in stac92xx_build_pcms */
2448};
2449
Takashi Iwai2b635362011-05-02 12:33:43 +02002450static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002451 .substreams = 1,
2452 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002453 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002454 .nid = 0x02, /* NID to query formats and rates */
2455 .ops = {
2456 .open = stac92xx_playback_pcm_open,
2457 .prepare = stac92xx_playback_pcm_prepare,
2458 .cleanup = stac92xx_playback_pcm_cleanup
2459 },
2460};
2461
Takashi Iwai2b635362011-05-02 12:33:43 +02002462static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002463 .substreams = 1,
2464 .channels_min = 2,
2465 .channels_max = 2,
2466 .nid = 0x06, /* NID to query formats and rates */
2467 .ops = {
2468 .open = stac92xx_playback_pcm_open,
2469 .prepare = stac92xx_playback_pcm_prepare,
2470 .cleanup = stac92xx_playback_pcm_cleanup
2471 },
2472};
2473
Takashi Iwai2b635362011-05-02 12:33:43 +02002474static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002475 .channels_min = 2,
2476 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002477 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002478 .ops = {
2479 .prepare = stac92xx_capture_pcm_prepare,
2480 .cleanup = stac92xx_capture_pcm_cleanup
2481 },
2482};
2483
2484static int stac92xx_build_pcms(struct hda_codec *codec)
2485{
2486 struct sigmatel_spec *spec = codec->spec;
2487 struct hda_pcm *info = spec->pcm_rec;
2488
2489 codec->num_pcms = 1;
2490 codec->pcm_info = info;
2491
Mattc7d4b2f2005-06-27 14:59:41 +02002492 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002493 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002494 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2495 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002496 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002497 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002498 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002499
2500 if (spec->alt_switch) {
2501 codec->num_pcms++;
2502 info++;
2503 info->name = "STAC92xx Analog Alt";
2504 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2505 }
Matt2f2f4252005-04-13 14:45:30 +02002506
Mattdabbed62005-06-14 10:19:34 +02002507 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2508 codec->num_pcms++;
2509 info++;
2510 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002511 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002512 if (spec->multiout.dig_out_nid) {
2513 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2514 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2515 }
2516 if (spec->dig_in_nid) {
2517 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2518 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2519 }
2520 }
2521
Matt2f2f4252005-04-13 14:45:30 +02002522 return 0;
2523}
2524
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002525static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2526 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002527{
Takashi Iwai1327a322009-03-23 13:07:47 +01002528 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002529 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2530 if (pincap & AC_PINCAP_VREF_100)
2531 return AC_PINCTL_VREF_100;
2532 if (pincap & AC_PINCAP_VREF_80)
2533 return AC_PINCTL_VREF_80;
2534 if (pincap & AC_PINCAP_VREF_50)
2535 return AC_PINCTL_VREF_50;
2536 if (pincap & AC_PINCAP_VREF_GRD)
2537 return AC_PINCTL_VREF_GRD;
2538 return 0;
2539}
2540
Matt Porter403d1942005-11-29 15:00:51 +01002541static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2542
2543{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002544 snd_hda_codec_write_cache(codec, nid, 0,
2545 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002546}
2547
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002548#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2549
2550static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2551 struct snd_ctl_elem_value *ucontrol)
2552{
2553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2554 struct sigmatel_spec *spec = codec->spec;
2555
Takashi Iwaid7a89432008-11-12 09:48:04 +01002556 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002557 return 0;
2558}
2559
Takashi Iwai62558ce2009-07-29 14:23:09 +02002560static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002561
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002562static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2563 struct snd_ctl_elem_value *ucontrol)
2564{
2565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2566 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002567 int nid = kcontrol->private_value;
2568
2569 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002570
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002571 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002572 * switch changes
2573 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002574 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002575
2576 return 1;
2577}
2578
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002579static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2580 struct snd_ctl_elem_info *uinfo)
2581{
2582 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002583 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002584 "Mic In", "Line In", "Line Out"
2585 };
2586
2587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2588 struct sigmatel_spec *spec = codec->spec;
2589 hda_nid_t nid = kcontrol->private_value;
2590
2591 if (nid == spec->mic_switch || nid == spec->line_switch)
2592 i = 3;
2593 else
2594 i = 2;
2595
2596 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2597 uinfo->value.enumerated.items = i;
2598 uinfo->count = 1;
2599 if (uinfo->value.enumerated.item >= i)
2600 uinfo->value.enumerated.item = i-1;
2601 strcpy(uinfo->value.enumerated.name,
2602 texts[uinfo->value.enumerated.item]);
2603
2604 return 0;
2605}
2606
2607static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2608 struct snd_ctl_elem_value *ucontrol)
2609{
2610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2611 hda_nid_t nid = kcontrol->private_value;
2612 unsigned int vref = stac92xx_vref_get(codec, nid);
2613
2614 if (vref == stac92xx_get_default_vref(codec, nid))
2615 ucontrol->value.enumerated.item[0] = 0;
2616 else if (vref == AC_PINCTL_VREF_GRD)
2617 ucontrol->value.enumerated.item[0] = 1;
2618 else if (vref == AC_PINCTL_VREF_HIZ)
2619 ucontrol->value.enumerated.item[0] = 2;
2620
2621 return 0;
2622}
2623
2624static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2625 struct snd_ctl_elem_value *ucontrol)
2626{
2627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2628 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002629 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002630 hda_nid_t nid = kcontrol->private_value;
2631
2632 if (ucontrol->value.enumerated.item[0] == 0)
2633 new_vref = stac92xx_get_default_vref(codec, nid);
2634 else if (ucontrol->value.enumerated.item[0] == 1)
2635 new_vref = AC_PINCTL_VREF_GRD;
2636 else if (ucontrol->value.enumerated.item[0] == 2)
2637 new_vref = AC_PINCTL_VREF_HIZ;
2638 else
2639 return 0;
2640
2641 if (new_vref != stac92xx_vref_get(codec, nid)) {
2642 error = stac92xx_vref_set(codec, nid, new_vref);
2643 return error;
2644 }
2645
2646 return 0;
2647}
2648
2649static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2650 struct snd_ctl_elem_info *uinfo)
2651{
Takashi Iwai2b635362011-05-02 12:33:43 +02002652 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2654 struct sigmatel_spec *spec = codec->spec;
2655
2656 if (kcontrol->private_value == spec->line_switch)
2657 texts[0] = "Line In";
2658 else
2659 texts[0] = "Mic In";
2660 texts[1] = "Line Out";
2661 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2662 uinfo->value.enumerated.items = 2;
2663 uinfo->count = 1;
2664
2665 if (uinfo->value.enumerated.item >= 2)
2666 uinfo->value.enumerated.item = 1;
2667 strcpy(uinfo->value.enumerated.name,
2668 texts[uinfo->value.enumerated.item]);
2669
2670 return 0;
2671}
Matt Porter403d1942005-11-29 15:00:51 +01002672
2673static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2674{
2675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2676 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002677 hda_nid_t nid = kcontrol->private_value;
2678 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002679
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002680 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002681 return 0;
2682}
2683
2684static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2685{
2686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2687 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002688 hda_nid_t nid = kcontrol->private_value;
2689 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2690 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002691
2692 spec->io_switch[io_idx] = val;
2693
2694 if (val)
2695 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002696 else {
2697 unsigned int pinctl = AC_PINCTL_IN_EN;
2698 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002699 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002700 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2701 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002702
2703 /* check the auto-mute again: we need to mute/unmute the speaker
2704 * appropriately according to the pin direction
2705 */
2706 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002707 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002708
Matt Porter403d1942005-11-29 15:00:51 +01002709 return 1;
2710}
2711
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002712#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2713
2714static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2715 struct snd_ctl_elem_value *ucontrol)
2716{
2717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2718 struct sigmatel_spec *spec = codec->spec;
2719
2720 ucontrol->value.integer.value[0] = spec->clfe_swap;
2721 return 0;
2722}
2723
2724static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2725 struct snd_ctl_elem_value *ucontrol)
2726{
2727 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2728 struct sigmatel_spec *spec = codec->spec;
2729 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002730 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002731
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002732 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002733 return 0;
2734
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002735 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002736
2737 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2738 spec->clfe_swap ? 0x4 : 0x0);
2739
2740 return 1;
2741}
2742
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002743#define STAC_CODEC_HP_SWITCH(xname) \
2744 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2745 .name = xname, \
2746 .index = 0, \
2747 .info = stac92xx_hp_switch_info, \
2748 .get = stac92xx_hp_switch_get, \
2749 .put = stac92xx_hp_switch_put, \
2750 }
2751
Matt Porter403d1942005-11-29 15:00:51 +01002752#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2753 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2754 .name = xname, \
2755 .index = 0, \
2756 .info = stac92xx_io_switch_info, \
2757 .get = stac92xx_io_switch_get, \
2758 .put = stac92xx_io_switch_put, \
2759 .private_value = xpval, \
2760 }
2761
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002762#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2763 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2764 .name = xname, \
2765 .index = 0, \
2766 .info = stac92xx_clfe_switch_info, \
2767 .get = stac92xx_clfe_switch_get, \
2768 .put = stac92xx_clfe_switch_put, \
2769 .private_value = xpval, \
2770 }
Matt Porter403d1942005-11-29 15:00:51 +01002771
Mattc7d4b2f2005-06-27 14:59:41 +02002772enum {
2773 STAC_CTL_WIDGET_VOL,
2774 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002775 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002776 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002777 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002778 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002779 STAC_CTL_WIDGET_CLFE_SWITCH,
2780 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002781};
2782
Takashi Iwai2b635362011-05-02 12:33:43 +02002783static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002784 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2785 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002786 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002787 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002788 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002789 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002790 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002791 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002792};
2793
2794/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002795static struct snd_kcontrol_new *
2796stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002797 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002798 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002799 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002800{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002801 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002802
Takashi Iwai603c4012008-07-30 15:01:44 +02002803 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2804 knew = snd_array_new(&spec->kctls);
2805 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002806 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002807 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002808 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002809 if (!knew->name) {
2810 /* roolback */
2811 memset(knew, 0, sizeof(*knew));
2812 spec->kctls.alloced--;
2813 return NULL;
2814 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002815 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002816 return knew;
2817}
2818
2819static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002820 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01002821 int idx, const char *name,
2822 unsigned long val)
2823{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002824 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002825 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002826 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002827 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002828 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002829 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002830 return 0;
2831}
2832
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002833static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2834 int type, int idx, const char *name,
2835 unsigned long val)
2836{
2837 return stac92xx_add_control_temp(spec,
2838 &stac92xx_control_templates[type],
2839 idx, name, val);
2840}
2841
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002842
2843/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002844static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2845 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002846{
2847 return stac92xx_add_control_idx(spec, type, 0, name, val);
2848}
2849
Takashi Iwai2b635362011-05-02 12:33:43 +02002850static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01002851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2852 .name = "Input Source",
2853 .info = stac92xx_mux_enum_info,
2854 .get = stac92xx_mux_enum_get,
2855 .put = stac92xx_mux_enum_put,
2856};
2857
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002858static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2859 hda_nid_t nid, int idx)
2860{
2861 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2862 int control = 0;
2863 struct sigmatel_spec *spec = codec->spec;
2864 char name[22];
2865
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002866 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002867 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2868 && nid == spec->line_switch)
2869 control = STAC_CTL_WIDGET_IO_SWITCH;
2870 else if (snd_hda_query_pin_caps(codec, nid)
2871 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2872 control = STAC_CTL_WIDGET_DC_BIAS;
2873 else if (nid == spec->mic_switch)
2874 control = STAC_CTL_WIDGET_IO_SWITCH;
2875 }
2876
2877 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002878 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002879 return stac92xx_add_control(codec->spec, control,
2880 strcat(name, " Jack Mode"), nid);
2881 }
2882
2883 return 0;
2884}
2885
Takashi Iwaie3c75962009-01-23 11:57:22 +01002886static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2887{
2888 struct snd_kcontrol_new *knew;
2889 struct hda_input_mux *imux = &spec->private_imux;
2890
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002891 if (spec->auto_mic)
2892 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002893 if (!spec->num_adcs || imux->num_items <= 1)
2894 return 0; /* no need for input source control */
2895 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002896 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002897 if (!knew)
2898 return -ENOMEM;
2899 knew->count = spec->num_adcs;
2900 return 0;
2901}
2902
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002903/* check whether the line-input can be used as line-out */
2904static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002905{
2906 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002907 struct auto_pin_cfg *cfg = &spec->autocfg;
2908 hda_nid_t nid;
2909 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002910 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002911
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002912 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2913 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002914 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002915 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002916 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002917 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002918 if (pincap & AC_PINCAP_OUT)
2919 return nid;
2920 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002921 }
Matt Porter403d1942005-11-29 15:00:51 +01002922 return 0;
2923}
2924
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002925static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2926
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002927/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002928static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002929{
2930 struct sigmatel_spec *spec = codec->spec;
2931 struct auto_pin_cfg *cfg = &spec->autocfg;
2932 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002933 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002934
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002935 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002936 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2937 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002938 for (i = 0; i < cfg->num_inputs; i++) {
2939 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002940 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002941 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002942 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2943 /* some laptops have an internal analog microphone
2944 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002945 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002946 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002947 if (pincap & AC_PINCAP_OUT) {
2948 *dac = get_unassigned_dac(codec, nid);
2949 if (*dac)
2950 return nid;
2951 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002952 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002953 }
2954 return 0;
2955}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002956
2957static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2958{
2959 int i;
2960
2961 for (i = 0; i < spec->multiout.num_dacs; i++) {
2962 if (spec->multiout.dac_nids[i] == nid)
2963 return 1;
2964 }
2965
2966 return 0;
2967}
2968
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002969static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2970{
2971 int i;
2972 if (is_in_dac_nids(spec, nid))
2973 return 1;
2974 for (i = 0; i < spec->autocfg.hp_outs; i++)
2975 if (spec->hp_dacs[i] == nid)
2976 return 1;
2977 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2978 if (spec->speaker_dacs[i] == nid)
2979 return 1;
2980 return 0;
2981}
2982
2983static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2984{
2985 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02002986 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002987 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02002988 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002989 unsigned int wcaps, wtype;
2990
2991 conn_len = snd_hda_get_connections(codec, nid, conn,
2992 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002993 /* 92HD88: trace back up the link of nids to find the DAC */
2994 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2995 != AC_WID_AUD_OUT)) {
2996 nid = conn[0];
2997 conn_len = snd_hda_get_connections(codec, nid, conn,
2998 HDA_MAX_CONNECTIONS);
2999 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003000 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003001 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003002 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003003 /* we check only analog outputs */
3004 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3005 continue;
3006 /* if this route has a free DAC, assign it */
3007 if (!check_all_dac_nids(spec, conn[j])) {
3008 if (conn_len > 1) {
3009 /* select this DAC in the pin's input mux */
3010 snd_hda_codec_write_cache(codec, nid, 0,
3011 AC_VERB_SET_CONNECT_SEL, j);
3012 }
3013 return conn[j];
3014 }
3015 }
David Henningsson48718ea2011-10-05 09:49:05 +02003016
3017 /* if all DACs are already assigned, connect to the primary DAC,
3018 unless we're assigning a secondary headphone */
3019 fallback_dac = spec->multiout.dac_nids[0];
3020 if (spec->multiout.hp_nid) {
3021 for (j = 0; j < cfg->hp_outs; j++)
3022 if (cfg->hp_pins[j] == nid) {
3023 fallback_dac = spec->multiout.hp_nid;
3024 break;
3025 }
3026 }
3027
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003028 if (conn_len > 1) {
3029 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003030 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003031 snd_hda_codec_write_cache(codec, nid, 0,
3032 AC_VERB_SET_CONNECT_SEL, j);
3033 break;
3034 }
3035 }
3036 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003037 return 0;
3038}
3039
3040static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3041static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3042
Matt Porter3cc08dc2006-01-23 15:27:49 +01003043/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003044 * Fill in the dac_nids table from the parsed pin configuration
3045 * This function only works when every pin in line_out_pins[]
3046 * contains atleast one DAC in its connection list. Some 92xx
3047 * codecs are not connected directly to a DAC, such as the 9200
3048 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003049 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003050static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003051{
3052 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003053 struct auto_pin_cfg *cfg = &spec->autocfg;
3054 int i;
3055 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003056
Mattc7d4b2f2005-06-27 14:59:41 +02003057 for (i = 0; i < cfg->line_outs; i++) {
3058 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003059 dac = get_unassigned_dac(codec, nid);
3060 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003061 if (spec->multiout.num_dacs > 0) {
3062 /* we have already working output pins,
3063 * so let's drop the broken ones again
3064 */
3065 cfg->line_outs = spec->multiout.num_dacs;
3066 break;
3067 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003068 /* error out, no available DAC found */
3069 snd_printk(KERN_ERR
3070 "%s: No available DAC for pin 0x%x\n",
3071 __func__, nid);
3072 return -ENODEV;
3073 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003074 add_spec_dacs(spec, dac);
3075 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003076
Takashi Iwai139e0712009-03-06 12:10:41 +01003077 for (i = 0; i < cfg->hp_outs; i++) {
3078 nid = cfg->hp_pins[i];
3079 dac = get_unassigned_dac(codec, nid);
3080 if (dac) {
3081 if (!spec->multiout.hp_nid)
3082 spec->multiout.hp_nid = dac;
3083 else
3084 add_spec_extra_dacs(spec, dac);
3085 }
3086 spec->hp_dacs[i] = dac;
3087 }
3088
3089 for (i = 0; i < cfg->speaker_outs; i++) {
3090 nid = cfg->speaker_pins[i];
3091 dac = get_unassigned_dac(codec, nid);
3092 if (dac)
3093 add_spec_extra_dacs(spec, dac);
3094 spec->speaker_dacs[i] = dac;
3095 }
3096
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003097 /* add line-in as output */
3098 nid = check_line_out_switch(codec);
3099 if (nid) {
3100 dac = get_unassigned_dac(codec, nid);
3101 if (dac) {
3102 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3103 nid, cfg->line_outs);
3104 cfg->line_out_pins[cfg->line_outs] = nid;
3105 cfg->line_outs++;
3106 spec->line_switch = nid;
3107 add_spec_dacs(spec, dac);
3108 }
3109 }
3110 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003111 nid = check_mic_out_switch(codec, &dac);
3112 if (nid && dac) {
3113 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3114 nid, cfg->line_outs);
3115 cfg->line_out_pins[cfg->line_outs] = nid;
3116 cfg->line_outs++;
3117 spec->mic_switch = nid;
3118 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003119 }
3120
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003121 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003122 spec->multiout.num_dacs,
3123 spec->multiout.dac_nids[0],
3124 spec->multiout.dac_nids[1],
3125 spec->multiout.dac_nids[2],
3126 spec->multiout.dac_nids[3],
3127 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003128
Mattc7d4b2f2005-06-27 14:59:41 +02003129 return 0;
3130}
3131
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003132/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003133static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3134 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003135{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003136 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003137 char name[32];
3138 int err;
3139
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003140 if (!spec->check_volume_offset) {
3141 unsigned int caps, step, nums, db_scale;
3142 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3143 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3144 AC_AMPCAP_STEP_SIZE_SHIFT;
3145 step = (step + 1) * 25; /* in .01dB unit */
3146 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3147 AC_AMPCAP_NUM_STEPS_SHIFT;
3148 db_scale = nums * step;
3149 /* if dB scale is over -64dB, and finer enough,
3150 * let's reduce it to half
3151 */
3152 if (db_scale > 6400 && nums >= 0x1f)
3153 spec->volume_offset = nums / 2;
3154 spec->check_volume_offset = 1;
3155 }
3156
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003157 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003158 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003159 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3160 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003161 if (err < 0)
3162 return err;
3163 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003164 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003165 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3166 if (err < 0)
3167 return err;
3168 return 0;
3169}
3170
Takashi Iwai668b9652009-03-06 10:13:24 +01003171#define create_controls(codec, pfx, nid, chs) \
3172 create_controls_idx(codec, pfx, 0, nid, chs)
3173
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003174static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3175{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003176 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003177 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3178 return 1;
3179 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003180 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3181 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003182 spec->multiout.num_dacs++;
3183 }
3184 return 0;
3185}
3186
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003187static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003188{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003189 int i;
3190 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3191 if (!spec->multiout.extra_out_nid[i]) {
3192 spec->multiout.extra_out_nid[i] = nid;
3193 return 0;
3194 }
3195 }
3196 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3197 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003198}
3199
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003200/* Create output controls
3201 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3202 */
3203static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3204 const hda_nid_t *pins,
3205 const hda_nid_t *dac_nids,
3206 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003207{
Takashi Iwai76624532008-12-19 10:09:47 +01003208 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003209 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003210 "Front", "Surround", NULL /*CLFE*/, "Side"
3211 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003212 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003213 int i, err;
3214 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003215
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003216 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003217 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003218 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003219 spec->hp_detect = 1;
3220 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003221 nid = dac_nids[i];
3222 if (!nid)
3223 continue;
3224 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003225 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003226 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003227 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003228 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003229 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003230 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003231 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003232
3233 wid_caps = get_wcaps(codec, nid);
3234
3235 if (wid_caps & AC_WCAP_LR_SWAP) {
3236 err = stac92xx_add_control(spec,
3237 STAC_CTL_WIDGET_CLFE_SWITCH,
3238 "Swap Center/LFE Playback Switch", nid);
3239
3240 if (err < 0)
3241 return err;
3242 }
3243
Mattc7d4b2f2005-06-27 14:59:41 +02003244 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003245 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003246 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003247 switch (type) {
3248 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003249 name = "Headphone";
3250 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003251 break;
3252 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003253 name = "Speaker";
3254 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003255 break;
3256 default:
3257 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003258 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003259 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003260 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003261 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003262 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003263 return err;
3264 }
3265 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003266 return 0;
3267}
3268
Takashi Iwai6479c632009-07-28 18:20:25 +02003269static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3270 unsigned long sw, int idx)
3271{
3272 int err;
3273 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003274 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003275 if (err < 0)
3276 return err;
3277 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003278 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003279 if (err < 0)
3280 return err;
3281 return 0;
3282}
3283
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003284/* add playback controls from the parsed DAC table */
3285static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3286 const struct auto_pin_cfg *cfg)
3287{
3288 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003289 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003290 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003291 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003292
3293 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3294 spec->multiout.dac_nids,
3295 cfg->line_out_type);
3296 if (err < 0)
3297 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003298
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003299 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003300 err = stac92xx_add_control(spec,
3301 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003302 "Headphone as Line Out Switch",
3303 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003304 if (err < 0)
3305 return err;
3306 }
3307
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003308 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003309 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003310 break;
3311 nid = cfg->inputs[idx].pin;
3312 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3313 if (err < 0)
3314 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003315 }
Matt Porter403d1942005-11-29 15:00:51 +01003316
Mattc7d4b2f2005-06-27 14:59:41 +02003317 return 0;
3318}
3319
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003320/* add playback controls for Speaker and HP outputs */
3321static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3322 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003323{
3324 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003325 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003326
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003327 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3328 spec->hp_dacs, AUTO_PIN_HP_OUT);
3329 if (err < 0)
3330 return err;
3331
3332 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3333 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3334 if (err < 0)
3335 return err;
3336
Mattc7d4b2f2005-06-27 14:59:41 +02003337 return 0;
3338}
3339
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003340/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003341static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003342 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003343};
3344
3345/* create mono mux for mono out on capable codecs */
3346static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3347{
3348 struct sigmatel_spec *spec = codec->spec;
3349 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3350 int i, num_cons;
3351 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3352
3353 num_cons = snd_hda_get_connections(codec,
3354 spec->mono_nid,
3355 con_lst,
3356 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003357 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003358 return -EINVAL;
3359
Takashi Iwai10a20af2010-09-09 16:28:02 +02003360 for (i = 0; i < num_cons; i++)
3361 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3362 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003363
3364 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3365 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003366}
3367
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003368/* create PC beep volume controls */
3369static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3370 hda_nid_t nid)
3371{
3372 struct sigmatel_spec *spec = codec->spec;
3373 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003374 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3375
3376 if (spec->anabeep_nid == nid)
3377 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003378
3379 /* check for mute support for the the amp */
3380 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003381 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003382 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003383 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3384 if (err < 0)
3385 return err;
3386 }
3387
3388 /* check to see if there is volume support for the amp */
3389 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3390 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003391 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003392 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3393 if (err < 0)
3394 return err;
3395 }
3396 return 0;
3397}
3398
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003399#ifdef CONFIG_SND_HDA_INPUT_BEEP
3400#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3401
3402static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3403 struct snd_ctl_elem_value *ucontrol)
3404{
3405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3406 ucontrol->value.integer.value[0] = codec->beep->enabled;
3407 return 0;
3408}
3409
3410static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3411 struct snd_ctl_elem_value *ucontrol)
3412{
3413 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003414 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003415}
3416
Takashi Iwai2b635362011-05-02 12:33:43 +02003417static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003418 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3419 .info = stac92xx_dig_beep_switch_info,
3420 .get = stac92xx_dig_beep_switch_get,
3421 .put = stac92xx_dig_beep_switch_put,
3422};
3423
3424static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3425{
3426 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003427 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003428}
3429#endif
3430
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003431static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3432{
3433 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003434 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003435
3436 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003437 hda_nid_t nid;
3438 unsigned int wcaps;
3439 unsigned long val;
3440
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003441 nid = spec->mux_nids[i];
3442 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003443 if (!(wcaps & AC_WCAP_OUT_AMP))
3444 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003445
Takashi Iwai667067d2009-08-13 18:14:42 +02003446 /* check whether already the same control was created as
3447 * normal Capture Volume.
3448 */
3449 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3450 for (j = 0; j < spec->num_caps; j++) {
3451 if (spec->capvols[j] == val)
3452 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003453 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003454 if (j < spec->num_caps)
3455 continue;
3456
3457 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3458 "Mux Capture Volume", val);
3459 if (err < 0)
3460 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003461 }
3462 return 0;
3463};
3464
Takashi Iwaiea734962011-01-17 11:29:34 +01003465static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003466 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003467};
3468
3469static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3470{
3471 struct sigmatel_spec *spec = codec->spec;
3472 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003473 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003474 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003475 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003476
3477 num_cons = snd_hda_get_connections(codec,
3478 spec->smux_nids[0],
3479 con_lst,
3480 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003481 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003482 return -EINVAL;
3483
Matthew Ranostay65973632008-09-16 10:39:37 -04003484 if (!labels)
3485 labels = stac92xx_spdif_labels;
3486
Takashi Iwai10a20af2010-09-09 16:28:02 +02003487 for (i = 0; i < num_cons; i++)
3488 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003489
3490 return 0;
3491}
3492
Matt Porter8b657272006-10-26 17:12:59 +02003493/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003494static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003495 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3496 "Digital Mic 3", "Digital Mic 4"
3497};
3498
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003499static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3500 int idx)
3501{
3502 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3503 int nums;
3504 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3505 if (idx >= 0 && idx < nums)
3506 return conn[idx];
3507 return 0;
3508}
3509
Takashi Iwai8d087c72011-06-28 12:45:47 +02003510/* look for NID recursively */
3511#define get_connection_index(codec, mux, nid) \
3512 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003513
Takashi Iwai667067d2009-08-13 18:14:42 +02003514/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003515/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003516static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003517 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003518{
3519 unsigned int caps, nums;
3520 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003521 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003522
Takashi Iwai96f845d2009-08-29 00:49:36 +02003523 if (direction == HDA_OUTPUT)
3524 caps = AC_WCAP_OUT_AMP;
3525 else
3526 caps = AC_WCAP_IN_AMP;
3527 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003528 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003529 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003530 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3531 if (!nums)
3532 return 0;
3533 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003534 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3535 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003536 if (err < 0)
3537 return err;
3538 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003539}
3540
Matt Porter8b657272006-10-26 17:12:59 +02003541/* create playback/capture controls for input pins on dmic capable codecs */
3542static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3543 const struct auto_pin_cfg *cfg)
3544{
3545 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003546 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003547 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003548 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003549 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003550
Takashi Iwai10a20af2010-09-09 16:28:02 +02003551 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003552
Matt Porter8b657272006-10-26 17:12:59 +02003553 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003554 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003555 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003556 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003557
Takashi Iwai667067d2009-08-13 18:14:42 +02003558 nid = spec->dmic_nids[i];
3559 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3560 continue;
3561 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003562 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3563 continue;
3564
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003565 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3566 if (index < 0)
3567 continue;
3568
Takashi Iwai10a20af2010-09-09 16:28:02 +02003569 label = hda_get_input_pin_label(codec, nid, 1);
3570 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003571 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3572 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003573
Takashi Iwai10a20af2010-09-09 16:28:02 +02003574 err = create_elem_capture_vol(codec, nid, label, type_idx,
3575 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003576 if (err < 0)
3577 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003578 if (!err) {
3579 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003580 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003581 if (err < 0)
3582 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003583 if (!err) {
3584 nid = get_connected_node(codec,
3585 spec->dmux_nids[0], index);
3586 if (nid)
3587 err = create_elem_capture_vol(codec,
3588 nid, label,
3589 type_idx, HDA_INPUT);
3590 if (err < 0)
3591 return err;
3592 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003593 }
Matt Porter8b657272006-10-26 17:12:59 +02003594 }
3595
3596 return 0;
3597}
3598
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003599static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003600 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003601{
3602 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003603 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003604
3605 if (!nid)
3606 return 0;
3607 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003608 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003609 switch (snd_hda_get_input_pin_attr(cfg)) {
3610 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003611 if (*fixed)
3612 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003613 if (type != AC_JACK_MIC_IN)
3614 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003615 *fixed = nid;
3616 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003617 case INPUT_PIN_ATTR_UNUSED:
3618 break;
3619 case INPUT_PIN_ATTR_DOCK:
3620 if (*dock)
3621 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003622 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3623 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003624 *dock = nid;
3625 break;
3626 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003627 if (*ext)
3628 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003629 if (type != AC_JACK_MIC_IN)
3630 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003631 *ext = nid;
3632 break;
3633 }
3634 return 0;
3635}
3636
3637static int set_mic_route(struct hda_codec *codec,
3638 struct sigmatel_mic_route *mic,
3639 hda_nid_t pin)
3640{
3641 struct sigmatel_spec *spec = codec->spec;
3642 struct auto_pin_cfg *cfg = &spec->autocfg;
3643 int i;
3644
3645 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003646 if (pin == 0)
3647 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003648 for (i = 0; i < cfg->num_inputs; i++) {
3649 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003650 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003651 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003652 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003653 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003654 i = get_connection_index(codec, spec->mux_nids[0], pin);
3655 if (i < 0)
3656 return -1;
3657 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003658 mic->dmux_idx = -1;
3659 if (spec->dmux_nids)
3660 mic->dmux_idx = get_connection_index(codec,
3661 spec->dmux_nids[0],
3662 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003663 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003664 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003665 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3666 if (i < 0)
3667 return -1;
3668 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003669 mic->mux_idx = -1;
3670 if (spec->mux_nids)
3671 mic->mux_idx = get_connection_index(codec,
3672 spec->mux_nids[0],
3673 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003674 }
3675 return 0;
3676}
3677
3678/* return non-zero if the device is for automatic mic switch */
3679static int stac_check_auto_mic(struct hda_codec *codec)
3680{
3681 struct sigmatel_spec *spec = codec->spec;
3682 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003683 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003684 int i;
3685
Charles Chin99077902010-09-17 10:22:32 +02003686 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003687 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003688 if (check_mic_pin(codec, cfg->inputs[i].pin,
3689 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003690 return 0;
3691 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003692 if (check_mic_pin(codec, spec->dmic_nids[i],
3693 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003694 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003695 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003696 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003697 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003698 return 0; /* no unsol support */
3699 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003700 set_mic_route(codec, &spec->int_mic, fixed) ||
3701 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003702 return 0; /* something is wrong */
3703 return 1;
3704}
3705
Mattc7d4b2f2005-06-27 14:59:41 +02003706/* create playback/capture controls for input pins */
3707static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3708{
3709 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003710 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003711 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003712 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003713
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003714 for (i = 0; i < cfg->num_inputs; i++) {
3715 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003716 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003717
Takashi Iwai314634b2006-09-21 11:56:18 +02003718 index = -1;
3719 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003720 index = get_connection_index(codec, spec->mux_nids[j],
3721 nid);
3722 if (index >= 0)
3723 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003724 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003725 if (index < 0)
3726 continue;
3727
Takashi Iwai10a20af2010-09-09 16:28:02 +02003728 label = hda_get_autocfg_input_label(codec, cfg, i);
3729 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003730
Takashi Iwai667067d2009-08-13 18:14:42 +02003731 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003732 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003733 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003734 if (err < 0)
3735 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003736 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003737 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003738
Steve Longerbeam7b043892007-05-03 20:50:03 +02003739 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003740 /*
3741 * Set the current input for the muxes.
3742 * The STAC9221 has two input muxes with identical source
3743 * NID lists. Hopefully this won't get confused.
3744 */
3745 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003746 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3747 AC_VERB_SET_CONNECT_SEL,
3748 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003749 }
3750 }
3751
Mattc7d4b2f2005-06-27 14:59:41 +02003752 return 0;
3753}
3754
Mattc7d4b2f2005-06-27 14:59:41 +02003755static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3756{
3757 struct sigmatel_spec *spec = codec->spec;
3758 int i;
3759
3760 for (i = 0; i < spec->autocfg.line_outs; i++) {
3761 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3762 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3763 }
3764}
3765
3766static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3767{
3768 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003769 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003770
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003771 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3772 hda_nid_t pin;
3773 pin = spec->autocfg.hp_pins[i];
3774 if (pin) /* connect to front */
3775 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3776 }
3777 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3778 hda_nid_t pin;
3779 pin = spec->autocfg.speaker_pins[i];
3780 if (pin) /* connect to front */
3781 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3782 }
Mattc7d4b2f2005-06-27 14:59:41 +02003783}
3784
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003785static int is_dual_headphones(struct hda_codec *codec)
3786{
3787 struct sigmatel_spec *spec = codec->spec;
3788 int i, valid_hps;
3789
3790 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3791 spec->autocfg.hp_outs <= 1)
3792 return 0;
3793 valid_hps = 0;
3794 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3795 hda_nid_t nid = spec->autocfg.hp_pins[i];
3796 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3797 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3798 continue;
3799 valid_hps++;
3800 }
3801 return (valid_hps > 1);
3802}
3803
3804
Charles Chin9009b0e2011-11-03 10:27:27 +01003805static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003806{
3807 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01003808 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003809 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003810 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003811
Matt Porter8b657272006-10-26 17:12:59 +02003812 if ((err = snd_hda_parse_pin_def_config(codec,
3813 &spec->autocfg,
3814 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003815 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003816 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003817 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003818
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003819 /* If we have no real line-out pin and multiple hp-outs, HPs should
3820 * be set up as multi-channel outputs.
3821 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003822 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003823 /* Copy hp_outs to line_outs, backup line_outs in
3824 * speaker_outs so that the following routines can handle
3825 * HP pins as primary outputs.
3826 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003827 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003828 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3829 sizeof(spec->autocfg.line_out_pins));
3830 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3831 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3832 sizeof(spec->autocfg.hp_pins));
3833 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003834 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3835 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003836 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003837 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003838 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003839 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3840 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003841 u32 caps = query_amp_caps(codec,
3842 spec->autocfg.mono_out_pin, dir);
3843 hda_nid_t conn_list[1];
3844
3845 /* get the mixer node and then the mono mux if it exists */
3846 if (snd_hda_get_connections(codec,
3847 spec->autocfg.mono_out_pin, conn_list, 1) &&
3848 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003849 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003850
3851 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003852 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003853 /* LR swap check, some stac925x have a mux that
3854 * changes the DACs output path instead of the
3855 * mono-mux path.
3856 */
3857 if (wid_type == AC_WID_AUD_SEL &&
3858 !(wcaps & AC_WCAP_LR_SWAP))
3859 spec->mono_nid = conn_list[0];
3860 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003861 if (dir) {
3862 hda_nid_t nid = spec->autocfg.mono_out_pin;
3863
3864 /* most mono outs have a least a mute/unmute switch */
3865 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3866 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3867 "Mono Playback Switch",
3868 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003869 if (err < 0)
3870 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003871 /* check for volume support for the amp */
3872 if ((caps & AC_AMPCAP_NUM_STEPS)
3873 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3874 err = stac92xx_add_control(spec,
3875 STAC_CTL_WIDGET_VOL,
3876 "Mono Playback Volume",
3877 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3878 if (err < 0)
3879 return err;
3880 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003881 }
3882
3883 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3884 AC_PINCTL_OUT_EN);
3885 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003886
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003887 if (!spec->multiout.num_dacs) {
3888 err = stac92xx_auto_fill_dac_nids(codec);
3889 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003890 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003891 err = stac92xx_auto_create_multi_out_ctls(codec,
3892 &spec->autocfg);
3893 if (err < 0)
3894 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003895 }
Mattc7d4b2f2005-06-27 14:59:41 +02003896
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003897 /* setup analog beep controls */
3898 if (spec->anabeep_nid > 0) {
3899 err = stac92xx_auto_create_beep_ctls(codec,
3900 spec->anabeep_nid);
3901 if (err < 0)
3902 return err;
3903 }
3904
3905 /* setup digital beep controls and input device */
3906#ifdef CONFIG_SND_HDA_INPUT_BEEP
3907 if (spec->digbeep_nid > 0) {
3908 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003909 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003910
3911 err = stac92xx_auto_create_beep_ctls(codec, nid);
3912 if (err < 0)
3913 return err;
3914 err = snd_hda_attach_beep_device(codec, nid);
3915 if (err < 0)
3916 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003917 if (codec->beep) {
3918 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003919 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003920 /* if no beep switch is available, make its own one */
3921 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3922 if (!(caps & AC_AMPCAP_MUTE)) {
3923 err = stac92xx_beep_switch_ctl(codec);
3924 if (err < 0)
3925 return err;
3926 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003927 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003928 }
3929#endif
3930
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003931 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003932 if (err < 0)
3933 return err;
3934
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003935 /* All output parsing done, now restore the swapped hp pins */
3936 if (hp_swap) {
3937 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3938 sizeof(spec->autocfg.hp_pins));
3939 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3940 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3941 spec->autocfg.line_outs = 0;
3942 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003943
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003944 if (stac_check_auto_mic(codec)) {
3945 spec->auto_mic = 1;
3946 /* only one capture for auto-mic */
3947 spec->num_adcs = 1;
3948 spec->num_caps = 1;
3949 spec->num_muxes = 1;
3950 }
3951
Takashi Iwai6479c632009-07-28 18:20:25 +02003952 for (i = 0; i < spec->num_caps; i++) {
3953 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3954 spec->capsws[i], i);
3955 if (err < 0)
3956 return err;
3957 }
3958
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003959 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003960 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003961 return err;
3962
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003963 if (spec->mono_nid > 0) {
3964 err = stac92xx_auto_create_mono_output_ctls(codec);
3965 if (err < 0)
3966 return err;
3967 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003968 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003969 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3970 &spec->autocfg)) < 0)
3971 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003972 if (spec->num_muxes > 0) {
3973 err = stac92xx_auto_create_mux_input_ctls(codec);
3974 if (err < 0)
3975 return err;
3976 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003977 if (spec->num_smuxes > 0) {
3978 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3979 if (err < 0)
3980 return err;
3981 }
Matt Porter8b657272006-10-26 17:12:59 +02003982
Takashi Iwaie3c75962009-01-23 11:57:22 +01003983 err = stac92xx_add_input_source(spec);
3984 if (err < 0)
3985 return err;
3986
Mattc7d4b2f2005-06-27 14:59:41 +02003987 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003988 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003989 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003990
Charles Chin9009b0e2011-11-03 10:27:27 +01003991 /* find digital out and in converters */
3992 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3993 unsigned int wid_caps = get_wcaps(codec, i);
3994 if (wid_caps & AC_WCAP_DIGITAL) {
3995 switch (get_wcaps_type(wid_caps)) {
3996 case AC_WID_AUD_OUT:
3997 if (!dig_out)
3998 dig_out = i;
3999 break;
4000 case AC_WID_AUD_IN:
4001 if (!dig_in)
4002 dig_in = i;
4003 break;
4004 }
4005 }
4006 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004007 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004008 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004009 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004010 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004011
Takashi Iwai603c4012008-07-30 15:01:44 +02004012 if (spec->kctls.list)
4013 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004014
4015 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004016 if (!spec->dinput_mux)
4017 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004018 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004019 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004020 return 1;
4021}
4022
Takashi Iwai82bc9552006-03-21 11:24:42 +01004023/* add playback controls for HP output */
4024static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4025 struct auto_pin_cfg *cfg)
4026{
4027 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004028 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004029
4030 if (! pin)
4031 return 0;
4032
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004033 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004034 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004035
4036 return 0;
4037}
4038
Richard Fish160ea0d2006-09-06 13:58:25 +02004039/* add playback controls for LFE output */
4040static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4041 struct auto_pin_cfg *cfg)
4042{
4043 struct sigmatel_spec *spec = codec->spec;
4044 int err;
4045 hda_nid_t lfe_pin = 0x0;
4046 int i;
4047
4048 /*
4049 * search speaker outs and line outs for a mono speaker pin
4050 * with an amp. If one is found, add LFE controls
4051 * for it.
4052 */
4053 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4054 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004055 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004056 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4057 if (wcaps == AC_WCAP_OUT_AMP)
4058 /* found a mono speaker with an amp, must be lfe */
4059 lfe_pin = pin;
4060 }
4061
4062 /* if speaker_outs is 0, then speakers may be in line_outs */
4063 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4064 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4065 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004066 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004067 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004068 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004069 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004070 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4071 if (wcaps == AC_WCAP_OUT_AMP)
4072 /* found a mono speaker with an amp,
4073 must be lfe */
4074 lfe_pin = pin;
4075 }
4076 }
4077 }
4078
4079 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004080 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004081 if (err < 0)
4082 return err;
4083 }
4084
4085 return 0;
4086}
4087
Mattc7d4b2f2005-06-27 14:59:41 +02004088static int stac9200_parse_auto_config(struct hda_codec *codec)
4089{
4090 struct sigmatel_spec *spec = codec->spec;
4091 int err;
4092
Kailang Yangdf694da2005-12-05 19:42:22 +01004093 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004094 return err;
4095
4096 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4097 return err;
4098
Takashi Iwai82bc9552006-03-21 11:24:42 +01004099 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4100 return err;
4101
Richard Fish160ea0d2006-09-06 13:58:25 +02004102 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4103 return err;
4104
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004105 if (spec->num_muxes > 0) {
4106 err = stac92xx_auto_create_mux_input_ctls(codec);
4107 if (err < 0)
4108 return err;
4109 }
4110
Takashi Iwaie3c75962009-01-23 11:57:22 +01004111 err = stac92xx_add_input_source(spec);
4112 if (err < 0)
4113 return err;
4114
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004115 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004116 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004117 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004118 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004119
Takashi Iwai603c4012008-07-30 15:01:44 +02004120 if (spec->kctls.list)
4121 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004122
4123 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004124 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004125
4126 return 1;
4127}
4128
Sam Revitch62fe78e2006-05-10 15:09:17 +02004129/*
4130 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4131 * funky external mute control using GPIO pins.
4132 */
4133
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004134static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004135 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004136{
4137 unsigned int gpiostate, gpiomask, gpiodir;
4138
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004139 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4140
Sam Revitch62fe78e2006-05-10 15:09:17 +02004141 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4142 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004143 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004144
4145 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4146 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004147 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004148
4149 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4150 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004151 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004152
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004153 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004154 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4155
4156 snd_hda_codec_write(codec, codec->afg, 0,
4157 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004158 snd_hda_codec_read(codec, codec->afg, 0,
4159 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004160
4161 msleep(1);
4162
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004163 snd_hda_codec_read(codec, codec->afg, 0,
4164 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004165}
4166
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004167static int stac92xx_add_jack(struct hda_codec *codec,
4168 hda_nid_t nid, int type)
4169{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004170#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai330ee992009-02-20 14:33:36 +01004171 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004172 int connectivity = get_defcfg_connect(def_conf);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004173
4174 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4175 return 0;
4176
David Henningssoneb335a42011-10-03 16:25:42 +02004177 return snd_hda_input_jack_add(codec, nid, type, NULL);
4178#else
Takashi Iwai95c09092009-04-14 16:15:29 +02004179 return 0;
David Henningssoneb335a42011-10-03 16:25:42 +02004180#endif /* CONFIG_SND_HDA_INPUT_JACK */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004181}
4182
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004183static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4184 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004185{
4186 struct sigmatel_event *event;
4187
4188 snd_array_init(&spec->events, sizeof(*event), 32);
4189 event = snd_array_new(&spec->events);
4190 if (!event)
4191 return -ENOMEM;
4192 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004193 event->type = type;
4194 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004195 event->data = data;
4196
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004197 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004198}
4199
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004200static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004201 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004202{
4203 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004204 struct sigmatel_event *event = spec->events.list;
4205 int i;
4206
4207 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004208 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004209 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004210 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004211 return NULL;
4212}
4213
4214static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4215 unsigned char tag)
4216{
4217 struct sigmatel_spec *spec = codec->spec;
4218 struct sigmatel_event *event = spec->events.list;
4219 int i;
4220
4221 for (i = 0; i < spec->events.used; i++, event++) {
4222 if (event->tag == tag)
4223 return event;
4224 }
4225 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004226}
4227
Takashi Iwai62558ce2009-07-29 14:23:09 +02004228/* check if given nid is a valid pin and no other events are assigned
4229 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4230 * Otherwise, returns zero.
4231 */
4232static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4233 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004234{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004235 struct sigmatel_event *event;
4236 int tag;
4237
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004238 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004239 return 0;
4240 event = stac_get_event(codec, nid);
4241 if (event) {
4242 if (event->type != type)
4243 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004244 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004245 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004246 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004247 if (tag < 0)
4248 return 0;
4249 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004250 snd_hda_codec_write_cache(codec, nid, 0,
4251 AC_VERB_SET_UNSOLICITED_ENABLE,
4252 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004253 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004254}
4255
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004256static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4257{
4258 int i;
4259 for (i = 0; i < cfg->hp_outs; i++)
4260 if (cfg->hp_pins[i] == nid)
4261 return 1; /* nid is a HP-Out */
4262
4263 return 0; /* nid is not a HP-Out */
4264};
4265
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004266static void stac92xx_power_down(struct hda_codec *codec)
4267{
4268 struct sigmatel_spec *spec = codec->spec;
4269
4270 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004271 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004272 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004273 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004274 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004275 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4276}
4277
Takashi Iwaif73d3582008-11-25 08:21:51 +01004278static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4279 int enable);
4280
Takashi Iwai014c41f2009-12-27 13:53:24 +01004281static inline int get_int_hint(struct hda_codec *codec, const char *key,
4282 int *valp)
4283{
4284 const char *p;
4285 p = snd_hda_get_hint(codec, key);
4286 if (p) {
4287 unsigned long val;
4288 if (!strict_strtoul(p, 0, &val)) {
4289 *valp = val;
4290 return 1;
4291 }
4292 }
4293 return 0;
4294}
4295
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004296/* override some hints from the hwdep entry */
4297static void stac_store_hints(struct hda_codec *codec)
4298{
4299 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004300 int val;
4301
4302 val = snd_hda_get_bool_hint(codec, "hp_detect");
4303 if (val >= 0)
4304 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004305 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004306 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4307 spec->gpio_mask;
4308 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004309 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4310 spec->gpio_mask &= spec->gpio_mask;
4311 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4312 spec->gpio_dir &= spec->gpio_mask;
4313 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4314 spec->eapd_mask &= spec->gpio_mask;
4315 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4316 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004317 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4318 if (val >= 0)
4319 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004320 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4321 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004322 spec->gpio_mask |= spec->gpio_led;
4323 spec->gpio_dir |= spec->gpio_led;
4324 if (spec->gpio_led_polarity)
4325 spec->gpio_data |= spec->gpio_led;
Takashi Iwai043958e2009-12-26 10:36:12 +01004326 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004327}
4328
Mattc7d4b2f2005-06-27 14:59:41 +02004329static int stac92xx_init(struct hda_codec *codec)
4330{
4331 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004332 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004333 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004334 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004335
Mattc7d4b2f2005-06-27 14:59:41 +02004336 snd_hda_sequence_write(codec, spec->init);
4337
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004338 /* power down adcs initially */
4339 if (spec->powerdown_adcs)
4340 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004341 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004342 spec->adc_nids[i], 0,
4343 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004344
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004345 /* override some hints */
4346 stac_store_hints(codec);
4347
Takashi Iwaif73d3582008-11-25 08:21:51 +01004348 /* set up GPIO */
4349 gpio = spec->gpio_data;
4350 /* turn on EAPD statically when spec->eapd_switch isn't set.
4351 * otherwise, unsol event will turn it on/off dynamically
4352 */
4353 if (!spec->eapd_switch)
4354 gpio |= spec->eapd_mask;
4355 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4356
Takashi Iwai82bc9552006-03-21 11:24:42 +01004357 /* set up pins */
4358 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004359 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004360 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004361 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004362 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004363 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004364 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4365 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004366 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004367 for (i = 0; i < cfg->line_outs; i++) {
4368 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004369 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4370 }
4371 }
4372
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004373 /* force to enable the first line-out; the others are set up
4374 * in unsol_event
4375 */
4376 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004377 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004378 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004379 if (cfg->hp_pins[0])
4380 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4381 else if (cfg->line_out_pins[0])
4382 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004383 } else {
4384 stac92xx_auto_init_multi_out(codec);
4385 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004386 for (i = 0; i < cfg->hp_outs; i++)
4387 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004388 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004389 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004390 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004391 if (spec->dmux_nids)
4392 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004393 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004394 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4395 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004396 if (enable_pin_detect(codec, spec->dock_mic.pin,
4397 STAC_MIC_EVENT))
4398 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004399 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004400 for (i = 0; i < cfg->num_inputs; i++) {
4401 hda_nid_t nid = cfg->inputs[i].pin;
4402 int type = cfg->inputs[i].type;
4403 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004404 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004405 /* for mic pins, force to initialize */
4406 pinctl = stac92xx_get_default_vref(codec, nid);
4407 pinctl |= AC_PINCTL_IN_EN;
4408 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4409 } else {
4410 pinctl = snd_hda_codec_read(codec, nid, 0,
4411 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4412 /* if PINCTL already set then skip */
4413 /* Also, if both INPUT and OUTPUT are set,
4414 * it must be a BIOS bug; need to override, too
4415 */
4416 if (!(pinctl & AC_PINCTL_IN_EN) ||
4417 (pinctl & AC_PINCTL_OUT_EN)) {
4418 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004419 pinctl |= AC_PINCTL_IN_EN;
4420 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004421 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004422 }
4423 conf = snd_hda_codec_get_pincfg(codec, nid);
4424 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4425 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4426 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004427 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004428 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004429 for (i = 0; i < spec->num_dmics; i++)
4430 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4431 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004432 if (cfg->dig_out_pins[0])
4433 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004434 AC_PINCTL_OUT_EN);
4435 if (cfg->dig_in_pin)
4436 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4437 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004438 for (i = 0; i < spec->num_pwrs; i++) {
4439 hda_nid_t nid = spec->pwr_nids[i];
4440 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004441
Takashi Iwaieb632122008-12-19 16:39:48 +01004442 /* power on when no jack detection is available */
4443 if (!spec->hp_detect) {
4444 stac_toggle_power_map(codec, nid, 1);
4445 continue;
4446 }
4447
4448 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004449 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004450
Takashi Iwaif73d3582008-11-25 08:21:51 +01004451 pinctl = snd_hda_codec_read(codec, nid, 0,
4452 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4453 /* outputs are only ports capable of power management
4454 * any attempts on powering down a input port cause the
4455 * referenced VREF to act quirky.
4456 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004457 if (pinctl & AC_PINCTL_IN_EN) {
4458 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004459 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004460 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004461 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004462 def_conf = get_defcfg_connect(def_conf);
4463 /* skip any ports that don't have jacks since presence
4464 * detection is useless */
4465 if (def_conf != AC_JACK_PORT_COMPLEX) {
4466 if (def_conf != AC_JACK_PORT_NONE)
4467 stac_toggle_power_map(codec, nid, 1);
4468 continue;
4469 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004470 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004471 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004472 continue;
4473 }
4474 /* none of the above, turn the port OFF */
4475 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004476 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004477
Takashi Iwaic21bd022010-02-08 15:16:08 +01004478 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004479 if (spec->gpio_led)
4480 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004481 if (spec->dac_list)
4482 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004483 return 0;
4484}
4485
Takashi Iwai603c4012008-07-30 15:01:44 +02004486static void stac92xx_free_kctls(struct hda_codec *codec)
4487{
4488 struct sigmatel_spec *spec = codec->spec;
4489
4490 if (spec->kctls.list) {
4491 struct snd_kcontrol_new *kctl = spec->kctls.list;
4492 int i;
4493 for (i = 0; i < spec->kctls.used; i++)
4494 kfree(kctl[i].name);
4495 }
4496 snd_array_free(&spec->kctls);
4497}
4498
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004499static void stac92xx_shutup_pins(struct hda_codec *codec)
4500{
4501 unsigned int i, def_conf;
4502
4503 if (codec->bus->shutdown)
4504 return;
4505 for (i = 0; i < codec->init_pins.used; i++) {
4506 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4507 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4508 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4509 snd_hda_codec_write(codec, pin->nid, 0,
4510 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4511 }
4512}
4513
Takashi Iwai167eae52009-11-06 15:47:50 +01004514static void stac92xx_shutup(struct hda_codec *codec)
4515{
4516 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004517
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004518 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004519
4520 if (spec->eapd_mask)
4521 stac_gpio_set(codec, spec->gpio_mask,
4522 spec->gpio_dir, spec->gpio_data &
4523 ~spec->eapd_mask);
4524}
4525
Matt2f2f4252005-04-13 14:45:30 +02004526static void stac92xx_free(struct hda_codec *codec)
4527{
Mattc7d4b2f2005-06-27 14:59:41 +02004528 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004529
4530 if (! spec)
4531 return;
4532
Takashi Iwai167eae52009-11-06 15:47:50 +01004533 stac92xx_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004534 snd_hda_input_jack_free(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004535 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004536
Mattc7d4b2f2005-06-27 14:59:41 +02004537 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004538 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004539}
4540
Matt4e550962005-07-04 17:51:39 +02004541static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4542 unsigned int flag)
4543{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004544 unsigned int old_ctl, pin_ctl;
4545
4546 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004547 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004548
Takashi Iwaif9acba42007-05-29 18:01:06 +02004549 if (pin_ctl & AC_PINCTL_IN_EN) {
4550 /*
4551 * we need to check the current set-up direction of
4552 * shared input pins since they can be switched via
4553 * "xxx as Output" mixer switch
4554 */
4555 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004556 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004557 return;
4558 }
4559
Takashi Iwai8ce84192009-01-22 16:59:20 +01004560 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004561 /* if setting pin direction bits, clear the current
4562 direction bits first */
4563 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4564 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4565
Takashi Iwai8ce84192009-01-22 16:59:20 +01004566 pin_ctl |= flag;
4567 if (old_ctl != pin_ctl)
4568 snd_hda_codec_write_cache(codec, nid, 0,
4569 AC_VERB_SET_PIN_WIDGET_CONTROL,
4570 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004571}
4572
4573static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4574 unsigned int flag)
4575{
4576 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4577 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004578 if (pin_ctl & flag)
4579 snd_hda_codec_write_cache(codec, nid, 0,
4580 AC_VERB_SET_PIN_WIDGET_CONTROL,
4581 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004582}
4583
Takashi Iwaid56757a2009-11-18 08:00:14 +01004584static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004585{
4586 if (!nid)
4587 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004588 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004589}
4590
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004591static void stac92xx_line_out_detect(struct hda_codec *codec,
4592 int presence)
4593{
4594 struct sigmatel_spec *spec = codec->spec;
4595 struct auto_pin_cfg *cfg = &spec->autocfg;
4596 int i;
4597
4598 for (i = 0; i < cfg->line_outs; i++) {
4599 if (presence)
4600 break;
4601 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4602 if (presence) {
4603 unsigned int pinctl;
4604 pinctl = snd_hda_codec_read(codec,
4605 cfg->line_out_pins[i], 0,
4606 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4607 if (pinctl & AC_PINCTL_IN_EN)
4608 presence = 0; /* mic- or line-input */
4609 }
4610 }
4611
4612 if (presence) {
4613 /* disable speakers */
4614 for (i = 0; i < cfg->speaker_outs; i++)
4615 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4616 AC_PINCTL_OUT_EN);
4617 if (spec->eapd_mask && spec->eapd_switch)
4618 stac_gpio_set(codec, spec->gpio_mask,
4619 spec->gpio_dir, spec->gpio_data &
4620 ~spec->eapd_mask);
4621 } else {
4622 /* enable speakers */
4623 for (i = 0; i < cfg->speaker_outs; i++)
4624 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4625 AC_PINCTL_OUT_EN);
4626 if (spec->eapd_mask && spec->eapd_switch)
4627 stac_gpio_set(codec, spec->gpio_mask,
4628 spec->gpio_dir, spec->gpio_data |
4629 spec->eapd_mask);
4630 }
4631}
4632
Takashi Iwaid7a89432008-11-12 09:48:04 +01004633/* return non-zero if the hp-pin of the given array index isn't
4634 * a jack-detection target
4635 */
4636static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4637{
4638 struct auto_pin_cfg *cfg = &spec->autocfg;
4639
4640 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004641 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004642 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004643 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004644 return 1;
4645 /* ignore if the pin is set as line-out */
4646 if (cfg->hp_pins[i] == spec->hp_switch)
4647 return 1;
4648 return 0;
4649}
4650
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004651static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004652{
4653 struct sigmatel_spec *spec = codec->spec;
4654 struct auto_pin_cfg *cfg = &spec->autocfg;
4655 int i, presence;
4656
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004657 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004658 if (spec->gpio_mute)
4659 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4660 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4661
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004662 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004663 if (presence)
4664 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004665 if (no_hp_sensing(spec, i))
4666 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004667 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4668 if (presence) {
4669 unsigned int pinctl;
4670 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4671 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4672 if (pinctl & AC_PINCTL_IN_EN)
4673 presence = 0; /* mic- or line-input */
4674 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004675 }
Matt4e550962005-07-04 17:51:39 +02004676
4677 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004678 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004679 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004680 stac92xx_reset_pinctl(codec, spec->hp_switch,
4681 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004682 for (i = 0; i < cfg->line_outs; i++)
4683 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4684 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004685 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004686 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004687 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004688 stac92xx_set_pinctl(codec, spec->hp_switch,
4689 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004690 for (i = 0; i < cfg->line_outs; i++)
4691 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4692 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004693 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004694 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004695 /* toggle hp outs */
4696 for (i = 0; i < cfg->hp_outs; i++) {
4697 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4698 if (no_hp_sensing(spec, i))
4699 continue;
4700 if (presence)
4701 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004702#if 0 /* FIXME */
4703/* Resetting the pinctl like below may lead to (a sort of) regressions
4704 * on some devices since they use the HP pin actually for line/speaker
4705 * outs although the default pin config shows a different pin (that is
4706 * wrong and useless).
4707 *
4708 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4709 * But, disabling the code below just works around it, and I'm too tired of
4710 * bug reports with such devices...
4711 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004712 else
4713 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004714#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004715 }
Matt4e550962005-07-04 17:51:39 +02004716}
4717
Takashi Iwaif73d3582008-11-25 08:21:51 +01004718static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4719 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004720{
4721 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004722 unsigned int idx, val;
4723
4724 for (idx = 0; idx < spec->num_pwrs; idx++) {
4725 if (spec->pwr_nids[idx] == nid)
4726 break;
4727 }
4728 if (idx >= spec->num_pwrs)
4729 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004730
Charles Chinafef2cf2011-11-11 08:05:28 +01004731 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004732
Takashi Iwaif73d3582008-11-25 08:21:51 +01004733 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4734 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004735 val &= ~idx;
4736 else
4737 val |= idx;
4738
4739 /* power down unused output ports */
4740 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004741}
4742
Takashi Iwaif73d3582008-11-25 08:21:51 +01004743static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4744{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004745 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004746}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004747
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004748/* get the pin connection (fixed, none, etc) */
4749static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4750{
4751 struct sigmatel_spec *spec = codec->spec;
4752 unsigned int cfg;
4753
4754 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4755 return get_defcfg_connect(cfg);
4756}
4757
4758static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02004759 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004760{
4761 struct sigmatel_spec *spec = codec->spec;
4762 int idx, num;
4763 unsigned int def_conf;
4764
4765 for (num = 0; num < num_nids; num++) {
4766 for (idx = 0; idx < spec->num_pins; idx++)
4767 if (spec->pin_nids[idx] == nids[num])
4768 break;
4769 if (idx >= spec->num_pins)
4770 break;
4771 def_conf = stac_get_defcfg_connect(codec, idx);
4772 if (def_conf == AC_JACK_PORT_NONE)
4773 break;
4774 }
4775 return num;
4776}
4777
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004778static void stac92xx_mic_detect(struct hda_codec *codec)
4779{
4780 struct sigmatel_spec *spec = codec->spec;
4781 struct sigmatel_mic_route *mic;
4782
4783 if (get_pin_presence(codec, spec->ext_mic.pin))
4784 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004785 else if (get_pin_presence(codec, spec->dock_mic.pin))
4786 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004787 else
4788 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004789 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004790 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4791 AC_VERB_SET_CONNECT_SEL,
4792 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004793 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004794 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4795 AC_VERB_SET_CONNECT_SEL,
4796 mic->mux_idx);
4797}
4798
Takashi Iwai62558ce2009-07-29 14:23:09 +02004799static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004800{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004801 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004802 if (!event)
4803 return;
4804 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4805}
4806
Takashi Iwai314634b2006-09-21 11:56:18 +02004807static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4808{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004809 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004810 struct sigmatel_event *event;
4811 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004812
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004813 tag = (res >> 26) & 0x7f;
4814 event = stac_get_event_from_tag(codec, tag);
4815 if (!event)
4816 return;
4817
4818 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004819 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004820 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004821 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004822 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004823 case STAC_MIC_EVENT:
4824 stac92xx_mic_detect(codec);
4825 break;
4826 }
4827
4828 switch (event->type) {
4829 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004830 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004831 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004832 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004833 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004834 if (spec->num_pwrs > 0)
4835 stac92xx_pin_sense(codec, event->nid);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004836 snd_hda_input_jack_report(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004837
4838 switch (codec->subsystem_id) {
4839 case 0x103c308f:
4840 if (event->nid == 0xb) {
4841 int pin = AC_PINCTL_IN_EN;
4842
4843 if (get_pin_presence(codec, 0xa)
4844 && get_pin_presence(codec, 0xb))
4845 pin |= AC_PINCTL_VREF_80;
4846 if (!get_pin_presence(codec, 0xb))
4847 pin |= AC_PINCTL_VREF_80;
4848
4849 /* toggle VREF state based on mic + hp pin
4850 * status
4851 */
4852 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4853 }
4854 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004855 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004856 case STAC_VREF_EVENT:
4857 data = snd_hda_codec_read(codec, codec->afg, 0,
4858 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004859 /* toggle VREF state based on GPIOx status */
4860 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004861 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004862 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004863 }
4864}
4865
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304866static int hp_blike_system(u32 subsystem_id);
4867
4868static void set_hp_led_gpio(struct hda_codec *codec)
4869{
4870 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004871 unsigned int gpio;
4872
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004873 if (spec->gpio_led)
4874 return;
4875
Takashi Iwai07f80442010-02-08 15:06:13 +01004876 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4877 gpio &= AC_GPIO_IO_COUNT;
4878 if (gpio > 3)
4879 spec->gpio_led = 0x08; /* GPIO 3 */
4880 else
4881 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304882}
4883
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004884/*
4885 * This method searches for the mute LED GPIO configuration
4886 * provided as OEM string in SMBIOS. The format of that string
4887 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4888 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4889 * that corresponds to the NOT muted state of the master volume
4890 * and G is the index of the GPIO to use as the mute LED control (0..9)
4891 * If _G portion is missing it is assigned based on the codec ID
4892 *
4893 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4894 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304895 *
4896 *
4897 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4898 * SMBIOS - at least the ones I have seen do not have them - which include
4899 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4900 * HP Pavilion dv9500t CTO.
4901 * Need more information on whether it is true across the entire series.
4902 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004903 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004904static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004905{
4906 struct sigmatel_spec *spec = codec->spec;
4907 const struct dmi_device *dev = NULL;
4908
4909 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4910 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4911 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004912 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304913 &spec->gpio_led_polarity,
4914 &spec->gpio_led) == 2) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004915 unsigned int max_gpio;
4916 max_gpio = snd_hda_param_read(codec, codec->afg,
4917 AC_PAR_GPIO_CAP);
4918 max_gpio &= AC_GPIO_IO_COUNT;
4919 if (spec->gpio_led < max_gpio)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004920 spec->gpio_led = 1 << spec->gpio_led;
Takashi Iwaif1a73742011-12-04 13:44:06 +01004921 else
4922 spec->vref_mute_led_nid = spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004923 return 1;
4924 }
4925 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304926 &spec->gpio_led_polarity) == 1) {
4927 set_hp_led_gpio(codec);
4928 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004929 }
4930 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304931
4932 /*
4933 * Fallback case - if we don't find the DMI strings,
4934 * we statically set the GPIO - if not a B-series system.
4935 */
4936 if (!hp_blike_system(codec->subsystem_id)) {
4937 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004938 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304939 return 1;
4940 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004941 }
4942 return 0;
4943}
4944
4945static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004946{
4947 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004948 case 0x103c1520:
4949 case 0x103c1521:
4950 case 0x103c1523:
4951 case 0x103c1524:
4952 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004953 case 0x103c1722:
4954 case 0x103c1723:
4955 case 0x103c1724:
4956 case 0x103c1725:
4957 case 0x103c1726:
4958 case 0x103c1727:
4959 case 0x103c1728:
4960 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004961 case 0x103c172a:
4962 case 0x103c172b:
4963 case 0x103c307e:
4964 case 0x103c307f:
4965 case 0x103c3080:
4966 case 0x103c3081:
4967 case 0x103c7007:
4968 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004969 return 1;
4970 }
4971 return 0;
4972}
4973
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004974#ifdef CONFIG_PROC_FS
4975static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4976 struct hda_codec *codec, hda_nid_t nid)
4977{
4978 if (nid == codec->afg)
4979 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4980 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4981}
4982
4983static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4984 struct hda_codec *codec,
4985 unsigned int verb)
4986{
4987 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4988 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4989}
4990
4991/* stac92hd71bxx, stac92hd73xx */
4992static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4993 struct hda_codec *codec, hda_nid_t nid)
4994{
4995 stac92hd_proc_hook(buffer, codec, nid);
4996 if (nid == codec->afg)
4997 analog_loop_proc_hook(buffer, codec, 0xfa0);
4998}
4999
5000static void stac9205_proc_hook(struct snd_info_buffer *buffer,
5001 struct hda_codec *codec, hda_nid_t nid)
5002{
5003 if (nid == codec->afg)
5004 analog_loop_proc_hook(buffer, codec, 0xfe0);
5005}
5006
5007static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5008 struct hda_codec *codec, hda_nid_t nid)
5009{
5010 if (nid == codec->afg)
5011 analog_loop_proc_hook(buffer, codec, 0xfeb);
5012}
5013#else
5014#define stac92hd_proc_hook NULL
5015#define stac92hd7x_proc_hook NULL
5016#define stac9205_proc_hook NULL
5017#define stac927x_proc_hook NULL
5018#endif
5019
Takashi Iwai2a439522011-07-26 09:52:50 +02005020#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005021static int stac92xx_resume(struct hda_codec *codec)
5022{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02005023 struct sigmatel_spec *spec = codec->spec;
5024
Takashi Iwai2c885872008-11-18 09:36:55 +01005025 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005026 snd_hda_codec_resume_amp(codec);
5027 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005028 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02005029 if (spec->hp_detect) {
5030 if (spec->autocfg.hp_pins[0])
5031 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
5032 else if (spec->autocfg.line_out_pins[0])
5033 stac_issue_unsol_event(codec,
5034 spec->autocfg.line_out_pins[0]);
5035 }
Mattff6fdc32005-06-27 15:06:52 +02005036 return 0;
5037}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005038
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005039static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5040{
5041 stac92xx_shutup(codec);
5042 return 0;
5043}
5044
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005045#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005046static int stac92xx_pre_resume(struct hda_codec *codec)
5047{
5048 struct sigmatel_spec *spec = codec->spec;
5049
5050 /* sync mute LED */
Takashi Iwaif1a73742011-12-04 13:44:06 +01005051 if (spec->vref_mute_led_nid)
5052 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5053 spec->vref_led);
5054 else if (spec->gpio_led)
5055 stac_gpio_set(codec, spec->gpio_mask,
5056 spec->gpio_dir, spec->gpio_data);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005057 return 0;
5058}
5059
5060static int stac92xx_post_suspend(struct hda_codec *codec)
5061{
5062 struct sigmatel_spec *spec = codec->spec;
5063 if (spec->gpio_led > 8) {
5064 /* with vref-out pin used for mute led control
5065 * codec AFG is prevented from D3 state, but on
5066 * system suspend it can (and should) be used
5067 */
5068 snd_hda_codec_read(codec, codec->afg, 0,
5069 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5070 }
5071 return 0;
5072}
5073
5074static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5075 unsigned int power_state)
5076{
5077 unsigned int afg_power_state = power_state;
5078 struct sigmatel_spec *spec = codec->spec;
5079
5080 if (power_state == AC_PWRST_D3) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005081 if (spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005082 /* with vref-out pin used for mute led control
5083 * codec AFG is prevented from D3 state
5084 */
5085 afg_power_state = AC_PWRST_D1;
5086 }
5087 /* this delay seems necessary to avoid click noise at power-down */
5088 msleep(100);
5089 }
5090 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5091 afg_power_state);
5092 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5093}
5094
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005095/*
5096 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5097 * as mute LED state is updated in check_power_status hook
5098 */
5099static int stac92xx_update_led_status(struct hda_codec *codec)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005100{
5101 struct sigmatel_spec *spec = codec->spec;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005102 int i, num_ext_dacs, muted = 1;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005103 unsigned int muted_lvl, notmtd_lvl;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005104 hda_nid_t nid;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005105
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005106 if (!spec->gpio_led)
5107 return 0;
5108
Takashi Iwaic21bd022010-02-08 15:16:08 +01005109 for (i = 0; i < spec->multiout.num_dacs; i++) {
5110 nid = spec->multiout.dac_nids[i];
5111 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5112 HDA_AMP_MUTE)) {
5113 muted = 0; /* something heard */
5114 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005115 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005116 }
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005117 if (muted && spec->multiout.hp_nid)
5118 if (!(snd_hda_codec_amp_read(codec,
5119 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5120 HDA_AMP_MUTE)) {
5121 muted = 0; /* HP is not muted */
5122 }
5123 num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5124 for (i = 0; muted && i < num_ext_dacs; i++) {
5125 nid = spec->multiout.extra_out_nid[i];
5126 if (nid == 0)
5127 break;
5128 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5129 HDA_AMP_MUTE)) {
5130 muted = 0; /* extra output is not muted */
5131 }
5132 }
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005133 /*polarity defines *not* muted state level*/
Takashi Iwaif1a73742011-12-04 13:44:06 +01005134 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005135 if (muted)
5136 spec->gpio_data &= ~spec->gpio_led; /* orange */
5137 else
5138 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005139
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005140 if (!spec->gpio_led_polarity) {
5141 /* LED state is inverted on these systems */
5142 spec->gpio_data ^= spec->gpio_led;
5143 }
5144 stac_gpio_set(codec, spec->gpio_mask,
5145 spec->gpio_dir, spec->gpio_data);
5146 } else {
5147 notmtd_lvl = spec->gpio_led_polarity ?
5148 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5149 muted_lvl = spec->gpio_led_polarity ?
5150 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5151 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005152 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5153 spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005154 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005155 return 0;
5156}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005157
5158/*
5159 * use power check for controlling mute led of HP notebooks
5160 */
5161static int stac92xx_check_power_status(struct hda_codec *codec,
5162 hda_nid_t nid)
5163{
5164 stac92xx_update_led_status(codec);
5165
5166 return 0;
5167}
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005168#endif /* CONFIG_SND_HDA_POWER_SAVE */
Takashi Iwai2a439522011-07-26 09:52:50 +02005169#endif /* CONFIG_PM */
Mattff6fdc32005-06-27 15:06:52 +02005170
Takashi Iwai2b635362011-05-02 12:33:43 +02005171static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005172 .build_controls = stac92xx_build_controls,
5173 .build_pcms = stac92xx_build_pcms,
5174 .init = stac92xx_init,
5175 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005176 .unsol_event = stac92xx_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005177#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005178 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005179 .resume = stac92xx_resume,
5180#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005181 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005182};
5183
5184static int patch_stac9200(struct hda_codec *codec)
5185{
5186 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005187 int err;
Matt2f2f4252005-04-13 14:45:30 +02005188
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005190 if (spec == NULL)
5191 return -ENOMEM;
5192
Takashi Iwaia252c812009-12-25 22:56:20 +01005193 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005194 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005195 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005196 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005197 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005198 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5199 stac9200_models,
5200 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005201 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005202 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5203 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005204 else
5205 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005206 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005207
5208 spec->multiout.max_channels = 2;
5209 spec->multiout.num_dacs = 1;
5210 spec->multiout.dac_nids = stac9200_dac_nids;
5211 spec->adc_nids = stac9200_adc_nids;
5212 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005213 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005214 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005215 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005216 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005217
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005218 if (spec->board_config == STAC_9200_M4 ||
5219 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005220 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005221 spec->init = stac9200_eapd_init;
5222 else
5223 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005224 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005225
Takashi Iwai117f2572008-03-18 09:53:23 +01005226 if (spec->board_config == STAC_9200_PANASONIC) {
5227 spec->gpio_mask = spec->gpio_dir = 0x09;
5228 spec->gpio_data = 0x00;
5229 }
5230
Mattc7d4b2f2005-06-27 14:59:41 +02005231 err = stac9200_parse_auto_config(codec);
5232 if (err < 0) {
5233 stac92xx_free(codec);
5234 return err;
5235 }
Matt2f2f4252005-04-13 14:45:30 +02005236
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005237 /* CF-74 has no headphone detection, and the driver should *NOT*
5238 * do detection and HP/speaker toggle because the hardware does it.
5239 */
5240 if (spec->board_config == STAC_9200_PANASONIC)
5241 spec->hp_detect = 0;
5242
Matt2f2f4252005-04-13 14:45:30 +02005243 codec->patch_ops = stac92xx_patch_ops;
5244
5245 return 0;
5246}
5247
Tobin Davis8e21c342007-01-08 11:04:17 +01005248static int patch_stac925x(struct hda_codec *codec)
5249{
5250 struct sigmatel_spec *spec;
5251 int err;
5252
5253 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5254 if (spec == NULL)
5255 return -ENOMEM;
5256
Takashi Iwaia252c812009-12-25 22:56:20 +01005257 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005258 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005259 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005260 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005261 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005262
5263 /* Check first for codec ID */
5264 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5265 STAC_925x_MODELS,
5266 stac925x_models,
5267 stac925x_codec_id_cfg_tbl);
5268
5269 /* Now checks for PCI ID, if codec ID is not found */
5270 if (spec->board_config < 0)
5271 spec->board_config = snd_hda_check_board_config(codec,
5272 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005273 stac925x_models,
5274 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005275 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005276 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005277 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5278 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005279 else
5280 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005281 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005282
5283 spec->multiout.max_channels = 2;
5284 spec->multiout.num_dacs = 1;
5285 spec->multiout.dac_nids = stac925x_dac_nids;
5286 spec->adc_nids = stac925x_adc_nids;
5287 spec->mux_nids = stac925x_mux_nids;
5288 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005289 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005290 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005291 switch (codec->vendor_id) {
5292 case 0x83847632: /* STAC9202 */
5293 case 0x83847633: /* STAC9202D */
5294 case 0x83847636: /* STAC9251 */
5295 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005296 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005297 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005298 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5299 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005300 break;
5301 default:
5302 spec->num_dmics = 0;
5303 break;
5304 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005305
5306 spec->init = stac925x_core_init;
5307 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005308 spec->num_caps = 1;
5309 spec->capvols = stac925x_capvols;
5310 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005311
Charles Chin9009b0e2011-11-03 10:27:27 +01005312 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005313 if (!err) {
5314 if (spec->board_config < 0) {
5315 printk(KERN_WARNING "hda_codec: No auto-config is "
5316 "available, default to model=ref\n");
5317 spec->board_config = STAC_925x_REF;
5318 goto again;
5319 }
5320 err = -EINVAL;
5321 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005322 if (err < 0) {
5323 stac92xx_free(codec);
5324 return err;
5325 }
5326
5327 codec->patch_ops = stac92xx_patch_ops;
5328
5329 return 0;
5330}
5331
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005332static int patch_stac92hd73xx(struct hda_codec *codec)
5333{
5334 struct sigmatel_spec *spec;
5335 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5336 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005337 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005338
5339 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5340 if (spec == NULL)
5341 return -ENOMEM;
5342
Takashi Iwaia252c812009-12-25 22:56:20 +01005343 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005344 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005345 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005346 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005347 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5348 spec->pin_nids = stac92hd73xx_pin_nids;
5349 spec->board_config = snd_hda_check_board_config(codec,
5350 STAC_92HD73XX_MODELS,
5351 stac92hd73xx_models,
5352 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005353 /* check codec subsystem id if not found */
5354 if (spec->board_config < 0)
5355 spec->board_config =
5356 snd_hda_check_board_codec_sid_config(codec,
5357 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5358 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005359again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005360 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005361 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5362 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005363 else
5364 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005365 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005366
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005367 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005368 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5369
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005370 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005371 printk(KERN_WARNING "hda_codec: Could not determine "
5372 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005373 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005374 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005375 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005376 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005377 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005378 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005379 break;
5380 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005381 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005382 break;
5383 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005384 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5385 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005386 }
5387 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005388
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005389 spec->aloopback_mask = 0x01;
5390 spec->aloopback_shift = 8;
5391
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005392 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005393 spec->mux_nids = stac92hd73xx_mux_nids;
5394 spec->adc_nids = stac92hd73xx_adc_nids;
5395 spec->dmic_nids = stac92hd73xx_dmic_nids;
5396 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005397 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005398
5399 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5400 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005401 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005402
Takashi Iwai6479c632009-07-28 18:20:25 +02005403 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5404 spec->capvols = stac92hd73xx_capvols;
5405 spec->capsws = stac92hd73xx_capsws;
5406
Matthew Ranostaya7662642008-02-21 07:51:14 +01005407 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005408 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005409 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005410 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005411 case STAC_DELL_M6_AMIC:
5412 case STAC_DELL_M6_DMIC:
5413 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005414 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005415 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005416
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005417 switch (spec->board_config) {
5418 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005419 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005420 spec->num_dmics = 0;
5421 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005422 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005423 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005424 spec->num_dmics = 1;
5425 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005426 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005427 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5428 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005429 spec->num_dmics = 1;
5430 break;
5431 }
5432 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005433 case STAC_ALIENWARE_M17X:
5434 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5435 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5436 spec->eapd_switch = 0;
5437 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005438 default:
5439 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005440 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005441 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005442 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005443 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005444 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005445 /* GPIO0 High = Enable EAPD */
5446 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5447 spec->gpio_data = 0x01;
5448 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005449
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005450 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5451 spec->pwr_nids = stac92hd73xx_pwr_nids;
5452
Charles Chin9009b0e2011-11-03 10:27:27 +01005453 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005454
5455 if (!err) {
5456 if (spec->board_config < 0) {
5457 printk(KERN_WARNING "hda_codec: No auto-config is "
5458 "available, default to model=ref\n");
5459 spec->board_config = STAC_92HD73XX_REF;
5460 goto again;
5461 }
5462 err = -EINVAL;
5463 }
5464
5465 if (err < 0) {
5466 stac92xx_free(codec);
5467 return err;
5468 }
5469
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005470 if (spec->board_config == STAC_92HD73XX_NO_JD)
5471 spec->hp_detect = 0;
5472
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005473 codec->patch_ops = stac92xx_patch_ops;
5474
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005475 codec->proc_widget_hook = stac92hd7x_proc_hook;
5476
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005477 return 0;
5478}
5479
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005480static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005481{
5482 if (codec->vendor_id != 0x111d7605 &&
5483 codec->vendor_id != 0x111d76d1)
5484 return 0;
5485
5486 switch (codec->subsystem_id) {
5487 case 0x103c1618:
5488 case 0x103c1619:
5489 case 0x103c161a:
5490 case 0x103c161b:
5491 case 0x103c161c:
5492 case 0x103c161d:
5493 case 0x103c161e:
5494 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005495
5496 case 0x103c162a:
5497 case 0x103c162b:
5498
5499 case 0x103c1630:
5500 case 0x103c1631:
5501
5502 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005503 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005504 case 0x103c1635:
5505
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005506 case 0x103c3587:
5507 case 0x103c3588:
5508 case 0x103c3589:
5509 case 0x103c358a:
5510
5511 case 0x103c3667:
5512 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005513 case 0x103c3669:
5514
5515 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005516 }
5517 return 0;
5518}
5519
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005520static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5521{
5522 struct sigmatel_spec *spec = codec->spec;
5523 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5524 int i;
5525
5526 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5527 spec->auto_pin_cnt++;
5528
5529 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5530 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5531 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5532 if (nid == stac92hd83xxx_dmic_nids[i]) {
5533 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5534 spec->auto_dmic_cnt++;
5535 }
5536 }
5537 }
5538}
5539
5540static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5541{
5542 struct sigmatel_spec *spec = codec->spec;
5543
5544 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5545 spec->auto_adc_cnt++;
5546}
5547
5548static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5549{
5550 int i, j;
5551 struct sigmatel_spec *spec = codec->spec;
5552
5553 for (i = 0; i < spec->auto_adc_cnt; i++) {
5554 if (get_connection_index(codec,
5555 spec->auto_adc_nids[i], nid) >= 0) {
5556 /* mux and volume for adc_nids[i] */
5557 if (!spec->auto_mux_nids[i]) {
5558 spec->auto_mux_nids[i] = nid;
5559 /* 92hd codecs capture volume is in mux */
5560 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5561 3, 0, HDA_OUTPUT);
5562 }
5563 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5564 if (get_connection_index(codec, nid,
5565 spec->auto_dmic_nids[j]) >= 0) {
5566 /* dmux for adc_nids[i] */
5567 if (!spec->auto_dmux_nids[i])
5568 spec->auto_dmux_nids[i] = nid;
5569 break;
5570 }
5571 }
5572 break;
5573 }
5574 }
5575}
5576
5577static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5578{
5579 hda_nid_t nid, end_nid;
5580 unsigned int wid_caps, wid_type;
5581 struct sigmatel_spec *spec = codec->spec;
5582
5583 end_nid = codec->start_nid + codec->num_nodes;
5584
5585 for (nid = codec->start_nid; nid < end_nid; nid++) {
5586 wid_caps = get_wcaps(codec, nid);
5587 wid_type = get_wcaps_type(wid_caps);
5588
5589 if (wid_type == AC_WID_PIN)
5590 stac92hd8x_add_pin(codec, nid);
5591
5592 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5593 stac92hd8x_add_adc(codec, nid);
5594 }
5595
5596 for (nid = codec->start_nid; nid < end_nid; nid++) {
5597 wid_caps = get_wcaps(codec, nid);
5598 wid_type = get_wcaps_type(wid_caps);
5599
5600 if (wid_type == AC_WID_AUD_SEL)
5601 stac92hd8x_add_mux(codec, nid);
5602 }
5603
5604 spec->pin_nids = spec->auto_pin_nids;
5605 spec->num_pins = spec->auto_pin_cnt;
5606 spec->adc_nids = spec->auto_adc_nids;
5607 spec->num_adcs = spec->auto_adc_cnt;
5608 spec->capvols = spec->auto_capvols;
5609 spec->capsws = spec->auto_capvols;
5610 spec->num_caps = spec->auto_adc_cnt;
5611 spec->mux_nids = spec->auto_mux_nids;
5612 spec->num_muxes = spec->auto_adc_cnt;
5613 spec->dmux_nids = spec->auto_dmux_nids;
5614 spec->num_dmuxes = spec->auto_adc_cnt;
5615 spec->dmic_nids = spec->auto_dmic_nids;
5616 spec->num_dmics = spec->auto_dmic_cnt;
5617}
5618
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005619static int patch_stac92hd83xxx(struct hda_codec *codec)
5620{
5621 struct sigmatel_spec *spec;
5622 int err;
5623
5624 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5625 if (spec == NULL)
5626 return -ENOMEM;
5627
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005628 if (hp_bnb2011_with_dock(codec)) {
5629 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5630 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5631 }
5632
Takashi Iwaia252c812009-12-25 22:56:20 +01005633 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005634 codec->spec = spec;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005635
5636 stac92hd8x_fill_auto_spec(codec);
5637
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005638 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005639 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005640 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005641 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005642 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005643 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005644 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005645
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005646 spec->board_config = snd_hda_check_board_config(codec,
5647 STAC_92HD83XXX_MODELS,
5648 stac92hd83xxx_models,
5649 stac92hd83xxx_cfg_tbl);
5650again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005651 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005652 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5653 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005654 else
5655 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005656 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005657
Takashi Iwaib4e81872009-11-18 17:20:24 +01005658 codec->patch_ops = stac92xx_patch_ops;
5659
Takashi Iwaidce17d42010-02-09 09:25:26 +01005660 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005661 snd_printd("mute LED gpio %d polarity %d\n",
5662 spec->gpio_led,
5663 spec->gpio_led_polarity);
5664
Takashi Iwaib4e81872009-11-18 17:20:24 +01005665#ifdef CONFIG_SND_HDA_POWER_SAVE
5666 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005667 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005668 spec->gpio_mask |= spec->gpio_led;
5669 spec->gpio_dir |= spec->gpio_led;
5670 spec->gpio_data |= spec->gpio_led;
5671 } else {
5672 codec->patch_ops.set_power_state =
5673 stac92xx_set_power_state;
5674 codec->patch_ops.post_suspend =
5675 stac92xx_post_suspend;
5676 }
5677 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005678 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005679 stac92xx_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005680 }
5681#endif
5682
Charles Chin9009b0e2011-11-03 10:27:27 +01005683 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005684 if (!err) {
5685 if (spec->board_config < 0) {
5686 printk(KERN_WARNING "hda_codec: No auto-config is "
5687 "available, default to model=ref\n");
5688 spec->board_config = STAC_92HD83XXX_REF;
5689 goto again;
5690 }
5691 err = -EINVAL;
5692 }
5693
5694 if (err < 0) {
5695 stac92xx_free(codec);
5696 return err;
5697 }
5698
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005699 codec->proc_widget_hook = stac92hd_proc_hook;
5700
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005701 return 0;
5702}
5703
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005704static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5705 hda_nid_t dig0pin)
5706{
5707 struct sigmatel_spec *spec = codec->spec;
5708 int idx;
5709
5710 for (idx = 0; idx < spec->num_pins; idx++)
5711 if (spec->pin_nids[idx] == dig0pin)
5712 break;
5713 if ((idx + 2) >= spec->num_pins)
5714 return 0;
5715
5716 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005717 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005718 return 2;
5719
5720 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005721 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005722 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005723 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005724 return 1;
5725 else
5726 return 0;
5727}
5728
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005729/* HP dv7 bass switch - GPIO5 */
5730#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5731static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5732 struct snd_ctl_elem_value *ucontrol)
5733{
5734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5735 struct sigmatel_spec *spec = codec->spec;
5736 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5737 return 0;
5738}
5739
5740static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5741 struct snd_ctl_elem_value *ucontrol)
5742{
5743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5744 struct sigmatel_spec *spec = codec->spec;
5745 unsigned int gpio_data;
5746
5747 gpio_data = (spec->gpio_data & ~0x20) |
5748 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5749 if (gpio_data == spec->gpio_data)
5750 return 0;
5751 spec->gpio_data = gpio_data;
5752 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5753 return 1;
5754}
5755
Takashi Iwai2b635362011-05-02 12:33:43 +02005756static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5758 .info = stac_hp_bass_gpio_info,
5759 .get = stac_hp_bass_gpio_get,
5760 .put = stac_hp_bass_gpio_put,
5761};
5762
5763static int stac_add_hp_bass_switch(struct hda_codec *codec)
5764{
5765 struct sigmatel_spec *spec = codec->spec;
5766
5767 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5768 "Bass Speaker Playback Switch", 0))
5769 return -ENOMEM;
5770
5771 spec->gpio_mask |= 0x20;
5772 spec->gpio_dir |= 0x20;
5773 spec->gpio_data |= 0x20;
5774 return 0;
5775}
5776
Matthew Ranostaye035b842007-11-06 11:53:55 +01005777static int patch_stac92hd71bxx(struct hda_codec *codec)
5778{
5779 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005780 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005781 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005782 int err = 0;
5783
5784 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5785 if (spec == NULL)
5786 return -ENOMEM;
5787
Takashi Iwaia252c812009-12-25 22:56:20 +01005788 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005789 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005790 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005791 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005792 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5793 switch (codec->vendor_id) {
5794 case 0x111d76b6:
5795 case 0x111d76b7:
5796 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5797 break;
5798 case 0x111d7603:
5799 case 0x111d7608:
5800 /* On 92HD75Bx 0x27 isn't a pin nid */
5801 spec->num_pins--;
5802 /* fallthrough */
5803 default:
5804 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5805 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005806 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005807 spec->board_config = snd_hda_check_board_config(codec,
5808 STAC_92HD71BXX_MODELS,
5809 stac92hd71bxx_models,
5810 stac92hd71bxx_cfg_tbl);
5811again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005812 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005813 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5814 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005815 else
5816 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005817 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005818
Takashi Iwaifc64b262009-09-14 15:33:01 +02005819 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005820 /* GPIO0 = EAPD */
5821 spec->gpio_mask = 0x01;
5822 spec->gpio_dir = 0x01;
5823 spec->gpio_data = 0x01;
5824 }
5825
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005826 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5827 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5828
Takashi Iwai6479c632009-07-28 18:20:25 +02005829 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5830 spec->capvols = stac92hd71bxx_capvols;
5831 spec->capsws = stac92hd71bxx_capsws;
5832
Matthew Ranostay541eee82007-12-14 12:08:04 +01005833 switch (codec->vendor_id) {
5834 case 0x111d76b6: /* 4 Port without Analog Mixer */
5835 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005836 unmute_init++;
5837 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005838 case 0x111d76b4: /* 6 Port without Analog Mixer */
5839 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005840 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005841 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005842 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005843 stac92hd71bxx_dmic_nids,
5844 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005845 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005846 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005847 switch (spec->board_config) {
5848 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005849 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005850 err = stac_add_event(spec, codec->afg,
5851 STAC_VREF_EVENT, 0x02);
5852 if (err < 0)
5853 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005854 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005855 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5856 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005857 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005858 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005859 spec->gpio_mask |= 0x02;
5860 break;
5861 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005862 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005863 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005864 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005865
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005866 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005867 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005868 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005869 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5870 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02005871 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005872 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005873 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005874 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005875 break;
5876 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005877 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005878 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005879
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005880 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005881 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005882 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005883 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005884 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005885 stac92hd71bxx_dmic_nids,
5886 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005887 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005888 }
5889
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005890 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5891 snd_hda_sequence_write_cache(codec, unmute_init);
5892
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005893 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005894 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005895 spec->aloopback_shift = 0;
5896
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005897 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005898 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005899 spec->mux_nids = stac92hd71bxx_mux_nids;
5900 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005901 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005902 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005903
5904 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5905 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005906 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005907 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005908
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305909 snd_printdd("Found board config: %d\n", spec->board_config);
5910
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005911 switch (spec->board_config) {
5912 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005913 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005914 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005915 stac92xx_auto_set_pinctl(codec, 0x0e,
5916 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005917 /* fallthru */
5918 case STAC_DELL_M4_2:
5919 spec->num_dmics = 0;
5920 spec->num_smuxes = 0;
5921 spec->num_dmuxes = 0;
5922 break;
5923 case STAC_DELL_M4_1:
5924 case STAC_DELL_M4_3:
5925 spec->num_dmics = 1;
5926 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005927 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005928 break;
James Gardiner514bf542009-05-03 04:00:44 -04005929 case STAC_HP_DV4_1222NR:
5930 spec->num_dmics = 1;
5931 /* I don't know if it needs 1 or 2 smuxes - will wait for
5932 * bug reports to fix if needed
5933 */
5934 spec->num_smuxes = 1;
5935 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005936 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005937 case STAC_HP_DV4:
5938 spec->gpio_led = 0x01;
5939 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005940 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005941 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005942 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005943 /* HP dv6 gives the headphone pin as a line-out. Thus we
5944 * need to set hp_detect flag here to force to enable HP
5945 * detection.
5946 */
5947 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005948 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005949 case STAC_HP_HDX:
5950 spec->num_dmics = 1;
5951 spec->num_dmuxes = 1;
5952 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005953 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005954 break;
5955 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005956
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005957 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005958 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5959 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5960 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5961 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5962 /* It was changed in the BIOS to just satisfy MS DTM.
5963 * Lets turn it back into slaved HP
5964 */
5965 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5966 | (AC_JACK_HP_OUT <<
5967 AC_DEFCFG_DEVICE_SHIFT);
5968 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5969 | AC_DEFCFG_SEQUENCE)))
5970 | 0x1f;
5971 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5972 }
5973 }
5974
Takashi Iwaidce17d42010-02-09 09:25:26 +01005975 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005976 snd_printd("mute LED gpio %d polarity %d\n",
5977 spec->gpio_led,
5978 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005979
Takashi Iwai86d190e2009-05-26 15:18:58 +02005980#ifdef CONFIG_SND_HDA_POWER_SAVE
5981 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005982 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005983 spec->gpio_mask |= spec->gpio_led;
5984 spec->gpio_dir |= spec->gpio_led;
5985 spec->gpio_data |= spec->gpio_led;
5986 } else {
5987 codec->patch_ops.set_power_state =
5988 stac92xx_set_power_state;
5989 codec->patch_ops.post_suspend =
5990 stac92xx_post_suspend;
5991 }
5992 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005993 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005994 stac92xx_check_power_status;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005995 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005996#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005997
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005998 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005999
Charles Chin9009b0e2011-11-03 10:27:27 +01006000 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006001 if (!err) {
6002 if (spec->board_config < 0) {
6003 printk(KERN_WARNING "hda_codec: No auto-config is "
6004 "available, default to model=ref\n");
6005 spec->board_config = STAC_92HD71BXX_REF;
6006 goto again;
6007 }
6008 err = -EINVAL;
6009 }
6010
6011 if (err < 0) {
6012 stac92xx_free(codec);
6013 return err;
6014 }
6015
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006016 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006017 if (spec->board_config == STAC_HP_DV4 ||
6018 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006019 unsigned int cap;
6020 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6021 cap &= AC_GPIO_IO_COUNT;
6022 if (cap >= 6)
6023 stac_add_hp_bass_switch(codec);
6024 }
6025
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006026 codec->proc_widget_hook = stac92hd7x_proc_hook;
6027
Matthew Ranostaye035b842007-11-06 11:53:55 +01006028 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006029}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006030
Matt2f2f4252005-04-13 14:45:30 +02006031static int patch_stac922x(struct hda_codec *codec)
6032{
6033 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006034 int err;
Matt2f2f4252005-04-13 14:45:30 +02006035
Takashi Iwaie560d8d2005-09-09 14:21:46 +02006036 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02006037 if (spec == NULL)
6038 return -ENOMEM;
6039
Takashi Iwaia252c812009-12-25 22:56:20 +01006040 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02006041 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006042 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006043 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006044 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006045 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6046 stac922x_models,
6047 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006048 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006049 spec->gpio_mask = spec->gpio_dir = 0x03;
6050 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006051 /* Intel Macs have all same PCI SSID, so we need to check
6052 * codec SSID to distinguish the exact models
6053 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006054 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006055 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006056
6057 case 0x106b0800:
6058 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006059 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006060 case 0x106b0600:
6061 case 0x106b0700:
6062 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006063 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006064 case 0x106b0e00:
6065 case 0x106b0f00:
6066 case 0x106b1600:
6067 case 0x106b1700:
6068 case 0x106b0200:
6069 case 0x106b1e00:
6070 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006071 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006072 case 0x106b1a00:
6073 case 0x00000100:
6074 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006075 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006076 case 0x106b0a00:
6077 case 0x106b2200:
6078 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006079 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006080 default:
6081 spec->board_config = STAC_INTEL_MAC_V3;
6082 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006083 }
6084 }
6085
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006086 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006087 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006088 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6089 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006090 else
6091 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006092 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006093
Matt2f2f4252005-04-13 14:45:30 +02006094 spec->adc_nids = stac922x_adc_nids;
6095 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006096 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006097 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006098 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006099 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006100
6101 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006102
6103 spec->num_caps = STAC922X_NUM_CAPS;
6104 spec->capvols = stac922x_capvols;
6105 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006106
6107 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006108
Charles Chin9009b0e2011-11-03 10:27:27 +01006109 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006110 if (!err) {
6111 if (spec->board_config < 0) {
6112 printk(KERN_WARNING "hda_codec: No auto-config is "
6113 "available, default to model=ref\n");
6114 spec->board_config = STAC_D945_REF;
6115 goto again;
6116 }
6117 err = -EINVAL;
6118 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006119 if (err < 0) {
6120 stac92xx_free(codec);
6121 return err;
6122 }
6123
6124 codec->patch_ops = stac92xx_patch_ops;
6125
Takashi Iwai807a46362007-05-29 19:01:37 +02006126 /* Fix Mux capture level; max to 2 */
6127 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6128 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6129 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6130 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6131 (0 << AC_AMPCAP_MUTE_SHIFT));
6132
Matt Porter3cc08dc2006-01-23 15:27:49 +01006133 return 0;
6134}
6135
6136static int patch_stac927x(struct hda_codec *codec)
6137{
6138 struct sigmatel_spec *spec;
6139 int err;
6140
6141 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6142 if (spec == NULL)
6143 return -ENOMEM;
6144
Takashi Iwaia252c812009-12-25 22:56:20 +01006145 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006146 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006147 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006148 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006149 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006150 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006151 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6152 stac927x_models,
6153 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006154 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006155 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006156 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6157 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006158 else
6159 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006160 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006161
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006162 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006163 spec->adc_nids = stac927x_adc_nids;
6164 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6165 spec->mux_nids = stac927x_mux_nids;
6166 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006167 spec->smux_nids = stac927x_smux_nids;
6168 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006169 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006170 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006171 spec->multiout.dac_nids = spec->dac_nids;
6172
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006173 if (spec->board_config != STAC_D965_REF) {
6174 /* GPIO0 High = Enable EAPD */
6175 spec->eapd_mask = spec->gpio_mask = 0x01;
6176 spec->gpio_dir = spec->gpio_data = 0x01;
6177 }
6178
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006179 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006180 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006181 case STAC_D965_5ST:
6182 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006183 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006184 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006185 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006186 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006187 switch (codec->subsystem_id) {
6188 case 0x10280209:
6189 case 0x1028022e:
6190 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006191 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006192 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006193 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006194 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006195 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006196 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006197 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006198 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006199 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006200 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006201 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006202 if (codec->subsystem_id != 0x1028022f) {
6203 /* GPIO2 High = Enable EAPD */
6204 spec->eapd_mask = spec->gpio_mask = 0x04;
6205 spec->gpio_dir = spec->gpio_data = 0x04;
6206 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006207 spec->dmic_nids = stac927x_dmic_nids;
6208 spec->num_dmics = STAC927X_NUM_DMICS;
6209
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006210 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006211 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006212 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006213 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006214 case STAC_927X_VOLKNOB:
6215 spec->num_dmics = 0;
6216 spec->init = stac927x_volknob_core_init;
6217 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006218 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006219 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006220 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006221 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006222 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006223
Takashi Iwai6479c632009-07-28 18:20:25 +02006224 spec->num_caps = STAC927X_NUM_CAPS;
6225 spec->capvols = stac927x_capvols;
6226 spec->capsws = stac927x_capsws;
6227
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006228 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006229 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006230 spec->aloopback_mask = 0x40;
6231 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006232 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006233
Charles Chin9009b0e2011-11-03 10:27:27 +01006234 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006235 if (!err) {
6236 if (spec->board_config < 0) {
6237 printk(KERN_WARNING "hda_codec: No auto-config is "
6238 "available, default to model=ref\n");
6239 spec->board_config = STAC_D965_REF;
6240 goto again;
6241 }
6242 err = -EINVAL;
6243 }
Mattc7d4b2f2005-06-27 14:59:41 +02006244 if (err < 0) {
6245 stac92xx_free(codec);
6246 return err;
6247 }
Matt2f2f4252005-04-13 14:45:30 +02006248
6249 codec->patch_ops = stac92xx_patch_ops;
6250
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006251 codec->proc_widget_hook = stac927x_proc_hook;
6252
Takashi Iwai52987652008-01-16 16:09:47 +01006253 /*
6254 * !!FIXME!!
6255 * The STAC927x seem to require fairly long delays for certain
6256 * command sequences. With too short delays (even if the answer
6257 * is set to RIRB properly), it results in the silence output
6258 * on some hardwares like Dell.
6259 *
6260 * The below flag enables the longer delay (see get_response
6261 * in hda_intel.c).
6262 */
6263 codec->bus->needs_damn_long_delay = 1;
6264
Takashi Iwaie28d8322008-12-17 13:48:29 +01006265 /* no jack detecion for ref-no-jd model */
6266 if (spec->board_config == STAC_D965_REF_NO_JD)
6267 spec->hp_detect = 0;
6268
Matt2f2f4252005-04-13 14:45:30 +02006269 return 0;
6270}
6271
Matt Porterf3302a52006-07-31 12:49:34 +02006272static int patch_stac9205(struct hda_codec *codec)
6273{
6274 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006275 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006276
6277 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6278 if (spec == NULL)
6279 return -ENOMEM;
6280
Takashi Iwaia252c812009-12-25 22:56:20 +01006281 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006282 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006283 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006284 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006285 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006286 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6287 stac9205_models,
6288 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006289 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006290 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006291 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6292 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006293 else
6294 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006295 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006296
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006297 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006298 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006299 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006300 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006301 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006302 spec->smux_nids = stac9205_smux_nids;
6303 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006304 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006305 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006306 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006307 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006308 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006309
6310 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006311 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006312
Takashi Iwai6479c632009-07-28 18:20:25 +02006313 spec->num_caps = STAC9205_NUM_CAPS;
6314 spec->capvols = stac9205_capvols;
6315 spec->capsws = stac9205_capsws;
6316
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006317 spec->aloopback_mask = 0x40;
6318 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006319 /* Turn on/off EAPD per HP plugging */
6320 if (spec->board_config != STAC_9205_EAPD)
6321 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006322 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006323
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006324 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006325 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006326 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006327 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6328 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006329
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006330 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006331 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6332 if (err < 0)
6333 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006334 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006335 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6336 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006337 AC_VERB_SET_UNSOLICITED_ENABLE,
6338 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006339
6340 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006341 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006342 spec->gpio_mask = 0x1b;
6343 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006344 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006345 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006346 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006347 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006348 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006349 case STAC_9205_REF:
6350 /* SPDIF-In enabled */
6351 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006352 default:
6353 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006354 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006355 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006356 break;
6357 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006358
Charles Chin9009b0e2011-11-03 10:27:27 +01006359 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006360 if (!err) {
6361 if (spec->board_config < 0) {
6362 printk(KERN_WARNING "hda_codec: No auto-config is "
6363 "available, default to model=ref\n");
6364 spec->board_config = STAC_9205_REF;
6365 goto again;
6366 }
6367 err = -EINVAL;
6368 }
Matt Porterf3302a52006-07-31 12:49:34 +02006369 if (err < 0) {
6370 stac92xx_free(codec);
6371 return err;
6372 }
6373
6374 codec->patch_ops = stac92xx_patch_ops;
6375
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006376 codec->proc_widget_hook = stac9205_proc_hook;
6377
Matt Porterf3302a52006-07-31 12:49:34 +02006378 return 0;
6379}
6380
Matt2f2f4252005-04-13 14:45:30 +02006381/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006382 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006383 */
6384
Takashi Iwai2b635362011-05-02 12:33:43 +02006385static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006386 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006387 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6388 {}
6389};
6390
Takashi Iwai2b635362011-05-02 12:33:43 +02006391static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006392 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6393 0x11, 0x13, 0x14,
6394};
6395
Takashi Iwai2b635362011-05-02 12:33:43 +02006396static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006397 0x8 /*,0x6*/
6398};
6399
Takashi Iwai2b635362011-05-02 12:33:43 +02006400static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006401 0x15
6402};
6403
Takashi Iwai2b635362011-05-02 12:33:43 +02006404static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006405 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6406};
6407#define stac9872_capsws stac9872_capvols
6408
Takashi Iwai2b635362011-05-02 12:33:43 +02006409static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006410 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6411 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6412 0x90a7013e
6413};
6414
Takashi Iwaiea734962011-01-17 11:29:34 +01006415static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006416 [STAC_9872_AUTO] = "auto",
6417 [STAC_9872_VAIO] = "vaio",
6418};
6419
Takashi Iwai2b635362011-05-02 12:33:43 +02006420static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006421 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6422};
6423
Takashi Iwai2b635362011-05-02 12:33:43 +02006424static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006425 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6426 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006427 {} /* terminator */
6428};
6429
Guillaume Munch6d859062006-08-22 17:15:47 +02006430static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006431{
6432 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006433 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006434
Takashi Iwaidb064e52006-03-16 16:04:58 +01006435 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6436 if (spec == NULL)
6437 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006438 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006439 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006440 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006441 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6442 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006443
6444 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6445 stac9872_models,
6446 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006447 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006448 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6449 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006450 else
6451 stac92xx_set_config_regs(codec,
6452 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006453
Takashi Iwai1e137f92009-01-21 07:41:22 +01006454 spec->multiout.dac_nids = spec->dac_nids;
6455 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6456 spec->adc_nids = stac9872_adc_nids;
6457 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6458 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006459 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006460 spec->num_caps = 1;
6461 spec->capvols = stac9872_capvols;
6462 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006463
Charles Chin9009b0e2011-11-03 10:27:27 +01006464 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006465 if (err < 0) {
6466 stac92xx_free(codec);
6467 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006468 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006469 spec->input_mux = &spec->private_imux;
6470 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006471 return 0;
6472}
6473
6474
6475/*
Matt2f2f4252005-04-13 14:45:30 +02006476 * patch entries
6477 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006478static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006479 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6480 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6481 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6482 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6483 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6484 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6485 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006486 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6487 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6488 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6489 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6490 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6491 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006492 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6493 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6494 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6495 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6496 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6497 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6498 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6499 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6500 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6501 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006502 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6503 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6504 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6505 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6506 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6507 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006508 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6509 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006510 /* The following does not take into account .id=0x83847661 when subsys =
6511 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6512 * currently not fully supported.
6513 */
6514 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6515 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6516 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006517 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006518 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6519 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6520 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6521 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6522 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6523 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6524 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6525 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006526 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006527 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006528 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006529 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006530 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006531 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6532 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006533 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6534 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6535 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6536 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006537 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006538 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6539 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006540 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006541 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6542 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6543 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6544 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6545 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6546 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6547 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6548 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006549 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6550 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6551 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6552 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6553 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6554 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6555 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6556 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6557 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6558 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6559 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6560 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6561 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6562 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6563 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006564 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006565 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006566 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6567 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006568 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006569 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6570 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6571 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6572 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6573 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6574 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6575 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6576 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6577 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6578 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6579 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6580 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006581 {} /* terminator */
6582};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006583
6584MODULE_ALIAS("snd-hda-codec-id:8384*");
6585MODULE_ALIAS("snd-hda-codec-id:111d*");
6586
6587MODULE_LICENSE("GPL");
6588MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6589
6590static struct hda_codec_preset_list sigmatel_list = {
6591 .preset = snd_hda_preset_sigmatel,
6592 .owner = THIS_MODULE,
6593};
6594
6595static int __init patch_sigmatel_init(void)
6596{
6597 return snd_hda_add_codec_preset(&sigmatel_list);
6598}
6599
6600static void __exit patch_sigmatel_exit(void)
6601{
6602 snd_hda_delete_codec_preset(&sigmatel_list);
6603}
6604
6605module_init(patch_sigmatel_init)
6606module_exit(patch_sigmatel_exit)