blob: afa510f0b99367fe337e5bf0ada528b2a8ebe322 [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;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001605 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001606 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001607 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001608 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001609 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001610 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001611 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001612}
1613
1614/* turn on/off EAPD (+ mute HP) as a master switch */
1615static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1616 struct snd_ctl_elem_value *ucontrol)
1617{
1618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1619
1620 if (!cxt_eapd_put(kcontrol, ucontrol))
1621 return 0;
1622 cxt5051_update_speaker(codec);
1623 return 1;
1624}
1625
1626/* toggle input of built-in and mic jack appropriately */
1627static void cxt5051_portb_automic(struct hda_codec *codec)
1628{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001629 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001630 unsigned int present;
1631
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001632 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001633 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001634 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001635 snd_hda_codec_write(codec, 0x14, 0,
1636 AC_VERB_SET_CONNECT_SEL,
1637 present ? 0x01 : 0x00);
1638}
1639
1640/* switch the current ADC according to the jack state */
1641static void cxt5051_portc_automic(struct hda_codec *codec)
1642{
1643 struct conexant_spec *spec = codec->spec;
1644 unsigned int present;
1645 hda_nid_t new_adc;
1646
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001647 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001648 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001649 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001650 if (present)
1651 spec->cur_adc_idx = 1;
1652 else
1653 spec->cur_adc_idx = 0;
1654 new_adc = spec->adc_nids[spec->cur_adc_idx];
1655 if (spec->cur_adc && spec->cur_adc != new_adc) {
1656 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001657 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001658 spec->cur_adc = new_adc;
1659 snd_hda_codec_setup_stream(codec, new_adc,
1660 spec->cur_adc_stream_tag, 0,
1661 spec->cur_adc_format);
1662 }
1663}
1664
1665/* mute internal speaker if HP is plugged */
1666static void cxt5051_hp_automute(struct hda_codec *codec)
1667{
1668 struct conexant_spec *spec = codec->spec;
1669
Takashi Iwaid56757a2009-11-18 08:00:14 +01001670 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001671 cxt5051_update_speaker(codec);
1672}
1673
1674/* unsolicited event for HP jack sensing */
1675static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1676 unsigned int res)
1677{
1678 switch (res >> 26) {
1679 case CONEXANT_HP_EVENT:
1680 cxt5051_hp_automute(codec);
1681 break;
1682 case CXT5051_PORTB_EVENT:
1683 cxt5051_portb_automic(codec);
1684 break;
1685 case CXT5051_PORTC_EVENT:
1686 cxt5051_portc_automic(codec);
1687 break;
1688 }
1689}
1690
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001691static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001692 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1693 {
1694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1695 .name = "Master Playback Switch",
1696 .info = cxt_eapd_info,
1697 .get = cxt_eapd_get,
1698 .put = cxt5051_hp_master_sw_put,
1699 .private_value = 0x1a,
1700 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001701 {}
1702};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001703
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001704static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001705 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1706 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001707 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1708 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001709 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1710 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001711 {}
1712};
1713
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001714static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1716 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001717 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1718 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 {}
1720};
1721
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001722static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001723 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1724 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001725 {}
1726};
1727
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001728static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001729 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1730 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001731 {}
1732};
1733
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001734static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001735 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001737 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1738 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001739 {}
1740};
1741
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001742static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001743 /* Line in, Mic */
1744 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1745 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1746 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1747 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1748 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1749 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1750 /* SPK */
1751 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1752 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1753 /* HP, Amp */
1754 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1755 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1756 /* DAC1 */
1757 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001758 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001759 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1761 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1762 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001763 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001764 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1765 /* EAPD */
1766 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1767 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001768 { } /* end */
1769};
1770
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001771static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001772 /* Line in, Mic */
1773 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1776 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1777 /* SPK */
1778 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1779 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1780 /* HP, Amp */
1781 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1782 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1783 /* DAC1 */
1784 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001785 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1787 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1788 /* SPDIF route: PCM */
1789 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1790 /* EAPD */
1791 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1792 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001793 { } /* end */
1794};
1795
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001796static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001797 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001798 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001799 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1800 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1801 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1802 /* SPK */
1803 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1804 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1805 /* HP, Amp */
1806 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1807 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1808 /* DAC1 */
1809 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001810 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1812 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1813 /* SPDIF route: PCM */
1814 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1815 /* EAPD */
1816 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1817 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001818 { } /* end */
1819};
1820
Takashi Iwai6953e552010-01-24 11:00:27 +01001821static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1822 unsigned int event)
1823{
1824 snd_hda_codec_write(codec, nid, 0,
1825 AC_VERB_SET_UNSOLICITED_ENABLE,
1826 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001827}
1828
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001829static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001830 /* Subwoofer */
1831 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1832 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1833 { } /* end */
1834};
1835
Takashi Iwai461e2c72008-01-25 11:35:17 +01001836/* initialize jack-sensing, too */
1837static int cxt5051_init(struct hda_codec *codec)
1838{
Takashi Iwai6953e552010-01-24 11:00:27 +01001839 struct conexant_spec *spec = codec->spec;
1840
Takashi Iwai461e2c72008-01-25 11:35:17 +01001841 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001842
1843 if (spec->auto_mic & AUTO_MIC_PORTB)
1844 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1845 if (spec->auto_mic & AUTO_MIC_PORTC)
1846 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1847
Takashi Iwai461e2c72008-01-25 11:35:17 +01001848 if (codec->patch_ops.unsol_event) {
1849 cxt5051_hp_automute(codec);
1850 cxt5051_portb_automic(codec);
1851 cxt5051_portc_automic(codec);
1852 }
1853 return 0;
1854}
1855
1856
1857enum {
1858 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1859 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001860 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001861 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001862 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001863 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001864 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001865 CXT5051_MODELS
1866};
1867
Takashi Iwaiea734962011-01-17 11:29:34 +01001868static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001869 [CXT5051_LAPTOP] = "laptop",
1870 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001871 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001872 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001873 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001874 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001875 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001876};
1877
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001878static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001879 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001880 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001881 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001882 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001883 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1884 CXT5051_LAPTOP),
1885 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001886 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001887 {}
1888};
1889
1890static int patch_cxt5051(struct hda_codec *codec)
1891{
1892 struct conexant_spec *spec;
1893 int board_config;
1894
Takashi Iwai6764bce2011-05-13 16:52:25 +02001895 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1896 cxt5051_models,
1897 cxt5051_cfg_tbl);
1898 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001899 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001900 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001901 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001902
Takashi Iwai461e2c72008-01-25 11:35:17 +01001903 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1904 if (!spec)
1905 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001906 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001907 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001908
1909 codec->patch_ops = conexant_patch_ops;
1910 codec->patch_ops.init = cxt5051_init;
1911
1912 spec->multiout.max_channels = 2;
1913 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1914 spec->multiout.dac_nids = cxt5051_dac_nids;
1915 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1916 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1917 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001918 spec->num_mixers = 2;
1919 spec->mixers[0] = cxt5051_capture_mixers;
1920 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001921 spec->num_init_verbs = 1;
1922 spec->init_verbs[0] = cxt5051_init_verbs;
1923 spec->spdif_route = 0;
1924 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1925 spec->channel_mode = cxt5051_modes;
1926 spec->cur_adc = 0;
1927 spec->cur_adc_idx = 0;
1928
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001929 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1930
Takashi Iwai79d7d532009-03-04 09:03:50 +01001931 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1932
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001933 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001934 switch (board_config) {
1935 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001936 spec->mixers[0] = cxt5051_hp_mixers;
1937 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001938 case CXT5051_HP_DV6736:
1939 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1940 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001941 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001942 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001943 case CXT5051_F700:
1944 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1945 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001946 spec->auto_mic = 0;
1947 break;
1948 case CXT5051_TOSHIBA:
1949 spec->mixers[0] = cxt5051_toshiba_mixers;
1950 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001951 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001952 case CXT5051_IDEAPAD:
1953 spec->init_verbs[spec->num_init_verbs++] =
1954 cxt5051_ideapad_init_verbs;
1955 spec->ideapad = 1;
1956 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001957 }
1958
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001959 if (spec->beep_amp)
1960 snd_hda_attach_beep_device(codec, spec->beep_amp);
1961
Takashi Iwai461e2c72008-01-25 11:35:17 +01001962 return 0;
1963}
1964
Daniel Drake0fb67e92009-07-16 14:46:57 +01001965/* Conexant 5066 specific */
1966
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001967static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1968static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1969static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1970static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001971
Daniel Drakedbaccc02009-11-09 15:17:24 +00001972/* OLPC's microphone port is DC coupled for use with external sensors,
1973 * therefore we use a 50% mic bias in order to center the input signal with
1974 * the DC input range of the codec. */
1975#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1976
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001977static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001978 { 2, NULL },
1979};
1980
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001981#define HP_PRESENT_PORT_A (1 << 0)
1982#define HP_PRESENT_PORT_D (1 << 1)
1983#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1984#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1985
Daniel Drake0fb67e92009-07-16 14:46:57 +01001986static void cxt5066_update_speaker(struct hda_codec *codec)
1987{
1988 struct conexant_spec *spec = codec->spec;
1989 unsigned int pinctl;
1990
John Baboval3a253442010-12-02 11:21:31 -05001991 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1992 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001993
1994 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001995 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001996 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001997
1998 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001999 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2000 if (spec->dell_automute || spec->thinkpad) {
2001 /* Mute if Port A is connected */
2002 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002003 pinctl = 0;
2004 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002005 /* Thinkpad/Dell doesn't give pin-D status */
2006 if (!hp_port_d_present(spec))
2007 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002008 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002009 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002010
2011 /* CLASS_D AMP */
2012 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002013 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002014}
2015
2016/* turn on/off EAPD (+ mute HP) as a master switch */
2017static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2018 struct snd_ctl_elem_value *ucontrol)
2019{
2020 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2021
2022 if (!cxt_eapd_put(kcontrol, ucontrol))
2023 return 0;
2024
2025 cxt5066_update_speaker(codec);
2026 return 1;
2027}
2028
Daniel Drakec4cfe662010-01-07 13:47:04 +01002029static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2030 .num_items = 3,
2031 .items = {
2032 { "Off", PIN_IN },
2033 { "50%", PIN_VREF50 },
2034 { "80%", PIN_VREF80 },
2035 },
2036};
2037
2038static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2039{
2040 struct conexant_spec *spec = codec->spec;
2041 /* Even though port F is the DC input, the bias is controlled on port B.
2042 * we also leave that port as an active input (but unselected) in DC mode
2043 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002044 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002045 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2046}
2047
Daniel Drake75f89912010-01-07 13:46:25 +01002048/* OLPC defers mic widget control until when capture is started because the
2049 * microphone LED comes on as soon as these settings are put in place. if we
2050 * did this before recording, it would give the false indication that recording
2051 * is happening when it is not. */
2052static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002053{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002054 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002055 if (!spec->recording)
2056 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002057
Daniel Drakec4cfe662010-01-07 13:47:04 +01002058 if (spec->dc_enable) {
2059 /* in DC mode we ignore presence detection and just use the jack
2060 * through our special DC port */
2061 const struct hda_verb enable_dc_mode[] = {
2062 /* disble internal mic, port C */
2063 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2064
2065 /* enable DC capture, port F */
2066 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2067 {},
2068 };
2069
2070 snd_hda_sequence_write(codec, enable_dc_mode);
2071 /* port B input disabled (and bias set) through the following call */
2072 cxt5066_set_olpc_dc_bias(codec);
2073 return;
2074 }
2075
2076 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002077 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002078
Daniel Drake75f89912010-01-07 13:46:25 +01002079 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002080 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002081 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002082
Daniel Drake75f89912010-01-07 13:46:25 +01002083 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002084 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002085 spec->ext_mic_present ? 0 : PIN_VREF80);
2086}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002087
Daniel Drake75f89912010-01-07 13:46:25 +01002088/* toggle input of built-in and mic jack appropriately */
2089static void cxt5066_olpc_automic(struct hda_codec *codec)
2090{
2091 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002092 unsigned int present;
2093
Daniel Drakec4cfe662010-01-07 13:47:04 +01002094 if (spec->dc_enable) /* don't do presence detection in DC mode */
2095 return;
2096
Daniel Drake75f89912010-01-07 13:46:25 +01002097 present = snd_hda_codec_read(codec, 0x1a, 0,
2098 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2099 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002100 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002101 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002102 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002103
2104 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2105 present ? 0 : 1);
2106 spec->ext_mic_present = !!present;
2107
2108 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002109}
2110
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002111/* toggle input of built-in digital mic and mic jack appropriately */
2112static void cxt5066_vostro_automic(struct hda_codec *codec)
2113{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002114 unsigned int present;
2115
2116 struct hda_verb ext_mic_present[] = {
2117 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002118 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002119
2120 /* switch to external mic input */
2121 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2122 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2123
2124 /* disable internal digital mic */
2125 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2126 {}
2127 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002128 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002129 /* enable internal mic, port C */
2130 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2131
2132 /* switch to internal mic input */
2133 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2134
2135 /* disable external mic, port B */
2136 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2137 {}
2138 };
2139
2140 present = snd_hda_jack_detect(codec, 0x1a);
2141 if (present) {
2142 snd_printdd("CXT5066: external microphone detected\n");
2143 snd_hda_sequence_write(codec, ext_mic_present);
2144 } else {
2145 snd_printdd("CXT5066: external microphone absent\n");
2146 snd_hda_sequence_write(codec, ext_mic_absent);
2147 }
2148}
2149
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002150/* toggle input of built-in digital mic and mic jack appropriately */
2151static void cxt5066_ideapad_automic(struct hda_codec *codec)
2152{
2153 unsigned int present;
2154
2155 struct hda_verb ext_mic_present[] = {
2156 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2157 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2158 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2159 {}
2160 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002161 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002162 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2163 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2164 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2165 {}
2166 };
2167
2168 present = snd_hda_jack_detect(codec, 0x1b);
2169 if (present) {
2170 snd_printdd("CXT5066: external microphone detected\n");
2171 snd_hda_sequence_write(codec, ext_mic_present);
2172 } else {
2173 snd_printdd("CXT5066: external microphone absent\n");
2174 snd_hda_sequence_write(codec, ext_mic_absent);
2175 }
2176}
2177
David Henningssona1d69062011-01-21 13:33:28 +01002178
2179/* toggle input of built-in digital mic and mic jack appropriately */
2180static void cxt5066_asus_automic(struct hda_codec *codec)
2181{
2182 unsigned int present;
2183
2184 present = snd_hda_jack_detect(codec, 0x1b);
2185 snd_printdd("CXT5066: external microphone present=%d\n", present);
2186 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2187 present ? 1 : 0);
2188}
2189
2190
David Henningsson048e78a2010-09-02 08:35:47 +02002191/* toggle input of built-in digital mic and mic jack appropriately */
2192static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2193{
2194 unsigned int present;
2195
2196 present = snd_hda_jack_detect(codec, 0x1b);
2197 snd_printdd("CXT5066: external microphone present=%d\n", present);
2198 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2199 present ? 1 : 3);
2200}
2201
2202
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002203/* toggle input of built-in digital mic and mic jack appropriately
2204 order is: external mic -> dock mic -> interal mic */
2205static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2206{
2207 unsigned int ext_present, dock_present;
2208
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002209 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002210 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2211 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2212 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2213 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2214 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2215 {}
2216 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002217 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002218 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2219 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2220 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2221 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2222 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223 {}
2224 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002225 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002226 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2227 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2228 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2229 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2230 {}
2231 };
2232
2233 ext_present = snd_hda_jack_detect(codec, 0x1b);
2234 dock_present = snd_hda_jack_detect(codec, 0x1a);
2235 if (ext_present) {
2236 snd_printdd("CXT5066: external microphone detected\n");
2237 snd_hda_sequence_write(codec, ext_mic_present);
2238 } else if (dock_present) {
2239 snd_printdd("CXT5066: dock microphone detected\n");
2240 snd_hda_sequence_write(codec, dock_mic_present);
2241 } else {
2242 snd_printdd("CXT5066: external microphone absent\n");
2243 snd_hda_sequence_write(codec, ext_mic_absent);
2244 }
2245}
2246
Daniel Drake0fb67e92009-07-16 14:46:57 +01002247/* mute internal speaker if HP is plugged */
2248static void cxt5066_hp_automute(struct hda_codec *codec)
2249{
2250 struct conexant_spec *spec = codec->spec;
2251 unsigned int portA, portD;
2252
2253 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002254 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002255
2256 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002257 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002258
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002259 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2260 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002261 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2262 portA, portD, spec->hp_present);
2263 cxt5066_update_speaker(codec);
2264}
2265
David Henningsson02b6b5b2011-01-21 13:27:39 +01002266/* Dispatch the right mic autoswitch function */
2267static void cxt5066_automic(struct hda_codec *codec)
2268{
2269 struct conexant_spec *spec = codec->spec;
2270
2271 if (spec->dell_vostro)
2272 cxt5066_vostro_automic(codec);
2273 else if (spec->ideapad)
2274 cxt5066_ideapad_automic(codec);
2275 else if (spec->thinkpad)
2276 cxt5066_thinkpad_automic(codec);
2277 else if (spec->hp_laptop)
2278 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002279 else if (spec->asus)
2280 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002281}
2282
Daniel Drake0fb67e92009-07-16 14:46:57 +01002283/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002284static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002285{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002286 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002287 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2288 switch (res >> 26) {
2289 case CONEXANT_HP_EVENT:
2290 cxt5066_hp_automute(codec);
2291 break;
2292 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002293 /* ignore mic events in DC mode; we're always using the jack */
2294 if (!spec->dc_enable)
2295 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002296 break;
2297 }
2298}
2299
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002300/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002301static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002302{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002303 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002304 switch (res >> 26) {
2305 case CONEXANT_HP_EVENT:
2306 cxt5066_hp_automute(codec);
2307 break;
2308 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002309 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002310 break;
2311 }
2312}
2313
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002314
Daniel Drake0fb67e92009-07-16 14:46:57 +01002315static const struct hda_input_mux cxt5066_analog_mic_boost = {
2316 .num_items = 5,
2317 .items = {
2318 { "0dB", 0 },
2319 { "10dB", 1 },
2320 { "20dB", 2 },
2321 { "30dB", 3 },
2322 { "40dB", 4 },
2323 },
2324};
2325
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002326static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002327{
2328 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002329 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002330 AC_VERB_SET_AMP_GAIN_MUTE,
2331 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2332 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002333 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002334 /* adjust the internal mic as well...it is not through 0x17 */
2335 snd_hda_codec_write_cache(codec, 0x23, 0,
2336 AC_VERB_SET_AMP_GAIN_MUTE,
2337 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2338 cxt5066_analog_mic_boost.
2339 items[spec->mic_boost].index);
2340 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002341}
2342
Daniel Drake0fb67e92009-07-16 14:46:57 +01002343static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2344 struct snd_ctl_elem_info *uinfo)
2345{
2346 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2347}
2348
2349static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2350 struct snd_ctl_elem_value *ucontrol)
2351{
2352 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002353 struct conexant_spec *spec = codec->spec;
2354 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002355 return 0;
2356}
2357
2358static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2359 struct snd_ctl_elem_value *ucontrol)
2360{
2361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002362 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002363 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2364 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002365 idx = ucontrol->value.enumerated.item[0];
2366 if (idx >= imux->num_items)
2367 idx = imux->num_items - 1;
2368
Daniel Drakec4cfe662010-01-07 13:47:04 +01002369 spec->mic_boost = idx;
2370 if (!spec->dc_enable)
2371 cxt5066_set_mic_boost(codec);
2372 return 1;
2373}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002374
Daniel Drakec4cfe662010-01-07 13:47:04 +01002375static void cxt5066_enable_dc(struct hda_codec *codec)
2376{
2377 const struct hda_verb enable_dc_mode[] = {
2378 /* disable gain */
2379 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2380
2381 /* switch to DC input */
2382 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2383 {}
2384 };
2385
2386 /* configure as input source */
2387 snd_hda_sequence_write(codec, enable_dc_mode);
2388 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2389}
2390
2391static void cxt5066_disable_dc(struct hda_codec *codec)
2392{
2393 /* reconfigure input source */
2394 cxt5066_set_mic_boost(codec);
2395 /* automic also selects the right mic if we're recording */
2396 cxt5066_olpc_automic(codec);
2397}
2398
2399static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2400 struct snd_ctl_elem_value *ucontrol)
2401{
2402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2403 struct conexant_spec *spec = codec->spec;
2404 ucontrol->value.integer.value[0] = spec->dc_enable;
2405 return 0;
2406}
2407
2408static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2409 struct snd_ctl_elem_value *ucontrol)
2410{
2411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2412 struct conexant_spec *spec = codec->spec;
2413 int dc_enable = !!ucontrol->value.integer.value[0];
2414
2415 if (dc_enable == spec->dc_enable)
2416 return 0;
2417
2418 spec->dc_enable = dc_enable;
2419 if (dc_enable)
2420 cxt5066_enable_dc(codec);
2421 else
2422 cxt5066_disable_dc(codec);
2423
2424 return 1;
2425}
2426
2427static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2428 struct snd_ctl_elem_info *uinfo)
2429{
2430 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2431}
2432
2433static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2434 struct snd_ctl_elem_value *ucontrol)
2435{
2436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2437 struct conexant_spec *spec = codec->spec;
2438 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2439 return 0;
2440}
2441
2442static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2444{
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2446 struct conexant_spec *spec = codec->spec;
2447 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2448 unsigned int idx;
2449
2450 idx = ucontrol->value.enumerated.item[0];
2451 if (idx >= imux->num_items)
2452 idx = imux->num_items - 1;
2453
2454 spec->dc_input_bias = idx;
2455 if (spec->dc_enable)
2456 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002457 return 1;
2458}
2459
Daniel Drake75f89912010-01-07 13:46:25 +01002460static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2461{
2462 struct conexant_spec *spec = codec->spec;
2463 /* mark as recording and configure the microphone widget so that the
2464 * recording LED comes on. */
2465 spec->recording = 1;
2466 cxt5066_olpc_select_mic(codec);
2467}
2468
2469static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2470{
2471 struct conexant_spec *spec = codec->spec;
2472 const struct hda_verb disable_mics[] = {
2473 /* disable external mic, port B */
2474 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2475
2476 /* disble internal mic, port C */
2477 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002478
2479 /* disable DC capture, port F */
2480 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002481 {},
2482 };
2483
2484 snd_hda_sequence_write(codec, disable_mics);
2485 spec->recording = 0;
2486}
2487
Andy Robinsonf6a24912011-01-24 10:12:37 -05002488static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002489 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002490 int num_pins)
2491{
2492 struct conexant_spec *spec = codec->spec;
2493 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2494 int i;
2495
2496 for (i = 0; i < num_pins; i++, dig_pins++) {
2497 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2498 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2499 continue;
2500 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2501 continue;
2502 if (spec->slave_dig_outs[0])
2503 nid_loc++;
2504 else
2505 nid_loc = spec->slave_dig_outs;
2506 }
2507}
2508
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002509static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002510 .num_items = 4,
2511 .items = {
2512 { "Mic B", 0 },
2513 { "Mic C", 1 },
2514 { "Mic E", 2 },
2515 { "Mic F", 3 },
2516 },
2517};
2518
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002519static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002520 .ops = &snd_hda_bind_vol,
2521 .values = {
2522 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2523 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2524 0
2525 },
2526};
2527
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002528static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002529 .ops = &snd_hda_bind_sw,
2530 .values = {
2531 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2532 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2533 0
2534 },
2535};
2536
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002537static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002538 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2539 {}
2540};
2541
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002542static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002543 {
2544 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2545 .name = "Master Playback Volume",
2546 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2547 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2548 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002549 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002550 .info = snd_hda_mixer_amp_volume_info,
2551 .get = snd_hda_mixer_amp_volume_get,
2552 .put = snd_hda_mixer_amp_volume_put,
2553 .tlv = { .c = snd_hda_mixer_amp_tlv },
2554 /* offset by 28 volume steps to limit minimum gain to -46dB */
2555 .private_value =
2556 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2557 },
2558 {}
2559};
2560
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002561static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002562 {
2563 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2564 .name = "DC Mode Enable Switch",
2565 .info = snd_ctl_boolean_mono_info,
2566 .get = cxt5066_olpc_dc_get,
2567 .put = cxt5066_olpc_dc_put,
2568 },
2569 {
2570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2571 .name = "DC Input Bias Enum",
2572 .info = cxt5066_olpc_dc_bias_enum_info,
2573 .get = cxt5066_olpc_dc_bias_enum_get,
2574 .put = cxt5066_olpc_dc_bias_enum_put,
2575 },
2576 {}
2577};
2578
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002579static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002580 {
2581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2582 .name = "Master Playback Switch",
2583 .info = cxt_eapd_info,
2584 .get = cxt_eapd_get,
2585 .put = cxt5066_hp_master_sw_put,
2586 .private_value = 0x1d,
2587 },
2588
2589 {
2590 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002591 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002592 .info = cxt5066_mic_boost_mux_enum_info,
2593 .get = cxt5066_mic_boost_mux_enum_get,
2594 .put = cxt5066_mic_boost_mux_enum_put,
2595 },
2596
2597 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2598 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2599 {}
2600};
2601
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002602static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002603 {
2604 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002605 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002606 .info = cxt5066_mic_boost_mux_enum_info,
2607 .get = cxt5066_mic_boost_mux_enum_get,
2608 .put = cxt5066_mic_boost_mux_enum_put,
2609 .private_value = 0x23 | 0x100,
2610 },
2611 {}
2612};
2613
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002614static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002615 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2616 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2617 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2618 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2619
2620 /* Speakers */
2621 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2622 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2623
2624 /* HP, Amp */
2625 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2626 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2627
2628 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2629 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2630
2631 /* DAC1 */
2632 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2633
2634 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2635 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2636 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2637 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2638 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2639 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2640
2641 /* no digital microphone support yet */
2642 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2643
2644 /* Audio input selector */
2645 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2646
2647 /* SPDIF route: PCM */
2648 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2649 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2650
2651 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2652 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2653
2654 /* EAPD */
2655 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2656
2657 /* not handling these yet */
2658 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2659 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2660 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2661 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2662 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2663 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2664 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2665 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2666 { } /* end */
2667};
2668
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002669static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002670 /* Port A: headphones */
2671 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2672 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2673
2674 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002675 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002676
2677 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002678 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002679
2680 /* Port D: unused */
2681 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2682
2683 /* Port E: unused, but has primary EAPD */
2684 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2685 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2686
Daniel Drakec4cfe662010-01-07 13:47:04 +01002687 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002688 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2689
2690 /* Port G: internal speakers */
2691 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2692 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2693
2694 /* DAC1 */
2695 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2696
2697 /* DAC2: unused */
2698 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2699
2700 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2701 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2702 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2703 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2704 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2705 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2706 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2707 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2708 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2709 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2710 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2711 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2712
2713 /* Disable digital microphone port */
2714 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2715
2716 /* Audio input selectors */
2717 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2718 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2719
2720 /* Disable SPDIF */
2721 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2722 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2723
2724 /* enable unsolicited events for Port A and B */
2725 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2726 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2727 { } /* end */
2728};
2729
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002730static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002731 /* Port A: headphones */
2732 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2733 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2734
2735 /* Port B: external microphone */
2736 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2737
2738 /* Port C: unused */
2739 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2740
2741 /* Port D: unused */
2742 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2743
2744 /* Port E: unused, but has primary EAPD */
2745 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2746 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2747
2748 /* Port F: unused */
2749 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2750
2751 /* Port G: internal speakers */
2752 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2753 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2754
2755 /* DAC1 */
2756 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2757
2758 /* DAC2: unused */
2759 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2760
2761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2762 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2763 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2764 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2765 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2766 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2767 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2768 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2769 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2770 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2771 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2772 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2773
2774 /* Digital microphone port */
2775 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2776
2777 /* Audio input selectors */
2778 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2779 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2780
2781 /* Disable SPDIF */
2782 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2783 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2784
2785 /* enable unsolicited events for Port A and B */
2786 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2787 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2788 { } /* end */
2789};
2790
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002791static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002792 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2793 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2794 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2795 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2796
2797 /* Speakers */
2798 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2799 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2800
2801 /* HP, Amp */
2802 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2803 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2804
2805 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2806 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2807
2808 /* DAC1 */
2809 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2810
2811 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2814 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2817 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2818
2819 /* Audio input selector */
2820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2821 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2822
2823 /* SPDIF route: PCM */
2824 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2825 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2826
2827 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2828 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2829
2830 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002831 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002832
2833 /* EAPD */
2834 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2835
2836 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2837 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2838 { } /* end */
2839};
2840
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002841static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002842 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2843 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2844
2845 /* Port G: internal speakers */
2846 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2847 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2848
2849 /* Port A: HP, Amp */
2850 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2851 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2852
2853 /* Port B: Mic Dock */
2854 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855
2856 /* Port C: Mic */
2857 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2858
2859 /* Port D: HP Dock, Amp */
2860 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2861 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2862
2863 /* DAC1 */
2864 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2865
2866 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2870 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2871 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2872 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2873
2874 /* Audio input selector */
2875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2876 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2877
2878 /* SPDIF route: PCM */
2879 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2880 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2881
2882 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2883 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2884
2885 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002886 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002887
2888 /* EAPD */
2889 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2890
2891 /* enable unsolicited events for Port A, B, C and D */
2892 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2893 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2894 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2895 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2896 { } /* end */
2897};
2898
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002899static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002900 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2901 { } /* end */
2902};
2903
David Henningsson048e78a2010-09-02 08:35:47 +02002904
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002905static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002906 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2907 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2908 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2909 { } /* end */
2910};
2911
Daniel Drake0fb67e92009-07-16 14:46:57 +01002912/* initialize jack-sensing, too */
2913static int cxt5066_init(struct hda_codec *codec)
2914{
2915 snd_printdd("CXT5066: init\n");
2916 conexant_init(codec);
2917 if (codec->patch_ops.unsol_event) {
2918 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002919 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002920 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002921 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002922 return 0;
2923}
2924
Daniel Drake75f89912010-01-07 13:46:25 +01002925static int cxt5066_olpc_init(struct hda_codec *codec)
2926{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002927 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002928 snd_printdd("CXT5066: init\n");
2929 conexant_init(codec);
2930 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002931 if (!spec->dc_enable) {
2932 cxt5066_set_mic_boost(codec);
2933 cxt5066_olpc_automic(codec);
2934 } else {
2935 cxt5066_enable_dc(codec);
2936 }
Daniel Drake75f89912010-01-07 13:46:25 +01002937 return 0;
2938}
2939
Daniel Drake0fb67e92009-07-16 14:46:57 +01002940enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002941 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002942 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2943 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002944 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002945 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002946 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002947 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002948 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002949 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002950 CXT5066_MODELS
2951};
2952
Takashi Iwaiea734962011-01-17 11:29:34 +01002953static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002954 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002955 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2956 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002957 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002958 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002959 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002960 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002961 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002962 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002963};
2964
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002965static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02002966 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002967 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002968 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002969 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002970 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02002971 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002972 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002973 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2974 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002975 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002976 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002977 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002978 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002979 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002980 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002981 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2982 CXT5066_LAPTOP),
2983 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002984 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002985 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002986 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson29c5fbb2012-01-23 16:39:55 +01002987 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO),
Daniel Suchyca201c02011-10-18 11:09:44 +02002988 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02002989 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002990 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002991 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002992 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02002993 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04002994 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002995 {}
2996};
2997
2998static int patch_cxt5066(struct hda_codec *codec)
2999{
3000 struct conexant_spec *spec;
3001 int board_config;
3002
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003003 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3004 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003005 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003006 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003007 if (board_config == CXT5066_AUTO)
3008 return patch_conexant_auto(codec);
3009
Daniel Drake0fb67e92009-07-16 14:46:57 +01003010 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3011 if (!spec)
3012 return -ENOMEM;
3013 codec->spec = spec;
3014
3015 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003016 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003017
3018 spec->dell_automute = 0;
3019 spec->multiout.max_channels = 2;
3020 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3021 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003022 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3023 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003024 spec->num_adc_nids = 1;
3025 spec->adc_nids = cxt5066_adc_nids;
3026 spec->capsrc_nids = cxt5066_capsrc_nids;
3027 spec->input_mux = &cxt5066_capture_source;
3028
3029 spec->port_d_mode = PIN_HP;
3030
3031 spec->num_init_verbs = 1;
3032 spec->init_verbs[0] = cxt5066_init_verbs;
3033 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3034 spec->channel_mode = cxt5066_modes;
3035 spec->cur_adc = 0;
3036 spec->cur_adc_idx = 0;
3037
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003038 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3039
Daniel Drake0fb67e92009-07-16 14:46:57 +01003040 switch (board_config) {
3041 default:
3042 case CXT5066_LAPTOP:
3043 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3044 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3045 break;
3046 case CXT5066_DELL_LAPTOP:
3047 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3048 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3049
3050 spec->port_d_mode = PIN_OUT;
3051 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3052 spec->num_init_verbs++;
3053 spec->dell_automute = 1;
3054 break;
David Henningssona1d69062011-01-21 13:33:28 +01003055 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003056 case CXT5066_HP_LAPTOP:
3057 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003058 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003059 spec->init_verbs[spec->num_init_verbs] =
3060 cxt5066_init_verbs_hp_laptop;
3061 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003062 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3063 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003064 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3065 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3066 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003067 if (board_config == CXT5066_HP_LAPTOP)
3068 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003069 /* input source automatically selected */
3070 spec->input_mux = NULL;
3071 spec->port_d_mode = 0;
3072 spec->mic_boost = 3; /* default 30dB gain */
3073 break;
3074
Daniel Drake0fb67e92009-07-16 14:46:57 +01003075 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003076 codec->patch_ops.init = cxt5066_olpc_init;
3077 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003078 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3079 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003080 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003081 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3082 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003083 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003084
3085 /* no S/PDIF out */
3086 spec->multiout.dig_out_nid = 0;
3087
3088 /* input source automatically selected */
3089 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003090
3091 /* our capture hooks which allow us to turn on the microphone LED
3092 * at the right time */
3093 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3094 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003095 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003096 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003097 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003098 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003099 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3100 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3101 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003102 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003103 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003104 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003105 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003106
3107 /* no S/PDIF out */
3108 spec->multiout.dig_out_nid = 0;
3109
3110 /* input source automatically selected */
3111 spec->input_mux = NULL;
3112 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003113 case CXT5066_IDEAPAD:
3114 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003115 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003116 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3117 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3118 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3119 spec->port_d_mode = 0;
3120 spec->ideapad = 1;
3121 spec->mic_boost = 2; /* default 20dB gain */
3122
3123 /* no S/PDIF out */
3124 spec->multiout.dig_out_nid = 0;
3125
3126 /* input source automatically selected */
3127 spec->input_mux = NULL;
3128 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003129 case CXT5066_THINKPAD:
3130 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003131 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003132 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3133 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3134 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3135 spec->thinkpad = 1;
3136 spec->port_d_mode = PIN_OUT;
3137 spec->mic_boost = 2; /* default 20dB gain */
3138
3139 /* no S/PDIF out */
3140 spec->multiout.dig_out_nid = 0;
3141
3142 /* input source automatically selected */
3143 spec->input_mux = NULL;
3144 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003145 }
3146
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003147 if (spec->beep_amp)
3148 snd_hda_attach_beep_device(codec, spec->beep_amp);
3149
Daniel Drake0fb67e92009-07-16 14:46:57 +01003150 return 0;
3151}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003152
3153/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003154 * Automatic parser for CX20641 & co
3155 */
3156
Takashi Iwai6764bce2011-05-13 16:52:25 +02003157static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3158 struct hda_codec *codec,
3159 unsigned int stream_tag,
3160 unsigned int format,
3161 struct snd_pcm_substream *substream)
3162{
3163 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003164 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003165 if (spec->adc_switching) {
3166 spec->cur_adc = adc;
3167 spec->cur_adc_stream_tag = stream_tag;
3168 spec->cur_adc_format = format;
3169 }
3170 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3171 return 0;
3172}
3173
3174static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3175 struct hda_codec *codec,
3176 struct snd_pcm_substream *substream)
3177{
3178 struct conexant_spec *spec = codec->spec;
3179 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3180 spec->cur_adc = 0;
3181 return 0;
3182}
3183
3184static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3185 .substreams = 1,
3186 .channels_min = 2,
3187 .channels_max = 2,
3188 .nid = 0, /* fill later */
3189 .ops = {
3190 .prepare = cx_auto_capture_pcm_prepare,
3191 .cleanup = cx_auto_capture_pcm_cleanup
3192 },
3193};
3194
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003195static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003196
Takashi Iwai8d087c72011-06-28 12:45:47 +02003197#define get_connection_index(codec, mux, nid)\
3198 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003199
3200/* get an unassigned DAC from the given list.
3201 * Return the nid if found and reduce the DAC list, or return zero if
3202 * not found
3203 */
3204static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3205 hda_nid_t *dacs, int *num_dacs)
3206{
3207 int i, nums = *num_dacs;
3208 hda_nid_t ret = 0;
3209
3210 for (i = 0; i < nums; i++) {
3211 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3212 ret = dacs[i];
3213 break;
3214 }
3215 }
3216 if (!ret)
3217 return 0;
3218 if (--nums > 0)
3219 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3220 *num_dacs = nums;
3221 return ret;
3222}
3223
3224#define MAX_AUTO_DACS 5
3225
Takashi Iwai1f015f52011-08-23 14:57:08 +02003226#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3227
Takashi Iwaif2e57312010-09-15 10:07:08 +02003228/* fill analog DAC list from the widget tree */
3229static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3230{
3231 hda_nid_t nid, end_nid;
3232 int nums = 0;
3233
3234 end_nid = codec->start_nid + codec->num_nodes;
3235 for (nid = codec->start_nid; nid < end_nid; nid++) {
3236 unsigned int wcaps = get_wcaps(codec, nid);
3237 unsigned int type = get_wcaps_type(wcaps);
3238 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3239 dacs[nums++] = nid;
3240 if (nums >= MAX_AUTO_DACS)
3241 break;
3242 }
3243 }
3244 return nums;
3245}
3246
3247/* fill pin_dac_pair list from the pin and dac list */
3248static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3249 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003250 struct pin_dac_pair *filled, int nums,
3251 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003252{
David Henningsson468c5452011-08-25 13:16:02 +02003253 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003254
David Henningsson468c5452011-08-25 13:16:02 +02003255 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003256 filled[nums].pin = pins[i];
3257 filled[nums].type = type;
3258 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003259 if (filled[nums].dac)
3260 continue;
3261 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3262 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3263 continue;
3264 }
3265 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003266 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003267 continue;
3268 }
3269 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003270 }
3271 return nums;
3272}
3273
3274/* parse analog output paths */
3275static void cx_auto_parse_output(struct hda_codec *codec)
3276{
3277 struct conexant_spec *spec = codec->spec;
3278 struct auto_pin_cfg *cfg = &spec->autocfg;
3279 hda_nid_t dacs[MAX_AUTO_DACS];
3280 int i, j, nums, rest;
3281
3282 rest = fill_cx_auto_dacs(codec, dacs);
3283 /* parse all analog output pins */
3284 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003285 dacs, &rest, spec->dac_info, 0,
3286 AUTO_PIN_LINE_OUT);
3287 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3288 dacs, &rest, spec->dac_info, nums,
3289 AUTO_PIN_HP_OUT);
3290 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3291 dacs, &rest, spec->dac_info, nums,
3292 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003293 spec->dac_info_filled = nums;
3294 /* fill multiout struct */
3295 for (i = 0; i < nums; i++) {
3296 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003297 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003298 continue;
3299 switch (spec->dac_info[i].type) {
3300 case AUTO_PIN_LINE_OUT:
3301 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3302 spec->multiout.num_dacs++;
3303 break;
3304 case AUTO_PIN_HP_OUT:
3305 case AUTO_PIN_SPEAKER_OUT:
3306 if (!spec->multiout.hp_nid) {
3307 spec->multiout.hp_nid = dac;
3308 break;
3309 }
3310 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3311 if (!spec->multiout.extra_out_nid[j]) {
3312 spec->multiout.extra_out_nid[j] = dac;
3313 break;
3314 }
3315 break;
3316 }
3317 }
3318 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003319 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003320
Takashi Iwai03697e22011-05-17 09:53:31 +02003321 for (i = 0; i < cfg->hp_outs; i++) {
3322 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3323 spec->auto_mute = 1;
3324 break;
3325 }
3326 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003327 if (spec->auto_mute &&
3328 cfg->line_out_pins[0] &&
3329 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003330 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3331 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3332 for (i = 0; i < cfg->line_outs; i++) {
3333 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3334 spec->detect_line = 1;
3335 break;
3336 }
3337 }
3338 spec->automute_lines = spec->detect_line;
3339 }
3340
Takashi Iwaif2e57312010-09-15 10:07:08 +02003341 spec->vmaster_nid = spec->private_dac_nids[0];
3342}
3343
Takashi Iwaida339862011-05-13 16:24:15 +02003344static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3345 hda_nid_t *pins, bool on);
3346
Takashi Iwai03697e22011-05-17 09:53:31 +02003347static void do_automute(struct hda_codec *codec, int num_pins,
3348 hda_nid_t *pins, bool on)
3349{
Takashi Iwai254f2962011-10-14 15:22:34 +02003350 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003351 int i;
3352 for (i = 0; i < num_pins; i++)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003353 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003354 if (spec->pin_eapd_ctrls)
3355 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003356}
3357
3358static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3359{
3360 int i, present = 0;
3361
3362 for (i = 0; i < num_pins; i++) {
3363 hda_nid_t nid = pins[i];
3364 if (!nid || !is_jack_detectable(codec, nid))
3365 break;
Takashi Iwai03697e22011-05-17 09:53:31 +02003366 present |= snd_hda_jack_detect(codec, nid);
3367 }
3368 return present;
3369}
3370
Takashi Iwaif2e57312010-09-15 10:07:08 +02003371/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003372static void cx_auto_update_speakers(struct hda_codec *codec)
3373{
3374 struct conexant_spec *spec = codec->spec;
3375 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003376 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003377
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003378 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003379 if (spec->pin_eapd_ctrls) {
3380 if (spec->auto_mute)
3381 on = spec->hp_present;
3382 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3383 }
3384
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003385 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3386 if (spec->auto_mute)
3387 on = !(spec->hp_present ||
3388 (spec->detect_line && spec->line_present));
3389 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003390
3391 /* toggle line-out mutes if needed, too */
3392 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3393 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3394 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3395 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003396 if (spec->auto_mute) {
3397 /* mute LO in auto-mode when HP jack is present */
3398 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3399 spec->automute_lines)
3400 on = !spec->hp_present;
3401 else
3402 on = 1;
3403 }
3404 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003405}
3406
Takashi Iwaif2e57312010-09-15 10:07:08 +02003407static void cx_auto_hp_automute(struct hda_codec *codec)
3408{
3409 struct conexant_spec *spec = codec->spec;
3410 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003411
3412 if (!spec->auto_mute)
3413 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003414 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3415 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003416}
3417
Takashi Iwai03697e22011-05-17 09:53:31 +02003418static void cx_auto_line_automute(struct hda_codec *codec)
3419{
3420 struct conexant_spec *spec = codec->spec;
3421 struct auto_pin_cfg *cfg = &spec->autocfg;
3422
3423 if (!spec->auto_mute || !spec->detect_line)
3424 return;
3425 spec->line_present = detect_jacks(codec, cfg->line_outs,
3426 cfg->line_out_pins);
3427 cx_auto_update_speakers(codec);
3428}
3429
3430static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3431 struct snd_ctl_elem_info *uinfo)
3432{
3433 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3434 struct conexant_spec *spec = codec->spec;
3435 static const char * const texts2[] = {
3436 "Disabled", "Enabled"
3437 };
3438 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +01003439 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai03697e22011-05-17 09:53:31 +02003440 };
3441 const char * const *texts;
3442
3443 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3444 uinfo->count = 1;
3445 if (spec->automute_hp_lo) {
3446 uinfo->value.enumerated.items = 3;
3447 texts = texts3;
3448 } else {
3449 uinfo->value.enumerated.items = 2;
3450 texts = texts2;
3451 }
3452 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3453 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3454 strcpy(uinfo->value.enumerated.name,
3455 texts[uinfo->value.enumerated.item]);
3456 return 0;
3457}
3458
3459static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3460 struct snd_ctl_elem_value *ucontrol)
3461{
3462 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3463 struct conexant_spec *spec = codec->spec;
3464 unsigned int val;
3465 if (!spec->auto_mute)
3466 val = 0;
3467 else if (!spec->automute_lines)
3468 val = 1;
3469 else
3470 val = 2;
3471 ucontrol->value.enumerated.item[0] = val;
3472 return 0;
3473}
3474
3475static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3476 struct snd_ctl_elem_value *ucontrol)
3477{
3478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3479 struct conexant_spec *spec = codec->spec;
3480
3481 switch (ucontrol->value.enumerated.item[0]) {
3482 case 0:
3483 if (!spec->auto_mute)
3484 return 0;
3485 spec->auto_mute = 0;
3486 break;
3487 case 1:
3488 if (spec->auto_mute && !spec->automute_lines)
3489 return 0;
3490 spec->auto_mute = 1;
3491 spec->automute_lines = 0;
3492 break;
3493 case 2:
3494 if (!spec->automute_hp_lo)
3495 return -EINVAL;
3496 if (spec->auto_mute && spec->automute_lines)
3497 return 0;
3498 spec->auto_mute = 1;
3499 spec->automute_lines = 1;
3500 break;
3501 default:
3502 return -EINVAL;
3503 }
3504 cx_auto_update_speakers(codec);
3505 return 1;
3506}
3507
3508static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3509 {
3510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3511 .name = "Auto-Mute Mode",
3512 .info = cx_automute_mode_info,
3513 .get = cx_automute_mode_get,
3514 .put = cx_automute_mode_put,
3515 },
3516 { }
3517};
3518
Takashi Iwai6764bce2011-05-13 16:52:25 +02003519static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3520 struct snd_ctl_elem_info *uinfo)
3521{
3522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3523 struct conexant_spec *spec = codec->spec;
3524
3525 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3526}
3527
3528static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3529 struct snd_ctl_elem_value *ucontrol)
3530{
3531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3532 struct conexant_spec *spec = codec->spec;
3533
3534 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3535 return 0;
3536}
3537
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003538/* look for the route the given pin from mux and return the index;
3539 * if do_select is set, actually select the route.
3540 */
3541static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003542 hda_nid_t pin, hda_nid_t *srcp,
3543 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003544{
3545 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3546 int i, nums;
3547
Takashi Iwaicf27f292011-05-16 11:33:02 +02003548 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3549 case AC_WID_AUD_IN:
3550 case AC_WID_AUD_SEL:
3551 case AC_WID_AUD_MIX:
3552 break;
3553 default:
3554 return -1;
3555 }
3556
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003557 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3558 for (i = 0; i < nums; i++)
3559 if (conn[i] == pin) {
3560 if (do_select)
3561 snd_hda_codec_write(codec, mux, 0,
3562 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003563 if (srcp)
3564 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003565 return i;
3566 }
3567 depth++;
3568 if (depth == 2)
3569 return -1;
3570 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003571 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003572 do_select, depth);
3573 if (ret >= 0) {
3574 if (do_select)
3575 snd_hda_codec_write(codec, mux, 0,
3576 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003577 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003578 }
3579 }
3580 return -1;
3581}
3582
3583static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3584 hda_nid_t pin)
3585{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003586 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003587}
3588
3589static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3590 hda_nid_t pin)
3591{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003592 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003593}
3594
Takashi Iwai6764bce2011-05-13 16:52:25 +02003595static int cx_auto_mux_enum_update(struct hda_codec *codec,
3596 const struct hda_input_mux *imux,
3597 unsigned int idx)
3598{
3599 struct conexant_spec *spec = codec->spec;
3600 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003601 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003602
3603 if (!imux->num_items)
3604 return 0;
3605 if (idx >= imux->num_items)
3606 idx = imux->num_items - 1;
3607 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003608 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003609 adc = spec->imux_info[idx].adc;
3610 select_input_connection(codec, spec->imux_info[idx].adc,
3611 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003612 if (spec->cur_adc && spec->cur_adc != adc) {
3613 /* stream is running, let's swap the current ADC */
3614 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3615 spec->cur_adc = adc;
3616 snd_hda_codec_setup_stream(codec, adc,
3617 spec->cur_adc_stream_tag, 0,
3618 spec->cur_adc_format);
3619 }
3620 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003621 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003622}
3623
3624static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3625 struct snd_ctl_elem_value *ucontrol)
3626{
3627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3628 struct conexant_spec *spec = codec->spec;
3629
3630 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3631 ucontrol->value.enumerated.item[0]);
3632}
3633
3634static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3635 {
3636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3637 .name = "Capture Source",
3638 .info = cx_auto_mux_enum_info,
3639 .get = cx_auto_mux_enum_get,
3640 .put = cx_auto_mux_enum_put
3641 },
3642 {}
3643};
3644
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003645static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3646{
3647 struct conexant_spec *spec = codec->spec;
3648 if (idx < 0)
3649 return false;
3650 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3651 return false;
3652 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3653 return true;
3654}
3655
Takashi Iwaif2e57312010-09-15 10:07:08 +02003656/* automatic switch internal and external mic */
3657static void cx_auto_automic(struct hda_codec *codec)
3658{
3659 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003660
3661 if (!spec->auto_mic)
3662 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003663 if (!select_automic(codec, spec->auto_mic_ext, true))
3664 if (!select_automic(codec, spec->auto_mic_dock, true))
3665 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003666}
3667
3668static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3669{
Takashi Iwai3a938972011-10-28 01:16:55 +02003670 switch (snd_hda_jack_get_action(codec, res >> 26)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003671 case CONEXANT_HP_EVENT:
3672 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003673 break;
3674 case CONEXANT_LINE_EVENT:
3675 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003676 break;
3677 case CONEXANT_MIC_EVENT:
3678 cx_auto_automic(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003679 break;
3680 }
Takashi Iwai01a61e12011-10-28 00:03:22 +02003681 snd_hda_jack_report_sync(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003682}
3683
Takashi Iwaif2e57312010-09-15 10:07:08 +02003684/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003685 * auto-mic is enabled only when one int-mic and one ext- and/or
3686 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003687 */
3688static void cx_auto_check_auto_mic(struct hda_codec *codec)
3689{
3690 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003691 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3692 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003693
Takashi Iwai506a4192011-05-23 20:07:15 +02003694 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003695 pset[i] = -1;
3696 for (i = 0; i < spec->private_imux.num_items; i++) {
3697 hda_nid_t pin = spec->imux_info[i].pin;
3698 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003699 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003700 attr = snd_hda_get_input_pin_attr(def_conf);
3701 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003702 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003703 if (attr > INPUT_PIN_ATTR_NORMAL)
3704 attr = INPUT_PIN_ATTR_NORMAL;
3705 if (attr != INPUT_PIN_ATTR_INT &&
3706 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003707 return; /* non-detectable pin */
3708 type = get_defcfg_device(def_conf);
3709 if (type != AC_JACK_MIC_IN &&
3710 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3711 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003712 if (pset[attr] >= 0)
3713 return; /* already occupied */
3714 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003715 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003716 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3717 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3718 return; /* no input to switch*/
3719 spec->auto_mic = 1;
3720 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3721 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3722 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003723}
3724
3725static void cx_auto_parse_input(struct hda_codec *codec)
3726{
3727 struct conexant_spec *spec = codec->spec;
3728 struct auto_pin_cfg *cfg = &spec->autocfg;
3729 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003730 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003731
3732 imux = &spec->private_imux;
3733 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003734 for (j = 0; j < spec->num_adc_nids; j++) {
3735 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003736 int idx = get_input_connection(codec, adc,
3737 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003738 if (idx >= 0) {
3739 const char *label;
3740 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003741 spec->imux_info[imux->num_items].index = i;
3742 spec->imux_info[imux->num_items].boost = 0;
3743 spec->imux_info[imux->num_items].adc = adc;
3744 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003745 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003746 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003747 break;
3748 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003749 }
3750 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003751 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003752 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003753 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003754 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003755 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003756 spec->adc_switching = 1;
3757 break;
3758 }
3759 }
3760 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003761}
3762
3763/* get digital-input audio widget corresponding to the given pin */
3764static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3765{
3766 hda_nid_t nid, end_nid;
3767
3768 end_nid = codec->start_nid + codec->num_nodes;
3769 for (nid = codec->start_nid; nid < end_nid; nid++) {
3770 unsigned int wcaps = get_wcaps(codec, nid);
3771 unsigned int type = get_wcaps_type(wcaps);
3772 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3773 if (get_connection_index(codec, nid, pin) >= 0)
3774 return nid;
3775 }
3776 }
3777 return 0;
3778}
3779
3780static void cx_auto_parse_digital(struct hda_codec *codec)
3781{
3782 struct conexant_spec *spec = codec->spec;
3783 struct auto_pin_cfg *cfg = &spec->autocfg;
3784 hda_nid_t nid;
3785
3786 if (cfg->dig_outs &&
3787 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3788 spec->multiout.dig_out_nid = nid;
3789 if (cfg->dig_in_pin)
3790 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3791}
3792
3793#ifdef CONFIG_SND_HDA_INPUT_BEEP
3794static void cx_auto_parse_beep(struct hda_codec *codec)
3795{
3796 struct conexant_spec *spec = codec->spec;
3797 hda_nid_t nid, end_nid;
3798
3799 end_nid = codec->start_nid + codec->num_nodes;
3800 for (nid = codec->start_nid; nid < end_nid; nid++)
3801 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3802 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3803 break;
3804 }
3805}
3806#else
3807#define cx_auto_parse_beep(codec)
3808#endif
3809
Takashi Iwai254f2962011-10-14 15:22:34 +02003810/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003811static void cx_auto_parse_eapd(struct hda_codec *codec)
3812{
3813 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003814 hda_nid_t nid, end_nid;
3815
3816 end_nid = codec->start_nid + codec->num_nodes;
3817 for (nid = codec->start_nid; nid < end_nid; nid++) {
3818 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3819 continue;
3820 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3821 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003822 spec->eapds[spec->num_eapds++] = nid;
3823 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3824 break;
3825 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003826
3827 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3828 * it's a new chip, where EAPDs are supposed to be associated to
3829 * pins, and we can control EAPD per pin.
3830 * OTOH, if only one or two EAPDs are found, it's an old chip,
3831 * thus it might control over all pins.
3832 */
3833 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003834}
3835
Takashi Iwaif2e57312010-09-15 10:07:08 +02003836static int cx_auto_parse_auto_config(struct hda_codec *codec)
3837{
3838 struct conexant_spec *spec = codec->spec;
3839 int err;
3840
3841 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3842 if (err < 0)
3843 return err;
3844
3845 cx_auto_parse_output(codec);
3846 cx_auto_parse_input(codec);
3847 cx_auto_parse_digital(codec);
3848 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003849 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003850 return 0;
3851}
3852
Takashi Iwaida339862011-05-13 16:24:15 +02003853static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3854 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003855{
3856 int i;
3857 for (i = 0; i < num_pins; i++) {
3858 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3859 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003860 AC_VERB_SET_EAPD_BTLENABLE,
3861 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003862 }
3863}
3864
3865static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3866 hda_nid_t src)
3867{
3868 int idx = get_connection_index(codec, pin, src);
3869 if (idx >= 0)
3870 snd_hda_codec_write(codec, pin, 0,
3871 AC_VERB_SET_CONNECT_SEL, idx);
3872}
3873
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003874static void mute_outputs(struct hda_codec *codec, int num_nids,
3875 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003876{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003877 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003878
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003879 for (i = 0; i < num_nids; i++) {
3880 hda_nid_t nid = nids[i];
3881 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3882 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003883 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3884 val = AMP_OUT_MUTE;
3885 else
3886 val = AMP_OUT_ZERO;
3887 snd_hda_codec_write(codec, nid, 0,
3888 AC_VERB_SET_AMP_GAIN_MUTE, val);
3889 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003890}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003891
Takashi Iwai03697e22011-05-17 09:53:31 +02003892static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
Takashi Iwai3a938972011-10-28 01:16:55 +02003893 hda_nid_t *pins, unsigned int action)
Takashi Iwai03697e22011-05-17 09:53:31 +02003894{
3895 int i;
3896 for (i = 0; i < num_pins; i++)
Takashi Iwai3a938972011-10-28 01:16:55 +02003897 snd_hda_jack_detect_enable(codec, pins[i], action);
Takashi Iwai03697e22011-05-17 09:53:31 +02003898}
3899
Takashi Iwai07cafff2012-02-20 12:30:59 +01003900static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3901{
3902 int i;
3903 for (i = 0; i < nums; i++)
3904 if (list[i] == nid)
3905 return true;
3906 return false;
3907}
3908
3909/* is the given NID found in any of autocfg items? */
3910static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3911{
3912 int i;
3913
3914 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3915 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3916 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3917 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3918 return true;
3919 for (i = 0; i < cfg->num_inputs; i++)
3920 if (cfg->inputs[i].pin == nid)
3921 return true;
3922 if (cfg->dig_in_pin == nid)
3923 return true;
3924 return false;
3925}
3926
3927/* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3928 * invalid unsol tags by some reason
3929 */
3930static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3931{
3932 struct conexant_spec *spec = codec->spec;
3933 struct auto_pin_cfg *cfg = &spec->autocfg;
3934 int i;
3935
3936 for (i = 0; i < codec->init_pins.used; i++) {
3937 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3938 if (!found_in_autocfg(cfg, pin->nid))
3939 snd_hda_codec_write(codec, pin->nid, 0,
3940 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3941 }
3942}
3943
Takashi Iwai527c73b2012-03-12 12:38:51 +01003944/* turn on/off EAPD according to Master switch */
3945static void cx_auto_vmaster_hook(void *private_data, int enabled)
3946{
3947 struct hda_codec *codec = private_data;
3948 struct conexant_spec *spec = codec->spec;
3949
3950 if (enabled && spec->pin_eapd_ctrls) {
3951 cx_auto_update_speakers(codec);
3952 return;
3953 }
3954 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3955}
3956
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003957static void cx_auto_init_output(struct hda_codec *codec)
3958{
3959 struct conexant_spec *spec = codec->spec;
3960 struct auto_pin_cfg *cfg = &spec->autocfg;
3961 hda_nid_t nid;
3962 int i;
3963
3964 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003965 for (i = 0; i < cfg->hp_outs; i++) {
3966 unsigned int val = PIN_OUT;
3967 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3968 AC_PINCAP_HP_DRV)
3969 val |= AC_PINCTL_HP_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003970 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
Takashi Iwaica3649d2012-04-19 15:15:25 +02003971 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003972 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3973 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3974 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003975 for (i = 0; i < spec->dac_info_filled; i++) {
3976 nid = spec->dac_info[i].dac;
3977 if (!nid)
3978 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02003979 else if (nid & DAC_SLAVE_FLAG)
3980 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003981 select_connection(codec, spec->dac_info[i].pin, nid);
3982 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003983 if (spec->auto_mute) {
3984 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3985 CONEXANT_HP_EVENT);
3986 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3987 cfg->hp_pins);
3988 if (spec->detect_line) {
3989 enable_unsol_pins(codec, cfg->line_outs,
3990 cfg->line_out_pins,
3991 CONEXANT_LINE_EVENT);
3992 spec->line_present =
3993 detect_jacks(codec, cfg->line_outs,
3994 cfg->line_out_pins);
3995 }
3996 }
3997 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02003998 /* turn on all EAPDs if no individual EAPD control is available */
3999 if (!spec->pin_eapd_ctrls)
4000 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwai07cafff2012-02-20 12:30:59 +01004001 clear_unsol_on_unused_pins(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004002}
4003
4004static void cx_auto_init_input(struct hda_codec *codec)
4005{
4006 struct conexant_spec *spec = codec->spec;
4007 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004008 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004009
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004010 for (i = 0; i < spec->num_adc_nids; i++) {
4011 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004012 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4013 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004014 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4015 val = AMP_IN_MUTE(0);
4016 else
4017 val = AMP_IN_UNMUTE(0);
4018 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4019 val);
4020 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004021
4022 for (i = 0; i < cfg->num_inputs; i++) {
4023 unsigned int type;
4024 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4025 type = PIN_VREF80;
4026 else
4027 type = PIN_IN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004028 snd_hda_set_pin_ctl(codec, cfg->inputs[i].pin, type);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004029 }
4030
4031 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004032 if (spec->auto_mic_ext >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004033 snd_hda_jack_detect_enable(codec,
4034 cfg->inputs[spec->auto_mic_ext].pin,
4035 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004036 }
4037 if (spec->auto_mic_dock >= 0) {
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004038 snd_hda_jack_detect_enable(codec,
4039 cfg->inputs[spec->auto_mic_dock].pin,
4040 CONEXANT_MIC_EVENT);
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004041 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004042 cx_auto_automic(codec);
4043 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004044 select_input_connection(codec, spec->imux_info[0].adc,
4045 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004046 }
4047}
4048
4049static void cx_auto_init_digital(struct hda_codec *codec)
4050{
4051 struct conexant_spec *spec = codec->spec;
4052 struct auto_pin_cfg *cfg = &spec->autocfg;
4053
4054 if (spec->multiout.dig_out_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004055 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004056 if (spec->dig_in_nid)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004057 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004058}
4059
4060static int cx_auto_init(struct hda_codec *codec)
4061{
Takashi Iwai527c73b2012-03-12 12:38:51 +01004062 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004063 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4064 cx_auto_init_output(codec);
4065 cx_auto_init_input(codec);
4066 cx_auto_init_digital(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004067 snd_hda_jack_report_sync(codec);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004068 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004069 return 0;
4070}
4071
David Henningsson983345e2011-02-15 19:57:09 +01004072static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004073 const char *dir, int cidx,
David Henningsson18dcd302012-04-02 15:40:27 +02004074 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004075{
David Henningsson18dcd302012-04-02 15:40:27 +02004076 static char name[44];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004077 static struct snd_kcontrol_new knew[] = {
4078 HDA_CODEC_VOLUME(name, 0, 0, 0),
4079 HDA_CODEC_MUTE(name, 0, 0, 0),
4080 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004081 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004082 int i, err;
4083
4084 for (i = 0; i < 2; i++) {
4085 struct snd_kcontrol *kctl;
David Henningsson18dcd302012-04-02 15:40:27 +02004086 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
David Henningsson983345e2011-02-15 19:57:09 +01004087 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004088 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4089 knew[i].index = cidx;
4090 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4091 kctl = snd_ctl_new1(&knew[i], codec);
4092 if (!kctl)
4093 return -ENOMEM;
4094 err = snd_hda_ctl_add(codec, nid, kctl);
4095 if (err < 0)
4096 return err;
Takashi Iwai38681372012-02-27 15:00:58 +01004097 if (!(query_amp_caps(codec, nid, hda_dir) &
4098 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
Takashi Iwaif2e57312010-09-15 10:07:08 +02004099 break;
4100 }
4101 return 0;
4102}
4103
David Henningsson983345e2011-02-15 19:57:09 +01004104#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
David Henningsson18dcd302012-04-02 15:40:27 +02004105 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
David Henningsson983345e2011-02-15 19:57:09 +01004106
Takashi Iwaif2e57312010-09-15 10:07:08 +02004107#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4108 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4109
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004110static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4111 hda_nid_t pin, const char *name, int idx)
4112{
4113 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004114 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4115 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4116 if (caps & AC_AMPCAP_NUM_STEPS)
4117 return cx_auto_add_pb_volume(codec, dac, name, idx);
4118 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004119 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4120 if (caps & AC_AMPCAP_NUM_STEPS)
4121 return cx_auto_add_pb_volume(codec, pin, name, idx);
4122 return 0;
4123}
4124
Takashi Iwaif2e57312010-09-15 10:07:08 +02004125static int cx_auto_build_output_controls(struct hda_codec *codec)
4126{
4127 struct conexant_spec *spec = codec->spec;
4128 int i, err;
4129 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004130 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004131
4132 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004133 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4134 spec->dac_info[0].pin,
4135 "Master", 0);
4136
Takashi Iwaif2e57312010-09-15 10:07:08 +02004137 for (i = 0; i < spec->dac_info_filled; i++) {
4138 const char *label;
4139 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004140 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004141 type = spec->dac_info[i].type;
4142 if (type == AUTO_PIN_LINE_OUT)
4143 type = spec->autocfg.line_out_type;
4144 switch (type) {
4145 case AUTO_PIN_LINE_OUT:
4146 default:
4147 label = texts[num_line++];
4148 idx = 0;
4149 break;
4150 case AUTO_PIN_HP_OUT:
4151 label = "Headphone";
4152 idx = num_hp++;
4153 break;
4154 case AUTO_PIN_SPEAKER_OUT:
4155 label = "Speaker";
4156 idx = num_spk++;
4157 break;
4158 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004159 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004160 spec->dac_info[i].pin,
4161 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004162 if (err < 0)
4163 return err;
4164 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004165
4166 if (spec->auto_mute) {
4167 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4168 if (err < 0)
4169 return err;
4170 }
4171
Takashi Iwaif2e57312010-09-15 10:07:08 +02004172 return 0;
4173}
4174
David Henningsson18dcd302012-04-02 15:40:27 +02004175/* Returns zero if this is a normal stereo channel, and non-zero if it should
4176 be split in two independent channels.
4177 dest_label must be at least 44 characters. */
4178static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4179 char *dest_label, int nid)
4180{
4181 struct conexant_spec *spec = codec->spec;
4182 int i;
4183
4184 if (!spec->fixup_stereo_dmic)
4185 return 0;
4186
4187 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4188 int def_conf;
4189 if (spec->autocfg.inputs[i].pin != nid)
4190 continue;
4191
4192 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4193 return 0;
4194 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4195 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4196 return 0;
4197
4198 /* Finally found the inverted internal mic! */
4199 snprintf(dest_label, 44, "Inverted %s", label);
4200 return 1;
4201 }
4202 return 0;
4203}
4204
Takashi Iwai6764bce2011-05-13 16:52:25 +02004205static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4206 const char *label, const char *pfx,
4207 int cidx)
4208{
4209 struct conexant_spec *spec = codec->spec;
4210 int i;
4211
4212 for (i = 0; i < spec->num_adc_nids; i++) {
David Henningsson18dcd302012-04-02 15:40:27 +02004213 char rightch_label[44];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004214 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004215 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004216 if (idx < 0)
4217 continue;
Michael Karcher4f324562012-04-06 15:34:15 +02004218 if (codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004219 idx = 0;
David Henningsson18dcd302012-04-02 15:40:27 +02004220
4221 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4222 /* Make two independent kcontrols for left and right */
4223 int err = cx_auto_add_volume_idx(codec, label, pfx,
4224 cidx, adc_nid, HDA_INPUT, idx, 1);
4225 if (err < 0)
4226 return err;
4227 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4228 cidx, adc_nid, HDA_INPUT, idx, 2);
4229 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004230 return cx_auto_add_volume_idx(codec, label, pfx,
David Henningsson18dcd302012-04-02 15:40:27 +02004231 cidx, adc_nid, HDA_INPUT, idx, 3);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004232 }
4233 return 0;
4234}
4235
Takashi Iwaicf27f292011-05-16 11:33:02 +02004236static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4237 const char *label, int cidx)
4238{
4239 struct conexant_spec *spec = codec->spec;
4240 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004241 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004242
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004243 nid = spec->imux_info[idx].pin;
David Henningsson18dcd302012-04-02 15:40:27 +02004244 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4245 char rightch_label[44];
4246 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4247 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4248 cidx, nid, HDA_INPUT, 0, 1);
4249 if (err < 0)
4250 return err;
4251 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4252 cidx, nid, HDA_INPUT, 0, 2);
4253 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004254 return cx_auto_add_volume(codec, label, " Boost", cidx,
4255 nid, HDA_INPUT);
David Henningsson18dcd302012-04-02 15:40:27 +02004256 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004257 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4258 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004259 if (con < 0)
4260 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004261 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004262 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004263 return 0; /* already present */
4264 }
4265
4266 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004267 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004268 return cx_auto_add_volume(codec, label, " Boost", 0,
4269 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004270 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004271 return 0;
4272}
4273
Takashi Iwaif2e57312010-09-15 10:07:08 +02004274static int cx_auto_build_input_controls(struct hda_codec *codec)
4275{
4276 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004277 struct hda_input_mux *imux = &spec->private_imux;
4278 const char *prev_label;
4279 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004280 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004281 int multi_connection;
4282
Takashi Iwai6b452142011-10-14 15:26:20 +02004283 if (!imux->num_items)
4284 return 0;
4285
Takashi Iwaicf27f292011-05-16 11:33:02 +02004286 multi_connection = 0;
4287 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004288 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4289 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004290 if (cidx < 0)
4291 continue;
4292 input_conn[i] = spec->imux_info[i].adc;
Michael Karcher4f324562012-04-06 15:34:15 +02004293 if (!codec->single_adc_amp)
Takashi Iwai6b452142011-10-14 15:26:20 +02004294 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004295 if (i > 0 && input_conn[i] != input_conn[0])
4296 multi_connection = 1;
4297 }
David Henningsson983345e2011-02-15 19:57:09 +01004298
Takashi Iwaif2e57312010-09-15 10:07:08 +02004299 prev_label = NULL;
4300 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004301 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004302 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004303 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004304
Takashi Iwaicf27f292011-05-16 11:33:02 +02004305 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004306 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004307 if (label == prev_label)
4308 cidx++;
4309 else
4310 cidx = 0;
4311 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004312
Takashi Iwaicf27f292011-05-16 11:33:02 +02004313 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4314 if (err < 0)
4315 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004316
Takashi Iwaicf27f292011-05-16 11:33:02 +02004317 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004318 if (i > 0)
4319 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004320 err = cx_auto_add_capture_volume(codec, nid,
4321 "Capture", "", cidx);
4322 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004323 bool dup_found = false;
4324 for (j = 0; j < i; j++) {
4325 if (input_conn[j] == input_conn[i]) {
4326 dup_found = true;
4327 break;
4328 }
4329 }
4330 if (dup_found)
4331 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004332 err = cx_auto_add_capture_volume(codec, nid,
4333 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004334 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004335 if (err < 0)
4336 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004337 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004338
4339 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4340 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4341 if (err < 0)
4342 return err;
4343 }
4344
Takashi Iwaif2e57312010-09-15 10:07:08 +02004345 return 0;
4346}
4347
4348static int cx_auto_build_controls(struct hda_codec *codec)
4349{
Takashi Iwai31ef2252011-12-01 17:41:36 +01004350 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004351 int err;
4352
4353 err = cx_auto_build_output_controls(codec);
4354 if (err < 0)
4355 return err;
4356 err = cx_auto_build_input_controls(codec);
4357 if (err < 0)
4358 return err;
Takashi Iwai31ef2252011-12-01 17:41:36 +01004359 err = conexant_build_controls(codec);
4360 if (err < 0)
4361 return err;
4362 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4363 if (err < 0)
4364 return err;
Takashi Iwaif29735c2012-03-13 07:55:10 +01004365 if (spec->vmaster_mute.sw_kctl) {
4366 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4367 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4368 spec->vmaster_mute_led);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01004369 if (err < 0)
4370 return err;
Takashi Iwai527c73b2012-03-12 12:38:51 +01004371 }
Takashi Iwai31ef2252011-12-01 17:41:36 +01004372 return 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004373}
4374
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004375static int cx_auto_search_adcs(struct hda_codec *codec)
4376{
4377 struct conexant_spec *spec = codec->spec;
4378 hda_nid_t nid, end_nid;
4379
4380 end_nid = codec->start_nid + codec->num_nodes;
4381 for (nid = codec->start_nid; nid < end_nid; nid++) {
4382 unsigned int caps = get_wcaps(codec, nid);
4383 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4384 continue;
4385 if (caps & AC_WCAP_DIGITAL)
4386 continue;
4387 if (snd_BUG_ON(spec->num_adc_nids >=
4388 ARRAY_SIZE(spec->private_adc_nids)))
4389 break;
4390 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4391 }
4392 spec->adc_nids = spec->private_adc_nids;
4393 return 0;
4394}
4395
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004396static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004397 .build_controls = cx_auto_build_controls,
4398 .build_pcms = conexant_build_pcms,
4399 .init = cx_auto_init,
4400 .free = conexant_free,
4401 .unsol_event = cx_auto_unsol_event,
4402#ifdef CONFIG_SND_HDA_POWER_SAVE
4403 .suspend = conexant_suspend,
4404#endif
4405 .reboot_notify = snd_hda_shutup_pins,
4406};
4407
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004408/*
4409 * pin fix-up
4410 */
4411struct cxt_pincfg {
4412 hda_nid_t nid;
4413 u32 val;
4414};
4415
4416static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4417{
4418 for (; cfg->nid; cfg++)
4419 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4420
4421}
4422
David Henningsson18dcd302012-04-02 15:40:27 +02004423enum {
4424 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02004425 CXT_PINCFG_LENOVO_TP410,
David Henningsson18dcd302012-04-02 15:40:27 +02004426 CXT_FIXUP_STEREO_DMIC,
4427};
4428
4429static void apply_fixup(struct hda_codec *codec,
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004430 const struct snd_pci_quirk *quirk,
4431 const struct cxt_pincfg **table)
4432{
David Henningsson18dcd302012-04-02 15:40:27 +02004433 struct conexant_spec *spec = codec->spec;
4434
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004435 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
David Henningsson83b0c6b2012-04-10 13:05:29 +02004436 if (!quirk)
4437 return;
4438 if (table[quirk->value]) {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004439 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4440 quirk->name);
4441 apply_pincfg(codec, table[quirk->value]);
4442 }
David Henningsson18dcd302012-04-02 15:40:27 +02004443 if (quirk->value == CXT_FIXUP_STEREO_DMIC) {
4444 snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n",
4445 quirk->name);
4446 spec->fixup_stereo_dmic = 1;
4447 }
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004448}
4449
Takashi Iwaid70f3632012-04-19 15:18:08 +02004450/* ThinkPad X200 & co with cxt5051 */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004451static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4452 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4453 { 0x17, 0x21a11000 }, /* dock-mic */
4454 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01004455 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004456 {}
4457};
4458
Takashi Iwaid70f3632012-04-19 15:18:08 +02004459/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4460static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = {
4461 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4462 { 0x1a, 0x21a190f0 }, /* dock-mic */
4463 { 0x1c, 0x212140ff }, /* dock-HP */
4464 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004465};
4466
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004467static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4468 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
Takashi Iwaid70f3632012-04-19 15:18:08 +02004469 [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410,
David Henningsson18dcd302012-04-02 15:40:27 +02004470 [CXT_FIXUP_STEREO_DMIC] = NULL,
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004471};
4472
Takashi Iwaid70f3632012-04-19 15:18:08 +02004473static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004474 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4475 {}
4476};
4477
Takashi Iwaid70f3632012-04-19 15:18:08 +02004478static const struct snd_pci_quirk cxt5066_fixups[] = {
4479 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4480 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4481 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4482 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4483 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02004484 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaif2e57312010-09-15 10:07:08 +02004485 {}
4486};
4487
Takashi Iwai38681372012-02-27 15:00:58 +01004488/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4489 * can be created (bko#42825)
4490 */
4491static void add_cx5051_fake_mutes(struct hda_codec *codec)
4492{
4493 static hda_nid_t out_nids[] = {
4494 0x10, 0x11, 0
4495 };
4496 hda_nid_t *p;
4497
4498 for (p = out_nids; *p; p++)
4499 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4500 AC_AMPCAP_MIN_MUTE |
4501 query_amp_caps(codec, *p, HDA_OUTPUT));
4502}
4503
Takashi Iwaif2e57312010-09-15 10:07:08 +02004504static int patch_conexant_auto(struct hda_codec *codec)
4505{
4506 struct conexant_spec *spec;
4507 int err;
4508
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004509 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4510 codec->chip_name);
4511
Takashi Iwaif2e57312010-09-15 10:07:08 +02004512 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4513 if (!spec)
4514 return -ENOMEM;
4515 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004516
Takashi Iwai6b452142011-10-14 15:26:20 +02004517 switch (codec->vendor_id) {
4518 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02004519 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02004520 break;
Takashi Iwai38681372012-02-27 15:00:58 +01004521 case 0x14f15051:
4522 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02004523 codec->pin_amp_workaround = 1;
Takashi Iwaid3980112012-04-19 17:17:59 +02004524 apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl);
Takashi Iwai38681372012-02-27 15:00:58 +01004525 break;
Michael Karcher51969d62012-04-06 15:34:19 +02004526 default:
4527 codec->pin_amp_workaround = 1;
Takashi Iwaid3980112012-04-19 17:17:59 +02004528 apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl);
Takashi Iwai6b452142011-10-14 15:26:20 +02004529 }
4530
Takashi Iwaif29735c2012-03-13 07:55:10 +01004531 /* Show mute-led control only on HP laptops
4532 * This is a sort of white-list: on HP laptops, EAPD corresponds
4533 * only to the mute-LED without actualy amp function. Meanwhile,
4534 * others may use EAPD really as an amp switch, so it might be
4535 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01004536 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01004537 switch (codec->subsystem_id >> 16) {
4538 case 0x103c:
4539 spec->vmaster_mute_led = 1;
4540 break;
4541 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01004542
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004543 err = cx_auto_search_adcs(codec);
4544 if (err < 0)
4545 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004546 err = cx_auto_parse_auto_config(codec);
4547 if (err < 0) {
4548 kfree(codec->spec);
4549 codec->spec = NULL;
4550 return err;
4551 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004552 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004553 codec->patch_ops = cx_auto_patch_ops;
4554 if (spec->beep_amp)
4555 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01004556
4557 /* Some laptops with Conexant chips show stalls in S3 resume,
4558 * which falls into the single-cmd mode.
4559 * Better to make reset, then.
4560 */
4561 if (!codec->bus->sync_write) {
4562 snd_printd("hda_codec: "
4563 "Enable sync_write for stable communication\n");
4564 codec->bus->sync_write = 1;
4565 codec->bus->allow_bus_reset = 1;
4566 }
4567
Takashi Iwaif2e57312010-09-15 10:07:08 +02004568 return 0;
4569}
4570
4571/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004572 */
4573
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004574static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004575 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4576 .patch = patch_cxt5045 },
4577 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4578 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004579 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4580 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004581 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4582 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004583 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4584 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004585 { .id = 0x14f15068, .name = "CX20584",
4586 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004587 { .id = 0x14f15069, .name = "CX20585",
4588 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004589 { .id = 0x14f1506c, .name = "CX20588",
4590 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004591 { .id = 0x14f1506e, .name = "CX20590",
4592 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004593 { .id = 0x14f15097, .name = "CX20631",
4594 .patch = patch_conexant_auto },
4595 { .id = 0x14f15098, .name = "CX20632",
4596 .patch = patch_conexant_auto },
4597 { .id = 0x14f150a1, .name = "CX20641",
4598 .patch = patch_conexant_auto },
4599 { .id = 0x14f150a2, .name = "CX20642",
4600 .patch = patch_conexant_auto },
4601 { .id = 0x14f150ab, .name = "CX20651",
4602 .patch = patch_conexant_auto },
4603 { .id = 0x14f150ac, .name = "CX20652",
4604 .patch = patch_conexant_auto },
4605 { .id = 0x14f150b8, .name = "CX20664",
4606 .patch = patch_conexant_auto },
4607 { .id = 0x14f150b9, .name = "CX20665",
4608 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004609 {} /* terminator */
4610};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004611
4612MODULE_ALIAS("snd-hda-codec-id:14f15045");
4613MODULE_ALIAS("snd-hda-codec-id:14f15047");
4614MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004615MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004616MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004617MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004618MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004619MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004620MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004621MODULE_ALIAS("snd-hda-codec-id:14f15097");
4622MODULE_ALIAS("snd-hda-codec-id:14f15098");
4623MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4624MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4625MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4626MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4627MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4628MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004629
4630MODULE_LICENSE("GPL");
4631MODULE_DESCRIPTION("Conexant HD-audio codec");
4632
4633static struct hda_codec_preset_list conexant_list = {
4634 .preset = snd_hda_preset_conexant,
4635 .owner = THIS_MODULE,
4636};
4637
4638static int __init patch_conexant_init(void)
4639{
4640 return snd_hda_add_codec_preset(&conexant_list);
4641}
4642
4643static void __exit patch_conexant_exit(void)
4644{
4645 snd_hda_delete_codec_preset(&conexant_list);
4646}
4647
4648module_init(patch_conexant_init)
4649module_exit(patch_conexant_exit)