blob: 6e04c2bf06de47b1b1a267d773cebec8be6a59c6 [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Tobin Davisc9b443d2006-11-14 12:13:39 +010028#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010029#include <sound/jack.h>
30
Tobin Davisc9b443d2006-11-14 12:13:39 +010031#include "hda_codec.h"
32#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020033#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020034#include "hda_jack.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010035
36#define CXT_PIN_DIR_IN 0x00
37#define CXT_PIN_DIR_OUT 0x01
38#define CXT_PIN_DIR_INOUT 0x02
39#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
40#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
41
42#define CONEXANT_HP_EVENT 0x37
43#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020044#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010045
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010047
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010048#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010049#define CXT5051_PORTB_EVENT 0x38
50#define CXT5051_PORTC_EVENT 0x39
51
Takashi Iwaifaddaa52010-01-23 22:31:36 +010052#define AUTO_MIC_PORTB (1 << 1)
53#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010054
Takashi Iwaif2e57312010-09-15 10:07:08 +020055struct pin_dac_pair {
56 hda_nid_t pin;
57 hda_nid_t dac;
58 int type;
59};
60
Takashi Iwai47ad1f42011-05-17 09:15:55 +020061struct imux_info {
62 hda_nid_t pin; /* input pin NID */
63 hda_nid_t adc; /* connected ADC NID */
64 hda_nid_t boost; /* optional boost volume NID */
65 int index; /* corresponding to autocfg.input */
66};
67
Tobin Davisc9b443d2006-11-14 12:13:39 +010068struct conexant_spec {
69
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020070 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010071 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010072 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +010073 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaif29735c2012-03-13 07:55:10 +010074 bool vmaster_mute_led;
Tobin Davisc9b443d2006-11-14 12:13:39 +010075
76 const struct hda_verb *init_verbs[5]; /* initialization verbs
77 * don't forget NULL
78 * termination!
79 */
80 unsigned int num_init_verbs;
81
82 /* playback */
83 struct hda_multi_out multiout; /* playback set-up
84 * max_channels, dacs must be set
85 * dig_out_nid and hp_nid are optional
86 */
87 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010088 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020089 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010090 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020091 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020092 int auto_mic_dock; /* imux_pins[] index for dock mic */
93 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050095 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010096
97 /* capture */
98 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020099 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100100 hda_nid_t dig_in_nid; /* digital-in NID; optional */
101
Takashi Iwai461e2c72008-01-25 11:35:17 +0100102 unsigned int cur_adc_idx;
103 hda_nid_t cur_adc;
104 unsigned int cur_adc_stream_tag;
105 unsigned int cur_adc_format;
106
Takashi Iwai6764bce2011-05-13 16:52:25 +0200107 const struct hda_pcm_stream *capture_stream;
108
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109 /* capture source */
110 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200111 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100112 unsigned int cur_mux[3];
113
114 /* channel model */
115 const struct hda_channel_mode *channel_mode;
116 int num_channel_mode;
117
118 /* PCM information */
119 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
120
Tobin Davisc9b443d2006-11-14 12:13:39 +0100121 unsigned int spdif_route;
122
123 /* dynamic controls, init_verbs and input_mux */
124 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100125 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200126 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200127 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200128 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200129 struct pin_dac_pair dac_info[8];
130 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100131
Daniel Drake0fb67e92009-07-16 14:46:57 +0100132 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200133 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200134 unsigned int detect_line:1; /* Line-out detection enabled */
135 unsigned int automute_lines:1; /* automute line-out as well */
136 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200137 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500138 unsigned int dell_vostro:1;
139 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200140 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200141 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100142 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200143 unsigned int pin_eapd_ctrls:1;
David Henningsson18dcd302012-04-02 15:40:27 +0200144 unsigned int fixup_stereo_dmic:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100145
Takashi Iwai6764bce2011-05-13 16:52:25 +0200146 unsigned int adc_switching:1;
147
Daniel Drake75f89912010-01-07 13:46:25 +0100148 unsigned int ext_mic_present;
149 unsigned int recording;
150 void (*capture_prepare)(struct hda_codec *codec);
151 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100152
153 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
154 * through the microphone jack.
155 * When the user enables this through a mixer switch, both internal and
156 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
157 * we also allow the bias to be configured through a separate mixer
158 * control. */
159 unsigned int dc_enable;
160 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
161 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200162
163 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200164
165 /* extra EAPD pins */
166 unsigned int num_eapds;
167 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100168};
169
170static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100175 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
176 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100177}
178
179static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
182 unsigned int format,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
187 stream_tag,
188 format, substream);
189}
190
191static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
194{
195 struct conexant_spec *spec = codec->spec;
196 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
197}
198
199/*
200 * Digital out
201 */
202static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 struct snd_pcm_substream *substream)
205{
206 struct conexant_spec *spec = codec->spec;
207 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
208}
209
210static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 struct snd_pcm_substream *substream)
213{
214 struct conexant_spec *spec = codec->spec;
215 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
216}
217
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200218static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
219 struct hda_codec *codec,
220 unsigned int stream_tag,
221 unsigned int format,
222 struct snd_pcm_substream *substream)
223{
224 struct conexant_spec *spec = codec->spec;
225 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
226 stream_tag,
227 format, substream);
228}
229
Tobin Davisc9b443d2006-11-14 12:13:39 +0100230/*
231 * Analog capture
232 */
233static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
234 struct hda_codec *codec,
235 unsigned int stream_tag,
236 unsigned int format,
237 struct snd_pcm_substream *substream)
238{
239 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100240 if (spec->capture_prepare)
241 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100242 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
243 stream_tag, 0, format);
244 return 0;
245}
246
247static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
248 struct hda_codec *codec,
249 struct snd_pcm_substream *substream)
250{
251 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100252 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100253 if (spec->capture_cleanup)
254 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100255 return 0;
256}
257
258
259
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200260static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261 .substreams = 1,
262 .channels_min = 2,
263 .channels_max = 2,
264 .nid = 0, /* fill later */
265 .ops = {
266 .open = conexant_playback_pcm_open,
267 .prepare = conexant_playback_pcm_prepare,
268 .cleanup = conexant_playback_pcm_cleanup
269 },
270};
271
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200272static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100273 .substreams = 1,
274 .channels_min = 2,
275 .channels_max = 2,
276 .nid = 0, /* fill later */
277 .ops = {
278 .prepare = conexant_capture_pcm_prepare,
279 .cleanup = conexant_capture_pcm_cleanup
280 },
281};
282
283
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200284static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100285 .substreams = 1,
286 .channels_min = 2,
287 .channels_max = 2,
288 .nid = 0, /* fill later */
289 .ops = {
290 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200291 .close = conexant_dig_playback_pcm_close,
292 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100293 },
294};
295
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200296static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100297 .substreams = 1,
298 .channels_min = 2,
299 .channels_max = 2,
300 /* NID is set in alc_build_pcms */
301};
302
Takashi Iwai461e2c72008-01-25 11:35:17 +0100303static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
304 struct hda_codec *codec,
305 unsigned int stream_tag,
306 unsigned int format,
307 struct snd_pcm_substream *substream)
308{
309 struct conexant_spec *spec = codec->spec;
310 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
311 spec->cur_adc_stream_tag = stream_tag;
312 spec->cur_adc_format = format;
313 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
314 return 0;
315}
316
317static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 struct snd_pcm_substream *substream)
320{
321 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100322 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100323 spec->cur_adc = 0;
324 return 0;
325}
326
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200327static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100328 .substreams = 1,
329 .channels_min = 2,
330 .channels_max = 2,
331 .nid = 0, /* fill later */
332 .ops = {
333 .prepare = cx5051_capture_pcm_prepare,
334 .cleanup = cx5051_capture_pcm_cleanup
335 },
336};
337
Tobin Davisc9b443d2006-11-14 12:13:39 +0100338static int conexant_build_pcms(struct hda_codec *codec)
339{
340 struct conexant_spec *spec = codec->spec;
341 struct hda_pcm *info = spec->pcm_rec;
342
343 codec->num_pcms = 1;
344 codec->pcm_info = info;
345
346 info->name = "CONEXANT Analog";
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
349 spec->multiout.max_channels;
350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
351 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200352 if (spec->capture_stream)
353 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
354 else {
355 if (codec->vendor_id == 0x14f15051)
356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
357 cx5051_pcm_analog_capture;
358 else {
359 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
360 conexant_pcm_analog_capture;
361 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
362 spec->num_adc_nids;
363 }
364 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100365 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
366
367 if (spec->multiout.dig_out_nid) {
368 info++;
369 codec->num_pcms++;
370 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100371 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100372 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
373 conexant_pcm_digital_playback;
374 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
375 spec->multiout.dig_out_nid;
376 if (spec->dig_in_nid) {
377 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
378 conexant_pcm_digital_capture;
379 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
380 spec->dig_in_nid;
381 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500382 if (spec->slave_dig_outs[0])
383 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100384 }
385
386 return 0;
387}
388
389static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_info *uinfo)
391{
392 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
393 struct conexant_spec *spec = codec->spec;
394
395 return snd_hda_input_mux_info(spec->input_mux, uinfo);
396}
397
398static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 struct conexant_spec *spec = codec->spec;
403 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
404
405 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
406 return 0;
407}
408
409static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
410 struct snd_ctl_elem_value *ucontrol)
411{
412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413 struct conexant_spec *spec = codec->spec;
414 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
415
416 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
417 spec->capsrc_nids[adc_idx],
418 &spec->cur_mux[adc_idx]);
419}
420
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200421static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
422 unsigned int power_state)
423{
424 if (power_state == AC_PWRST_D3)
425 msleep(100);
426 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
427 power_state);
428 /* partial workaround for "azx_get_response timeout" */
429 if (power_state == AC_PWRST_D0)
430 msleep(10);
431 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
432}
433
Tobin Davisc9b443d2006-11-14 12:13:39 +0100434static int conexant_init(struct hda_codec *codec)
435{
436 struct conexant_spec *spec = codec->spec;
437 int i;
438
439 for (i = 0; i < spec->num_init_verbs; i++)
440 snd_hda_sequence_write(codec, spec->init_verbs[i]);
441 return 0;
442}
443
444static void conexant_free(struct hda_codec *codec)
445{
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200446 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100447 kfree(codec->spec);
448}
449
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200450static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100451 {
452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
453 .name = "Capture Source",
454 .info = conexant_mux_enum_info,
455 .get = conexant_mux_enum_get,
456 .put = conexant_mux_enum_put
457 },
458 {}
459};
460
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200461#ifdef CONFIG_SND_HDA_INPUT_BEEP
462/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200463static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200464 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
465 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
466 { } /* end */
467};
468#endif
469
Takashi Iwai9322ca52012-02-03 14:28:01 +0100470static const char * const slave_pfxs[] = {
471 "Headphone", "Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100472 NULL
473};
474
Tobin Davisc9b443d2006-11-14 12:13:39 +0100475static int conexant_build_controls(struct hda_codec *codec)
476{
477 struct conexant_spec *spec = codec->spec;
478 unsigned int i;
479 int err;
480
481 for (i = 0; i < spec->num_mixers; i++) {
482 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
483 if (err < 0)
484 return err;
485 }
486 if (spec->multiout.dig_out_nid) {
487 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600488 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100489 spec->multiout.dig_out_nid);
490 if (err < 0)
491 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100492 err = snd_hda_create_spdif_share_sw(codec,
493 &spec->multiout);
494 if (err < 0)
495 return err;
496 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100497 }
498 if (spec->dig_in_nid) {
499 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
500 if (err < 0)
501 return err;
502 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100503
504 /* if we have no master control, let's create it */
505 if (spec->vmaster_nid &&
506 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
507 unsigned int vmaster_tlv[4];
508 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
509 HDA_OUTPUT, vmaster_tlv);
510 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100511 vmaster_tlv, slave_pfxs,
512 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100513 if (err < 0)
514 return err;
515 }
516 if (spec->vmaster_nid &&
517 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai527c73b2012-03-12 12:38:51 +0100518 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
519 NULL, slave_pfxs,
520 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100521 &spec->vmaster_mute.sw_kctl);
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100522 if (err < 0)
523 return err;
524 }
525
Takashi Iwaib880c742009-03-10 14:41:05 +0100526 if (spec->input_mux) {
527 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
528 if (err < 0)
529 return err;
530 }
531
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200532#ifdef CONFIG_SND_HDA_INPUT_BEEP
533 /* create beep controls if needed */
534 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200535 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200536 for (knew = cxt_beep_mixer; knew->name; knew++) {
537 struct snd_kcontrol *kctl;
538 kctl = snd_ctl_new1(knew, codec);
539 if (!kctl)
540 return -ENOMEM;
541 kctl->private_value = spec->beep_amp;
542 err = snd_hda_ctl_add(codec, 0, kctl);
543 if (err < 0)
544 return err;
545 }
546 }
547#endif
548
Tobin Davisc9b443d2006-11-14 12:13:39 +0100549 return 0;
550}
551
Takashi Iwai697c3732010-07-30 11:28:02 +0200552#ifdef CONFIG_SND_HDA_POWER_SAVE
553static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
554{
555 snd_hda_shutup_pins(codec);
556 return 0;
557}
558#endif
559
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200560static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100561 .build_controls = conexant_build_controls,
562 .build_pcms = conexant_build_pcms,
563 .init = conexant_init,
564 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200565 .set_power_state = conexant_set_power,
Takashi Iwai697c3732010-07-30 11:28:02 +0200566#ifdef CONFIG_SND_HDA_POWER_SAVE
567 .suspend = conexant_suspend,
568#endif
569 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100570};
571
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200572#ifdef CONFIG_SND_HDA_INPUT_BEEP
573#define set_beep_amp(spec, nid, idx, dir) \
574 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
575#else
576#define set_beep_amp(spec, nid, idx, dir) /* NOP */
577#endif
578
Takashi Iwai6764bce2011-05-13 16:52:25 +0200579static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100580/*
581 * EAPD control
582 * the private value = nid | (invert << 8)
583 */
584
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200585#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586
Tobin Davis82f30042007-02-13 12:45:44 +0100587static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100588 struct snd_ctl_elem_value *ucontrol)
589{
590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
591 struct conexant_spec *spec = codec->spec;
592 int invert = (kcontrol->private_value >> 8) & 1;
593 if (invert)
594 ucontrol->value.integer.value[0] = !spec->cur_eapd;
595 else
596 ucontrol->value.integer.value[0] = spec->cur_eapd;
597 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100598
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599}
600
Tobin Davis82f30042007-02-13 12:45:44 +0100601static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602 struct snd_ctl_elem_value *ucontrol)
603{
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 struct conexant_spec *spec = codec->spec;
606 int invert = (kcontrol->private_value >> 8) & 1;
607 hda_nid_t nid = kcontrol->private_value & 0xff;
608 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100609
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100610 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100611 if (invert)
612 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200613 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100615
Tobin Davisc9b443d2006-11-14 12:13:39 +0100616 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200617 snd_hda_codec_write_cache(codec, nid,
618 0, AC_VERB_SET_EAPD_BTLENABLE,
619 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620 return 1;
621}
622
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100623/* controls for test mode */
624#ifdef CONFIG_SND_DEBUG
625
Tobin Davis82f30042007-02-13 12:45:44 +0100626#define CXT_EAPD_SWITCH(xname, nid, mask) \
627 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
628 .info = cxt_eapd_info, \
629 .get = cxt_eapd_get, \
630 .put = cxt_eapd_put, \
631 .private_value = nid | (mask<<16) }
632
633
634
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_info *uinfo)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct conexant_spec *spec = codec->spec;
640 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
641 spec->num_channel_mode);
642}
643
644static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_value *ucontrol)
646{
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct conexant_spec *spec = codec->spec;
649 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
650 spec->num_channel_mode,
651 spec->multiout.max_channels);
652}
653
654static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
656{
657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658 struct conexant_spec *spec = codec->spec;
659 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
660 spec->num_channel_mode,
661 &spec->multiout.max_channels);
662 if (err >= 0 && spec->need_dac_fix)
663 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
664 return err;
665}
666
667#define CXT_PIN_MODE(xname, nid, dir) \
668 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
669 .info = conexant_ch_mode_info, \
670 .get = conexant_ch_mode_get, \
671 .put = conexant_ch_mode_put, \
672 .private_value = nid | (dir<<16) }
673
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100674#endif /* CONFIG_SND_DEBUG */
675
Tobin Davisc9b443d2006-11-14 12:13:39 +0100676/* Conexant 5045 specific */
677
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200678static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
679static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
680static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100681#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100682
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200683static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100684 { 2, NULL },
685};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200687static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100688 .num_items = 2,
689 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200690 { "Internal Mic", 0x1 },
691 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100692 }
693};
694
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200695static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200696 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100697 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200698 { "Internal Mic", 0x1 },
699 { "Mic", 0x2 },
700 { "Line", 0x3 },
701 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100702 }
703};
704
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200705static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100706 .num_items = 2,
707 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200708 { "Mic", 0x1 },
709 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100710 }
711};
712
Tobin Davisc9b443d2006-11-14 12:13:39 +0100713/* turn on/off EAPD (+ mute HP) as a master switch */
714static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100719 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100720
Tobin Davis82f30042007-02-13 12:45:44 +0100721 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722 return 0;
723
Tobin Davis82f30042007-02-13 12:45:44 +0100724 /* toggle internal speakers mute depending of presence of
725 * the headphone jack
726 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200727 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
728 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
729 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100730
Takashi Iwai47fd8302007-08-10 17:11:07 +0200731 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
732 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
733 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734 return 1;
735}
736
737/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200738static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200739 .ops = &snd_hda_bind_vol,
740 .values = {
741 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
742 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
743 0
744 },
745};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746
Tobin Davis7f296732007-03-12 11:39:01 +0100747/* toggle input of built-in and mic jack appropriately */
748static void cxt5045_hp_automic(struct hda_codec *codec)
749{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200750 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
752 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
753 {}
754 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200755 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100756 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
758 {}
759 };
760 unsigned int present;
761
Takashi Iwaid56757a2009-11-18 08:00:14 +0100762 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100763 if (present)
764 snd_hda_sequence_write(codec, mic_jack_on);
765 else
766 snd_hda_sequence_write(codec, mic_jack_off);
767}
768
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769
770/* mute internal speaker if HP is plugged */
771static void cxt5045_hp_automute(struct hda_codec *codec)
772{
Tobin Davis82f30042007-02-13 12:45:44 +0100773 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100774 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775
Takashi Iwaid56757a2009-11-18 08:00:14 +0100776 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100777
Takashi Iwai47fd8302007-08-10 17:11:07 +0200778 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
779 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
780 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100781}
782
783/* unsolicited event for HP jack sensing */
784static void cxt5045_hp_unsol_event(struct hda_codec *codec,
785 unsigned int res)
786{
787 res >>= 26;
788 switch (res) {
789 case CONEXANT_HP_EVENT:
790 cxt5045_hp_automute(codec);
791 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100792 case CONEXANT_MIC_EVENT:
793 cxt5045_hp_automic(codec);
794 break;
795
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796 }
797}
798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200799static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200800 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
801 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200802 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
803 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100804 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
805 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100806 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
807 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200808 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100809 {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100812 .info = cxt_eapd_info,
813 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100814 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100815 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100816 },
817
818 {}
819};
820
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200821static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200822 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
823 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200824
Jiang Zhe5218c892008-01-17 11:18:41 +0100825 {}
826};
827
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200828static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200829 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
830 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100831 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
832 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100833 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
834 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100835 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
836 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100837 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
838 {
839 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
840 .name = "Master Playback Switch",
841 .info = cxt_eapd_info,
842 .get = cxt_eapd_get,
843 .put = cxt5045_hp_master_sw_put,
844 .private_value = 0x10,
845 },
846
847 {}
848};
849
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200850static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100851 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200852 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100853 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200855 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
856 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
857 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
858 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
859 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
860 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
861 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
863 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100864 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100865 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100866 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
868 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100869 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100870 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100871 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100872 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873 { } /* end */
874};
875
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200876static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100877 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100878 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
879 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
880 /* Line In,HP, Amp */
881 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
882 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
883 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
884 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
885 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
886 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100890 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100891 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
892 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
893 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
894 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100895 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100896 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
897 /* EAPD */
898 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
899 { } /* end */
900};
Tobin Davis7f296732007-03-12 11:39:01 +0100901
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200902static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100903 /* pin sensing on HP jack */
904 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200905 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100906};
907
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200908static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100909 /* pin sensing on HP jack */
910 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200911 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100912};
913
Tobin Davisc9b443d2006-11-14 12:13:39 +0100914#ifdef CONFIG_SND_DEBUG
915/* Test configuration for debugging, modelled after the ALC260 test
916 * configuration.
917 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200918static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100919 .num_items = 5,
920 .items = {
921 { "MIXER", 0x0 },
922 { "MIC1 pin", 0x1 },
923 { "LINE1 pin", 0x2 },
924 { "HP-OUT pin", 0x3 },
925 { "CD pin", 0x4 },
926 },
927};
928
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200929static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930
931 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
933 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200934 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
935 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
936 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
937 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100938
939 /* Modes for retasking pin widgets */
940 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
941 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
942
Tobin Davis82f30042007-02-13 12:45:44 +0100943 /* EAPD Switch Control */
944 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
945
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947
Michael Karcher250f3272012-04-06 15:34:20 +0200948 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
949 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
950 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
951 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
952 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
953 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
954 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
955 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
956 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
957 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100958 {
959 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
960 .name = "Input Source",
961 .info = conexant_mux_enum_info,
962 .get = conexant_mux_enum_get,
963 .put = conexant_mux_enum_put,
964 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200965 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200966 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
967 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100968 { } /* end */
969};
970
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200971static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100972 /* Set connections */
973 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
974 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
975 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100976 /* Enable retasking pins as output, initially without power amp */
977 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100978 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100979
980 /* Disable digital (SPDIF) pins initially, but users can enable
981 * them via a mixer switch. In the case of SPDIF-out, this initverb
982 * payload also sets the generation to 0, output to be in "consumer"
983 * PCM format, copyright asserted, no pre-emphasis and no validity
984 * control.
985 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100986 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
987 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100988
Tobin Davisc9b443d2006-11-14 12:13:39 +0100989 /* Unmute retasking pin widget output buffers since the default
990 * state appears to be output. As the pin mode is changed by the
991 * user the pin mode control will take care of enabling the pin's
992 * input/output buffers as needed.
993 */
994 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
995 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
996
997 /* Mute capture amp left and right */
998 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
999
1000 /* Set ADC connection select to match default mixer setting (mic1
1001 * pin)
1002 */
Michael Karcher250f3272012-04-06 15:34:20 +02001003 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1004 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001005
1006 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +02001007 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001008 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1009 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1010 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1011 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1012
1013 { }
1014};
1015#endif
1016
1017
1018/* initialize jack-sensing, too */
1019static int cxt5045_init(struct hda_codec *codec)
1020{
1021 conexant_init(codec);
1022 cxt5045_hp_automute(codec);
1023 return 0;
1024}
1025
1026
1027enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001028 CXT5045_LAPTOP_HPSENSE,
1029 CXT5045_LAPTOP_MICSENSE,
1030 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001031 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001032 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033#ifdef CONFIG_SND_DEBUG
1034 CXT5045_TEST,
1035#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001036 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001037 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001038};
1039
Takashi Iwaiea734962011-01-17 11:29:34 +01001040static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001041 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1042 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1043 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1044 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001045 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001046#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001047 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001048#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001049 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001050};
1051
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001052static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001053 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001054 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001055 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001056 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1057 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001058 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1059 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001060 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1061 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1062 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001063 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1064 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001065 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001066 {}
1067};
1068
1069static int patch_cxt5045(struct hda_codec *codec)
1070{
1071 struct conexant_spec *spec;
1072 int board_config;
1073
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001074 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1075 cxt5045_models,
1076 cxt5045_cfg_tbl);
1077 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001078 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001079 if (board_config == CXT5045_AUTO)
1080 return patch_conexant_auto(codec);
1081
Tobin Davisc9b443d2006-11-14 12:13:39 +01001082 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1083 if (!spec)
1084 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001085 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001086 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001087
1088 spec->multiout.max_channels = 2;
1089 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1090 spec->multiout.dac_nids = cxt5045_dac_nids;
1091 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1092 spec->num_adc_nids = 1;
1093 spec->adc_nids = cxt5045_adc_nids;
1094 spec->capsrc_nids = cxt5045_capsrc_nids;
1095 spec->input_mux = &cxt5045_capture_source;
1096 spec->num_mixers = 1;
1097 spec->mixers[0] = cxt5045_mixers;
1098 spec->num_init_verbs = 1;
1099 spec->init_verbs[0] = cxt5045_init_verbs;
1100 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001101 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1102 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001103
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001104 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001105
1106 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001107
Tobin Davisc9b443d2006-11-14 12:13:39 +01001108 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001109 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001110 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111 spec->input_mux = &cxt5045_capture_source;
1112 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001113 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1114 spec->mixers[0] = cxt5045_mixers;
1115 codec->patch_ops.init = cxt5045_init;
1116 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001117 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001118 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001119 spec->input_mux = &cxt5045_capture_source;
1120 spec->num_init_verbs = 2;
1121 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001122 spec->mixers[0] = cxt5045_mixers;
1123 codec->patch_ops.init = cxt5045_init;
1124 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001125 default:
1126 case CXT5045_LAPTOP_HPMICSENSE:
1127 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1128 spec->input_mux = &cxt5045_capture_source;
1129 spec->num_init_verbs = 3;
1130 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1131 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1132 spec->mixers[0] = cxt5045_mixers;
1133 codec->patch_ops.init = cxt5045_init;
1134 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001135 case CXT5045_BENQ:
1136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1137 spec->input_mux = &cxt5045_capture_source_benq;
1138 spec->num_init_verbs = 1;
1139 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1140 spec->mixers[0] = cxt5045_mixers;
1141 spec->mixers[1] = cxt5045_benq_mixers;
1142 spec->num_mixers = 2;
1143 codec->patch_ops.init = cxt5045_init;
1144 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001145 case CXT5045_LAPTOP_HP530:
1146 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1147 spec->input_mux = &cxt5045_capture_source_hp530;
1148 spec->num_init_verbs = 2;
1149 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1150 spec->mixers[0] = cxt5045_mixers_hp530;
1151 codec->patch_ops.init = cxt5045_init;
1152 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153#ifdef CONFIG_SND_DEBUG
1154 case CXT5045_TEST:
1155 spec->input_mux = &cxt5045_test_capture_source;
1156 spec->mixers[0] = cxt5045_test_mixer;
1157 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001158 break;
1159
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160#endif
1161 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001162
Takashi Iwai031005f2008-06-26 14:49:58 +02001163 switch (codec->subsystem_id >> 16) {
1164 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001165 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001166 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001167 case 0x17aa:
1168 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1169 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1170 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001171 */
1172 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1173 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1174 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1175 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1176 (1 << AC_AMPCAP_MUTE_SHIFT));
1177 break;
1178 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001179
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001180 if (spec->beep_amp)
1181 snd_hda_attach_beep_device(codec, spec->beep_amp);
1182
Tobin Davisc9b443d2006-11-14 12:13:39 +01001183 return 0;
1184}
1185
1186
1187/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001188#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001189
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001190static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1191static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1192static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001194static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001195 { 2, NULL },
1196};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001198static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001199 .num_items = 2,
1200 .items = {
1201 { "ExtMic", 0x2 },
1202 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001203 }
1204};
1205
1206/* turn on/off EAPD (+ mute HP) as a master switch */
1207static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1208 struct snd_ctl_elem_value *ucontrol)
1209{
1210 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1211 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001212 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001213
Tobin Davis82f30042007-02-13 12:45:44 +01001214 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001215 return 0;
1216
Tobin Davis82f30042007-02-13 12:45:44 +01001217 /* toggle internal speakers mute depending of presence of
1218 * the headphone jack
1219 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001220 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001221 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1222 * pin widgets unlike other codecs. In this case, we need to
1223 * set index 0x01 for the volume from the mixer amp 0x19.
1224 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001225 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001226 HDA_AMP_MUTE, bits);
1227 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1228 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1229 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001230 return 1;
1231}
1232
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233/* mute internal speaker if HP is plugged */
1234static void cxt5047_hp_automute(struct hda_codec *codec)
1235{
Tobin Davis82f30042007-02-13 12:45:44 +01001236 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001237 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001238
Takashi Iwaid56757a2009-11-18 08:00:14 +01001239 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001240
Takashi Iwai47fd8302007-08-10 17:11:07 +02001241 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001242 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001243 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001244 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245}
1246
1247/* toggle input of built-in and mic jack appropriately */
1248static void cxt5047_hp_automic(struct hda_codec *codec)
1249{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001250 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001251 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1252 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 {}
1254 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001255 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001256 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1257 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001258 {}
1259 };
1260 unsigned int present;
1261
Takashi Iwaid56757a2009-11-18 08:00:14 +01001262 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001263 if (present)
1264 snd_hda_sequence_write(codec, mic_jack_on);
1265 else
1266 snd_hda_sequence_write(codec, mic_jack_off);
1267}
1268
1269/* unsolicited event for HP jack sensing */
1270static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1271 unsigned int res)
1272{
Marc Boucher9f113e02008-01-22 15:18:08 +01001273 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274 case CONEXANT_HP_EVENT:
1275 cxt5047_hp_automute(codec);
1276 break;
1277 case CONEXANT_MIC_EVENT:
1278 cxt5047_hp_automic(codec);
1279 break;
1280 }
1281}
1282
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001283static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001284 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1285 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001286 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1288 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1289 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1290 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001291 {
1292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1293 .name = "Master Playback Switch",
1294 .info = cxt_eapd_info,
1295 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001296 .put = cxt5047_hp_master_sw_put,
1297 .private_value = 0x13,
1298 },
1299
1300 {}
1301};
1302
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001303static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001304 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001305 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001306 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1307 {}
1308};
1309
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001310static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001311 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 { } /* end */
1313};
1314
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001315static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 /* Line in, Mic, Built-in Mic */
1317 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1318 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1319 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001320 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001321 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001322 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1323 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001324 /* Record selector: Mic */
1325 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1326 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1327 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1328 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001329 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1330 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1331 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1332 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333 /* SPDIF route: PCM */
1334 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001335 /* Enable unsolicited events */
1336 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1337 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001338 { } /* end */
1339};
1340
1341/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001342static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001343 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 {}
1345};
1346
1347/* Test configuration for debugging, modelled after the ALC260 test
1348 * configuration.
1349 */
1350#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001351static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001352 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001353 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001354 { "LINE1 pin", 0x0 },
1355 { "MIC1 pin", 0x1 },
1356 { "MIC2 pin", 0x2 },
1357 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001358 },
1359};
1360
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001361static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362
1363 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001364 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1366 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001368 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001372 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001376
1377 /* Modes for retasking pin widgets */
1378 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1379 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1380
Tobin Davis82f30042007-02-13 12:45:44 +01001381 /* EAPD Switch Control */
1382 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1383
Tobin Davisc9b443d2006-11-14 12:13:39 +01001384 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001385 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1386 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1387 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1388 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1389 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1390 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1391 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1392 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393
Tobin Davis82f30042007-02-13 12:45:44 +01001394 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1395 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1396 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1397 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1398 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1399 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1400 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1401 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402 {
1403 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1404 .name = "Input Source",
1405 .info = conexant_mux_enum_info,
1406 .get = conexant_mux_enum_get,
1407 .put = conexant_mux_enum_put,
1408 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001409 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001410
Tobin Davisc9b443d2006-11-14 12:13:39 +01001411 { } /* end */
1412};
1413
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001414static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 /* Enable retasking pins as output, initially without power amp */
1416 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1417 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1418 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1419
1420 /* Disable digital (SPDIF) pins initially, but users can enable
1421 * them via a mixer switch. In the case of SPDIF-out, this initverb
1422 * payload also sets the generation to 0, output to be in "consumer"
1423 * PCM format, copyright asserted, no pre-emphasis and no validity
1424 * control.
1425 */
1426 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1427
1428 /* Ensure mic1, mic2, line1 pin widgets take input from the
1429 * OUT1 sum bus when acting as an output.
1430 */
1431 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1432 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1433
1434 /* Start with output sum widgets muted and their output gains at min */
1435 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1436 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1437
1438 /* Unmute retasking pin widget output buffers since the default
1439 * state appears to be output. As the pin mode is changed by the
1440 * user the pin mode control will take care of enabling the pin's
1441 * input/output buffers as needed.
1442 */
1443 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1444 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1445 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1446
1447 /* Mute capture amp left and right */
1448 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1449
1450 /* Set ADC connection select to match default mixer setting (mic1
1451 * pin)
1452 */
1453 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1454
1455 /* Mute all inputs to mixer widget (even unconnected ones) */
1456 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1457 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1458 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1459 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1460 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1461 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1464
1465 { }
1466};
1467#endif
1468
1469
1470/* initialize jack-sensing, too */
1471static int cxt5047_hp_init(struct hda_codec *codec)
1472{
1473 conexant_init(codec);
1474 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001475 return 0;
1476}
1477
1478
1479enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001480 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1481 CXT5047_LAPTOP_HP, /* Some HP laptops */
1482 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001483#ifdef CONFIG_SND_DEBUG
1484 CXT5047_TEST,
1485#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001486 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001487 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001488};
1489
Takashi Iwaiea734962011-01-17 11:29:34 +01001490static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001491 [CXT5047_LAPTOP] = "laptop",
1492 [CXT5047_LAPTOP_HP] = "laptop-hp",
1493 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001494#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001495 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001496#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001497 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001498};
1499
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001500static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001501 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001502 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1503 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001504 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001505 {}
1506};
1507
1508static int patch_cxt5047(struct hda_codec *codec)
1509{
1510 struct conexant_spec *spec;
1511 int board_config;
1512
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001513 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1514 cxt5047_models,
1515 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001516 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001517 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001518 if (board_config == CXT5047_AUTO)
1519 return patch_conexant_auto(codec);
1520
Tobin Davisc9b443d2006-11-14 12:13:39 +01001521 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1522 if (!spec)
1523 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001525 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001526
1527 spec->multiout.max_channels = 2;
1528 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1529 spec->multiout.dac_nids = cxt5047_dac_nids;
1530 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1531 spec->num_adc_nids = 1;
1532 spec->adc_nids = cxt5047_adc_nids;
1533 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001534 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001535 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001536 spec->num_init_verbs = 1;
1537 spec->init_verbs[0] = cxt5047_init_verbs;
1538 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001539 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1540 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001541
1542 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544 switch (board_config) {
1545 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001546 spec->num_mixers = 2;
1547 spec->mixers[1] = cxt5047_hp_spk_mixers;
1548 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001549 break;
1550 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001551 spec->num_mixers = 2;
1552 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001553 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554 codec->patch_ops.init = cxt5047_hp_init;
1555 break;
1556 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001557 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001558 spec->num_mixers = 2;
1559 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560 spec->num_init_verbs = 2;
1561 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001562 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001563 break;
1564#ifdef CONFIG_SND_DEBUG
1565 case CXT5047_TEST:
1566 spec->input_mux = &cxt5047_test_capture_source;
1567 spec->mixers[0] = cxt5047_test_mixer;
1568 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001569 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570#endif
1571 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001572 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001573
1574 switch (codec->subsystem_id >> 16) {
1575 case 0x103c:
1576 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1577 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1578 * with 0 dB offset 0x17)
1579 */
1580 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1581 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1582 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1583 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1584 (1 << AC_AMPCAP_MUTE_SHIFT));
1585 break;
1586 }
1587
Tobin Davisc9b443d2006-11-14 12:13:39 +01001588 return 0;
1589}
1590
Takashi Iwai461e2c72008-01-25 11:35:17 +01001591/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001592static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1593static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001594
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001595static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001596 { 2, NULL },
1597};
1598
1599static void cxt5051_update_speaker(struct hda_codec *codec)
1600{
1601 struct conexant_spec *spec = codec->spec;
1602 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001603 /* headphone pin */
1604 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1605 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1606 pinctl);
1607 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001608 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1609 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1610 pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001611 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001612 if (spec->ideapad)
1613 snd_hda_codec_write(codec, 0x1b, 0,
1614 AC_VERB_SET_PIN_WIDGET_CONTROL,
1615 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001616}
1617
1618/* turn on/off EAPD (+ mute HP) as a master switch */
1619static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1621{
1622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1623
1624 if (!cxt_eapd_put(kcontrol, ucontrol))
1625 return 0;
1626 cxt5051_update_speaker(codec);
1627 return 1;
1628}
1629
1630/* toggle input of built-in and mic jack appropriately */
1631static void cxt5051_portb_automic(struct hda_codec *codec)
1632{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001633 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001634 unsigned int present;
1635
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001636 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001637 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001638 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001639 snd_hda_codec_write(codec, 0x14, 0,
1640 AC_VERB_SET_CONNECT_SEL,
1641 present ? 0x01 : 0x00);
1642}
1643
1644/* switch the current ADC according to the jack state */
1645static void cxt5051_portc_automic(struct hda_codec *codec)
1646{
1647 struct conexant_spec *spec = codec->spec;
1648 unsigned int present;
1649 hda_nid_t new_adc;
1650
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001651 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001652 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001653 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001654 if (present)
1655 spec->cur_adc_idx = 1;
1656 else
1657 spec->cur_adc_idx = 0;
1658 new_adc = spec->adc_nids[spec->cur_adc_idx];
1659 if (spec->cur_adc && spec->cur_adc != new_adc) {
1660 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001661 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662 spec->cur_adc = new_adc;
1663 snd_hda_codec_setup_stream(codec, new_adc,
1664 spec->cur_adc_stream_tag, 0,
1665 spec->cur_adc_format);
1666 }
1667}
1668
1669/* mute internal speaker if HP is plugged */
1670static void cxt5051_hp_automute(struct hda_codec *codec)
1671{
1672 struct conexant_spec *spec = codec->spec;
1673
Takashi Iwaid56757a2009-11-18 08:00:14 +01001674 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001675 cxt5051_update_speaker(codec);
1676}
1677
1678/* unsolicited event for HP jack sensing */
1679static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1680 unsigned int res)
1681{
1682 switch (res >> 26) {
1683 case CONEXANT_HP_EVENT:
1684 cxt5051_hp_automute(codec);
1685 break;
1686 case CXT5051_PORTB_EVENT:
1687 cxt5051_portb_automic(codec);
1688 break;
1689 case CXT5051_PORTC_EVENT:
1690 cxt5051_portc_automic(codec);
1691 break;
1692 }
1693}
1694
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001695static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001696 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1697 {
1698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1699 .name = "Master Playback Switch",
1700 .info = cxt_eapd_info,
1701 .get = cxt_eapd_get,
1702 .put = cxt5051_hp_master_sw_put,
1703 .private_value = 0x1a,
1704 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001705 {}
1706};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001708static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001709 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1710 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001711 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1712 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001713 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1714 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 {}
1716};
1717
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001718static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1720 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001721 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1722 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 {}
1724};
1725
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001726static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001727 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1728 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001729 {}
1730};
1731
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001732static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001733 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1734 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001735 {}
1736};
1737
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001738static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001739 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1740 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001741 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1742 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001743 {}
1744};
1745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001746static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001747 /* Line in, Mic */
1748 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1749 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1750 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1751 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1752 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1753 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1754 /* SPK */
1755 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1756 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1757 /* HP, Amp */
1758 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1760 /* DAC1 */
1761 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001762 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001763 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1764 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1765 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1766 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001767 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001768 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1769 /* EAPD */
1770 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1771 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001772 { } /* end */
1773};
1774
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001775static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001776 /* Line in, Mic */
1777 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1778 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1779 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1780 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1781 /* SPK */
1782 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1783 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1784 /* HP, Amp */
1785 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1786 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1787 /* DAC1 */
1788 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001789 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001790 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1791 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1792 /* SPDIF route: PCM */
1793 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1794 /* EAPD */
1795 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1796 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001797 { } /* end */
1798};
1799
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001800static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001801 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001802 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001803 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1804 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1805 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1806 /* SPK */
1807 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1808 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1809 /* HP, Amp */
1810 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1811 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1812 /* DAC1 */
1813 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001814 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1816 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1817 /* SPDIF route: PCM */
1818 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1819 /* EAPD */
1820 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1821 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001822 { } /* end */
1823};
1824
Takashi Iwai6953e552010-01-24 11:00:27 +01001825static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1826 unsigned int event)
1827{
1828 snd_hda_codec_write(codec, nid, 0,
1829 AC_VERB_SET_UNSOLICITED_ENABLE,
1830 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001831}
1832
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001833static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001834 /* Subwoofer */
1835 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1836 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1837 { } /* end */
1838};
1839
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840/* initialize jack-sensing, too */
1841static int cxt5051_init(struct hda_codec *codec)
1842{
Takashi Iwai6953e552010-01-24 11:00:27 +01001843 struct conexant_spec *spec = codec->spec;
1844
Takashi Iwai461e2c72008-01-25 11:35:17 +01001845 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001846
1847 if (spec->auto_mic & AUTO_MIC_PORTB)
1848 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1849 if (spec->auto_mic & AUTO_MIC_PORTC)
1850 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1851
Takashi Iwai461e2c72008-01-25 11:35:17 +01001852 if (codec->patch_ops.unsol_event) {
1853 cxt5051_hp_automute(codec);
1854 cxt5051_portb_automic(codec);
1855 cxt5051_portc_automic(codec);
1856 }
1857 return 0;
1858}
1859
1860
1861enum {
1862 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1863 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001864 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001865 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001866 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001867 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001868 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001869 CXT5051_MODELS
1870};
1871
Takashi Iwaiea734962011-01-17 11:29:34 +01001872static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001873 [CXT5051_LAPTOP] = "laptop",
1874 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001875 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001876 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001877 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001878 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001879 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001880};
1881
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001882static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001883 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001884 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001885 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001886 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001887 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1888 CXT5051_LAPTOP),
1889 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001890 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001891 {}
1892};
1893
1894static int patch_cxt5051(struct hda_codec *codec)
1895{
1896 struct conexant_spec *spec;
1897 int board_config;
1898
Takashi Iwai6764bce2011-05-13 16:52:25 +02001899 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1900 cxt5051_models,
1901 cxt5051_cfg_tbl);
1902 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001903 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001904 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001905 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001906
Takashi Iwai461e2c72008-01-25 11:35:17 +01001907 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1908 if (!spec)
1909 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001910 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001911 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001912
1913 codec->patch_ops = conexant_patch_ops;
1914 codec->patch_ops.init = cxt5051_init;
1915
1916 spec->multiout.max_channels = 2;
1917 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1918 spec->multiout.dac_nids = cxt5051_dac_nids;
1919 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1920 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1921 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001922 spec->num_mixers = 2;
1923 spec->mixers[0] = cxt5051_capture_mixers;
1924 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001925 spec->num_init_verbs = 1;
1926 spec->init_verbs[0] = cxt5051_init_verbs;
1927 spec->spdif_route = 0;
1928 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1929 spec->channel_mode = cxt5051_modes;
1930 spec->cur_adc = 0;
1931 spec->cur_adc_idx = 0;
1932
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001933 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1934
Takashi Iwai79d7d532009-03-04 09:03:50 +01001935 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1936
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001937 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001938 switch (board_config) {
1939 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001940 spec->mixers[0] = cxt5051_hp_mixers;
1941 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001942 case CXT5051_HP_DV6736:
1943 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1944 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001945 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001946 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001947 case CXT5051_F700:
1948 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1949 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001950 spec->auto_mic = 0;
1951 break;
1952 case CXT5051_TOSHIBA:
1953 spec->mixers[0] = cxt5051_toshiba_mixers;
1954 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001955 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001956 case CXT5051_IDEAPAD:
1957 spec->init_verbs[spec->num_init_verbs++] =
1958 cxt5051_ideapad_init_verbs;
1959 spec->ideapad = 1;
1960 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001961 }
1962
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001963 if (spec->beep_amp)
1964 snd_hda_attach_beep_device(codec, spec->beep_amp);
1965
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 return 0;
1967}
1968
Daniel Drake0fb67e92009-07-16 14:46:57 +01001969/* Conexant 5066 specific */
1970
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001971static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1972static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1973static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1974static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001975
Daniel Drakedbaccc02009-11-09 15:17:24 +00001976/* OLPC's microphone port is DC coupled for use with external sensors,
1977 * therefore we use a 50% mic bias in order to center the input signal with
1978 * the DC input range of the codec. */
1979#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1980
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001981static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001982 { 2, NULL },
1983};
1984
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001985#define HP_PRESENT_PORT_A (1 << 0)
1986#define HP_PRESENT_PORT_D (1 << 1)
1987#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1988#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1989
Daniel Drake0fb67e92009-07-16 14:46:57 +01001990static void cxt5066_update_speaker(struct hda_codec *codec)
1991{
1992 struct conexant_spec *spec = codec->spec;
1993 unsigned int pinctl;
1994
John Baboval3a253442010-12-02 11:21:31 -05001995 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1996 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001997
1998 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001999 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002000 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2001 pinctl);
2002
2003 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002004 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2005 if (spec->dell_automute || spec->thinkpad) {
2006 /* Mute if Port A is connected */
2007 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002008 pinctl = 0;
2009 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002010 /* Thinkpad/Dell doesn't give pin-D status */
2011 if (!hp_port_d_present(spec))
2012 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002013 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002014 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2015 pinctl);
2016
2017 /* CLASS_D AMP */
2018 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2019 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2020 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002021}
2022
2023/* turn on/off EAPD (+ mute HP) as a master switch */
2024static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2025 struct snd_ctl_elem_value *ucontrol)
2026{
2027 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2028
2029 if (!cxt_eapd_put(kcontrol, ucontrol))
2030 return 0;
2031
2032 cxt5066_update_speaker(codec);
2033 return 1;
2034}
2035
Daniel Drakec4cfe662010-01-07 13:47:04 +01002036static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2037 .num_items = 3,
2038 .items = {
2039 { "Off", PIN_IN },
2040 { "50%", PIN_VREF50 },
2041 { "80%", PIN_VREF80 },
2042 },
2043};
2044
2045static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2046{
2047 struct conexant_spec *spec = codec->spec;
2048 /* Even though port F is the DC input, the bias is controlled on port B.
2049 * we also leave that port as an active input (but unselected) in DC mode
2050 * just in case that is necessary to make the bias setting take effect. */
2051 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2052 AC_VERB_SET_PIN_WIDGET_CONTROL,
2053 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2054}
2055
Daniel Drake75f89912010-01-07 13:46:25 +01002056/* OLPC defers mic widget control until when capture is started because the
2057 * microphone LED comes on as soon as these settings are put in place. if we
2058 * did this before recording, it would give the false indication that recording
2059 * is happening when it is not. */
2060static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002061{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002062 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002063 if (!spec->recording)
2064 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002065
Daniel Drakec4cfe662010-01-07 13:47:04 +01002066 if (spec->dc_enable) {
2067 /* in DC mode we ignore presence detection and just use the jack
2068 * through our special DC port */
2069 const struct hda_verb enable_dc_mode[] = {
2070 /* disble internal mic, port C */
2071 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2072
2073 /* enable DC capture, port F */
2074 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2075 {},
2076 };
2077
2078 snd_hda_sequence_write(codec, enable_dc_mode);
2079 /* port B input disabled (and bias set) through the following call */
2080 cxt5066_set_olpc_dc_bias(codec);
2081 return;
2082 }
2083
2084 /* disable DC (port F) */
2085 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2086
Daniel Drake75f89912010-01-07 13:46:25 +01002087 /* external mic, port B */
2088 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2089 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002090
Daniel Drake75f89912010-01-07 13:46:25 +01002091 /* internal mic, port C */
2092 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2093 spec->ext_mic_present ? 0 : PIN_VREF80);
2094}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002095
Daniel Drake75f89912010-01-07 13:46:25 +01002096/* toggle input of built-in and mic jack appropriately */
2097static void cxt5066_olpc_automic(struct hda_codec *codec)
2098{
2099 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002100 unsigned int present;
2101
Daniel Drakec4cfe662010-01-07 13:47:04 +01002102 if (spec->dc_enable) /* don't do presence detection in DC mode */
2103 return;
2104
Daniel Drake75f89912010-01-07 13:46:25 +01002105 present = snd_hda_codec_read(codec, 0x1a, 0,
2106 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2107 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002108 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002109 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002110 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002111
2112 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2113 present ? 0 : 1);
2114 spec->ext_mic_present = !!present;
2115
2116 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002117}
2118
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002119/* toggle input of built-in digital mic and mic jack appropriately */
2120static void cxt5066_vostro_automic(struct hda_codec *codec)
2121{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002122 unsigned int present;
2123
2124 struct hda_verb ext_mic_present[] = {
2125 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002126 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002127
2128 /* switch to external mic input */
2129 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2130 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2131
2132 /* disable internal digital mic */
2133 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2134 {}
2135 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002136 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002137 /* enable internal mic, port C */
2138 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2139
2140 /* switch to internal mic input */
2141 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2142
2143 /* disable external mic, port B */
2144 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2145 {}
2146 };
2147
2148 present = snd_hda_jack_detect(codec, 0x1a);
2149 if (present) {
2150 snd_printdd("CXT5066: external microphone detected\n");
2151 snd_hda_sequence_write(codec, ext_mic_present);
2152 } else {
2153 snd_printdd("CXT5066: external microphone absent\n");
2154 snd_hda_sequence_write(codec, ext_mic_absent);
2155 }
2156}
2157
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002158/* toggle input of built-in digital mic and mic jack appropriately */
2159static void cxt5066_ideapad_automic(struct hda_codec *codec)
2160{
2161 unsigned int present;
2162
2163 struct hda_verb ext_mic_present[] = {
2164 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2165 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2166 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2167 {}
2168 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002169 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002170 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2171 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2172 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2173 {}
2174 };
2175
2176 present = snd_hda_jack_detect(codec, 0x1b);
2177 if (present) {
2178 snd_printdd("CXT5066: external microphone detected\n");
2179 snd_hda_sequence_write(codec, ext_mic_present);
2180 } else {
2181 snd_printdd("CXT5066: external microphone absent\n");
2182 snd_hda_sequence_write(codec, ext_mic_absent);
2183 }
2184}
2185
David Henningssona1d69062011-01-21 13:33:28 +01002186
2187/* toggle input of built-in digital mic and mic jack appropriately */
2188static void cxt5066_asus_automic(struct hda_codec *codec)
2189{
2190 unsigned int present;
2191
2192 present = snd_hda_jack_detect(codec, 0x1b);
2193 snd_printdd("CXT5066: external microphone present=%d\n", present);
2194 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2195 present ? 1 : 0);
2196}
2197
2198
David Henningsson048e78a2010-09-02 08:35:47 +02002199/* toggle input of built-in digital mic and mic jack appropriately */
2200static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2201{
2202 unsigned int present;
2203
2204 present = snd_hda_jack_detect(codec, 0x1b);
2205 snd_printdd("CXT5066: external microphone present=%d\n", present);
2206 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2207 present ? 1 : 3);
2208}
2209
2210
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002211/* toggle input of built-in digital mic and mic jack appropriately
2212 order is: external mic -> dock mic -> interal mic */
2213static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2214{
2215 unsigned int ext_present, dock_present;
2216
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002217 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002218 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2219 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2220 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2221 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2222 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223 {}
2224 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002225 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002226 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2227 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2228 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2229 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2230 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2231 {}
2232 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002233 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002234 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2235 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2236 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2237 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {}
2239 };
2240
2241 ext_present = snd_hda_jack_detect(codec, 0x1b);
2242 dock_present = snd_hda_jack_detect(codec, 0x1a);
2243 if (ext_present) {
2244 snd_printdd("CXT5066: external microphone detected\n");
2245 snd_hda_sequence_write(codec, ext_mic_present);
2246 } else if (dock_present) {
2247 snd_printdd("CXT5066: dock microphone detected\n");
2248 snd_hda_sequence_write(codec, dock_mic_present);
2249 } else {
2250 snd_printdd("CXT5066: external microphone absent\n");
2251 snd_hda_sequence_write(codec, ext_mic_absent);
2252 }
2253}
2254
Daniel Drake0fb67e92009-07-16 14:46:57 +01002255/* mute internal speaker if HP is plugged */
2256static void cxt5066_hp_automute(struct hda_codec *codec)
2257{
2258 struct conexant_spec *spec = codec->spec;
2259 unsigned int portA, portD;
2260
2261 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002262 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002263
2264 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002265 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002266
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002267 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2268 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002269 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2270 portA, portD, spec->hp_present);
2271 cxt5066_update_speaker(codec);
2272}
2273
David Henningsson02b6b5b2011-01-21 13:27:39 +01002274/* Dispatch the right mic autoswitch function */
2275static void cxt5066_automic(struct hda_codec *codec)
2276{
2277 struct conexant_spec *spec = codec->spec;
2278
2279 if (spec->dell_vostro)
2280 cxt5066_vostro_automic(codec);
2281 else if (spec->ideapad)
2282 cxt5066_ideapad_automic(codec);
2283 else if (spec->thinkpad)
2284 cxt5066_thinkpad_automic(codec);
2285 else if (spec->hp_laptop)
2286 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002287 else if (spec->asus)
2288 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002289}
2290
Daniel Drake0fb67e92009-07-16 14:46:57 +01002291/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002292static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002293{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002294 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002295 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2296 switch (res >> 26) {
2297 case CONEXANT_HP_EVENT:
2298 cxt5066_hp_automute(codec);
2299 break;
2300 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002301 /* ignore mic events in DC mode; we're always using the jack */
2302 if (!spec->dc_enable)
2303 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002304 break;
2305 }
2306}
2307
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002308/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002309static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002310{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002311 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002312 switch (res >> 26) {
2313 case CONEXANT_HP_EVENT:
2314 cxt5066_hp_automute(codec);
2315 break;
2316 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002317 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002318 break;
2319 }
2320}
2321
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002322
Daniel Drake0fb67e92009-07-16 14:46:57 +01002323static const struct hda_input_mux cxt5066_analog_mic_boost = {
2324 .num_items = 5,
2325 .items = {
2326 { "0dB", 0 },
2327 { "10dB", 1 },
2328 { "20dB", 2 },
2329 { "30dB", 3 },
2330 { "40dB", 4 },
2331 },
2332};
2333
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002334static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002335{
2336 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002337 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002338 AC_VERB_SET_AMP_GAIN_MUTE,
2339 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2340 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002341 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002342 /* adjust the internal mic as well...it is not through 0x17 */
2343 snd_hda_codec_write_cache(codec, 0x23, 0,
2344 AC_VERB_SET_AMP_GAIN_MUTE,
2345 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2346 cxt5066_analog_mic_boost.
2347 items[spec->mic_boost].index);
2348 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002349}
2350
Daniel Drake0fb67e92009-07-16 14:46:57 +01002351static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2352 struct snd_ctl_elem_info *uinfo)
2353{
2354 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2355}
2356
2357static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2358 struct snd_ctl_elem_value *ucontrol)
2359{
2360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002361 struct conexant_spec *spec = codec->spec;
2362 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002363 return 0;
2364}
2365
2366static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2367 struct snd_ctl_elem_value *ucontrol)
2368{
2369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002370 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002371 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2372 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002373 idx = ucontrol->value.enumerated.item[0];
2374 if (idx >= imux->num_items)
2375 idx = imux->num_items - 1;
2376
Daniel Drakec4cfe662010-01-07 13:47:04 +01002377 spec->mic_boost = idx;
2378 if (!spec->dc_enable)
2379 cxt5066_set_mic_boost(codec);
2380 return 1;
2381}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002382
Daniel Drakec4cfe662010-01-07 13:47:04 +01002383static void cxt5066_enable_dc(struct hda_codec *codec)
2384{
2385 const struct hda_verb enable_dc_mode[] = {
2386 /* disable gain */
2387 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2388
2389 /* switch to DC input */
2390 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2391 {}
2392 };
2393
2394 /* configure as input source */
2395 snd_hda_sequence_write(codec, enable_dc_mode);
2396 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2397}
2398
2399static void cxt5066_disable_dc(struct hda_codec *codec)
2400{
2401 /* reconfigure input source */
2402 cxt5066_set_mic_boost(codec);
2403 /* automic also selects the right mic if we're recording */
2404 cxt5066_olpc_automic(codec);
2405}
2406
2407static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2408 struct snd_ctl_elem_value *ucontrol)
2409{
2410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2411 struct conexant_spec *spec = codec->spec;
2412 ucontrol->value.integer.value[0] = spec->dc_enable;
2413 return 0;
2414}
2415
2416static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2417 struct snd_ctl_elem_value *ucontrol)
2418{
2419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2420 struct conexant_spec *spec = codec->spec;
2421 int dc_enable = !!ucontrol->value.integer.value[0];
2422
2423 if (dc_enable == spec->dc_enable)
2424 return 0;
2425
2426 spec->dc_enable = dc_enable;
2427 if (dc_enable)
2428 cxt5066_enable_dc(codec);
2429 else
2430 cxt5066_disable_dc(codec);
2431
2432 return 1;
2433}
2434
2435static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2436 struct snd_ctl_elem_info *uinfo)
2437{
2438 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2439}
2440
2441static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2442 struct snd_ctl_elem_value *ucontrol)
2443{
2444 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2445 struct conexant_spec *spec = codec->spec;
2446 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2447 return 0;
2448}
2449
2450static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2451 struct snd_ctl_elem_value *ucontrol)
2452{
2453 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2454 struct conexant_spec *spec = codec->spec;
2455 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2456 unsigned int idx;
2457
2458 idx = ucontrol->value.enumerated.item[0];
2459 if (idx >= imux->num_items)
2460 idx = imux->num_items - 1;
2461
2462 spec->dc_input_bias = idx;
2463 if (spec->dc_enable)
2464 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002465 return 1;
2466}
2467
Daniel Drake75f89912010-01-07 13:46:25 +01002468static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2469{
2470 struct conexant_spec *spec = codec->spec;
2471 /* mark as recording and configure the microphone widget so that the
2472 * recording LED comes on. */
2473 spec->recording = 1;
2474 cxt5066_olpc_select_mic(codec);
2475}
2476
2477static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2478{
2479 struct conexant_spec *spec = codec->spec;
2480 const struct hda_verb disable_mics[] = {
2481 /* disable external mic, port B */
2482 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2483
2484 /* disble internal mic, port C */
2485 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002486
2487 /* disable DC capture, port F */
2488 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002489 {},
2490 };
2491
2492 snd_hda_sequence_write(codec, disable_mics);
2493 spec->recording = 0;
2494}
2495
Andy Robinsonf6a24912011-01-24 10:12:37 -05002496static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002497 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002498 int num_pins)
2499{
2500 struct conexant_spec *spec = codec->spec;
2501 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2502 int i;
2503
2504 for (i = 0; i < num_pins; i++, dig_pins++) {
2505 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2506 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2507 continue;
2508 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2509 continue;
2510 if (spec->slave_dig_outs[0])
2511 nid_loc++;
2512 else
2513 nid_loc = spec->slave_dig_outs;
2514 }
2515}
2516
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002517static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002518 .num_items = 4,
2519 .items = {
2520 { "Mic B", 0 },
2521 { "Mic C", 1 },
2522 { "Mic E", 2 },
2523 { "Mic F", 3 },
2524 },
2525};
2526
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002527static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002528 .ops = &snd_hda_bind_vol,
2529 .values = {
2530 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2531 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2532 0
2533 },
2534};
2535
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002536static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002537 .ops = &snd_hda_bind_sw,
2538 .values = {
2539 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2540 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2541 0
2542 },
2543};
2544
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002545static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002546 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2547 {}
2548};
2549
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002550static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002551 {
2552 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2553 .name = "Master Playback Volume",
2554 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2555 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2556 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002557 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002558 .info = snd_hda_mixer_amp_volume_info,
2559 .get = snd_hda_mixer_amp_volume_get,
2560 .put = snd_hda_mixer_amp_volume_put,
2561 .tlv = { .c = snd_hda_mixer_amp_tlv },
2562 /* offset by 28 volume steps to limit minimum gain to -46dB */
2563 .private_value =
2564 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2565 },
2566 {}
2567};
2568
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002569static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002570 {
2571 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2572 .name = "DC Mode Enable Switch",
2573 .info = snd_ctl_boolean_mono_info,
2574 .get = cxt5066_olpc_dc_get,
2575 .put = cxt5066_olpc_dc_put,
2576 },
2577 {
2578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2579 .name = "DC Input Bias Enum",
2580 .info = cxt5066_olpc_dc_bias_enum_info,
2581 .get = cxt5066_olpc_dc_bias_enum_get,
2582 .put = cxt5066_olpc_dc_bias_enum_put,
2583 },
2584 {}
2585};
2586
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002587static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002588 {
2589 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2590 .name = "Master Playback Switch",
2591 .info = cxt_eapd_info,
2592 .get = cxt_eapd_get,
2593 .put = cxt5066_hp_master_sw_put,
2594 .private_value = 0x1d,
2595 },
2596
2597 {
2598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002599 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002600 .info = cxt5066_mic_boost_mux_enum_info,
2601 .get = cxt5066_mic_boost_mux_enum_get,
2602 .put = cxt5066_mic_boost_mux_enum_put,
2603 },
2604
2605 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2606 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2607 {}
2608};
2609
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002610static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002611 {
2612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002613 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002614 .info = cxt5066_mic_boost_mux_enum_info,
2615 .get = cxt5066_mic_boost_mux_enum_get,
2616 .put = cxt5066_mic_boost_mux_enum_put,
2617 .private_value = 0x23 | 0x100,
2618 },
2619 {}
2620};
2621
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002622static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002623 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2624 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2625 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2626 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2627
2628 /* Speakers */
2629 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2630 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2631
2632 /* HP, Amp */
2633 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2634 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2635
2636 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2637 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2638
2639 /* DAC1 */
2640 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2641
2642 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2643 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2644 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2645 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2646 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2647 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2648
2649 /* no digital microphone support yet */
2650 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2651
2652 /* Audio input selector */
2653 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2654
2655 /* SPDIF route: PCM */
2656 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2657 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2658
2659 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2660 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2661
2662 /* EAPD */
2663 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2664
2665 /* not handling these yet */
2666 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2667 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2668 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2669 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2670 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2671 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2672 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2673 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2674 { } /* end */
2675};
2676
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002677static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002678 /* Port A: headphones */
2679 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2680 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2681
2682 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002683 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002684
2685 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002686 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002687
2688 /* Port D: unused */
2689 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2690
2691 /* Port E: unused, but has primary EAPD */
2692 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2693 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2694
Daniel Drakec4cfe662010-01-07 13:47:04 +01002695 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002696 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2697
2698 /* Port G: internal speakers */
2699 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2700 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2701
2702 /* DAC1 */
2703 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2704
2705 /* DAC2: unused */
2706 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2707
2708 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2709 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2710 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2711 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2712 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2713 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2714 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2715 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2716 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2717 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2718 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2719 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2720
2721 /* Disable digital microphone port */
2722 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2723
2724 /* Audio input selectors */
2725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2726 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2727
2728 /* Disable SPDIF */
2729 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2730 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731
2732 /* enable unsolicited events for Port A and B */
2733 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2734 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2735 { } /* end */
2736};
2737
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002738static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002739 /* Port A: headphones */
2740 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2741 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2742
2743 /* Port B: external microphone */
2744 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2745
2746 /* Port C: unused */
2747 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2748
2749 /* Port D: unused */
2750 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2751
2752 /* Port E: unused, but has primary EAPD */
2753 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2754 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2755
2756 /* Port F: unused */
2757 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2758
2759 /* Port G: internal speakers */
2760 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2761 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2762
2763 /* DAC1 */
2764 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2765
2766 /* DAC2: unused */
2767 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2768
2769 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2773 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2774 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2775 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2776 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2777 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2778 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2779 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2781
2782 /* Digital microphone port */
2783 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2784
2785 /* Audio input selectors */
2786 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2787 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2788
2789 /* Disable SPDIF */
2790 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2791 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2792
2793 /* enable unsolicited events for Port A and B */
2794 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2795 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2796 { } /* end */
2797};
2798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002799static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002800 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2801 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2802 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2803 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2804
2805 /* Speakers */
2806 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2807 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2808
2809 /* HP, Amp */
2810 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2811 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2812
2813 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2814 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2815
2816 /* DAC1 */
2817 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2818
2819 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2825 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2826
2827 /* Audio input selector */
2828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2829 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2830
2831 /* SPDIF route: PCM */
2832 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2833 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2834
2835 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2836 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2837
2838 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002839 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002840
2841 /* EAPD */
2842 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2843
2844 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2845 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2846 { } /* end */
2847};
2848
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002849static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002850 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2851 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2852
2853 /* Port G: internal speakers */
2854 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2855 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2856
2857 /* Port A: HP, Amp */
2858 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2859 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2860
2861 /* Port B: Mic Dock */
2862 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863
2864 /* Port C: Mic */
2865 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866
2867 /* Port D: HP Dock, Amp */
2868 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2869 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2870
2871 /* DAC1 */
2872 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2873
2874 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2877 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2880 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2881
2882 /* Audio input selector */
2883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2884 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2885
2886 /* SPDIF route: PCM */
2887 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2888 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2889
2890 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2891 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2892
2893 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002894 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002895
2896 /* EAPD */
2897 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2898
2899 /* enable unsolicited events for Port A, B, C and D */
2900 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2901 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2903 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2904 { } /* end */
2905};
2906
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002907static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002908 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2909 { } /* end */
2910};
2911
David Henningsson048e78a2010-09-02 08:35:47 +02002912
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002913static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002914 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2915 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2916 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2917 { } /* end */
2918};
2919
Daniel Drake0fb67e92009-07-16 14:46:57 +01002920/* initialize jack-sensing, too */
2921static int cxt5066_init(struct hda_codec *codec)
2922{
2923 snd_printdd("CXT5066: init\n");
2924 conexant_init(codec);
2925 if (codec->patch_ops.unsol_event) {
2926 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002927 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002928 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002929 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002930 return 0;
2931}
2932
Daniel Drake75f89912010-01-07 13:46:25 +01002933static int cxt5066_olpc_init(struct hda_codec *codec)
2934{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002935 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002936 snd_printdd("CXT5066: init\n");
2937 conexant_init(codec);
2938 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002939 if (!spec->dc_enable) {
2940 cxt5066_set_mic_boost(codec);
2941 cxt5066_olpc_automic(codec);
2942 } else {
2943 cxt5066_enable_dc(codec);
2944 }
Daniel Drake75f89912010-01-07 13:46:25 +01002945 return 0;
2946}
2947
Daniel Drake0fb67e92009-07-16 14:46:57 +01002948enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002949 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002950 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2951 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002952 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002953 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002954 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002955 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002956 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002957 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002958 CXT5066_MODELS
2959};
2960
Takashi Iwaiea734962011-01-17 11:29:34 +01002961static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002962 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002963 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2964 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002965 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002966 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002967 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002968 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002969 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002970 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002971};
2972
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002973static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02002974 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002975 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002976 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002977 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002978 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02002979 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002980 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002981 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2982 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002983 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002984 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002985 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002986 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002987 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002988 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002989 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2990 CXT5066_LAPTOP),
2991 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002992 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002993 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002994 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson29c5fbb2012-01-23 16:39:55 +01002995 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
Daniel Suchyca201c02011-10-18 11:09:44 +02002996 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02002997 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002998 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002999 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003000 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003001 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003002 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003003 {}
3004};
3005
3006static int patch_cxt5066(struct hda_codec *codec)
3007{
3008 struct conexant_spec *spec;
3009 int board_config;
3010
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003011 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3012 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003013 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003014 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003015 if (board_config == CXT5066_AUTO)
3016 return patch_conexant_auto(codec);
3017
Daniel Drake0fb67e92009-07-16 14:46:57 +01003018 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3019 if (!spec)
3020 return -ENOMEM;
3021 codec->spec = spec;
3022
3023 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003024 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003025
3026 spec->dell_automute = 0;
3027 spec->multiout.max_channels = 2;
3028 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3029 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003030 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3031 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032 spec->num_adc_nids = 1;
3033 spec->adc_nids = cxt5066_adc_nids;
3034 spec->capsrc_nids = cxt5066_capsrc_nids;
3035 spec->input_mux = &cxt5066_capture_source;
3036
3037 spec->port_d_mode = PIN_HP;
3038
3039 spec->num_init_verbs = 1;
3040 spec->init_verbs[0] = cxt5066_init_verbs;
3041 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3042 spec->channel_mode = cxt5066_modes;
3043 spec->cur_adc = 0;
3044 spec->cur_adc_idx = 0;
3045
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003046 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3047
Daniel Drake0fb67e92009-07-16 14:46:57 +01003048 switch (board_config) {
3049 default:
3050 case CXT5066_LAPTOP:
3051 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3052 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3053 break;
3054 case CXT5066_DELL_LAPTOP:
3055 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3056 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3057
3058 spec->port_d_mode = PIN_OUT;
3059 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3060 spec->num_init_verbs++;
3061 spec->dell_automute = 1;
3062 break;
David Henningssona1d69062011-01-21 13:33:28 +01003063 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003064 case CXT5066_HP_LAPTOP:
3065 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003066 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003067 spec->init_verbs[spec->num_init_verbs] =
3068 cxt5066_init_verbs_hp_laptop;
3069 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003070 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3071 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003072 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3073 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3074 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003075 if (board_config == CXT5066_HP_LAPTOP)
3076 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003077 /* input source automatically selected */
3078 spec->input_mux = NULL;
3079 spec->port_d_mode = 0;
3080 spec->mic_boost = 3; /* default 30dB gain */
3081 break;
3082
Daniel Drake0fb67e92009-07-16 14:46:57 +01003083 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003084 codec->patch_ops.init = cxt5066_olpc_init;
3085 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003086 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3087 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003088 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003089 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3090 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003091 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003092
3093 /* no S/PDIF out */
3094 spec->multiout.dig_out_nid = 0;
3095
3096 /* input source automatically selected */
3097 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003098
3099 /* our capture hooks which allow us to turn on the microphone LED
3100 * at the right time */
3101 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3102 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003103 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003104 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003105 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003106 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003107 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3108 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3109 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003110 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003111 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003112 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003113 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003114
3115 /* no S/PDIF out */
3116 spec->multiout.dig_out_nid = 0;
3117
3118 /* input source automatically selected */
3119 spec->input_mux = NULL;
3120 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003121 case CXT5066_IDEAPAD:
3122 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003123 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003124 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3125 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3126 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3127 spec->port_d_mode = 0;
3128 spec->ideapad = 1;
3129 spec->mic_boost = 2; /* default 20dB gain */
3130
3131 /* no S/PDIF out */
3132 spec->multiout.dig_out_nid = 0;
3133
3134 /* input source automatically selected */
3135 spec->input_mux = NULL;
3136 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003137 case CXT5066_THINKPAD:
3138 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003139 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003140 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3141 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3142 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3143 spec->thinkpad = 1;
3144 spec->port_d_mode = PIN_OUT;
3145 spec->mic_boost = 2; /* default 20dB gain */
3146
3147 /* no S/PDIF out */
3148 spec->multiout.dig_out_nid = 0;
3149
3150 /* input source automatically selected */
3151 spec->input_mux = NULL;
3152 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003153 }
3154
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003155 if (spec->beep_amp)
3156 snd_hda_attach_beep_device(codec, spec->beep_amp);
3157
Daniel Drake0fb67e92009-07-16 14:46:57 +01003158 return 0;
3159}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003160
3161/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003162 * Automatic parser for CX20641 & co
3163 */
3164
Takashi Iwai6764bce2011-05-13 16:52:25 +02003165static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3166 struct hda_codec *codec,
3167 unsigned int stream_tag,
3168 unsigned int format,
3169 struct snd_pcm_substream *substream)
3170{
3171 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003172 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003173 if (spec->adc_switching) {
3174 spec->cur_adc = adc;
3175 spec->cur_adc_stream_tag = stream_tag;
3176 spec->cur_adc_format = format;
3177 }
3178 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3179 return 0;
3180}
3181
3182static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3183 struct hda_codec *codec,
3184 struct snd_pcm_substream *substream)
3185{
3186 struct conexant_spec *spec = codec->spec;
3187 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3188 spec->cur_adc = 0;
3189 return 0;
3190}
3191
3192static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3193 .substreams = 1,
3194 .channels_min = 2,
3195 .channels_max = 2,
3196 .nid = 0, /* fill later */
3197 .ops = {
3198 .prepare = cx_auto_capture_pcm_prepare,
3199 .cleanup = cx_auto_capture_pcm_cleanup
3200 },
3201};
3202
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003203static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003204
Takashi Iwai8d087c72011-06-28 12:45:47 +02003205#define get_connection_index(codec, mux, nid)\
3206 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003207
3208/* get an unassigned DAC from the given list.
3209 * Return the nid if found and reduce the DAC list, or return zero if
3210 * not found
3211 */
3212static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3213 hda_nid_t *dacs, int *num_dacs)
3214{
3215 int i, nums = *num_dacs;
3216 hda_nid_t ret = 0;
3217
3218 for (i = 0; i < nums; i++) {
3219 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3220 ret = dacs[i];
3221 break;
3222 }
3223 }
3224 if (!ret)
3225 return 0;
3226 if (--nums > 0)
3227 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3228 *num_dacs = nums;
3229 return ret;
3230}
3231
3232#define MAX_AUTO_DACS 5
3233
Takashi Iwai1f015f52011-08-23 14:57:08 +02003234#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3235
Takashi Iwaif2e57312010-09-15 10:07:08 +02003236/* fill analog DAC list from the widget tree */
3237static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3238{
3239 hda_nid_t nid, end_nid;
3240 int nums = 0;
3241
3242 end_nid = codec->start_nid + codec->num_nodes;
3243 for (nid = codec->start_nid; nid < end_nid; nid++) {
3244 unsigned int wcaps = get_wcaps(codec, nid);
3245 unsigned int type = get_wcaps_type(wcaps);
3246 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3247 dacs[nums++] = nid;
3248 if (nums >= MAX_AUTO_DACS)
3249 break;
3250 }
3251 }
3252 return nums;
3253}
3254
3255/* fill pin_dac_pair list from the pin and dac list */
3256static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3257 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003258 struct pin_dac_pair *filled, int nums,
3259 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003260{
David Henningsson468c5452011-08-25 13:16:02 +02003261 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003262
David Henningsson468c5452011-08-25 13:16:02 +02003263 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003264 filled[nums].pin = pins[i];
3265 filled[nums].type = type;
3266 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003267 if (filled[nums].dac)
3268 continue;
3269 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3270 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3271 continue;
3272 }
3273 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003274 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003275 continue;
3276 }
3277 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003278 }
3279 return nums;
3280}
3281
3282/* parse analog output paths */
3283static void cx_auto_parse_output(struct hda_codec *codec)
3284{
3285 struct conexant_spec *spec = codec->spec;
3286 struct auto_pin_cfg *cfg = &spec->autocfg;
3287 hda_nid_t dacs[MAX_AUTO_DACS];
3288 int i, j, nums, rest;
3289
3290 rest = fill_cx_auto_dacs(codec, dacs);
3291 /* parse all analog output pins */
3292 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003293 dacs, &rest, spec->dac_info, 0,
3294 AUTO_PIN_LINE_OUT);
3295 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3296 dacs, &rest, spec->dac_info, nums,
3297 AUTO_PIN_HP_OUT);
3298 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3299 dacs, &rest, spec->dac_info, nums,
3300 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003301 spec->dac_info_filled = nums;
3302 /* fill multiout struct */
3303 for (i = 0; i < nums; i++) {
3304 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003305 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003306 continue;
3307 switch (spec->dac_info[i].type) {
3308 case AUTO_PIN_LINE_OUT:
3309 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3310 spec->multiout.num_dacs++;
3311 break;
3312 case AUTO_PIN_HP_OUT:
3313 case AUTO_PIN_SPEAKER_OUT:
3314 if (!spec->multiout.hp_nid) {
3315 spec->multiout.hp_nid = dac;
3316 break;
3317 }
3318 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3319 if (!spec->multiout.extra_out_nid[j]) {
3320 spec->multiout.extra_out_nid[j] = dac;
3321 break;
3322 }
3323 break;
3324 }
3325 }
3326 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003327 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003328
Takashi Iwai03697e22011-05-17 09:53:31 +02003329 for (i = 0; i < cfg->hp_outs; i++) {
3330 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3331 spec->auto_mute = 1;
3332 break;
3333 }
3334 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003335 if (spec->auto_mute &&
3336 cfg->line_out_pins[0] &&
3337 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003338 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3339 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3340 for (i = 0; i < cfg->line_outs; i++) {
3341 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3342 spec->detect_line = 1;
3343 break;
3344 }
3345 }
3346 spec->automute_lines = spec->detect_line;
3347 }
3348
Takashi Iwaif2e57312010-09-15 10:07:08 +02003349 spec->vmaster_nid = spec->private_dac_nids[0];
3350}
3351
Takashi Iwaida339862011-05-13 16:24:15 +02003352static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3353 hda_nid_t *pins, bool on);
3354
Takashi Iwai03697e22011-05-17 09:53:31 +02003355static void do_automute(struct hda_codec *codec, int num_pins,
3356 hda_nid_t *pins, bool on)
3357{
Takashi Iwai254f2962011-10-14 15:22:34 +02003358 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003359 int i;
3360 for (i = 0; i < num_pins; i++)
3361 snd_hda_codec_write(codec, pins[i], 0,
3362 AC_VERB_SET_PIN_WIDGET_CONTROL,
3363 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003364 if (spec->pin_eapd_ctrls)
3365 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003366}
3367
3368static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3369{
3370 int i, present = 0;
3371
3372 for (i = 0; i < num_pins; i++) {
3373 hda_nid_t nid = pins[i];
3374 if (!nid || !is_jack_detectable(codec, nid))
3375 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003376 present |= snd_hda_jack_detect(codec, nid);
3377 }
3378 return present;
3379}
3380
Takashi Iwaif2e57312010-09-15 10:07:08 +02003381/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003382static void cx_auto_update_speakers(struct hda_codec *codec)
3383{
3384 struct conexant_spec *spec = codec->spec;
3385 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003386 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003387
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003388 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003389 if (spec->pin_eapd_ctrls) {
3390 if (spec->auto_mute)
3391 on = spec->hp_present;
3392 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3393 }
3394
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003395 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3396 if (spec->auto_mute)
3397 on = !(spec->hp_present ||
3398 (spec->detect_line && spec->line_present));
3399 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003400
3401 /* toggle line-out mutes if needed, too */
3402 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3403 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3404 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3405 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003406 if (spec->auto_mute) {
3407 /* mute LO in auto-mode when HP jack is present */
3408 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3409 spec->automute_lines)
3410 on = !spec->hp_present;
3411 else
3412 on = 1;
3413 }
3414 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003415}
3416
Takashi Iwaif2e57312010-09-15 10:07:08 +02003417static void cx_auto_hp_automute(struct hda_codec *codec)
3418{
3419 struct conexant_spec *spec = codec->spec;
3420 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003421
3422 if (!spec->auto_mute)
3423 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003424 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3425 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003426}
3427
Takashi Iwai03697e22011-05-17 09:53:31 +02003428static void cx_auto_line_automute(struct hda_codec *codec)
3429{
3430 struct conexant_spec *spec = codec->spec;
3431 struct auto_pin_cfg *cfg = &spec->autocfg;
3432
3433 if (!spec->auto_mute || !spec->detect_line)
3434 return;
3435 spec->line_present = detect_jacks(codec, cfg->line_outs,
3436 cfg->line_out_pins);
3437 cx_auto_update_speakers(codec);
3438}
3439
3440static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3441 struct snd_ctl_elem_info *uinfo)
3442{
3443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3444 struct conexant_spec *spec = codec->spec;
3445 static const char * const texts2[] = {
3446 "Disabled", "Enabled"
3447 };
3448 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003449 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003450 };
3451 const char * const *texts;
3452
3453 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3454 uinfo->count = 1;
3455 if (spec->automute_hp_lo) {
3456 uinfo->value.enumerated.items = 3;
3457 texts = texts3;
3458 } else {
3459 uinfo->value.enumerated.items = 2;
3460 texts = texts2;
3461 }
3462 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3463 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3464 strcpy(uinfo->value.enumerated.name,
3465 texts[uinfo->value.enumerated.item]);
3466 return 0;
3467}
3468
3469static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3470 struct snd_ctl_elem_value *ucontrol)
3471{
3472 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3473 struct conexant_spec *spec = codec->spec;
3474 unsigned int val;
3475 if (!spec->auto_mute)
3476 val = 0;
3477 else if (!spec->automute_lines)
3478 val = 1;
3479 else
3480 val = 2;
3481 ucontrol->value.enumerated.item[0] = val;
3482 return 0;
3483}
3484
3485static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3486 struct snd_ctl_elem_value *ucontrol)
3487{
3488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3489 struct conexant_spec *spec = codec->spec;
3490
3491 switch (ucontrol->value.enumerated.item[0]) {
3492 case 0:
3493 if (!spec->auto_mute)
3494 return 0;
3495 spec->auto_mute = 0;
3496 break;
3497 case 1:
3498 if (spec->auto_mute && !spec->automute_lines)
3499 return 0;
3500 spec->auto_mute = 1;
3501 spec->automute_lines = 0;
3502 break;
3503 case 2:
3504 if (!spec->automute_hp_lo)
3505 return -EINVAL;
3506 if (spec->auto_mute && spec->automute_lines)
3507 return 0;
3508 spec->auto_mute = 1;
3509 spec->automute_lines = 1;
3510 break;
3511 default:
3512 return -EINVAL;
3513 }
3514 cx_auto_update_speakers(codec);
3515 return 1;
3516}
3517
3518static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3519 {
3520 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3521 .name = "Auto-Mute Mode",
3522 .info = cx_automute_mode_info,
3523 .get = cx_automute_mode_get,
3524 .put = cx_automute_mode_put,
3525 },
3526 { }
3527};
3528
Takashi Iwai6764bce2011-05-13 16:52:25 +02003529static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3530 struct snd_ctl_elem_info *uinfo)
3531{
3532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3533 struct conexant_spec *spec = codec->spec;
3534
3535 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3536}
3537
3538static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3539 struct snd_ctl_elem_value *ucontrol)
3540{
3541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3542 struct conexant_spec *spec = codec->spec;
3543
3544 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3545 return 0;
3546}
3547
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003548/* look for the route the given pin from mux and return the index;
3549 * if do_select is set, actually select the route.
3550 */
3551static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003552 hda_nid_t pin, hda_nid_t *srcp,
3553 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003554{
3555 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3556 int i, nums;
3557
Takashi Iwaicf27f292011-05-16 11:33:02 +02003558 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3559 case AC_WID_AUD_IN:
3560 case AC_WID_AUD_SEL:
3561 case AC_WID_AUD_MIX:
3562 break;
3563 default:
3564 return -1;
3565 }
3566
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003567 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3568 for (i = 0; i < nums; i++)
3569 if (conn[i] == pin) {
3570 if (do_select)
3571 snd_hda_codec_write(codec, mux, 0,
3572 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003573 if (srcp)
3574 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003575 return i;
3576 }
3577 depth++;
3578 if (depth == 2)
3579 return -1;
3580 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003581 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003582 do_select, depth);
3583 if (ret >= 0) {
3584 if (do_select)
3585 snd_hda_codec_write(codec, mux, 0,
3586 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003587 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003588 }
3589 }
3590 return -1;
3591}
3592
3593static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3594 hda_nid_t pin)
3595{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003596 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003597}
3598
3599static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3600 hda_nid_t pin)
3601{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003602 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003603}
3604
Takashi Iwai6764bce2011-05-13 16:52:25 +02003605static int cx_auto_mux_enum_update(struct hda_codec *codec,
3606 const struct hda_input_mux *imux,
3607 unsigned int idx)
3608{
3609 struct conexant_spec *spec = codec->spec;
3610 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003611 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003612
3613 if (!imux->num_items)
3614 return 0;
3615 if (idx >= imux->num_items)
3616 idx = imux->num_items - 1;
3617 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003618 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003619 adc = spec->imux_info[idx].adc;
3620 select_input_connection(codec, spec->imux_info[idx].adc,
3621 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003622 if (spec->cur_adc && spec->cur_adc != adc) {
3623 /* stream is running, let's swap the current ADC */
3624 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3625 spec->cur_adc = adc;
3626 snd_hda_codec_setup_stream(codec, adc,
3627 spec->cur_adc_stream_tag, 0,
3628 spec->cur_adc_format);
3629 }
3630 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003631 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003632}
3633
3634static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3635 struct snd_ctl_elem_value *ucontrol)
3636{
3637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3638 struct conexant_spec *spec = codec->spec;
3639
3640 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3641 ucontrol->value.enumerated.item[0]);
3642}
3643
3644static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3645 {
3646 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3647 .name = "Capture Source",
3648 .info = cx_auto_mux_enum_info,
3649 .get = cx_auto_mux_enum_get,
3650 .put = cx_auto_mux_enum_put
3651 },
3652 {}
3653};
3654
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003655static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3656{
3657 struct conexant_spec *spec = codec->spec;
3658 if (idx < 0)
3659 return false;
3660 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3661 return false;
3662 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3663 return true;
3664}
3665
Takashi Iwaif2e57312010-09-15 10:07:08 +02003666/* automatic switch internal and external mic */
3667static void cx_auto_automic(struct hda_codec *codec)
3668{
3669 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003670
3671 if (!spec->auto_mic)
3672 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003673 if (!select_automic(codec, spec->auto_mic_ext, true))
3674 if (!select_automic(codec, spec->auto_mic_dock, true))
3675 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003676}
3677
3678static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3679{
Takashi Iwai3a938972011-10-28 01:16:55 +02003680 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003681 case CONEXANT_HP_EVENT:
3682 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003683 break;
3684 case CONEXANT_LINE_EVENT:
3685 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003686 break;
3687 case CONEXANT_MIC_EVENT:
3688 cx_auto_automic(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003689 break;
3690 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02003691 snd_hda_jack_report_sync(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003692}
3693
Takashi Iwaif2e57312010-09-15 10:07:08 +02003694/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003695 * auto-mic is enabled only when one int-mic and one ext- and/or
3696 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003697 */
3698static void cx_auto_check_auto_mic(struct hda_codec *codec)
3699{
3700 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003701 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3702 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003703
Takashi Iwai506a4192011-05-23 20:07:15 +02003704 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003705 pset[i] = -1;
3706 for (i = 0; i < spec->private_imux.num_items; i++) {
3707 hda_nid_t pin = spec->imux_info[i].pin;
3708 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003709 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003710 attr = snd_hda_get_input_pin_attr(def_conf);
3711 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003712 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003713 if (attr > INPUT_PIN_ATTR_NORMAL)
3714 attr = INPUT_PIN_ATTR_NORMAL;
3715 if (attr != INPUT_PIN_ATTR_INT &&
3716 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003717 return; /* non-detectable pin */
3718 type = get_defcfg_device(def_conf);
3719 if (type != AC_JACK_MIC_IN &&
3720 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3721 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003722 if (pset[attr] >= 0)
3723 return; /* already occupied */
3724 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003725 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003726 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3727 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3728 return; /* no input to switch*/
3729 spec->auto_mic = 1;
3730 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3731 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3732 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003733}
3734
3735static void cx_auto_parse_input(struct hda_codec *codec)
3736{
3737 struct conexant_spec *spec = codec->spec;
3738 struct auto_pin_cfg *cfg = &spec->autocfg;
3739 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003740 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003741
3742 imux = &spec->private_imux;
3743 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003744 for (j = 0; j < spec->num_adc_nids; j++) {
3745 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003746 int idx = get_input_connection(codec, adc,
3747 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003748 if (idx >= 0) {
3749 const char *label;
3750 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003751 spec->imux_info[imux->num_items].index = i;
3752 spec->imux_info[imux->num_items].boost = 0;
3753 spec->imux_info[imux->num_items].adc = adc;
3754 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003755 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003756 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003757 break;
3758 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003759 }
3760 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003761 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003762 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003763 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003764 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003765 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003766 spec->adc_switching = 1;
3767 break;
3768 }
3769 }
3770 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003771}
3772
3773/* get digital-input audio widget corresponding to the given pin */
3774static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3775{
3776 hda_nid_t nid, end_nid;
3777
3778 end_nid = codec->start_nid + codec->num_nodes;
3779 for (nid = codec->start_nid; nid < end_nid; nid++) {
3780 unsigned int wcaps = get_wcaps(codec, nid);
3781 unsigned int type = get_wcaps_type(wcaps);
3782 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3783 if (get_connection_index(codec, nid, pin) >= 0)
3784 return nid;
3785 }
3786 }
3787 return 0;
3788}
3789
3790static void cx_auto_parse_digital(struct hda_codec *codec)
3791{
3792 struct conexant_spec *spec = codec->spec;
3793 struct auto_pin_cfg *cfg = &spec->autocfg;
3794 hda_nid_t nid;
3795
3796 if (cfg->dig_outs &&
3797 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3798 spec->multiout.dig_out_nid = nid;
3799 if (cfg->dig_in_pin)
3800 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3801}
3802
3803#ifdef CONFIG_SND_HDA_INPUT_BEEP
3804static void cx_auto_parse_beep(struct hda_codec *codec)
3805{
3806 struct conexant_spec *spec = codec->spec;
3807 hda_nid_t nid, end_nid;
3808
3809 end_nid = codec->start_nid + codec->num_nodes;
3810 for (nid = codec->start_nid; nid < end_nid; nid++)
3811 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3812 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3813 break;
3814 }
3815}
3816#else
3817#define cx_auto_parse_beep(codec)
3818#endif
3819
Takashi Iwai254f2962011-10-14 15:22:34 +02003820/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003821static void cx_auto_parse_eapd(struct hda_codec *codec)
3822{
3823 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003824 hda_nid_t nid, end_nid;
3825
3826 end_nid = codec->start_nid + codec->num_nodes;
3827 for (nid = codec->start_nid; nid < end_nid; nid++) {
3828 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3829 continue;
3830 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3831 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003832 spec->eapds[spec->num_eapds++] = nid;
3833 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3834 break;
3835 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003836
3837 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3838 * it's a new chip, where EAPDs are supposed to be associated to
3839 * pins, and we can control EAPD per pin.
3840 * OTOH, if only one or two EAPDs are found, it's an old chip,
3841 * thus it might control over all pins.
3842 */
3843 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003844}
3845
Takashi Iwaif2e57312010-09-15 10:07:08 +02003846static int cx_auto_parse_auto_config(struct hda_codec *codec)
3847{
3848 struct conexant_spec *spec = codec->spec;
3849 int err;
3850
3851 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3852 if (err < 0)
3853 return err;
3854
3855 cx_auto_parse_output(codec);
3856 cx_auto_parse_input(codec);
3857 cx_auto_parse_digital(codec);
3858 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003859 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003860 return 0;
3861}
3862
Takashi Iwaida339862011-05-13 16:24:15 +02003863static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3864 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003865{
3866 int i;
3867 for (i = 0; i < num_pins; i++) {
3868 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3869 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003870 AC_VERB_SET_EAPD_BTLENABLE,
3871 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003872 }
3873}
3874
3875static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3876 hda_nid_t src)
3877{
3878 int idx = get_connection_index(codec, pin, src);
3879 if (idx >= 0)
3880 snd_hda_codec_write(codec, pin, 0,
3881 AC_VERB_SET_CONNECT_SEL, idx);
3882}
3883
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003884static void mute_outputs(struct hda_codec *codec, int num_nids,
3885 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003886{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003887 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003888
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003889 for (i = 0; i < num_nids; i++) {
3890 hda_nid_t nid = nids[i];
3891 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3892 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003893 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3894 val = AMP_OUT_MUTE;
3895 else
3896 val = AMP_OUT_ZERO;
3897 snd_hda_codec_write(codec, nid, 0,
3898 AC_VERB_SET_AMP_GAIN_MUTE, val);
3899 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003900}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003901
Takashi Iwai03697e22011-05-17 09:53:31 +02003902static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
Takashi Iwai3a938972011-10-28 01:16:55 +02003903 hda_nid_t *pins, unsigned int action)
Takashi Iwai03697e22011-05-17 09:53:31 +02003904{
3905 int i;
3906 for (i = 0; i < num_pins; i++)
Takashi Iwai3a938972011-10-28 01:16:55 +02003907 snd_hda_jack_detect_enable(codec, pins[i], action);
Takashi Iwai03697e22011-05-17 09:53:31 +02003908}
3909
Takashi Iwai07cafff2012-02-20 12:30:59 +01003910static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3911{
3912 int i;
3913 for (i = 0; i < nums; i++)
3914 if (list[i] == nid)
3915 return true;
3916 return false;
3917}
3918
3919/* is the given NID found in any of autocfg items? */
3920static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3921{
3922 int i;
3923
3924 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3925 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3926 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3927 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3928 return true;
3929 for (i = 0; i < cfg->num_inputs; i++)
3930 if (cfg->inputs[i].pin == nid)
3931 return true;
3932 if (cfg->dig_in_pin == nid)
3933 return true;
3934 return false;
3935}
3936
3937/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3938 * invalid unsol tags by some reason
3939 */
3940static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3941{
3942 struct conexant_spec *spec = codec->spec;
3943 struct auto_pin_cfg *cfg = &spec->autocfg;
3944 int i;
3945
3946 for (i = 0; i < codec->init_pins.used; i++) {
3947 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3948 if (!found_in_autocfg(cfg, pin->nid))
3949 snd_hda_codec_write(codec, pin->nid, 0,
3950 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3951 }
3952}
3953
Takashi Iwai527c73b2012-03-12 12:38:51 +01003954/* turn on/off EAPD according to Master switch */
3955static void cx_auto_vmaster_hook(void *private_data, int enabled)
3956{
3957 struct hda_codec *codec = private_data;
3958 struct conexant_spec *spec = codec->spec;
3959
3960 if (enabled && spec->pin_eapd_ctrls) {
3961 cx_auto_update_speakers(codec);
3962 return;
3963 }
3964 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3965}
3966
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003967static void cx_auto_init_output(struct hda_codec *codec)
3968{
3969 struct conexant_spec *spec = codec->spec;
3970 struct auto_pin_cfg *cfg = &spec->autocfg;
3971 hda_nid_t nid;
3972 int i;
3973
3974 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003975 for (i = 0; i < cfg->hp_outs; i++) {
3976 unsigned int val = PIN_OUT;
3977 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3978 AC_PINCAP_HP_DRV)
3979 val |= AC_PINCTL_HP_EN;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003980 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
Takashi Iwaica3649d2012-04-19 15:15:25 +02003981 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
3982 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003983 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3984 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3985 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003986 for (i = 0; i < spec->dac_info_filled; i++) {
3987 nid = spec->dac_info[i].dac;
3988 if (!nid)
3989 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003990 else if (nid & DAC_SLAVE_FLAG)
3991 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003992 select_connection(codec, spec->dac_info[i].pin, nid);
3993 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003994 if (spec->auto_mute) {
3995 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3996 CONEXANT_HP_EVENT);
3997 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3998 cfg->hp_pins);
3999 if (spec->detect_line) {
4000 enable_unsol_pins(codec, cfg->line_outs,
4001 cfg->line_out_pins,
4002 CONEXANT_LINE_EVENT);
4003 spec->line_present =
4004 detect_jacks(codec, cfg->line_outs,
4005 cfg->line_out_pins);
4006 }
4007 }
4008 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004009 /* turn on all EAPDs if no individual EAPD control is available */
4010 if (!spec->pin_eapd_ctrls)
4011 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01004012 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004013}
4014
4015static void cx_auto_init_input(struct hda_codec *codec)
4016{
4017 struct conexant_spec *spec = codec->spec;
4018 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004019 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004020
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004021 for (i = 0; i < spec->num_adc_nids; i++) {
4022 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004023 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4024 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004025 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4026 val = AMP_IN_MUTE(0);
4027 else
4028 val = AMP_IN_UNMUTE(0);
4029 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4030 val);
4031 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004032
4033 for (i = 0; i < cfg->num_inputs; i++) {
4034 unsigned int type;
4035 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4036 type = PIN_VREF80;
4037 else
4038 type = PIN_IN;
4039 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4040 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4041 }
4042
4043 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004044 if (spec->auto_mic_ext >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004045 snd_hda_jack_detect_enable(codec,
4046 cfg->inputs[spec->auto_mic_ext].pin,
4047 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004048 }
4049 if (spec->auto_mic_dock >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004050 snd_hda_jack_detect_enable(codec,
4051 cfg->inputs[spec->auto_mic_dock].pin,
4052 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004053 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004054 cx_auto_automic(codec);
4055 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004056 select_input_connection(codec, spec->imux_info[0].adc,
4057 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004058 }
4059}
4060
4061static void cx_auto_init_digital(struct hda_codec *codec)
4062{
4063 struct conexant_spec *spec = codec->spec;
4064 struct auto_pin_cfg *cfg = &spec->autocfg;
4065
4066 if (spec->multiout.dig_out_nid)
4067 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4068 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4069 if (spec->dig_in_nid)
4070 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4071 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4072}
4073
4074static int cx_auto_init(struct hda_codec *codec)
4075{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004076 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004077 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4078 cx_auto_init_output(codec);
4079 cx_auto_init_input(codec);
4080 cx_auto_init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004081 snd_hda_jack_report_sync(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004082 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004083 return 0;
4084}
4085
David Henningsson983345e2011-02-15 19:57:09 +01004086static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004087 const char *dir, int cidx,
David Henningsson18dcd302012-04-02 15:40:27 +02004088 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004089{
David Henningsson18dcd302012-04-02 15:40:27 +02004090 static char name[44];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004091 static struct snd_kcontrol_new knew[] = {
4092 HDA_CODEC_VOLUME(name, 0, 0, 0),
4093 HDA_CODEC_MUTE(name, 0, 0, 0),
4094 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004095 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004096 int i, err;
4097
4098 for (i = 0; i < 2; i++) {
4099 struct snd_kcontrol *kctl;
David Henningsson18dcd302012-04-02 15:40:27 +02004100 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
David Henningsson983345e2011-02-15 19:57:09 +01004101 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004102 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4103 knew[i].index = cidx;
4104 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4105 kctl = snd_ctl_new1(&knew[i], codec);
4106 if (!kctl)
4107 return -ENOMEM;
4108 err = snd_hda_ctl_add(codec, nid, kctl);
4109 if (err < 0)
4110 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004111 if (!(query_amp_caps(codec, nid, hda_dir) &
4112 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004113 break;
4114 }
4115 return 0;
4116}
4117
David Henningsson983345e2011-02-15 19:57:09 +01004118#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
David Henningsson18dcd302012-04-02 15:40:27 +02004119 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
David Henningsson983345e2011-02-15 19:57:09 +01004120
Takashi Iwaif2e57312010-09-15 10:07:08 +02004121#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4122 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4123
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004124static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4125 hda_nid_t pin, const char *name, int idx)
4126{
4127 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004128 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4129 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4130 if (caps & AC_AMPCAP_NUM_STEPS)
4131 return cx_auto_add_pb_volume(codec, dac, name, idx);
4132 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004133 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4134 if (caps & AC_AMPCAP_NUM_STEPS)
4135 return cx_auto_add_pb_volume(codec, pin, name, idx);
4136 return 0;
4137}
4138
Takashi Iwaif2e57312010-09-15 10:07:08 +02004139static int cx_auto_build_output_controls(struct hda_codec *codec)
4140{
4141 struct conexant_spec *spec = codec->spec;
4142 int i, err;
4143 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004144 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004145
4146 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004147 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4148 spec->dac_info[0].pin,
4149 "Master", 0);
4150
Takashi Iwaif2e57312010-09-15 10:07:08 +02004151 for (i = 0; i < spec->dac_info_filled; i++) {
4152 const char *label;
4153 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004154 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004155 type = spec->dac_info[i].type;
4156 if (type == AUTO_PIN_LINE_OUT)
4157 type = spec->autocfg.line_out_type;
4158 switch (type) {
4159 case AUTO_PIN_LINE_OUT:
4160 default:
4161 label = texts[num_line++];
4162 idx = 0;
4163 break;
4164 case AUTO_PIN_HP_OUT:
4165 label = "Headphone";
4166 idx = num_hp++;
4167 break;
4168 case AUTO_PIN_SPEAKER_OUT:
4169 label = "Speaker";
4170 idx = num_spk++;
4171 break;
4172 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004173 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004174 spec->dac_info[i].pin,
4175 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004176 if (err < 0)
4177 return err;
4178 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004179
4180 if (spec->auto_mute) {
4181 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4182 if (err < 0)
4183 return err;
4184 }
4185
Takashi Iwaif2e57312010-09-15 10:07:08 +02004186 return 0;
4187}
4188
David Henningsson18dcd302012-04-02 15:40:27 +02004189/* Returns zero if this is a normal stereo channel, and non-zero if it should
4190 be split in two independent channels.
4191 dest_label must be at least 44 characters. */
4192static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4193 char *dest_label, int nid)
4194{
4195 struct conexant_spec *spec = codec->spec;
4196 int i;
4197
4198 if (!spec->fixup_stereo_dmic)
4199 return 0;
4200
4201 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4202 int def_conf;
4203 if (spec->autocfg.inputs[i].pin != nid)
4204 continue;
4205
4206 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4207 return 0;
4208 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4209 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4210 return 0;
4211
4212 /* Finally found the inverted internal mic! */
4213 snprintf(dest_label, 44, "Inverted %s", label);
4214 return 1;
4215 }
4216 return 0;
4217}
4218
Takashi Iwai6764bce2011-05-13 16:52:25 +02004219static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4220 const char *label, const char *pfx,
4221 int cidx)
4222{
4223 struct conexant_spec *spec = codec->spec;
4224 int i;
4225
4226 for (i = 0; i < spec->num_adc_nids; i++) {
David Henningsson18dcd302012-04-02 15:40:27 +02004227 char rightch_label[44];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004228 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004229 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004230 if (idx < 0)
4231 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004232 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004233 idx = 0;
David Henningsson18dcd302012-04-02 15:40:27 +02004234
4235 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4236 /* Make two independent kcontrols for left and right */
4237 int err = cx_auto_add_volume_idx(codec, label, pfx,
4238 cidx, adc_nid, HDA_INPUT, idx, 1);
4239 if (err < 0)
4240 return err;
4241 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4242 cidx, adc_nid, HDA_INPUT, idx, 2);
4243 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004244 return cx_auto_add_volume_idx(codec, label, pfx,
David Henningsson18dcd302012-04-02 15:40:27 +02004245 cidx, adc_nid, HDA_INPUT, idx, 3);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004246 }
4247 return 0;
4248}
4249
Takashi Iwaicf27f292011-05-16 11:33:02 +02004250static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4251 const char *label, int cidx)
4252{
4253 struct conexant_spec *spec = codec->spec;
4254 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004255 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004256
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004257 nid = spec->imux_info[idx].pin;
David Henningsson18dcd302012-04-02 15:40:27 +02004258 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4259 char rightch_label[44];
4260 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4261 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4262 cidx, nid, HDA_INPUT, 0, 1);
4263 if (err < 0)
4264 return err;
4265 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4266 cidx, nid, HDA_INPUT, 0, 2);
4267 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004268 return cx_auto_add_volume(codec, label, " Boost", cidx,
4269 nid, HDA_INPUT);
David Henningsson18dcd302012-04-02 15:40:27 +02004270 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004271 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4272 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004273 if (con < 0)
4274 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004275 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004276 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004277 return 0; /* already present */
4278 }
4279
4280 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004281 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004282 return cx_auto_add_volume(codec, label, " Boost", 0,
4283 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004284 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004285 return 0;
4286}
4287
Takashi Iwaif2e57312010-09-15 10:07:08 +02004288static int cx_auto_build_input_controls(struct hda_codec *codec)
4289{
4290 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004291 struct hda_input_mux *imux = &spec->private_imux;
4292 const char *prev_label;
4293 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004294 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004295 int multi_connection;
4296
Takashi Iwai6b452142011-10-14 15:26:20 +02004297 if (!imux->num_items)
4298 return 0;
4299
Takashi Iwaicf27f292011-05-16 11:33:02 +02004300 multi_connection = 0;
4301 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004302 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4303 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004304 if (cidx < 0)
4305 continue;
4306 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004307 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004308 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004309 if (i > 0 && input_conn[i] != input_conn[0])
4310 multi_connection = 1;
4311 }
David Henningsson983345e2011-02-15 19:57:09 +01004312
Takashi Iwaif2e57312010-09-15 10:07:08 +02004313 prev_label = NULL;
4314 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004315 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004316 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004317 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004318
Takashi Iwaicf27f292011-05-16 11:33:02 +02004319 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004320 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004321 if (label == prev_label)
4322 cidx++;
4323 else
4324 cidx = 0;
4325 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004326
Takashi Iwaicf27f292011-05-16 11:33:02 +02004327 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4328 if (err < 0)
4329 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004330
Takashi Iwaicf27f292011-05-16 11:33:02 +02004331 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004332 if (i > 0)
4333 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004334 err = cx_auto_add_capture_volume(codec, nid,
4335 "Capture", "", cidx);
4336 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004337 bool dup_found = false;
4338 for (j = 0; j < i; j++) {
4339 if (input_conn[j] == input_conn[i]) {
4340 dup_found = true;
4341 break;
4342 }
4343 }
4344 if (dup_found)
4345 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004346 err = cx_auto_add_capture_volume(codec, nid,
4347 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004348 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004349 if (err < 0)
4350 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004351 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004352
4353 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4354 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4355 if (err < 0)
4356 return err;
4357 }
4358
Takashi Iwaif2e57312010-09-15 10:07:08 +02004359 return 0;
4360}
4361
4362static int cx_auto_build_controls(struct hda_codec *codec)
4363{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004364 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004365 int err;
4366
4367 err = cx_auto_build_output_controls(codec);
4368 if (err < 0)
4369 return err;
4370 err = cx_auto_build_input_controls(codec);
4371 if (err < 0)
4372 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004373 err = conexant_build_controls(codec);
4374 if (err < 0)
4375 return err;
4376 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4377 if (err < 0)
4378 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004379 if (spec->vmaster_mute.sw_kctl) {
4380 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4381 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4382 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004383 if (err < 0)
4384 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004385 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004386 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004387}
4388
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004389static int cx_auto_search_adcs(struct hda_codec *codec)
4390{
4391 struct conexant_spec *spec = codec->spec;
4392 hda_nid_t nid, end_nid;
4393
4394 end_nid = codec->start_nid + codec->num_nodes;
4395 for (nid = codec->start_nid; nid < end_nid; nid++) {
4396 unsigned int caps = get_wcaps(codec, nid);
4397 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4398 continue;
4399 if (caps & AC_WCAP_DIGITAL)
4400 continue;
4401 if (snd_BUG_ON(spec->num_adc_nids >=
4402 ARRAY_SIZE(spec->private_adc_nids)))
4403 break;
4404 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4405 }
4406 spec->adc_nids = spec->private_adc_nids;
4407 return 0;
4408}
4409
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004410static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004411 .build_controls = cx_auto_build_controls,
4412 .build_pcms = conexant_build_pcms,
4413 .init = cx_auto_init,
4414 .free = conexant_free,
4415 .unsol_event = cx_auto_unsol_event,
4416#ifdef CONFIG_SND_HDA_POWER_SAVE
4417 .suspend = conexant_suspend,
4418#endif
4419 .reboot_notify = snd_hda_shutup_pins,
4420};
4421
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004422/*
4423 * pin fix-up
4424 */
4425struct cxt_pincfg {
4426 hda_nid_t nid;
4427 u32 val;
4428};
4429
4430static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4431{
4432 for (; cfg->nid; cfg++)
4433 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4434
4435}
4436
David Henningsson18dcd302012-04-02 15:40:27 +02004437enum {
4438 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02004439 CXT_PINCFG_LENOVO_TP410,
David Henningsson18dcd302012-04-02 15:40:27 +02004440 CXT_FIXUP_STEREO_DMIC,
4441};
4442
4443static void apply_fixup(struct hda_codec *codec,
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004444 const struct snd_pci_quirk *quirk,
4445 const struct cxt_pincfg **table)
4446{
David Henningsson18dcd302012-04-02 15:40:27 +02004447 struct conexant_spec *spec = codec->spec;
4448
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004449 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
David Henningsson83b0c6b2012-04-10 13:05:29 +02004450 if (!quirk)
4451 return;
4452 if (table[quirk->value]) {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004453 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4454 quirk->name);
4455 apply_pincfg(codec, table[quirk->value]);
4456 }
David Henningsson18dcd302012-04-02 15:40:27 +02004457 if (quirk->value == CXT_FIXUP_STEREO_DMIC) {
4458 snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n",
4459 quirk->name);
4460 spec->fixup_stereo_dmic = 1;
4461 }
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004462}
4463
Takashi Iwaid70f3632012-04-19 15:18:08 +02004464/* ThinkPad X200 & co with cxt5051 */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004465static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4466 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4467 { 0x17, 0x21a11000 }, /* dock-mic */
4468 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004469 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004470 {}
4471};
4472
Takashi Iwaid70f3632012-04-19 15:18:08 +02004473/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4474static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = {
4475 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4476 { 0x1a, 0x21a190f0 }, /* dock-mic */
4477 { 0x1c, 0x212140ff }, /* dock-HP */
4478 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004479};
4480
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004481static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4482 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
Takashi Iwaid70f3632012-04-19 15:18:08 +02004483 [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410,
David Henningsson18dcd302012-04-02 15:40:27 +02004484 [CXT_FIXUP_STEREO_DMIC] = NULL,
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004485};
4486
Takashi Iwaid70f3632012-04-19 15:18:08 +02004487static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004488 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4489 {}
4490};
4491
Takashi Iwaid70f3632012-04-19 15:18:08 +02004492static const struct snd_pci_quirk cxt5066_fixups[] = {
4493 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4494 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4495 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4496 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4497 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02004498 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaif2e57312010-09-15 10:07:08 +02004499 {}
4500};
4501
Takashi Iwai38681372012-02-27 15:00:58 +01004502/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4503 * can be created (bko#42825)
4504 */
4505static void add_cx5051_fake_mutes(struct hda_codec *codec)
4506{
4507 static hda_nid_t out_nids[] = {
4508 0x10, 0x11, 0
4509 };
4510 hda_nid_t *p;
4511
4512 for (p = out_nids; *p; p++)
4513 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4514 AC_AMPCAP_MIN_MUTE |
4515 query_amp_caps(codec, *p, HDA_OUTPUT));
4516}
4517
Takashi Iwaif2e57312010-09-15 10:07:08 +02004518static int patch_conexant_auto(struct hda_codec *codec)
4519{
4520 struct conexant_spec *spec;
4521 int err;
4522
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004523 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4524 codec->chip_name);
4525
Takashi Iwaif2e57312010-09-15 10:07:08 +02004526 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4527 if (!spec)
4528 return -ENOMEM;
4529 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004530
Takashi Iwai6b452142011-10-14 15:26:20 +02004531 switch (codec->vendor_id) {
4532 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004533 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004534 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004535 case 0x14f15051:
4536 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02004537 codec->pin_amp_workaround = 1;
Takashi Iwaid3980112012-04-19 17:17:59 +02004538 apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl);
Takashi Iwai38681372012-02-27 15:00:58 +01004539 break;
Michael Karcher51969d62012-04-06 15:34:19 +02004540 default:
4541 codec->pin_amp_workaround = 1;
Takashi Iwaid3980112012-04-19 17:17:59 +02004542 apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl);
Takashi Iwai6b452142011-10-14 15:26:20 +02004543 }
4544
Takashi Iwaif29735c2012-03-13 07:55:10 +01004545 /* Show mute-led control only on HP laptops
4546 * This is a sort of white-list: on HP laptops, EAPD corresponds
4547 * only to the mute-LED without actualy amp function. Meanwhile,
4548 * others may use EAPD really as an amp switch, so it might be
4549 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004550 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004551 switch (codec->subsystem_id >> 16) {
4552 case 0x103c:
4553 spec->vmaster_mute_led = 1;
4554 break;
4555 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004556
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004557 err = cx_auto_search_adcs(codec);
4558 if (err < 0)
4559 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004560 err = cx_auto_parse_auto_config(codec);
4561 if (err < 0) {
4562 kfree(codec->spec);
4563 codec->spec = NULL;
4564 return err;
4565 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004566 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004567 codec->patch_ops = cx_auto_patch_ops;
4568 if (spec->beep_amp)
4569 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004570
4571 /* Some laptops with Conexant chips show stalls in S3 resume,
4572 * which falls into the single-cmd mode.
4573 * Better to make reset, then.
4574 */
4575 if (!codec->bus->sync_write) {
4576 snd_printd("hda_codec: "
4577 "Enable sync_write for stable communication\n");
4578 codec->bus->sync_write = 1;
4579 codec->bus->allow_bus_reset = 1;
4580 }
4581
Takashi Iwaif2e57312010-09-15 10:07:08 +02004582 return 0;
4583}
4584
4585/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004586 */
4587
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004588static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004589 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4590 .patch = patch_cxt5045 },
4591 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4592 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004593 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4594 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004595 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4596 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004597 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4598 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004599 { .id = 0x14f15068, .name = "CX20584",
4600 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004601 { .id = 0x14f15069, .name = "CX20585",
4602 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004603 { .id = 0x14f1506c, .name = "CX20588",
4604 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004605 { .id = 0x14f1506e, .name = "CX20590",
4606 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004607 { .id = 0x14f15097, .name = "CX20631",
4608 .patch = patch_conexant_auto },
4609 { .id = 0x14f15098, .name = "CX20632",
4610 .patch = patch_conexant_auto },
4611 { .id = 0x14f150a1, .name = "CX20641",
4612 .patch = patch_conexant_auto },
4613 { .id = 0x14f150a2, .name = "CX20642",
4614 .patch = patch_conexant_auto },
4615 { .id = 0x14f150ab, .name = "CX20651",
4616 .patch = patch_conexant_auto },
4617 { .id = 0x14f150ac, .name = "CX20652",
4618 .patch = patch_conexant_auto },
4619 { .id = 0x14f150b8, .name = "CX20664",
4620 .patch = patch_conexant_auto },
4621 { .id = 0x14f150b9, .name = "CX20665",
4622 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004623 {} /* terminator */
4624};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004625
4626MODULE_ALIAS("snd-hda-codec-id:14f15045");
4627MODULE_ALIAS("snd-hda-codec-id:14f15047");
4628MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004629MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004630MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004631MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004632MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004633MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004634MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004635MODULE_ALIAS("snd-hda-codec-id:14f15097");
4636MODULE_ALIAS("snd-hda-codec-id:14f15098");
4637MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4638MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4639MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4640MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4641MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4642MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004643
4644MODULE_LICENSE("GPL");
4645MODULE_DESCRIPTION("Conexant HD-audio codec");
4646
4647static struct hda_codec_preset_list conexant_list = {
4648 .preset = snd_hda_preset_conexant,
4649 .owner = THIS_MODULE,
4650};
4651
4652static int __init patch_conexant_init(void)
4653{
4654 return snd_hda_add_codec_preset(&conexant_list);
4655}
4656
4657static void __exit patch_conexant_exit(void)
4658{
4659 snd_hda_delete_codec_preset(&conexant_list);
4660}
4661
4662module_init(patch_conexant_init)
4663module_exit(patch_conexant_exit)