blob: 4ca880bb68fa8fa8371b46262523761bacc9bf61 [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);
1127 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001128 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001129 if (board_config == CXT5045_AUTO)
1130 return patch_conexant_auto(codec);
1131
Tobin Davisc9b443d2006-11-14 12:13:39 +01001132 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1133 if (!spec)
1134 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001136 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137
1138 spec->multiout.max_channels = 2;
1139 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1140 spec->multiout.dac_nids = cxt5045_dac_nids;
1141 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1142 spec->num_adc_nids = 1;
1143 spec->adc_nids = cxt5045_adc_nids;
1144 spec->capsrc_nids = cxt5045_capsrc_nids;
1145 spec->input_mux = &cxt5045_capture_source;
1146 spec->num_mixers = 1;
1147 spec->mixers[0] = cxt5045_mixers;
1148 spec->num_init_verbs = 1;
1149 spec->init_verbs[0] = cxt5045_init_verbs;
1150 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001151 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1152 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001153
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001154 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001155
1156 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157
Tobin Davisc9b443d2006-11-14 12:13:39 +01001158 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001159 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001160 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001161 spec->input_mux = &cxt5045_capture_source;
1162 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001163 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1164 spec->mixers[0] = cxt5045_mixers;
1165 codec->patch_ops.init = cxt5045_init;
1166 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001167 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001168 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001169 spec->input_mux = &cxt5045_capture_source;
1170 spec->num_init_verbs = 2;
1171 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001172 spec->mixers[0] = cxt5045_mixers;
1173 codec->patch_ops.init = cxt5045_init;
1174 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001175 default:
1176 case CXT5045_LAPTOP_HPMICSENSE:
1177 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1178 spec->input_mux = &cxt5045_capture_source;
1179 spec->num_init_verbs = 3;
1180 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1181 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1182 spec->mixers[0] = cxt5045_mixers;
1183 codec->patch_ops.init = cxt5045_init;
1184 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001185 case CXT5045_BENQ:
1186 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1187 spec->input_mux = &cxt5045_capture_source_benq;
1188 spec->num_init_verbs = 1;
1189 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1190 spec->mixers[0] = cxt5045_mixers;
1191 spec->mixers[1] = cxt5045_benq_mixers;
1192 spec->num_mixers = 2;
1193 codec->patch_ops.init = cxt5045_init;
1194 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001195 case CXT5045_LAPTOP_HP530:
1196 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1197 spec->input_mux = &cxt5045_capture_source_hp530;
1198 spec->num_init_verbs = 2;
1199 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1200 spec->mixers[0] = cxt5045_mixers_hp530;
1201 codec->patch_ops.init = cxt5045_init;
1202 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001203#ifdef CONFIG_SND_DEBUG
1204 case CXT5045_TEST:
1205 spec->input_mux = &cxt5045_test_capture_source;
1206 spec->mixers[0] = cxt5045_test_mixer;
1207 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001208 break;
1209
Tobin Davisc9b443d2006-11-14 12:13:39 +01001210#endif
1211 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001212
Takashi Iwai031005f2008-06-26 14:49:58 +02001213 switch (codec->subsystem_id >> 16) {
1214 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001215 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001216 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001217 case 0x17aa:
1218 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1219 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1220 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001221 */
1222 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1223 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1224 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1225 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1226 (1 << AC_AMPCAP_MUTE_SHIFT));
1227 break;
1228 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001229
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001230 if (spec->beep_amp)
1231 snd_hda_attach_beep_device(codec, spec->beep_amp);
1232
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233 return 0;
1234}
1235
1236
1237/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001238#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001239
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001240static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1241static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1242static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001243
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001244static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001245 { 2, NULL },
1246};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001248static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001249 .num_items = 2,
1250 .items = {
1251 { "ExtMic", 0x2 },
1252 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 }
1254};
1255
1256/* turn on/off EAPD (+ mute HP) as a master switch */
1257static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1258 struct snd_ctl_elem_value *ucontrol)
1259{
1260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1261 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001262 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001263
Tobin Davis82f30042007-02-13 12:45:44 +01001264 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001265 return 0;
1266
Tobin Davis82f30042007-02-13 12:45:44 +01001267 /* toggle internal speakers mute depending of presence of
1268 * the headphone jack
1269 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001270 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001271 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1272 * pin widgets unlike other codecs. In this case, we need to
1273 * set index 0x01 for the volume from the mixer amp 0x19.
1274 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001275 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001276 HDA_AMP_MUTE, bits);
1277 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1278 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1279 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280 return 1;
1281}
1282
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283/* mute internal speaker if HP is plugged */
1284static void cxt5047_hp_automute(struct hda_codec *codec)
1285{
Tobin Davis82f30042007-02-13 12:45:44 +01001286 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001287 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001288
Takashi Iwaid56757a2009-11-18 08:00:14 +01001289 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001290
Takashi Iwai47fd8302007-08-10 17:11:07 +02001291 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001292 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001293 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001294 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001295}
1296
1297/* toggle input of built-in and mic jack appropriately */
1298static void cxt5047_hp_automic(struct hda_codec *codec)
1299{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001300 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001301 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1302 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303 {}
1304 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001305 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001306 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1307 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308 {}
1309 };
1310 unsigned int present;
1311
Takashi Iwaid56757a2009-11-18 08:00:14 +01001312 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001313 if (present)
1314 snd_hda_sequence_write(codec, mic_jack_on);
1315 else
1316 snd_hda_sequence_write(codec, mic_jack_off);
1317}
1318
1319/* unsolicited event for HP jack sensing */
1320static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1321 unsigned int res)
1322{
Marc Boucher9f113e02008-01-22 15:18:08 +01001323 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001324 case CONEXANT_HP_EVENT:
1325 cxt5047_hp_automute(codec);
1326 break;
1327 case CONEXANT_MIC_EVENT:
1328 cxt5047_hp_automic(codec);
1329 break;
1330 }
1331}
1332
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001333static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001334 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1335 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001336 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001337 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1339 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001341 {
1342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1343 .name = "Master Playback Switch",
1344 .info = cxt_eapd_info,
1345 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 .put = cxt5047_hp_master_sw_put,
1347 .private_value = 0x13,
1348 },
1349
1350 {}
1351};
1352
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001353static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001354 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001355 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001356 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1357 {}
1358};
1359
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001360static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 { } /* end */
1363};
1364
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001365static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 /* Line in, Mic, Built-in Mic */
1367 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1368 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1369 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001370 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001371 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001372 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1373 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001374 /* Record selector: Mic */
1375 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1376 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1377 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1378 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001379 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1380 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1381 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1382 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001383 /* SPDIF route: PCM */
1384 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001385 /* Enable unsolicited events */
1386 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1387 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388 { } /* end */
1389};
1390
1391/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001392static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001393 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001394 {}
1395};
1396
1397/* Test configuration for debugging, modelled after the ALC260 test
1398 * configuration.
1399 */
1400#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001401static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001402 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001403 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001404 { "LINE1 pin", 0x0 },
1405 { "MIC1 pin", 0x1 },
1406 { "MIC2 pin", 0x2 },
1407 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001408 },
1409};
1410
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001411static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001412
1413 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001414 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1416 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001418 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001422 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001426
1427 /* Modes for retasking pin widgets */
1428 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1429 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1430
Tobin Davis82f30042007-02-13 12:45:44 +01001431 /* EAPD Switch Control */
1432 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1433
Tobin Davisc9b443d2006-11-14 12:13:39 +01001434 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001435 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1436 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1437 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1438 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1439 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1440 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1441 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1442 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443
Tobin Davis82f30042007-02-13 12:45:44 +01001444 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1445 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1446 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1447 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1448 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1449 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1450 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1451 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001452 {
1453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1454 .name = "Input Source",
1455 .info = conexant_mux_enum_info,
1456 .get = conexant_mux_enum_get,
1457 .put = conexant_mux_enum_put,
1458 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001459 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001460
Tobin Davisc9b443d2006-11-14 12:13:39 +01001461 { } /* end */
1462};
1463
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001464static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001465 /* Enable retasking pins as output, initially without power amp */
1466 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1467 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1469
1470 /* Disable digital (SPDIF) pins initially, but users can enable
1471 * them via a mixer switch. In the case of SPDIF-out, this initverb
1472 * payload also sets the generation to 0, output to be in "consumer"
1473 * PCM format, copyright asserted, no pre-emphasis and no validity
1474 * control.
1475 */
1476 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1477
1478 /* Ensure mic1, mic2, line1 pin widgets take input from the
1479 * OUT1 sum bus when acting as an output.
1480 */
1481 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1482 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1483
1484 /* Start with output sum widgets muted and their output gains at min */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1487
1488 /* Unmute retasking pin widget output buffers since the default
1489 * state appears to be output. As the pin mode is changed by the
1490 * user the pin mode control will take care of enabling the pin's
1491 * input/output buffers as needed.
1492 */
1493 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1494 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1495 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1496
1497 /* Mute capture amp left and right */
1498 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1499
1500 /* Set ADC connection select to match default mixer setting (mic1
1501 * pin)
1502 */
1503 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1504
1505 /* Mute all inputs to mixer widget (even unconnected ones) */
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1507 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1508 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1509 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1510 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1511 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1512 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1513 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1514
1515 { }
1516};
1517#endif
1518
1519
1520/* initialize jack-sensing, too */
1521static int cxt5047_hp_init(struct hda_codec *codec)
1522{
1523 conexant_init(codec);
1524 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001525 return 0;
1526}
1527
1528
1529enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1531 CXT5047_LAPTOP_HP, /* Some HP laptops */
1532 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001533#ifdef CONFIG_SND_DEBUG
1534 CXT5047_TEST,
1535#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001536 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001537 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538};
1539
Takashi Iwaiea734962011-01-17 11:29:34 +01001540static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001541 [CXT5047_LAPTOP] = "laptop",
1542 [CXT5047_LAPTOP_HP] = "laptop-hp",
1543 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001544#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001545 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001546#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001547 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001548};
1549
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001550static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001551 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001552 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1553 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001554 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001555 {}
1556};
1557
1558static int patch_cxt5047(struct hda_codec *codec)
1559{
1560 struct conexant_spec *spec;
1561 int board_config;
1562
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001563 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1564 cxt5047_models,
1565 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001566 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001567 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001568 if (board_config == CXT5047_AUTO)
1569 return patch_conexant_auto(codec);
1570
Tobin Davisc9b443d2006-11-14 12:13:39 +01001571 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1572 if (!spec)
1573 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001574 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001575 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576
1577 spec->multiout.max_channels = 2;
1578 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1579 spec->multiout.dac_nids = cxt5047_dac_nids;
1580 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1581 spec->num_adc_nids = 1;
1582 spec->adc_nids = cxt5047_adc_nids;
1583 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001585 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001586 spec->num_init_verbs = 1;
1587 spec->init_verbs[0] = cxt5047_init_verbs;
1588 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001589 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1590 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001591
1592 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001593
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594 switch (board_config) {
1595 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001596 spec->num_mixers = 2;
1597 spec->mixers[1] = cxt5047_hp_spk_mixers;
1598 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001599 break;
1600 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001601 spec->num_mixers = 2;
1602 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001603 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001604 codec->patch_ops.init = cxt5047_hp_init;
1605 break;
1606 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001607 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001608 spec->num_mixers = 2;
1609 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610 spec->num_init_verbs = 2;
1611 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001612 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001613 break;
1614#ifdef CONFIG_SND_DEBUG
1615 case CXT5047_TEST:
1616 spec->input_mux = &cxt5047_test_capture_source;
1617 spec->mixers[0] = cxt5047_test_mixer;
1618 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001619 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001620#endif
1621 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001622 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001623
1624 switch (codec->subsystem_id >> 16) {
1625 case 0x103c:
1626 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1627 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1628 * with 0 dB offset 0x17)
1629 */
1630 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1631 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1632 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1633 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1634 (1 << AC_AMPCAP_MUTE_SHIFT));
1635 break;
1636 }
1637
Tobin Davisc9b443d2006-11-14 12:13:39 +01001638 return 0;
1639}
1640
Takashi Iwai461e2c72008-01-25 11:35:17 +01001641/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001642static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1643static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001644
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001645static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001646 { 2, NULL },
1647};
1648
1649static void cxt5051_update_speaker(struct hda_codec *codec)
1650{
1651 struct conexant_spec *spec = codec->spec;
1652 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001653 /* headphone pin */
1654 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1655 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1656 pinctl);
1657 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001658 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1659 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1660 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001661 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1662 if (spec->ideapad)
1663 snd_hda_codec_write(codec, 0x1b, 0,
1664 AC_VERB_SET_PIN_WIDGET_CONTROL,
1665 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001666}
1667
1668/* turn on/off EAPD (+ mute HP) as a master switch */
1669static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol)
1671{
1672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1673
1674 if (!cxt_eapd_put(kcontrol, ucontrol))
1675 return 0;
1676 cxt5051_update_speaker(codec);
1677 return 1;
1678}
1679
1680/* toggle input of built-in and mic jack appropriately */
1681static void cxt5051_portb_automic(struct hda_codec *codec)
1682{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001683 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001684 unsigned int present;
1685
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001686 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001687 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001688 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001689 snd_hda_codec_write(codec, 0x14, 0,
1690 AC_VERB_SET_CONNECT_SEL,
1691 present ? 0x01 : 0x00);
1692}
1693
1694/* switch the current ADC according to the jack state */
1695static void cxt5051_portc_automic(struct hda_codec *codec)
1696{
1697 struct conexant_spec *spec = codec->spec;
1698 unsigned int present;
1699 hda_nid_t new_adc;
1700
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001701 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001702 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001703 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001704 if (present)
1705 spec->cur_adc_idx = 1;
1706 else
1707 spec->cur_adc_idx = 0;
1708 new_adc = spec->adc_nids[spec->cur_adc_idx];
1709 if (spec->cur_adc && spec->cur_adc != new_adc) {
1710 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001711 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001712 spec->cur_adc = new_adc;
1713 snd_hda_codec_setup_stream(codec, new_adc,
1714 spec->cur_adc_stream_tag, 0,
1715 spec->cur_adc_format);
1716 }
1717}
1718
1719/* mute internal speaker if HP is plugged */
1720static void cxt5051_hp_automute(struct hda_codec *codec)
1721{
1722 struct conexant_spec *spec = codec->spec;
1723
Takashi Iwaid56757a2009-11-18 08:00:14 +01001724 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001725 cxt5051_update_speaker(codec);
1726}
1727
1728/* unsolicited event for HP jack sensing */
1729static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1730 unsigned int res)
1731{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001732 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001733 switch (res >> 26) {
1734 case CONEXANT_HP_EVENT:
1735 cxt5051_hp_automute(codec);
1736 break;
1737 case CXT5051_PORTB_EVENT:
1738 cxt5051_portb_automic(codec);
1739 break;
1740 case CXT5051_PORTC_EVENT:
1741 cxt5051_portc_automic(codec);
1742 break;
1743 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001744 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001745}
1746
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001747static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001748 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1749 {
1750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1751 .name = "Master Playback Switch",
1752 .info = cxt_eapd_info,
1753 .get = cxt_eapd_get,
1754 .put = cxt5051_hp_master_sw_put,
1755 .private_value = 0x1a,
1756 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001757 {}
1758};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001759
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001760static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001761 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1762 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001763 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1764 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001765 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1766 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001767 {}
1768};
1769
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001770static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001771 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1772 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001773 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1774 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001775 {}
1776};
1777
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001778static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001779 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1780 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001781 {}
1782};
1783
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001784static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001785 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1786 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001787 {}
1788};
1789
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001790static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001791 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1792 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001793 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1794 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001795 {}
1796};
1797
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001798static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001799 /* Line in, Mic */
1800 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1801 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1802 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1803 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1804 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1805 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1806 /* SPK */
1807 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1808 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1809 /* HP, Amp */
1810 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1811 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1812 /* DAC1 */
1813 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001814 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1817 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1818 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001819 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001820 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1821 /* EAPD */
1822 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1823 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001824 { } /* end */
1825};
1826
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001827static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001828 /* Line in, Mic */
1829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1830 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1831 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1832 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1833 /* SPK */
1834 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1835 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1836 /* HP, Amp */
1837 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1838 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1839 /* DAC1 */
1840 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001841 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1843 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1844 /* SPDIF route: PCM */
1845 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1846 /* EAPD */
1847 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1848 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001849 { } /* end */
1850};
1851
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001852static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001853 /* Line in, Mic */
1854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1855 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1856 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1857 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1858 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1859 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1860 /* SPK */
1861 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1862 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1863 /* HP, Amp */
1864 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1865 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1866 /* Docking HP */
1867 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1868 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1869 /* DAC1 */
1870 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001871 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001872 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1873 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1874 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1875 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001876 {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 -05001877 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1878 /* EAPD */
1879 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1880 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001881 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1882 { } /* end */
1883};
1884
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001885static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001886 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001888 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1889 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1890 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1891 /* SPK */
1892 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1893 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1894 /* HP, Amp */
1895 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1896 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1897 /* DAC1 */
1898 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001899 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001900 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1901 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1902 /* SPDIF route: PCM */
1903 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1904 /* EAPD */
1905 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1906 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001907 { } /* end */
1908};
1909
Takashi Iwai6953e552010-01-24 11:00:27 +01001910static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1911 unsigned int event)
1912{
1913 snd_hda_codec_write(codec, nid, 0,
1914 AC_VERB_SET_UNSOLICITED_ENABLE,
1915 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001916 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1917 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001918}
1919
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001920static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001921 /* Subwoofer */
1922 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1923 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1924 { } /* end */
1925};
1926
Takashi Iwai461e2c72008-01-25 11:35:17 +01001927/* initialize jack-sensing, too */
1928static int cxt5051_init(struct hda_codec *codec)
1929{
Takashi Iwai6953e552010-01-24 11:00:27 +01001930 struct conexant_spec *spec = codec->spec;
1931
Takashi Iwai461e2c72008-01-25 11:35:17 +01001932 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001933 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001934
1935 if (spec->auto_mic & AUTO_MIC_PORTB)
1936 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1937 if (spec->auto_mic & AUTO_MIC_PORTC)
1938 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1939
Takashi Iwai461e2c72008-01-25 11:35:17 +01001940 if (codec->patch_ops.unsol_event) {
1941 cxt5051_hp_automute(codec);
1942 cxt5051_portb_automic(codec);
1943 cxt5051_portc_automic(codec);
1944 }
1945 return 0;
1946}
1947
1948
1949enum {
1950 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1951 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001952 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001953 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001954 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001955 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001956 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001957 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001958 CXT5051_MODELS
1959};
1960
Takashi Iwaiea734962011-01-17 11:29:34 +01001961static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001962 [CXT5051_LAPTOP] = "laptop",
1963 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001964 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001965 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001966 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001967 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001968 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001969 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001970};
1971
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001972static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001973 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001974 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001975 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001976 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001977 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1978 CXT5051_LAPTOP),
1979 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001980 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001981 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001982 {}
1983};
1984
1985static int patch_cxt5051(struct hda_codec *codec)
1986{
1987 struct conexant_spec *spec;
1988 int board_config;
1989
Takashi Iwai6764bce2011-05-13 16:52:25 +02001990 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1991 cxt5051_models,
1992 cxt5051_cfg_tbl);
1993 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001994 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001995 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001996 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001997
Takashi Iwai461e2c72008-01-25 11:35:17 +01001998 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1999 if (!spec)
2000 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002001 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002002 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002003
2004 codec->patch_ops = conexant_patch_ops;
2005 codec->patch_ops.init = cxt5051_init;
2006
2007 spec->multiout.max_channels = 2;
2008 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2009 spec->multiout.dac_nids = cxt5051_dac_nids;
2010 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2011 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2012 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002013 spec->num_mixers = 2;
2014 spec->mixers[0] = cxt5051_capture_mixers;
2015 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002016 spec->num_init_verbs = 1;
2017 spec->init_verbs[0] = cxt5051_init_verbs;
2018 spec->spdif_route = 0;
2019 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2020 spec->channel_mode = cxt5051_modes;
2021 spec->cur_adc = 0;
2022 spec->cur_adc_idx = 0;
2023
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002024 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2025
Takashi Iwai79d7d532009-03-04 09:03:50 +01002026 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2027
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002028 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002029 switch (board_config) {
2030 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002031 spec->mixers[0] = cxt5051_hp_mixers;
2032 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002033 case CXT5051_HP_DV6736:
2034 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2035 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002036 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002037 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002038 case CXT5051_LENOVO_X200:
2039 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002040 /* Thinkpad X301 does not have S/PDIF wired and no ability
2041 to use a docking station. */
2042 if (codec->subsystem_id == 0x17aa211f)
2043 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002044 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002045 case CXT5051_F700:
2046 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2047 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002048 spec->auto_mic = 0;
2049 break;
2050 case CXT5051_TOSHIBA:
2051 spec->mixers[0] = cxt5051_toshiba_mixers;
2052 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002053 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002054 case CXT5051_IDEAPAD:
2055 spec->init_verbs[spec->num_init_verbs++] =
2056 cxt5051_ideapad_init_verbs;
2057 spec->ideapad = 1;
2058 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002059 }
2060
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002061 if (spec->beep_amp)
2062 snd_hda_attach_beep_device(codec, spec->beep_amp);
2063
Takashi Iwai461e2c72008-01-25 11:35:17 +01002064 return 0;
2065}
2066
Daniel Drake0fb67e92009-07-16 14:46:57 +01002067/* Conexant 5066 specific */
2068
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002069static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2070static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2071static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2072static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002073
Daniel Drakedbaccc02009-11-09 15:17:24 +00002074/* OLPC's microphone port is DC coupled for use with external sensors,
2075 * therefore we use a 50% mic bias in order to center the input signal with
2076 * the DC input range of the codec. */
2077#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2078
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002079static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002080 { 2, NULL },
2081};
2082
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002083#define HP_PRESENT_PORT_A (1 << 0)
2084#define HP_PRESENT_PORT_D (1 << 1)
2085#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2086#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2087
Daniel Drake0fb67e92009-07-16 14:46:57 +01002088static void cxt5066_update_speaker(struct hda_codec *codec)
2089{
2090 struct conexant_spec *spec = codec->spec;
2091 unsigned int pinctl;
2092
John Baboval3a253442010-12-02 11:21:31 -05002093 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2094 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002095
2096 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002097 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002098 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2099 pinctl);
2100
2101 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002102 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2103 if (spec->dell_automute || spec->thinkpad) {
2104 /* Mute if Port A is connected */
2105 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002106 pinctl = 0;
2107 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002108 /* Thinkpad/Dell doesn't give pin-D status */
2109 if (!hp_port_d_present(spec))
2110 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002111 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002112 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2113 pinctl);
2114
2115 /* CLASS_D AMP */
2116 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2117 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2118 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002119}
2120
2121/* turn on/off EAPD (+ mute HP) as a master switch */
2122static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2123 struct snd_ctl_elem_value *ucontrol)
2124{
2125 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2126
2127 if (!cxt_eapd_put(kcontrol, ucontrol))
2128 return 0;
2129
2130 cxt5066_update_speaker(codec);
2131 return 1;
2132}
2133
Daniel Drakec4cfe662010-01-07 13:47:04 +01002134static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2135 .num_items = 3,
2136 .items = {
2137 { "Off", PIN_IN },
2138 { "50%", PIN_VREF50 },
2139 { "80%", PIN_VREF80 },
2140 },
2141};
2142
2143static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2144{
2145 struct conexant_spec *spec = codec->spec;
2146 /* Even though port F is the DC input, the bias is controlled on port B.
2147 * we also leave that port as an active input (but unselected) in DC mode
2148 * just in case that is necessary to make the bias setting take effect. */
2149 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2150 AC_VERB_SET_PIN_WIDGET_CONTROL,
2151 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2152}
2153
Daniel Drake75f89912010-01-07 13:46:25 +01002154/* OLPC defers mic widget control until when capture is started because the
2155 * microphone LED comes on as soon as these settings are put in place. if we
2156 * did this before recording, it would give the false indication that recording
2157 * is happening when it is not. */
2158static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002159{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002160 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002161 if (!spec->recording)
2162 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002163
Daniel Drakec4cfe662010-01-07 13:47:04 +01002164 if (spec->dc_enable) {
2165 /* in DC mode we ignore presence detection and just use the jack
2166 * through our special DC port */
2167 const struct hda_verb enable_dc_mode[] = {
2168 /* disble internal mic, port C */
2169 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2170
2171 /* enable DC capture, port F */
2172 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2173 {},
2174 };
2175
2176 snd_hda_sequence_write(codec, enable_dc_mode);
2177 /* port B input disabled (and bias set) through the following call */
2178 cxt5066_set_olpc_dc_bias(codec);
2179 return;
2180 }
2181
2182 /* disable DC (port F) */
2183 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2184
Daniel Drake75f89912010-01-07 13:46:25 +01002185 /* external mic, port B */
2186 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2187 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002188
Daniel Drake75f89912010-01-07 13:46:25 +01002189 /* internal mic, port C */
2190 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2191 spec->ext_mic_present ? 0 : PIN_VREF80);
2192}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002193
Daniel Drake75f89912010-01-07 13:46:25 +01002194/* toggle input of built-in and mic jack appropriately */
2195static void cxt5066_olpc_automic(struct hda_codec *codec)
2196{
2197 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002198 unsigned int present;
2199
Daniel Drakec4cfe662010-01-07 13:47:04 +01002200 if (spec->dc_enable) /* don't do presence detection in DC mode */
2201 return;
2202
Daniel Drake75f89912010-01-07 13:46:25 +01002203 present = snd_hda_codec_read(codec, 0x1a, 0,
2204 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2205 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002206 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002207 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002208 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002209
2210 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2211 present ? 0 : 1);
2212 spec->ext_mic_present = !!present;
2213
2214 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002215}
2216
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002217/* toggle input of built-in digital mic and mic jack appropriately */
2218static void cxt5066_vostro_automic(struct hda_codec *codec)
2219{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002220 unsigned int present;
2221
2222 struct hda_verb ext_mic_present[] = {
2223 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002224 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002225
2226 /* switch to external mic input */
2227 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2228 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2229
2230 /* disable internal digital mic */
2231 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2232 {}
2233 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002234 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002235 /* enable internal mic, port C */
2236 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2237
2238 /* switch to internal mic input */
2239 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2240
2241 /* disable external mic, port B */
2242 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2243 {}
2244 };
2245
2246 present = snd_hda_jack_detect(codec, 0x1a);
2247 if (present) {
2248 snd_printdd("CXT5066: external microphone detected\n");
2249 snd_hda_sequence_write(codec, ext_mic_present);
2250 } else {
2251 snd_printdd("CXT5066: external microphone absent\n");
2252 snd_hda_sequence_write(codec, ext_mic_absent);
2253 }
2254}
2255
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002256/* toggle input of built-in digital mic and mic jack appropriately */
2257static void cxt5066_ideapad_automic(struct hda_codec *codec)
2258{
2259 unsigned int present;
2260
2261 struct hda_verb ext_mic_present[] = {
2262 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2263 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2264 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2265 {}
2266 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002267 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002268 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2269 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2270 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2271 {}
2272 };
2273
2274 present = snd_hda_jack_detect(codec, 0x1b);
2275 if (present) {
2276 snd_printdd("CXT5066: external microphone detected\n");
2277 snd_hda_sequence_write(codec, ext_mic_present);
2278 } else {
2279 snd_printdd("CXT5066: external microphone absent\n");
2280 snd_hda_sequence_write(codec, ext_mic_absent);
2281 }
2282}
2283
David Henningssona1d69062011-01-21 13:33:28 +01002284
2285/* toggle input of built-in digital mic and mic jack appropriately */
2286static void cxt5066_asus_automic(struct hda_codec *codec)
2287{
2288 unsigned int present;
2289
2290 present = snd_hda_jack_detect(codec, 0x1b);
2291 snd_printdd("CXT5066: external microphone present=%d\n", present);
2292 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2293 present ? 1 : 0);
2294}
2295
2296
David Henningsson048e78a2010-09-02 08:35:47 +02002297/* toggle input of built-in digital mic and mic jack appropriately */
2298static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2299{
2300 unsigned int present;
2301
2302 present = snd_hda_jack_detect(codec, 0x1b);
2303 snd_printdd("CXT5066: external microphone present=%d\n", present);
2304 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2305 present ? 1 : 3);
2306}
2307
2308
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002309/* toggle input of built-in digital mic and mic jack appropriately
2310 order is: external mic -> dock mic -> interal mic */
2311static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2312{
2313 unsigned int ext_present, dock_present;
2314
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002315 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002316 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2317 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2318 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2319 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2320 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2321 {}
2322 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002323 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002324 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2325 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2326 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2327 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2328 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2329 {}
2330 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002331 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002332 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2333 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2334 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2335 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2336 {}
2337 };
2338
2339 ext_present = snd_hda_jack_detect(codec, 0x1b);
2340 dock_present = snd_hda_jack_detect(codec, 0x1a);
2341 if (ext_present) {
2342 snd_printdd("CXT5066: external microphone detected\n");
2343 snd_hda_sequence_write(codec, ext_mic_present);
2344 } else if (dock_present) {
2345 snd_printdd("CXT5066: dock microphone detected\n");
2346 snd_hda_sequence_write(codec, dock_mic_present);
2347 } else {
2348 snd_printdd("CXT5066: external microphone absent\n");
2349 snd_hda_sequence_write(codec, ext_mic_absent);
2350 }
2351}
2352
Daniel Drake0fb67e92009-07-16 14:46:57 +01002353/* mute internal speaker if HP is plugged */
2354static void cxt5066_hp_automute(struct hda_codec *codec)
2355{
2356 struct conexant_spec *spec = codec->spec;
2357 unsigned int portA, portD;
2358
2359 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002360 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002361
2362 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002363 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002364
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002365 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2366 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2368 portA, portD, spec->hp_present);
2369 cxt5066_update_speaker(codec);
2370}
2371
David Henningsson02b6b5b2011-01-21 13:27:39 +01002372/* Dispatch the right mic autoswitch function */
2373static void cxt5066_automic(struct hda_codec *codec)
2374{
2375 struct conexant_spec *spec = codec->spec;
2376
2377 if (spec->dell_vostro)
2378 cxt5066_vostro_automic(codec);
2379 else if (spec->ideapad)
2380 cxt5066_ideapad_automic(codec);
2381 else if (spec->thinkpad)
2382 cxt5066_thinkpad_automic(codec);
2383 else if (spec->hp_laptop)
2384 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002385 else if (spec->asus)
2386 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002387}
2388
Daniel Drake0fb67e92009-07-16 14:46:57 +01002389/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002390static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002391{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002392 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002393 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2394 switch (res >> 26) {
2395 case CONEXANT_HP_EVENT:
2396 cxt5066_hp_automute(codec);
2397 break;
2398 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002399 /* ignore mic events in DC mode; we're always using the jack */
2400 if (!spec->dc_enable)
2401 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002402 break;
2403 }
2404}
2405
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002406/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002407static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002408{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002409 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002410 switch (res >> 26) {
2411 case CONEXANT_HP_EVENT:
2412 cxt5066_hp_automute(codec);
2413 break;
2414 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002415 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002416 break;
2417 }
2418}
2419
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002420
Daniel Drake0fb67e92009-07-16 14:46:57 +01002421static const struct hda_input_mux cxt5066_analog_mic_boost = {
2422 .num_items = 5,
2423 .items = {
2424 { "0dB", 0 },
2425 { "10dB", 1 },
2426 { "20dB", 2 },
2427 { "30dB", 3 },
2428 { "40dB", 4 },
2429 },
2430};
2431
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002432static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002433{
2434 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002435 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002436 AC_VERB_SET_AMP_GAIN_MUTE,
2437 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2438 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002439 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002440 /* adjust the internal mic as well...it is not through 0x17 */
2441 snd_hda_codec_write_cache(codec, 0x23, 0,
2442 AC_VERB_SET_AMP_GAIN_MUTE,
2443 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2444 cxt5066_analog_mic_boost.
2445 items[spec->mic_boost].index);
2446 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002447}
2448
Daniel Drake0fb67e92009-07-16 14:46:57 +01002449static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2450 struct snd_ctl_elem_info *uinfo)
2451{
2452 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2453}
2454
2455static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2456 struct snd_ctl_elem_value *ucontrol)
2457{
2458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002459 struct conexant_spec *spec = codec->spec;
2460 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002461 return 0;
2462}
2463
2464static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2465 struct snd_ctl_elem_value *ucontrol)
2466{
2467 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002468 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002469 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2470 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002471 idx = ucontrol->value.enumerated.item[0];
2472 if (idx >= imux->num_items)
2473 idx = imux->num_items - 1;
2474
Daniel Drakec4cfe662010-01-07 13:47:04 +01002475 spec->mic_boost = idx;
2476 if (!spec->dc_enable)
2477 cxt5066_set_mic_boost(codec);
2478 return 1;
2479}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002480
Daniel Drakec4cfe662010-01-07 13:47:04 +01002481static void cxt5066_enable_dc(struct hda_codec *codec)
2482{
2483 const struct hda_verb enable_dc_mode[] = {
2484 /* disable gain */
2485 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486
2487 /* switch to DC input */
2488 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2489 {}
2490 };
2491
2492 /* configure as input source */
2493 snd_hda_sequence_write(codec, enable_dc_mode);
2494 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2495}
2496
2497static void cxt5066_disable_dc(struct hda_codec *codec)
2498{
2499 /* reconfigure input source */
2500 cxt5066_set_mic_boost(codec);
2501 /* automic also selects the right mic if we're recording */
2502 cxt5066_olpc_automic(codec);
2503}
2504
2505static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2506 struct snd_ctl_elem_value *ucontrol)
2507{
2508 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2509 struct conexant_spec *spec = codec->spec;
2510 ucontrol->value.integer.value[0] = spec->dc_enable;
2511 return 0;
2512}
2513
2514static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2515 struct snd_ctl_elem_value *ucontrol)
2516{
2517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2518 struct conexant_spec *spec = codec->spec;
2519 int dc_enable = !!ucontrol->value.integer.value[0];
2520
2521 if (dc_enable == spec->dc_enable)
2522 return 0;
2523
2524 spec->dc_enable = dc_enable;
2525 if (dc_enable)
2526 cxt5066_enable_dc(codec);
2527 else
2528 cxt5066_disable_dc(codec);
2529
2530 return 1;
2531}
2532
2533static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2534 struct snd_ctl_elem_info *uinfo)
2535{
2536 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2537}
2538
2539static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2540 struct snd_ctl_elem_value *ucontrol)
2541{
2542 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2543 struct conexant_spec *spec = codec->spec;
2544 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2545 return 0;
2546}
2547
2548static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2549 struct snd_ctl_elem_value *ucontrol)
2550{
2551 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2552 struct conexant_spec *spec = codec->spec;
2553 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2554 unsigned int idx;
2555
2556 idx = ucontrol->value.enumerated.item[0];
2557 if (idx >= imux->num_items)
2558 idx = imux->num_items - 1;
2559
2560 spec->dc_input_bias = idx;
2561 if (spec->dc_enable)
2562 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002563 return 1;
2564}
2565
Daniel Drake75f89912010-01-07 13:46:25 +01002566static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2567{
2568 struct conexant_spec *spec = codec->spec;
2569 /* mark as recording and configure the microphone widget so that the
2570 * recording LED comes on. */
2571 spec->recording = 1;
2572 cxt5066_olpc_select_mic(codec);
2573}
2574
2575static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2576{
2577 struct conexant_spec *spec = codec->spec;
2578 const struct hda_verb disable_mics[] = {
2579 /* disable external mic, port B */
2580 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2581
2582 /* disble internal mic, port C */
2583 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002584
2585 /* disable DC capture, port F */
2586 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002587 {},
2588 };
2589
2590 snd_hda_sequence_write(codec, disable_mics);
2591 spec->recording = 0;
2592}
2593
Andy Robinsonf6a24912011-01-24 10:12:37 -05002594static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002595 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002596 int num_pins)
2597{
2598 struct conexant_spec *spec = codec->spec;
2599 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2600 int i;
2601
2602 for (i = 0; i < num_pins; i++, dig_pins++) {
2603 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2604 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2605 continue;
2606 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2607 continue;
2608 if (spec->slave_dig_outs[0])
2609 nid_loc++;
2610 else
2611 nid_loc = spec->slave_dig_outs;
2612 }
2613}
2614
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002615static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002616 .num_items = 4,
2617 .items = {
2618 { "Mic B", 0 },
2619 { "Mic C", 1 },
2620 { "Mic E", 2 },
2621 { "Mic F", 3 },
2622 },
2623};
2624
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002625static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002626 .ops = &snd_hda_bind_vol,
2627 .values = {
2628 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2629 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2630 0
2631 },
2632};
2633
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002634static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002635 .ops = &snd_hda_bind_sw,
2636 .values = {
2637 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2638 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2639 0
2640 },
2641};
2642
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002643static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002644 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2645 {}
2646};
2647
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002648static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002649 {
2650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2651 .name = "Master Playback Volume",
2652 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2653 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2654 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002655 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002656 .info = snd_hda_mixer_amp_volume_info,
2657 .get = snd_hda_mixer_amp_volume_get,
2658 .put = snd_hda_mixer_amp_volume_put,
2659 .tlv = { .c = snd_hda_mixer_amp_tlv },
2660 /* offset by 28 volume steps to limit minimum gain to -46dB */
2661 .private_value =
2662 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2663 },
2664 {}
2665};
2666
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002667static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002668 {
2669 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2670 .name = "DC Mode Enable Switch",
2671 .info = snd_ctl_boolean_mono_info,
2672 .get = cxt5066_olpc_dc_get,
2673 .put = cxt5066_olpc_dc_put,
2674 },
2675 {
2676 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2677 .name = "DC Input Bias Enum",
2678 .info = cxt5066_olpc_dc_bias_enum_info,
2679 .get = cxt5066_olpc_dc_bias_enum_get,
2680 .put = cxt5066_olpc_dc_bias_enum_put,
2681 },
2682 {}
2683};
2684
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002685static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002686 {
2687 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2688 .name = "Master Playback Switch",
2689 .info = cxt_eapd_info,
2690 .get = cxt_eapd_get,
2691 .put = cxt5066_hp_master_sw_put,
2692 .private_value = 0x1d,
2693 },
2694
2695 {
2696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002697 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002698 .info = cxt5066_mic_boost_mux_enum_info,
2699 .get = cxt5066_mic_boost_mux_enum_get,
2700 .put = cxt5066_mic_boost_mux_enum_put,
2701 },
2702
2703 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2704 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2705 {}
2706};
2707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002708static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002709 {
2710 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002711 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002712 .info = cxt5066_mic_boost_mux_enum_info,
2713 .get = cxt5066_mic_boost_mux_enum_get,
2714 .put = cxt5066_mic_boost_mux_enum_put,
2715 .private_value = 0x23 | 0x100,
2716 },
2717 {}
2718};
2719
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002720static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002721 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2722 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2723 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2724 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2725
2726 /* Speakers */
2727 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2728 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2729
2730 /* HP, Amp */
2731 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2732 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2733
2734 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2735 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2736
2737 /* DAC1 */
2738 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2739
2740 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2741 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2742 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2744 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2745 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2746
2747 /* no digital microphone support yet */
2748 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2749
2750 /* Audio input selector */
2751 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2752
2753 /* SPDIF route: PCM */
2754 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2755 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2756
2757 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2758 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2759
2760 /* EAPD */
2761 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2762
2763 /* not handling these yet */
2764 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2765 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2766 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2767 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2768 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2769 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2770 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2771 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2772 { } /* end */
2773};
2774
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002775static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002776 /* Port A: headphones */
2777 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2778 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2779
2780 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002781 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002782
2783 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002784 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002785
2786 /* Port D: unused */
2787 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2788
2789 /* Port E: unused, but has primary EAPD */
2790 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2791 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2792
Daniel Drakec4cfe662010-01-07 13:47:04 +01002793 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002794 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2795
2796 /* Port G: internal speakers */
2797 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2798 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2799
2800 /* DAC1 */
2801 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2802
2803 /* DAC2: unused */
2804 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2805
2806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2810 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2811 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2812 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2815 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2816 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2817 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2818
2819 /* Disable digital microphone port */
2820 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821
2822 /* Audio input selectors */
2823 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2824 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2825
2826 /* Disable SPDIF */
2827 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2828 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2829
2830 /* enable unsolicited events for Port A and B */
2831 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2832 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2833 { } /* end */
2834};
2835
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002836static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002837 /* Port A: headphones */
2838 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2839 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2840
2841 /* Port B: external microphone */
2842 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2843
2844 /* Port C: unused */
2845 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2846
2847 /* Port D: unused */
2848 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2849
2850 /* Port E: unused, but has primary EAPD */
2851 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2852 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2853
2854 /* Port F: unused */
2855 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2856
2857 /* Port G: internal speakers */
2858 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2859 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2860
2861 /* DAC1 */
2862 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2863
2864 /* DAC2: unused */
2865 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2866
2867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2870 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2871 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2872 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2873 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2874 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2875 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2876 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2877 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2878 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2879
2880 /* Digital microphone port */
2881 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2882
2883 /* Audio input selectors */
2884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2885 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2886
2887 /* Disable SPDIF */
2888 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2889 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2890
2891 /* enable unsolicited events for Port A and B */
2892 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2893 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2894 { } /* end */
2895};
2896
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002897static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002898 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2899 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2900 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2901 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2902
2903 /* Speakers */
2904 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2905 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2906
2907 /* HP, Amp */
2908 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2909 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2910
2911 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2912 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2913
2914 /* DAC1 */
2915 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2916
2917 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2918 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2919 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2920 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2921 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2922 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2923 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2924
2925 /* Audio input selector */
2926 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2927 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2928
2929 /* SPDIF route: PCM */
2930 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2931 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2932
2933 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2934 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2935
2936 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002937 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002938
2939 /* EAPD */
2940 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2941
2942 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2943 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2944 { } /* end */
2945};
2946
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002947static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002948 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2949 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2950
2951 /* Port G: internal speakers */
2952 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2953 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2954
2955 /* Port A: HP, Amp */
2956 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2957 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2958
2959 /* Port B: Mic Dock */
2960 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2961
2962 /* Port C: Mic */
2963 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2964
2965 /* Port D: HP Dock, Amp */
2966 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2967 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2968
2969 /* DAC1 */
2970 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2971
2972 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2973 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2974 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2975 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2976 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2977 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2978 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2979
2980 /* Audio input selector */
2981 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2982 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2983
2984 /* SPDIF route: PCM */
2985 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2986 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2987
2988 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2989 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2990
2991 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002992 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002993
2994 /* EAPD */
2995 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2996
2997 /* enable unsolicited events for Port A, B, C and D */
2998 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2999 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3000 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3001 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3002 { } /* end */
3003};
3004
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003005static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01003006 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3007 { } /* end */
3008};
3009
David Henningsson048e78a2010-09-02 08:35:47 +02003010
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003011static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02003012 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3013 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3014 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3015 { } /* end */
3016};
3017
Daniel Drake0fb67e92009-07-16 14:46:57 +01003018/* initialize jack-sensing, too */
3019static int cxt5066_init(struct hda_codec *codec)
3020{
3021 snd_printdd("CXT5066: init\n");
3022 conexant_init(codec);
3023 if (codec->patch_ops.unsol_event) {
3024 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003025 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003026 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003027 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003028 return 0;
3029}
3030
Daniel Drake75f89912010-01-07 13:46:25 +01003031static int cxt5066_olpc_init(struct hda_codec *codec)
3032{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003033 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003034 snd_printdd("CXT5066: init\n");
3035 conexant_init(codec);
3036 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003037 if (!spec->dc_enable) {
3038 cxt5066_set_mic_boost(codec);
3039 cxt5066_olpc_automic(codec);
3040 } else {
3041 cxt5066_enable_dc(codec);
3042 }
Daniel Drake75f89912010-01-07 13:46:25 +01003043 return 0;
3044}
3045
Daniel Drake0fb67e92009-07-16 14:46:57 +01003046enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003047 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003048 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3049 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003050 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003051 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003052 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003053 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003054 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003055 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003056 CXT5066_MODELS
3057};
3058
Takashi Iwaiea734962011-01-17 11:29:34 +01003059static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003060 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003061 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3062 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003063 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003064 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003065 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003066 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003067 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003068 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003069};
3070
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003071static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
David Henningsson9966db222011-06-21 21:01:52 +02003072 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003073 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003074 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003075 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003076 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003077 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003078 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003079 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3080 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003081 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003082 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003083 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003084 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003085 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003086 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003087 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003088 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3089 CXT5066_LAPTOP),
3090 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003091 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003092 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003093 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003094 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003095 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003096 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02003097 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003098 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Takashi Iwaiaf4ccf42011-05-25 07:33:20 +02003099 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
David Henningsson22f21d52011-01-07 07:53:39 +01003100 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel T Chen7ab1fc02011-06-10 10:14:01 -04003101 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003102 {}
3103};
3104
3105static int patch_cxt5066(struct hda_codec *codec)
3106{
3107 struct conexant_spec *spec;
3108 int board_config;
3109
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003110 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3111 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003112 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02003113 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003114 if (board_config == CXT5066_AUTO)
3115 return patch_conexant_auto(codec);
3116
Daniel Drake0fb67e92009-07-16 14:46:57 +01003117 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3118 if (!spec)
3119 return -ENOMEM;
3120 codec->spec = spec;
3121
3122 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003123 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003124
3125 spec->dell_automute = 0;
3126 spec->multiout.max_channels = 2;
3127 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3128 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003129 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3130 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003131 spec->num_adc_nids = 1;
3132 spec->adc_nids = cxt5066_adc_nids;
3133 spec->capsrc_nids = cxt5066_capsrc_nids;
3134 spec->input_mux = &cxt5066_capture_source;
3135
3136 spec->port_d_mode = PIN_HP;
3137
3138 spec->num_init_verbs = 1;
3139 spec->init_verbs[0] = cxt5066_init_verbs;
3140 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3141 spec->channel_mode = cxt5066_modes;
3142 spec->cur_adc = 0;
3143 spec->cur_adc_idx = 0;
3144
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003145 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3146
Daniel Drake0fb67e92009-07-16 14:46:57 +01003147 switch (board_config) {
3148 default:
3149 case CXT5066_LAPTOP:
3150 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3152 break;
3153 case CXT5066_DELL_LAPTOP:
3154 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3155 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3156
3157 spec->port_d_mode = PIN_OUT;
3158 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3159 spec->num_init_verbs++;
3160 spec->dell_automute = 1;
3161 break;
David Henningssona1d69062011-01-21 13:33:28 +01003162 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003163 case CXT5066_HP_LAPTOP:
3164 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003165 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003166 spec->init_verbs[spec->num_init_verbs] =
3167 cxt5066_init_verbs_hp_laptop;
3168 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003169 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3170 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003171 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3172 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3173 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003174 if (board_config == CXT5066_HP_LAPTOP)
3175 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003176 /* input source automatically selected */
3177 spec->input_mux = NULL;
3178 spec->port_d_mode = 0;
3179 spec->mic_boost = 3; /* default 30dB gain */
3180 break;
3181
Daniel Drake0fb67e92009-07-16 14:46:57 +01003182 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003183 codec->patch_ops.init = cxt5066_olpc_init;
3184 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003185 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3186 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003187 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003188 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3189 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003190 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003191
3192 /* no S/PDIF out */
3193 spec->multiout.dig_out_nid = 0;
3194
3195 /* input source automatically selected */
3196 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003197
3198 /* our capture hooks which allow us to turn on the microphone LED
3199 * at the right time */
3200 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3201 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003202 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003203 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003204 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003205 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003206 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3207 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3208 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003209 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003210 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003211 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003212 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003213
3214 /* no S/PDIF out */
3215 spec->multiout.dig_out_nid = 0;
3216
3217 /* input source automatically selected */
3218 spec->input_mux = NULL;
3219 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003220 case CXT5066_IDEAPAD:
3221 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003222 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003223 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3224 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3225 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3226 spec->port_d_mode = 0;
3227 spec->ideapad = 1;
3228 spec->mic_boost = 2; /* default 20dB gain */
3229
3230 /* no S/PDIF out */
3231 spec->multiout.dig_out_nid = 0;
3232
3233 /* input source automatically selected */
3234 spec->input_mux = NULL;
3235 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003236 case CXT5066_THINKPAD:
3237 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003238 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003239 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3240 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3241 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3242 spec->thinkpad = 1;
3243 spec->port_d_mode = PIN_OUT;
3244 spec->mic_boost = 2; /* default 20dB gain */
3245
3246 /* no S/PDIF out */
3247 spec->multiout.dig_out_nid = 0;
3248
3249 /* input source automatically selected */
3250 spec->input_mux = NULL;
3251 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003252 }
3253
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003254 if (spec->beep_amp)
3255 snd_hda_attach_beep_device(codec, spec->beep_amp);
3256
Daniel Drake0fb67e92009-07-16 14:46:57 +01003257 return 0;
3258}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003259
3260/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003261 * Automatic parser for CX20641 & co
3262 */
3263
Takashi Iwai6764bce2011-05-13 16:52:25 +02003264static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3265 struct hda_codec *codec,
3266 unsigned int stream_tag,
3267 unsigned int format,
3268 struct snd_pcm_substream *substream)
3269{
3270 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003271 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003272 if (spec->adc_switching) {
3273 spec->cur_adc = adc;
3274 spec->cur_adc_stream_tag = stream_tag;
3275 spec->cur_adc_format = format;
3276 }
3277 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3278 return 0;
3279}
3280
3281static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3282 struct hda_codec *codec,
3283 struct snd_pcm_substream *substream)
3284{
3285 struct conexant_spec *spec = codec->spec;
3286 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3287 spec->cur_adc = 0;
3288 return 0;
3289}
3290
3291static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3292 .substreams = 1,
3293 .channels_min = 2,
3294 .channels_max = 2,
3295 .nid = 0, /* fill later */
3296 .ops = {
3297 .prepare = cx_auto_capture_pcm_prepare,
3298 .cleanup = cx_auto_capture_pcm_cleanup
3299 },
3300};
3301
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003302static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003303
Takashi Iwai8d087c72011-06-28 12:45:47 +02003304#define get_connection_index(codec, mux, nid)\
3305 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003306
3307/* get an unassigned DAC from the given list.
3308 * Return the nid if found and reduce the DAC list, or return zero if
3309 * not found
3310 */
3311static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3312 hda_nid_t *dacs, int *num_dacs)
3313{
3314 int i, nums = *num_dacs;
3315 hda_nid_t ret = 0;
3316
3317 for (i = 0; i < nums; i++) {
3318 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3319 ret = dacs[i];
3320 break;
3321 }
3322 }
3323 if (!ret)
3324 return 0;
3325 if (--nums > 0)
3326 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3327 *num_dacs = nums;
3328 return ret;
3329}
3330
3331#define MAX_AUTO_DACS 5
3332
3333/* fill analog DAC list from the widget tree */
3334static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3335{
3336 hda_nid_t nid, end_nid;
3337 int nums = 0;
3338
3339 end_nid = codec->start_nid + codec->num_nodes;
3340 for (nid = codec->start_nid; nid < end_nid; nid++) {
3341 unsigned int wcaps = get_wcaps(codec, nid);
3342 unsigned int type = get_wcaps_type(wcaps);
3343 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3344 dacs[nums++] = nid;
3345 if (nums >= MAX_AUTO_DACS)
3346 break;
3347 }
3348 }
3349 return nums;
3350}
3351
3352/* fill pin_dac_pair list from the pin and dac list */
3353static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3354 int num_pins, hda_nid_t *dacs, int *rest,
3355 struct pin_dac_pair *filled, int type)
3356{
3357 int i, nums;
3358
3359 nums = 0;
3360 for (i = 0; i < num_pins; i++) {
3361 filled[nums].pin = pins[i];
3362 filled[nums].type = type;
3363 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3364 nums++;
3365 }
3366 return nums;
3367}
3368
3369/* parse analog output paths */
3370static void cx_auto_parse_output(struct hda_codec *codec)
3371{
3372 struct conexant_spec *spec = codec->spec;
3373 struct auto_pin_cfg *cfg = &spec->autocfg;
3374 hda_nid_t dacs[MAX_AUTO_DACS];
3375 int i, j, nums, rest;
3376
3377 rest = fill_cx_auto_dacs(codec, dacs);
3378 /* parse all analog output pins */
3379 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3380 dacs, &rest, spec->dac_info,
3381 AUTO_PIN_LINE_OUT);
3382 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3383 dacs, &rest, spec->dac_info + nums,
3384 AUTO_PIN_HP_OUT);
3385 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3386 dacs, &rest, spec->dac_info + nums,
3387 AUTO_PIN_SPEAKER_OUT);
3388 spec->dac_info_filled = nums;
3389 /* fill multiout struct */
3390 for (i = 0; i < nums; i++) {
3391 hda_nid_t dac = spec->dac_info[i].dac;
3392 if (!dac)
3393 continue;
3394 switch (spec->dac_info[i].type) {
3395 case AUTO_PIN_LINE_OUT:
3396 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3397 spec->multiout.num_dacs++;
3398 break;
3399 case AUTO_PIN_HP_OUT:
3400 case AUTO_PIN_SPEAKER_OUT:
3401 if (!spec->multiout.hp_nid) {
3402 spec->multiout.hp_nid = dac;
3403 break;
3404 }
3405 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3406 if (!spec->multiout.extra_out_nid[j]) {
3407 spec->multiout.extra_out_nid[j] = dac;
3408 break;
3409 }
3410 break;
3411 }
3412 }
3413 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003414 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003415
Takashi Iwai03697e22011-05-17 09:53:31 +02003416 for (i = 0; i < cfg->hp_outs; i++) {
3417 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3418 spec->auto_mute = 1;
3419 break;
3420 }
3421 }
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003422 if (spec->auto_mute &&
3423 cfg->line_out_pins[0] &&
3424 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003425 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3426 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3427 for (i = 0; i < cfg->line_outs; i++) {
3428 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3429 spec->detect_line = 1;
3430 break;
3431 }
3432 }
3433 spec->automute_lines = spec->detect_line;
3434 }
3435
Takashi Iwaif2e57312010-09-15 10:07:08 +02003436 spec->vmaster_nid = spec->private_dac_nids[0];
3437}
3438
Takashi Iwaida339862011-05-13 16:24:15 +02003439static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3440 hda_nid_t *pins, bool on);
3441
Takashi Iwai03697e22011-05-17 09:53:31 +02003442static void do_automute(struct hda_codec *codec, int num_pins,
3443 hda_nid_t *pins, bool on)
3444{
3445 int i;
3446 for (i = 0; i < num_pins; i++)
3447 snd_hda_codec_write(codec, pins[i], 0,
3448 AC_VERB_SET_PIN_WIDGET_CONTROL,
3449 on ? PIN_OUT : 0);
3450 cx_auto_turn_eapd(codec, num_pins, pins, on);
3451}
3452
3453static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3454{
3455 int i, present = 0;
3456
3457 for (i = 0; i < num_pins; i++) {
3458 hda_nid_t nid = pins[i];
3459 if (!nid || !is_jack_detectable(codec, nid))
3460 break;
3461 snd_hda_input_jack_report(codec, nid);
3462 present |= snd_hda_jack_detect(codec, nid);
3463 }
3464 return present;
3465}
3466
Takashi Iwaif2e57312010-09-15 10:07:08 +02003467/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003468static void cx_auto_update_speakers(struct hda_codec *codec)
3469{
3470 struct conexant_spec *spec = codec->spec;
3471 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003472 int on = 1;
Takashi Iwai03697e22011-05-17 09:53:31 +02003473
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003474 /* turn on HP EAPD when HP jacks are present */
3475 if (spec->auto_mute)
3476 on = spec->hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +02003477 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003478 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3479 if (spec->auto_mute)
3480 on = !(spec->hp_present ||
3481 (spec->detect_line && spec->line_present));
3482 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003483
3484 /* toggle line-out mutes if needed, too */
3485 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3486 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3487 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3488 return;
Takashi Iwaie2df82f2011-05-24 11:49:12 +02003489 if (spec->auto_mute) {
3490 /* mute LO in auto-mode when HP jack is present */
3491 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3492 spec->automute_lines)
3493 on = !spec->hp_present;
3494 else
3495 on = 1;
3496 }
3497 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
Takashi Iwai03697e22011-05-17 09:53:31 +02003498}
3499
Takashi Iwaif2e57312010-09-15 10:07:08 +02003500static void cx_auto_hp_automute(struct hda_codec *codec)
3501{
3502 struct conexant_spec *spec = codec->spec;
3503 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003504
3505 if (!spec->auto_mute)
3506 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003507 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3508 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003509}
3510
Takashi Iwai03697e22011-05-17 09:53:31 +02003511static void cx_auto_line_automute(struct hda_codec *codec)
3512{
3513 struct conexant_spec *spec = codec->spec;
3514 struct auto_pin_cfg *cfg = &spec->autocfg;
3515
3516 if (!spec->auto_mute || !spec->detect_line)
3517 return;
3518 spec->line_present = detect_jacks(codec, cfg->line_outs,
3519 cfg->line_out_pins);
3520 cx_auto_update_speakers(codec);
3521}
3522
3523static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3524 struct snd_ctl_elem_info *uinfo)
3525{
3526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3527 struct conexant_spec *spec = codec->spec;
3528 static const char * const texts2[] = {
3529 "Disabled", "Enabled"
3530 };
3531 static const char * const texts3[] = {
3532 "Disabled", "Speaker Only", "Line-Out+Speaker"
3533 };
3534 const char * const *texts;
3535
3536 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3537 uinfo->count = 1;
3538 if (spec->automute_hp_lo) {
3539 uinfo->value.enumerated.items = 3;
3540 texts = texts3;
3541 } else {
3542 uinfo->value.enumerated.items = 2;
3543 texts = texts2;
3544 }
3545 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3546 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3547 strcpy(uinfo->value.enumerated.name,
3548 texts[uinfo->value.enumerated.item]);
3549 return 0;
3550}
3551
3552static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3553 struct snd_ctl_elem_value *ucontrol)
3554{
3555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3556 struct conexant_spec *spec = codec->spec;
3557 unsigned int val;
3558 if (!spec->auto_mute)
3559 val = 0;
3560 else if (!spec->automute_lines)
3561 val = 1;
3562 else
3563 val = 2;
3564 ucontrol->value.enumerated.item[0] = val;
3565 return 0;
3566}
3567
3568static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3569 struct snd_ctl_elem_value *ucontrol)
3570{
3571 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3572 struct conexant_spec *spec = codec->spec;
3573
3574 switch (ucontrol->value.enumerated.item[0]) {
3575 case 0:
3576 if (!spec->auto_mute)
3577 return 0;
3578 spec->auto_mute = 0;
3579 break;
3580 case 1:
3581 if (spec->auto_mute && !spec->automute_lines)
3582 return 0;
3583 spec->auto_mute = 1;
3584 spec->automute_lines = 0;
3585 break;
3586 case 2:
3587 if (!spec->automute_hp_lo)
3588 return -EINVAL;
3589 if (spec->auto_mute && spec->automute_lines)
3590 return 0;
3591 spec->auto_mute = 1;
3592 spec->automute_lines = 1;
3593 break;
3594 default:
3595 return -EINVAL;
3596 }
3597 cx_auto_update_speakers(codec);
3598 return 1;
3599}
3600
3601static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3602 {
3603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3604 .name = "Auto-Mute Mode",
3605 .info = cx_automute_mode_info,
3606 .get = cx_automute_mode_get,
3607 .put = cx_automute_mode_put,
3608 },
3609 { }
3610};
3611
Takashi Iwai6764bce2011-05-13 16:52:25 +02003612static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3613 struct snd_ctl_elem_info *uinfo)
3614{
3615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3616 struct conexant_spec *spec = codec->spec;
3617
3618 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3619}
3620
3621static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3622 struct snd_ctl_elem_value *ucontrol)
3623{
3624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3625 struct conexant_spec *spec = codec->spec;
3626
3627 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3628 return 0;
3629}
3630
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003631/* look for the route the given pin from mux and return the index;
3632 * if do_select is set, actually select the route.
3633 */
3634static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003635 hda_nid_t pin, hda_nid_t *srcp,
3636 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003637{
3638 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3639 int i, nums;
3640
Takashi Iwaicf27f292011-05-16 11:33:02 +02003641 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3642 case AC_WID_AUD_IN:
3643 case AC_WID_AUD_SEL:
3644 case AC_WID_AUD_MIX:
3645 break;
3646 default:
3647 return -1;
3648 }
3649
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003650 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3651 for (i = 0; i < nums; i++)
3652 if (conn[i] == pin) {
3653 if (do_select)
3654 snd_hda_codec_write(codec, mux, 0,
3655 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003656 if (srcp)
3657 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003658 return i;
3659 }
3660 depth++;
3661 if (depth == 2)
3662 return -1;
3663 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003664 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003665 do_select, depth);
3666 if (ret >= 0) {
3667 if (do_select)
3668 snd_hda_codec_write(codec, mux, 0,
3669 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003670 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003671 }
3672 }
3673 return -1;
3674}
3675
3676static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3677 hda_nid_t pin)
3678{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003679 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003680}
3681
3682static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3683 hda_nid_t pin)
3684{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003685 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003686}
3687
Takashi Iwai6764bce2011-05-13 16:52:25 +02003688static int cx_auto_mux_enum_update(struct hda_codec *codec,
3689 const struct hda_input_mux *imux,
3690 unsigned int idx)
3691{
3692 struct conexant_spec *spec = codec->spec;
3693 hda_nid_t adc;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003694 int changed = 1;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003695
3696 if (!imux->num_items)
3697 return 0;
3698 if (idx >= imux->num_items)
3699 idx = imux->num_items - 1;
3700 if (spec->cur_mux[0] == idx)
Takashi Iwai313d2c02011-05-23 20:27:02 +02003701 changed = 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003702 adc = spec->imux_info[idx].adc;
3703 select_input_connection(codec, spec->imux_info[idx].adc,
3704 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003705 if (spec->cur_adc && spec->cur_adc != adc) {
3706 /* stream is running, let's swap the current ADC */
3707 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3708 spec->cur_adc = adc;
3709 snd_hda_codec_setup_stream(codec, adc,
3710 spec->cur_adc_stream_tag, 0,
3711 spec->cur_adc_format);
3712 }
3713 spec->cur_mux[0] = idx;
Takashi Iwai313d2c02011-05-23 20:27:02 +02003714 return changed;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003715}
3716
3717static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3718 struct snd_ctl_elem_value *ucontrol)
3719{
3720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3721 struct conexant_spec *spec = codec->spec;
3722
3723 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3724 ucontrol->value.enumerated.item[0]);
3725}
3726
3727static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3728 {
3729 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3730 .name = "Capture Source",
3731 .info = cx_auto_mux_enum_info,
3732 .get = cx_auto_mux_enum_get,
3733 .put = cx_auto_mux_enum_put
3734 },
3735 {}
3736};
3737
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003738static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3739{
3740 struct conexant_spec *spec = codec->spec;
3741 if (idx < 0)
3742 return false;
3743 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3744 return false;
3745 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3746 return true;
3747}
3748
Takashi Iwaif2e57312010-09-15 10:07:08 +02003749/* automatic switch internal and external mic */
3750static void cx_auto_automic(struct hda_codec *codec)
3751{
3752 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003753
3754 if (!spec->auto_mic)
3755 return;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003756 if (!select_automic(codec, spec->auto_mic_ext, true))
3757 if (!select_automic(codec, spec->auto_mic_dock, true))
3758 select_automic(codec, spec->auto_mic_int, false);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003759}
3760
3761static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3762{
3763 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3764 switch (res >> 26) {
3765 case CONEXANT_HP_EVENT:
3766 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003767 break;
3768 case CONEXANT_LINE_EVENT:
3769 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003770 break;
3771 case CONEXANT_MIC_EVENT:
3772 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003773 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003774 break;
3775 }
3776}
3777
Takashi Iwaif2e57312010-09-15 10:07:08 +02003778/* check whether the pin config is suitable for auto-mic switching;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003779 * auto-mic is enabled only when one int-mic and one ext- and/or
3780 * one dock-mic exist
Takashi Iwaif2e57312010-09-15 10:07:08 +02003781 */
3782static void cx_auto_check_auto_mic(struct hda_codec *codec)
3783{
3784 struct conexant_spec *spec = codec->spec;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003785 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3786 int i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003787
Takashi Iwai506a4192011-05-23 20:07:15 +02003788 for (i = 0; i < ARRAY_SIZE(pset); i++)
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003789 pset[i] = -1;
3790 for (i = 0; i < spec->private_imux.num_items; i++) {
3791 hda_nid_t pin = spec->imux_info[i].pin;
3792 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003793 int type, attr;
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003794 attr = snd_hda_get_input_pin_attr(def_conf);
3795 if (attr == INPUT_PIN_ATTR_UNUSED)
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003796 return; /* invalid entry */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003797 if (attr > INPUT_PIN_ATTR_NORMAL)
3798 attr = INPUT_PIN_ATTR_NORMAL;
3799 if (attr != INPUT_PIN_ATTR_INT &&
3800 !is_jack_detectable(codec, pin))
Takashi Iwaib55fcb52011-05-17 12:57:46 +02003801 return; /* non-detectable pin */
3802 type = get_defcfg_device(def_conf);
3803 if (type != AC_JACK_MIC_IN &&
3804 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3805 return; /* no valid input type */
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003806 if (pset[attr] >= 0)
3807 return; /* already occupied */
3808 pset[attr] = i;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003809 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003810 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3811 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3812 return; /* no input to switch*/
3813 spec->auto_mic = 1;
3814 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3815 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3816 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
Takashi Iwaif2e57312010-09-15 10:07:08 +02003817}
3818
3819static void cx_auto_parse_input(struct hda_codec *codec)
3820{
3821 struct conexant_spec *spec = codec->spec;
3822 struct auto_pin_cfg *cfg = &spec->autocfg;
3823 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003824 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003825
3826 imux = &spec->private_imux;
3827 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003828 for (j = 0; j < spec->num_adc_nids; j++) {
3829 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003830 int idx = get_input_connection(codec, adc,
3831 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003832 if (idx >= 0) {
3833 const char *label;
3834 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003835 spec->imux_info[imux->num_items].index = i;
3836 spec->imux_info[imux->num_items].boost = 0;
3837 spec->imux_info[imux->num_items].adc = adc;
3838 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003839 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003840 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003841 break;
3842 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003843 }
3844 }
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02003845 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003846 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003847 if (imux->num_items > 1 && !spec->auto_mic) {
3848 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003849 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003850 spec->adc_switching = 1;
3851 break;
3852 }
3853 }
3854 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003855}
3856
3857/* get digital-input audio widget corresponding to the given pin */
3858static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3859{
3860 hda_nid_t nid, end_nid;
3861
3862 end_nid = codec->start_nid + codec->num_nodes;
3863 for (nid = codec->start_nid; nid < end_nid; nid++) {
3864 unsigned int wcaps = get_wcaps(codec, nid);
3865 unsigned int type = get_wcaps_type(wcaps);
3866 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3867 if (get_connection_index(codec, nid, pin) >= 0)
3868 return nid;
3869 }
3870 }
3871 return 0;
3872}
3873
3874static void cx_auto_parse_digital(struct hda_codec *codec)
3875{
3876 struct conexant_spec *spec = codec->spec;
3877 struct auto_pin_cfg *cfg = &spec->autocfg;
3878 hda_nid_t nid;
3879
3880 if (cfg->dig_outs &&
3881 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3882 spec->multiout.dig_out_nid = nid;
3883 if (cfg->dig_in_pin)
3884 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3885}
3886
3887#ifdef CONFIG_SND_HDA_INPUT_BEEP
3888static void cx_auto_parse_beep(struct hda_codec *codec)
3889{
3890 struct conexant_spec *spec = codec->spec;
3891 hda_nid_t nid, end_nid;
3892
3893 end_nid = codec->start_nid + codec->num_nodes;
3894 for (nid = codec->start_nid; nid < end_nid; nid++)
3895 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3896 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3897 break;
3898 }
3899}
3900#else
3901#define cx_auto_parse_beep(codec)
3902#endif
3903
3904static int cx_auto_parse_auto_config(struct hda_codec *codec)
3905{
3906 struct conexant_spec *spec = codec->spec;
3907 int err;
3908
3909 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3910 if (err < 0)
3911 return err;
3912
3913 cx_auto_parse_output(codec);
3914 cx_auto_parse_input(codec);
3915 cx_auto_parse_digital(codec);
3916 cx_auto_parse_beep(codec);
3917 return 0;
3918}
3919
Takashi Iwaida339862011-05-13 16:24:15 +02003920static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3921 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003922{
3923 int i;
3924 for (i = 0; i < num_pins; i++) {
3925 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3926 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003927 AC_VERB_SET_EAPD_BTLENABLE,
3928 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003929 }
3930}
3931
3932static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3933 hda_nid_t src)
3934{
3935 int idx = get_connection_index(codec, pin, src);
3936 if (idx >= 0)
3937 snd_hda_codec_write(codec, pin, 0,
3938 AC_VERB_SET_CONNECT_SEL, idx);
3939}
3940
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003941static void mute_outputs(struct hda_codec *codec, int num_nids,
3942 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003943{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003944 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003945
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003946 for (i = 0; i < num_nids; i++) {
3947 hda_nid_t nid = nids[i];
3948 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3949 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003950 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3951 val = AMP_OUT_MUTE;
3952 else
3953 val = AMP_OUT_ZERO;
3954 snd_hda_codec_write(codec, nid, 0,
3955 AC_VERB_SET_AMP_GAIN_MUTE, val);
3956 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003957}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003958
Takashi Iwai03697e22011-05-17 09:53:31 +02003959static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3960 hda_nid_t *pins, unsigned int tag)
3961{
3962 int i;
3963 for (i = 0; i < num_pins; i++)
3964 snd_hda_codec_write(codec, pins[i], 0,
3965 AC_VERB_SET_UNSOLICITED_ENABLE,
3966 AC_USRSP_EN | tag);
3967}
3968
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003969static void cx_auto_init_output(struct hda_codec *codec)
3970{
3971 struct conexant_spec *spec = codec->spec;
3972 struct auto_pin_cfg *cfg = &spec->autocfg;
3973 hda_nid_t nid;
3974 int i;
3975
3976 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003977 for (i = 0; i < cfg->hp_outs; i++)
3978 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3979 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003980 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3981 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3982 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003983 for (i = 0; i < spec->dac_info_filled; i++) {
3984 nid = spec->dac_info[i].dac;
3985 if (!nid)
3986 nid = spec->multiout.dac_nids[0];
3987 select_connection(codec, spec->dac_info[i].pin, nid);
3988 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003989 if (spec->auto_mute) {
3990 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3991 CONEXANT_HP_EVENT);
3992 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3993 cfg->hp_pins);
3994 if (spec->detect_line) {
3995 enable_unsol_pins(codec, cfg->line_outs,
3996 cfg->line_out_pins,
3997 CONEXANT_LINE_EVENT);
3998 spec->line_present =
3999 detect_jacks(codec, cfg->line_outs,
4000 cfg->line_out_pins);
4001 }
4002 }
4003 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004004}
4005
4006static void cx_auto_init_input(struct hda_codec *codec)
4007{
4008 struct conexant_spec *spec = codec->spec;
4009 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004010 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004011
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004012 for (i = 0; i < spec->num_adc_nids; i++) {
4013 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004014 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4015 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004016 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4017 val = AMP_IN_MUTE(0);
4018 else
4019 val = AMP_IN_UNMUTE(0);
4020 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4021 val);
4022 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004023
4024 for (i = 0; i < cfg->num_inputs; i++) {
4025 unsigned int type;
4026 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4027 type = PIN_VREF80;
4028 else
4029 type = PIN_IN;
4030 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4031 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4032 }
4033
4034 if (spec->auto_mic) {
Takashi Iwai43c1b2e2011-05-17 10:35:15 +02004035 if (spec->auto_mic_ext >= 0) {
4036 snd_hda_codec_write(codec,
4037 cfg->inputs[spec->auto_mic_ext].pin, 0,
4038 AC_VERB_SET_UNSOLICITED_ENABLE,
4039 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4040 }
4041 if (spec->auto_mic_dock >= 0) {
4042 snd_hda_codec_write(codec,
4043 cfg->inputs[spec->auto_mic_dock].pin, 0,
4044 AC_VERB_SET_UNSOLICITED_ENABLE,
4045 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4046 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004047 cx_auto_automic(codec);
4048 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004049 select_input_connection(codec, spec->imux_info[0].adc,
4050 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004051 }
4052}
4053
4054static void cx_auto_init_digital(struct hda_codec *codec)
4055{
4056 struct conexant_spec *spec = codec->spec;
4057 struct auto_pin_cfg *cfg = &spec->autocfg;
4058
4059 if (spec->multiout.dig_out_nid)
4060 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4061 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4062 if (spec->dig_in_nid)
4063 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4064 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4065}
4066
4067static int cx_auto_init(struct hda_codec *codec)
4068{
4069 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4070 cx_auto_init_output(codec);
4071 cx_auto_init_input(codec);
4072 cx_auto_init_digital(codec);
4073 return 0;
4074}
4075
David Henningsson983345e2011-02-15 19:57:09 +01004076static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004077 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004078 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004079{
4080 static char name[32];
4081 static struct snd_kcontrol_new knew[] = {
4082 HDA_CODEC_VOLUME(name, 0, 0, 0),
4083 HDA_CODEC_MUTE(name, 0, 0, 0),
4084 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004085 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004086 int i, err;
4087
4088 for (i = 0; i < 2; i++) {
4089 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004090 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4091 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004092 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4093 knew[i].index = cidx;
4094 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4095 kctl = snd_ctl_new1(&knew[i], codec);
4096 if (!kctl)
4097 return -ENOMEM;
4098 err = snd_hda_ctl_add(codec, nid, kctl);
4099 if (err < 0)
4100 return err;
4101 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4102 break;
4103 }
4104 return 0;
4105}
4106
David Henningsson983345e2011-02-15 19:57:09 +01004107#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4108 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4109
Takashi Iwaif2e57312010-09-15 10:07:08 +02004110#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4111 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4112
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004113static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4114 hda_nid_t pin, const char *name, int idx)
4115{
4116 unsigned int caps;
4117 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4118 if (caps & AC_AMPCAP_NUM_STEPS)
4119 return cx_auto_add_pb_volume(codec, dac, name, idx);
4120 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4121 if (caps & AC_AMPCAP_NUM_STEPS)
4122 return cx_auto_add_pb_volume(codec, pin, name, idx);
4123 return 0;
4124}
4125
Takashi Iwaif2e57312010-09-15 10:07:08 +02004126static int cx_auto_build_output_controls(struct hda_codec *codec)
4127{
4128 struct conexant_spec *spec = codec->spec;
4129 int i, err;
4130 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004131 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004132
4133 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004134 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4135 spec->dac_info[0].pin,
4136 "Master", 0);
4137
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138 for (i = 0; i < spec->dac_info_filled; i++) {
4139 const char *label;
4140 int idx, type;
4141 if (!spec->dac_info[i].dac)
4142 continue;
4143 type = spec->dac_info[i].type;
4144 if (type == AUTO_PIN_LINE_OUT)
4145 type = spec->autocfg.line_out_type;
4146 switch (type) {
4147 case AUTO_PIN_LINE_OUT:
4148 default:
4149 label = texts[num_line++];
4150 idx = 0;
4151 break;
4152 case AUTO_PIN_HP_OUT:
4153 label = "Headphone";
4154 idx = num_hp++;
4155 break;
4156 case AUTO_PIN_SPEAKER_OUT:
4157 label = "Speaker";
4158 idx = num_spk++;
4159 break;
4160 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004161 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
4162 spec->dac_info[i].pin,
4163 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004164 if (err < 0)
4165 return err;
4166 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004167
4168 if (spec->auto_mute) {
4169 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4170 if (err < 0)
4171 return err;
4172 }
4173
Takashi Iwaif2e57312010-09-15 10:07:08 +02004174 return 0;
4175}
4176
Takashi Iwai6764bce2011-05-13 16:52:25 +02004177static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4178 const char *label, const char *pfx,
4179 int cidx)
4180{
4181 struct conexant_spec *spec = codec->spec;
4182 int i;
4183
4184 for (i = 0; i < spec->num_adc_nids; i++) {
4185 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004186 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004187 if (idx < 0)
4188 continue;
4189 return cx_auto_add_volume_idx(codec, label, pfx,
4190 cidx, adc_nid, HDA_INPUT, idx);
4191 }
4192 return 0;
4193}
4194
Takashi Iwaicf27f292011-05-16 11:33:02 +02004195static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4196 const char *label, int cidx)
4197{
4198 struct conexant_spec *spec = codec->spec;
4199 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004200 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004201
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004202 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004203 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4204 return cx_auto_add_volume(codec, label, " Boost", cidx,
4205 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004206 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4207 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004208 if (con < 0)
4209 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004210 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004211 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004212 return 0; /* already present */
4213 }
4214
4215 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004216 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004217 return cx_auto_add_volume(codec, label, " Boost", 0,
4218 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004219 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004220 return 0;
4221}
4222
Takashi Iwaif2e57312010-09-15 10:07:08 +02004223static int cx_auto_build_input_controls(struct hda_codec *codec)
4224{
4225 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004226 struct hda_input_mux *imux = &spec->private_imux;
4227 const char *prev_label;
4228 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004229 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004230 int multi_connection;
4231
4232 multi_connection = 0;
4233 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004234 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4235 spec->imux_info[i].pin);
4236 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004237 if (i > 0 && input_conn[i] != input_conn[0])
4238 multi_connection = 1;
4239 }
David Henningsson983345e2011-02-15 19:57:09 +01004240
Takashi Iwaif2e57312010-09-15 10:07:08 +02004241 prev_label = NULL;
4242 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004243 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004244 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004245 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004246
Takashi Iwaicf27f292011-05-16 11:33:02 +02004247 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004248 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004249 if (label == prev_label)
4250 cidx++;
4251 else
4252 cidx = 0;
4253 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004254
Takashi Iwaicf27f292011-05-16 11:33:02 +02004255 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4256 if (err < 0)
4257 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004258
Takashi Iwaicf27f292011-05-16 11:33:02 +02004259 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004260 if (i > 0)
4261 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004262 err = cx_auto_add_capture_volume(codec, nid,
4263 "Capture", "", cidx);
4264 } else {
4265 err = cx_auto_add_capture_volume(codec, nid,
4266 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004267 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004268 if (err < 0)
4269 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004270 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004271
4272 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4273 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4274 if (err < 0)
4275 return err;
4276 }
4277
Takashi Iwaif2e57312010-09-15 10:07:08 +02004278 return 0;
4279}
4280
4281static int cx_auto_build_controls(struct hda_codec *codec)
4282{
4283 int err;
4284
4285 err = cx_auto_build_output_controls(codec);
4286 if (err < 0)
4287 return err;
4288 err = cx_auto_build_input_controls(codec);
4289 if (err < 0)
4290 return err;
4291 return conexant_build_controls(codec);
4292}
4293
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004294static int cx_auto_search_adcs(struct hda_codec *codec)
4295{
4296 struct conexant_spec *spec = codec->spec;
4297 hda_nid_t nid, end_nid;
4298
4299 end_nid = codec->start_nid + codec->num_nodes;
4300 for (nid = codec->start_nid; nid < end_nid; nid++) {
4301 unsigned int caps = get_wcaps(codec, nid);
4302 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4303 continue;
4304 if (caps & AC_WCAP_DIGITAL)
4305 continue;
4306 if (snd_BUG_ON(spec->num_adc_nids >=
4307 ARRAY_SIZE(spec->private_adc_nids)))
4308 break;
4309 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4310 }
4311 spec->adc_nids = spec->private_adc_nids;
4312 return 0;
4313}
4314
4315
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004316static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004317 .build_controls = cx_auto_build_controls,
4318 .build_pcms = conexant_build_pcms,
4319 .init = cx_auto_init,
4320 .free = conexant_free,
4321 .unsol_event = cx_auto_unsol_event,
4322#ifdef CONFIG_SND_HDA_POWER_SAVE
4323 .suspend = conexant_suspend,
4324#endif
4325 .reboot_notify = snd_hda_shutup_pins,
4326};
4327
4328static int patch_conexant_auto(struct hda_codec *codec)
4329{
4330 struct conexant_spec *spec;
4331 int err;
4332
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004333 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4334 codec->chip_name);
4335
Takashi Iwaif2e57312010-09-15 10:07:08 +02004336 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4337 if (!spec)
4338 return -ENOMEM;
4339 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004340 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004341 err = cx_auto_search_adcs(codec);
4342 if (err < 0)
4343 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004344 err = cx_auto_parse_auto_config(codec);
4345 if (err < 0) {
4346 kfree(codec->spec);
4347 codec->spec = NULL;
4348 return err;
4349 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004350 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004351 codec->patch_ops = cx_auto_patch_ops;
4352 if (spec->beep_amp)
4353 snd_hda_attach_beep_device(codec, spec->beep_amp);
4354 return 0;
4355}
4356
4357/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004358 */
4359
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004360static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004361 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4362 .patch = patch_cxt5045 },
4363 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4364 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004365 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4366 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004367 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4368 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004369 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4370 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004371 { .id = 0x14f15068, .name = "CX20584",
4372 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004373 { .id = 0x14f15069, .name = "CX20585",
4374 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02004375 { .id = 0x14f1506c, .name = "CX20588",
4376 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004377 { .id = 0x14f1506e, .name = "CX20590",
4378 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004379 { .id = 0x14f15097, .name = "CX20631",
4380 .patch = patch_conexant_auto },
4381 { .id = 0x14f15098, .name = "CX20632",
4382 .patch = patch_conexant_auto },
4383 { .id = 0x14f150a1, .name = "CX20641",
4384 .patch = patch_conexant_auto },
4385 { .id = 0x14f150a2, .name = "CX20642",
4386 .patch = patch_conexant_auto },
4387 { .id = 0x14f150ab, .name = "CX20651",
4388 .patch = patch_conexant_auto },
4389 { .id = 0x14f150ac, .name = "CX20652",
4390 .patch = patch_conexant_auto },
4391 { .id = 0x14f150b8, .name = "CX20664",
4392 .patch = patch_conexant_auto },
4393 { .id = 0x14f150b9, .name = "CX20665",
4394 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004395 {} /* terminator */
4396};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004397
4398MODULE_ALIAS("snd-hda-codec-id:14f15045");
4399MODULE_ALIAS("snd-hda-codec-id:14f15047");
4400MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004401MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004402MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004403MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004404MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02004405MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01004406MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004407MODULE_ALIAS("snd-hda-codec-id:14f15097");
4408MODULE_ALIAS("snd-hda-codec-id:14f15098");
4409MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4410MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4411MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4412MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4413MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4414MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004415
4416MODULE_LICENSE("GPL");
4417MODULE_DESCRIPTION("Conexant HD-audio codec");
4418
4419static struct hda_codec_preset_list conexant_list = {
4420 .preset = snd_hda_preset_conexant,
4421 .owner = THIS_MODULE,
4422};
4423
4424static int __init patch_conexant_init(void)
4425{
4426 return snd_hda_add_codec_preset(&conexant_list);
4427}
4428
4429static void __exit patch_conexant_exit(void)
4430{
4431 snd_hda_delete_codec_preset(&conexant_list);
4432}
4433
4434module_init(patch_conexant_init)
4435module_exit(patch_conexant_exit)