blob: b575c9989f3ceb000a70041989bac5fb02066adf [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
42
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010043/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010045#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046#define CXT5051_PORTB_EVENT 0x38
47#define CXT5051_PORTC_EVENT 0x39
48
Takashi Iwaifaddaa52010-01-23 22:31:36 +010049#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051
Takashi Iwaif2e57312010-09-15 10:07:08 +020052struct pin_dac_pair {
53 hda_nid_t pin;
54 hda_nid_t dac;
55 int type;
56};
57
Tobin Davisc9b443d2006-11-14 12:13:39 +010058struct conexant_spec {
59
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020060 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010061 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010062 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010063
64 const struct hda_verb *init_verbs[5]; /* initialization verbs
65 * don't forget NULL
66 * termination!
67 */
68 unsigned int num_init_verbs;
69
70 /* playback */
71 struct hda_multi_out multiout; /* playback set-up
72 * max_channels, dacs must be set
73 * dig_out_nid and hp_nid are optional
74 */
75 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010076 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010077 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020078 int auto_mic_ext; /* imux_pins[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010079 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050080 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010081
82 /* capture */
83 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020084 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010085 hda_nid_t dig_in_nid; /* digital-in NID; optional */
86
Takashi Iwai461e2c72008-01-25 11:35:17 +010087 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
91
Takashi Iwai6764bce2011-05-13 16:52:25 +020092 const struct hda_pcm_stream *capture_stream;
93
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 /* capture source */
95 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020096 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010097 unsigned int cur_mux[3];
98
99 /* channel model */
100 const struct hda_channel_mode *channel_mode;
101 int num_channel_mode;
102
103 /* PCM information */
104 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
105
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 unsigned int spdif_route;
107
108 /* dynamic controls, init_verbs and input_mux */
109 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100110 struct hda_input_mux private_imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200111 hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS];
Takashi Iwaif6100bb2011-05-13 18:26:39 +0200112 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200113 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200114 struct pin_dac_pair dac_info[8];
115 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100116
Daniel Drake0fb67e92009-07-16 14:46:57 +0100117 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200118 unsigned int auto_mute:1; /* used in auto-parser */
119 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500120 unsigned int dell_vostro:1;
121 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200122 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200123 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100124 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100125
Takashi Iwai6764bce2011-05-13 16:52:25 +0200126 unsigned int adc_switching:1;
127
Daniel Drake75f89912010-01-07 13:46:25 +0100128 unsigned int ext_mic_present;
129 unsigned int recording;
130 void (*capture_prepare)(struct hda_codec *codec);
131 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100132
133 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
134 * through the microphone jack.
135 * When the user enables this through a mixer switch, both internal and
136 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
137 * we also allow the bias to be configured through a separate mixer
138 * control. */
139 unsigned int dc_enable;
140 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
141 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200142
143 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100144};
145
146static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
147 struct hda_codec *codec,
148 struct snd_pcm_substream *substream)
149{
150 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100151 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
152 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100153}
154
155static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
156 struct hda_codec *codec,
157 unsigned int stream_tag,
158 unsigned int format,
159 struct snd_pcm_substream *substream)
160{
161 struct conexant_spec *spec = codec->spec;
162 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
163 stream_tag,
164 format, substream);
165}
166
167static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 struct snd_pcm_substream *substream)
170{
171 struct conexant_spec *spec = codec->spec;
172 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
173}
174
175/*
176 * Digital out
177 */
178static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
179 struct hda_codec *codec,
180 struct snd_pcm_substream *substream)
181{
182 struct conexant_spec *spec = codec->spec;
183 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
184}
185
186static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
187 struct hda_codec *codec,
188 struct snd_pcm_substream *substream)
189{
190 struct conexant_spec *spec = codec->spec;
191 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
192}
193
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200194static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
195 struct hda_codec *codec,
196 unsigned int stream_tag,
197 unsigned int format,
198 struct snd_pcm_substream *substream)
199{
200 struct conexant_spec *spec = codec->spec;
201 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
202 stream_tag,
203 format, substream);
204}
205
Tobin Davisc9b443d2006-11-14 12:13:39 +0100206/*
207 * Analog capture
208 */
209static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
210 struct hda_codec *codec,
211 unsigned int stream_tag,
212 unsigned int format,
213 struct snd_pcm_substream *substream)
214{
215 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100216 if (spec->capture_prepare)
217 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100218 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
219 stream_tag, 0, format);
220 return 0;
221}
222
223static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
224 struct hda_codec *codec,
225 struct snd_pcm_substream *substream)
226{
227 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100228 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100229 if (spec->capture_cleanup)
230 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100231 return 0;
232}
233
234
235
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200236static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100237 .substreams = 1,
238 .channels_min = 2,
239 .channels_max = 2,
240 .nid = 0, /* fill later */
241 .ops = {
242 .open = conexant_playback_pcm_open,
243 .prepare = conexant_playback_pcm_prepare,
244 .cleanup = conexant_playback_pcm_cleanup
245 },
246};
247
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200248static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100249 .substreams = 1,
250 .channels_min = 2,
251 .channels_max = 2,
252 .nid = 0, /* fill later */
253 .ops = {
254 .prepare = conexant_capture_pcm_prepare,
255 .cleanup = conexant_capture_pcm_cleanup
256 },
257};
258
259
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200260static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261 .substreams = 1,
262 .channels_min = 2,
263 .channels_max = 2,
264 .nid = 0, /* fill later */
265 .ops = {
266 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200267 .close = conexant_dig_playback_pcm_close,
268 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100269 },
270};
271
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200272static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100273 .substreams = 1,
274 .channels_min = 2,
275 .channels_max = 2,
276 /* NID is set in alc_build_pcms */
277};
278
Takashi Iwai461e2c72008-01-25 11:35:17 +0100279static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
280 struct hda_codec *codec,
281 unsigned int stream_tag,
282 unsigned int format,
283 struct snd_pcm_substream *substream)
284{
285 struct conexant_spec *spec = codec->spec;
286 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
287 spec->cur_adc_stream_tag = stream_tag;
288 spec->cur_adc_format = format;
289 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
290 return 0;
291}
292
293static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
294 struct hda_codec *codec,
295 struct snd_pcm_substream *substream)
296{
297 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100298 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100299 spec->cur_adc = 0;
300 return 0;
301}
302
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200303static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100304 .substreams = 1,
305 .channels_min = 2,
306 .channels_max = 2,
307 .nid = 0, /* fill later */
308 .ops = {
309 .prepare = cx5051_capture_pcm_prepare,
310 .cleanup = cx5051_capture_pcm_cleanup
311 },
312};
313
Tobin Davisc9b443d2006-11-14 12:13:39 +0100314static int conexant_build_pcms(struct hda_codec *codec)
315{
316 struct conexant_spec *spec = codec->spec;
317 struct hda_pcm *info = spec->pcm_rec;
318
319 codec->num_pcms = 1;
320 codec->pcm_info = info;
321
322 info->name = "CONEXANT Analog";
323 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
325 spec->multiout.max_channels;
326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
327 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200328 if (spec->capture_stream)
329 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
330 else {
331 if (codec->vendor_id == 0x14f15051)
332 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
333 cx5051_pcm_analog_capture;
334 else {
335 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
336 conexant_pcm_analog_capture;
337 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
338 spec->num_adc_nids;
339 }
340 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100341 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
342
343 if (spec->multiout.dig_out_nid) {
344 info++;
345 codec->num_pcms++;
346 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100347 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100348 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
349 conexant_pcm_digital_playback;
350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
351 spec->multiout.dig_out_nid;
352 if (spec->dig_in_nid) {
353 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
354 conexant_pcm_digital_capture;
355 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
356 spec->dig_in_nid;
357 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500358 if (spec->slave_dig_outs[0])
359 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100360 }
361
362 return 0;
363}
364
365static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_info *uinfo)
367{
368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369 struct conexant_spec *spec = codec->spec;
370
371 return snd_hda_input_mux_info(spec->input_mux, uinfo);
372}
373
374static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
375 struct snd_ctl_elem_value *ucontrol)
376{
377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
378 struct conexant_spec *spec = codec->spec;
379 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
380
381 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
382 return 0;
383}
384
385static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_value *ucontrol)
387{
388 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
389 struct conexant_spec *spec = codec->spec;
390 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
391
392 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
393 spec->capsrc_nids[adc_idx],
394 &spec->cur_mux[adc_idx]);
395}
396
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100397static int conexant_init_jacks(struct hda_codec *codec)
398{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100399#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100400 struct conexant_spec *spec = codec->spec;
401 int i;
402
403 for (i = 0; i < spec->num_init_verbs; i++) {
404 const struct hda_verb *hv;
405
406 hv = spec->init_verbs[i];
407 while (hv->nid) {
408 int err = 0;
409 switch (hv->param ^ AC_USRSP_EN) {
410 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100411 err = snd_hda_input_jack_add(codec, hv->nid,
412 SND_JACK_HEADPHONE, NULL);
413 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100414 break;
415 case CXT5051_PORTC_EVENT:
416 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100417 err = snd_hda_input_jack_add(codec, hv->nid,
418 SND_JACK_MICROPHONE, NULL);
419 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100420 break;
421 }
422 if (err < 0)
423 return err;
424 ++hv;
425 }
426 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100427#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100428 return 0;
429}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100430
Tobin Davisc9b443d2006-11-14 12:13:39 +0100431static int conexant_init(struct hda_codec *codec)
432{
433 struct conexant_spec *spec = codec->spec;
434 int i;
435
436 for (i = 0; i < spec->num_init_verbs; i++)
437 snd_hda_sequence_write(codec, spec->init_verbs[i]);
438 return 0;
439}
440
441static void conexant_free(struct hda_codec *codec)
442{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100443 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200444 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100445 kfree(codec->spec);
446}
447
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200448static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100449 {
450 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
451 .name = "Capture Source",
452 .info = conexant_mux_enum_info,
453 .get = conexant_mux_enum_get,
454 .put = conexant_mux_enum_put
455 },
456 {}
457};
458
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200459#ifdef CONFIG_SND_HDA_INPUT_BEEP
460/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200461static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200462 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
463 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
464 { } /* end */
465};
466#endif
467
Takashi Iwaiea734962011-01-17 11:29:34 +0100468static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100469 "Headphone Playback Volume",
470 "Speaker Playback Volume",
471 NULL
472};
473
Takashi Iwaiea734962011-01-17 11:29:34 +0100474static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100475 "Headphone Playback Switch",
476 "Speaker Playback Switch",
477 NULL
478};
479
Tobin Davisc9b443d2006-11-14 12:13:39 +0100480static int conexant_build_controls(struct hda_codec *codec)
481{
482 struct conexant_spec *spec = codec->spec;
483 unsigned int i;
484 int err;
485
486 for (i = 0; i < spec->num_mixers; i++) {
487 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
488 if (err < 0)
489 return err;
490 }
491 if (spec->multiout.dig_out_nid) {
492 err = snd_hda_create_spdif_out_ctls(codec,
493 spec->multiout.dig_out_nid);
494 if (err < 0)
495 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100496 err = snd_hda_create_spdif_share_sw(codec,
497 &spec->multiout);
498 if (err < 0)
499 return err;
500 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100501 }
502 if (spec->dig_in_nid) {
503 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
504 if (err < 0)
505 return err;
506 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100507
508 /* if we have no master control, let's create it */
509 if (spec->vmaster_nid &&
510 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
511 unsigned int vmaster_tlv[4];
512 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
513 HDA_OUTPUT, vmaster_tlv);
514 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
515 vmaster_tlv, slave_vols);
516 if (err < 0)
517 return err;
518 }
519 if (spec->vmaster_nid &&
520 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
521 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
522 NULL, slave_sws);
523 if (err < 0)
524 return err;
525 }
526
Takashi Iwaib880c742009-03-10 14:41:05 +0100527 if (spec->input_mux) {
528 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
529 if (err < 0)
530 return err;
531 }
532
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200533#ifdef CONFIG_SND_HDA_INPUT_BEEP
534 /* create beep controls if needed */
535 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200536 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200537 for (knew = cxt_beep_mixer; knew->name; knew++) {
538 struct snd_kcontrol *kctl;
539 kctl = snd_ctl_new1(knew, codec);
540 if (!kctl)
541 return -ENOMEM;
542 kctl->private_value = spec->beep_amp;
543 err = snd_hda_ctl_add(codec, 0, kctl);
544 if (err < 0)
545 return err;
546 }
547 }
548#endif
549
Tobin Davisc9b443d2006-11-14 12:13:39 +0100550 return 0;
551}
552
Takashi Iwai697c3732010-07-30 11:28:02 +0200553#ifdef CONFIG_SND_HDA_POWER_SAVE
554static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
555{
556 snd_hda_shutup_pins(codec);
557 return 0;
558}
559#endif
560
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200561static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100562 .build_controls = conexant_build_controls,
563 .build_pcms = conexant_build_pcms,
564 .init = conexant_init,
565 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200566#ifdef CONFIG_SND_HDA_POWER_SAVE
567 .suspend = conexant_suspend,
568#endif
569 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100570};
571
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200572#ifdef CONFIG_SND_HDA_INPUT_BEEP
573#define set_beep_amp(spec, nid, idx, dir) \
574 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
575#else
576#define set_beep_amp(spec, nid, idx, dir) /* NOP */
577#endif
578
Takashi Iwai6764bce2011-05-13 16:52:25 +0200579static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100580/*
581 * EAPD control
582 * the private value = nid | (invert << 8)
583 */
584
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200585#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586
Tobin Davis82f30042007-02-13 12:45:44 +0100587static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100588 struct snd_ctl_elem_value *ucontrol)
589{
590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
591 struct conexant_spec *spec = codec->spec;
592 int invert = (kcontrol->private_value >> 8) & 1;
593 if (invert)
594 ucontrol->value.integer.value[0] = !spec->cur_eapd;
595 else
596 ucontrol->value.integer.value[0] = spec->cur_eapd;
597 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100598
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599}
600
Tobin Davis82f30042007-02-13 12:45:44 +0100601static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602 struct snd_ctl_elem_value *ucontrol)
603{
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 struct conexant_spec *spec = codec->spec;
606 int invert = (kcontrol->private_value >> 8) & 1;
607 hda_nid_t nid = kcontrol->private_value & 0xff;
608 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100609
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100610 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100611 if (invert)
612 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200613 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100615
Tobin Davisc9b443d2006-11-14 12:13:39 +0100616 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200617 snd_hda_codec_write_cache(codec, nid,
618 0, AC_VERB_SET_EAPD_BTLENABLE,
619 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620 return 1;
621}
622
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100623/* controls for test mode */
624#ifdef CONFIG_SND_DEBUG
625
Tobin Davis82f30042007-02-13 12:45:44 +0100626#define CXT_EAPD_SWITCH(xname, nid, mask) \
627 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
628 .info = cxt_eapd_info, \
629 .get = cxt_eapd_get, \
630 .put = cxt_eapd_put, \
631 .private_value = nid | (mask<<16) }
632
633
634
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_info *uinfo)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct conexant_spec *spec = codec->spec;
640 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
641 spec->num_channel_mode);
642}
643
644static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_value *ucontrol)
646{
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct conexant_spec *spec = codec->spec;
649 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
650 spec->num_channel_mode,
651 spec->multiout.max_channels);
652}
653
654static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
656{
657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658 struct conexant_spec *spec = codec->spec;
659 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
660 spec->num_channel_mode,
661 &spec->multiout.max_channels);
662 if (err >= 0 && spec->need_dac_fix)
663 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
664 return err;
665}
666
667#define CXT_PIN_MODE(xname, nid, dir) \
668 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
669 .info = conexant_ch_mode_info, \
670 .get = conexant_ch_mode_get, \
671 .put = conexant_ch_mode_put, \
672 .private_value = nid | (dir<<16) }
673
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100674#endif /* CONFIG_SND_DEBUG */
675
Tobin Davisc9b443d2006-11-14 12:13:39 +0100676/* Conexant 5045 specific */
677
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200678static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
679static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
680static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100681#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100682
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200683static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100684 { 2, NULL },
685};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200687static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100688 .num_items = 2,
689 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100690 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100691 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100692 }
693};
694
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200695static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200696 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100697 .items = {
698 { "IntMic", 0x1 },
699 { "ExtMic", 0x2 },
700 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200701 { "CD", 0x4 },
702 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100703 }
704};
705
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200706static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100707 .num_items = 2,
708 .items = {
709 { "ExtMic", 0x1 },
710 { "IntMic", 0x2 },
711 }
712};
713
Tobin Davisc9b443d2006-11-14 12:13:39 +0100714/* turn on/off EAPD (+ mute HP) as a master switch */
715static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
716 struct snd_ctl_elem_value *ucontrol)
717{
718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
719 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100720 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100721
Tobin Davis82f30042007-02-13 12:45:44 +0100722 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100723 return 0;
724
Tobin Davis82f30042007-02-13 12:45:44 +0100725 /* toggle internal speakers mute depending of presence of
726 * the headphone jack
727 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200728 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
729 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
730 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100731
Takashi Iwai47fd8302007-08-10 17:11:07 +0200732 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
733 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
734 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100735 return 1;
736}
737
738/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200739static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200740 .ops = &snd_hda_bind_vol,
741 .values = {
742 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
743 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
744 0
745 },
746};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747
Tobin Davis7f296732007-03-12 11:39:01 +0100748/* toggle input of built-in and mic jack appropriately */
749static void cxt5045_hp_automic(struct hda_codec *codec)
750{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200751 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100752 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
753 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
754 {}
755 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200756 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100757 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
759 {}
760 };
761 unsigned int present;
762
Takashi Iwaid56757a2009-11-18 08:00:14 +0100763 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100764 if (present)
765 snd_hda_sequence_write(codec, mic_jack_on);
766 else
767 snd_hda_sequence_write(codec, mic_jack_off);
768}
769
Tobin Davisc9b443d2006-11-14 12:13:39 +0100770
771/* mute internal speaker if HP is plugged */
772static void cxt5045_hp_automute(struct hda_codec *codec)
773{
Tobin Davis82f30042007-02-13 12:45:44 +0100774 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100775 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100776
Takashi Iwaid56757a2009-11-18 08:00:14 +0100777 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100778
Takashi Iwai47fd8302007-08-10 17:11:07 +0200779 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
780 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
781 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100782}
783
784/* unsolicited event for HP jack sensing */
785static void cxt5045_hp_unsol_event(struct hda_codec *codec,
786 unsigned int res)
787{
788 res >>= 26;
789 switch (res) {
790 case CONEXANT_HP_EVENT:
791 cxt5045_hp_automute(codec);
792 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100793 case CONEXANT_MIC_EVENT:
794 cxt5045_hp_automic(codec);
795 break;
796
Tobin Davisc9b443d2006-11-14 12:13:39 +0100797 }
798}
799
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200800static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100801 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
802 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100803 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
804 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200805 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
806 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100807 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
808 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100809 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
810 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200811 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100812 {
813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
814 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100815 .info = cxt_eapd_info,
816 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100817 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100818 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100819 },
820
821 {}
822};
823
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200824static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200825 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
826 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
827 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
828 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
829
Jiang Zhe5218c892008-01-17 11:18:41 +0100830 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
831 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
832 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
833 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
834
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200835 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
836 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
837
Jiang Zhe5218c892008-01-17 11:18:41 +0100838 {}
839};
840
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200841static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100842 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
843 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100844 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
845 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100846 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, 0x2, HDA_INPUT),
849 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100850 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
851 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100852 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
853 {
854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
855 .name = "Master Playback Switch",
856 .info = cxt_eapd_info,
857 .get = cxt_eapd_get,
858 .put = cxt5045_hp_master_sw_put,
859 .private_value = 0x10,
860 },
861
862 {}
863};
864
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200865static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100866 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200867 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100868 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100869 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200870 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
871 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
872 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
873 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
878 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100879 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100880 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100881 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100882 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
883 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100884 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100885 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100886 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100887 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100888 { } /* end */
889};
890
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200891static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100892 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100893 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
894 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
895 /* Line In,HP, Amp */
896 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
897 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
898 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
899 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
901 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100905 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100906 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
907 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
908 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
909 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100910 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100911 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
912 /* EAPD */
913 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
914 { } /* end */
915};
Tobin Davis7f296732007-03-12 11:39:01 +0100916
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200917static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100918 /* pin sensing on HP jack */
919 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200920 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100921};
922
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200923static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100924 /* pin sensing on HP jack */
925 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200926 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100927};
928
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929#ifdef CONFIG_SND_DEBUG
930/* Test configuration for debugging, modelled after the ALC260 test
931 * configuration.
932 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200933static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100934 .num_items = 5,
935 .items = {
936 { "MIXER", 0x0 },
937 { "MIC1 pin", 0x1 },
938 { "LINE1 pin", 0x2 },
939 { "HP-OUT pin", 0x3 },
940 { "CD pin", 0x4 },
941 },
942};
943
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200944static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100945
946 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
948 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100949 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
950 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
951 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
952 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100953
954 /* Modes for retasking pin widgets */
955 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
956 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
957
Tobin Davis82f30042007-02-13 12:45:44 +0100958 /* EAPD Switch Control */
959 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
960
Tobin Davisc9b443d2006-11-14 12:13:39 +0100961 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100962
Tobin Davis7f296732007-03-12 11:39:01 +0100963 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
964 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
965 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
966 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
967 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
968 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
969 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
970 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
971 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
972 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100973 {
974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
975 .name = "Input Source",
976 .info = conexant_mux_enum_info,
977 .get = conexant_mux_enum_get,
978 .put = conexant_mux_enum_put,
979 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200980 /* Audio input controls */
981 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
982 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
983 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
984 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
985 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
986 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
987 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
988 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
989 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
990 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100991 { } /* end */
992};
993
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200994static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100995 /* Set connections */
996 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
997 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
998 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100999 /* Enable retasking pins as output, initially without power amp */
1000 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001001 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002
1003 /* Disable digital (SPDIF) pins initially, but users can enable
1004 * them via a mixer switch. In the case of SPDIF-out, this initverb
1005 * payload also sets the generation to 0, output to be in "consumer"
1006 * PCM format, copyright asserted, no pre-emphasis and no validity
1007 * control.
1008 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001009 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1010 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001011
1012 /* Start with output sum widgets muted and their output gains at min */
1013 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1014 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1015
1016 /* Unmute retasking pin widget output buffers since the default
1017 * state appears to be output. As the pin mode is changed by the
1018 * user the pin mode control will take care of enabling the pin's
1019 * input/output buffers as needed.
1020 */
1021 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1022 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1023
1024 /* Mute capture amp left and right */
1025 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1026
1027 /* Set ADC connection select to match default mixer setting (mic1
1028 * pin)
1029 */
1030 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001031 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001032
1033 /* Mute all inputs to mixer widget (even unconnected ones) */
1034 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1037 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1038 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1039
1040 { }
1041};
1042#endif
1043
1044
1045/* initialize jack-sensing, too */
1046static int cxt5045_init(struct hda_codec *codec)
1047{
1048 conexant_init(codec);
1049 cxt5045_hp_automute(codec);
1050 return 0;
1051}
1052
1053
1054enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001055 CXT5045_LAPTOP_HPSENSE,
1056 CXT5045_LAPTOP_MICSENSE,
1057 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001058 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001059 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001060#ifdef CONFIG_SND_DEBUG
1061 CXT5045_TEST,
1062#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001063 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001064 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001065};
1066
Takashi Iwaiea734962011-01-17 11:29:34 +01001067static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001068 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1069 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1070 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1071 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001072 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001074 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001076 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001077};
1078
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001079static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001080 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001081 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1082 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001083 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001084 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001085 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1086 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001087 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1088 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001089 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1090 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1091 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001092 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1093 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001094 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001095 {}
1096};
1097
1098static int patch_cxt5045(struct hda_codec *codec)
1099{
1100 struct conexant_spec *spec;
1101 int board_config;
1102
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001103 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1104 cxt5045_models,
1105 cxt5045_cfg_tbl);
1106 if (board_config < 0)
1107 board_config = CXT5045_AUTO;
1108 if (board_config == CXT5045_AUTO)
1109 return patch_conexant_auto(codec);
1110
Tobin Davisc9b443d2006-11-14 12:13:39 +01001111 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1112 if (!spec)
1113 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001114 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001115 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116
1117 spec->multiout.max_channels = 2;
1118 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1119 spec->multiout.dac_nids = cxt5045_dac_nids;
1120 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1121 spec->num_adc_nids = 1;
1122 spec->adc_nids = cxt5045_adc_nids;
1123 spec->capsrc_nids = cxt5045_capsrc_nids;
1124 spec->input_mux = &cxt5045_capture_source;
1125 spec->num_mixers = 1;
1126 spec->mixers[0] = cxt5045_mixers;
1127 spec->num_init_verbs = 1;
1128 spec->init_verbs[0] = cxt5045_init_verbs;
1129 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001130 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1131 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001132
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001133 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001134
1135 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001138 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001139 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140 spec->input_mux = &cxt5045_capture_source;
1141 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001142 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1143 spec->mixers[0] = cxt5045_mixers;
1144 codec->patch_ops.init = cxt5045_init;
1145 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001146 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001147 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001148 spec->input_mux = &cxt5045_capture_source;
1149 spec->num_init_verbs = 2;
1150 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001151 spec->mixers[0] = cxt5045_mixers;
1152 codec->patch_ops.init = cxt5045_init;
1153 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001154 default:
1155 case CXT5045_LAPTOP_HPMICSENSE:
1156 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1157 spec->input_mux = &cxt5045_capture_source;
1158 spec->num_init_verbs = 3;
1159 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1160 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1161 spec->mixers[0] = cxt5045_mixers;
1162 codec->patch_ops.init = cxt5045_init;
1163 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001164 case CXT5045_BENQ:
1165 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1166 spec->input_mux = &cxt5045_capture_source_benq;
1167 spec->num_init_verbs = 1;
1168 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1169 spec->mixers[0] = cxt5045_mixers;
1170 spec->mixers[1] = cxt5045_benq_mixers;
1171 spec->num_mixers = 2;
1172 codec->patch_ops.init = cxt5045_init;
1173 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001174 case CXT5045_LAPTOP_HP530:
1175 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1176 spec->input_mux = &cxt5045_capture_source_hp530;
1177 spec->num_init_verbs = 2;
1178 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1179 spec->mixers[0] = cxt5045_mixers_hp530;
1180 codec->patch_ops.init = cxt5045_init;
1181 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001182#ifdef CONFIG_SND_DEBUG
1183 case CXT5045_TEST:
1184 spec->input_mux = &cxt5045_test_capture_source;
1185 spec->mixers[0] = cxt5045_test_mixer;
1186 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001187 break;
1188
Tobin Davisc9b443d2006-11-14 12:13:39 +01001189#endif
1190 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001191
Takashi Iwai031005f2008-06-26 14:49:58 +02001192 switch (codec->subsystem_id >> 16) {
1193 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001194 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001195 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001196 case 0x17aa:
1197 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1198 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1199 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001200 */
1201 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1202 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1203 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1204 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1205 (1 << AC_AMPCAP_MUTE_SHIFT));
1206 break;
1207 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001208
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001209 if (spec->beep_amp)
1210 snd_hda_attach_beep_device(codec, spec->beep_amp);
1211
Tobin Davisc9b443d2006-11-14 12:13:39 +01001212 return 0;
1213}
1214
1215
1216/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001217#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001218
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001219static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1220static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1221static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001223static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001224 { 2, NULL },
1225};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001226
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001227static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001228 .num_items = 2,
1229 .items = {
1230 { "ExtMic", 0x2 },
1231 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001232 }
1233};
1234
1235/* turn on/off EAPD (+ mute HP) as a master switch */
1236static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1237 struct snd_ctl_elem_value *ucontrol)
1238{
1239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1240 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001241 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242
Tobin Davis82f30042007-02-13 12:45:44 +01001243 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001244 return 0;
1245
Tobin Davis82f30042007-02-13 12:45:44 +01001246 /* toggle internal speakers mute depending of presence of
1247 * the headphone jack
1248 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001249 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001250 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1251 * pin widgets unlike other codecs. In this case, we need to
1252 * set index 0x01 for the volume from the mixer amp 0x19.
1253 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001254 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001255 HDA_AMP_MUTE, bits);
1256 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1257 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1258 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259 return 1;
1260}
1261
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262/* mute internal speaker if HP is plugged */
1263static void cxt5047_hp_automute(struct hda_codec *codec)
1264{
Tobin Davis82f30042007-02-13 12:45:44 +01001265 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001266 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267
Takashi Iwaid56757a2009-11-18 08:00:14 +01001268 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001269
Takashi Iwai47fd8302007-08-10 17:11:07 +02001270 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001271 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001272 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001273 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274}
1275
1276/* toggle input of built-in and mic jack appropriately */
1277static void cxt5047_hp_automic(struct hda_codec *codec)
1278{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001279 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001280 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1281 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282 {}
1283 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001284 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001285 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1286 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287 {}
1288 };
1289 unsigned int present;
1290
Takashi Iwaid56757a2009-11-18 08:00:14 +01001291 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001292 if (present)
1293 snd_hda_sequence_write(codec, mic_jack_on);
1294 else
1295 snd_hda_sequence_write(codec, mic_jack_off);
1296}
1297
1298/* unsolicited event for HP jack sensing */
1299static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1300 unsigned int res)
1301{
Marc Boucher9f113e02008-01-22 15:18:08 +01001302 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303 case CONEXANT_HP_EVENT:
1304 cxt5047_hp_automute(codec);
1305 break;
1306 case CONEXANT_MIC_EVENT:
1307 cxt5047_hp_automic(codec);
1308 break;
1309 }
1310}
1311
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001312static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001313 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001315 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1318 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1319 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001320 {
1321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1322 .name = "Master Playback Switch",
1323 .info = cxt_eapd_info,
1324 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 .put = cxt5047_hp_master_sw_put,
1326 .private_value = 0x13,
1327 },
1328
1329 {}
1330};
1331
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001332static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001333 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001334 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001335 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1336 {}
1337};
1338
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001339static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001341 { } /* end */
1342};
1343
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001344static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001345 /* Line in, Mic, Built-in Mic */
1346 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1347 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1348 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001349 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001350 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001351 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1352 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001353 /* Record selector: Mic */
1354 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1355 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1356 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1357 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001358 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1359 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1360 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1361 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 /* SPDIF route: PCM */
1363 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001364 /* Enable unsolicited events */
1365 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1366 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 { } /* end */
1368};
1369
1370/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001371static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001372 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001373 {}
1374};
1375
1376/* Test configuration for debugging, modelled after the ALC260 test
1377 * configuration.
1378 */
1379#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001380static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001381 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001383 { "LINE1 pin", 0x0 },
1384 { "MIC1 pin", 0x1 },
1385 { "MIC2 pin", 0x2 },
1386 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 },
1388};
1389
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001390static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001391
1392 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001393 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1394 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1395 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1396 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001401 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1404 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405
1406 /* Modes for retasking pin widgets */
1407 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1408 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1409
Tobin Davis82f30042007-02-13 12:45:44 +01001410 /* EAPD Switch Control */
1411 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1412
Tobin Davisc9b443d2006-11-14 12:13:39 +01001413 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001414 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1415 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1416 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1417 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1418 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1419 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1420 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1421 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001422
Tobin Davis82f30042007-02-13 12:45:44 +01001423 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1424 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1426 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1427 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1428 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1429 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1430 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001431 {
1432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1433 .name = "Input Source",
1434 .info = conexant_mux_enum_info,
1435 .get = conexant_mux_enum_get,
1436 .put = conexant_mux_enum_put,
1437 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001438 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001439
Tobin Davisc9b443d2006-11-14 12:13:39 +01001440 { } /* end */
1441};
1442
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001443static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001444 /* Enable retasking pins as output, initially without power amp */
1445 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1446 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1448
1449 /* Disable digital (SPDIF) pins initially, but users can enable
1450 * them via a mixer switch. In the case of SPDIF-out, this initverb
1451 * payload also sets the generation to 0, output to be in "consumer"
1452 * PCM format, copyright asserted, no pre-emphasis and no validity
1453 * control.
1454 */
1455 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1456
1457 /* Ensure mic1, mic2, line1 pin widgets take input from the
1458 * OUT1 sum bus when acting as an output.
1459 */
1460 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1461 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1462
1463 /* Start with output sum widgets muted and their output gains at min */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1466
1467 /* Unmute retasking pin widget output buffers since the default
1468 * state appears to be output. As the pin mode is changed by the
1469 * user the pin mode control will take care of enabling the pin's
1470 * input/output buffers as needed.
1471 */
1472 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1475
1476 /* Mute capture amp left and right */
1477 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1478
1479 /* Set ADC connection select to match default mixer setting (mic1
1480 * pin)
1481 */
1482 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1483
1484 /* Mute all inputs to mixer widget (even unconnected ones) */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1492 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1493
1494 { }
1495};
1496#endif
1497
1498
1499/* initialize jack-sensing, too */
1500static int cxt5047_hp_init(struct hda_codec *codec)
1501{
1502 conexant_init(codec);
1503 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504 return 0;
1505}
1506
1507
1508enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001509 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1510 CXT5047_LAPTOP_HP, /* Some HP laptops */
1511 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001512#ifdef CONFIG_SND_DEBUG
1513 CXT5047_TEST,
1514#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001515 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001516};
1517
Takashi Iwaiea734962011-01-17 11:29:34 +01001518static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001519 [CXT5047_LAPTOP] = "laptop",
1520 [CXT5047_LAPTOP_HP] = "laptop-hp",
1521 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001523 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001525};
1526
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001527static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001528 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001529 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1530 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001531 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532 {}
1533};
1534
1535static int patch_cxt5047(struct hda_codec *codec)
1536{
1537 struct conexant_spec *spec;
1538 int board_config;
1539
1540 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1541 if (!spec)
1542 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001544 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545
1546 spec->multiout.max_channels = 2;
1547 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1548 spec->multiout.dac_nids = cxt5047_dac_nids;
1549 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1550 spec->num_adc_nids = 1;
1551 spec->adc_nids = cxt5047_adc_nids;
1552 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001554 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001555 spec->num_init_verbs = 1;
1556 spec->init_verbs[0] = cxt5047_init_verbs;
1557 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001558 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1559 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560
1561 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001563 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1564 cxt5047_models,
1565 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001566 switch (board_config) {
1567 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001568 spec->num_mixers = 2;
1569 spec->mixers[1] = cxt5047_hp_spk_mixers;
1570 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001571 break;
1572 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001573 spec->num_mixers = 2;
1574 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001575 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576 codec->patch_ops.init = cxt5047_hp_init;
1577 break;
1578 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001579 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001580 spec->num_mixers = 2;
1581 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001582 spec->num_init_verbs = 2;
1583 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001584 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001585 break;
1586#ifdef CONFIG_SND_DEBUG
1587 case CXT5047_TEST:
1588 spec->input_mux = &cxt5047_test_capture_source;
1589 spec->mixers[0] = cxt5047_test_mixer;
1590 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001591 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592#endif
1593 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001594 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001595
1596 switch (codec->subsystem_id >> 16) {
1597 case 0x103c:
1598 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1599 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1600 * with 0 dB offset 0x17)
1601 */
1602 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1603 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1604 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1605 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1606 (1 << AC_AMPCAP_MUTE_SHIFT));
1607 break;
1608 }
1609
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610 return 0;
1611}
1612
Takashi Iwai461e2c72008-01-25 11:35:17 +01001613/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001614static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1615static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001616
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001617static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001618 { 2, NULL },
1619};
1620
1621static void cxt5051_update_speaker(struct hda_codec *codec)
1622{
1623 struct conexant_spec *spec = codec->spec;
1624 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001625 /* headphone pin */
1626 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1627 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1628 pinctl);
1629 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001630 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1631 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1632 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001633 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1634 if (spec->ideapad)
1635 snd_hda_codec_write(codec, 0x1b, 0,
1636 AC_VERB_SET_PIN_WIDGET_CONTROL,
1637 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001638}
1639
1640/* turn on/off EAPD (+ mute HP) as a master switch */
1641static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1642 struct snd_ctl_elem_value *ucontrol)
1643{
1644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1645
1646 if (!cxt_eapd_put(kcontrol, ucontrol))
1647 return 0;
1648 cxt5051_update_speaker(codec);
1649 return 1;
1650}
1651
1652/* toggle input of built-in and mic jack appropriately */
1653static void cxt5051_portb_automic(struct hda_codec *codec)
1654{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001655 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001656 unsigned int present;
1657
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001658 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001659 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001660 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001661 snd_hda_codec_write(codec, 0x14, 0,
1662 AC_VERB_SET_CONNECT_SEL,
1663 present ? 0x01 : 0x00);
1664}
1665
1666/* switch the current ADC according to the jack state */
1667static void cxt5051_portc_automic(struct hda_codec *codec)
1668{
1669 struct conexant_spec *spec = codec->spec;
1670 unsigned int present;
1671 hda_nid_t new_adc;
1672
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001673 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001674 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001675 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001676 if (present)
1677 spec->cur_adc_idx = 1;
1678 else
1679 spec->cur_adc_idx = 0;
1680 new_adc = spec->adc_nids[spec->cur_adc_idx];
1681 if (spec->cur_adc && spec->cur_adc != new_adc) {
1682 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001683 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001684 spec->cur_adc = new_adc;
1685 snd_hda_codec_setup_stream(codec, new_adc,
1686 spec->cur_adc_stream_tag, 0,
1687 spec->cur_adc_format);
1688 }
1689}
1690
1691/* mute internal speaker if HP is plugged */
1692static void cxt5051_hp_automute(struct hda_codec *codec)
1693{
1694 struct conexant_spec *spec = codec->spec;
1695
Takashi Iwaid56757a2009-11-18 08:00:14 +01001696 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001697 cxt5051_update_speaker(codec);
1698}
1699
1700/* unsolicited event for HP jack sensing */
1701static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1702 unsigned int res)
1703{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001704 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001705 switch (res >> 26) {
1706 case CONEXANT_HP_EVENT:
1707 cxt5051_hp_automute(codec);
1708 break;
1709 case CXT5051_PORTB_EVENT:
1710 cxt5051_portb_automic(codec);
1711 break;
1712 case CXT5051_PORTC_EVENT:
1713 cxt5051_portc_automic(codec);
1714 break;
1715 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001716 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001717}
1718
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001719static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001720 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1721 {
1722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1723 .name = "Master Playback Switch",
1724 .info = cxt_eapd_info,
1725 .get = cxt_eapd_get,
1726 .put = cxt5051_hp_master_sw_put,
1727 .private_value = 0x1a,
1728 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001729 {}
1730};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001731
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001732static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001733 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1734 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001735 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1736 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001737 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1738 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001739 {}
1740};
1741
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001742static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001743 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1744 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001745 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1746 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001747 {}
1748};
1749
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001750static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001751 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1752 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001753 {}
1754};
1755
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001756static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001757 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1758 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001759 {}
1760};
1761
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001762static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001763 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1764 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001765 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1766 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001767 {}
1768};
1769
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001770static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001771 /* Line in, Mic */
1772 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1773 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1774 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1775 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1776 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1777 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1778 /* SPK */
1779 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1780 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1781 /* HP, Amp */
1782 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1783 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1784 /* DAC1 */
1785 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001786 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1788 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1789 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1790 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001791 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001792 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1793 /* EAPD */
1794 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1795 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001796 { } /* end */
1797};
1798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001799static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001800 /* Line in, Mic */
1801 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1802 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1803 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1804 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1805 /* SPK */
1806 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1807 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1808 /* HP, Amp */
1809 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1810 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1811 /* DAC1 */
1812 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001813 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001814 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1815 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1816 /* SPDIF route: PCM */
1817 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1818 /* EAPD */
1819 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1820 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001821 { } /* end */
1822};
1823
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001824static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001825 /* Line in, Mic */
1826 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1827 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1828 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1829 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1830 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1831 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1832 /* SPK */
1833 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1834 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* HP, Amp */
1836 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1837 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1838 /* Docking HP */
1839 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1840 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1841 /* DAC1 */
1842 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001843 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1845 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1846 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1847 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001848 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001849 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1850 /* EAPD */
1851 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1852 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001853 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1854 { } /* end */
1855};
1856
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001857static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001858 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001859 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001860 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1861 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1862 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1863 /* SPK */
1864 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1865 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1866 /* HP, Amp */
1867 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1868 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1869 /* DAC1 */
1870 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001871 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001872 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1873 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1874 /* SPDIF route: PCM */
1875 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1876 /* EAPD */
1877 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1878 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001879 { } /* end */
1880};
1881
Takashi Iwai6953e552010-01-24 11:00:27 +01001882static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1883 unsigned int event)
1884{
1885 snd_hda_codec_write(codec, nid, 0,
1886 AC_VERB_SET_UNSOLICITED_ENABLE,
1887 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001888 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1889 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001890}
1891
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001892static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001893 /* Subwoofer */
1894 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1895 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1896 { } /* end */
1897};
1898
Takashi Iwai461e2c72008-01-25 11:35:17 +01001899/* initialize jack-sensing, too */
1900static int cxt5051_init(struct hda_codec *codec)
1901{
Takashi Iwai6953e552010-01-24 11:00:27 +01001902 struct conexant_spec *spec = codec->spec;
1903
Takashi Iwai461e2c72008-01-25 11:35:17 +01001904 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001905 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001906
1907 if (spec->auto_mic & AUTO_MIC_PORTB)
1908 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1909 if (spec->auto_mic & AUTO_MIC_PORTC)
1910 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1911
Takashi Iwai461e2c72008-01-25 11:35:17 +01001912 if (codec->patch_ops.unsol_event) {
1913 cxt5051_hp_automute(codec);
1914 cxt5051_portb_automic(codec);
1915 cxt5051_portc_automic(codec);
1916 }
1917 return 0;
1918}
1919
1920
1921enum {
1922 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1923 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001924 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001925 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001926 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001927 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001928 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001929 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001930 CXT5051_MODELS
1931};
1932
Takashi Iwaiea734962011-01-17 11:29:34 +01001933static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001934 [CXT5051_LAPTOP] = "laptop",
1935 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001936 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001937 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001938 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001939 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001940 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001941 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001942};
1943
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001944static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001945 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001946 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001947 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001948 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001949 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1950 CXT5051_LAPTOP),
1951 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001952 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001953 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001954 {}
1955};
1956
1957static int patch_cxt5051(struct hda_codec *codec)
1958{
1959 struct conexant_spec *spec;
1960 int board_config;
1961
Takashi Iwai6764bce2011-05-13 16:52:25 +02001962 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1963 cxt5051_models,
1964 cxt5051_cfg_tbl);
1965 if (board_config < 0)
1966 board_config = CXT5051_AUTO;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001967 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001968 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001969
Takashi Iwai461e2c72008-01-25 11:35:17 +01001970 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1971 if (!spec)
1972 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001973 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001974 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001975
1976 codec->patch_ops = conexant_patch_ops;
1977 codec->patch_ops.init = cxt5051_init;
1978
1979 spec->multiout.max_channels = 2;
1980 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1981 spec->multiout.dac_nids = cxt5051_dac_nids;
1982 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1983 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1984 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001985 spec->num_mixers = 2;
1986 spec->mixers[0] = cxt5051_capture_mixers;
1987 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001988 spec->num_init_verbs = 1;
1989 spec->init_verbs[0] = cxt5051_init_verbs;
1990 spec->spdif_route = 0;
1991 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1992 spec->channel_mode = cxt5051_modes;
1993 spec->cur_adc = 0;
1994 spec->cur_adc_idx = 0;
1995
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001996 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1997
Takashi Iwai79d7d532009-03-04 09:03:50 +01001998 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1999
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002000 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002001 switch (board_config) {
2002 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002003 spec->mixers[0] = cxt5051_hp_mixers;
2004 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002005 case CXT5051_HP_DV6736:
2006 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2007 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002008 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002009 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002010 case CXT5051_LENOVO_X200:
2011 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002012 /* Thinkpad X301 does not have S/PDIF wired and no ability
2013 to use a docking station. */
2014 if (codec->subsystem_id == 0x17aa211f)
2015 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002016 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002017 case CXT5051_F700:
2018 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2019 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002020 spec->auto_mic = 0;
2021 break;
2022 case CXT5051_TOSHIBA:
2023 spec->mixers[0] = cxt5051_toshiba_mixers;
2024 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002025 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002026 case CXT5051_IDEAPAD:
2027 spec->init_verbs[spec->num_init_verbs++] =
2028 cxt5051_ideapad_init_verbs;
2029 spec->ideapad = 1;
2030 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002031 }
2032
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002033 if (spec->beep_amp)
2034 snd_hda_attach_beep_device(codec, spec->beep_amp);
2035
Takashi Iwai461e2c72008-01-25 11:35:17 +01002036 return 0;
2037}
2038
Daniel Drake0fb67e92009-07-16 14:46:57 +01002039/* Conexant 5066 specific */
2040
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002041static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2042static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2043static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2044static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002045
Daniel Drakedbaccc02009-11-09 15:17:24 +00002046/* OLPC's microphone port is DC coupled for use with external sensors,
2047 * therefore we use a 50% mic bias in order to center the input signal with
2048 * the DC input range of the codec. */
2049#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2050
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002051static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002052 { 2, NULL },
2053};
2054
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002055#define HP_PRESENT_PORT_A (1 << 0)
2056#define HP_PRESENT_PORT_D (1 << 1)
2057#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2058#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2059
Daniel Drake0fb67e92009-07-16 14:46:57 +01002060static void cxt5066_update_speaker(struct hda_codec *codec)
2061{
2062 struct conexant_spec *spec = codec->spec;
2063 unsigned int pinctl;
2064
John Baboval3a253442010-12-02 11:21:31 -05002065 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2066 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002067
2068 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002069 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002070 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2071 pinctl);
2072
2073 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002074 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2075 if (spec->dell_automute || spec->thinkpad) {
2076 /* Mute if Port A is connected */
2077 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002078 pinctl = 0;
2079 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002080 /* Thinkpad/Dell doesn't give pin-D status */
2081 if (!hp_port_d_present(spec))
2082 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002083 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002084 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2085 pinctl);
2086
2087 /* CLASS_D AMP */
2088 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2089 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2090 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002091}
2092
2093/* turn on/off EAPD (+ mute HP) as a master switch */
2094static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2095 struct snd_ctl_elem_value *ucontrol)
2096{
2097 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2098
2099 if (!cxt_eapd_put(kcontrol, ucontrol))
2100 return 0;
2101
2102 cxt5066_update_speaker(codec);
2103 return 1;
2104}
2105
Daniel Drakec4cfe662010-01-07 13:47:04 +01002106static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2107 .num_items = 3,
2108 .items = {
2109 { "Off", PIN_IN },
2110 { "50%", PIN_VREF50 },
2111 { "80%", PIN_VREF80 },
2112 },
2113};
2114
2115static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2116{
2117 struct conexant_spec *spec = codec->spec;
2118 /* Even though port F is the DC input, the bias is controlled on port B.
2119 * we also leave that port as an active input (but unselected) in DC mode
2120 * just in case that is necessary to make the bias setting take effect. */
2121 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2122 AC_VERB_SET_PIN_WIDGET_CONTROL,
2123 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2124}
2125
Daniel Drake75f89912010-01-07 13:46:25 +01002126/* OLPC defers mic widget control until when capture is started because the
2127 * microphone LED comes on as soon as these settings are put in place. if we
2128 * did this before recording, it would give the false indication that recording
2129 * is happening when it is not. */
2130static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002131{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002132 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002133 if (!spec->recording)
2134 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002135
Daniel Drakec4cfe662010-01-07 13:47:04 +01002136 if (spec->dc_enable) {
2137 /* in DC mode we ignore presence detection and just use the jack
2138 * through our special DC port */
2139 const struct hda_verb enable_dc_mode[] = {
2140 /* disble internal mic, port C */
2141 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2142
2143 /* enable DC capture, port F */
2144 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2145 {},
2146 };
2147
2148 snd_hda_sequence_write(codec, enable_dc_mode);
2149 /* port B input disabled (and bias set) through the following call */
2150 cxt5066_set_olpc_dc_bias(codec);
2151 return;
2152 }
2153
2154 /* disable DC (port F) */
2155 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2156
Daniel Drake75f89912010-01-07 13:46:25 +01002157 /* external mic, port B */
2158 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2159 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002160
Daniel Drake75f89912010-01-07 13:46:25 +01002161 /* internal mic, port C */
2162 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2163 spec->ext_mic_present ? 0 : PIN_VREF80);
2164}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002165
Daniel Drake75f89912010-01-07 13:46:25 +01002166/* toggle input of built-in and mic jack appropriately */
2167static void cxt5066_olpc_automic(struct hda_codec *codec)
2168{
2169 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002170 unsigned int present;
2171
Daniel Drakec4cfe662010-01-07 13:47:04 +01002172 if (spec->dc_enable) /* don't do presence detection in DC mode */
2173 return;
2174
Daniel Drake75f89912010-01-07 13:46:25 +01002175 present = snd_hda_codec_read(codec, 0x1a, 0,
2176 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2177 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002178 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002179 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002180 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002181
2182 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2183 present ? 0 : 1);
2184 spec->ext_mic_present = !!present;
2185
2186 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002187}
2188
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002189/* toggle input of built-in digital mic and mic jack appropriately */
2190static void cxt5066_vostro_automic(struct hda_codec *codec)
2191{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002192 unsigned int present;
2193
2194 struct hda_verb ext_mic_present[] = {
2195 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002196 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002197
2198 /* switch to external mic input */
2199 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2200 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2201
2202 /* disable internal digital mic */
2203 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2204 {}
2205 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002206 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002207 /* enable internal mic, port C */
2208 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2209
2210 /* switch to internal mic input */
2211 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2212
2213 /* disable external mic, port B */
2214 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2215 {}
2216 };
2217
2218 present = snd_hda_jack_detect(codec, 0x1a);
2219 if (present) {
2220 snd_printdd("CXT5066: external microphone detected\n");
2221 snd_hda_sequence_write(codec, ext_mic_present);
2222 } else {
2223 snd_printdd("CXT5066: external microphone absent\n");
2224 snd_hda_sequence_write(codec, ext_mic_absent);
2225 }
2226}
2227
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002228/* toggle input of built-in digital mic and mic jack appropriately */
2229static void cxt5066_ideapad_automic(struct hda_codec *codec)
2230{
2231 unsigned int present;
2232
2233 struct hda_verb ext_mic_present[] = {
2234 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2235 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2236 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2237 {}
2238 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002239 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002240 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2241 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2242 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2243 {}
2244 };
2245
2246 present = snd_hda_jack_detect(codec, 0x1b);
2247 if (present) {
2248 snd_printdd("CXT5066: external microphone detected\n");
2249 snd_hda_sequence_write(codec, ext_mic_present);
2250 } else {
2251 snd_printdd("CXT5066: external microphone absent\n");
2252 snd_hda_sequence_write(codec, ext_mic_absent);
2253 }
2254}
2255
David Henningssona1d69062011-01-21 13:33:28 +01002256
2257/* toggle input of built-in digital mic and mic jack appropriately */
2258static void cxt5066_asus_automic(struct hda_codec *codec)
2259{
2260 unsigned int present;
2261
2262 present = snd_hda_jack_detect(codec, 0x1b);
2263 snd_printdd("CXT5066: external microphone present=%d\n", present);
2264 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2265 present ? 1 : 0);
2266}
2267
2268
David Henningsson048e78a2010-09-02 08:35:47 +02002269/* toggle input of built-in digital mic and mic jack appropriately */
2270static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2271{
2272 unsigned int present;
2273
2274 present = snd_hda_jack_detect(codec, 0x1b);
2275 snd_printdd("CXT5066: external microphone present=%d\n", present);
2276 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2277 present ? 1 : 3);
2278}
2279
2280
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002281/* toggle input of built-in digital mic and mic jack appropriately
2282 order is: external mic -> dock mic -> interal mic */
2283static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2284{
2285 unsigned int ext_present, dock_present;
2286
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002287 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002288 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2289 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2290 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2291 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2292 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2293 {}
2294 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002295 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002296 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2297 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2298 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2299 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2300 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2301 {}
2302 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002303 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002304 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2305 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2306 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2307 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2308 {}
2309 };
2310
2311 ext_present = snd_hda_jack_detect(codec, 0x1b);
2312 dock_present = snd_hda_jack_detect(codec, 0x1a);
2313 if (ext_present) {
2314 snd_printdd("CXT5066: external microphone detected\n");
2315 snd_hda_sequence_write(codec, ext_mic_present);
2316 } else if (dock_present) {
2317 snd_printdd("CXT5066: dock microphone detected\n");
2318 snd_hda_sequence_write(codec, dock_mic_present);
2319 } else {
2320 snd_printdd("CXT5066: external microphone absent\n");
2321 snd_hda_sequence_write(codec, ext_mic_absent);
2322 }
2323}
2324
Daniel Drake0fb67e92009-07-16 14:46:57 +01002325/* mute internal speaker if HP is plugged */
2326static void cxt5066_hp_automute(struct hda_codec *codec)
2327{
2328 struct conexant_spec *spec = codec->spec;
2329 unsigned int portA, portD;
2330
2331 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002332 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002333
2334 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002335 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002336
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002337 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2338 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002339 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2340 portA, portD, spec->hp_present);
2341 cxt5066_update_speaker(codec);
2342}
2343
David Henningsson02b6b5b2011-01-21 13:27:39 +01002344/* Dispatch the right mic autoswitch function */
2345static void cxt5066_automic(struct hda_codec *codec)
2346{
2347 struct conexant_spec *spec = codec->spec;
2348
2349 if (spec->dell_vostro)
2350 cxt5066_vostro_automic(codec);
2351 else if (spec->ideapad)
2352 cxt5066_ideapad_automic(codec);
2353 else if (spec->thinkpad)
2354 cxt5066_thinkpad_automic(codec);
2355 else if (spec->hp_laptop)
2356 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002357 else if (spec->asus)
2358 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002359}
2360
Daniel Drake0fb67e92009-07-16 14:46:57 +01002361/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002362static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002363{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002364 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002365 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2366 switch (res >> 26) {
2367 case CONEXANT_HP_EVENT:
2368 cxt5066_hp_automute(codec);
2369 break;
2370 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002371 /* ignore mic events in DC mode; we're always using the jack */
2372 if (!spec->dc_enable)
2373 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002374 break;
2375 }
2376}
2377
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002378/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002379static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002380{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002381 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002382 switch (res >> 26) {
2383 case CONEXANT_HP_EVENT:
2384 cxt5066_hp_automute(codec);
2385 break;
2386 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002387 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002388 break;
2389 }
2390}
2391
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002392
Daniel Drake0fb67e92009-07-16 14:46:57 +01002393static const struct hda_input_mux cxt5066_analog_mic_boost = {
2394 .num_items = 5,
2395 .items = {
2396 { "0dB", 0 },
2397 { "10dB", 1 },
2398 { "20dB", 2 },
2399 { "30dB", 3 },
2400 { "40dB", 4 },
2401 },
2402};
2403
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002404static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002405{
2406 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002407 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002408 AC_VERB_SET_AMP_GAIN_MUTE,
2409 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2410 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002411 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002412 /* adjust the internal mic as well...it is not through 0x17 */
2413 snd_hda_codec_write_cache(codec, 0x23, 0,
2414 AC_VERB_SET_AMP_GAIN_MUTE,
2415 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2416 cxt5066_analog_mic_boost.
2417 items[spec->mic_boost].index);
2418 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002419}
2420
Daniel Drake0fb67e92009-07-16 14:46:57 +01002421static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2422 struct snd_ctl_elem_info *uinfo)
2423{
2424 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2425}
2426
2427static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2428 struct snd_ctl_elem_value *ucontrol)
2429{
2430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002431 struct conexant_spec *spec = codec->spec;
2432 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002433 return 0;
2434}
2435
2436static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_value *ucontrol)
2438{
2439 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002440 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002441 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2442 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002443 idx = ucontrol->value.enumerated.item[0];
2444 if (idx >= imux->num_items)
2445 idx = imux->num_items - 1;
2446
Daniel Drakec4cfe662010-01-07 13:47:04 +01002447 spec->mic_boost = idx;
2448 if (!spec->dc_enable)
2449 cxt5066_set_mic_boost(codec);
2450 return 1;
2451}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002452
Daniel Drakec4cfe662010-01-07 13:47:04 +01002453static void cxt5066_enable_dc(struct hda_codec *codec)
2454{
2455 const struct hda_verb enable_dc_mode[] = {
2456 /* disable gain */
2457 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2458
2459 /* switch to DC input */
2460 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2461 {}
2462 };
2463
2464 /* configure as input source */
2465 snd_hda_sequence_write(codec, enable_dc_mode);
2466 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2467}
2468
2469static void cxt5066_disable_dc(struct hda_codec *codec)
2470{
2471 /* reconfigure input source */
2472 cxt5066_set_mic_boost(codec);
2473 /* automic also selects the right mic if we're recording */
2474 cxt5066_olpc_automic(codec);
2475}
2476
2477static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2478 struct snd_ctl_elem_value *ucontrol)
2479{
2480 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2481 struct conexant_spec *spec = codec->spec;
2482 ucontrol->value.integer.value[0] = spec->dc_enable;
2483 return 0;
2484}
2485
2486static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2487 struct snd_ctl_elem_value *ucontrol)
2488{
2489 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2490 struct conexant_spec *spec = codec->spec;
2491 int dc_enable = !!ucontrol->value.integer.value[0];
2492
2493 if (dc_enable == spec->dc_enable)
2494 return 0;
2495
2496 spec->dc_enable = dc_enable;
2497 if (dc_enable)
2498 cxt5066_enable_dc(codec);
2499 else
2500 cxt5066_disable_dc(codec);
2501
2502 return 1;
2503}
2504
2505static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2506 struct snd_ctl_elem_info *uinfo)
2507{
2508 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2509}
2510
2511static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2512 struct snd_ctl_elem_value *ucontrol)
2513{
2514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2515 struct conexant_spec *spec = codec->spec;
2516 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2517 return 0;
2518}
2519
2520static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2521 struct snd_ctl_elem_value *ucontrol)
2522{
2523 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2524 struct conexant_spec *spec = codec->spec;
2525 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2526 unsigned int idx;
2527
2528 idx = ucontrol->value.enumerated.item[0];
2529 if (idx >= imux->num_items)
2530 idx = imux->num_items - 1;
2531
2532 spec->dc_input_bias = idx;
2533 if (spec->dc_enable)
2534 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002535 return 1;
2536}
2537
Daniel Drake75f89912010-01-07 13:46:25 +01002538static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2539{
2540 struct conexant_spec *spec = codec->spec;
2541 /* mark as recording and configure the microphone widget so that the
2542 * recording LED comes on. */
2543 spec->recording = 1;
2544 cxt5066_olpc_select_mic(codec);
2545}
2546
2547static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2548{
2549 struct conexant_spec *spec = codec->spec;
2550 const struct hda_verb disable_mics[] = {
2551 /* disable external mic, port B */
2552 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2553
2554 /* disble internal mic, port C */
2555 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002556
2557 /* disable DC capture, port F */
2558 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002559 {},
2560 };
2561
2562 snd_hda_sequence_write(codec, disable_mics);
2563 spec->recording = 0;
2564}
2565
Andy Robinsonf6a24912011-01-24 10:12:37 -05002566static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002567 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002568 int num_pins)
2569{
2570 struct conexant_spec *spec = codec->spec;
2571 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2572 int i;
2573
2574 for (i = 0; i < num_pins; i++, dig_pins++) {
2575 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2576 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2577 continue;
2578 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2579 continue;
2580 if (spec->slave_dig_outs[0])
2581 nid_loc++;
2582 else
2583 nid_loc = spec->slave_dig_outs;
2584 }
2585}
2586
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002587static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002588 .num_items = 4,
2589 .items = {
2590 { "Mic B", 0 },
2591 { "Mic C", 1 },
2592 { "Mic E", 2 },
2593 { "Mic F", 3 },
2594 },
2595};
2596
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002597static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002598 .ops = &snd_hda_bind_vol,
2599 .values = {
2600 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2601 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2602 0
2603 },
2604};
2605
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002606static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002607 .ops = &snd_hda_bind_sw,
2608 .values = {
2609 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2610 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2611 0
2612 },
2613};
2614
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002615static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002616 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2617 {}
2618};
2619
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002620static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002621 {
2622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2623 .name = "Master Playback Volume",
2624 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2625 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2626 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002627 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002628 .info = snd_hda_mixer_amp_volume_info,
2629 .get = snd_hda_mixer_amp_volume_get,
2630 .put = snd_hda_mixer_amp_volume_put,
2631 .tlv = { .c = snd_hda_mixer_amp_tlv },
2632 /* offset by 28 volume steps to limit minimum gain to -46dB */
2633 .private_value =
2634 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2635 },
2636 {}
2637};
2638
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002639static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002640 {
2641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2642 .name = "DC Mode Enable Switch",
2643 .info = snd_ctl_boolean_mono_info,
2644 .get = cxt5066_olpc_dc_get,
2645 .put = cxt5066_olpc_dc_put,
2646 },
2647 {
2648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2649 .name = "DC Input Bias Enum",
2650 .info = cxt5066_olpc_dc_bias_enum_info,
2651 .get = cxt5066_olpc_dc_bias_enum_get,
2652 .put = cxt5066_olpc_dc_bias_enum_put,
2653 },
2654 {}
2655};
2656
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002657static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002658 {
2659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2660 .name = "Master Playback Switch",
2661 .info = cxt_eapd_info,
2662 .get = cxt_eapd_get,
2663 .put = cxt5066_hp_master_sw_put,
2664 .private_value = 0x1d,
2665 },
2666
2667 {
2668 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002669 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002670 .info = cxt5066_mic_boost_mux_enum_info,
2671 .get = cxt5066_mic_boost_mux_enum_get,
2672 .put = cxt5066_mic_boost_mux_enum_put,
2673 },
2674
2675 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2676 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2677 {}
2678};
2679
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002680static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002681 {
2682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002683 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002684 .info = cxt5066_mic_boost_mux_enum_info,
2685 .get = cxt5066_mic_boost_mux_enum_get,
2686 .put = cxt5066_mic_boost_mux_enum_put,
2687 .private_value = 0x23 | 0x100,
2688 },
2689 {}
2690};
2691
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002692static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002693 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2694 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2695 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2696 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2697
2698 /* Speakers */
2699 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2700 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2701
2702 /* HP, Amp */
2703 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2704 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2705
2706 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2707 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2708
2709 /* DAC1 */
2710 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2711
2712 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2713 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2714 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2715 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2716 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2718
2719 /* no digital microphone support yet */
2720 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2721
2722 /* Audio input selector */
2723 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2724
2725 /* SPDIF route: PCM */
2726 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2727 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2728
2729 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2730 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2731
2732 /* EAPD */
2733 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2734
2735 /* not handling these yet */
2736 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2737 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2738 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2739 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2740 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2741 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2742 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 { } /* end */
2745};
2746
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002747static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002748 /* Port A: headphones */
2749 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2750 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2751
2752 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002753 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002754
2755 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002756 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002757
2758 /* Port D: unused */
2759 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2760
2761 /* Port E: unused, but has primary EAPD */
2762 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2763 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2764
Daniel Drakec4cfe662010-01-07 13:47:04 +01002765 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002766 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2767
2768 /* Port G: internal speakers */
2769 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2770 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2771
2772 /* DAC1 */
2773 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2774
2775 /* DAC2: unused */
2776 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2777
2778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2782 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2784 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2785 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2786 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2787 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2788 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2789 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2790
2791 /* Disable digital microphone port */
2792 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2793
2794 /* Audio input selectors */
2795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2796 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2797
2798 /* Disable SPDIF */
2799 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2800 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2801
2802 /* enable unsolicited events for Port A and B */
2803 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2804 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2805 { } /* end */
2806};
2807
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002808static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002809 /* Port A: headphones */
2810 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2811 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2812
2813 /* Port B: external microphone */
2814 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815
2816 /* Port C: unused */
2817 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818
2819 /* Port D: unused */
2820 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821
2822 /* Port E: unused, but has primary EAPD */
2823 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2825
2826 /* Port F: unused */
2827 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2828
2829 /* Port G: internal speakers */
2830 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2831 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2832
2833 /* DAC1 */
2834 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2835
2836 /* DAC2: unused */
2837 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2838
2839 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2840 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2843 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2844 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2846 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2847 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2848 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2851
2852 /* Digital microphone port */
2853 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2854
2855 /* Audio input selectors */
2856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2857 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2858
2859 /* Disable SPDIF */
2860 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2861 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2862
2863 /* enable unsolicited events for Port A and B */
2864 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2865 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2866 { } /* end */
2867};
2868
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002869static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002870 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2871 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2872 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2873 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2874
2875 /* Speakers */
2876 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2877 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2878
2879 /* HP, Amp */
2880 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2881 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2882
2883 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2884 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2885
2886 /* DAC1 */
2887 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2888
2889 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2891 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2893 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2894 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2895 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2896
2897 /* Audio input selector */
2898 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2899 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2900
2901 /* SPDIF route: PCM */
2902 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2903 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2904
2905 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2906 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2907
2908 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002909 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002910
2911 /* EAPD */
2912 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2913
2914 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2915 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2916 { } /* end */
2917};
2918
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002919static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002920 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2921 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2922
2923 /* Port G: internal speakers */
2924 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2925 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2926
2927 /* Port A: HP, Amp */
2928 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2929 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2930
2931 /* Port B: Mic Dock */
2932 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2933
2934 /* Port C: Mic */
2935 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2936
2937 /* Port D: HP Dock, Amp */
2938 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2939 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2940
2941 /* DAC1 */
2942 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2943
2944 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2945 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2946 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2947 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2948 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2949 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2950 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2951
2952 /* Audio input selector */
2953 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2954 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2955
2956 /* SPDIF route: PCM */
2957 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2958 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2959
2960 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2961 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2962
2963 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002964 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002965
2966 /* EAPD */
2967 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2968
2969 /* enable unsolicited events for Port A, B, C and D */
2970 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2971 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2972 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2973 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2974 { } /* end */
2975};
2976
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002977static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002978 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2979 { } /* end */
2980};
2981
David Henningsson048e78a2010-09-02 08:35:47 +02002982
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002983static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002984 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2985 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2986 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2987 { } /* end */
2988};
2989
Daniel Drake0fb67e92009-07-16 14:46:57 +01002990/* initialize jack-sensing, too */
2991static int cxt5066_init(struct hda_codec *codec)
2992{
2993 snd_printdd("CXT5066: init\n");
2994 conexant_init(codec);
2995 if (codec->patch_ops.unsol_event) {
2996 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002997 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002998 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002999 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003000 return 0;
3001}
3002
Daniel Drake75f89912010-01-07 13:46:25 +01003003static int cxt5066_olpc_init(struct hda_codec *codec)
3004{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003005 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003006 snd_printdd("CXT5066: init\n");
3007 conexant_init(codec);
3008 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003009 if (!spec->dc_enable) {
3010 cxt5066_set_mic_boost(codec);
3011 cxt5066_olpc_automic(codec);
3012 } else {
3013 cxt5066_enable_dc(codec);
3014 }
Daniel Drake75f89912010-01-07 13:46:25 +01003015 return 0;
3016}
3017
Daniel Drake0fb67e92009-07-16 14:46:57 +01003018enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003019 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003020 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3021 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003022 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003023 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003024 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003025 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003026 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003027 CXT5066_MODELS
3028};
3029
Takashi Iwaiea734962011-01-17 11:29:34 +01003030static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003031 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3033 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003034 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003035 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003036 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003037 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003038 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003039};
3040
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003041static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003042 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003043 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003044 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003045 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003046 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003047 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003048 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3049 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003050 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003051 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003052 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003053 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003054 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003055 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003056 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003057 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3058 CXT5066_LAPTOP),
3059 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003060 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003061 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003062 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003063 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003064 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003065 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003066 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003067 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003068 {}
3069};
3070
3071static int patch_cxt5066(struct hda_codec *codec)
3072{
3073 struct conexant_spec *spec;
3074 int board_config;
3075
3076 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3077 if (!spec)
3078 return -ENOMEM;
3079 codec->spec = spec;
3080
3081 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003082 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003083
3084 spec->dell_automute = 0;
3085 spec->multiout.max_channels = 2;
3086 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3087 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003088 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3089 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003090 spec->num_adc_nids = 1;
3091 spec->adc_nids = cxt5066_adc_nids;
3092 spec->capsrc_nids = cxt5066_capsrc_nids;
3093 spec->input_mux = &cxt5066_capture_source;
3094
3095 spec->port_d_mode = PIN_HP;
3096
3097 spec->num_init_verbs = 1;
3098 spec->init_verbs[0] = cxt5066_init_verbs;
3099 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3100 spec->channel_mode = cxt5066_modes;
3101 spec->cur_adc = 0;
3102 spec->cur_adc_idx = 0;
3103
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003104 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3105
Daniel Drake0fb67e92009-07-16 14:46:57 +01003106 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3107 cxt5066_models, cxt5066_cfg_tbl);
3108 switch (board_config) {
3109 default:
3110 case CXT5066_LAPTOP:
3111 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3112 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3113 break;
3114 case CXT5066_DELL_LAPTOP:
3115 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3116 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3117
3118 spec->port_d_mode = PIN_OUT;
3119 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3120 spec->num_init_verbs++;
3121 spec->dell_automute = 1;
3122 break;
David Henningssona1d69062011-01-21 13:33:28 +01003123 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003124 case CXT5066_HP_LAPTOP:
3125 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003126 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003127 spec->init_verbs[spec->num_init_verbs] =
3128 cxt5066_init_verbs_hp_laptop;
3129 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003130 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3131 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003132 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3133 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3134 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003135 if (board_config == CXT5066_HP_LAPTOP)
3136 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003137 /* input source automatically selected */
3138 spec->input_mux = NULL;
3139 spec->port_d_mode = 0;
3140 spec->mic_boost = 3; /* default 30dB gain */
3141 break;
3142
Daniel Drake0fb67e92009-07-16 14:46:57 +01003143 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003144 codec->patch_ops.init = cxt5066_olpc_init;
3145 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003146 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003148 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003149 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3150 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003151 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003152
3153 /* no S/PDIF out */
3154 spec->multiout.dig_out_nid = 0;
3155
3156 /* input source automatically selected */
3157 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003158
3159 /* our capture hooks which allow us to turn on the microphone LED
3160 * at the right time */
3161 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3162 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003163 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003164 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003165 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003166 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003167 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3168 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3169 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003170 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003171 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003172 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003173 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003174
3175 /* no S/PDIF out */
3176 spec->multiout.dig_out_nid = 0;
3177
3178 /* input source automatically selected */
3179 spec->input_mux = NULL;
3180 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003181 case CXT5066_IDEAPAD:
3182 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003183 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003184 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3185 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3186 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3187 spec->port_d_mode = 0;
3188 spec->ideapad = 1;
3189 spec->mic_boost = 2; /* default 20dB gain */
3190
3191 /* no S/PDIF out */
3192 spec->multiout.dig_out_nid = 0;
3193
3194 /* input source automatically selected */
3195 spec->input_mux = NULL;
3196 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003197 case CXT5066_THINKPAD:
3198 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003199 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003200 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3201 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3202 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3203 spec->thinkpad = 1;
3204 spec->port_d_mode = PIN_OUT;
3205 spec->mic_boost = 2; /* default 20dB gain */
3206
3207 /* no S/PDIF out */
3208 spec->multiout.dig_out_nid = 0;
3209
3210 /* input source automatically selected */
3211 spec->input_mux = NULL;
3212 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003213 }
3214
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003215 if (spec->beep_amp)
3216 snd_hda_attach_beep_device(codec, spec->beep_amp);
3217
Daniel Drake0fb67e92009-07-16 14:46:57 +01003218 return 0;
3219}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003220
3221/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003222 * Automatic parser for CX20641 & co
3223 */
3224
Takashi Iwai6764bce2011-05-13 16:52:25 +02003225static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3226 struct hda_codec *codec,
3227 unsigned int stream_tag,
3228 unsigned int format,
3229 struct snd_pcm_substream *substream)
3230{
3231 struct conexant_spec *spec = codec->spec;
3232 hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]];
3233 if (spec->adc_switching) {
3234 spec->cur_adc = adc;
3235 spec->cur_adc_stream_tag = stream_tag;
3236 spec->cur_adc_format = format;
3237 }
3238 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3239 return 0;
3240}
3241
3242static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3243 struct hda_codec *codec,
3244 struct snd_pcm_substream *substream)
3245{
3246 struct conexant_spec *spec = codec->spec;
3247 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3248 spec->cur_adc = 0;
3249 return 0;
3250}
3251
3252static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3253 .substreams = 1,
3254 .channels_min = 2,
3255 .channels_max = 2,
3256 .nid = 0, /* fill later */
3257 .ops = {
3258 .prepare = cx_auto_capture_pcm_prepare,
3259 .cleanup = cx_auto_capture_pcm_cleanup
3260 },
3261};
3262
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003263static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003264
3265/* get the connection index of @nid in the widget @mux */
3266static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3267 hda_nid_t nid)
3268{
3269 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3270 int i, nums;
3271
3272 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3273 for (i = 0; i < nums; i++)
3274 if (conn[i] == nid)
3275 return i;
3276 return -1;
3277}
3278
Takashi Iwai6764bce2011-05-13 16:52:25 +02003279static int has_multi_connection(struct hda_codec *codec, hda_nid_t mux)
3280{
3281 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3282 int nums;
3283
3284 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3285 return nums > 1;
3286}
3287
Takashi Iwaif2e57312010-09-15 10:07:08 +02003288/* get an unassigned DAC from the given list.
3289 * Return the nid if found and reduce the DAC list, or return zero if
3290 * not found
3291 */
3292static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3293 hda_nid_t *dacs, int *num_dacs)
3294{
3295 int i, nums = *num_dacs;
3296 hda_nid_t ret = 0;
3297
3298 for (i = 0; i < nums; i++) {
3299 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3300 ret = dacs[i];
3301 break;
3302 }
3303 }
3304 if (!ret)
3305 return 0;
3306 if (--nums > 0)
3307 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3308 *num_dacs = nums;
3309 return ret;
3310}
3311
3312#define MAX_AUTO_DACS 5
3313
3314/* fill analog DAC list from the widget tree */
3315static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3316{
3317 hda_nid_t nid, end_nid;
3318 int nums = 0;
3319
3320 end_nid = codec->start_nid + codec->num_nodes;
3321 for (nid = codec->start_nid; nid < end_nid; nid++) {
3322 unsigned int wcaps = get_wcaps(codec, nid);
3323 unsigned int type = get_wcaps_type(wcaps);
3324 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3325 dacs[nums++] = nid;
3326 if (nums >= MAX_AUTO_DACS)
3327 break;
3328 }
3329 }
3330 return nums;
3331}
3332
3333/* fill pin_dac_pair list from the pin and dac list */
3334static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3335 int num_pins, hda_nid_t *dacs, int *rest,
3336 struct pin_dac_pair *filled, int type)
3337{
3338 int i, nums;
3339
3340 nums = 0;
3341 for (i = 0; i < num_pins; i++) {
3342 filled[nums].pin = pins[i];
3343 filled[nums].type = type;
3344 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3345 nums++;
3346 }
3347 return nums;
3348}
3349
3350/* parse analog output paths */
3351static void cx_auto_parse_output(struct hda_codec *codec)
3352{
3353 struct conexant_spec *spec = codec->spec;
3354 struct auto_pin_cfg *cfg = &spec->autocfg;
3355 hda_nid_t dacs[MAX_AUTO_DACS];
3356 int i, j, nums, rest;
3357
3358 rest = fill_cx_auto_dacs(codec, dacs);
3359 /* parse all analog output pins */
3360 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3361 dacs, &rest, spec->dac_info,
3362 AUTO_PIN_LINE_OUT);
3363 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3364 dacs, &rest, spec->dac_info + nums,
3365 AUTO_PIN_HP_OUT);
3366 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3367 dacs, &rest, spec->dac_info + nums,
3368 AUTO_PIN_SPEAKER_OUT);
3369 spec->dac_info_filled = nums;
3370 /* fill multiout struct */
3371 for (i = 0; i < nums; i++) {
3372 hda_nid_t dac = spec->dac_info[i].dac;
3373 if (!dac)
3374 continue;
3375 switch (spec->dac_info[i].type) {
3376 case AUTO_PIN_LINE_OUT:
3377 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3378 spec->multiout.num_dacs++;
3379 break;
3380 case AUTO_PIN_HP_OUT:
3381 case AUTO_PIN_SPEAKER_OUT:
3382 if (!spec->multiout.hp_nid) {
3383 spec->multiout.hp_nid = dac;
3384 break;
3385 }
3386 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3387 if (!spec->multiout.extra_out_nid[j]) {
3388 spec->multiout.extra_out_nid[j] = dac;
3389 break;
3390 }
3391 break;
3392 }
3393 }
3394 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003395 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003396
3397 if (cfg->hp_outs > 0)
3398 spec->auto_mute = 1;
3399 spec->vmaster_nid = spec->private_dac_nids[0];
3400}
3401
Takashi Iwaida339862011-05-13 16:24:15 +02003402static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3403 hda_nid_t *pins, bool on);
3404
Takashi Iwaif2e57312010-09-15 10:07:08 +02003405/* auto-mute/unmute speaker and line outs according to headphone jack */
3406static void cx_auto_hp_automute(struct hda_codec *codec)
3407{
3408 struct conexant_spec *spec = codec->spec;
3409 struct auto_pin_cfg *cfg = &spec->autocfg;
3410 int i, present;
3411
3412 if (!spec->auto_mute)
3413 return;
3414 present = 0;
3415 for (i = 0; i < cfg->hp_outs; i++) {
3416 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3417 present = 1;
3418 break;
3419 }
3420 }
Takashi Iwaida339862011-05-13 16:24:15 +02003421 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003422 for (i = 0; i < cfg->line_outs; i++) {
3423 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3424 AC_VERB_SET_PIN_WIDGET_CONTROL,
3425 present ? 0 : PIN_OUT);
3426 }
Takashi Iwaida339862011-05-13 16:24:15 +02003427 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003428 for (i = 0; !present && i < cfg->line_outs; i++)
3429 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3430 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003431 for (i = 0; i < cfg->speaker_outs; i++) {
3432 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3433 AC_VERB_SET_PIN_WIDGET_CONTROL,
3434 present ? 0 : PIN_OUT);
3435 }
Takashi Iwaida339862011-05-13 16:24:15 +02003436 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003437}
3438
Takashi Iwai6764bce2011-05-13 16:52:25 +02003439static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3440 struct snd_ctl_elem_info *uinfo)
3441{
3442 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3443 struct conexant_spec *spec = codec->spec;
3444
3445 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3446}
3447
3448static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3449 struct snd_ctl_elem_value *ucontrol)
3450{
3451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3452 struct conexant_spec *spec = codec->spec;
3453
3454 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3455 return 0;
3456}
3457
3458static int cx_auto_mux_enum_update(struct hda_codec *codec,
3459 const struct hda_input_mux *imux,
3460 unsigned int idx)
3461{
3462 struct conexant_spec *spec = codec->spec;
3463 hda_nid_t adc;
3464
3465 if (!imux->num_items)
3466 return 0;
3467 if (idx >= imux->num_items)
3468 idx = imux->num_items - 1;
3469 if (spec->cur_mux[0] == idx)
3470 return 0;
3471 adc = spec->imux_adcs[idx];
3472 if (has_multi_connection(codec, adc))
3473 snd_hda_codec_write(codec, adc, 0,
3474 AC_VERB_SET_CONNECT_SEL,
3475 imux->items[idx].index);
3476 if (spec->cur_adc && spec->cur_adc != adc) {
3477 /* stream is running, let's swap the current ADC */
3478 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3479 spec->cur_adc = adc;
3480 snd_hda_codec_setup_stream(codec, adc,
3481 spec->cur_adc_stream_tag, 0,
3482 spec->cur_adc_format);
3483 }
3484 spec->cur_mux[0] = idx;
3485 return 1;
3486}
3487
3488static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3489 struct snd_ctl_elem_value *ucontrol)
3490{
3491 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3492 struct conexant_spec *spec = codec->spec;
3493
3494 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3495 ucontrol->value.enumerated.item[0]);
3496}
3497
3498static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3499 {
3500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3501 .name = "Capture Source",
3502 .info = cx_auto_mux_enum_info,
3503 .get = cx_auto_mux_enum_get,
3504 .put = cx_auto_mux_enum_put
3505 },
3506 {}
3507};
3508
Takashi Iwaif2e57312010-09-15 10:07:08 +02003509/* automatic switch internal and external mic */
3510static void cx_auto_automic(struct hda_codec *codec)
3511{
3512 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003513 int ext_idx = spec->auto_mic_ext;
3514
3515 if (!spec->auto_mic)
3516 return;
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003517 if (snd_hda_jack_detect(codec, spec->imux_pins[ext_idx]))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003518 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3519 else
3520 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003521}
3522
3523static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3524{
3525 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3526 switch (res >> 26) {
3527 case CONEXANT_HP_EVENT:
3528 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003529 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003530 break;
3531 case CONEXANT_MIC_EVENT:
3532 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003533 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003534 break;
3535 }
3536}
3537
Takashi Iwaif2e57312010-09-15 10:07:08 +02003538/* return true if it's an internal-mic pin */
3539static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3540{
3541 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3542 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003543 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003544}
3545
3546/* return true if it's an external-mic pin */
3547static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3548{
3549 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3550 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003551 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3552 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003553}
3554
3555/* check whether the pin config is suitable for auto-mic switching;
3556 * auto-mic is enabled only when one int-mic and one-ext mic exist
3557 */
3558static void cx_auto_check_auto_mic(struct hda_codec *codec)
3559{
3560 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003561
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003562 if (is_ext_mic(codec, spec->imux_pins[0]) &&
3563 is_int_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003564 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003565 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003566 return;
3567 }
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003568 if (is_int_mic(codec, spec->imux_pins[0]) &&
3569 is_ext_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003570 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003571 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003572 return;
3573 }
3574}
3575
3576static void cx_auto_parse_input(struct hda_codec *codec)
3577{
3578 struct conexant_spec *spec = codec->spec;
3579 struct auto_pin_cfg *cfg = &spec->autocfg;
3580 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003581 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003582
3583 imux = &spec->private_imux;
3584 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003585 for (j = 0; j < spec->num_adc_nids; j++) {
3586 hda_nid_t adc = spec->adc_nids[j];
3587 int idx = get_connection_index(codec, adc,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003588 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003589 if (idx >= 0) {
3590 const char *label;
3591 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003592 spec->imux_adcs[imux->num_items] = adc;
3593 spec->imux_pins[imux->num_items] =
3594 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003595 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003596 break;
3597 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003598 }
3599 }
3600 if (imux->num_items == 2 && cfg->num_inputs == 2)
3601 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003602 if (imux->num_items > 1 && !spec->auto_mic) {
3603 for (i = 1; i < imux->num_items; i++) {
3604 if (spec->imux_adcs[i] != spec->imux_adcs[0]) {
3605 spec->adc_switching = 1;
3606 break;
3607 }
3608 }
3609 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003610}
3611
3612/* get digital-input audio widget corresponding to the given pin */
3613static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3614{
3615 hda_nid_t nid, end_nid;
3616
3617 end_nid = codec->start_nid + codec->num_nodes;
3618 for (nid = codec->start_nid; nid < end_nid; nid++) {
3619 unsigned int wcaps = get_wcaps(codec, nid);
3620 unsigned int type = get_wcaps_type(wcaps);
3621 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3622 if (get_connection_index(codec, nid, pin) >= 0)
3623 return nid;
3624 }
3625 }
3626 return 0;
3627}
3628
3629static void cx_auto_parse_digital(struct hda_codec *codec)
3630{
3631 struct conexant_spec *spec = codec->spec;
3632 struct auto_pin_cfg *cfg = &spec->autocfg;
3633 hda_nid_t nid;
3634
3635 if (cfg->dig_outs &&
3636 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3637 spec->multiout.dig_out_nid = nid;
3638 if (cfg->dig_in_pin)
3639 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3640}
3641
3642#ifdef CONFIG_SND_HDA_INPUT_BEEP
3643static void cx_auto_parse_beep(struct hda_codec *codec)
3644{
3645 struct conexant_spec *spec = codec->spec;
3646 hda_nid_t nid, end_nid;
3647
3648 end_nid = codec->start_nid + codec->num_nodes;
3649 for (nid = codec->start_nid; nid < end_nid; nid++)
3650 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3651 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3652 break;
3653 }
3654}
3655#else
3656#define cx_auto_parse_beep(codec)
3657#endif
3658
3659static int cx_auto_parse_auto_config(struct hda_codec *codec)
3660{
3661 struct conexant_spec *spec = codec->spec;
3662 int err;
3663
3664 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3665 if (err < 0)
3666 return err;
3667
3668 cx_auto_parse_output(codec);
3669 cx_auto_parse_input(codec);
3670 cx_auto_parse_digital(codec);
3671 cx_auto_parse_beep(codec);
3672 return 0;
3673}
3674
Takashi Iwaida339862011-05-13 16:24:15 +02003675static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3676 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003677{
3678 int i;
3679 for (i = 0; i < num_pins; i++) {
3680 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3681 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003682 AC_VERB_SET_EAPD_BTLENABLE,
3683 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003684 }
3685}
3686
3687static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3688 hda_nid_t src)
3689{
3690 int idx = get_connection_index(codec, pin, src);
3691 if (idx >= 0)
3692 snd_hda_codec_write(codec, pin, 0,
3693 AC_VERB_SET_CONNECT_SEL, idx);
3694}
3695
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003696static void mute_outputs(struct hda_codec *codec, int num_nids,
3697 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003698{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003699 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003700
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003701 for (i = 0; i < num_nids; i++) {
3702 hda_nid_t nid = nids[i];
3703 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3704 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003705 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3706 val = AMP_OUT_MUTE;
3707 else
3708 val = AMP_OUT_ZERO;
3709 snd_hda_codec_write(codec, nid, 0,
3710 AC_VERB_SET_AMP_GAIN_MUTE, val);
3711 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003712}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003713
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003714static void cx_auto_init_output(struct hda_codec *codec)
3715{
3716 struct conexant_spec *spec = codec->spec;
3717 struct auto_pin_cfg *cfg = &spec->autocfg;
3718 hda_nid_t nid;
3719 int i;
3720
3721 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003722 for (i = 0; i < cfg->hp_outs; i++)
3723 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3724 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003725 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3726 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3727 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003728 if (spec->auto_mute) {
3729 for (i = 0; i < cfg->hp_outs; i++) {
3730 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3731 AC_VERB_SET_UNSOLICITED_ENABLE,
3732 AC_USRSP_EN | CONEXANT_HP_EVENT);
3733 }
3734 cx_auto_hp_automute(codec);
3735 } else {
3736 for (i = 0; i < cfg->line_outs; i++)
3737 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3738 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3739 for (i = 0; i < cfg->speaker_outs; i++)
3740 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3741 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003742 /* turn on EAPD */
3743 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3744 true);
3745 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3746 true);
3747 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3748 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003749 }
3750
3751 for (i = 0; i < spec->dac_info_filled; i++) {
3752 nid = spec->dac_info[i].dac;
3753 if (!nid)
3754 nid = spec->multiout.dac_nids[0];
3755 select_connection(codec, spec->dac_info[i].pin, nid);
3756 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003757}
3758
3759static void cx_auto_init_input(struct hda_codec *codec)
3760{
3761 struct conexant_spec *spec = codec->spec;
3762 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003763 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003764
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003765 for (i = 0; i < spec->num_adc_nids; i++) {
3766 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003767 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3768 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003769 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3770 val = AMP_IN_MUTE(0);
3771 else
3772 val = AMP_IN_UNMUTE(0);
3773 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3774 val);
3775 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003776
3777 for (i = 0; i < cfg->num_inputs; i++) {
3778 unsigned int type;
3779 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3780 type = PIN_VREF80;
3781 else
3782 type = PIN_IN;
3783 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3784 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3785 }
3786
3787 if (spec->auto_mic) {
3788 int ext_idx = spec->auto_mic_ext;
3789 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3790 AC_VERB_SET_UNSOLICITED_ENABLE,
3791 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3792 cx_auto_automic(codec);
3793 } else {
3794 for (i = 0; i < spec->num_adc_nids; i++) {
3795 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3796 AC_VERB_SET_CONNECT_SEL,
3797 spec->private_imux.items[0].index);
3798 }
3799 }
3800}
3801
3802static void cx_auto_init_digital(struct hda_codec *codec)
3803{
3804 struct conexant_spec *spec = codec->spec;
3805 struct auto_pin_cfg *cfg = &spec->autocfg;
3806
3807 if (spec->multiout.dig_out_nid)
3808 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3809 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3810 if (spec->dig_in_nid)
3811 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3812 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3813}
3814
3815static int cx_auto_init(struct hda_codec *codec)
3816{
3817 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3818 cx_auto_init_output(codec);
3819 cx_auto_init_input(codec);
3820 cx_auto_init_digital(codec);
3821 return 0;
3822}
3823
David Henningsson983345e2011-02-15 19:57:09 +01003824static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003825 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003826 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003827{
3828 static char name[32];
3829 static struct snd_kcontrol_new knew[] = {
3830 HDA_CODEC_VOLUME(name, 0, 0, 0),
3831 HDA_CODEC_MUTE(name, 0, 0, 0),
3832 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003833 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003834 int i, err;
3835
3836 for (i = 0; i < 2; i++) {
3837 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003838 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3839 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003840 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3841 knew[i].index = cidx;
3842 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3843 kctl = snd_ctl_new1(&knew[i], codec);
3844 if (!kctl)
3845 return -ENOMEM;
3846 err = snd_hda_ctl_add(codec, nid, kctl);
3847 if (err < 0)
3848 return err;
3849 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3850 break;
3851 }
3852 return 0;
3853}
3854
David Henningsson983345e2011-02-15 19:57:09 +01003855#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3856 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3857
Takashi Iwaif2e57312010-09-15 10:07:08 +02003858#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3859 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3860
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003861static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3862 hda_nid_t pin, const char *name, int idx)
3863{
3864 unsigned int caps;
3865 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3866 if (caps & AC_AMPCAP_NUM_STEPS)
3867 return cx_auto_add_pb_volume(codec, dac, name, idx);
3868 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3869 if (caps & AC_AMPCAP_NUM_STEPS)
3870 return cx_auto_add_pb_volume(codec, pin, name, idx);
3871 return 0;
3872}
3873
Takashi Iwaif2e57312010-09-15 10:07:08 +02003874static int cx_auto_build_output_controls(struct hda_codec *codec)
3875{
3876 struct conexant_spec *spec = codec->spec;
3877 int i, err;
3878 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003879 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003880
3881 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003882 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3883 spec->dac_info[0].pin,
3884 "Master", 0);
3885
Takashi Iwaif2e57312010-09-15 10:07:08 +02003886 for (i = 0; i < spec->dac_info_filled; i++) {
3887 const char *label;
3888 int idx, type;
3889 if (!spec->dac_info[i].dac)
3890 continue;
3891 type = spec->dac_info[i].type;
3892 if (type == AUTO_PIN_LINE_OUT)
3893 type = spec->autocfg.line_out_type;
3894 switch (type) {
3895 case AUTO_PIN_LINE_OUT:
3896 default:
3897 label = texts[num_line++];
3898 idx = 0;
3899 break;
3900 case AUTO_PIN_HP_OUT:
3901 label = "Headphone";
3902 idx = num_hp++;
3903 break;
3904 case AUTO_PIN_SPEAKER_OUT:
3905 label = "Speaker";
3906 idx = num_spk++;
3907 break;
3908 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003909 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3910 spec->dac_info[i].pin,
3911 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003912 if (err < 0)
3913 return err;
3914 }
3915 return 0;
3916}
3917
Takashi Iwai6764bce2011-05-13 16:52:25 +02003918static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3919 const char *label, const char *pfx,
3920 int cidx)
3921{
3922 struct conexant_spec *spec = codec->spec;
3923 int i;
3924
3925 for (i = 0; i < spec->num_adc_nids; i++) {
3926 hda_nid_t adc_nid = spec->adc_nids[i];
3927 int idx = get_connection_index(codec, adc_nid, nid);
3928 if (idx < 0)
3929 continue;
3930 return cx_auto_add_volume_idx(codec, label, pfx,
3931 cidx, adc_nid, HDA_INPUT, idx);
3932 }
3933 return 0;
3934}
3935
Takashi Iwaif2e57312010-09-15 10:07:08 +02003936static int cx_auto_build_input_controls(struct hda_codec *codec)
3937{
3938 struct conexant_spec *spec = codec->spec;
3939 struct auto_pin_cfg *cfg = &spec->autocfg;
3940 static const char *prev_label;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003941 int i, err, cidx;
David Henningsson983345e2011-02-15 19:57:09 +01003942
Takashi Iwaif2e57312010-09-15 10:07:08 +02003943 prev_label = NULL;
3944 cidx = 0;
3945 for (i = 0; i < cfg->num_inputs; i++) {
3946 hda_nid_t nid = cfg->inputs[i].pin;
3947 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01003948 int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
David Henningsson983345e2011-02-15 19:57:09 +01003949
Takashi Iwaif2e57312010-09-15 10:07:08 +02003950 label = hda_get_autocfg_input_label(codec, cfg, i);
3951 if (label == prev_label)
3952 cidx++;
3953 else
3954 cidx = 0;
3955 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01003956
3957 if (pin_amp) {
3958 err = cx_auto_add_volume(codec, label, " Boost", cidx,
3959 nid, HDA_INPUT);
3960 if (err < 0)
3961 return err;
3962 }
3963
Takashi Iwai6764bce2011-05-13 16:52:25 +02003964 if (cfg->num_inputs == 1) {
3965 err = cx_auto_add_capture_volume(codec, nid,
3966 "Capture", "", cidx);
3967 } else {
3968 err = cx_auto_add_capture_volume(codec, nid,
3969 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01003970 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02003971 if (err < 0)
3972 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003973 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02003974
3975 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
3976 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
3977 if (err < 0)
3978 return err;
3979 }
3980
Takashi Iwaif2e57312010-09-15 10:07:08 +02003981 return 0;
3982}
3983
3984static int cx_auto_build_controls(struct hda_codec *codec)
3985{
3986 int err;
3987
3988 err = cx_auto_build_output_controls(codec);
3989 if (err < 0)
3990 return err;
3991 err = cx_auto_build_input_controls(codec);
3992 if (err < 0)
3993 return err;
3994 return conexant_build_controls(codec);
3995}
3996
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003997static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003998 .build_controls = cx_auto_build_controls,
3999 .build_pcms = conexant_build_pcms,
4000 .init = cx_auto_init,
4001 .free = conexant_free,
4002 .unsol_event = cx_auto_unsol_event,
4003#ifdef CONFIG_SND_HDA_POWER_SAVE
4004 .suspend = conexant_suspend,
4005#endif
4006 .reboot_notify = snd_hda_shutup_pins,
4007};
4008
4009static int patch_conexant_auto(struct hda_codec *codec)
4010{
4011 struct conexant_spec *spec;
4012 int err;
4013
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004014 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4015 codec->chip_name);
4016
Takashi Iwaif2e57312010-09-15 10:07:08 +02004017 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4018 if (!spec)
4019 return -ENOMEM;
4020 codec->spec = spec;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004021 switch (codec->vendor_id) {
4022 case 0x14f15051:
Takashi Iwai6764bce2011-05-13 16:52:25 +02004023 codec->pin_amp_workaround = 1;
4024 spec->adc_nids = cxt5051_adc_nids;
4025 spec->num_adc_nids = ARRAY_SIZE(cxt5051_adc_nids);
4026 spec->capsrc_nids = spec->adc_nids;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004027 break;
4028 case 0x14f15045:
4029 codec->pin_amp_workaround = 1;
4030 spec->adc_nids = cxt5045_adc_nids;
4031 spec->num_adc_nids = ARRAY_SIZE(cxt5045_adc_nids);
4032 spec->capsrc_nids = spec->adc_nids;
4033 break;
4034 default:
Takashi Iwai6764bce2011-05-13 16:52:25 +02004035 spec->adc_nids = cx_auto_adc_nids;
4036 spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
4037 spec->capsrc_nids = spec->adc_nids;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004038 break;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004039 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004040 err = cx_auto_parse_auto_config(codec);
4041 if (err < 0) {
4042 kfree(codec->spec);
4043 codec->spec = NULL;
4044 return err;
4045 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004046 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004047 codec->patch_ops = cx_auto_patch_ops;
4048 if (spec->beep_amp)
4049 snd_hda_attach_beep_device(codec, spec->beep_amp);
4050 return 0;
4051}
4052
4053/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004054 */
4055
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004056static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004057 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4058 .patch = patch_cxt5045 },
4059 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4060 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004061 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4062 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004063 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4064 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004065 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4066 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004067 { .id = 0x14f15068, .name = "CX20584",
4068 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004069 { .id = 0x14f15069, .name = "CX20585",
4070 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004071 { .id = 0x14f1506e, .name = "CX20590",
4072 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004073 { .id = 0x14f15097, .name = "CX20631",
4074 .patch = patch_conexant_auto },
4075 { .id = 0x14f15098, .name = "CX20632",
4076 .patch = patch_conexant_auto },
4077 { .id = 0x14f150a1, .name = "CX20641",
4078 .patch = patch_conexant_auto },
4079 { .id = 0x14f150a2, .name = "CX20642",
4080 .patch = patch_conexant_auto },
4081 { .id = 0x14f150ab, .name = "CX20651",
4082 .patch = patch_conexant_auto },
4083 { .id = 0x14f150ac, .name = "CX20652",
4084 .patch = patch_conexant_auto },
4085 { .id = 0x14f150b8, .name = "CX20664",
4086 .patch = patch_conexant_auto },
4087 { .id = 0x14f150b9, .name = "CX20665",
4088 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004089 {} /* terminator */
4090};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004091
4092MODULE_ALIAS("snd-hda-codec-id:14f15045");
4093MODULE_ALIAS("snd-hda-codec-id:14f15047");
4094MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004095MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004096MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004097MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004098MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004099MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004100MODULE_ALIAS("snd-hda-codec-id:14f15097");
4101MODULE_ALIAS("snd-hda-codec-id:14f15098");
4102MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4103MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4104MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4105MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4106MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4107MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004108
4109MODULE_LICENSE("GPL");
4110MODULE_DESCRIPTION("Conexant HD-audio codec");
4111
4112static struct hda_codec_preset_list conexant_list = {
4113 .preset = snd_hda_preset_conexant,
4114 .owner = THIS_MODULE,
4115};
4116
4117static int __init patch_conexant_init(void)
4118{
4119 return snd_hda_add_codec_preset(&conexant_list);
4120}
4121
4122static void __exit patch_conexant_exit(void)
4123{
4124 snd_hda_delete_codec_preset(&conexant_list);
4125}
4126
4127module_init(patch_conexant_init)
4128module_exit(patch_conexant_exit)