blob: 217ca9e13425137fc7b35f1de705e5d896a50b6f [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020042#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010043
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010044/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010045
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010046#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010047#define CXT5051_PORTB_EVENT 0x38
48#define CXT5051_PORTC_EVENT 0x39
49
Takashi Iwaifaddaa52010-01-23 22:31:36 +010050#define AUTO_MIC_PORTB (1 << 1)
51#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010052
Takashi Iwaif2e57312010-09-15 10:07:08 +020053struct pin_dac_pair {
54 hda_nid_t pin;
55 hda_nid_t dac;
56 int type;
57};
58
Takashi Iwai47ad1f42011-05-17 09:15:55 +020059struct imux_info {
60 hda_nid_t pin; /* input pin NID */
61 hda_nid_t adc; /* connected ADC NID */
62 hda_nid_t boost; /* optional boost volume NID */
63 int index; /* corresponding to autocfg.input */
64};
65
Tobin Davisc9b443d2006-11-14 12:13:39 +010066struct conexant_spec {
67
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020068 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010069 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010070 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010071
72 const struct hda_verb *init_verbs[5]; /* initialization verbs
73 * don't forget NULL
74 * termination!
75 */
76 unsigned int num_init_verbs;
77
78 /* playback */
79 struct hda_multi_out multiout; /* playback set-up
80 * max_channels, dacs must be set
81 * dig_out_nid and hp_nid are optional
82 */
83 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010084 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020085 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010086 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020087 int auto_mic_ext; /* imux_pins[] index for ext mic */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +020088 int auto_mic_dock; /* imux_pins[] index for dock mic */
89 int auto_mic_int; /* imux_pins[] index for int mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010090 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050091 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010092
93 /* capture */
94 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020095 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010096 hda_nid_t dig_in_nid; /* digital-in NID; optional */
97
Takashi Iwai461e2c72008-01-25 11:35:17 +010098 unsigned int cur_adc_idx;
99 hda_nid_t cur_adc;
100 unsigned int cur_adc_stream_tag;
101 unsigned int cur_adc_format;
102
Takashi Iwai6764bce2011-05-13 16:52:25 +0200103 const struct hda_pcm_stream *capture_stream;
104
Tobin Davisc9b443d2006-11-14 12:13:39 +0100105 /* capture source */
106 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200107 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100108 unsigned int cur_mux[3];
109
110 /* channel model */
111 const struct hda_channel_mode *channel_mode;
112 int num_channel_mode;
113
114 /* PCM information */
115 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
116
Tobin Davisc9b443d2006-11-14 12:13:39 +0100117 unsigned int spdif_route;
118
119 /* dynamic controls, init_verbs and input_mux */
120 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100121 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200122 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200123 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200124 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200125 struct pin_dac_pair dac_info[8];
126 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100127
Daniel Drake0fb67e92009-07-16 14:46:57 +0100128 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200129 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200130 unsigned int detect_line:1; /* Line-out detection enabled */
131 unsigned int automute_lines:1; /* automute line-out as well */
132 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200133 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500134 unsigned int dell_vostro:1;
135 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200136 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200137 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100138 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100139
Takashi Iwai6764bce2011-05-13 16:52:25 +0200140 unsigned int adc_switching:1;
141
Daniel Drake75f89912010-01-07 13:46:25 +0100142 unsigned int ext_mic_present;
143 unsigned int recording;
144 void (*capture_prepare)(struct hda_codec *codec);
145 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100146
147 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
148 * through the microphone jack.
149 * When the user enables this through a mixer switch, both internal and
150 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
151 * we also allow the bias to be configured through a separate mixer
152 * control. */
153 unsigned int dc_enable;
154 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
155 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200156
157 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100158};
159
160static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 struct snd_pcm_substream *substream)
163{
164 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100165 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
166 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100167}
168
169static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
170 struct hda_codec *codec,
171 unsigned int stream_tag,
172 unsigned int format,
173 struct snd_pcm_substream *substream)
174{
175 struct conexant_spec *spec = codec->spec;
176 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
177 stream_tag,
178 format, substream);
179}
180
181static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
182 struct hda_codec *codec,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
187}
188
189/*
190 * Digital out
191 */
192static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
193 struct hda_codec *codec,
194 struct snd_pcm_substream *substream)
195{
196 struct conexant_spec *spec = codec->spec;
197 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
198}
199
200static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
201 struct hda_codec *codec,
202 struct snd_pcm_substream *substream)
203{
204 struct conexant_spec *spec = codec->spec;
205 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
206}
207
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200208static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
209 struct hda_codec *codec,
210 unsigned int stream_tag,
211 unsigned int format,
212 struct snd_pcm_substream *substream)
213{
214 struct conexant_spec *spec = codec->spec;
215 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
216 stream_tag,
217 format, substream);
218}
219
Tobin Davisc9b443d2006-11-14 12:13:39 +0100220/*
221 * Analog capture
222 */
223static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
224 struct hda_codec *codec,
225 unsigned int stream_tag,
226 unsigned int format,
227 struct snd_pcm_substream *substream)
228{
229 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100230 if (spec->capture_prepare)
231 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100232 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
233 stream_tag, 0, format);
234 return 0;
235}
236
237static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
238 struct hda_codec *codec,
239 struct snd_pcm_substream *substream)
240{
241 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100242 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100243 if (spec->capture_cleanup)
244 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100245 return 0;
246}
247
248
249
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200250static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100251 .substreams = 1,
252 .channels_min = 2,
253 .channels_max = 2,
254 .nid = 0, /* fill later */
255 .ops = {
256 .open = conexant_playback_pcm_open,
257 .prepare = conexant_playback_pcm_prepare,
258 .cleanup = conexant_playback_pcm_cleanup
259 },
260};
261
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200262static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100263 .substreams = 1,
264 .channels_min = 2,
265 .channels_max = 2,
266 .nid = 0, /* fill later */
267 .ops = {
268 .prepare = conexant_capture_pcm_prepare,
269 .cleanup = conexant_capture_pcm_cleanup
270 },
271};
272
273
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200274static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100275 .substreams = 1,
276 .channels_min = 2,
277 .channels_max = 2,
278 .nid = 0, /* fill later */
279 .ops = {
280 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200281 .close = conexant_dig_playback_pcm_close,
282 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100283 },
284};
285
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200286static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100287 .substreams = 1,
288 .channels_min = 2,
289 .channels_max = 2,
290 /* NID is set in alc_build_pcms */
291};
292
Takashi Iwai461e2c72008-01-25 11:35:17 +0100293static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
294 struct hda_codec *codec,
295 unsigned int stream_tag,
296 unsigned int format,
297 struct snd_pcm_substream *substream)
298{
299 struct conexant_spec *spec = codec->spec;
300 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
301 spec->cur_adc_stream_tag = stream_tag;
302 spec->cur_adc_format = format;
303 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
304 return 0;
305}
306
307static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
308 struct hda_codec *codec,
309 struct snd_pcm_substream *substream)
310{
311 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100312 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100313 spec->cur_adc = 0;
314 return 0;
315}
316
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200317static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100318 .substreams = 1,
319 .channels_min = 2,
320 .channels_max = 2,
321 .nid = 0, /* fill later */
322 .ops = {
323 .prepare = cx5051_capture_pcm_prepare,
324 .cleanup = cx5051_capture_pcm_cleanup
325 },
326};
327
Tobin Davisc9b443d2006-11-14 12:13:39 +0100328static int conexant_build_pcms(struct hda_codec *codec)
329{
330 struct conexant_spec *spec = codec->spec;
331 struct hda_pcm *info = spec->pcm_rec;
332
333 codec->num_pcms = 1;
334 codec->pcm_info = info;
335
336 info->name = "CONEXANT Analog";
337 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
338 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
339 spec->multiout.max_channels;
340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
341 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200342 if (spec->capture_stream)
343 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
344 else {
345 if (codec->vendor_id == 0x14f15051)
346 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
347 cx5051_pcm_analog_capture;
348 else {
349 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
350 conexant_pcm_analog_capture;
351 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
352 spec->num_adc_nids;
353 }
354 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100355 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
356
357 if (spec->multiout.dig_out_nid) {
358 info++;
359 codec->num_pcms++;
360 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100361 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100362 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
363 conexant_pcm_digital_playback;
364 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
365 spec->multiout.dig_out_nid;
366 if (spec->dig_in_nid) {
367 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
368 conexant_pcm_digital_capture;
369 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
370 spec->dig_in_nid;
371 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500372 if (spec->slave_dig_outs[0])
373 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100374 }
375
376 return 0;
377}
378
379static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_info *uinfo)
381{
382 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
383 struct conexant_spec *spec = codec->spec;
384
385 return snd_hda_input_mux_info(spec->input_mux, uinfo);
386}
387
388static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_value *ucontrol)
390{
391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
392 struct conexant_spec *spec = codec->spec;
393 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
394
395 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
396 return 0;
397}
398
399static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
400 struct snd_ctl_elem_value *ucontrol)
401{
402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
403 struct conexant_spec *spec = codec->spec;
404 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
405
406 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
407 spec->capsrc_nids[adc_idx],
408 &spec->cur_mux[adc_idx]);
409}
410
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100411static int conexant_init_jacks(struct hda_codec *codec)
412{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100413#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100414 struct conexant_spec *spec = codec->spec;
415 int i;
416
417 for (i = 0; i < spec->num_init_verbs; i++) {
418 const struct hda_verb *hv;
419
420 hv = spec->init_verbs[i];
421 while (hv->nid) {
422 int err = 0;
423 switch (hv->param ^ AC_USRSP_EN) {
424 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100425 err = snd_hda_input_jack_add(codec, hv->nid,
426 SND_JACK_HEADPHONE, NULL);
427 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100428 break;
429 case CXT5051_PORTC_EVENT:
430 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100431 err = snd_hda_input_jack_add(codec, hv->nid,
432 SND_JACK_MICROPHONE, NULL);
433 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100434 break;
435 }
436 if (err < 0)
437 return err;
438 ++hv;
439 }
440 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100441#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100442 return 0;
443}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100444
Tobin Davisc9b443d2006-11-14 12:13:39 +0100445static int conexant_init(struct hda_codec *codec)
446{
447 struct conexant_spec *spec = codec->spec;
448 int i;
449
450 for (i = 0; i < spec->num_init_verbs; i++)
451 snd_hda_sequence_write(codec, spec->init_verbs[i]);
452 return 0;
453}
454
455static void conexant_free(struct hda_codec *codec)
456{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100457 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200458 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100459 kfree(codec->spec);
460}
461
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200462static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100463 {
464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
465 .name = "Capture Source",
466 .info = conexant_mux_enum_info,
467 .get = conexant_mux_enum_get,
468 .put = conexant_mux_enum_put
469 },
470 {}
471};
472
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200473#ifdef CONFIG_SND_HDA_INPUT_BEEP
474/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200475static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200476 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
477 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
478 { } /* end */
479};
480#endif
481
Takashi Iwaiea734962011-01-17 11:29:34 +0100482static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100483 "Headphone Playback Volume",
484 "Speaker Playback Volume",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200485 "Front Playback Volume",
486 "Surround Playback Volume",
487 "CLFE Playback Volume",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100488 NULL
489};
490
Takashi Iwaiea734962011-01-17 11:29:34 +0100491static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100492 "Headphone Playback Switch",
493 "Speaker Playback Switch",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200494 "Front Playback Switch",
495 "Surround Playback Switch",
496 "CLFE Playback Switch",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100497 NULL
498};
499
Tobin Davisc9b443d2006-11-14 12:13:39 +0100500static int conexant_build_controls(struct hda_codec *codec)
501{
502 struct conexant_spec *spec = codec->spec;
503 unsigned int i;
504 int err;
505
506 for (i = 0; i < spec->num_mixers; i++) {
507 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
508 if (err < 0)
509 return err;
510 }
511 if (spec->multiout.dig_out_nid) {
512 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600513 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100514 spec->multiout.dig_out_nid);
515 if (err < 0)
516 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100517 err = snd_hda_create_spdif_share_sw(codec,
518 &spec->multiout);
519 if (err < 0)
520 return err;
521 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100522 }
523 if (spec->dig_in_nid) {
524 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
525 if (err < 0)
526 return err;
527 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100528
529 /* if we have no master control, let's create it */
530 if (spec->vmaster_nid &&
531 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
532 unsigned int vmaster_tlv[4];
533 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
534 HDA_OUTPUT, vmaster_tlv);
535 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
536 vmaster_tlv, slave_vols);
537 if (err < 0)
538 return err;
539 }
540 if (spec->vmaster_nid &&
541 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
542 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
543 NULL, slave_sws);
544 if (err < 0)
545 return err;
546 }
547
Takashi Iwaib880c742009-03-10 14:41:05 +0100548 if (spec->input_mux) {
549 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
550 if (err < 0)
551 return err;
552 }
553
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200554#ifdef CONFIG_SND_HDA_INPUT_BEEP
555 /* create beep controls if needed */
556 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200557 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200558 for (knew = cxt_beep_mixer; knew->name; knew++) {
559 struct snd_kcontrol *kctl;
560 kctl = snd_ctl_new1(knew, codec);
561 if (!kctl)
562 return -ENOMEM;
563 kctl->private_value = spec->beep_amp;
564 err = snd_hda_ctl_add(codec, 0, kctl);
565 if (err < 0)
566 return err;
567 }
568 }
569#endif
570
Tobin Davisc9b443d2006-11-14 12:13:39 +0100571 return 0;
572}
573
Takashi Iwai697c3732010-07-30 11:28:02 +0200574#ifdef CONFIG_SND_HDA_POWER_SAVE
575static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
576{
577 snd_hda_shutup_pins(codec);
578 return 0;
579}
580#endif
581
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200582static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583 .build_controls = conexant_build_controls,
584 .build_pcms = conexant_build_pcms,
585 .init = conexant_init,
586 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200587#ifdef CONFIG_SND_HDA_POWER_SAVE
588 .suspend = conexant_suspend,
589#endif
590 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591};
592
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200593#ifdef CONFIG_SND_HDA_INPUT_BEEP
594#define set_beep_amp(spec, nid, idx, dir) \
595 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
596#else
597#define set_beep_amp(spec, nid, idx, dir) /* NOP */
598#endif
599
Takashi Iwai6764bce2011-05-13 16:52:25 +0200600static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601/*
602 * EAPD control
603 * the private value = nid | (invert << 8)
604 */
605
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200606#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100607
Tobin Davis82f30042007-02-13 12:45:44 +0100608static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100609 struct snd_ctl_elem_value *ucontrol)
610{
611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612 struct conexant_spec *spec = codec->spec;
613 int invert = (kcontrol->private_value >> 8) & 1;
614 if (invert)
615 ucontrol->value.integer.value[0] = !spec->cur_eapd;
616 else
617 ucontrol->value.integer.value[0] = spec->cur_eapd;
618 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100619
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620}
621
Tobin Davis82f30042007-02-13 12:45:44 +0100622static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623 struct snd_ctl_elem_value *ucontrol)
624{
625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct conexant_spec *spec = codec->spec;
627 int invert = (kcontrol->private_value >> 8) & 1;
628 hda_nid_t nid = kcontrol->private_value & 0xff;
629 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100630
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100631 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100632 if (invert)
633 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200634 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100635 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100636
Tobin Davisc9b443d2006-11-14 12:13:39 +0100637 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200638 snd_hda_codec_write_cache(codec, nid,
639 0, AC_VERB_SET_EAPD_BTLENABLE,
640 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100641 return 1;
642}
643
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100644/* controls for test mode */
645#ifdef CONFIG_SND_DEBUG
646
Tobin Davis82f30042007-02-13 12:45:44 +0100647#define CXT_EAPD_SWITCH(xname, nid, mask) \
648 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
649 .info = cxt_eapd_info, \
650 .get = cxt_eapd_get, \
651 .put = cxt_eapd_put, \
652 .private_value = nid | (mask<<16) }
653
654
655
Tobin Davisc9b443d2006-11-14 12:13:39 +0100656static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
657 struct snd_ctl_elem_info *uinfo)
658{
659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660 struct conexant_spec *spec = codec->spec;
661 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
662 spec->num_channel_mode);
663}
664
665static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
666 struct snd_ctl_elem_value *ucontrol)
667{
668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
669 struct conexant_spec *spec = codec->spec;
670 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
671 spec->num_channel_mode,
672 spec->multiout.max_channels);
673}
674
675static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
677{
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct conexant_spec *spec = codec->spec;
680 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
681 spec->num_channel_mode,
682 &spec->multiout.max_channels);
683 if (err >= 0 && spec->need_dac_fix)
684 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
685 return err;
686}
687
688#define CXT_PIN_MODE(xname, nid, dir) \
689 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
690 .info = conexant_ch_mode_info, \
691 .get = conexant_ch_mode_get, \
692 .put = conexant_ch_mode_put, \
693 .private_value = nid | (dir<<16) }
694
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100695#endif /* CONFIG_SND_DEBUG */
696
Tobin Davisc9b443d2006-11-14 12:13:39 +0100697/* Conexant 5045 specific */
698
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200699static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
700static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
701static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100702#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100703
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200704static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100705 { 2, NULL },
706};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200708static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100709 .num_items = 2,
710 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100711 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100712 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100713 }
714};
715
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200716static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200717 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100718 .items = {
719 { "IntMic", 0x1 },
720 { "ExtMic", 0x2 },
721 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200722 { "CD", 0x4 },
723 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100724 }
725};
726
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200727static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100728 .num_items = 2,
729 .items = {
730 { "ExtMic", 0x1 },
731 { "IntMic", 0x2 },
732 }
733};
734
Tobin Davisc9b443d2006-11-14 12:13:39 +0100735/* turn on/off EAPD (+ mute HP) as a master switch */
736static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
737 struct snd_ctl_elem_value *ucontrol)
738{
739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
740 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100741 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100742
Tobin Davis82f30042007-02-13 12:45:44 +0100743 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100744 return 0;
745
Tobin Davis82f30042007-02-13 12:45:44 +0100746 /* toggle internal speakers mute depending of presence of
747 * the headphone jack
748 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200749 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
750 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
751 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100752
Takashi Iwai47fd8302007-08-10 17:11:07 +0200753 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
754 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
755 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100756 return 1;
757}
758
759/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200760static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200761 .ops = &snd_hda_bind_vol,
762 .values = {
763 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
764 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
765 0
766 },
767};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100768
Tobin Davis7f296732007-03-12 11:39:01 +0100769/* toggle input of built-in and mic jack appropriately */
770static void cxt5045_hp_automic(struct hda_codec *codec)
771{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200772 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100773 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
774 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
775 {}
776 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200777 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100778 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
780 {}
781 };
782 unsigned int present;
783
Takashi Iwaid56757a2009-11-18 08:00:14 +0100784 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100785 if (present)
786 snd_hda_sequence_write(codec, mic_jack_on);
787 else
788 snd_hda_sequence_write(codec, mic_jack_off);
789}
790
Tobin Davisc9b443d2006-11-14 12:13:39 +0100791
792/* mute internal speaker if HP is plugged */
793static void cxt5045_hp_automute(struct hda_codec *codec)
794{
Tobin Davis82f30042007-02-13 12:45:44 +0100795 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100796 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100797
Takashi Iwaid56757a2009-11-18 08:00:14 +0100798 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100799
Takashi Iwai47fd8302007-08-10 17:11:07 +0200800 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
801 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
802 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100803}
804
805/* unsolicited event for HP jack sensing */
806static void cxt5045_hp_unsol_event(struct hda_codec *codec,
807 unsigned int res)
808{
809 res >>= 26;
810 switch (res) {
811 case CONEXANT_HP_EVENT:
812 cxt5045_hp_automute(codec);
813 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100814 case CONEXANT_MIC_EVENT:
815 cxt5045_hp_automic(codec);
816 break;
817
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 }
819}
820
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200821static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100822 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
823 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100824 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
825 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200826 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
827 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100828 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
829 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100830 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
831 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200832 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100833 {
834 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
835 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100836 .info = cxt_eapd_info,
837 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100838 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100839 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100840 },
841
842 {}
843};
844
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200845static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200846 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
847 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
848 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
849 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
850
Jiang Zhe5218c892008-01-17 11:18:41 +0100851 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
852 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
853 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
854 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
855
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200856 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
857 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
858
Jiang Zhe5218c892008-01-17 11:18:41 +0100859 {}
860};
861
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200862static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100863 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
864 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100865 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
866 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100867 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
868 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100869 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
870 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100871 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
872 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100873 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
874 {
875 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
876 .name = "Master Playback Switch",
877 .info = cxt_eapd_info,
878 .get = cxt_eapd_get,
879 .put = cxt5045_hp_master_sw_put,
880 .private_value = 0x10,
881 },
882
883 {}
884};
885
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200886static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200888 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100889 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100890 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200891 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
892 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
893 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
894 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
895 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
896 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
897 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
898 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
899 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100900 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100901 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100902 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100903 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
904 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100905 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100906 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100907 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100908 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100909 { } /* end */
910};
911
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200912static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100913 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100914 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
915 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
916 /* Line In,HP, Amp */
917 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
918 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
919 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
920 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
921 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
922 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
923 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
924 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
925 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100926 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100927 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
928 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
929 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
930 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100931 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100932 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
933 /* EAPD */
934 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
935 { } /* end */
936};
Tobin Davis7f296732007-03-12 11:39:01 +0100937
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200938static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100939 /* pin sensing on HP jack */
940 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200941 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100942};
943
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200944static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100945 /* pin sensing on HP jack */
946 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200947 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100948};
949
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950#ifdef CONFIG_SND_DEBUG
951/* Test configuration for debugging, modelled after the ALC260 test
952 * configuration.
953 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200954static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100955 .num_items = 5,
956 .items = {
957 { "MIXER", 0x0 },
958 { "MIC1 pin", 0x1 },
959 { "LINE1 pin", 0x2 },
960 { "HP-OUT pin", 0x3 },
961 { "CD pin", 0x4 },
962 },
963};
964
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200965static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100966
967 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100968 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
969 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100970 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
971 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
972 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
973 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100974
975 /* Modes for retasking pin widgets */
976 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
977 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
978
Tobin Davis82f30042007-02-13 12:45:44 +0100979 /* EAPD Switch Control */
980 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
981
Tobin Davisc9b443d2006-11-14 12:13:39 +0100982 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100983
Tobin Davis7f296732007-03-12 11:39:01 +0100984 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
985 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
986 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
987 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
988 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
989 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
990 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
991 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
992 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
993 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100994 {
995 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
996 .name = "Input Source",
997 .info = conexant_mux_enum_info,
998 .get = conexant_mux_enum_get,
999 .put = conexant_mux_enum_put,
1000 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001001 /* Audio input controls */
1002 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1003 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1004 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1005 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1006 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1007 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1008 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1009 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1010 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1011 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012 { } /* end */
1013};
1014
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001015static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001016 /* Set connections */
1017 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1018 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1019 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001020 /* Enable retasking pins as output, initially without power amp */
1021 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001022 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001023
1024 /* Disable digital (SPDIF) pins initially, but users can enable
1025 * them via a mixer switch. In the case of SPDIF-out, this initverb
1026 * payload also sets the generation to 0, output to be in "consumer"
1027 * PCM format, copyright asserted, no pre-emphasis and no validity
1028 * control.
1029 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001030 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1031 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001032
1033 /* Start with output sum widgets muted and their output gains at min */
1034 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1036
1037 /* Unmute retasking pin widget output buffers since the default
1038 * state appears to be output. As the pin mode is changed by the
1039 * user the pin mode control will take care of enabling the pin's
1040 * input/output buffers as needed.
1041 */
1042 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1043 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1044
1045 /* Mute capture amp left and right */
1046 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1047
1048 /* Set ADC connection select to match default mixer setting (mic1
1049 * pin)
1050 */
1051 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001052 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001053
1054 /* Mute all inputs to mixer widget (even unconnected ones) */
1055 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1056 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1057 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1058 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1059 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1060
1061 { }
1062};
1063#endif
1064
1065
1066/* initialize jack-sensing, too */
1067static int cxt5045_init(struct hda_codec *codec)
1068{
1069 conexant_init(codec);
1070 cxt5045_hp_automute(codec);
1071 return 0;
1072}
1073
1074
1075enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001076 CXT5045_LAPTOP_HPSENSE,
1077 CXT5045_LAPTOP_MICSENSE,
1078 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001079 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001080 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001081#ifdef CONFIG_SND_DEBUG
1082 CXT5045_TEST,
1083#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001084 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001085 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086};
1087
Takashi Iwaiea734962011-01-17 11:29:34 +01001088static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001089 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1090 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1091 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1092 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001093 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001094#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001095 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001096#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001097 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001098};
1099
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001100static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001101 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001102 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1103 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001104 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001105 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001106 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1107 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001108 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1109 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001110 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1111 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1112 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001113 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1114 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001115 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116 {}
1117};
1118
1119static int patch_cxt5045(struct hda_codec *codec)
1120{
1121 struct conexant_spec *spec;
1122 int board_config;
1123
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001124 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1125 cxt5045_models,
1126 cxt5045_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001127#if 0 /* use the old method just for safety */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001128 if (board_config < 0)
1129 board_config = CXT5045_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001130#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001131 if (board_config == CXT5045_AUTO)
1132 return patch_conexant_auto(codec);
1133
Tobin Davisc9b443d2006-11-14 12:13:39 +01001134 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1135 if (!spec)
1136 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001138 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001139
1140 spec->multiout.max_channels = 2;
1141 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1142 spec->multiout.dac_nids = cxt5045_dac_nids;
1143 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1144 spec->num_adc_nids = 1;
1145 spec->adc_nids = cxt5045_adc_nids;
1146 spec->capsrc_nids = cxt5045_capsrc_nids;
1147 spec->input_mux = &cxt5045_capture_source;
1148 spec->num_mixers = 1;
1149 spec->mixers[0] = cxt5045_mixers;
1150 spec->num_init_verbs = 1;
1151 spec->init_verbs[0] = cxt5045_init_verbs;
1152 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001153 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1154 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001155
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001156 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157
1158 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001159
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001161 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001162 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001163 spec->input_mux = &cxt5045_capture_source;
1164 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001165 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1166 spec->mixers[0] = cxt5045_mixers;
1167 codec->patch_ops.init = cxt5045_init;
1168 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001169 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001170 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001171 spec->input_mux = &cxt5045_capture_source;
1172 spec->num_init_verbs = 2;
1173 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001174 spec->mixers[0] = cxt5045_mixers;
1175 codec->patch_ops.init = cxt5045_init;
1176 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001177 default:
1178 case CXT5045_LAPTOP_HPMICSENSE:
1179 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1180 spec->input_mux = &cxt5045_capture_source;
1181 spec->num_init_verbs = 3;
1182 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1183 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers;
1185 codec->patch_ops.init = cxt5045_init;
1186 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001187 case CXT5045_BENQ:
1188 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1189 spec->input_mux = &cxt5045_capture_source_benq;
1190 spec->num_init_verbs = 1;
1191 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1192 spec->mixers[0] = cxt5045_mixers;
1193 spec->mixers[1] = cxt5045_benq_mixers;
1194 spec->num_mixers = 2;
1195 codec->patch_ops.init = cxt5045_init;
1196 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001197 case CXT5045_LAPTOP_HP530:
1198 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1199 spec->input_mux = &cxt5045_capture_source_hp530;
1200 spec->num_init_verbs = 2;
1201 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1202 spec->mixers[0] = cxt5045_mixers_hp530;
1203 codec->patch_ops.init = cxt5045_init;
1204 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205#ifdef CONFIG_SND_DEBUG
1206 case CXT5045_TEST:
1207 spec->input_mux = &cxt5045_test_capture_source;
1208 spec->mixers[0] = cxt5045_test_mixer;
1209 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001210 break;
1211
Tobin Davisc9b443d2006-11-14 12:13:39 +01001212#endif
1213 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001214
Takashi Iwai031005f2008-06-26 14:49:58 +02001215 switch (codec->subsystem_id >> 16) {
1216 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001217 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001218 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001219 case 0x17aa:
1220 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1221 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1222 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001223 */
1224 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1225 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1226 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1227 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1228 (1 << AC_AMPCAP_MUTE_SHIFT));
1229 break;
1230 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001231
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001232 if (spec->beep_amp)
1233 snd_hda_attach_beep_device(codec, spec->beep_amp);
1234
Tobin Davisc9b443d2006-11-14 12:13:39 +01001235 return 0;
1236}
1237
1238
1239/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001240#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001242static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1243static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1244static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001246static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001247 { 2, NULL },
1248};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001249
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001250static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001251 .num_items = 2,
1252 .items = {
1253 { "ExtMic", 0x2 },
1254 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001255 }
1256};
1257
1258/* turn on/off EAPD (+ mute HP) as a master switch */
1259static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1260 struct snd_ctl_elem_value *ucontrol)
1261{
1262 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1263 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001264 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001265
Tobin Davis82f30042007-02-13 12:45:44 +01001266 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267 return 0;
1268
Tobin Davis82f30042007-02-13 12:45:44 +01001269 /* toggle internal speakers mute depending of presence of
1270 * the headphone jack
1271 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001272 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001273 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1274 * pin widgets unlike other codecs. In this case, we need to
1275 * set index 0x01 for the volume from the mixer amp 0x19.
1276 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001277 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001278 HDA_AMP_MUTE, bits);
1279 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1280 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1281 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282 return 1;
1283}
1284
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285/* mute internal speaker if HP is plugged */
1286static void cxt5047_hp_automute(struct hda_codec *codec)
1287{
Tobin Davis82f30042007-02-13 12:45:44 +01001288 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001289 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001290
Takashi Iwaid56757a2009-11-18 08:00:14 +01001291 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001292
Takashi Iwai47fd8302007-08-10 17:11:07 +02001293 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001294 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001295 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001296 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297}
1298
1299/* toggle input of built-in and mic jack appropriately */
1300static void cxt5047_hp_automic(struct hda_codec *codec)
1301{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001302 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001303 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1304 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001305 {}
1306 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001307 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001308 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1309 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001310 {}
1311 };
1312 unsigned int present;
1313
Takashi Iwaid56757a2009-11-18 08:00:14 +01001314 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315 if (present)
1316 snd_hda_sequence_write(codec, mic_jack_on);
1317 else
1318 snd_hda_sequence_write(codec, mic_jack_off);
1319}
1320
1321/* unsolicited event for HP jack sensing */
1322static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1323 unsigned int res)
1324{
Marc Boucher9f113e02008-01-22 15:18:08 +01001325 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326 case CONEXANT_HP_EVENT:
1327 cxt5047_hp_automute(codec);
1328 break;
1329 case CONEXANT_MIC_EVENT:
1330 cxt5047_hp_automic(codec);
1331 break;
1332 }
1333}
1334
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001335static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001336 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1337 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001338 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001339 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1340 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1341 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1342 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001343 {
1344 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1345 .name = "Master Playback Switch",
1346 .info = cxt_eapd_info,
1347 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001348 .put = cxt5047_hp_master_sw_put,
1349 .private_value = 0x13,
1350 },
1351
1352 {}
1353};
1354
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001355static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001356 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001357 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001358 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1359 {}
1360};
1361
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001362static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001363 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001364 { } /* end */
1365};
1366
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001367static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001368 /* Line in, Mic, Built-in Mic */
1369 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1370 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1371 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001372 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001373 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001374 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1375 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001376 /* Record selector: Mic */
1377 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1378 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1379 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1380 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1382 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1383 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1384 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001385 /* SPDIF route: PCM */
1386 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001387 /* Enable unsolicited events */
1388 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1389 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001390 { } /* end */
1391};
1392
1393/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001394static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001395 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001396 {}
1397};
1398
1399/* Test configuration for debugging, modelled after the ALC260 test
1400 * configuration.
1401 */
1402#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001403static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001404 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001406 { "LINE1 pin", 0x0 },
1407 { "MIC1 pin", 0x1 },
1408 { "MIC2 pin", 0x2 },
1409 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410 },
1411};
1412
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001413static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414
1415 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001416 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1418 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001420 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001424 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001428
1429 /* Modes for retasking pin widgets */
1430 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1431 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1432
Tobin Davis82f30042007-02-13 12:45:44 +01001433 /* EAPD Switch Control */
1434 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1435
Tobin Davisc9b443d2006-11-14 12:13:39 +01001436 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001437 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1438 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1439 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1440 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1441 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1442 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1443 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1444 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445
Tobin Davis82f30042007-02-13 12:45:44 +01001446 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1447 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1448 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1449 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1450 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1451 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1452 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1453 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001454 {
1455 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1456 .name = "Input Source",
1457 .info = conexant_mux_enum_info,
1458 .get = conexant_mux_enum_get,
1459 .put = conexant_mux_enum_put,
1460 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001461 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001462
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463 { } /* end */
1464};
1465
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001466static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001467 /* Enable retasking pins as output, initially without power amp */
1468 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1469 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1470 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1471
1472 /* Disable digital (SPDIF) pins initially, but users can enable
1473 * them via a mixer switch. In the case of SPDIF-out, this initverb
1474 * payload also sets the generation to 0, output to be in "consumer"
1475 * PCM format, copyright asserted, no pre-emphasis and no validity
1476 * control.
1477 */
1478 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1479
1480 /* Ensure mic1, mic2, line1 pin widgets take input from the
1481 * OUT1 sum bus when acting as an output.
1482 */
1483 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1484 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1485
1486 /* Start with output sum widgets muted and their output gains at min */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1489
1490 /* Unmute retasking pin widget output buffers since the default
1491 * state appears to be output. As the pin mode is changed by the
1492 * user the pin mode control will take care of enabling the pin's
1493 * input/output buffers as needed.
1494 */
1495 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1496 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1497 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498
1499 /* Mute capture amp left and right */
1500 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1501
1502 /* Set ADC connection select to match default mixer setting (mic1
1503 * pin)
1504 */
1505 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1506
1507 /* Mute all inputs to mixer widget (even unconnected ones) */
1508 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1509 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1510 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1511 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1512 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1513 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1514 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1515 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1516
1517 { }
1518};
1519#endif
1520
1521
1522/* initialize jack-sensing, too */
1523static int cxt5047_hp_init(struct hda_codec *codec)
1524{
1525 conexant_init(codec);
1526 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001527 return 0;
1528}
1529
1530
1531enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001532 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1533 CXT5047_LAPTOP_HP, /* Some HP laptops */
1534 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001535#ifdef CONFIG_SND_DEBUG
1536 CXT5047_TEST,
1537#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001538 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001539 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001540};
1541
Takashi Iwaiea734962011-01-17 11:29:34 +01001542static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001543 [CXT5047_LAPTOP] = "laptop",
1544 [CXT5047_LAPTOP_HP] = "laptop-hp",
1545 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001546#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001547 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001548#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001549 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001550};
1551
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001552static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001553 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001554 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1555 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001556 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557 {}
1558};
1559
1560static int patch_cxt5047(struct hda_codec *codec)
1561{
1562 struct conexant_spec *spec;
1563 int board_config;
1564
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001565 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1566 cxt5047_models,
1567 cxt5047_cfg_tbl);
1568#if 0 /* not enabled as default, as BIOS often broken for this codec */
1569 if (board_config < 0)
1570 board_config = CXT5047_AUTO;
1571#endif
1572 if (board_config == CXT5047_AUTO)
1573 return patch_conexant_auto(codec);
1574
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1576 if (!spec)
1577 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001578 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001579 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580
1581 spec->multiout.max_channels = 2;
1582 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1583 spec->multiout.dac_nids = cxt5047_dac_nids;
1584 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1585 spec->num_adc_nids = 1;
1586 spec->adc_nids = cxt5047_adc_nids;
1587 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001588 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001589 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001590 spec->num_init_verbs = 1;
1591 spec->init_verbs[0] = cxt5047_init_verbs;
1592 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001593 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1594 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001595
1596 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001597
Tobin Davisc9b443d2006-11-14 12:13:39 +01001598 switch (board_config) {
1599 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001600 spec->num_mixers = 2;
1601 spec->mixers[1] = cxt5047_hp_spk_mixers;
1602 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001603 break;
1604 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001605 spec->num_mixers = 2;
1606 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001607 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001608 codec->patch_ops.init = cxt5047_hp_init;
1609 break;
1610 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001611 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001612 spec->num_mixers = 2;
1613 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614 spec->num_init_verbs = 2;
1615 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001616 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001617 break;
1618#ifdef CONFIG_SND_DEBUG
1619 case CXT5047_TEST:
1620 spec->input_mux = &cxt5047_test_capture_source;
1621 spec->mixers[0] = cxt5047_test_mixer;
1622 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001623 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001624#endif
1625 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001626 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001627
1628 switch (codec->subsystem_id >> 16) {
1629 case 0x103c:
1630 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1631 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1632 * with 0 dB offset 0x17)
1633 */
1634 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1635 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1636 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1637 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1638 (1 << AC_AMPCAP_MUTE_SHIFT));
1639 break;
1640 }
1641
Tobin Davisc9b443d2006-11-14 12:13:39 +01001642 return 0;
1643}
1644
Takashi Iwai461e2c72008-01-25 11:35:17 +01001645/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001646static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1647static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001648
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001649static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001650 { 2, NULL },
1651};
1652
1653static void cxt5051_update_speaker(struct hda_codec *codec)
1654{
1655 struct conexant_spec *spec = codec->spec;
1656 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001657 /* headphone pin */
1658 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1659 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1660 pinctl);
1661 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1663 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1664 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001665 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1666 if (spec->ideapad)
1667 snd_hda_codec_write(codec, 0x1b, 0,
1668 AC_VERB_SET_PIN_WIDGET_CONTROL,
1669 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001670}
1671
1672/* turn on/off EAPD (+ mute HP) as a master switch */
1673static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1674 struct snd_ctl_elem_value *ucontrol)
1675{
1676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1677
1678 if (!cxt_eapd_put(kcontrol, ucontrol))
1679 return 0;
1680 cxt5051_update_speaker(codec);
1681 return 1;
1682}
1683
1684/* toggle input of built-in and mic jack appropriately */
1685static void cxt5051_portb_automic(struct hda_codec *codec)
1686{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001687 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001688 unsigned int present;
1689
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001690 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001691 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001692 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001693 snd_hda_codec_write(codec, 0x14, 0,
1694 AC_VERB_SET_CONNECT_SEL,
1695 present ? 0x01 : 0x00);
1696}
1697
1698/* switch the current ADC according to the jack state */
1699static void cxt5051_portc_automic(struct hda_codec *codec)
1700{
1701 struct conexant_spec *spec = codec->spec;
1702 unsigned int present;
1703 hda_nid_t new_adc;
1704
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001705 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001706 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001707 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001708 if (present)
1709 spec->cur_adc_idx = 1;
1710 else
1711 spec->cur_adc_idx = 0;
1712 new_adc = spec->adc_nids[spec->cur_adc_idx];
1713 if (spec->cur_adc && spec->cur_adc != new_adc) {
1714 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001715 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001716 spec->cur_adc = new_adc;
1717 snd_hda_codec_setup_stream(codec, new_adc,
1718 spec->cur_adc_stream_tag, 0,
1719 spec->cur_adc_format);
1720 }
1721}
1722
1723/* mute internal speaker if HP is plugged */
1724static void cxt5051_hp_automute(struct hda_codec *codec)
1725{
1726 struct conexant_spec *spec = codec->spec;
1727
Takashi Iwaid56757a2009-11-18 08:00:14 +01001728 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001729 cxt5051_update_speaker(codec);
1730}
1731
1732/* unsolicited event for HP jack sensing */
1733static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1734 unsigned int res)
1735{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001736 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001737 switch (res >> 26) {
1738 case CONEXANT_HP_EVENT:
1739 cxt5051_hp_automute(codec);
1740 break;
1741 case CXT5051_PORTB_EVENT:
1742 cxt5051_portb_automic(codec);
1743 break;
1744 case CXT5051_PORTC_EVENT:
1745 cxt5051_portc_automic(codec);
1746 break;
1747 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001748 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749}
1750
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001751static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001752 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1753 {
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1755 .name = "Master Playback Switch",
1756 .info = cxt_eapd_info,
1757 .get = cxt_eapd_get,
1758 .put = cxt5051_hp_master_sw_put,
1759 .private_value = 0x1a,
1760 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001761 {}
1762};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001763
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001764static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001765 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1766 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001767 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1768 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001769 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1770 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001771 {}
1772};
1773
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001774static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001775 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1776 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001777 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1778 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001779 {}
1780};
1781
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001782static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001783 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1784 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001785 {}
1786};
1787
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001788static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001789 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1790 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001791 {}
1792};
1793
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001794static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001795 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1796 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001797 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1798 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001799 {}
1800};
1801
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001802static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001803 /* Line in, Mic */
1804 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1805 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1806 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1807 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1808 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1809 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1810 /* SPK */
1811 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1812 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1813 /* HP, Amp */
1814 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1815 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1816 /* DAC1 */
1817 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001818 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1821 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1822 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001823 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001824 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1825 /* EAPD */
1826 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1827 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001828 { } /* end */
1829};
1830
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001831static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001832 /* Line in, Mic */
1833 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1834 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1835 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1836 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1837 /* SPK */
1838 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1839 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1840 /* HP, Amp */
1841 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1842 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1843 /* DAC1 */
1844 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001845 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1847 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1848 /* SPDIF route: PCM */
1849 {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},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001853 { } /* end */
1854};
1855
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001856static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001857 /* Line in, Mic */
1858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1859 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1860 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1861 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1862 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1863 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1864 /* SPK */
1865 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1866 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1867 /* HP, Amp */
1868 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1869 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1870 /* Docking HP */
1871 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1872 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1873 /* DAC1 */
1874 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001875 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1877 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1878 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1879 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001880 {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 -05001881 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1882 /* EAPD */
1883 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1884 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001885 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1886 { } /* end */
1887};
1888
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001889static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001890 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001892 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1893 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1894 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1895 /* SPK */
1896 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1897 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1898 /* HP, Amp */
1899 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1900 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1901 /* DAC1 */
1902 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001903 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1905 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1906 /* SPDIF route: PCM */
1907 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1908 /* EAPD */
1909 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1910 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001911 { } /* end */
1912};
1913
Takashi Iwai6953e552010-01-24 11:00:27 +01001914static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1915 unsigned int event)
1916{
1917 snd_hda_codec_write(codec, nid, 0,
1918 AC_VERB_SET_UNSOLICITED_ENABLE,
1919 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001920 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1921 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001922}
1923
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001924static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001925 /* Subwoofer */
1926 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1927 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1928 { } /* end */
1929};
1930
Takashi Iwai461e2c72008-01-25 11:35:17 +01001931/* initialize jack-sensing, too */
1932static int cxt5051_init(struct hda_codec *codec)
1933{
Takashi Iwai6953e552010-01-24 11:00:27 +01001934 struct conexant_spec *spec = codec->spec;
1935
Takashi Iwai461e2c72008-01-25 11:35:17 +01001936 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001937 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001938
1939 if (spec->auto_mic & AUTO_MIC_PORTB)
1940 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1941 if (spec->auto_mic & AUTO_MIC_PORTC)
1942 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1943
Takashi Iwai461e2c72008-01-25 11:35:17 +01001944 if (codec->patch_ops.unsol_event) {
1945 cxt5051_hp_automute(codec);
1946 cxt5051_portb_automic(codec);
1947 cxt5051_portc_automic(codec);
1948 }
1949 return 0;
1950}
1951
1952
1953enum {
1954 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1955 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001956 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001957 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001958 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001959 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001960 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001961 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001962 CXT5051_MODELS
1963};
1964
Takashi Iwaiea734962011-01-17 11:29:34 +01001965static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 [CXT5051_LAPTOP] = "laptop",
1967 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001968 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001969 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001970 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001971 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001972 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001973 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001974};
1975
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001976static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001977 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001978 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001979 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001980 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001981 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1982 CXT5051_LAPTOP),
1983 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001984 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001985 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001986 {}
1987};
1988
1989static int patch_cxt5051(struct hda_codec *codec)
1990{
1991 struct conexant_spec *spec;
1992 int board_config;
1993
Takashi Iwai6764bce2011-05-13 16:52:25 +02001994 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1995 cxt5051_models,
1996 cxt5051_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001997#if 0 /* use the old method just for safety */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001998 if (board_config < 0)
1999 board_config = CXT5051_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02002000#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02002001 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02002002 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02002003
Takashi Iwai461e2c72008-01-25 11:35:17 +01002004 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2005 if (!spec)
2006 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002007 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002008 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002009
2010 codec->patch_ops = conexant_patch_ops;
2011 codec->patch_ops.init = cxt5051_init;
2012
2013 spec->multiout.max_channels = 2;
2014 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2015 spec->multiout.dac_nids = cxt5051_dac_nids;
2016 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2017 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2018 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002019 spec->num_mixers = 2;
2020 spec->mixers[0] = cxt5051_capture_mixers;
2021 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002022 spec->num_init_verbs = 1;
2023 spec->init_verbs[0] = cxt5051_init_verbs;
2024 spec->spdif_route = 0;
2025 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2026 spec->channel_mode = cxt5051_modes;
2027 spec->cur_adc = 0;
2028 spec->cur_adc_idx = 0;
2029
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002030 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2031
Takashi Iwai79d7d532009-03-04 09:03:50 +01002032 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2033
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002034 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002035 switch (board_config) {
2036 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002037 spec->mixers[0] = cxt5051_hp_mixers;
2038 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002039 case CXT5051_HP_DV6736:
2040 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2041 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002042 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002043 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002044 case CXT5051_LENOVO_X200:
2045 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002046 /* Thinkpad X301 does not have S/PDIF wired and no ability
2047 to use a docking station. */
2048 if (codec->subsystem_id == 0x17aa211f)
2049 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002050 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002051 case CXT5051_F700:
2052 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2053 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002054 spec->auto_mic = 0;
2055 break;
2056 case CXT5051_TOSHIBA:
2057 spec->mixers[0] = cxt5051_toshiba_mixers;
2058 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002059 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002060 case CXT5051_IDEAPAD:
2061 spec->init_verbs[spec->num_init_verbs++] =
2062 cxt5051_ideapad_init_verbs;
2063 spec->ideapad = 1;
2064 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002065 }
2066
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002067 if (spec->beep_amp)
2068 snd_hda_attach_beep_device(codec, spec->beep_amp);
2069
Takashi Iwai461e2c72008-01-25 11:35:17 +01002070 return 0;
2071}
2072
Daniel Drake0fb67e92009-07-16 14:46:57 +01002073/* Conexant 5066 specific */
2074
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002075static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2076static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2077static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2078static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002079
Daniel Drakedbaccc02009-11-09 15:17:24 +00002080/* OLPC's microphone port is DC coupled for use with external sensors,
2081 * therefore we use a 50% mic bias in order to center the input signal with
2082 * the DC input range of the codec. */
2083#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2084
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002085static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002086 { 2, NULL },
2087};
2088
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002089#define HP_PRESENT_PORT_A (1 << 0)
2090#define HP_PRESENT_PORT_D (1 << 1)
2091#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2092#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2093
Daniel Drake0fb67e92009-07-16 14:46:57 +01002094static void cxt5066_update_speaker(struct hda_codec *codec)
2095{
2096 struct conexant_spec *spec = codec->spec;
2097 unsigned int pinctl;
2098
John Baboval3a253442010-12-02 11:21:31 -05002099 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2100 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002101
2102 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002103 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002104 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2105 pinctl);
2106
2107 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002108 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2109 if (spec->dell_automute || spec->thinkpad) {
2110 /* Mute if Port A is connected */
2111 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002112 pinctl = 0;
2113 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002114 /* Thinkpad/Dell doesn't give pin-D status */
2115 if (!hp_port_d_present(spec))
2116 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002117 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002118 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2119 pinctl);
2120
2121 /* CLASS_D AMP */
2122 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2123 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2124 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002125}
2126
2127/* turn on/off EAPD (+ mute HP) as a master switch */
2128static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2129 struct snd_ctl_elem_value *ucontrol)
2130{
2131 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2132
2133 if (!cxt_eapd_put(kcontrol, ucontrol))
2134 return 0;
2135
2136 cxt5066_update_speaker(codec);
2137 return 1;
2138}
2139
Daniel Drakec4cfe662010-01-07 13:47:04 +01002140static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2141 .num_items = 3,
2142 .items = {
2143 { "Off", PIN_IN },
2144 { "50%", PIN_VREF50 },
2145 { "80%", PIN_VREF80 },
2146 },
2147};
2148
2149static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2150{
2151 struct conexant_spec *spec = codec->spec;
2152 /* Even though port F is the DC input, the bias is controlled on port B.
2153 * we also leave that port as an active input (but unselected) in DC mode
2154 * just in case that is necessary to make the bias setting take effect. */
2155 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2156 AC_VERB_SET_PIN_WIDGET_CONTROL,
2157 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2158}
2159
Daniel Drake75f89912010-01-07 13:46:25 +01002160/* OLPC defers mic widget control until when capture is started because the
2161 * microphone LED comes on as soon as these settings are put in place. if we
2162 * did this before recording, it would give the false indication that recording
2163 * is happening when it is not. */
2164static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002165{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002166 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002167 if (!spec->recording)
2168 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002169
Daniel Drakec4cfe662010-01-07 13:47:04 +01002170 if (spec->dc_enable) {
2171 /* in DC mode we ignore presence detection and just use the jack
2172 * through our special DC port */
2173 const struct hda_verb enable_dc_mode[] = {
2174 /* disble internal mic, port C */
2175 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2176
2177 /* enable DC capture, port F */
2178 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2179 {},
2180 };
2181
2182 snd_hda_sequence_write(codec, enable_dc_mode);
2183 /* port B input disabled (and bias set) through the following call */
2184 cxt5066_set_olpc_dc_bias(codec);
2185 return;
2186 }
2187
2188 /* disable DC (port F) */
2189 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2190
Daniel Drake75f89912010-01-07 13:46:25 +01002191 /* external mic, port B */
2192 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2193 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002194
Daniel Drake75f89912010-01-07 13:46:25 +01002195 /* internal mic, port C */
2196 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2197 spec->ext_mic_present ? 0 : PIN_VREF80);
2198}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002199
Daniel Drake75f89912010-01-07 13:46:25 +01002200/* toggle input of built-in and mic jack appropriately */
2201static void cxt5066_olpc_automic(struct hda_codec *codec)
2202{
2203 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002204 unsigned int present;
2205
Daniel Drakec4cfe662010-01-07 13:47:04 +01002206 if (spec->dc_enable) /* don't do presence detection in DC mode */
2207 return;
2208
Daniel Drake75f89912010-01-07 13:46:25 +01002209 present = snd_hda_codec_read(codec, 0x1a, 0,
2210 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2211 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002212 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002213 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002214 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002215
2216 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2217 present ? 0 : 1);
2218 spec->ext_mic_present = !!present;
2219
2220 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002221}
2222
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002223/* toggle input of built-in digital mic and mic jack appropriately */
2224static void cxt5066_vostro_automic(struct hda_codec *codec)
2225{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002226 unsigned int present;
2227
2228 struct hda_verb ext_mic_present[] = {
2229 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002230 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002231
2232 /* switch to external mic input */
2233 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2234 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2235
2236 /* disable internal digital mic */
2237 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {}
2239 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002240 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002241 /* enable internal mic, port C */
2242 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2243
2244 /* switch to internal mic input */
2245 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2246
2247 /* disable external mic, port B */
2248 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2249 {}
2250 };
2251
2252 present = snd_hda_jack_detect(codec, 0x1a);
2253 if (present) {
2254 snd_printdd("CXT5066: external microphone detected\n");
2255 snd_hda_sequence_write(codec, ext_mic_present);
2256 } else {
2257 snd_printdd("CXT5066: external microphone absent\n");
2258 snd_hda_sequence_write(codec, ext_mic_absent);
2259 }
2260}
2261
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002262/* toggle input of built-in digital mic and mic jack appropriately */
2263static void cxt5066_ideapad_automic(struct hda_codec *codec)
2264{
2265 unsigned int present;
2266
2267 struct hda_verb ext_mic_present[] = {
2268 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2269 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2270 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2271 {}
2272 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002273 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002274 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2275 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2276 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2277 {}
2278 };
2279
2280 present = snd_hda_jack_detect(codec, 0x1b);
2281 if (present) {
2282 snd_printdd("CXT5066: external microphone detected\n");
2283 snd_hda_sequence_write(codec, ext_mic_present);
2284 } else {
2285 snd_printdd("CXT5066: external microphone absent\n");
2286 snd_hda_sequence_write(codec, ext_mic_absent);
2287 }
2288}
2289
David Henningssona1d69062011-01-21 13:33:28 +01002290
2291/* toggle input of built-in digital mic and mic jack appropriately */
2292static void cxt5066_asus_automic(struct hda_codec *codec)
2293{
2294 unsigned int present;
2295
2296 present = snd_hda_jack_detect(codec, 0x1b);
2297 snd_printdd("CXT5066: external microphone present=%d\n", present);
2298 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2299 present ? 1 : 0);
2300}
2301
2302
David Henningsson048e78a2010-09-02 08:35:47 +02002303/* toggle input of built-in digital mic and mic jack appropriately */
2304static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2305{
2306 unsigned int present;
2307
2308 present = snd_hda_jack_detect(codec, 0x1b);
2309 snd_printdd("CXT5066: external microphone present=%d\n", present);
2310 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2311 present ? 1 : 3);
2312}
2313
2314
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002315/* toggle input of built-in digital mic and mic jack appropriately
2316 order is: external mic -> dock mic -> interal mic */
2317static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2318{
2319 unsigned int ext_present, dock_present;
2320
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002321 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002322 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2323 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2324 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2325 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2326 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2327 {}
2328 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002329 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002330 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2331 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2332 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2333 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2334 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2335 {}
2336 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002337 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002338 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2339 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2341 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2342 {}
2343 };
2344
2345 ext_present = snd_hda_jack_detect(codec, 0x1b);
2346 dock_present = snd_hda_jack_detect(codec, 0x1a);
2347 if (ext_present) {
2348 snd_printdd("CXT5066: external microphone detected\n");
2349 snd_hda_sequence_write(codec, ext_mic_present);
2350 } else if (dock_present) {
2351 snd_printdd("CXT5066: dock microphone detected\n");
2352 snd_hda_sequence_write(codec, dock_mic_present);
2353 } else {
2354 snd_printdd("CXT5066: external microphone absent\n");
2355 snd_hda_sequence_write(codec, ext_mic_absent);
2356 }
2357}
2358
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359/* mute internal speaker if HP is plugged */
2360static void cxt5066_hp_automute(struct hda_codec *codec)
2361{
2362 struct conexant_spec *spec = codec->spec;
2363 unsigned int portA, portD;
2364
2365 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002366 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367
2368 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002369 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002370
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002371 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2372 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002373 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2374 portA, portD, spec->hp_present);
2375 cxt5066_update_speaker(codec);
2376}
2377
David Henningsson02b6b5b2011-01-21 13:27:39 +01002378/* Dispatch the right mic autoswitch function */
2379static void cxt5066_automic(struct hda_codec *codec)
2380{
2381 struct conexant_spec *spec = codec->spec;
2382
2383 if (spec->dell_vostro)
2384 cxt5066_vostro_automic(codec);
2385 else if (spec->ideapad)
2386 cxt5066_ideapad_automic(codec);
2387 else if (spec->thinkpad)
2388 cxt5066_thinkpad_automic(codec);
2389 else if (spec->hp_laptop)
2390 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002391 else if (spec->asus)
2392 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002393}
2394
Daniel Drake0fb67e92009-07-16 14:46:57 +01002395/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002396static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002397{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002398 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002399 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2400 switch (res >> 26) {
2401 case CONEXANT_HP_EVENT:
2402 cxt5066_hp_automute(codec);
2403 break;
2404 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002405 /* ignore mic events in DC mode; we're always using the jack */
2406 if (!spec->dc_enable)
2407 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002408 break;
2409 }
2410}
2411
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002412/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002413static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002414{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002415 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002416 switch (res >> 26) {
2417 case CONEXANT_HP_EVENT:
2418 cxt5066_hp_automute(codec);
2419 break;
2420 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002421 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002422 break;
2423 }
2424}
2425
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002426
Daniel Drake0fb67e92009-07-16 14:46:57 +01002427static const struct hda_input_mux cxt5066_analog_mic_boost = {
2428 .num_items = 5,
2429 .items = {
2430 { "0dB", 0 },
2431 { "10dB", 1 },
2432 { "20dB", 2 },
2433 { "30dB", 3 },
2434 { "40dB", 4 },
2435 },
2436};
2437
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002438static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002439{
2440 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002441 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002442 AC_VERB_SET_AMP_GAIN_MUTE,
2443 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2444 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002445 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002446 /* adjust the internal mic as well...it is not through 0x17 */
2447 snd_hda_codec_write_cache(codec, 0x23, 0,
2448 AC_VERB_SET_AMP_GAIN_MUTE,
2449 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2450 cxt5066_analog_mic_boost.
2451 items[spec->mic_boost].index);
2452 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002453}
2454
Daniel Drake0fb67e92009-07-16 14:46:57 +01002455static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2456 struct snd_ctl_elem_info *uinfo)
2457{
2458 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2459}
2460
2461static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2462 struct snd_ctl_elem_value *ucontrol)
2463{
2464 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002465 struct conexant_spec *spec = codec->spec;
2466 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002467 return 0;
2468}
2469
2470static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2471 struct snd_ctl_elem_value *ucontrol)
2472{
2473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002474 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002475 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2476 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002477 idx = ucontrol->value.enumerated.item[0];
2478 if (idx >= imux->num_items)
2479 idx = imux->num_items - 1;
2480
Daniel Drakec4cfe662010-01-07 13:47:04 +01002481 spec->mic_boost = idx;
2482 if (!spec->dc_enable)
2483 cxt5066_set_mic_boost(codec);
2484 return 1;
2485}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002486
Daniel Drakec4cfe662010-01-07 13:47:04 +01002487static void cxt5066_enable_dc(struct hda_codec *codec)
2488{
2489 const struct hda_verb enable_dc_mode[] = {
2490 /* disable gain */
2491 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492
2493 /* switch to DC input */
2494 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2495 {}
2496 };
2497
2498 /* configure as input source */
2499 snd_hda_sequence_write(codec, enable_dc_mode);
2500 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2501}
2502
2503static void cxt5066_disable_dc(struct hda_codec *codec)
2504{
2505 /* reconfigure input source */
2506 cxt5066_set_mic_boost(codec);
2507 /* automic also selects the right mic if we're recording */
2508 cxt5066_olpc_automic(codec);
2509}
2510
2511static int cxt5066_olpc_dc_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.integer.value[0] = spec->dc_enable;
2517 return 0;
2518}
2519
2520static int cxt5066_olpc_dc_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 int dc_enable = !!ucontrol->value.integer.value[0];
2526
2527 if (dc_enable == spec->dc_enable)
2528 return 0;
2529
2530 spec->dc_enable = dc_enable;
2531 if (dc_enable)
2532 cxt5066_enable_dc(codec);
2533 else
2534 cxt5066_disable_dc(codec);
2535
2536 return 1;
2537}
2538
2539static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2540 struct snd_ctl_elem_info *uinfo)
2541{
2542 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2543}
2544
2545static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2546 struct snd_ctl_elem_value *ucontrol)
2547{
2548 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2549 struct conexant_spec *spec = codec->spec;
2550 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2551 return 0;
2552}
2553
2554static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_value *ucontrol)
2556{
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 struct conexant_spec *spec = codec->spec;
2559 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2560 unsigned int idx;
2561
2562 idx = ucontrol->value.enumerated.item[0];
2563 if (idx >= imux->num_items)
2564 idx = imux->num_items - 1;
2565
2566 spec->dc_input_bias = idx;
2567 if (spec->dc_enable)
2568 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002569 return 1;
2570}
2571
Daniel Drake75f89912010-01-07 13:46:25 +01002572static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2573{
2574 struct conexant_spec *spec = codec->spec;
2575 /* mark as recording and configure the microphone widget so that the
2576 * recording LED comes on. */
2577 spec->recording = 1;
2578 cxt5066_olpc_select_mic(codec);
2579}
2580
2581static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2582{
2583 struct conexant_spec *spec = codec->spec;
2584 const struct hda_verb disable_mics[] = {
2585 /* disable external mic, port B */
2586 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2587
2588 /* disble internal mic, port C */
2589 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002590
2591 /* disable DC capture, port F */
2592 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002593 {},
2594 };
2595
2596 snd_hda_sequence_write(codec, disable_mics);
2597 spec->recording = 0;
2598}
2599
Andy Robinsonf6a24912011-01-24 10:12:37 -05002600static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002601 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002602 int num_pins)
2603{
2604 struct conexant_spec *spec = codec->spec;
2605 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2606 int i;
2607
2608 for (i = 0; i < num_pins; i++, dig_pins++) {
2609 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2610 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2611 continue;
2612 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2613 continue;
2614 if (spec->slave_dig_outs[0])
2615 nid_loc++;
2616 else
2617 nid_loc = spec->slave_dig_outs;
2618 }
2619}
2620
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002621static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002622 .num_items = 4,
2623 .items = {
2624 { "Mic B", 0 },
2625 { "Mic C", 1 },
2626 { "Mic E", 2 },
2627 { "Mic F", 3 },
2628 },
2629};
2630
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002631static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002632 .ops = &snd_hda_bind_vol,
2633 .values = {
2634 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2635 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2636 0
2637 },
2638};
2639
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002640static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002641 .ops = &snd_hda_bind_sw,
2642 .values = {
2643 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2644 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2645 0
2646 },
2647};
2648
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002649static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002650 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2651 {}
2652};
2653
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002654static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002655 {
2656 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2657 .name = "Master Playback Volume",
2658 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2659 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2660 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002661 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002662 .info = snd_hda_mixer_amp_volume_info,
2663 .get = snd_hda_mixer_amp_volume_get,
2664 .put = snd_hda_mixer_amp_volume_put,
2665 .tlv = { .c = snd_hda_mixer_amp_tlv },
2666 /* offset by 28 volume steps to limit minimum gain to -46dB */
2667 .private_value =
2668 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2669 },
2670 {}
2671};
2672
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002673static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002674 {
2675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2676 .name = "DC Mode Enable Switch",
2677 .info = snd_ctl_boolean_mono_info,
2678 .get = cxt5066_olpc_dc_get,
2679 .put = cxt5066_olpc_dc_put,
2680 },
2681 {
2682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2683 .name = "DC Input Bias Enum",
2684 .info = cxt5066_olpc_dc_bias_enum_info,
2685 .get = cxt5066_olpc_dc_bias_enum_get,
2686 .put = cxt5066_olpc_dc_bias_enum_put,
2687 },
2688 {}
2689};
2690
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002691static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002692 {
2693 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2694 .name = "Master Playback Switch",
2695 .info = cxt_eapd_info,
2696 .get = cxt_eapd_get,
2697 .put = cxt5066_hp_master_sw_put,
2698 .private_value = 0x1d,
2699 },
2700
2701 {
2702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002703 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002704 .info = cxt5066_mic_boost_mux_enum_info,
2705 .get = cxt5066_mic_boost_mux_enum_get,
2706 .put = cxt5066_mic_boost_mux_enum_put,
2707 },
2708
2709 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2710 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2711 {}
2712};
2713
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002714static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002715 {
2716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002717 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002718 .info = cxt5066_mic_boost_mux_enum_info,
2719 .get = cxt5066_mic_boost_mux_enum_get,
2720 .put = cxt5066_mic_boost_mux_enum_put,
2721 .private_value = 0x23 | 0x100,
2722 },
2723 {}
2724};
2725
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002726static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002727 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2728 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2729 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2730 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2731
2732 /* Speakers */
2733 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2734 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2735
2736 /* HP, Amp */
2737 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2738 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2739
2740 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2741 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2742
2743 /* DAC1 */
2744 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2745
2746 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2747 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2748 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2749 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2752
2753 /* no digital microphone support yet */
2754 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2755
2756 /* Audio input selector */
2757 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2758
2759 /* SPDIF route: PCM */
2760 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2761 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2762
2763 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2764 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2765
2766 /* EAPD */
2767 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2768
2769 /* not handling these yet */
2770 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2771 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2772 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2773 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2774 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2775 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2776 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2777 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2778 { } /* end */
2779};
2780
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002781static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002782 /* Port A: headphones */
2783 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2784 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2785
2786 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002787 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002788
2789 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002790 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002791
2792 /* Port D: unused */
2793 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2794
2795 /* Port E: unused, but has primary EAPD */
2796 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2797 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2798
Daniel Drakec4cfe662010-01-07 13:47:04 +01002799 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002800 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2801
2802 /* Port G: internal speakers */
2803 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2804 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2805
2806 /* DAC1 */
2807 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2808
2809 /* DAC2: unused */
2810 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2811
2812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2814 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2816 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2817 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2818 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2819 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2820 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2821 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2822 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2823 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2824
2825 /* Disable digital microphone port */
2826 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2827
2828 /* Audio input selectors */
2829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2830 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2831
2832 /* Disable SPDIF */
2833 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2834 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2835
2836 /* enable unsolicited events for Port A and B */
2837 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2838 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2839 { } /* end */
2840};
2841
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002842static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002843 /* Port A: headphones */
2844 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2845 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2846
2847 /* Port B: external microphone */
2848 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2849
2850 /* Port C: unused */
2851 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2852
2853 /* Port D: unused */
2854 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855
2856 /* Port E: unused, but has primary EAPD */
2857 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2858 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2859
2860 /* Port F: unused */
2861 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2862
2863 /* Port G: internal speakers */
2864 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2865 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2866
2867 /* DAC1 */
2868 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2869
2870 /* DAC2: unused */
2871 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2872
2873 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2874 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2877 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2878 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2879 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2880 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2881 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2882 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2883 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2884 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2885
2886 /* Digital microphone port */
2887 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2888
2889 /* Audio input selectors */
2890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2891 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2892
2893 /* Disable SPDIF */
2894 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2895 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2896
2897 /* enable unsolicited events for Port A and B */
2898 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2899 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2900 { } /* end */
2901};
2902
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002903static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002904 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2905 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2906 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2907 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2908
2909 /* Speakers */
2910 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2911 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2912
2913 /* HP, Amp */
2914 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2915 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2916
2917 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2918 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2919
2920 /* DAC1 */
2921 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2922
2923 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2924 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2925 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2926 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2927 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2928 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2929 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2930
2931 /* Audio input selector */
2932 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2933 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2934
2935 /* SPDIF route: PCM */
2936 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2937 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2938
2939 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2940 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2941
2942 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002943 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002944
2945 /* EAPD */
2946 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2947
2948 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2949 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2950 { } /* end */
2951};
2952
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002953static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002954 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2955 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2956
2957 /* Port G: internal speakers */
2958 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2959 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2960
2961 /* Port A: HP, Amp */
2962 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2963 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2964
2965 /* Port B: Mic Dock */
2966 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2967
2968 /* Port C: Mic */
2969 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2970
2971 /* Port D: HP Dock, Amp */
2972 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2973 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2974
2975 /* DAC1 */
2976 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2977
2978 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2979 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2980 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2981 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2982 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2983 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2984 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2985
2986 /* Audio input selector */
2987 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2988 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2989
2990 /* SPDIF route: PCM */
2991 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2992 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2993
2994 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2995 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2996
2997 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002998 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002999
3000 /* EAPD */
3001 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3002
3003 /* enable unsolicited events for Port A, B, C and D */
3004 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3005 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3006 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3007 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3008 { } /* end */
3009};
3010
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003011static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01003012 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3013 { } /* end */
3014};
3015
David Henningsson048e78a2010-09-02 08:35:47 +02003016
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003017static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02003018 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3019 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3020 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3021 { } /* end */
3022};
3023
Daniel Drake0fb67e92009-07-16 14:46:57 +01003024/* initialize jack-sensing, too */
3025static int cxt5066_init(struct hda_codec *codec)
3026{
3027 snd_printdd("CXT5066: init\n");
3028 conexant_init(codec);
3029 if (codec->patch_ops.unsol_event) {
3030 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003031 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003033 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003034 return 0;
3035}
3036
Daniel Drake75f89912010-01-07 13:46:25 +01003037static int cxt5066_olpc_init(struct hda_codec *codec)
3038{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003039 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003040 snd_printdd("CXT5066: init\n");
3041 conexant_init(codec);
3042 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003043 if (!spec->dc_enable) {
3044 cxt5066_set_mic_boost(codec);
3045 cxt5066_olpc_automic(codec);
3046 } else {
3047 cxt5066_enable_dc(codec);
3048 }
Daniel Drake75f89912010-01-07 13:46:25 +01003049 return 0;
3050}
3051
Daniel Drake0fb67e92009-07-16 14:46:57 +01003052enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003053 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003054 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3055 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003056 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003057 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003058 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003059 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003060 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003061 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003062 CXT5066_MODELS
3063};
3064
Takashi Iwaiea734962011-01-17 11:29:34 +01003065static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003066 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003067 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3068 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003069 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003070 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003071 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003072 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003073 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003074 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003075};
3076
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003077static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003078 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003079 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003080 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003081 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003082 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003083 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003084 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3085 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003086 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003087 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003088 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003089 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003090 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003091 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003092 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003093 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3094 CXT5066_LAPTOP),
3095 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003096 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003097 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003098 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003099 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003100 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003101 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003102 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003103 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003104 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
David Henningsson22f21d52011-01-07 07:53:39 +01003105 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003106 {}
3107};
3108
3109static int patch_cxt5066(struct hda_codec *codec)
3110{
3111 struct conexant_spec *spec;
3112 int board_config;
3113
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003114 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3115 cxt5066_models, cxt5066_cfg_tbl);
3116#if 0 /* use the old method just for safety */
3117 if (board_config < 0)
3118 board_config = CXT5066_AUTO;
3119#endif
3120 if (board_config == CXT5066_AUTO)
3121 return patch_conexant_auto(codec);
3122
Daniel Drake0fb67e92009-07-16 14:46:57 +01003123 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3124 if (!spec)
3125 return -ENOMEM;
3126 codec->spec = spec;
3127
3128 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003129 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003130
3131 spec->dell_automute = 0;
3132 spec->multiout.max_channels = 2;
3133 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3134 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003135 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3136 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003137 spec->num_adc_nids = 1;
3138 spec->adc_nids = cxt5066_adc_nids;
3139 spec->capsrc_nids = cxt5066_capsrc_nids;
3140 spec->input_mux = &cxt5066_capture_source;
3141
3142 spec->port_d_mode = PIN_HP;
3143
3144 spec->num_init_verbs = 1;
3145 spec->init_verbs[0] = cxt5066_init_verbs;
3146 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3147 spec->channel_mode = cxt5066_modes;
3148 spec->cur_adc = 0;
3149 spec->cur_adc_idx = 0;
3150
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003151 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3152
Daniel Drake0fb67e92009-07-16 14:46:57 +01003153 switch (board_config) {
3154 default:
3155 case CXT5066_LAPTOP:
3156 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3157 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3158 break;
3159 case CXT5066_DELL_LAPTOP:
3160 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3161 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3162
3163 spec->port_d_mode = PIN_OUT;
3164 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3165 spec->num_init_verbs++;
3166 spec->dell_automute = 1;
3167 break;
David Henningssona1d69062011-01-21 13:33:28 +01003168 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003169 case CXT5066_HP_LAPTOP:
3170 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003171 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003172 spec->init_verbs[spec->num_init_verbs] =
3173 cxt5066_init_verbs_hp_laptop;
3174 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003175 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3176 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003177 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3178 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3179 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003180 if (board_config == CXT5066_HP_LAPTOP)
3181 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003182 /* input source automatically selected */
3183 spec->input_mux = NULL;
3184 spec->port_d_mode = 0;
3185 spec->mic_boost = 3; /* default 30dB gain */
3186 break;
3187
Daniel Drake0fb67e92009-07-16 14:46:57 +01003188 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003189 codec->patch_ops.init = cxt5066_olpc_init;
3190 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003191 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3192 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003193 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003194 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3195 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003196 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003197
3198 /* no S/PDIF out */
3199 spec->multiout.dig_out_nid = 0;
3200
3201 /* input source automatically selected */
3202 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003203
3204 /* our capture hooks which allow us to turn on the microphone LED
3205 * at the right time */
3206 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3207 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003208 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003209 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003210 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003211 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003212 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3213 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3214 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003215 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003216 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003217 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003218 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003219
3220 /* no S/PDIF out */
3221 spec->multiout.dig_out_nid = 0;
3222
3223 /* input source automatically selected */
3224 spec->input_mux = NULL;
3225 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003226 case CXT5066_IDEAPAD:
3227 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003228 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003229 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3230 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3231 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3232 spec->port_d_mode = 0;
3233 spec->ideapad = 1;
3234 spec->mic_boost = 2; /* default 20dB gain */
3235
3236 /* no S/PDIF out */
3237 spec->multiout.dig_out_nid = 0;
3238
3239 /* input source automatically selected */
3240 spec->input_mux = NULL;
3241 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003242 case CXT5066_THINKPAD:
3243 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003244 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003245 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3246 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3247 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3248 spec->thinkpad = 1;
3249 spec->port_d_mode = PIN_OUT;
3250 spec->mic_boost = 2; /* default 20dB gain */
3251
3252 /* no S/PDIF out */
3253 spec->multiout.dig_out_nid = 0;
3254
3255 /* input source automatically selected */
3256 spec->input_mux = NULL;
3257 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003258 }
3259
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003260 if (spec->beep_amp)
3261 snd_hda_attach_beep_device(codec, spec->beep_amp);
3262
Daniel Drake0fb67e92009-07-16 14:46:57 +01003263 return 0;
3264}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003265
3266/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003267 * Automatic parser for CX20641 & co
3268 */
3269
Takashi Iwai6764bce2011-05-13 16:52:25 +02003270static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3271 struct hda_codec *codec,
3272 unsigned int stream_tag,
3273 unsigned int format,
3274 struct snd_pcm_substream *substream)
3275{
3276 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003277 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003278 if (spec->adc_switching) {
3279 spec->cur_adc = adc;
3280 spec->cur_adc_stream_tag = stream_tag;
3281 spec->cur_adc_format = format;
3282 }
3283 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3284 return 0;
3285}
3286
3287static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3288 struct hda_codec *codec,
3289 struct snd_pcm_substream *substream)
3290{
3291 struct conexant_spec *spec = codec->spec;
3292 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3293 spec->cur_adc = 0;
3294 return 0;
3295}
3296
3297static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3298 .substreams = 1,
3299 .channels_min = 2,
3300 .channels_max = 2,
3301 .nid = 0, /* fill later */
3302 .ops = {
3303 .prepare = cx_auto_capture_pcm_prepare,
3304 .cleanup = cx_auto_capture_pcm_cleanup
3305 },
3306};
3307
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003308static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003309
3310/* get the connection index of @nid in the widget @mux */
3311static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3312 hda_nid_t nid)
3313{
3314 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3315 int i, nums;
3316
3317 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3318 for (i = 0; i < nums; i++)
3319 if (conn[i] == nid)
3320 return i;
3321 return -1;
3322}
3323
3324/* get an unassigned DAC from the given list.
3325 * Return the nid if found and reduce the DAC list, or return zero if
3326 * not found
3327 */
3328static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3329 hda_nid_t *dacs, int *num_dacs)
3330{
3331 int i, nums = *num_dacs;
3332 hda_nid_t ret = 0;
3333
3334 for (i = 0; i < nums; i++) {
3335 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3336 ret = dacs[i];
3337 break;
3338 }
3339 }
3340 if (!ret)
3341 return 0;
3342 if (--nums > 0)
3343 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3344 *num_dacs = nums;
3345 return ret;
3346}
3347
3348#define MAX_AUTO_DACS 5
3349
3350/* fill analog DAC list from the widget tree */
3351static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3352{
3353 hda_nid_t nid, end_nid;
3354 int nums = 0;
3355
3356 end_nid = codec->start_nid + codec->num_nodes;
3357 for (nid = codec->start_nid; nid < end_nid; nid++) {
3358 unsigned int wcaps = get_wcaps(codec, nid);
3359 unsigned int type = get_wcaps_type(wcaps);
3360 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3361 dacs[nums++] = nid;
3362 if (nums >= MAX_AUTO_DACS)
3363 break;
3364 }
3365 }
3366 return nums;
3367}
3368
3369/* fill pin_dac_pair list from the pin and dac list */
3370static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3371 int num_pins, hda_nid_t *dacs, int *rest,
3372 struct pin_dac_pair *filled, int type)
3373{
3374 int i, nums;
3375
3376 nums = 0;
3377 for (i = 0; i < num_pins; i++) {
3378 filled[nums].pin = pins[i];
3379 filled[nums].type = type;
3380 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3381 nums++;
3382 }
3383 return nums;
3384}
3385
3386/* parse analog output paths */
3387static void cx_auto_parse_output(struct hda_codec *codec)
3388{
3389 struct conexant_spec *spec = codec->spec;
3390 struct auto_pin_cfg *cfg = &spec->autocfg;
3391 hda_nid_t dacs[MAX_AUTO_DACS];
3392 int i, j, nums, rest;
3393
3394 rest = fill_cx_auto_dacs(codec, dacs);
3395 /* parse all analog output pins */
3396 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3397 dacs, &rest, spec->dac_info,
3398 AUTO_PIN_LINE_OUT);
3399 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3400 dacs, &rest, spec->dac_info + nums,
3401 AUTO_PIN_HP_OUT);
3402 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3403 dacs, &rest, spec->dac_info + nums,
3404 AUTO_PIN_SPEAKER_OUT);
3405 spec->dac_info_filled = nums;
3406 /* fill multiout struct */
3407 for (i = 0; i < nums; i++) {
3408 hda_nid_t dac = spec->dac_info[i].dac;
3409 if (!dac)
3410 continue;
3411 switch (spec->dac_info[i].type) {
3412 case AUTO_PIN_LINE_OUT:
3413 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3414 spec->multiout.num_dacs++;
3415 break;
3416 case AUTO_PIN_HP_OUT:
3417 case AUTO_PIN_SPEAKER_OUT:
3418 if (!spec->multiout.hp_nid) {
3419 spec->multiout.hp_nid = dac;
3420 break;
3421 }
3422 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3423 if (!spec->multiout.extra_out_nid[j]) {
3424 spec->multiout.extra_out_nid[j] = dac;
3425 break;
3426 }
3427 break;
3428 }
3429 }
3430 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003431 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003432
Takashi Iwai03697e22011-05-17 09:53:31 +02003433 for (i = 0; i < cfg->hp_outs; i++) {
3434 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3435 spec->auto_mute = 1;
3436 break;
3437 }
3438 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003439 if (spec->auto_mute &&
3440 cfg->line_out_pins[0] &&
3441 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003442 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3443 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3444 for (i = 0; i < cfg->line_outs; i++) {
3445 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3446 spec->detect_line = 1;
3447 break;
3448 }
3449 }
3450 spec->automute_lines = spec->detect_line;
3451 }
3452
Takashi Iwaif2e57312010-09-15 10:07:08 +02003453 spec->vmaster_nid = spec->private_dac_nids[0];
3454}
3455
Takashi Iwaida339862011-05-13 16:24:15 +02003456static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3457 hda_nid_t *pins, bool on);
3458
Takashi Iwai03697e22011-05-17 09:53:31 +02003459static void do_automute(struct hda_codec *codec, int num_pins,
3460 hda_nid_t *pins, bool on)
3461{
3462 int i;
3463 for (i = 0; i < num_pins; i++)
3464 snd_hda_codec_write(codec, pins[i], 0,
3465 AC_VERB_SET_PIN_WIDGET_CONTROL,
3466 on ? PIN_OUT : 0);
3467 cx_auto_turn_eapd(codec, num_pins, pins, on);
3468}
3469
3470static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3471{
3472 int i, present = 0;
3473
3474 for (i = 0; i < num_pins; i++) {
3475 hda_nid_t nid = pins[i];
3476 if (!nid || !is_jack_detectable(codec, nid))
3477 break;
3478 snd_hda_input_jack_report(codec, nid);
3479 present |= snd_hda_jack_detect(codec, nid);
3480 }
3481 return present;
3482}
3483
Takashi Iwaif2e57312010-09-15 10:07:08 +02003484/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003485static void cx_auto_update_speakers(struct hda_codec *codec)
3486{
3487 struct conexant_spec *spec = codec->spec;
3488 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003489 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003490
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003491 /* turn on HP EAPD when HP jacks are present */
3492 if (spec->auto_mute)
3493 on = spec->hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +02003494 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003495 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3496 if (spec->auto_mute)
3497 on = !(spec->hp_present ||
3498 (spec->detect_line && spec->line_present));
3499 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003500
3501 /* toggle line-out mutes if needed, too */
3502 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3503 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3504 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3505 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003506 if (spec->auto_mute) {
3507 /* mute LO in auto-mode when HP jack is present */
3508 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3509 spec->automute_lines)
3510 on = !spec->hp_present;
3511 else
3512 on = 1;
3513 }
3514 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003515}
3516
Takashi Iwaif2e57312010-09-15 10:07:08 +02003517static void cx_auto_hp_automute(struct hda_codec *codec)
3518{
3519 struct conexant_spec *spec = codec->spec;
3520 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003521
3522 if (!spec->auto_mute)
3523 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003524 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3525 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003526}
3527
Takashi Iwai03697e22011-05-17 09:53:31 +02003528static void cx_auto_line_automute(struct hda_codec *codec)
3529{
3530 struct conexant_spec *spec = codec->spec;
3531 struct auto_pin_cfg *cfg = &spec->autocfg;
3532
3533 if (!spec->auto_mute || !spec->detect_line)
3534 return;
3535 spec->line_present = detect_jacks(codec, cfg->line_outs,
3536 cfg->line_out_pins);
3537 cx_auto_update_speakers(codec);
3538}
3539
3540static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3541 struct snd_ctl_elem_info *uinfo)
3542{
3543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3544 struct conexant_spec *spec = codec->spec;
3545 static const char * const texts2[] = {
3546 "Disabled", "Enabled"
3547 };
3548 static const char * const texts3[] = {
3549 "Disabled", "Speaker Only", "Line-Out+Speaker"
3550 };
3551 const char * const *texts;
3552
3553 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3554 uinfo->count = 1;
3555 if (spec->automute_hp_lo) {
3556 uinfo->value.enumerated.items = 3;
3557 texts = texts3;
3558 } else {
3559 uinfo->value.enumerated.items = 2;
3560 texts = texts2;
3561 }
3562 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3563 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3564 strcpy(uinfo->value.enumerated.name,
3565 texts[uinfo->value.enumerated.item]);
3566 return 0;
3567}
3568
3569static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3570 struct snd_ctl_elem_value *ucontrol)
3571{
3572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3573 struct conexant_spec *spec = codec->spec;
3574 unsigned int val;
3575 if (!spec->auto_mute)
3576 val = 0;
3577 else if (!spec->automute_lines)
3578 val = 1;
3579 else
3580 val = 2;
3581 ucontrol->value.enumerated.item[0] = val;
3582 return 0;
3583}
3584
3585static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3586 struct snd_ctl_elem_value *ucontrol)
3587{
3588 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3589 struct conexant_spec *spec = codec->spec;
3590
3591 switch (ucontrol->value.enumerated.item[0]) {
3592 case 0:
3593 if (!spec->auto_mute)
3594 return 0;
3595 spec->auto_mute = 0;
3596 break;
3597 case 1:
3598 if (spec->auto_mute && !spec->automute_lines)
3599 return 0;
3600 spec->auto_mute = 1;
3601 spec->automute_lines = 0;
3602 break;
3603 case 2:
3604 if (!spec->automute_hp_lo)
3605 return -EINVAL;
3606 if (spec->auto_mute && spec->automute_lines)
3607 return 0;
3608 spec->auto_mute = 1;
3609 spec->automute_lines = 1;
3610 break;
3611 default:
3612 return -EINVAL;
3613 }
3614 cx_auto_update_speakers(codec);
3615 return 1;
3616}
3617
3618static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3619 {
3620 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3621 .name = "Auto-Mute Mode",
3622 .info = cx_automute_mode_info,
3623 .get = cx_automute_mode_get,
3624 .put = cx_automute_mode_put,
3625 },
3626 { }
3627};
3628
Takashi Iwai6764bce2011-05-13 16:52:25 +02003629static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3630 struct snd_ctl_elem_info *uinfo)
3631{
3632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3633 struct conexant_spec *spec = codec->spec;
3634
3635 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3636}
3637
3638static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3639 struct snd_ctl_elem_value *ucontrol)
3640{
3641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3642 struct conexant_spec *spec = codec->spec;
3643
3644 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3645 return 0;
3646}
3647
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003648/* look for the route the given pin from mux and return the index;
3649 * if do_select is set, actually select the route.
3650 */
3651static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003652 hda_nid_t pin, hda_nid_t *srcp,
3653 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003654{
3655 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3656 int i, nums;
3657
Takashi Iwaicf27f292011-05-16 11:33:02 +02003658 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3659 case AC_WID_AUD_IN:
3660 case AC_WID_AUD_SEL:
3661 case AC_WID_AUD_MIX:
3662 break;
3663 default:
3664 return -1;
3665 }
3666
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003667 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3668 for (i = 0; i < nums; i++)
3669 if (conn[i] == pin) {
3670 if (do_select)
3671 snd_hda_codec_write(codec, mux, 0,
3672 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003673 if (srcp)
3674 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003675 return i;
3676 }
3677 depth++;
3678 if (depth == 2)
3679 return -1;
3680 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003681 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003682 do_select, depth);
3683 if (ret >= 0) {
3684 if (do_select)
3685 snd_hda_codec_write(codec, mux, 0,
3686 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003687 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003688 }
3689 }
3690 return -1;
3691}
3692
3693static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3694 hda_nid_t pin)
3695{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003696 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003697}
3698
3699static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3700 hda_nid_t pin)
3701{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003702 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003703}
3704
Takashi Iwai6764bce2011-05-13 16:52:25 +02003705static int cx_auto_mux_enum_update(struct hda_codec *codec,
3706 const struct hda_input_mux *imux,
3707 unsigned int idx)
3708{
3709 struct conexant_spec *spec = codec->spec;
3710 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003711 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003712
3713 if (!imux->num_items)
3714 return 0;
3715 if (idx >= imux->num_items)
3716 idx = imux->num_items - 1;
3717 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003718 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003719 adc = spec->imux_info[idx].adc;
3720 select_input_connection(codec, spec->imux_info[idx].adc,
3721 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003722 if (spec->cur_adc && spec->cur_adc != adc) {
3723 /* stream is running, let's swap the current ADC */
3724 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3725 spec->cur_adc = adc;
3726 snd_hda_codec_setup_stream(codec, adc,
3727 spec->cur_adc_stream_tag, 0,
3728 spec->cur_adc_format);
3729 }
3730 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003731 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003732}
3733
3734static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3735 struct snd_ctl_elem_value *ucontrol)
3736{
3737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3738 struct conexant_spec *spec = codec->spec;
3739
3740 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3741 ucontrol->value.enumerated.item[0]);
3742}
3743
3744static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3745 {
3746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3747 .name = "Capture Source",
3748 .info = cx_auto_mux_enum_info,
3749 .get = cx_auto_mux_enum_get,
3750 .put = cx_auto_mux_enum_put
3751 },
3752 {}
3753};
3754
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003755static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3756{
3757 struct conexant_spec *spec = codec->spec;
3758 if (idx < 0)
3759 return false;
3760 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3761 return false;
3762 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3763 return true;
3764}
3765
Takashi Iwaif2e57312010-09-15 10:07:08 +02003766/* automatic switch internal and external mic */
3767static void cx_auto_automic(struct hda_codec *codec)
3768{
3769 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003770
3771 if (!spec->auto_mic)
3772 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003773 if (!select_automic(codec, spec->auto_mic_ext, true))
3774 if (!select_automic(codec, spec->auto_mic_dock, true))
3775 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003776}
3777
3778static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3779{
3780 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3781 switch (res >> 26) {
3782 case CONEXANT_HP_EVENT:
3783 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003784 break;
3785 case CONEXANT_LINE_EVENT:
3786 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003787 break;
3788 case CONEXANT_MIC_EVENT:
3789 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003790 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003791 break;
3792 }
3793}
3794
Takashi Iwaif2e57312010-09-15 10:07:08 +02003795/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003796 * auto-mic is enabled only when one int-mic and one ext- and/or
3797 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003798 */
3799static void cx_auto_check_auto_mic(struct hda_codec *codec)
3800{
3801 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003802 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3803 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003804
Takashi Iwai506a4192011-05-23 20:07:15 +02003805 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003806 pset[i] = -1;
3807 for (i = 0; i < spec->private_imux.num_items; i++) {
3808 hda_nid_t pin = spec->imux_info[i].pin;
3809 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003810 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003811 attr = snd_hda_get_input_pin_attr(def_conf);
3812 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003813 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003814 if (attr > INPUT_PIN_ATTR_NORMAL)
3815 attr = INPUT_PIN_ATTR_NORMAL;
3816 if (attr != INPUT_PIN_ATTR_INT &&
3817 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003818 return; /* non-detectable pin */
3819 type = get_defcfg_device(def_conf);
3820 if (type != AC_JACK_MIC_IN &&
3821 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3822 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003823 if (pset[attr] >= 0)
3824 return; /* already occupied */
3825 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003826 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003827 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3828 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3829 return; /* no input to switch*/
3830 spec->auto_mic = 1;
3831 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3832 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3833 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003834}
3835
3836static void cx_auto_parse_input(struct hda_codec *codec)
3837{
3838 struct conexant_spec *spec = codec->spec;
3839 struct auto_pin_cfg *cfg = &spec->autocfg;
3840 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003841 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003842
3843 imux = &spec->private_imux;
3844 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003845 for (j = 0; j < spec->num_adc_nids; j++) {
3846 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003847 int idx = get_input_connection(codec, adc,
3848 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003849 if (idx >= 0) {
3850 const char *label;
3851 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003852 spec->imux_info[imux->num_items].index = i;
3853 spec->imux_info[imux->num_items].boost = 0;
3854 spec->imux_info[imux->num_items].adc = adc;
3855 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003856 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003857 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003858 break;
3859 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003860 }
3861 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003862 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003863 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003864 if (imux->num_items > 1 && !spec->auto_mic) {
3865 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003866 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003867 spec->adc_switching = 1;
3868 break;
3869 }
3870 }
3871 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003872}
3873
3874/* get digital-input audio widget corresponding to the given pin */
3875static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3876{
3877 hda_nid_t nid, end_nid;
3878
3879 end_nid = codec->start_nid + codec->num_nodes;
3880 for (nid = codec->start_nid; nid < end_nid; nid++) {
3881 unsigned int wcaps = get_wcaps(codec, nid);
3882 unsigned int type = get_wcaps_type(wcaps);
3883 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3884 if (get_connection_index(codec, nid, pin) >= 0)
3885 return nid;
3886 }
3887 }
3888 return 0;
3889}
3890
3891static void cx_auto_parse_digital(struct hda_codec *codec)
3892{
3893 struct conexant_spec *spec = codec->spec;
3894 struct auto_pin_cfg *cfg = &spec->autocfg;
3895 hda_nid_t nid;
3896
3897 if (cfg->dig_outs &&
3898 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3899 spec->multiout.dig_out_nid = nid;
3900 if (cfg->dig_in_pin)
3901 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3902}
3903
3904#ifdef CONFIG_SND_HDA_INPUT_BEEP
3905static void cx_auto_parse_beep(struct hda_codec *codec)
3906{
3907 struct conexant_spec *spec = codec->spec;
3908 hda_nid_t nid, end_nid;
3909
3910 end_nid = codec->start_nid + codec->num_nodes;
3911 for (nid = codec->start_nid; nid < end_nid; nid++)
3912 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3913 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3914 break;
3915 }
3916}
3917#else
3918#define cx_auto_parse_beep(codec)
3919#endif
3920
3921static int cx_auto_parse_auto_config(struct hda_codec *codec)
3922{
3923 struct conexant_spec *spec = codec->spec;
3924 int err;
3925
3926 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3927 if (err < 0)
3928 return err;
3929
3930 cx_auto_parse_output(codec);
3931 cx_auto_parse_input(codec);
3932 cx_auto_parse_digital(codec);
3933 cx_auto_parse_beep(codec);
3934 return 0;
3935}
3936
Takashi Iwaida339862011-05-13 16:24:15 +02003937static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3938 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003939{
3940 int i;
3941 for (i = 0; i < num_pins; i++) {
3942 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3943 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003944 AC_VERB_SET_EAPD_BTLENABLE,
3945 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003946 }
3947}
3948
3949static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3950 hda_nid_t src)
3951{
3952 int idx = get_connection_index(codec, pin, src);
3953 if (idx >= 0)
3954 snd_hda_codec_write(codec, pin, 0,
3955 AC_VERB_SET_CONNECT_SEL, idx);
3956}
3957
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003958static void mute_outputs(struct hda_codec *codec, int num_nids,
3959 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003960{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003961 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003962
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003963 for (i = 0; i < num_nids; i++) {
3964 hda_nid_t nid = nids[i];
3965 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3966 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003967 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3968 val = AMP_OUT_MUTE;
3969 else
3970 val = AMP_OUT_ZERO;
3971 snd_hda_codec_write(codec, nid, 0,
3972 AC_VERB_SET_AMP_GAIN_MUTE, val);
3973 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003974}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003975
Takashi Iwai03697e22011-05-17 09:53:31 +02003976static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3977 hda_nid_t *pins, unsigned int tag)
3978{
3979 int i;
3980 for (i = 0; i < num_pins; i++)
3981 snd_hda_codec_write(codec, pins[i], 0,
3982 AC_VERB_SET_UNSOLICITED_ENABLE,
3983 AC_USRSP_EN | tag);
3984}
3985
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003986static void cx_auto_init_output(struct hda_codec *codec)
3987{
3988 struct conexant_spec *spec = codec->spec;
3989 struct auto_pin_cfg *cfg = &spec->autocfg;
3990 hda_nid_t nid;
3991 int i;
3992
3993 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003994 for (i = 0; i < cfg->hp_outs; i++)
3995 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3996 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003997 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3998 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3999 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004000 for (i = 0; i < spec->dac_info_filled; i++) {
4001 nid = spec->dac_info[i].dac;
4002 if (!nid)
4003 nid = spec->multiout.dac_nids[0];
4004 select_connection(codec, spec->dac_info[i].pin, nid);
4005 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004006 if (spec->auto_mute) {
4007 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4008 CONEXANT_HP_EVENT);
4009 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4010 cfg->hp_pins);
4011 if (spec->detect_line) {
4012 enable_unsol_pins(codec, cfg->line_outs,
4013 cfg->line_out_pins,
4014 CONEXANT_LINE_EVENT);
4015 spec->line_present =
4016 detect_jacks(codec, cfg->line_outs,
4017 cfg->line_out_pins);
4018 }
4019 }
4020 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004021}
4022
4023static void cx_auto_init_input(struct hda_codec *codec)
4024{
4025 struct conexant_spec *spec = codec->spec;
4026 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004027 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004028
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004029 for (i = 0; i < spec->num_adc_nids; i++) {
4030 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004031 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4032 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004033 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4034 val = AMP_IN_MUTE(0);
4035 else
4036 val = AMP_IN_UNMUTE(0);
4037 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4038 val);
4039 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004040
4041 for (i = 0; i < cfg->num_inputs; i++) {
4042 unsigned int type;
4043 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4044 type = PIN_VREF80;
4045 else
4046 type = PIN_IN;
4047 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4048 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4049 }
4050
4051 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004052 if (spec->auto_mic_ext >= 0) {
4053 snd_hda_codec_write(codec,
4054 cfg->inputs[spec->auto_mic_ext].pin, 0,
4055 AC_VERB_SET_UNSOLICITED_ENABLE,
4056 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4057 }
4058 if (spec->auto_mic_dock >= 0) {
4059 snd_hda_codec_write(codec,
4060 cfg->inputs[spec->auto_mic_dock].pin, 0,
4061 AC_VERB_SET_UNSOLICITED_ENABLE,
4062 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4063 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004064 cx_auto_automic(codec);
4065 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004066 select_input_connection(codec, spec->imux_info[0].adc,
4067 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004068 }
4069}
4070
4071static void cx_auto_init_digital(struct hda_codec *codec)
4072{
4073 struct conexant_spec *spec = codec->spec;
4074 struct auto_pin_cfg *cfg = &spec->autocfg;
4075
4076 if (spec->multiout.dig_out_nid)
4077 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4078 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4079 if (spec->dig_in_nid)
4080 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4081 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4082}
4083
4084static int cx_auto_init(struct hda_codec *codec)
4085{
4086 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4087 cx_auto_init_output(codec);
4088 cx_auto_init_input(codec);
4089 cx_auto_init_digital(codec);
4090 return 0;
4091}
4092
David Henningsson983345e2011-02-15 19:57:09 +01004093static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004094 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004095 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004096{
4097 static char name[32];
4098 static struct snd_kcontrol_new knew[] = {
4099 HDA_CODEC_VOLUME(name, 0, 0, 0),
4100 HDA_CODEC_MUTE(name, 0, 0, 0),
4101 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004102 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004103 int i, err;
4104
4105 for (i = 0; i < 2; i++) {
4106 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004107 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4108 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004109 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4110 knew[i].index = cidx;
4111 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4112 kctl = snd_ctl_new1(&knew[i], codec);
4113 if (!kctl)
4114 return -ENOMEM;
4115 err = snd_hda_ctl_add(codec, nid, kctl);
4116 if (err < 0)
4117 return err;
4118 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4119 break;
4120 }
4121 return 0;
4122}
4123
David Henningsson983345e2011-02-15 19:57:09 +01004124#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4125 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4126
Takashi Iwaif2e57312010-09-15 10:07:08 +02004127#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4128 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4129
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004130static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4131 hda_nid_t pin, const char *name, int idx)
4132{
4133 unsigned int caps;
4134 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4135 if (caps & AC_AMPCAP_NUM_STEPS)
4136 return cx_auto_add_pb_volume(codec, dac, name, idx);
4137 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4138 if (caps & AC_AMPCAP_NUM_STEPS)
4139 return cx_auto_add_pb_volume(codec, pin, name, idx);
4140 return 0;
4141}
4142
Takashi Iwaif2e57312010-09-15 10:07:08 +02004143static int cx_auto_build_output_controls(struct hda_codec *codec)
4144{
4145 struct conexant_spec *spec = codec->spec;
4146 int i, err;
4147 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004148 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004149
4150 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004151 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4152 spec->dac_info[0].pin,
4153 "Master", 0);
4154
Takashi Iwaif2e57312010-09-15 10:07:08 +02004155 for (i = 0; i < spec->dac_info_filled; i++) {
4156 const char *label;
4157 int idx, type;
4158 if (!spec->dac_info[i].dac)
4159 continue;
4160 type = spec->dac_info[i].type;
4161 if (type == AUTO_PIN_LINE_OUT)
4162 type = spec->autocfg.line_out_type;
4163 switch (type) {
4164 case AUTO_PIN_LINE_OUT:
4165 default:
4166 label = texts[num_line++];
4167 idx = 0;
4168 break;
4169 case AUTO_PIN_HP_OUT:
4170 label = "Headphone";
4171 idx = num_hp++;
4172 break;
4173 case AUTO_PIN_SPEAKER_OUT:
4174 label = "Speaker";
4175 idx = num_spk++;
4176 break;
4177 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004178 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
4179 spec->dac_info[i].pin,
4180 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004181 if (err < 0)
4182 return err;
4183 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004184
4185 if (spec->auto_mute) {
4186 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4187 if (err < 0)
4188 return err;
4189 }
4190
Takashi Iwaif2e57312010-09-15 10:07:08 +02004191 return 0;
4192}
4193
Takashi Iwai6764bce2011-05-13 16:52:25 +02004194static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4195 const char *label, const char *pfx,
4196 int cidx)
4197{
4198 struct conexant_spec *spec = codec->spec;
4199 int i;
4200
4201 for (i = 0; i < spec->num_adc_nids; i++) {
4202 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004203 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004204 if (idx < 0)
4205 continue;
4206 return cx_auto_add_volume_idx(codec, label, pfx,
4207 cidx, adc_nid, HDA_INPUT, idx);
4208 }
4209 return 0;
4210}
4211
Takashi Iwaicf27f292011-05-16 11:33:02 +02004212static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4213 const char *label, int cidx)
4214{
4215 struct conexant_spec *spec = codec->spec;
4216 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004217 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004218
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004219 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004220 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4221 return cx_auto_add_volume(codec, label, " Boost", cidx,
4222 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004223 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4224 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004225 if (con < 0)
4226 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004227 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004228 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004229 return 0; /* already present */
4230 }
4231
4232 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004233 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004234 return cx_auto_add_volume(codec, label, " Boost", 0,
4235 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004236 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004237 return 0;
4238}
4239
Takashi Iwaif2e57312010-09-15 10:07:08 +02004240static int cx_auto_build_input_controls(struct hda_codec *codec)
4241{
4242 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004243 struct hda_input_mux *imux = &spec->private_imux;
4244 const char *prev_label;
4245 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004246 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004247 int multi_connection;
4248
4249 multi_connection = 0;
4250 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004251 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4252 spec->imux_info[i].pin);
4253 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004254 if (i > 0 && input_conn[i] != input_conn[0])
4255 multi_connection = 1;
4256 }
David Henningsson983345e2011-02-15 19:57:09 +01004257
Takashi Iwaif2e57312010-09-15 10:07:08 +02004258 prev_label = NULL;
4259 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004260 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004261 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004262 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004263
Takashi Iwaicf27f292011-05-16 11:33:02 +02004264 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004265 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004266 if (label == prev_label)
4267 cidx++;
4268 else
4269 cidx = 0;
4270 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004271
Takashi Iwaicf27f292011-05-16 11:33:02 +02004272 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4273 if (err < 0)
4274 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004275
Takashi Iwaicf27f292011-05-16 11:33:02 +02004276 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004277 if (i > 0)
4278 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004279 err = cx_auto_add_capture_volume(codec, nid,
4280 "Capture", "", cidx);
4281 } else {
4282 err = cx_auto_add_capture_volume(codec, nid,
4283 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004284 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004285 if (err < 0)
4286 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004287 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004288
4289 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4290 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4291 if (err < 0)
4292 return err;
4293 }
4294
Takashi Iwaif2e57312010-09-15 10:07:08 +02004295 return 0;
4296}
4297
4298static int cx_auto_build_controls(struct hda_codec *codec)
4299{
4300 int err;
4301
4302 err = cx_auto_build_output_controls(codec);
4303 if (err < 0)
4304 return err;
4305 err = cx_auto_build_input_controls(codec);
4306 if (err < 0)
4307 return err;
4308 return conexant_build_controls(codec);
4309}
4310
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004311static int cx_auto_search_adcs(struct hda_codec *codec)
4312{
4313 struct conexant_spec *spec = codec->spec;
4314 hda_nid_t nid, end_nid;
4315
4316 end_nid = codec->start_nid + codec->num_nodes;
4317 for (nid = codec->start_nid; nid < end_nid; nid++) {
4318 unsigned int caps = get_wcaps(codec, nid);
4319 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4320 continue;
4321 if (caps & AC_WCAP_DIGITAL)
4322 continue;
4323 if (snd_BUG_ON(spec->num_adc_nids >=
4324 ARRAY_SIZE(spec->private_adc_nids)))
4325 break;
4326 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4327 }
4328 spec->adc_nids = spec->private_adc_nids;
4329 return 0;
4330}
4331
4332
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004333static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004334 .build_controls = cx_auto_build_controls,
4335 .build_pcms = conexant_build_pcms,
4336 .init = cx_auto_init,
4337 .free = conexant_free,
4338 .unsol_event = cx_auto_unsol_event,
4339#ifdef CONFIG_SND_HDA_POWER_SAVE
4340 .suspend = conexant_suspend,
4341#endif
4342 .reboot_notify = snd_hda_shutup_pins,
4343};
4344
4345static int patch_conexant_auto(struct hda_codec *codec)
4346{
4347 struct conexant_spec *spec;
4348 int err;
4349
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004350 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4351 codec->chip_name);
4352
Takashi Iwaif2e57312010-09-15 10:07:08 +02004353 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4354 if (!spec)
4355 return -ENOMEM;
4356 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004357 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004358 err = cx_auto_search_adcs(codec);
4359 if (err < 0)
4360 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004361 err = cx_auto_parse_auto_config(codec);
4362 if (err < 0) {
4363 kfree(codec->spec);
4364 codec->spec = NULL;
4365 return err;
4366 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004367 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004368 codec->patch_ops = cx_auto_patch_ops;
4369 if (spec->beep_amp)
4370 snd_hda_attach_beep_device(codec, spec->beep_amp);
4371 return 0;
4372}
4373
4374/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004375 */
4376
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004377static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004378 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4379 .patch = patch_cxt5045 },
4380 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4381 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004382 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4383 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004384 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4385 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004386 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4387 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004388 { .id = 0x14f15068, .name = "CX20584",
4389 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004390 { .id = 0x14f15069, .name = "CX20585",
4391 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004392 { .id = 0x14f1506e, .name = "CX20590",
4393 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004394 { .id = 0x14f15097, .name = "CX20631",
4395 .patch = patch_conexant_auto },
4396 { .id = 0x14f15098, .name = "CX20632",
4397 .patch = patch_conexant_auto },
4398 { .id = 0x14f150a1, .name = "CX20641",
4399 .patch = patch_conexant_auto },
4400 { .id = 0x14f150a2, .name = "CX20642",
4401 .patch = patch_conexant_auto },
4402 { .id = 0x14f150ab, .name = "CX20651",
4403 .patch = patch_conexant_auto },
4404 { .id = 0x14f150ac, .name = "CX20652",
4405 .patch = patch_conexant_auto },
4406 { .id = 0x14f150b8, .name = "CX20664",
4407 .patch = patch_conexant_auto },
4408 { .id = 0x14f150b9, .name = "CX20665",
4409 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004410 {} /* terminator */
4411};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004412
4413MODULE_ALIAS("snd-hda-codec-id:14f15045");
4414MODULE_ALIAS("snd-hda-codec-id:14f15047");
4415MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004416MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004417MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004418MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004419MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004420MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004421MODULE_ALIAS("snd-hda-codec-id:14f15097");
4422MODULE_ALIAS("snd-hda-codec-id:14f15098");
4423MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4424MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4425MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4426MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4427MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4428MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004429
4430MODULE_LICENSE("GPL");
4431MODULE_DESCRIPTION("Conexant HD-audio codec");
4432
4433static struct hda_codec_preset_list conexant_list = {
4434 .preset = snd_hda_preset_conexant,
4435 .owner = THIS_MODULE,
4436};
4437
4438static int __init patch_conexant_init(void)
4439{
4440 return snd_hda_add_codec_preset(&conexant_list);
4441}
4442
4443static void __exit patch_conexant_exit(void)
4444{
4445 snd_hda_delete_codec_preset(&conexant_list);
4446}
4447
4448module_init(patch_conexant_init)
4449module_exit(patch_conexant_exit)