blob: 0c8b5a1993edbc277ec95e4e12a30dbc3361f837 [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>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020042#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010043
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010044/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010045
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010046#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010047#define CXT5051_PORTB_EVENT 0x38
48#define CXT5051_PORTC_EVENT 0x39
49
Takashi Iwaifaddaa52010-01-23 22:31:36 +010050#define AUTO_MIC_PORTB (1 << 1)
51#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010052
Takashi Iwaif2e57312010-09-15 10:07:08 +020053struct pin_dac_pair {
54 hda_nid_t pin;
55 hda_nid_t dac;
56 int type;
57};
58
Takashi Iwai47ad1f42011-05-17 09:15:55 +020059struct imux_info {
60 hda_nid_t pin; /* input pin NID */
61 hda_nid_t adc; /* connected ADC NID */
62 hda_nid_t boost; /* optional boost volume NID */
63 int index; /* corresponding to autocfg.input */
64};
65
Tobin Davisc9b443d2006-11-14 12:13:39 +010066struct conexant_spec {
67
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020068 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010069 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010070 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010071
72 const struct hda_verb *init_verbs[5]; /* initialization verbs
73 * don't forget NULL
74 * termination!
75 */
76 unsigned int num_init_verbs;
77
78 /* playback */
79 struct hda_multi_out multiout; /* playback set-up
80 * max_channels, dacs must be set
81 * dig_out_nid and hp_nid are optional
82 */
83 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010084 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020085 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010086 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020087 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020088 int auto_mic_dock; /* imux_pins[] index for dock mic */
89 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010090 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050091 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010092
93 /* capture */
94 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020095 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010096 hda_nid_t dig_in_nid; /* digital-in NID; optional */
97
Takashi Iwai461e2c72008-01-25 11:35:17 +010098 unsigned int cur_adc_idx;
99 hda_nid_t cur_adc;
100 unsigned int cur_adc_stream_tag;
101 unsigned int cur_adc_format;
102
Takashi Iwai6764bce2011-05-13 16:52:25 +0200103 const struct hda_pcm_stream *capture_stream;
104
Tobin Davisc9b443d2006-11-14 12:13:39 +0100105 /* capture source */
106 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200107 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100108 unsigned int cur_mux[3];
109
110 /* channel model */
111 const struct hda_channel_mode *channel_mode;
112 int num_channel_mode;
113
114 /* PCM information */
115 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
116
Tobin Davisc9b443d2006-11-14 12:13:39 +0100117 unsigned int spdif_route;
118
119 /* dynamic controls, init_verbs and input_mux */
120 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100121 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200122 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200123 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200124 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200125 struct pin_dac_pair dac_info[8];
126 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100127
Daniel Drake0fb67e92009-07-16 14:46:57 +0100128 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200129 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200130 unsigned int detect_line:1; /* Line-out detection enabled */
131 unsigned int automute_lines:1; /* automute line-out as well */
132 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200133 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500134 unsigned int dell_vostro:1;
135 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200136 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200137 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100138 unsigned int asus:1;
Takashi Iwai254f2962011-10-14 15:22:34 +0200139 unsigned int pin_eapd_ctrls:1;
Takashi Iwai6b452142011-10-14 15:26:20 +0200140 unsigned int single_adc_amp:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100141
Takashi Iwai6764bce2011-05-13 16:52:25 +0200142 unsigned int adc_switching:1;
143
Daniel Drake75f89912010-01-07 13:46:25 +0100144 unsigned int ext_mic_present;
145 unsigned int recording;
146 void (*capture_prepare)(struct hda_codec *codec);
147 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100148
149 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
150 * through the microphone jack.
151 * When the user enables this through a mixer switch, both internal and
152 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
153 * we also allow the bias to be configured through a separate mixer
154 * control. */
155 unsigned int dc_enable;
156 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
157 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200158
159 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200160
161 /* extra EAPD pins */
162 unsigned int num_eapds;
163 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100164};
165
166static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
167 struct hda_codec *codec,
168 struct snd_pcm_substream *substream)
169{
170 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100171 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
172 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100173}
174
175static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
176 struct hda_codec *codec,
177 unsigned int stream_tag,
178 unsigned int format,
179 struct snd_pcm_substream *substream)
180{
181 struct conexant_spec *spec = codec->spec;
182 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
183 stream_tag,
184 format, substream);
185}
186
187static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 struct snd_pcm_substream *substream)
190{
191 struct conexant_spec *spec = codec->spec;
192 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
193}
194
195/*
196 * Digital out
197 */
198static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 struct snd_pcm_substream *substream)
201{
202 struct conexant_spec *spec = codec->spec;
203 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
204}
205
206static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
207 struct hda_codec *codec,
208 struct snd_pcm_substream *substream)
209{
210 struct conexant_spec *spec = codec->spec;
211 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
212}
213
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200214static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
215 struct hda_codec *codec,
216 unsigned int stream_tag,
217 unsigned int format,
218 struct snd_pcm_substream *substream)
219{
220 struct conexant_spec *spec = codec->spec;
221 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
222 stream_tag,
223 format, substream);
224}
225
Tobin Davisc9b443d2006-11-14 12:13:39 +0100226/*
227 * Analog capture
228 */
229static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
230 struct hda_codec *codec,
231 unsigned int stream_tag,
232 unsigned int format,
233 struct snd_pcm_substream *substream)
234{
235 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100236 if (spec->capture_prepare)
237 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100238 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
239 stream_tag, 0, format);
240 return 0;
241}
242
243static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
244 struct hda_codec *codec,
245 struct snd_pcm_substream *substream)
246{
247 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100248 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100249 if (spec->capture_cleanup)
250 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100251 return 0;
252}
253
254
255
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200256static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100257 .substreams = 1,
258 .channels_min = 2,
259 .channels_max = 2,
260 .nid = 0, /* fill later */
261 .ops = {
262 .open = conexant_playback_pcm_open,
263 .prepare = conexant_playback_pcm_prepare,
264 .cleanup = conexant_playback_pcm_cleanup
265 },
266};
267
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200268static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100269 .substreams = 1,
270 .channels_min = 2,
271 .channels_max = 2,
272 .nid = 0, /* fill later */
273 .ops = {
274 .prepare = conexant_capture_pcm_prepare,
275 .cleanup = conexant_capture_pcm_cleanup
276 },
277};
278
279
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200280static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100281 .substreams = 1,
282 .channels_min = 2,
283 .channels_max = 2,
284 .nid = 0, /* fill later */
285 .ops = {
286 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200287 .close = conexant_dig_playback_pcm_close,
288 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100289 },
290};
291
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200292static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100293 .substreams = 1,
294 .channels_min = 2,
295 .channels_max = 2,
296 /* NID is set in alc_build_pcms */
297};
298
Takashi Iwai461e2c72008-01-25 11:35:17 +0100299static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
300 struct hda_codec *codec,
301 unsigned int stream_tag,
302 unsigned int format,
303 struct snd_pcm_substream *substream)
304{
305 struct conexant_spec *spec = codec->spec;
306 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
307 spec->cur_adc_stream_tag = stream_tag;
308 spec->cur_adc_format = format;
309 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
310 return 0;
311}
312
313static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
314 struct hda_codec *codec,
315 struct snd_pcm_substream *substream)
316{
317 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100318 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100319 spec->cur_adc = 0;
320 return 0;
321}
322
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200323static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100324 .substreams = 1,
325 .channels_min = 2,
326 .channels_max = 2,
327 .nid = 0, /* fill later */
328 .ops = {
329 .prepare = cx5051_capture_pcm_prepare,
330 .cleanup = cx5051_capture_pcm_cleanup
331 },
332};
333
Tobin Davisc9b443d2006-11-14 12:13:39 +0100334static int conexant_build_pcms(struct hda_codec *codec)
335{
336 struct conexant_spec *spec = codec->spec;
337 struct hda_pcm *info = spec->pcm_rec;
338
339 codec->num_pcms = 1;
340 codec->pcm_info = info;
341
342 info->name = "CONEXANT Analog";
343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
345 spec->multiout.max_channels;
346 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
347 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200348 if (spec->capture_stream)
349 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
350 else {
351 if (codec->vendor_id == 0x14f15051)
352 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
353 cx5051_pcm_analog_capture;
354 else {
355 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
356 conexant_pcm_analog_capture;
357 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
358 spec->num_adc_nids;
359 }
360 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100361 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
362
363 if (spec->multiout.dig_out_nid) {
364 info++;
365 codec->num_pcms++;
366 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100367 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100368 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
369 conexant_pcm_digital_playback;
370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
371 spec->multiout.dig_out_nid;
372 if (spec->dig_in_nid) {
373 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
374 conexant_pcm_digital_capture;
375 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
376 spec->dig_in_nid;
377 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500378 if (spec->slave_dig_outs[0])
379 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100380 }
381
382 return 0;
383}
384
385static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_info *uinfo)
387{
388 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
389 struct conexant_spec *spec = codec->spec;
390
391 return snd_hda_input_mux_info(spec->input_mux, uinfo);
392}
393
394static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
395 struct snd_ctl_elem_value *ucontrol)
396{
397 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398 struct conexant_spec *spec = codec->spec;
399 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
400
401 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
402 return 0;
403}
404
405static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_value *ucontrol)
407{
408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409 struct conexant_spec *spec = codec->spec;
410 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
411
412 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
413 spec->capsrc_nids[adc_idx],
414 &spec->cur_mux[adc_idx]);
415}
416
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100417static int conexant_init_jacks(struct hda_codec *codec)
418{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100419#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100420 struct conexant_spec *spec = codec->spec;
421 int i;
422
423 for (i = 0; i < spec->num_init_verbs; i++) {
424 const struct hda_verb *hv;
425
426 hv = spec->init_verbs[i];
427 while (hv->nid) {
428 int err = 0;
429 switch (hv->param ^ AC_USRSP_EN) {
430 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100431 err = snd_hda_input_jack_add(codec, hv->nid,
432 SND_JACK_HEADPHONE, NULL);
433 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100434 break;
435 case CXT5051_PORTC_EVENT:
436 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100437 err = snd_hda_input_jack_add(codec, hv->nid,
438 SND_JACK_MICROPHONE, NULL);
439 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100440 break;
441 }
442 if (err < 0)
443 return err;
444 ++hv;
445 }
446 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100447#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100448 return 0;
449}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100450
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200451static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
452 unsigned int power_state)
453{
454 if (power_state == AC_PWRST_D3)
455 msleep(100);
456 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
457 power_state);
458 /* partial workaround for "azx_get_response timeout" */
459 if (power_state == AC_PWRST_D0)
460 msleep(10);
461 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
462}
463
Tobin Davisc9b443d2006-11-14 12:13:39 +0100464static int conexant_init(struct hda_codec *codec)
465{
466 struct conexant_spec *spec = codec->spec;
467 int i;
468
469 for (i = 0; i < spec->num_init_verbs; i++)
470 snd_hda_sequence_write(codec, spec->init_verbs[i]);
471 return 0;
472}
473
474static void conexant_free(struct hda_codec *codec)
475{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100476 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200477 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100478 kfree(codec->spec);
479}
480
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200481static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100482 {
483 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
484 .name = "Capture Source",
485 .info = conexant_mux_enum_info,
486 .get = conexant_mux_enum_get,
487 .put = conexant_mux_enum_put
488 },
489 {}
490};
491
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200492#ifdef CONFIG_SND_HDA_INPUT_BEEP
493/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200494static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200495 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
496 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
497 { } /* end */
498};
499#endif
500
Takashi Iwaiea734962011-01-17 11:29:34 +0100501static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100502 "Headphone Playback Volume",
503 "Speaker Playback Volume",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200504 "Front Playback Volume",
505 "Surround Playback Volume",
506 "CLFE Playback Volume",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100507 NULL
508};
509
Takashi Iwaiea734962011-01-17 11:29:34 +0100510static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100511 "Headphone Playback Switch",
512 "Speaker Playback Switch",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200513 "Front Playback Switch",
514 "Surround Playback Switch",
515 "CLFE Playback Switch",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100516 NULL
517};
518
Tobin Davisc9b443d2006-11-14 12:13:39 +0100519static int conexant_build_controls(struct hda_codec *codec)
520{
521 struct conexant_spec *spec = codec->spec;
522 unsigned int i;
523 int err;
524
525 for (i = 0; i < spec->num_mixers; i++) {
526 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
527 if (err < 0)
528 return err;
529 }
530 if (spec->multiout.dig_out_nid) {
531 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600532 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100533 spec->multiout.dig_out_nid);
534 if (err < 0)
535 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100536 err = snd_hda_create_spdif_share_sw(codec,
537 &spec->multiout);
538 if (err < 0)
539 return err;
540 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100541 }
542 if (spec->dig_in_nid) {
543 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
544 if (err < 0)
545 return err;
546 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100547
548 /* if we have no master control, let's create it */
549 if (spec->vmaster_nid &&
550 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
551 unsigned int vmaster_tlv[4];
552 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
553 HDA_OUTPUT, vmaster_tlv);
554 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
555 vmaster_tlv, slave_vols);
556 if (err < 0)
557 return err;
558 }
559 if (spec->vmaster_nid &&
560 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
561 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
562 NULL, slave_sws);
563 if (err < 0)
564 return err;
565 }
566
Takashi Iwaib880c742009-03-10 14:41:05 +0100567 if (spec->input_mux) {
568 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
569 if (err < 0)
570 return err;
571 }
572
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200573#ifdef CONFIG_SND_HDA_INPUT_BEEP
574 /* create beep controls if needed */
575 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200576 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200577 for (knew = cxt_beep_mixer; knew->name; knew++) {
578 struct snd_kcontrol *kctl;
579 kctl = snd_ctl_new1(knew, codec);
580 if (!kctl)
581 return -ENOMEM;
582 kctl->private_value = spec->beep_amp;
583 err = snd_hda_ctl_add(codec, 0, kctl);
584 if (err < 0)
585 return err;
586 }
587 }
588#endif
589
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590 return 0;
591}
592
Takashi Iwai697c3732010-07-30 11:28:02 +0200593#ifdef CONFIG_SND_HDA_POWER_SAVE
594static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
595{
596 snd_hda_shutup_pins(codec);
597 return 0;
598}
599#endif
600
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200601static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602 .build_controls = conexant_build_controls,
603 .build_pcms = conexant_build_pcms,
604 .init = conexant_init,
605 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200606 .set_power_state = conexant_set_power,
Takashi Iwai697c3732010-07-30 11:28:02 +0200607#ifdef CONFIG_SND_HDA_POWER_SAVE
608 .suspend = conexant_suspend,
609#endif
610 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100611};
612
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200613#ifdef CONFIG_SND_HDA_INPUT_BEEP
614#define set_beep_amp(spec, nid, idx, dir) \
615 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
616#else
617#define set_beep_amp(spec, nid, idx, dir) /* NOP */
618#endif
619
Takashi Iwai6764bce2011-05-13 16:52:25 +0200620static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100621/*
622 * EAPD control
623 * the private value = nid | (invert << 8)
624 */
625
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200626#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100627
Tobin Davis82f30042007-02-13 12:45:44 +0100628static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 struct snd_ctl_elem_value *ucontrol)
630{
631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
632 struct conexant_spec *spec = codec->spec;
633 int invert = (kcontrol->private_value >> 8) & 1;
634 if (invert)
635 ucontrol->value.integer.value[0] = !spec->cur_eapd;
636 else
637 ucontrol->value.integer.value[0] = spec->cur_eapd;
638 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100639
Tobin Davisc9b443d2006-11-14 12:13:39 +0100640}
641
Tobin Davis82f30042007-02-13 12:45:44 +0100642static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100643 struct snd_ctl_elem_value *ucontrol)
644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct conexant_spec *spec = codec->spec;
647 int invert = (kcontrol->private_value >> 8) & 1;
648 hda_nid_t nid = kcontrol->private_value & 0xff;
649 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100650
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100651 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100652 if (invert)
653 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200654 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100655 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100656
Tobin Davisc9b443d2006-11-14 12:13:39 +0100657 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200658 snd_hda_codec_write_cache(codec, nid,
659 0, AC_VERB_SET_EAPD_BTLENABLE,
660 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100661 return 1;
662}
663
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100664/* controls for test mode */
665#ifdef CONFIG_SND_DEBUG
666
Tobin Davis82f30042007-02-13 12:45:44 +0100667#define CXT_EAPD_SWITCH(xname, nid, mask) \
668 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
669 .info = cxt_eapd_info, \
670 .get = cxt_eapd_get, \
671 .put = cxt_eapd_put, \
672 .private_value = nid | (mask<<16) }
673
674
675
Tobin Davisc9b443d2006-11-14 12:13:39 +0100676static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_info *uinfo)
678{
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 struct conexant_spec *spec = codec->spec;
681 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
682 spec->num_channel_mode);
683}
684
685static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
687{
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct conexant_spec *spec = codec->spec;
690 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
691 spec->num_channel_mode,
692 spec->multiout.max_channels);
693}
694
695static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_value *ucontrol)
697{
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699 struct conexant_spec *spec = codec->spec;
700 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
701 spec->num_channel_mode,
702 &spec->multiout.max_channels);
703 if (err >= 0 && spec->need_dac_fix)
704 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
705 return err;
706}
707
708#define CXT_PIN_MODE(xname, nid, dir) \
709 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
710 .info = conexant_ch_mode_info, \
711 .get = conexant_ch_mode_get, \
712 .put = conexant_ch_mode_put, \
713 .private_value = nid | (dir<<16) }
714
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100715#endif /* CONFIG_SND_DEBUG */
716
Tobin Davisc9b443d2006-11-14 12:13:39 +0100717/* Conexant 5045 specific */
718
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200719static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
720static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
721static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100722#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100723
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200724static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100725 { 2, NULL },
726};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100727
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200728static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100729 .num_items = 2,
730 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100731 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100732 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100733 }
734};
735
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200736static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200737 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100738 .items = {
739 { "IntMic", 0x1 },
740 { "ExtMic", 0x2 },
741 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200742 { "CD", 0x4 },
743 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100744 }
745};
746
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200747static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100748 .num_items = 2,
749 .items = {
750 { "ExtMic", 0x1 },
751 { "IntMic", 0x2 },
752 }
753};
754
Tobin Davisc9b443d2006-11-14 12:13:39 +0100755/* turn on/off EAPD (+ mute HP) as a master switch */
756static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
757 struct snd_ctl_elem_value *ucontrol)
758{
759 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
760 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100761 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100762
Tobin Davis82f30042007-02-13 12:45:44 +0100763 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100764 return 0;
765
Tobin Davis82f30042007-02-13 12:45:44 +0100766 /* toggle internal speakers mute depending of presence of
767 * the headphone jack
768 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200769 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
770 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
771 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100772
Takashi Iwai47fd8302007-08-10 17:11:07 +0200773 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
774 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
775 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100776 return 1;
777}
778
779/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200780static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200781 .ops = &snd_hda_bind_vol,
782 .values = {
783 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
784 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
785 0
786 },
787};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100788
Tobin Davis7f296732007-03-12 11:39:01 +0100789/* toggle input of built-in and mic jack appropriately */
790static void cxt5045_hp_automic(struct hda_codec *codec)
791{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200792 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100793 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
794 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
795 {}
796 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200797 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100798 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
799 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
800 {}
801 };
802 unsigned int present;
803
Takashi Iwaid56757a2009-11-18 08:00:14 +0100804 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100805 if (present)
806 snd_hda_sequence_write(codec, mic_jack_on);
807 else
808 snd_hda_sequence_write(codec, mic_jack_off);
809}
810
Tobin Davisc9b443d2006-11-14 12:13:39 +0100811
812/* mute internal speaker if HP is plugged */
813static void cxt5045_hp_automute(struct hda_codec *codec)
814{
Tobin Davis82f30042007-02-13 12:45:44 +0100815 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100816 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100817
Takashi Iwaid56757a2009-11-18 08:00:14 +0100818 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100819
Takashi Iwai47fd8302007-08-10 17:11:07 +0200820 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
821 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
822 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100823}
824
825/* unsolicited event for HP jack sensing */
826static void cxt5045_hp_unsol_event(struct hda_codec *codec,
827 unsigned int res)
828{
829 res >>= 26;
830 switch (res) {
831 case CONEXANT_HP_EVENT:
832 cxt5045_hp_automute(codec);
833 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100834 case CONEXANT_MIC_EVENT:
835 cxt5045_hp_automic(codec);
836 break;
837
Tobin Davisc9b443d2006-11-14 12:13:39 +0100838 }
839}
840
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200841static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100842 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
843 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100844 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
845 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200846 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
847 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100848 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
849 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100850 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
851 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200852 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100853 {
854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
855 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100856 .info = cxt_eapd_info,
857 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100858 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100859 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100860 },
861
862 {}
863};
864
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200865static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200866 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
867 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
868 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
869 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
870
Jiang Zhe5218c892008-01-17 11:18:41 +0100871 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
872 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
873 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
874 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
875
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200876 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
877 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
878
Jiang Zhe5218c892008-01-17 11:18:41 +0100879 {}
880};
881
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200882static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100883 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
884 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100885 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
886 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100887 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
888 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100889 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
890 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100891 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
892 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100893 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
894 {
895 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
896 .name = "Master Playback Switch",
897 .info = cxt_eapd_info,
898 .get = cxt_eapd_get,
899 .put = cxt5045_hp_master_sw_put,
900 .private_value = 0x10,
901 },
902
903 {}
904};
905
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200906static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100907 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200908 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100909 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100910 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200911 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
912 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
913 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
914 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
919 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100920 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100921 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100922 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100923 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
924 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100925 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100927 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100928 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929 { } /* end */
930};
931
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200932static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100933 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100934 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
935 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
936 /* Line In,HP, Amp */
937 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
938 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
939 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
940 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
943 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
944 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
945 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100946 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100947 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
948 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
949 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
950 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100951 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100952 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
953 /* EAPD */
954 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
955 { } /* end */
956};
Tobin Davis7f296732007-03-12 11:39:01 +0100957
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200958static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100959 /* pin sensing on HP jack */
960 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200961 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100962};
963
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200964static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100965 /* pin sensing on HP jack */
966 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200967 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100968};
969
Tobin Davisc9b443d2006-11-14 12:13:39 +0100970#ifdef CONFIG_SND_DEBUG
971/* Test configuration for debugging, modelled after the ALC260 test
972 * configuration.
973 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200974static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100975 .num_items = 5,
976 .items = {
977 { "MIXER", 0x0 },
978 { "MIC1 pin", 0x1 },
979 { "LINE1 pin", 0x2 },
980 { "HP-OUT pin", 0x3 },
981 { "CD pin", 0x4 },
982 },
983};
984
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200985static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100986
987 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100988 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
989 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100990 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
991 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
992 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
993 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100994
995 /* Modes for retasking pin widgets */
996 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
997 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
998
Tobin Davis82f30042007-02-13 12:45:44 +0100999 /* EAPD Switch Control */
1000 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1001
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001003
Tobin Davis7f296732007-03-12 11:39:01 +01001004 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1005 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1006 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1007 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1008 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1009 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1010 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1011 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1012 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1013 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001014 {
1015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1016 .name = "Input Source",
1017 .info = conexant_mux_enum_info,
1018 .get = conexant_mux_enum_get,
1019 .put = conexant_mux_enum_put,
1020 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001021 /* Audio input controls */
1022 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1023 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1024 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1025 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1026 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1027 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1028 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1029 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1030 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1031 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001032 { } /* end */
1033};
1034
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001035static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001036 /* Set connections */
1037 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1038 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1039 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001040 /* Enable retasking pins as output, initially without power amp */
1041 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001042 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001043
1044 /* Disable digital (SPDIF) pins initially, but users can enable
1045 * them via a mixer switch. In the case of SPDIF-out, this initverb
1046 * payload also sets the generation to 0, output to be in "consumer"
1047 * PCM format, copyright asserted, no pre-emphasis and no validity
1048 * control.
1049 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001050 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1051 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001052
1053 /* Start with output sum widgets muted and their output gains at min */
1054 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1055 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1056
1057 /* Unmute retasking pin widget output buffers since the default
1058 * state appears to be output. As the pin mode is changed by the
1059 * user the pin mode control will take care of enabling the pin's
1060 * input/output buffers as needed.
1061 */
1062 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1063 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1064
1065 /* Mute capture amp left and right */
1066 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1067
1068 /* Set ADC connection select to match default mixer setting (mic1
1069 * pin)
1070 */
1071 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001072 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073
1074 /* Mute all inputs to mixer widget (even unconnected ones) */
1075 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1076 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1077 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1078 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1079 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1080
1081 { }
1082};
1083#endif
1084
1085
1086/* initialize jack-sensing, too */
1087static int cxt5045_init(struct hda_codec *codec)
1088{
1089 conexant_init(codec);
1090 cxt5045_hp_automute(codec);
1091 return 0;
1092}
1093
1094
1095enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001096 CXT5045_LAPTOP_HPSENSE,
1097 CXT5045_LAPTOP_MICSENSE,
1098 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001099 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001100 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001101#ifdef CONFIG_SND_DEBUG
1102 CXT5045_TEST,
1103#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001104 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001105 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001106};
1107
Takashi Iwaiea734962011-01-17 11:29:34 +01001108static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001109 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1110 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1111 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1112 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001113 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001114#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001115 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001117 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001118};
1119
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001120static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001121 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001122 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1123 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001124 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001125 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001126 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1127 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001128 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1129 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001130 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1131 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1132 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001133 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1134 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001135 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136 {}
1137};
1138
1139static int patch_cxt5045(struct hda_codec *codec)
1140{
1141 struct conexant_spec *spec;
1142 int board_config;
1143
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001144 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1145 cxt5045_models,
1146 cxt5045_cfg_tbl);
1147 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001148 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001149 if (board_config == CXT5045_AUTO)
1150 return patch_conexant_auto(codec);
1151
Tobin Davisc9b443d2006-11-14 12:13:39 +01001152 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1153 if (!spec)
1154 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001155 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001156 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157
1158 spec->multiout.max_channels = 2;
1159 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1160 spec->multiout.dac_nids = cxt5045_dac_nids;
1161 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1162 spec->num_adc_nids = 1;
1163 spec->adc_nids = cxt5045_adc_nids;
1164 spec->capsrc_nids = cxt5045_capsrc_nids;
1165 spec->input_mux = &cxt5045_capture_source;
1166 spec->num_mixers = 1;
1167 spec->mixers[0] = cxt5045_mixers;
1168 spec->num_init_verbs = 1;
1169 spec->init_verbs[0] = cxt5045_init_verbs;
1170 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001171 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1172 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001173
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001174 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001175
1176 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177
Tobin Davisc9b443d2006-11-14 12:13:39 +01001178 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001179 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001180 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181 spec->input_mux = &cxt5045_capture_source;
1182 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001183 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers;
1185 codec->patch_ops.init = cxt5045_init;
1186 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001187 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001188 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001189 spec->input_mux = &cxt5045_capture_source;
1190 spec->num_init_verbs = 2;
1191 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001192 spec->mixers[0] = cxt5045_mixers;
1193 codec->patch_ops.init = cxt5045_init;
1194 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001195 default:
1196 case CXT5045_LAPTOP_HPMICSENSE:
1197 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1198 spec->input_mux = &cxt5045_capture_source;
1199 spec->num_init_verbs = 3;
1200 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1201 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1202 spec->mixers[0] = cxt5045_mixers;
1203 codec->patch_ops.init = cxt5045_init;
1204 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001205 case CXT5045_BENQ:
1206 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1207 spec->input_mux = &cxt5045_capture_source_benq;
1208 spec->num_init_verbs = 1;
1209 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1210 spec->mixers[0] = cxt5045_mixers;
1211 spec->mixers[1] = cxt5045_benq_mixers;
1212 spec->num_mixers = 2;
1213 codec->patch_ops.init = cxt5045_init;
1214 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001215 case CXT5045_LAPTOP_HP530:
1216 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1217 spec->input_mux = &cxt5045_capture_source_hp530;
1218 spec->num_init_verbs = 2;
1219 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1220 spec->mixers[0] = cxt5045_mixers_hp530;
1221 codec->patch_ops.init = cxt5045_init;
1222 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223#ifdef CONFIG_SND_DEBUG
1224 case CXT5045_TEST:
1225 spec->input_mux = &cxt5045_test_capture_source;
1226 spec->mixers[0] = cxt5045_test_mixer;
1227 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001228 break;
1229
Tobin Davisc9b443d2006-11-14 12:13:39 +01001230#endif
1231 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001232
Takashi Iwai031005f2008-06-26 14:49:58 +02001233 switch (codec->subsystem_id >> 16) {
1234 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001235 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001236 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001237 case 0x17aa:
1238 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1239 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1240 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001241 */
1242 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1243 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1244 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1245 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1246 (1 << AC_AMPCAP_MUTE_SHIFT));
1247 break;
1248 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001249
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001250 if (spec->beep_amp)
1251 snd_hda_attach_beep_device(codec, spec->beep_amp);
1252
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 return 0;
1254}
1255
1256
1257/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001258#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001260static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1261static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1262static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001263
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001264static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001265 { 2, NULL },
1266};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001268static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001269 .num_items = 2,
1270 .items = {
1271 { "ExtMic", 0x2 },
1272 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001273 }
1274};
1275
1276/* turn on/off EAPD (+ mute HP) as a master switch */
1277static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1278 struct snd_ctl_elem_value *ucontrol)
1279{
1280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1281 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001282 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283
Tobin Davis82f30042007-02-13 12:45:44 +01001284 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 return 0;
1286
Tobin Davis82f30042007-02-13 12:45:44 +01001287 /* toggle internal speakers mute depending of presence of
1288 * the headphone jack
1289 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001290 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001291 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1292 * pin widgets unlike other codecs. In this case, we need to
1293 * set index 0x01 for the volume from the mixer amp 0x19.
1294 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001295 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001296 HDA_AMP_MUTE, bits);
1297 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1298 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1299 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 return 1;
1301}
1302
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303/* mute internal speaker if HP is plugged */
1304static void cxt5047_hp_automute(struct hda_codec *codec)
1305{
Tobin Davis82f30042007-02-13 12:45:44 +01001306 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001307 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308
Takashi Iwaid56757a2009-11-18 08:00:14 +01001309 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001310
Takashi Iwai47fd8302007-08-10 17:11:07 +02001311 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001312 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001313 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001314 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315}
1316
1317/* toggle input of built-in and mic jack appropriately */
1318static void cxt5047_hp_automic(struct hda_codec *codec)
1319{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001320 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001321 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1322 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001323 {}
1324 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001325 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001326 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1327 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328 {}
1329 };
1330 unsigned int present;
1331
Takashi Iwaid56757a2009-11-18 08:00:14 +01001332 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333 if (present)
1334 snd_hda_sequence_write(codec, mic_jack_on);
1335 else
1336 snd_hda_sequence_write(codec, mic_jack_off);
1337}
1338
1339/* unsolicited event for HP jack sensing */
1340static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1341 unsigned int res)
1342{
Marc Boucher9f113e02008-01-22 15:18:08 +01001343 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 case CONEXANT_HP_EVENT:
1345 cxt5047_hp_automute(codec);
1346 break;
1347 case CONEXANT_MIC_EVENT:
1348 cxt5047_hp_automic(codec);
1349 break;
1350 }
1351}
1352
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001353static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001354 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1355 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001356 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1358 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1359 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001361 {
1362 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1363 .name = "Master Playback Switch",
1364 .info = cxt_eapd_info,
1365 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 .put = cxt5047_hp_master_sw_put,
1367 .private_value = 0x13,
1368 },
1369
1370 {}
1371};
1372
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001373static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001374 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001375 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001376 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1377 {}
1378};
1379
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001380static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 { } /* end */
1383};
1384
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001385static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001386 /* Line in, Mic, Built-in Mic */
1387 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1388 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1389 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001390 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001391 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001392 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1393 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001394 /* Record selector: Mic */
1395 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1396 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1397 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1398 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001399 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1400 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1401 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1402 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001403 /* SPDIF route: PCM */
1404 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001405 /* Enable unsolicited events */
1406 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1407 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001408 { } /* end */
1409};
1410
1411/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001412static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001413 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414 {}
1415};
1416
1417/* Test configuration for debugging, modelled after the ALC260 test
1418 * configuration.
1419 */
1420#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001421static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001422 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001423 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001424 { "LINE1 pin", 0x0 },
1425 { "MIC1 pin", 0x1 },
1426 { "MIC2 pin", 0x2 },
1427 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001428 },
1429};
1430
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001431static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001432
1433 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001434 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1436 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1437 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001438 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1439 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001442 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1443 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1444 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1445 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001446
1447 /* Modes for retasking pin widgets */
1448 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1449 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1450
Tobin Davis82f30042007-02-13 12:45:44 +01001451 /* EAPD Switch Control */
1452 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1453
Tobin Davisc9b443d2006-11-14 12:13:39 +01001454 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001455 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1456 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1457 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1458 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1459 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1460 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1461 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1462 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463
Tobin Davis82f30042007-02-13 12:45:44 +01001464 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1465 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1466 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1467 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1468 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1469 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1470 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1471 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001472 {
1473 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1474 .name = "Input Source",
1475 .info = conexant_mux_enum_info,
1476 .get = conexant_mux_enum_get,
1477 .put = conexant_mux_enum_put,
1478 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001479 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001480
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 { } /* end */
1482};
1483
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001484static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001485 /* Enable retasking pins as output, initially without power amp */
1486 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489
1490 /* Disable digital (SPDIF) pins initially, but users can enable
1491 * them via a mixer switch. In the case of SPDIF-out, this initverb
1492 * payload also sets the generation to 0, output to be in "consumer"
1493 * PCM format, copyright asserted, no pre-emphasis and no validity
1494 * control.
1495 */
1496 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497
1498 /* Ensure mic1, mic2, line1 pin widgets take input from the
1499 * OUT1 sum bus when acting as an output.
1500 */
1501 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1502 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503
1504 /* Start with output sum widgets muted and their output gains at min */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507
1508 /* Unmute retasking pin widget output buffers since the default
1509 * state appears to be output. As the pin mode is changed by the
1510 * user the pin mode control will take care of enabling the pin's
1511 * input/output buffers as needed.
1512 */
1513 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516
1517 /* Mute capture amp left and right */
1518 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519
1520 /* Set ADC connection select to match default mixer setting (mic1
1521 * pin)
1522 */
1523 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524
1525 /* Mute all inputs to mixer widget (even unconnected ones) */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1534
1535 { }
1536};
1537#endif
1538
1539
1540/* initialize jack-sensing, too */
1541static int cxt5047_hp_init(struct hda_codec *codec)
1542{
1543 conexant_init(codec);
1544 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545 return 0;
1546}
1547
1548
1549enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001550 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1551 CXT5047_LAPTOP_HP, /* Some HP laptops */
1552 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553#ifdef CONFIG_SND_DEBUG
1554 CXT5047_TEST,
1555#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001556 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001557 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558};
1559
Takashi Iwaiea734962011-01-17 11:29:34 +01001560static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001561 [CXT5047_LAPTOP] = "laptop",
1562 [CXT5047_LAPTOP_HP] = "laptop-hp",
1563 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001564#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001565 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001566#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001567 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001568};
1569
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001570static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001571 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001572 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1573 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001574 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575 {}
1576};
1577
1578static int patch_cxt5047(struct hda_codec *codec)
1579{
1580 struct conexant_spec *spec;
1581 int board_config;
1582
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001583 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1584 cxt5047_models,
1585 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001586 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001587 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001588 if (board_config == CXT5047_AUTO)
1589 return patch_conexant_auto(codec);
1590
Tobin Davisc9b443d2006-11-14 12:13:39 +01001591 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1592 if (!spec)
1593 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001595 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596
1597 spec->multiout.max_channels = 2;
1598 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1599 spec->multiout.dac_nids = cxt5047_dac_nids;
1600 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1601 spec->num_adc_nids = 1;
1602 spec->adc_nids = cxt5047_adc_nids;
1603 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001604 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001605 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001606 spec->num_init_verbs = 1;
1607 spec->init_verbs[0] = cxt5047_init_verbs;
1608 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001609 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1610 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001611
1612 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001613
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614 switch (board_config) {
1615 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001616 spec->num_mixers = 2;
1617 spec->mixers[1] = cxt5047_hp_spk_mixers;
1618 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001619 break;
1620 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001621 spec->num_mixers = 2;
1622 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001623 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001624 codec->patch_ops.init = cxt5047_hp_init;
1625 break;
1626 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001627 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001628 spec->num_mixers = 2;
1629 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001630 spec->num_init_verbs = 2;
1631 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001632 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001633 break;
1634#ifdef CONFIG_SND_DEBUG
1635 case CXT5047_TEST:
1636 spec->input_mux = &cxt5047_test_capture_source;
1637 spec->mixers[0] = cxt5047_test_mixer;
1638 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001639 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001640#endif
1641 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001642 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001643
1644 switch (codec->subsystem_id >> 16) {
1645 case 0x103c:
1646 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1647 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1648 * with 0 dB offset 0x17)
1649 */
1650 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1651 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1652 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1653 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1654 (1 << AC_AMPCAP_MUTE_SHIFT));
1655 break;
1656 }
1657
Tobin Davisc9b443d2006-11-14 12:13:39 +01001658 return 0;
1659}
1660
Takashi Iwai461e2c72008-01-25 11:35:17 +01001661/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001662static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1663static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001664
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001665static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001666 { 2, NULL },
1667};
1668
1669static void cxt5051_update_speaker(struct hda_codec *codec)
1670{
1671 struct conexant_spec *spec = codec->spec;
1672 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001673 /* headphone pin */
1674 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1675 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1676 pinctl);
1677 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001678 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1679 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1680 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001681 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1682 if (spec->ideapad)
1683 snd_hda_codec_write(codec, 0x1b, 0,
1684 AC_VERB_SET_PIN_WIDGET_CONTROL,
1685 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001686}
1687
1688/* turn on/off EAPD (+ mute HP) as a master switch */
1689static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_value *ucontrol)
1691{
1692 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1693
1694 if (!cxt_eapd_put(kcontrol, ucontrol))
1695 return 0;
1696 cxt5051_update_speaker(codec);
1697 return 1;
1698}
1699
1700/* toggle input of built-in and mic jack appropriately */
1701static void cxt5051_portb_automic(struct hda_codec *codec)
1702{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001703 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001704 unsigned int present;
1705
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001706 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001707 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001708 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001709 snd_hda_codec_write(codec, 0x14, 0,
1710 AC_VERB_SET_CONNECT_SEL,
1711 present ? 0x01 : 0x00);
1712}
1713
1714/* switch the current ADC according to the jack state */
1715static void cxt5051_portc_automic(struct hda_codec *codec)
1716{
1717 struct conexant_spec *spec = codec->spec;
1718 unsigned int present;
1719 hda_nid_t new_adc;
1720
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001721 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001722 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001723 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001724 if (present)
1725 spec->cur_adc_idx = 1;
1726 else
1727 spec->cur_adc_idx = 0;
1728 new_adc = spec->adc_nids[spec->cur_adc_idx];
1729 if (spec->cur_adc && spec->cur_adc != new_adc) {
1730 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001731 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732 spec->cur_adc = new_adc;
1733 snd_hda_codec_setup_stream(codec, new_adc,
1734 spec->cur_adc_stream_tag, 0,
1735 spec->cur_adc_format);
1736 }
1737}
1738
1739/* mute internal speaker if HP is plugged */
1740static void cxt5051_hp_automute(struct hda_codec *codec)
1741{
1742 struct conexant_spec *spec = codec->spec;
1743
Takashi Iwaid56757a2009-11-18 08:00:14 +01001744 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001745 cxt5051_update_speaker(codec);
1746}
1747
1748/* unsolicited event for HP jack sensing */
1749static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1750 unsigned int res)
1751{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001752 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001753 switch (res >> 26) {
1754 case CONEXANT_HP_EVENT:
1755 cxt5051_hp_automute(codec);
1756 break;
1757 case CXT5051_PORTB_EVENT:
1758 cxt5051_portb_automic(codec);
1759 break;
1760 case CXT5051_PORTC_EVENT:
1761 cxt5051_portc_automic(codec);
1762 break;
1763 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001764 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001765}
1766
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001767static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001768 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1769 {
1770 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1771 .name = "Master Playback Switch",
1772 .info = cxt_eapd_info,
1773 .get = cxt_eapd_get,
1774 .put = cxt5051_hp_master_sw_put,
1775 .private_value = 0x1a,
1776 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001777 {}
1778};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001779
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001780static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001781 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1782 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001783 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1784 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001785 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1786 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001787 {}
1788};
1789
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001790static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001791 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1792 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001793 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1794 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001795 {}
1796};
1797
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001798static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac6002010-01-23 22:29:54 +01001799 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1800 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001801 {}
1802};
1803
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001804static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001805 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1806 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001807 {}
1808};
1809
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001810static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001811 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1812 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001813 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1814 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001815 {}
1816};
1817
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001818static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001819 /* Line in, Mic */
1820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1821 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1822 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1823 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1824 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1825 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 /* SPK */
1827 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1828 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1829 /* HP, Amp */
1830 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1831 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1832 /* DAC1 */
1833 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001834 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1836 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1837 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1838 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001839 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1841 /* EAPD */
1842 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1843 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001844 { } /* end */
1845};
1846
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001847static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001848 /* Line in, Mic */
1849 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1850 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1851 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1852 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1853 /* SPK */
1854 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1855 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1856 /* HP, Amp */
1857 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1858 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1859 /* DAC1 */
1860 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001861 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001862 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1863 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1864 /* SPDIF route: PCM */
1865 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1866 /* EAPD */
1867 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1868 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001869 { } /* end */
1870};
1871
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001872static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001873 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001875 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1876 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1877 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1878 /* SPK */
1879 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1880 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1881 /* HP, Amp */
1882 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1883 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1884 /* DAC1 */
1885 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001886 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001887 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1888 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1889 /* SPDIF route: PCM */
1890 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1891 /* EAPD */
1892 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1893 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001894 { } /* end */
1895};
1896
Takashi Iwai6953e552010-01-24 11:00:27 +01001897static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1898 unsigned int event)
1899{
1900 snd_hda_codec_write(codec, nid, 0,
1901 AC_VERB_SET_UNSOLICITED_ENABLE,
1902 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001903 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1904 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001905}
1906
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001907static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001908 /* Subwoofer */
1909 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1910 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1911 { } /* end */
1912};
1913
Takashi Iwai461e2c72008-01-25 11:35:17 +01001914/* initialize jack-sensing, too */
1915static int cxt5051_init(struct hda_codec *codec)
1916{
Takashi Iwai6953e552010-01-24 11:00:27 +01001917 struct conexant_spec *spec = codec->spec;
1918
Takashi Iwai461e2c72008-01-25 11:35:17 +01001919 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001920 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001921
1922 if (spec->auto_mic & AUTO_MIC_PORTB)
1923 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1924 if (spec->auto_mic & AUTO_MIC_PORTC)
1925 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1926
Takashi Iwai461e2c72008-01-25 11:35:17 +01001927 if (codec->patch_ops.unsol_event) {
1928 cxt5051_hp_automute(codec);
1929 cxt5051_portb_automic(codec);
1930 cxt5051_portc_automic(codec);
1931 }
1932 return 0;
1933}
1934
1935
1936enum {
1937 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1938 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001939 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001940 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001941 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001942 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001943 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001944 CXT5051_MODELS
1945};
1946
Takashi Iwaiea734962011-01-17 11:29:34 +01001947static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001948 [CXT5051_LAPTOP] = "laptop",
1949 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001950 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001951 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001952 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001953 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001954 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001955};
1956
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001957static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001958 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001959 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001960 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001961 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001962 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1963 CXT5051_LAPTOP),
1964 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001965 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 {}
1967};
1968
1969static int patch_cxt5051(struct hda_codec *codec)
1970{
1971 struct conexant_spec *spec;
1972 int board_config;
1973
Takashi Iwai6764bce2011-05-13 16:52:25 +02001974 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1975 cxt5051_models,
1976 cxt5051_cfg_tbl);
1977 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001978 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001979 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001980 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001981
Takashi Iwai461e2c72008-01-25 11:35:17 +01001982 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1983 if (!spec)
1984 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001985 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001986 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001987
1988 codec->patch_ops = conexant_patch_ops;
1989 codec->patch_ops.init = cxt5051_init;
1990
1991 spec->multiout.max_channels = 2;
1992 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1993 spec->multiout.dac_nids = cxt5051_dac_nids;
1994 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1995 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1996 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001997 spec->num_mixers = 2;
1998 spec->mixers[0] = cxt5051_capture_mixers;
1999 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002000 spec->num_init_verbs = 1;
2001 spec->init_verbs[0] = cxt5051_init_verbs;
2002 spec->spdif_route = 0;
2003 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2004 spec->channel_mode = cxt5051_modes;
2005 spec->cur_adc = 0;
2006 spec->cur_adc_idx = 0;
2007
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002008 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2009
Takashi Iwai79d7d532009-03-04 09:03:50 +01002010 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2011
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002012 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002013 switch (board_config) {
2014 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002015 spec->mixers[0] = cxt5051_hp_mixers;
2016 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002017 case CXT5051_HP_DV6736:
2018 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2019 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002020 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002021 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002022 case CXT5051_F700:
2023 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2024 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002025 spec->auto_mic = 0;
2026 break;
2027 case CXT5051_TOSHIBA:
2028 spec->mixers[0] = cxt5051_toshiba_mixers;
2029 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002030 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002031 case CXT5051_IDEAPAD:
2032 spec->init_verbs[spec->num_init_verbs++] =
2033 cxt5051_ideapad_init_verbs;
2034 spec->ideapad = 1;
2035 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002036 }
2037
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002038 if (spec->beep_amp)
2039 snd_hda_attach_beep_device(codec, spec->beep_amp);
2040
Takashi Iwai461e2c72008-01-25 11:35:17 +01002041 return 0;
2042}
2043
Daniel Drake0fb67e92009-07-16 14:46:57 +01002044/* Conexant 5066 specific */
2045
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002046static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2047static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2048static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2049static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002050
Daniel Drakedbaccc02009-11-09 15:17:24 +00002051/* OLPC's microphone port is DC coupled for use with external sensors,
2052 * therefore we use a 50% mic bias in order to center the input signal with
2053 * the DC input range of the codec. */
2054#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2055
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002056static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002057 { 2, NULL },
2058};
2059
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002060#define HP_PRESENT_PORT_A (1 << 0)
2061#define HP_PRESENT_PORT_D (1 << 1)
2062#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2063#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2064
Daniel Drake0fb67e92009-07-16 14:46:57 +01002065static void cxt5066_update_speaker(struct hda_codec *codec)
2066{
2067 struct conexant_spec *spec = codec->spec;
2068 unsigned int pinctl;
2069
John Baboval3a253442010-12-02 11:21:31 -05002070 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2071 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002072
2073 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002074 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002075 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2076 pinctl);
2077
2078 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002079 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2080 if (spec->dell_automute || spec->thinkpad) {
2081 /* Mute if Port A is connected */
2082 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002083 pinctl = 0;
2084 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002085 /* Thinkpad/Dell doesn't give pin-D status */
2086 if (!hp_port_d_present(spec))
2087 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002088 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002089 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2090 pinctl);
2091
2092 /* CLASS_D AMP */
2093 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2094 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2095 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002096}
2097
2098/* turn on/off EAPD (+ mute HP) as a master switch */
2099static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2100 struct snd_ctl_elem_value *ucontrol)
2101{
2102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2103
2104 if (!cxt_eapd_put(kcontrol, ucontrol))
2105 return 0;
2106
2107 cxt5066_update_speaker(codec);
2108 return 1;
2109}
2110
Daniel Drakec4cfe662010-01-07 13:47:04 +01002111static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2112 .num_items = 3,
2113 .items = {
2114 { "Off", PIN_IN },
2115 { "50%", PIN_VREF50 },
2116 { "80%", PIN_VREF80 },
2117 },
2118};
2119
2120static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2121{
2122 struct conexant_spec *spec = codec->spec;
2123 /* Even though port F is the DC input, the bias is controlled on port B.
2124 * we also leave that port as an active input (but unselected) in DC mode
2125 * just in case that is necessary to make the bias setting take effect. */
2126 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2127 AC_VERB_SET_PIN_WIDGET_CONTROL,
2128 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2129}
2130
Daniel Drake75f89912010-01-07 13:46:25 +01002131/* OLPC defers mic widget control until when capture is started because the
2132 * microphone LED comes on as soon as these settings are put in place. if we
2133 * did this before recording, it would give the false indication that recording
2134 * is happening when it is not. */
2135static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002136{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002137 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002138 if (!spec->recording)
2139 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002140
Daniel Drakec4cfe662010-01-07 13:47:04 +01002141 if (spec->dc_enable) {
2142 /* in DC mode we ignore presence detection and just use the jack
2143 * through our special DC port */
2144 const struct hda_verb enable_dc_mode[] = {
2145 /* disble internal mic, port C */
2146 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2147
2148 /* enable DC capture, port F */
2149 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2150 {},
2151 };
2152
2153 snd_hda_sequence_write(codec, enable_dc_mode);
2154 /* port B input disabled (and bias set) through the following call */
2155 cxt5066_set_olpc_dc_bias(codec);
2156 return;
2157 }
2158
2159 /* disable DC (port F) */
2160 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2161
Daniel Drake75f89912010-01-07 13:46:25 +01002162 /* external mic, port B */
2163 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2164 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002165
Daniel Drake75f89912010-01-07 13:46:25 +01002166 /* internal mic, port C */
2167 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2168 spec->ext_mic_present ? 0 : PIN_VREF80);
2169}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002170
Daniel Drake75f89912010-01-07 13:46:25 +01002171/* toggle input of built-in and mic jack appropriately */
2172static void cxt5066_olpc_automic(struct hda_codec *codec)
2173{
2174 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002175 unsigned int present;
2176
Daniel Drakec4cfe662010-01-07 13:47:04 +01002177 if (spec->dc_enable) /* don't do presence detection in DC mode */
2178 return;
2179
Daniel Drake75f89912010-01-07 13:46:25 +01002180 present = snd_hda_codec_read(codec, 0x1a, 0,
2181 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2182 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002183 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002184 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002185 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002186
2187 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2188 present ? 0 : 1);
2189 spec->ext_mic_present = !!present;
2190
2191 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002192}
2193
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002194/* toggle input of built-in digital mic and mic jack appropriately */
2195static void cxt5066_vostro_automic(struct hda_codec *codec)
2196{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002197 unsigned int present;
2198
2199 struct hda_verb ext_mic_present[] = {
2200 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002201 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002202
2203 /* switch to external mic input */
2204 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2205 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2206
2207 /* disable internal digital mic */
2208 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2209 {}
2210 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002211 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002212 /* enable internal mic, port C */
2213 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2214
2215 /* switch to internal mic input */
2216 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2217
2218 /* disable external mic, port B */
2219 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2220 {}
2221 };
2222
2223 present = snd_hda_jack_detect(codec, 0x1a);
2224 if (present) {
2225 snd_printdd("CXT5066: external microphone detected\n");
2226 snd_hda_sequence_write(codec, ext_mic_present);
2227 } else {
2228 snd_printdd("CXT5066: external microphone absent\n");
2229 snd_hda_sequence_write(codec, ext_mic_absent);
2230 }
2231}
2232
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002233/* toggle input of built-in digital mic and mic jack appropriately */
2234static void cxt5066_ideapad_automic(struct hda_codec *codec)
2235{
2236 unsigned int present;
2237
2238 struct hda_verb ext_mic_present[] = {
2239 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2240 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2241 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2242 {}
2243 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002244 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002245 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2246 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2247 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2248 {}
2249 };
2250
2251 present = snd_hda_jack_detect(codec, 0x1b);
2252 if (present) {
2253 snd_printdd("CXT5066: external microphone detected\n");
2254 snd_hda_sequence_write(codec, ext_mic_present);
2255 } else {
2256 snd_printdd("CXT5066: external microphone absent\n");
2257 snd_hda_sequence_write(codec, ext_mic_absent);
2258 }
2259}
2260
David Henningssona1d69062011-01-21 13:33:28 +01002261
2262/* toggle input of built-in digital mic and mic jack appropriately */
2263static void cxt5066_asus_automic(struct hda_codec *codec)
2264{
2265 unsigned int present;
2266
2267 present = snd_hda_jack_detect(codec, 0x1b);
2268 snd_printdd("CXT5066: external microphone present=%d\n", present);
2269 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2270 present ? 1 : 0);
2271}
2272
2273
David Henningsson048e78a2010-09-02 08:35:47 +02002274/* toggle input of built-in digital mic and mic jack appropriately */
2275static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2276{
2277 unsigned int present;
2278
2279 present = snd_hda_jack_detect(codec, 0x1b);
2280 snd_printdd("CXT5066: external microphone present=%d\n", present);
2281 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2282 present ? 1 : 3);
2283}
2284
2285
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002286/* toggle input of built-in digital mic and mic jack appropriately
2287 order is: external mic -> dock mic -> interal mic */
2288static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2289{
2290 unsigned int ext_present, dock_present;
2291
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002292 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002293 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2294 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2295 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2298 {}
2299 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002300 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002301 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2302 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2303 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2304 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2305 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 {}
2307 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002308 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002309 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2310 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2311 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2312 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 {}
2314 };
2315
2316 ext_present = snd_hda_jack_detect(codec, 0x1b);
2317 dock_present = snd_hda_jack_detect(codec, 0x1a);
2318 if (ext_present) {
2319 snd_printdd("CXT5066: external microphone detected\n");
2320 snd_hda_sequence_write(codec, ext_mic_present);
2321 } else if (dock_present) {
2322 snd_printdd("CXT5066: dock microphone detected\n");
2323 snd_hda_sequence_write(codec, dock_mic_present);
2324 } else {
2325 snd_printdd("CXT5066: external microphone absent\n");
2326 snd_hda_sequence_write(codec, ext_mic_absent);
2327 }
2328}
2329
Daniel Drake0fb67e92009-07-16 14:46:57 +01002330/* mute internal speaker if HP is plugged */
2331static void cxt5066_hp_automute(struct hda_codec *codec)
2332{
2333 struct conexant_spec *spec = codec->spec;
2334 unsigned int portA, portD;
2335
2336 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002337 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002338
2339 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002340 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002341
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002342 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2343 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002344 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2345 portA, portD, spec->hp_present);
2346 cxt5066_update_speaker(codec);
2347}
2348
David Henningsson02b6b5b2011-01-21 13:27:39 +01002349/* Dispatch the right mic autoswitch function */
2350static void cxt5066_automic(struct hda_codec *codec)
2351{
2352 struct conexant_spec *spec = codec->spec;
2353
2354 if (spec->dell_vostro)
2355 cxt5066_vostro_automic(codec);
2356 else if (spec->ideapad)
2357 cxt5066_ideapad_automic(codec);
2358 else if (spec->thinkpad)
2359 cxt5066_thinkpad_automic(codec);
2360 else if (spec->hp_laptop)
2361 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002362 else if (spec->asus)
2363 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002364}
2365
Daniel Drake0fb67e92009-07-16 14:46:57 +01002366/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002367static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002368{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002369 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002370 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2371 switch (res >> 26) {
2372 case CONEXANT_HP_EVENT:
2373 cxt5066_hp_automute(codec);
2374 break;
2375 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002376 /* ignore mic events in DC mode; we're always using the jack */
2377 if (!spec->dc_enable)
2378 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002379 break;
2380 }
2381}
2382
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002383/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002384static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002385{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002386 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002387 switch (res >> 26) {
2388 case CONEXANT_HP_EVENT:
2389 cxt5066_hp_automute(codec);
2390 break;
2391 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002392 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002393 break;
2394 }
2395}
2396
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002397
Daniel Drake0fb67e92009-07-16 14:46:57 +01002398static const struct hda_input_mux cxt5066_analog_mic_boost = {
2399 .num_items = 5,
2400 .items = {
2401 { "0dB", 0 },
2402 { "10dB", 1 },
2403 { "20dB", 2 },
2404 { "30dB", 3 },
2405 { "40dB", 4 },
2406 },
2407};
2408
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002409static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002410{
2411 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002412 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002413 AC_VERB_SET_AMP_GAIN_MUTE,
2414 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2415 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002416 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002417 /* adjust the internal mic as well...it is not through 0x17 */
2418 snd_hda_codec_write_cache(codec, 0x23, 0,
2419 AC_VERB_SET_AMP_GAIN_MUTE,
2420 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2421 cxt5066_analog_mic_boost.
2422 items[spec->mic_boost].index);
2423 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002424}
2425
Daniel Drake0fb67e92009-07-16 14:46:57 +01002426static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2427 struct snd_ctl_elem_info *uinfo)
2428{
2429 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2430}
2431
2432static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2433 struct snd_ctl_elem_value *ucontrol)
2434{
2435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002436 struct conexant_spec *spec = codec->spec;
2437 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002438 return 0;
2439}
2440
2441static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2442 struct snd_ctl_elem_value *ucontrol)
2443{
2444 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002445 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002446 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2447 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002448 idx = ucontrol->value.enumerated.item[0];
2449 if (idx >= imux->num_items)
2450 idx = imux->num_items - 1;
2451
Daniel Drakec4cfe662010-01-07 13:47:04 +01002452 spec->mic_boost = idx;
2453 if (!spec->dc_enable)
2454 cxt5066_set_mic_boost(codec);
2455 return 1;
2456}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002457
Daniel Drakec4cfe662010-01-07 13:47:04 +01002458static void cxt5066_enable_dc(struct hda_codec *codec)
2459{
2460 const struct hda_verb enable_dc_mode[] = {
2461 /* disable gain */
2462 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2463
2464 /* switch to DC input */
2465 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2466 {}
2467 };
2468
2469 /* configure as input source */
2470 snd_hda_sequence_write(codec, enable_dc_mode);
2471 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2472}
2473
2474static void cxt5066_disable_dc(struct hda_codec *codec)
2475{
2476 /* reconfigure input source */
2477 cxt5066_set_mic_boost(codec);
2478 /* automic also selects the right mic if we're recording */
2479 cxt5066_olpc_automic(codec);
2480}
2481
2482static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2483 struct snd_ctl_elem_value *ucontrol)
2484{
2485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2486 struct conexant_spec *spec = codec->spec;
2487 ucontrol->value.integer.value[0] = spec->dc_enable;
2488 return 0;
2489}
2490
2491static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2492 struct snd_ctl_elem_value *ucontrol)
2493{
2494 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2495 struct conexant_spec *spec = codec->spec;
2496 int dc_enable = !!ucontrol->value.integer.value[0];
2497
2498 if (dc_enable == spec->dc_enable)
2499 return 0;
2500
2501 spec->dc_enable = dc_enable;
2502 if (dc_enable)
2503 cxt5066_enable_dc(codec);
2504 else
2505 cxt5066_disable_dc(codec);
2506
2507 return 1;
2508}
2509
2510static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2511 struct snd_ctl_elem_info *uinfo)
2512{
2513 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2514}
2515
2516static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2517 struct snd_ctl_elem_value *ucontrol)
2518{
2519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2520 struct conexant_spec *spec = codec->spec;
2521 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2522 return 0;
2523}
2524
2525static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2526 struct snd_ctl_elem_value *ucontrol)
2527{
2528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2529 struct conexant_spec *spec = codec->spec;
2530 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2531 unsigned int idx;
2532
2533 idx = ucontrol->value.enumerated.item[0];
2534 if (idx >= imux->num_items)
2535 idx = imux->num_items - 1;
2536
2537 spec->dc_input_bias = idx;
2538 if (spec->dc_enable)
2539 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002540 return 1;
2541}
2542
Daniel Drake75f89912010-01-07 13:46:25 +01002543static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2544{
2545 struct conexant_spec *spec = codec->spec;
2546 /* mark as recording and configure the microphone widget so that the
2547 * recording LED comes on. */
2548 spec->recording = 1;
2549 cxt5066_olpc_select_mic(codec);
2550}
2551
2552static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2553{
2554 struct conexant_spec *spec = codec->spec;
2555 const struct hda_verb disable_mics[] = {
2556 /* disable external mic, port B */
2557 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2558
2559 /* disble internal mic, port C */
2560 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002561
2562 /* disable DC capture, port F */
2563 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002564 {},
2565 };
2566
2567 snd_hda_sequence_write(codec, disable_mics);
2568 spec->recording = 0;
2569}
2570
Andy Robinsonf6a24912011-01-24 10:12:37 -05002571static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002572 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002573 int num_pins)
2574{
2575 struct conexant_spec *spec = codec->spec;
2576 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2577 int i;
2578
2579 for (i = 0; i < num_pins; i++, dig_pins++) {
2580 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2581 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2582 continue;
2583 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2584 continue;
2585 if (spec->slave_dig_outs[0])
2586 nid_loc++;
2587 else
2588 nid_loc = spec->slave_dig_outs;
2589 }
2590}
2591
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002592static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002593 .num_items = 4,
2594 .items = {
2595 { "Mic B", 0 },
2596 { "Mic C", 1 },
2597 { "Mic E", 2 },
2598 { "Mic F", 3 },
2599 },
2600};
2601
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002602static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002603 .ops = &snd_hda_bind_vol,
2604 .values = {
2605 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2606 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2607 0
2608 },
2609};
2610
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002611static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002612 .ops = &snd_hda_bind_sw,
2613 .values = {
2614 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2615 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2616 0
2617 },
2618};
2619
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002620static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002621 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2622 {}
2623};
2624
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002625static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002626 {
2627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2628 .name = "Master Playback Volume",
2629 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2630 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2631 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002632 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002633 .info = snd_hda_mixer_amp_volume_info,
2634 .get = snd_hda_mixer_amp_volume_get,
2635 .put = snd_hda_mixer_amp_volume_put,
2636 .tlv = { .c = snd_hda_mixer_amp_tlv },
2637 /* offset by 28 volume steps to limit minimum gain to -46dB */
2638 .private_value =
2639 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2640 },
2641 {}
2642};
2643
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002644static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002645 {
2646 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2647 .name = "DC Mode Enable Switch",
2648 .info = snd_ctl_boolean_mono_info,
2649 .get = cxt5066_olpc_dc_get,
2650 .put = cxt5066_olpc_dc_put,
2651 },
2652 {
2653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2654 .name = "DC Input Bias Enum",
2655 .info = cxt5066_olpc_dc_bias_enum_info,
2656 .get = cxt5066_olpc_dc_bias_enum_get,
2657 .put = cxt5066_olpc_dc_bias_enum_put,
2658 },
2659 {}
2660};
2661
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002662static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002663 {
2664 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2665 .name = "Master Playback Switch",
2666 .info = cxt_eapd_info,
2667 .get = cxt_eapd_get,
2668 .put = cxt5066_hp_master_sw_put,
2669 .private_value = 0x1d,
2670 },
2671
2672 {
2673 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002674 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002675 .info = cxt5066_mic_boost_mux_enum_info,
2676 .get = cxt5066_mic_boost_mux_enum_get,
2677 .put = cxt5066_mic_boost_mux_enum_put,
2678 },
2679
2680 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2681 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2682 {}
2683};
2684
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002685static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002686 {
2687 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002688 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002689 .info = cxt5066_mic_boost_mux_enum_info,
2690 .get = cxt5066_mic_boost_mux_enum_get,
2691 .put = cxt5066_mic_boost_mux_enum_put,
2692 .private_value = 0x23 | 0x100,
2693 },
2694 {}
2695};
2696
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002697static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002698 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2699 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2700 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2701 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2702
2703 /* Speakers */
2704 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2705 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2706
2707 /* HP, Amp */
2708 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2709 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2710
2711 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2712 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2713
2714 /* DAC1 */
2715 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2716
2717 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2723
2724 /* no digital microphone support yet */
2725 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2726
2727 /* Audio input selector */
2728 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2729
2730 /* SPDIF route: PCM */
2731 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2732 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2733
2734 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2735 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2736
2737 /* EAPD */
2738 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2739
2740 /* not handling these yet */
2741 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2742 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2745 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2746 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2747 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2748 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2749 { } /* end */
2750};
2751
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002752static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002753 /* Port A: headphones */
2754 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2755 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2756
2757 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002758 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002759
2760 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002761 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002762
2763 /* Port D: unused */
2764 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2765
2766 /* Port E: unused, but has primary EAPD */
2767 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2768 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2769
Daniel Drakec4cfe662010-01-07 13:47:04 +01002770 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002771 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2772
2773 /* Port G: internal speakers */
2774 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2775 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2776
2777 /* DAC1 */
2778 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2779
2780 /* DAC2: unused */
2781 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2782
2783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2784 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2785 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2787 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2789 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2791 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2792 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2793 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2794 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2795
2796 /* Disable digital microphone port */
2797 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2798
2799 /* Audio input selectors */
2800 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2801 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2802
2803 /* Disable SPDIF */
2804 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2805 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2806
2807 /* enable unsolicited events for Port A and B */
2808 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2809 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2810 { } /* end */
2811};
2812
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002813static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002814 /* Port A: headphones */
2815 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2816 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2817
2818 /* Port B: external microphone */
2819 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2820
2821 /* Port C: unused */
2822 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2823
2824 /* Port D: unused */
2825 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826
2827 /* Port E: unused, but has primary EAPD */
2828 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2829 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2830
2831 /* Port F: unused */
2832 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2833
2834 /* Port G: internal speakers */
2835 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2836 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2837
2838 /* DAC1 */
2839 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2840
2841 /* DAC2: unused */
2842 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2843
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2845 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2847 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2849 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2850 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2853 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2854 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2855 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2856
2857 /* Digital microphone port */
2858 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2859
2860 /* Audio input selectors */
2861 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2862 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2863
2864 /* Disable SPDIF */
2865 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867
2868 /* enable unsolicited events for Port A and B */
2869 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2870 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2871 { } /* end */
2872};
2873
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002874static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002875 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2876 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2877 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2878 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2879
2880 /* Speakers */
2881 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2882 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2883
2884 /* HP, Amp */
2885 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2886 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2887
2888 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2889 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2890
2891 /* DAC1 */
2892 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2893
2894 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2895 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2897 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2899 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2900 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2901
2902 /* Audio input selector */
2903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2904 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2905
2906 /* SPDIF route: PCM */
2907 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2908 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2909
2910 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2911 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2912
2913 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002914 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002915
2916 /* EAPD */
2917 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2918
2919 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2920 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2921 { } /* end */
2922};
2923
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002924static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002925 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2926 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2927
2928 /* Port G: internal speakers */
2929 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2930 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2931
2932 /* Port A: HP, Amp */
2933 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2934 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2935
2936 /* Port B: Mic Dock */
2937 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2938
2939 /* Port C: Mic */
2940 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2941
2942 /* Port D: HP Dock, Amp */
2943 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2944 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2945
2946 /* DAC1 */
2947 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2948
2949 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2950 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2952 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2953 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2954 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2955 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2956
2957 /* Audio input selector */
2958 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2959 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2960
2961 /* SPDIF route: PCM */
2962 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2963 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2964
2965 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2966 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2967
2968 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002969 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002970
2971 /* EAPD */
2972 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2973
2974 /* enable unsolicited events for Port A, B, C and D */
2975 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2976 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2977 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2978 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2979 { } /* end */
2980};
2981
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002982static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002983 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2984 { } /* end */
2985};
2986
David Henningsson048e78a2010-09-02 08:35:47 +02002987
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002988static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002989 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2990 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2991 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2992 { } /* end */
2993};
2994
Daniel Drake0fb67e92009-07-16 14:46:57 +01002995/* initialize jack-sensing, too */
2996static int cxt5066_init(struct hda_codec *codec)
2997{
2998 snd_printdd("CXT5066: init\n");
2999 conexant_init(codec);
3000 if (codec->patch_ops.unsol_event) {
3001 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003002 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003003 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003004 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003005 return 0;
3006}
3007
Daniel Drake75f89912010-01-07 13:46:25 +01003008static int cxt5066_olpc_init(struct hda_codec *codec)
3009{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003010 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003011 snd_printdd("CXT5066: init\n");
3012 conexant_init(codec);
3013 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003014 if (!spec->dc_enable) {
3015 cxt5066_set_mic_boost(codec);
3016 cxt5066_olpc_automic(codec);
3017 } else {
3018 cxt5066_enable_dc(codec);
3019 }
Daniel Drake75f89912010-01-07 13:46:25 +01003020 return 0;
3021}
3022
Daniel Drake0fb67e92009-07-16 14:46:57 +01003023enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003024 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003025 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3026 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003027 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003028 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003029 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003030 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003031 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003032 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003033 CXT5066_MODELS
3034};
3035
Takashi Iwaiea734962011-01-17 11:29:34 +01003036static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003037 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003038 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3039 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003040 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003041 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003042 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003043 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003044 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003045 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003046};
3047
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003048static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02003049 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003050 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003051 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003052 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003053 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003054 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003055 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd224c2011-02-23 13:15:56 +01003056 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3057 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003058 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003059 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003060 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003061 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003062 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003063 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003064 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003065 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3066 CXT5066_LAPTOP),
3067 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003068 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003069 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003070 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003071 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
Daniel Suchyca201c02011-10-18 11:09:44 +02003072 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
David Henningsson84012652011-03-31 09:36:19 +02003073 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003074 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003075 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003076 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003077 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
David Henningsson22f21d52011-01-07 07:53:39 +01003078 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003079 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003080 {}
3081};
3082
3083static int patch_cxt5066(struct hda_codec *codec)
3084{
3085 struct conexant_spec *spec;
3086 int board_config;
3087
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003088 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3089 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003090 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003091 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003092 if (board_config == CXT5066_AUTO)
3093 return patch_conexant_auto(codec);
3094
Daniel Drake0fb67e92009-07-16 14:46:57 +01003095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3096 if (!spec)
3097 return -ENOMEM;
3098 codec->spec = spec;
3099
3100 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003101 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003102
3103 spec->dell_automute = 0;
3104 spec->multiout.max_channels = 2;
3105 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3106 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003107 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3108 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003109 spec->num_adc_nids = 1;
3110 spec->adc_nids = cxt5066_adc_nids;
3111 spec->capsrc_nids = cxt5066_capsrc_nids;
3112 spec->input_mux = &cxt5066_capture_source;
3113
3114 spec->port_d_mode = PIN_HP;
3115
3116 spec->num_init_verbs = 1;
3117 spec->init_verbs[0] = cxt5066_init_verbs;
3118 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3119 spec->channel_mode = cxt5066_modes;
3120 spec->cur_adc = 0;
3121 spec->cur_adc_idx = 0;
3122
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003123 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3124
Daniel Drake0fb67e92009-07-16 14:46:57 +01003125 switch (board_config) {
3126 default:
3127 case CXT5066_LAPTOP:
3128 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3129 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3130 break;
3131 case CXT5066_DELL_LAPTOP:
3132 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3133 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3134
3135 spec->port_d_mode = PIN_OUT;
3136 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3137 spec->num_init_verbs++;
3138 spec->dell_automute = 1;
3139 break;
David Henningssona1d69062011-01-21 13:33:28 +01003140 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003141 case CXT5066_HP_LAPTOP:
3142 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003143 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003144 spec->init_verbs[spec->num_init_verbs] =
3145 cxt5066_init_verbs_hp_laptop;
3146 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003147 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3148 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003149 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3150 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3151 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003152 if (board_config == CXT5066_HP_LAPTOP)
3153 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003154 /* input source automatically selected */
3155 spec->input_mux = NULL;
3156 spec->port_d_mode = 0;
3157 spec->mic_boost = 3; /* default 30dB gain */
3158 break;
3159
Daniel Drake0fb67e92009-07-16 14:46:57 +01003160 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003161 codec->patch_ops.init = cxt5066_olpc_init;
3162 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003163 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3164 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003165 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003166 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3167 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003168 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003169
3170 /* no S/PDIF out */
3171 spec->multiout.dig_out_nid = 0;
3172
3173 /* input source automatically selected */
3174 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003175
3176 /* our capture hooks which allow us to turn on the microphone LED
3177 * at the right time */
3178 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3179 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003180 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003181 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003182 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003183 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003184 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3185 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3186 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003187 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003188 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003189 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003190 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003191
3192 /* no S/PDIF out */
3193 spec->multiout.dig_out_nid = 0;
3194
3195 /* input source automatically selected */
3196 spec->input_mux = NULL;
3197 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003198 case CXT5066_IDEAPAD:
3199 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003200 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003201 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3202 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3203 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3204 spec->port_d_mode = 0;
3205 spec->ideapad = 1;
3206 spec->mic_boost = 2; /* default 20dB gain */
3207
3208 /* no S/PDIF out */
3209 spec->multiout.dig_out_nid = 0;
3210
3211 /* input source automatically selected */
3212 spec->input_mux = NULL;
3213 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003214 case CXT5066_THINKPAD:
3215 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003216 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003217 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3218 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3219 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3220 spec->thinkpad = 1;
3221 spec->port_d_mode = PIN_OUT;
3222 spec->mic_boost = 2; /* default 20dB gain */
3223
3224 /* no S/PDIF out */
3225 spec->multiout.dig_out_nid = 0;
3226
3227 /* input source automatically selected */
3228 spec->input_mux = NULL;
3229 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003230 }
3231
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003232 if (spec->beep_amp)
3233 snd_hda_attach_beep_device(codec, spec->beep_amp);
3234
Daniel Drake0fb67e92009-07-16 14:46:57 +01003235 return 0;
3236}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003237
3238/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003239 * Automatic parser for CX20641 & co
3240 */
3241
Takashi Iwai6764bce2011-05-13 16:52:25 +02003242static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3243 struct hda_codec *codec,
3244 unsigned int stream_tag,
3245 unsigned int format,
3246 struct snd_pcm_substream *substream)
3247{
3248 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003249 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003250 if (spec->adc_switching) {
3251 spec->cur_adc = adc;
3252 spec->cur_adc_stream_tag = stream_tag;
3253 spec->cur_adc_format = format;
3254 }
3255 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3256 return 0;
3257}
3258
3259static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3260 struct hda_codec *codec,
3261 struct snd_pcm_substream *substream)
3262{
3263 struct conexant_spec *spec = codec->spec;
3264 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3265 spec->cur_adc = 0;
3266 return 0;
3267}
3268
3269static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3270 .substreams = 1,
3271 .channels_min = 2,
3272 .channels_max = 2,
3273 .nid = 0, /* fill later */
3274 .ops = {
3275 .prepare = cx_auto_capture_pcm_prepare,
3276 .cleanup = cx_auto_capture_pcm_cleanup
3277 },
3278};
3279
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003280static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003281
Takashi Iwai8d087c72011-06-28 12:45:47 +02003282#define get_connection_index(codec, mux, nid)\
3283 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003284
3285/* get an unassigned DAC from the given list.
3286 * Return the nid if found and reduce the DAC list, or return zero if
3287 * not found
3288 */
3289static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3290 hda_nid_t *dacs, int *num_dacs)
3291{
3292 int i, nums = *num_dacs;
3293 hda_nid_t ret = 0;
3294
3295 for (i = 0; i < nums; i++) {
3296 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3297 ret = dacs[i];
3298 break;
3299 }
3300 }
3301 if (!ret)
3302 return 0;
3303 if (--nums > 0)
3304 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3305 *num_dacs = nums;
3306 return ret;
3307}
3308
3309#define MAX_AUTO_DACS 5
3310
Takashi Iwai1f015f52011-08-23 14:57:08 +02003311#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3312
Takashi Iwaif2e57312010-09-15 10:07:08 +02003313/* fill analog DAC list from the widget tree */
3314static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3315{
3316 hda_nid_t nid, end_nid;
3317 int nums = 0;
3318
3319 end_nid = codec->start_nid + codec->num_nodes;
3320 for (nid = codec->start_nid; nid < end_nid; nid++) {
3321 unsigned int wcaps = get_wcaps(codec, nid);
3322 unsigned int type = get_wcaps_type(wcaps);
3323 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3324 dacs[nums++] = nid;
3325 if (nums >= MAX_AUTO_DACS)
3326 break;
3327 }
3328 }
3329 return nums;
3330}
3331
3332/* fill pin_dac_pair list from the pin and dac list */
3333static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3334 int num_pins, hda_nid_t *dacs, int *rest,
David Henningsson468c5452011-08-25 13:16:02 +02003335 struct pin_dac_pair *filled, int nums,
3336 int type)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003337{
David Henningsson468c5452011-08-25 13:16:02 +02003338 int i, start = nums;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003339
David Henningsson468c5452011-08-25 13:16:02 +02003340 for (i = 0; i < num_pins; i++, nums++) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003341 filled[nums].pin = pins[i];
3342 filled[nums].type = type;
3343 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
David Henningsson468c5452011-08-25 13:16:02 +02003344 if (filled[nums].dac)
3345 continue;
3346 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3347 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3348 continue;
3349 }
3350 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
Takashi Iwai1f015f52011-08-23 14:57:08 +02003351 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
David Henningsson468c5452011-08-25 13:16:02 +02003352 continue;
3353 }
3354 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003355 }
3356 return nums;
3357}
3358
3359/* parse analog output paths */
3360static void cx_auto_parse_output(struct hda_codec *codec)
3361{
3362 struct conexant_spec *spec = codec->spec;
3363 struct auto_pin_cfg *cfg = &spec->autocfg;
3364 hda_nid_t dacs[MAX_AUTO_DACS];
3365 int i, j, nums, rest;
3366
3367 rest = fill_cx_auto_dacs(codec, dacs);
3368 /* parse all analog output pins */
3369 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
David Henningsson468c5452011-08-25 13:16:02 +02003370 dacs, &rest, spec->dac_info, 0,
3371 AUTO_PIN_LINE_OUT);
3372 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3373 dacs, &rest, spec->dac_info, nums,
3374 AUTO_PIN_HP_OUT);
3375 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3376 dacs, &rest, spec->dac_info, nums,
3377 AUTO_PIN_SPEAKER_OUT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003378 spec->dac_info_filled = nums;
3379 /* fill multiout struct */
3380 for (i = 0; i < nums; i++) {
3381 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwai1f015f52011-08-23 14:57:08 +02003382 if (!dac || (dac & DAC_SLAVE_FLAG))
Takashi Iwaif2e57312010-09-15 10:07:08 +02003383 continue;
3384 switch (spec->dac_info[i].type) {
3385 case AUTO_PIN_LINE_OUT:
3386 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3387 spec->multiout.num_dacs++;
3388 break;
3389 case AUTO_PIN_HP_OUT:
3390 case AUTO_PIN_SPEAKER_OUT:
3391 if (!spec->multiout.hp_nid) {
3392 spec->multiout.hp_nid = dac;
3393 break;
3394 }
3395 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3396 if (!spec->multiout.extra_out_nid[j]) {
3397 spec->multiout.extra_out_nid[j] = dac;
3398 break;
3399 }
3400 break;
3401 }
3402 }
3403 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003404 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003405
Takashi Iwai03697e22011-05-17 09:53:31 +02003406 for (i = 0; i < cfg->hp_outs; i++) {
3407 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3408 spec->auto_mute = 1;
3409 break;
3410 }
3411 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003412 if (spec->auto_mute &&
3413 cfg->line_out_pins[0] &&
3414 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003415 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3416 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3417 for (i = 0; i < cfg->line_outs; i++) {
3418 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3419 spec->detect_line = 1;
3420 break;
3421 }
3422 }
3423 spec->automute_lines = spec->detect_line;
3424 }
3425
Takashi Iwaif2e57312010-09-15 10:07:08 +02003426 spec->vmaster_nid = spec->private_dac_nids[0];
3427}
3428
Takashi Iwaida339862011-05-13 16:24:15 +02003429static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3430 hda_nid_t *pins, bool on);
3431
Takashi Iwai03697e22011-05-17 09:53:31 +02003432static void do_automute(struct hda_codec *codec, int num_pins,
3433 hda_nid_t *pins, bool on)
3434{
Takashi Iwai254f2962011-10-14 15:22:34 +02003435 struct conexant_spec *spec = codec->spec;
Takashi Iwai03697e22011-05-17 09:53:31 +02003436 int i;
3437 for (i = 0; i < num_pins; i++)
3438 snd_hda_codec_write(codec, pins[i], 0,
3439 AC_VERB_SET_PIN_WIDGET_CONTROL,
3440 on ? PIN_OUT : 0);
Takashi Iwai254f2962011-10-14 15:22:34 +02003441 if (spec->pin_eapd_ctrls)
3442 cx_auto_turn_eapd(codec, num_pins, pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003443}
3444
3445static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3446{
3447 int i, present = 0;
3448
3449 for (i = 0; i < num_pins; i++) {
3450 hda_nid_t nid = pins[i];
3451 if (!nid || !is_jack_detectable(codec, nid))
3452 break;
3453 snd_hda_input_jack_report(codec, nid);
3454 present |= snd_hda_jack_detect(codec, nid);
3455 }
3456 return present;
3457}
3458
Takashi Iwaif2e57312010-09-15 10:07:08 +02003459/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003460static void cx_auto_update_speakers(struct hda_codec *codec)
3461{
3462 struct conexant_spec *spec = codec->spec;
3463 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003464 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003465
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003466 /* turn on HP EAPD when HP jacks are present */
Takashi Iwai254f2962011-10-14 15:22:34 +02003467 if (spec->pin_eapd_ctrls) {
3468 if (spec->auto_mute)
3469 on = spec->hp_present;
3470 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3471 }
3472
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003473 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3474 if (spec->auto_mute)
3475 on = !(spec->hp_present ||
3476 (spec->detect_line && spec->line_present));
3477 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003478
3479 /* toggle line-out mutes if needed, too */
3480 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3481 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3482 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3483 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003484 if (spec->auto_mute) {
3485 /* mute LO in auto-mode when HP jack is present */
3486 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3487 spec->automute_lines)
3488 on = !spec->hp_present;
3489 else
3490 on = 1;
3491 }
3492 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003493}
3494
Takashi Iwaif2e57312010-09-15 10:07:08 +02003495static void cx_auto_hp_automute(struct hda_codec *codec)
3496{
3497 struct conexant_spec *spec = codec->spec;
3498 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003499
3500 if (!spec->auto_mute)
3501 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003502 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3503 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003504}
3505
Takashi Iwai03697e22011-05-17 09:53:31 +02003506static void cx_auto_line_automute(struct hda_codec *codec)
3507{
3508 struct conexant_spec *spec = codec->spec;
3509 struct auto_pin_cfg *cfg = &spec->autocfg;
3510
3511 if (!spec->auto_mute || !spec->detect_line)
3512 return;
3513 spec->line_present = detect_jacks(codec, cfg->line_outs,
3514 cfg->line_out_pins);
3515 cx_auto_update_speakers(codec);
3516}
3517
3518static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3519 struct snd_ctl_elem_info *uinfo)
3520{
3521 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3522 struct conexant_spec *spec = codec->spec;
3523 static const char * const texts2[] = {
3524 "Disabled", "Enabled"
3525 };
3526 static const char * const texts3[] = {
3527 "Disabled", "Speaker Only", "Line-Out+Speaker"
3528 };
3529 const char * const *texts;
3530
3531 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3532 uinfo->count = 1;
3533 if (spec->automute_hp_lo) {
3534 uinfo->value.enumerated.items = 3;
3535 texts = texts3;
3536 } else {
3537 uinfo->value.enumerated.items = 2;
3538 texts = texts2;
3539 }
3540 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3541 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3542 strcpy(uinfo->value.enumerated.name,
3543 texts[uinfo->value.enumerated.item]);
3544 return 0;
3545}
3546
3547static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3548 struct snd_ctl_elem_value *ucontrol)
3549{
3550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3551 struct conexant_spec *spec = codec->spec;
3552 unsigned int val;
3553 if (!spec->auto_mute)
3554 val = 0;
3555 else if (!spec->automute_lines)
3556 val = 1;
3557 else
3558 val = 2;
3559 ucontrol->value.enumerated.item[0] = val;
3560 return 0;
3561}
3562
3563static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3564 struct snd_ctl_elem_value *ucontrol)
3565{
3566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3567 struct conexant_spec *spec = codec->spec;
3568
3569 switch (ucontrol->value.enumerated.item[0]) {
3570 case 0:
3571 if (!spec->auto_mute)
3572 return 0;
3573 spec->auto_mute = 0;
3574 break;
3575 case 1:
3576 if (spec->auto_mute && !spec->automute_lines)
3577 return 0;
3578 spec->auto_mute = 1;
3579 spec->automute_lines = 0;
3580 break;
3581 case 2:
3582 if (!spec->automute_hp_lo)
3583 return -EINVAL;
3584 if (spec->auto_mute && spec->automute_lines)
3585 return 0;
3586 spec->auto_mute = 1;
3587 spec->automute_lines = 1;
3588 break;
3589 default:
3590 return -EINVAL;
3591 }
3592 cx_auto_update_speakers(codec);
3593 return 1;
3594}
3595
3596static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3597 {
3598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3599 .name = "Auto-Mute Mode",
3600 .info = cx_automute_mode_info,
3601 .get = cx_automute_mode_get,
3602 .put = cx_automute_mode_put,
3603 },
3604 { }
3605};
3606
Takashi Iwai6764bce2011-05-13 16:52:25 +02003607static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3608 struct snd_ctl_elem_info *uinfo)
3609{
3610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3611 struct conexant_spec *spec = codec->spec;
3612
3613 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3614}
3615
3616static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3617 struct snd_ctl_elem_value *ucontrol)
3618{
3619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3620 struct conexant_spec *spec = codec->spec;
3621
3622 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3623 return 0;
3624}
3625
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003626/* look for the route the given pin from mux and return the index;
3627 * if do_select is set, actually select the route.
3628 */
3629static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003630 hda_nid_t pin, hda_nid_t *srcp,
3631 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003632{
3633 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3634 int i, nums;
3635
Takashi Iwaicf27f292011-05-16 11:33:02 +02003636 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3637 case AC_WID_AUD_IN:
3638 case AC_WID_AUD_SEL:
3639 case AC_WID_AUD_MIX:
3640 break;
3641 default:
3642 return -1;
3643 }
3644
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003645 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3646 for (i = 0; i < nums; i++)
3647 if (conn[i] == pin) {
3648 if (do_select)
3649 snd_hda_codec_write(codec, mux, 0,
3650 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003651 if (srcp)
3652 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003653 return i;
3654 }
3655 depth++;
3656 if (depth == 2)
3657 return -1;
3658 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003659 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003660 do_select, depth);
3661 if (ret >= 0) {
3662 if (do_select)
3663 snd_hda_codec_write(codec, mux, 0,
3664 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003665 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003666 }
3667 }
3668 return -1;
3669}
3670
3671static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3672 hda_nid_t pin)
3673{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003674 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003675}
3676
3677static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3678 hda_nid_t pin)
3679{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003680 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003681}
3682
Takashi Iwai6764bce2011-05-13 16:52:25 +02003683static int cx_auto_mux_enum_update(struct hda_codec *codec,
3684 const struct hda_input_mux *imux,
3685 unsigned int idx)
3686{
3687 struct conexant_spec *spec = codec->spec;
3688 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003689 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003690
3691 if (!imux->num_items)
3692 return 0;
3693 if (idx >= imux->num_items)
3694 idx = imux->num_items - 1;
3695 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003696 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003697 adc = spec->imux_info[idx].adc;
3698 select_input_connection(codec, spec->imux_info[idx].adc,
3699 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003700 if (spec->cur_adc && spec->cur_adc != adc) {
3701 /* stream is running, let's swap the current ADC */
3702 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3703 spec->cur_adc = adc;
3704 snd_hda_codec_setup_stream(codec, adc,
3705 spec->cur_adc_stream_tag, 0,
3706 spec->cur_adc_format);
3707 }
3708 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003709 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003710}
3711
3712static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3713 struct snd_ctl_elem_value *ucontrol)
3714{
3715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3716 struct conexant_spec *spec = codec->spec;
3717
3718 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3719 ucontrol->value.enumerated.item[0]);
3720}
3721
3722static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3723 {
3724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3725 .name = "Capture Source",
3726 .info = cx_auto_mux_enum_info,
3727 .get = cx_auto_mux_enum_get,
3728 .put = cx_auto_mux_enum_put
3729 },
3730 {}
3731};
3732
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003733static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3734{
3735 struct conexant_spec *spec = codec->spec;
3736 if (idx < 0)
3737 return false;
3738 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3739 return false;
3740 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3741 return true;
3742}
3743
Takashi Iwaif2e57312010-09-15 10:07:08 +02003744/* automatic switch internal and external mic */
3745static void cx_auto_automic(struct hda_codec *codec)
3746{
3747 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003748
3749 if (!spec->auto_mic)
3750 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003751 if (!select_automic(codec, spec->auto_mic_ext, true))
3752 if (!select_automic(codec, spec->auto_mic_dock, true))
3753 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003754}
3755
3756static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3757{
3758 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3759 switch (res >> 26) {
3760 case CONEXANT_HP_EVENT:
3761 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003762 break;
3763 case CONEXANT_LINE_EVENT:
3764 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003765 break;
3766 case CONEXANT_MIC_EVENT:
3767 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003768 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003769 break;
3770 }
3771}
3772
Takashi Iwaif2e57312010-09-15 10:07:08 +02003773/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003774 * auto-mic is enabled only when one int-mic and one ext- and/or
3775 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003776 */
3777static void cx_auto_check_auto_mic(struct hda_codec *codec)
3778{
3779 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003780 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3781 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003782
Takashi Iwai506a4192011-05-23 20:07:15 +02003783 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003784 pset[i] = -1;
3785 for (i = 0; i < spec->private_imux.num_items; i++) {
3786 hda_nid_t pin = spec->imux_info[i].pin;
3787 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003788 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003789 attr = snd_hda_get_input_pin_attr(def_conf);
3790 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003791 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003792 if (attr > INPUT_PIN_ATTR_NORMAL)
3793 attr = INPUT_PIN_ATTR_NORMAL;
3794 if (attr != INPUT_PIN_ATTR_INT &&
3795 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003796 return; /* non-detectable pin */
3797 type = get_defcfg_device(def_conf);
3798 if (type != AC_JACK_MIC_IN &&
3799 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3800 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003801 if (pset[attr] >= 0)
3802 return; /* already occupied */
3803 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003804 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003805 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3806 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3807 return; /* no input to switch*/
3808 spec->auto_mic = 1;
3809 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3810 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3811 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003812}
3813
3814static void cx_auto_parse_input(struct hda_codec *codec)
3815{
3816 struct conexant_spec *spec = codec->spec;
3817 struct auto_pin_cfg *cfg = &spec->autocfg;
3818 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003819 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003820
3821 imux = &spec->private_imux;
3822 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003823 for (j = 0; j < spec->num_adc_nids; j++) {
3824 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003825 int idx = get_input_connection(codec, adc,
3826 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003827 if (idx >= 0) {
3828 const char *label;
3829 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003830 spec->imux_info[imux->num_items].index = i;
3831 spec->imux_info[imux->num_items].boost = 0;
3832 spec->imux_info[imux->num_items].adc = adc;
3833 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003834 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003835 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003836 break;
3837 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003838 }
3839 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003840 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003841 cx_auto_check_auto_mic(codec);
Takashi Iwai76755352011-08-24 10:53:10 +02003842 if (imux->num_items > 1) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003843 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003844 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003845 spec->adc_switching = 1;
3846 break;
3847 }
3848 }
3849 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003850}
3851
3852/* get digital-input audio widget corresponding to the given pin */
3853static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3854{
3855 hda_nid_t nid, end_nid;
3856
3857 end_nid = codec->start_nid + codec->num_nodes;
3858 for (nid = codec->start_nid; nid < end_nid; nid++) {
3859 unsigned int wcaps = get_wcaps(codec, nid);
3860 unsigned int type = get_wcaps_type(wcaps);
3861 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3862 if (get_connection_index(codec, nid, pin) >= 0)
3863 return nid;
3864 }
3865 }
3866 return 0;
3867}
3868
3869static void cx_auto_parse_digital(struct hda_codec *codec)
3870{
3871 struct conexant_spec *spec = codec->spec;
3872 struct auto_pin_cfg *cfg = &spec->autocfg;
3873 hda_nid_t nid;
3874
3875 if (cfg->dig_outs &&
3876 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3877 spec->multiout.dig_out_nid = nid;
3878 if (cfg->dig_in_pin)
3879 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3880}
3881
3882#ifdef CONFIG_SND_HDA_INPUT_BEEP
3883static void cx_auto_parse_beep(struct hda_codec *codec)
3884{
3885 struct conexant_spec *spec = codec->spec;
3886 hda_nid_t nid, end_nid;
3887
3888 end_nid = codec->start_nid + codec->num_nodes;
3889 for (nid = codec->start_nid; nid < end_nid; nid++)
3890 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3891 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3892 break;
3893 }
3894}
3895#else
3896#define cx_auto_parse_beep(codec)
3897#endif
3898
Takashi Iwai254f2962011-10-14 15:22:34 +02003899/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003900static void cx_auto_parse_eapd(struct hda_codec *codec)
3901{
3902 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003903 hda_nid_t nid, end_nid;
3904
3905 end_nid = codec->start_nid + codec->num_nodes;
3906 for (nid = codec->start_nid; nid < end_nid; nid++) {
3907 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3908 continue;
3909 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3910 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003911 spec->eapds[spec->num_eapds++] = nid;
3912 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3913 break;
3914 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003915
3916 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3917 * it's a new chip, where EAPDs are supposed to be associated to
3918 * pins, and we can control EAPD per pin.
3919 * OTOH, if only one or two EAPDs are found, it's an old chip,
3920 * thus it might control over all pins.
3921 */
3922 spec->pin_eapd_ctrls = spec->num_eapds > 2;
Takashi Iwai19110592011-07-11 14:46:44 +02003923}
3924
Takashi Iwaif2e57312010-09-15 10:07:08 +02003925static int cx_auto_parse_auto_config(struct hda_codec *codec)
3926{
3927 struct conexant_spec *spec = codec->spec;
3928 int err;
3929
3930 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3931 if (err < 0)
3932 return err;
3933
3934 cx_auto_parse_output(codec);
3935 cx_auto_parse_input(codec);
3936 cx_auto_parse_digital(codec);
3937 cx_auto_parse_beep(codec);
Takashi Iwai19110592011-07-11 14:46:44 +02003938 cx_auto_parse_eapd(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003939 return 0;
3940}
3941
Takashi Iwaida339862011-05-13 16:24:15 +02003942static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3943 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003944{
3945 int i;
3946 for (i = 0; i < num_pins; i++) {
3947 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3948 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003949 AC_VERB_SET_EAPD_BTLENABLE,
3950 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003951 }
3952}
3953
3954static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3955 hda_nid_t src)
3956{
3957 int idx = get_connection_index(codec, pin, src);
3958 if (idx >= 0)
3959 snd_hda_codec_write(codec, pin, 0,
3960 AC_VERB_SET_CONNECT_SEL, idx);
3961}
3962
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003963static void mute_outputs(struct hda_codec *codec, int num_nids,
3964 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003965{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003966 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003967
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003968 for (i = 0; i < num_nids; i++) {
3969 hda_nid_t nid = nids[i];
3970 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3971 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003972 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3973 val = AMP_OUT_MUTE;
3974 else
3975 val = AMP_OUT_ZERO;
3976 snd_hda_codec_write(codec, nid, 0,
3977 AC_VERB_SET_AMP_GAIN_MUTE, val);
3978 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003979}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003980
Takashi Iwai03697e22011-05-17 09:53:31 +02003981static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3982 hda_nid_t *pins, unsigned int tag)
3983{
3984 int i;
3985 for (i = 0; i < num_pins; i++)
3986 snd_hda_codec_write(codec, pins[i], 0,
3987 AC_VERB_SET_UNSOLICITED_ENABLE,
3988 AC_USRSP_EN | tag);
3989}
3990
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003991static void cx_auto_init_output(struct hda_codec *codec)
3992{
3993 struct conexant_spec *spec = codec->spec;
3994 struct auto_pin_cfg *cfg = &spec->autocfg;
3995 hda_nid_t nid;
3996 int i;
3997
3998 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003999 for (i = 0; i < cfg->hp_outs; i++)
4000 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4001 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004002 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
4003 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
4004 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004005 for (i = 0; i < spec->dac_info_filled; i++) {
4006 nid = spec->dac_info[i].dac;
4007 if (!nid)
4008 nid = spec->multiout.dac_nids[0];
Takashi Iwai1f015f52011-08-23 14:57:08 +02004009 else if (nid & DAC_SLAVE_FLAG)
4010 nid &= ~DAC_SLAVE_FLAG;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004011 select_connection(codec, spec->dac_info[i].pin, nid);
4012 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004013 if (spec->auto_mute) {
4014 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4015 CONEXANT_HP_EVENT);
4016 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4017 cfg->hp_pins);
4018 if (spec->detect_line) {
4019 enable_unsol_pins(codec, cfg->line_outs,
4020 cfg->line_out_pins,
4021 CONEXANT_LINE_EVENT);
4022 spec->line_present =
4023 detect_jacks(codec, cfg->line_outs,
4024 cfg->line_out_pins);
4025 }
4026 }
4027 cx_auto_update_speakers(codec);
Takashi Iwai254f2962011-10-14 15:22:34 +02004028 /* turn on all EAPDs if no individual EAPD control is available */
4029 if (!spec->pin_eapd_ctrls)
4030 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004031}
4032
4033static void cx_auto_init_input(struct hda_codec *codec)
4034{
4035 struct conexant_spec *spec = codec->spec;
4036 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004037 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004038
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004039 for (i = 0; i < spec->num_adc_nids; i++) {
4040 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004041 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4042 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004043 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4044 val = AMP_IN_MUTE(0);
4045 else
4046 val = AMP_IN_UNMUTE(0);
4047 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4048 val);
4049 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004050
4051 for (i = 0; i < cfg->num_inputs; i++) {
4052 unsigned int type;
4053 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4054 type = PIN_VREF80;
4055 else
4056 type = PIN_IN;
4057 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4058 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4059 }
4060
4061 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004062 if (spec->auto_mic_ext >= 0) {
4063 snd_hda_codec_write(codec,
4064 cfg->inputs[spec->auto_mic_ext].pin, 0,
4065 AC_VERB_SET_UNSOLICITED_ENABLE,
4066 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4067 }
4068 if (spec->auto_mic_dock >= 0) {
4069 snd_hda_codec_write(codec,
4070 cfg->inputs[spec->auto_mic_dock].pin, 0,
4071 AC_VERB_SET_UNSOLICITED_ENABLE,
4072 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4073 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004074 cx_auto_automic(codec);
4075 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004076 select_input_connection(codec, spec->imux_info[0].adc,
4077 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004078 }
4079}
4080
4081static void cx_auto_init_digital(struct hda_codec *codec)
4082{
4083 struct conexant_spec *spec = codec->spec;
4084 struct auto_pin_cfg *cfg = &spec->autocfg;
4085
4086 if (spec->multiout.dig_out_nid)
4087 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4088 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4089 if (spec->dig_in_nid)
4090 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4091 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4092}
4093
4094static int cx_auto_init(struct hda_codec *codec)
4095{
4096 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4097 cx_auto_init_output(codec);
4098 cx_auto_init_input(codec);
4099 cx_auto_init_digital(codec);
4100 return 0;
4101}
4102
David Henningsson983345e2011-02-15 19:57:09 +01004103static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004104 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004105 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004106{
4107 static char name[32];
4108 static struct snd_kcontrol_new knew[] = {
4109 HDA_CODEC_VOLUME(name, 0, 0, 0),
4110 HDA_CODEC_MUTE(name, 0, 0, 0),
4111 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004112 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004113 int i, err;
4114
4115 for (i = 0; i < 2; i++) {
4116 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004117 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4118 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004119 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4120 knew[i].index = cidx;
4121 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4122 kctl = snd_ctl_new1(&knew[i], codec);
4123 if (!kctl)
4124 return -ENOMEM;
4125 err = snd_hda_ctl_add(codec, nid, kctl);
4126 if (err < 0)
4127 return err;
4128 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4129 break;
4130 }
4131 return 0;
4132}
4133
David Henningsson983345e2011-02-15 19:57:09 +01004134#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4135 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4136
Takashi Iwaif2e57312010-09-15 10:07:08 +02004137#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4138 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4139
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004140static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4141 hda_nid_t pin, const char *name, int idx)
4142{
4143 unsigned int caps;
David Henningsson468c5452011-08-25 13:16:02 +02004144 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4145 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4146 if (caps & AC_AMPCAP_NUM_STEPS)
4147 return cx_auto_add_pb_volume(codec, dac, name, idx);
4148 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004149 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4150 if (caps & AC_AMPCAP_NUM_STEPS)
4151 return cx_auto_add_pb_volume(codec, pin, name, idx);
4152 return 0;
4153}
4154
Takashi Iwaif2e57312010-09-15 10:07:08 +02004155static int cx_auto_build_output_controls(struct hda_codec *codec)
4156{
4157 struct conexant_spec *spec = codec->spec;
4158 int i, err;
4159 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004160 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004161
4162 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004163 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4164 spec->dac_info[0].pin,
4165 "Master", 0);
4166
Takashi Iwaif2e57312010-09-15 10:07:08 +02004167 for (i = 0; i < spec->dac_info_filled; i++) {
4168 const char *label;
4169 int idx, type;
Takashi Iwai1f015f52011-08-23 14:57:08 +02004170 hda_nid_t dac = spec->dac_info[i].dac;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004171 type = spec->dac_info[i].type;
4172 if (type == AUTO_PIN_LINE_OUT)
4173 type = spec->autocfg.line_out_type;
4174 switch (type) {
4175 case AUTO_PIN_LINE_OUT:
4176 default:
4177 label = texts[num_line++];
4178 idx = 0;
4179 break;
4180 case AUTO_PIN_HP_OUT:
4181 label = "Headphone";
4182 idx = num_hp++;
4183 break;
4184 case AUTO_PIN_SPEAKER_OUT:
4185 label = "Speaker";
4186 idx = num_spk++;
4187 break;
4188 }
Takashi Iwai1f015f52011-08-23 14:57:08 +02004189 err = try_add_pb_volume(codec, dac,
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004190 spec->dac_info[i].pin,
4191 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004192 if (err < 0)
4193 return err;
4194 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004195
4196 if (spec->auto_mute) {
4197 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4198 if (err < 0)
4199 return err;
4200 }
4201
Takashi Iwaif2e57312010-09-15 10:07:08 +02004202 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++) {
4213 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004214 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004215 if (idx < 0)
4216 continue;
Takashi Iwai6b452142011-10-14 15:26:20 +02004217 if (spec->single_adc_amp)
4218 idx = 0;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004219 return cx_auto_add_volume_idx(codec, label, pfx,
4220 cidx, adc_nid, HDA_INPUT, idx);
4221 }
4222 return 0;
4223}
4224
Takashi Iwaicf27f292011-05-16 11:33:02 +02004225static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4226 const char *label, int cidx)
4227{
4228 struct conexant_spec *spec = codec->spec;
4229 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004230 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004231
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004232 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004233 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4234 return cx_auto_add_volume(codec, label, " Boost", cidx,
4235 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004236 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4237 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004238 if (con < 0)
4239 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004240 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004241 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004242 return 0; /* already present */
4243 }
4244
4245 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004246 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004247 return cx_auto_add_volume(codec, label, " Boost", 0,
4248 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004249 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004250 return 0;
4251}
4252
Takashi Iwaif2e57312010-09-15 10:07:08 +02004253static int cx_auto_build_input_controls(struct hda_codec *codec)
4254{
4255 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004256 struct hda_input_mux *imux = &spec->private_imux;
4257 const char *prev_label;
4258 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6b452142011-10-14 15:26:20 +02004259 int i, j, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004260 int multi_connection;
4261
Takashi Iwai6b452142011-10-14 15:26:20 +02004262 if (!imux->num_items)
4263 return 0;
4264
Takashi Iwaicf27f292011-05-16 11:33:02 +02004265 multi_connection = 0;
4266 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004267 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4268 spec->imux_info[i].pin);
Takashi Iwai6b452142011-10-14 15:26:20 +02004269 if (cidx < 0)
4270 continue;
4271 input_conn[i] = spec->imux_info[i].adc;
4272 if (!spec->single_adc_amp)
4273 input_conn[i] |= cidx << 8;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004274 if (i > 0 && input_conn[i] != input_conn[0])
4275 multi_connection = 1;
4276 }
David Henningsson983345e2011-02-15 19:57:09 +01004277
Takashi Iwaif2e57312010-09-15 10:07:08 +02004278 prev_label = NULL;
4279 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004280 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004281 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004282 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004283
Takashi Iwaicf27f292011-05-16 11:33:02 +02004284 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004285 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004286 if (label == prev_label)
4287 cidx++;
4288 else
4289 cidx = 0;
4290 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004291
Takashi Iwaicf27f292011-05-16 11:33:02 +02004292 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4293 if (err < 0)
4294 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004295
Takashi Iwaicf27f292011-05-16 11:33:02 +02004296 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004297 if (i > 0)
4298 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004299 err = cx_auto_add_capture_volume(codec, nid,
4300 "Capture", "", cidx);
4301 } else {
Takashi Iwai6b452142011-10-14 15:26:20 +02004302 bool dup_found = false;
4303 for (j = 0; j < i; j++) {
4304 if (input_conn[j] == input_conn[i]) {
4305 dup_found = true;
4306 break;
4307 }
4308 }
4309 if (dup_found)
4310 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004311 err = cx_auto_add_capture_volume(codec, nid,
4312 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004313 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004314 if (err < 0)
4315 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004316 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004317
4318 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4319 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4320 if (err < 0)
4321 return err;
4322 }
4323
Takashi Iwaif2e57312010-09-15 10:07:08 +02004324 return 0;
4325}
4326
4327static int cx_auto_build_controls(struct hda_codec *codec)
4328{
4329 int err;
4330
4331 err = cx_auto_build_output_controls(codec);
4332 if (err < 0)
4333 return err;
4334 err = cx_auto_build_input_controls(codec);
4335 if (err < 0)
4336 return err;
4337 return conexant_build_controls(codec);
4338}
4339
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004340static int cx_auto_search_adcs(struct hda_codec *codec)
4341{
4342 struct conexant_spec *spec = codec->spec;
4343 hda_nid_t nid, end_nid;
4344
4345 end_nid = codec->start_nid + codec->num_nodes;
4346 for (nid = codec->start_nid; nid < end_nid; nid++) {
4347 unsigned int caps = get_wcaps(codec, nid);
4348 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4349 continue;
4350 if (caps & AC_WCAP_DIGITAL)
4351 continue;
4352 if (snd_BUG_ON(spec->num_adc_nids >=
4353 ARRAY_SIZE(spec->private_adc_nids)))
4354 break;
4355 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4356 }
4357 spec->adc_nids = spec->private_adc_nids;
4358 return 0;
4359}
4360
4361
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004362static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004363 .build_controls = cx_auto_build_controls,
4364 .build_pcms = conexant_build_pcms,
4365 .init = cx_auto_init,
4366 .free = conexant_free,
4367 .unsol_event = cx_auto_unsol_event,
4368#ifdef CONFIG_SND_HDA_POWER_SAVE
4369 .suspend = conexant_suspend,
4370#endif
4371 .reboot_notify = snd_hda_shutup_pins,
4372};
4373
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004374/*
4375 * pin fix-up
4376 */
4377struct cxt_pincfg {
4378 hda_nid_t nid;
4379 u32 val;
4380};
4381
4382static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4383{
4384 for (; cfg->nid; cfg++)
4385 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4386
4387}
4388
4389static void apply_pin_fixup(struct hda_codec *codec,
4390 const struct snd_pci_quirk *quirk,
4391 const struct cxt_pincfg **table)
4392{
4393 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4394 if (quirk) {
4395 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4396 quirk->name);
4397 apply_pincfg(codec, table[quirk->value]);
4398 }
4399}
4400
4401enum {
4402 CXT_PINCFG_LENOVO_X200,
4403};
4404
4405static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4406 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4407 { 0x17, 0x21a11000 }, /* dock-mic */
4408 { 0x19, 0x2121103f }, /* dock-HP */
4409 {}
4410};
4411
4412static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4413 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4414};
4415
4416static const struct snd_pci_quirk cxt_fixups[] = {
4417 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4418 {}
4419};
4420
Takashi Iwaif2e57312010-09-15 10:07:08 +02004421static int patch_conexant_auto(struct hda_codec *codec)
4422{
4423 struct conexant_spec *spec;
4424 int err;
4425
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004426 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4427 codec->chip_name);
4428
Takashi Iwaif2e57312010-09-15 10:07:08 +02004429 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4430 if (!spec)
4431 return -ENOMEM;
4432 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004433 codec->pin_amp_workaround = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004434
Takashi Iwai6b452142011-10-14 15:26:20 +02004435 switch (codec->vendor_id) {
4436 case 0x14f15045:
4437 spec->single_adc_amp = 1;
4438 break;
4439 }
4440
Takashi Iwaie92d4b02011-08-24 16:22:21 +02004441 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4442
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004443 err = cx_auto_search_adcs(codec);
4444 if (err < 0)
4445 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004446 err = cx_auto_parse_auto_config(codec);
4447 if (err < 0) {
4448 kfree(codec->spec);
4449 codec->spec = NULL;
4450 return err;
4451 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004452 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004453 codec->patch_ops = cx_auto_patch_ops;
4454 if (spec->beep_amp)
4455 snd_hda_attach_beep_device(codec, spec->beep_amp);
4456 return 0;
4457}
4458
4459/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004460 */
4461
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004462static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004463 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4464 .patch = patch_cxt5045 },
4465 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4466 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004467 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4468 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004469 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4470 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004471 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4472 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004473 { .id = 0x14f15068, .name = "CX20584",
4474 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004475 { .id = 0x14f15069, .name = "CX20585",
4476 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004477 { .id = 0x14f1506c, .name = "CX20588",
4478 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004479 { .id = 0x14f1506e, .name = "CX20590",
4480 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004481 { .id = 0x14f15097, .name = "CX20631",
4482 .patch = patch_conexant_auto },
4483 { .id = 0x14f15098, .name = "CX20632",
4484 .patch = patch_conexant_auto },
4485 { .id = 0x14f150a1, .name = "CX20641",
4486 .patch = patch_conexant_auto },
4487 { .id = 0x14f150a2, .name = "CX20642",
4488 .patch = patch_conexant_auto },
4489 { .id = 0x14f150ab, .name = "CX20651",
4490 .patch = patch_conexant_auto },
4491 { .id = 0x14f150ac, .name = "CX20652",
4492 .patch = patch_conexant_auto },
4493 { .id = 0x14f150b8, .name = "CX20664",
4494 .patch = patch_conexant_auto },
4495 { .id = 0x14f150b9, .name = "CX20665",
4496 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004497 {} /* terminator */
4498};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004499
4500MODULE_ALIAS("snd-hda-codec-id:14f15045");
4501MODULE_ALIAS("snd-hda-codec-id:14f15047");
4502MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004503MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004504MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004505MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004506MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004507MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004508MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004509MODULE_ALIAS("snd-hda-codec-id:14f15097");
4510MODULE_ALIAS("snd-hda-codec-id:14f15098");
4511MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4512MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4513MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4514MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4515MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4516MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004517
4518MODULE_LICENSE("GPL");
4519MODULE_DESCRIPTION("Conexant HD-audio codec");
4520
4521static struct hda_codec_preset_list conexant_list = {
4522 .preset = snd_hda_preset_conexant,
4523 .owner = THIS_MODULE,
4524};
4525
4526static int __init patch_conexant_init(void)
4527{
4528 return snd_hda_add_codec_preset(&conexant_list);
4529}
4530
4531static void __exit patch_conexant_exit(void)
4532{
4533 snd_hda_delete_codec_preset(&conexant_list);
4534}
4535
4536module_init(patch_conexant_init)
4537module_exit(patch_conexant_exit)