blob: ac595363e0e023f2b8a40a7b947cc2349397bf9c [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 */
Tobin Davisc9b443d2006-11-14 12:13:39 +010088 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050089 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010090
91 /* capture */
92 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020093 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 hda_nid_t dig_in_nid; /* digital-in NID; optional */
95
Takashi Iwai461e2c72008-01-25 11:35:17 +010096 unsigned int cur_adc_idx;
97 hda_nid_t cur_adc;
98 unsigned int cur_adc_stream_tag;
99 unsigned int cur_adc_format;
100
Takashi Iwai6764bce2011-05-13 16:52:25 +0200101 const struct hda_pcm_stream *capture_stream;
102
Tobin Davisc9b443d2006-11-14 12:13:39 +0100103 /* capture source */
104 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200105 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 unsigned int cur_mux[3];
107
108 /* channel model */
109 const struct hda_channel_mode *channel_mode;
110 int num_channel_mode;
111
112 /* PCM information */
113 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
114
Tobin Davisc9b443d2006-11-14 12:13:39 +0100115 unsigned int spdif_route;
116
117 /* dynamic controls, init_verbs and input_mux */
118 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100119 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200120 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200121 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200122 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200123 struct pin_dac_pair dac_info[8];
124 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100125
Daniel Drake0fb67e92009-07-16 14:46:57 +0100126 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200127 unsigned int auto_mute:1; /* used in auto-parser */
Takashi Iwai03697e22011-05-17 09:53:31 +0200128 unsigned int detect_line:1; /* Line-out detection enabled */
129 unsigned int automute_lines:1; /* automute line-out as well */
130 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaif2e57312010-09-15 10:07:08 +0200131 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500132 unsigned int dell_vostro:1;
133 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200134 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200135 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100136 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100137
Takashi Iwai6764bce2011-05-13 16:52:25 +0200138 unsigned int adc_switching:1;
139
Daniel Drake75f89912010-01-07 13:46:25 +0100140 unsigned int ext_mic_present;
141 unsigned int recording;
142 void (*capture_prepare)(struct hda_codec *codec);
143 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100144
145 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
146 * through the microphone jack.
147 * When the user enables this through a mixer switch, both internal and
148 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
149 * we also allow the bias to be configured through a separate mixer
150 * control. */
151 unsigned int dc_enable;
152 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
153 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200154
155 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100156};
157
158static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 struct snd_pcm_substream *substream)
161{
162 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100163 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
164 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100165}
166
167static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 unsigned int stream_tag,
170 unsigned int format,
171 struct snd_pcm_substream *substream)
172{
173 struct conexant_spec *spec = codec->spec;
174 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
175 stream_tag,
176 format, substream);
177}
178
179static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 struct snd_pcm_substream *substream)
182{
183 struct conexant_spec *spec = codec->spec;
184 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
185}
186
187/*
188 * Digital out
189 */
190static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
191 struct hda_codec *codec,
192 struct snd_pcm_substream *substream)
193{
194 struct conexant_spec *spec = codec->spec;
195 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
196}
197
198static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 struct snd_pcm_substream *substream)
201{
202 struct conexant_spec *spec = codec->spec;
203 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
204}
205
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200206static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
207 struct hda_codec *codec,
208 unsigned int stream_tag,
209 unsigned int format,
210 struct snd_pcm_substream *substream)
211{
212 struct conexant_spec *spec = codec->spec;
213 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
214 stream_tag,
215 format, substream);
216}
217
Tobin Davisc9b443d2006-11-14 12:13:39 +0100218/*
219 * Analog capture
220 */
221static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
223 unsigned int stream_tag,
224 unsigned int format,
225 struct snd_pcm_substream *substream)
226{
227 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100228 if (spec->capture_prepare)
229 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100230 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
231 stream_tag, 0, format);
232 return 0;
233}
234
235static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
236 struct hda_codec *codec,
237 struct snd_pcm_substream *substream)
238{
239 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100240 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100241 if (spec->capture_cleanup)
242 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100243 return 0;
244}
245
246
247
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200248static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100249 .substreams = 1,
250 .channels_min = 2,
251 .channels_max = 2,
252 .nid = 0, /* fill later */
253 .ops = {
254 .open = conexant_playback_pcm_open,
255 .prepare = conexant_playback_pcm_prepare,
256 .cleanup = conexant_playback_pcm_cleanup
257 },
258};
259
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200260static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261 .substreams = 1,
262 .channels_min = 2,
263 .channels_max = 2,
264 .nid = 0, /* fill later */
265 .ops = {
266 .prepare = conexant_capture_pcm_prepare,
267 .cleanup = conexant_capture_pcm_cleanup
268 },
269};
270
271
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200272static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100273 .substreams = 1,
274 .channels_min = 2,
275 .channels_max = 2,
276 .nid = 0, /* fill later */
277 .ops = {
278 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200279 .close = conexant_dig_playback_pcm_close,
280 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100281 },
282};
283
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200284static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100285 .substreams = 1,
286 .channels_min = 2,
287 .channels_max = 2,
288 /* NID is set in alc_build_pcms */
289};
290
Takashi Iwai461e2c72008-01-25 11:35:17 +0100291static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
292 struct hda_codec *codec,
293 unsigned int stream_tag,
294 unsigned int format,
295 struct snd_pcm_substream *substream)
296{
297 struct conexant_spec *spec = codec->spec;
298 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
299 spec->cur_adc_stream_tag = stream_tag;
300 spec->cur_adc_format = format;
301 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
302 return 0;
303}
304
305static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
306 struct hda_codec *codec,
307 struct snd_pcm_substream *substream)
308{
309 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100310 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100311 spec->cur_adc = 0;
312 return 0;
313}
314
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200315static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100316 .substreams = 1,
317 .channels_min = 2,
318 .channels_max = 2,
319 .nid = 0, /* fill later */
320 .ops = {
321 .prepare = cx5051_capture_pcm_prepare,
322 .cleanup = cx5051_capture_pcm_cleanup
323 },
324};
325
Tobin Davisc9b443d2006-11-14 12:13:39 +0100326static int conexant_build_pcms(struct hda_codec *codec)
327{
328 struct conexant_spec *spec = codec->spec;
329 struct hda_pcm *info = spec->pcm_rec;
330
331 codec->num_pcms = 1;
332 codec->pcm_info = info;
333
334 info->name = "CONEXANT Analog";
335 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
337 spec->multiout.max_channels;
338 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
339 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200340 if (spec->capture_stream)
341 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
342 else {
343 if (codec->vendor_id == 0x14f15051)
344 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
345 cx5051_pcm_analog_capture;
346 else {
347 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
348 conexant_pcm_analog_capture;
349 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
350 spec->num_adc_nids;
351 }
352 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100353 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
354
355 if (spec->multiout.dig_out_nid) {
356 info++;
357 codec->num_pcms++;
358 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100359 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100360 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
361 conexant_pcm_digital_playback;
362 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
363 spec->multiout.dig_out_nid;
364 if (spec->dig_in_nid) {
365 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
366 conexant_pcm_digital_capture;
367 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
368 spec->dig_in_nid;
369 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500370 if (spec->slave_dig_outs[0])
371 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100372 }
373
374 return 0;
375}
376
377static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_info *uinfo)
379{
380 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
381 struct conexant_spec *spec = codec->spec;
382
383 return snd_hda_input_mux_info(spec->input_mux, uinfo);
384}
385
386static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
387 struct snd_ctl_elem_value *ucontrol)
388{
389 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
390 struct conexant_spec *spec = codec->spec;
391 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
392
393 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
394 return 0;
395}
396
397static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol)
399{
400 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
401 struct conexant_spec *spec = codec->spec;
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403
404 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
405 spec->capsrc_nids[adc_idx],
406 &spec->cur_mux[adc_idx]);
407}
408
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100409static int conexant_init_jacks(struct hda_codec *codec)
410{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100411#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100412 struct conexant_spec *spec = codec->spec;
413 int i;
414
415 for (i = 0; i < spec->num_init_verbs; i++) {
416 const struct hda_verb *hv;
417
418 hv = spec->init_verbs[i];
419 while (hv->nid) {
420 int err = 0;
421 switch (hv->param ^ AC_USRSP_EN) {
422 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100423 err = snd_hda_input_jack_add(codec, hv->nid,
424 SND_JACK_HEADPHONE, NULL);
425 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100426 break;
427 case CXT5051_PORTC_EVENT:
428 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100429 err = snd_hda_input_jack_add(codec, hv->nid,
430 SND_JACK_MICROPHONE, NULL);
431 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100432 break;
433 }
434 if (err < 0)
435 return err;
436 ++hv;
437 }
438 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100439#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100440 return 0;
441}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100442
Tobin Davisc9b443d2006-11-14 12:13:39 +0100443static int conexant_init(struct hda_codec *codec)
444{
445 struct conexant_spec *spec = codec->spec;
446 int i;
447
448 for (i = 0; i < spec->num_init_verbs; i++)
449 snd_hda_sequence_write(codec, spec->init_verbs[i]);
450 return 0;
451}
452
453static void conexant_free(struct hda_codec *codec)
454{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100455 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200456 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100457 kfree(codec->spec);
458}
459
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200460static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100461 {
462 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
463 .name = "Capture Source",
464 .info = conexant_mux_enum_info,
465 .get = conexant_mux_enum_get,
466 .put = conexant_mux_enum_put
467 },
468 {}
469};
470
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200471#ifdef CONFIG_SND_HDA_INPUT_BEEP
472/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200473static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200474 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
475 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
476 { } /* end */
477};
478#endif
479
Takashi Iwaiea734962011-01-17 11:29:34 +0100480static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100481 "Headphone Playback Volume",
482 "Speaker Playback Volume",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200483 "Front Playback Volume",
484 "Surround Playback Volume",
485 "CLFE Playback Volume",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100486 NULL
487};
488
Takashi Iwaiea734962011-01-17 11:29:34 +0100489static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100490 "Headphone Playback Switch",
491 "Speaker Playback Switch",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200492 "Front Playback Switch",
493 "Surround Playback Switch",
494 "CLFE Playback Switch",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100495 NULL
496};
497
Tobin Davisc9b443d2006-11-14 12:13:39 +0100498static int conexant_build_controls(struct hda_codec *codec)
499{
500 struct conexant_spec *spec = codec->spec;
501 unsigned int i;
502 int err;
503
504 for (i = 0; i < spec->num_mixers; i++) {
505 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
506 if (err < 0)
507 return err;
508 }
509 if (spec->multiout.dig_out_nid) {
510 err = snd_hda_create_spdif_out_ctls(codec,
511 spec->multiout.dig_out_nid);
512 if (err < 0)
513 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100514 err = snd_hda_create_spdif_share_sw(codec,
515 &spec->multiout);
516 if (err < 0)
517 return err;
518 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100519 }
520 if (spec->dig_in_nid) {
521 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
522 if (err < 0)
523 return err;
524 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100525
526 /* if we have no master control, let's create it */
527 if (spec->vmaster_nid &&
528 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
529 unsigned int vmaster_tlv[4];
530 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
531 HDA_OUTPUT, vmaster_tlv);
532 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
533 vmaster_tlv, slave_vols);
534 if (err < 0)
535 return err;
536 }
537 if (spec->vmaster_nid &&
538 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
539 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
540 NULL, slave_sws);
541 if (err < 0)
542 return err;
543 }
544
Takashi Iwaib880c742009-03-10 14:41:05 +0100545 if (spec->input_mux) {
546 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
547 if (err < 0)
548 return err;
549 }
550
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200551#ifdef CONFIG_SND_HDA_INPUT_BEEP
552 /* create beep controls if needed */
553 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200554 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200555 for (knew = cxt_beep_mixer; knew->name; knew++) {
556 struct snd_kcontrol *kctl;
557 kctl = snd_ctl_new1(knew, codec);
558 if (!kctl)
559 return -ENOMEM;
560 kctl->private_value = spec->beep_amp;
561 err = snd_hda_ctl_add(codec, 0, kctl);
562 if (err < 0)
563 return err;
564 }
565 }
566#endif
567
Tobin Davisc9b443d2006-11-14 12:13:39 +0100568 return 0;
569}
570
Takashi Iwai697c3732010-07-30 11:28:02 +0200571#ifdef CONFIG_SND_HDA_POWER_SAVE
572static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
573{
574 snd_hda_shutup_pins(codec);
575 return 0;
576}
577#endif
578
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200579static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100580 .build_controls = conexant_build_controls,
581 .build_pcms = conexant_build_pcms,
582 .init = conexant_init,
583 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200584#ifdef CONFIG_SND_HDA_POWER_SAVE
585 .suspend = conexant_suspend,
586#endif
587 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100588};
589
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200590#ifdef CONFIG_SND_HDA_INPUT_BEEP
591#define set_beep_amp(spec, nid, idx, dir) \
592 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
593#else
594#define set_beep_amp(spec, nid, idx, dir) /* NOP */
595#endif
596
Takashi Iwai6764bce2011-05-13 16:52:25 +0200597static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100598/*
599 * EAPD control
600 * the private value = nid | (invert << 8)
601 */
602
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200603#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100604
Tobin Davis82f30042007-02-13 12:45:44 +0100605static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100606 struct snd_ctl_elem_value *ucontrol)
607{
608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609 struct conexant_spec *spec = codec->spec;
610 int invert = (kcontrol->private_value >> 8) & 1;
611 if (invert)
612 ucontrol->value.integer.value[0] = !spec->cur_eapd;
613 else
614 ucontrol->value.integer.value[0] = spec->cur_eapd;
615 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100616
Tobin Davisc9b443d2006-11-14 12:13:39 +0100617}
618
Tobin Davis82f30042007-02-13 12:45:44 +0100619static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100620 struct snd_ctl_elem_value *ucontrol)
621{
622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623 struct conexant_spec *spec = codec->spec;
624 int invert = (kcontrol->private_value >> 8) & 1;
625 hda_nid_t nid = kcontrol->private_value & 0xff;
626 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100627
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100628 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 if (invert)
630 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200631 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100632 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100633
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200635 snd_hda_codec_write_cache(codec, nid,
636 0, AC_VERB_SET_EAPD_BTLENABLE,
637 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100638 return 1;
639}
640
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100641/* controls for test mode */
642#ifdef CONFIG_SND_DEBUG
643
Tobin Davis82f30042007-02-13 12:45:44 +0100644#define CXT_EAPD_SWITCH(xname, nid, mask) \
645 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
646 .info = cxt_eapd_info, \
647 .get = cxt_eapd_get, \
648 .put = cxt_eapd_put, \
649 .private_value = nid | (mask<<16) }
650
651
652
Tobin Davisc9b443d2006-11-14 12:13:39 +0100653static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_info *uinfo)
655{
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct conexant_spec *spec = codec->spec;
658 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
659 spec->num_channel_mode);
660}
661
662static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_value *ucontrol)
664{
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct conexant_spec *spec = codec->spec;
667 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
668 spec->num_channel_mode,
669 spec->multiout.max_channels);
670}
671
672static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
674{
675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
676 struct conexant_spec *spec = codec->spec;
677 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
678 spec->num_channel_mode,
679 &spec->multiout.max_channels);
680 if (err >= 0 && spec->need_dac_fix)
681 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
682 return err;
683}
684
685#define CXT_PIN_MODE(xname, nid, dir) \
686 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
687 .info = conexant_ch_mode_info, \
688 .get = conexant_ch_mode_get, \
689 .put = conexant_ch_mode_put, \
690 .private_value = nid | (dir<<16) }
691
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100692#endif /* CONFIG_SND_DEBUG */
693
Tobin Davisc9b443d2006-11-14 12:13:39 +0100694/* Conexant 5045 specific */
695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200696static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
697static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
698static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100699#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100700
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200701static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100702 { 2, NULL },
703};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100704
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200705static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100706 .num_items = 2,
707 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100708 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100709 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100710 }
711};
712
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200713static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200714 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100715 .items = {
716 { "IntMic", 0x1 },
717 { "ExtMic", 0x2 },
718 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200719 { "CD", 0x4 },
720 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100721 }
722};
723
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200724static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100725 .num_items = 2,
726 .items = {
727 { "ExtMic", 0x1 },
728 { "IntMic", 0x2 },
729 }
730};
731
Tobin Davisc9b443d2006-11-14 12:13:39 +0100732/* turn on/off EAPD (+ mute HP) as a master switch */
733static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
734 struct snd_ctl_elem_value *ucontrol)
735{
736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100738 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100739
Tobin Davis82f30042007-02-13 12:45:44 +0100740 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100741 return 0;
742
Tobin Davis82f30042007-02-13 12:45:44 +0100743 /* toggle internal speakers mute depending of presence of
744 * the headphone jack
745 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200746 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
747 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
748 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100749
Takashi Iwai47fd8302007-08-10 17:11:07 +0200750 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
751 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
752 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100753 return 1;
754}
755
756/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200757static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200758 .ops = &snd_hda_bind_vol,
759 .values = {
760 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
761 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
762 0
763 },
764};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100765
Tobin Davis7f296732007-03-12 11:39:01 +0100766/* toggle input of built-in and mic jack appropriately */
767static void cxt5045_hp_automic(struct hda_codec *codec)
768{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200769 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
771 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
772 {}
773 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200774 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100775 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
777 {}
778 };
779 unsigned int present;
780
Takashi Iwaid56757a2009-11-18 08:00:14 +0100781 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100782 if (present)
783 snd_hda_sequence_write(codec, mic_jack_on);
784 else
785 snd_hda_sequence_write(codec, mic_jack_off);
786}
787
Tobin Davisc9b443d2006-11-14 12:13:39 +0100788
789/* mute internal speaker if HP is plugged */
790static void cxt5045_hp_automute(struct hda_codec *codec)
791{
Tobin Davis82f30042007-02-13 12:45:44 +0100792 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100793 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100794
Takashi Iwaid56757a2009-11-18 08:00:14 +0100795 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100796
Takashi Iwai47fd8302007-08-10 17:11:07 +0200797 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
798 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
799 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800}
801
802/* unsolicited event for HP jack sensing */
803static void cxt5045_hp_unsol_event(struct hda_codec *codec,
804 unsigned int res)
805{
806 res >>= 26;
807 switch (res) {
808 case CONEXANT_HP_EVENT:
809 cxt5045_hp_automute(codec);
810 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100811 case CONEXANT_MIC_EVENT:
812 cxt5045_hp_automic(codec);
813 break;
814
Tobin Davisc9b443d2006-11-14 12:13:39 +0100815 }
816}
817
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200818static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100819 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
820 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100821 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
822 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200823 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
824 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100825 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
826 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100827 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
828 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200829 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830 {
831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
832 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100833 .info = cxt_eapd_info,
834 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100835 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100836 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100837 },
838
839 {}
840};
841
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200842static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200843 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
844 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
845 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
846 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
847
Jiang Zhe5218c892008-01-17 11:18:41 +0100848 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
849 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
850 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
851 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
852
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200853 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
854 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
855
Jiang Zhe5218c892008-01-17 11:18:41 +0100856 {}
857};
858
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200859static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100860 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
861 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100862 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
863 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100864 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
865 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100866 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
867 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100868 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
869 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100870 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
871 {
872 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
873 .name = "Master Playback Switch",
874 .info = cxt_eapd_info,
875 .get = cxt_eapd_get,
876 .put = cxt5045_hp_master_sw_put,
877 .private_value = 0x10,
878 },
879
880 {}
881};
882
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200883static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100884 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200885 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100886 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200888 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
889 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
890 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
891 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
892 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
893 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
894 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
895 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
896 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100897 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100898 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100899 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100900 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
901 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100902 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100903 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100904 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100905 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100906 { } /* end */
907};
908
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200909static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100910 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100911 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
912 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
913 /* Line In,HP, Amp */
914 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
915 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
916 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
917 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
919 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
920 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
921 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
922 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100923 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100924 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
925 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
926 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
927 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100928 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100929 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
930 /* EAPD */
931 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
932 { } /* end */
933};
Tobin Davis7f296732007-03-12 11:39:01 +0100934
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200935static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100936 /* pin sensing on HP jack */
937 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200938 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100939};
940
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200941static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100942 /* pin sensing on HP jack */
943 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200944 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100945};
946
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947#ifdef CONFIG_SND_DEBUG
948/* Test configuration for debugging, modelled after the ALC260 test
949 * configuration.
950 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200951static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952 .num_items = 5,
953 .items = {
954 { "MIXER", 0x0 },
955 { "MIC1 pin", 0x1 },
956 { "LINE1 pin", 0x2 },
957 { "HP-OUT pin", 0x3 },
958 { "CD pin", 0x4 },
959 },
960};
961
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200962static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100963
964 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100965 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
966 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100967 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
968 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
969 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
970 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100971
972 /* Modes for retasking pin widgets */
973 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
974 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
975
Tobin Davis82f30042007-02-13 12:45:44 +0100976 /* EAPD Switch Control */
977 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
978
Tobin Davisc9b443d2006-11-14 12:13:39 +0100979 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100980
Tobin Davis7f296732007-03-12 11:39:01 +0100981 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
982 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
983 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
984 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
985 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
986 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
987 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
988 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
989 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
990 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100991 {
992 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
993 .name = "Input Source",
994 .info = conexant_mux_enum_info,
995 .get = conexant_mux_enum_get,
996 .put = conexant_mux_enum_put,
997 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200998 /* Audio input controls */
999 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1000 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1001 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1002 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1003 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1004 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1005 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1006 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1007 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1008 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001009 { } /* end */
1010};
1011
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001012static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001013 /* Set connections */
1014 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1015 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1016 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001017 /* Enable retasking pins as output, initially without power amp */
1018 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001019 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001020
1021 /* Disable digital (SPDIF) pins initially, but users can enable
1022 * them via a mixer switch. In the case of SPDIF-out, this initverb
1023 * payload also sets the generation to 0, output to be in "consumer"
1024 * PCM format, copyright asserted, no pre-emphasis and no validity
1025 * control.
1026 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001027 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1028 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001029
1030 /* Start with output sum widgets muted and their output gains at min */
1031 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1032 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1033
1034 /* Unmute retasking pin widget output buffers since the default
1035 * state appears to be output. As the pin mode is changed by the
1036 * user the pin mode control will take care of enabling the pin's
1037 * input/output buffers as needed.
1038 */
1039 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1040 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1041
1042 /* Mute capture amp left and right */
1043 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1044
1045 /* Set ADC connection select to match default mixer setting (mic1
1046 * pin)
1047 */
1048 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001049 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001050
1051 /* Mute all inputs to mixer widget (even unconnected ones) */
1052 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1053 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1054 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1055 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1056 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1057
1058 { }
1059};
1060#endif
1061
1062
1063/* initialize jack-sensing, too */
1064static int cxt5045_init(struct hda_codec *codec)
1065{
1066 conexant_init(codec);
1067 cxt5045_hp_automute(codec);
1068 return 0;
1069}
1070
1071
1072enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001073 CXT5045_LAPTOP_HPSENSE,
1074 CXT5045_LAPTOP_MICSENSE,
1075 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001076 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001077 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001078#ifdef CONFIG_SND_DEBUG
1079 CXT5045_TEST,
1080#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001081 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001082 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001083};
1084
Takashi Iwaiea734962011-01-17 11:29:34 +01001085static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001086 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1087 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1088 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1089 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001090 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001091#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001092 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001093#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001094 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001095};
1096
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001097static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001098 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001099 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1100 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001101 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001102 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001103 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1104 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001105 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1106 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001107 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1108 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1109 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001110 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1111 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001112 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113 {}
1114};
1115
1116static int patch_cxt5045(struct hda_codec *codec)
1117{
1118 struct conexant_spec *spec;
1119 int board_config;
1120
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001121 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1122 cxt5045_models,
1123 cxt5045_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001124#if 0 /* use the old method just for safety */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001125 if (board_config < 0)
1126 board_config = CXT5045_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001127#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001128 if (board_config == CXT5045_AUTO)
1129 return patch_conexant_auto(codec);
1130
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1132 if (!spec)
1133 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001134 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001135 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136
1137 spec->multiout.max_channels = 2;
1138 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1139 spec->multiout.dac_nids = cxt5045_dac_nids;
1140 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1141 spec->num_adc_nids = 1;
1142 spec->adc_nids = cxt5045_adc_nids;
1143 spec->capsrc_nids = cxt5045_capsrc_nids;
1144 spec->input_mux = &cxt5045_capture_source;
1145 spec->num_mixers = 1;
1146 spec->mixers[0] = cxt5045_mixers;
1147 spec->num_init_verbs = 1;
1148 spec->init_verbs[0] = cxt5045_init_verbs;
1149 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001150 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1151 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001152
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001153 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001154
1155 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001156
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001158 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001159 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160 spec->input_mux = &cxt5045_capture_source;
1161 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001162 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1163 spec->mixers[0] = cxt5045_mixers;
1164 codec->patch_ops.init = cxt5045_init;
1165 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001166 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001167 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001168 spec->input_mux = &cxt5045_capture_source;
1169 spec->num_init_verbs = 2;
1170 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001171 spec->mixers[0] = cxt5045_mixers;
1172 codec->patch_ops.init = cxt5045_init;
1173 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001174 default:
1175 case CXT5045_LAPTOP_HPMICSENSE:
1176 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1177 spec->input_mux = &cxt5045_capture_source;
1178 spec->num_init_verbs = 3;
1179 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1180 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1181 spec->mixers[0] = cxt5045_mixers;
1182 codec->patch_ops.init = cxt5045_init;
1183 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001184 case CXT5045_BENQ:
1185 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1186 spec->input_mux = &cxt5045_capture_source_benq;
1187 spec->num_init_verbs = 1;
1188 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1189 spec->mixers[0] = cxt5045_mixers;
1190 spec->mixers[1] = cxt5045_benq_mixers;
1191 spec->num_mixers = 2;
1192 codec->patch_ops.init = cxt5045_init;
1193 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001194 case CXT5045_LAPTOP_HP530:
1195 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1196 spec->input_mux = &cxt5045_capture_source_hp530;
1197 spec->num_init_verbs = 2;
1198 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1199 spec->mixers[0] = cxt5045_mixers_hp530;
1200 codec->patch_ops.init = cxt5045_init;
1201 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001202#ifdef CONFIG_SND_DEBUG
1203 case CXT5045_TEST:
1204 spec->input_mux = &cxt5045_test_capture_source;
1205 spec->mixers[0] = cxt5045_test_mixer;
1206 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001207 break;
1208
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209#endif
1210 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001211
Takashi Iwai031005f2008-06-26 14:49:58 +02001212 switch (codec->subsystem_id >> 16) {
1213 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001214 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001215 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001216 case 0x17aa:
1217 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1218 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1219 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001220 */
1221 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1222 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1223 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1224 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1225 (1 << AC_AMPCAP_MUTE_SHIFT));
1226 break;
1227 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001228
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001229 if (spec->beep_amp)
1230 snd_hda_attach_beep_device(codec, spec->beep_amp);
1231
Tobin Davisc9b443d2006-11-14 12:13:39 +01001232 return 0;
1233}
1234
1235
1236/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001237#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001238
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001239static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1240static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1241static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001243static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001244 { 2, NULL },
1245};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001246
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001247static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001248 .num_items = 2,
1249 .items = {
1250 { "ExtMic", 0x2 },
1251 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001252 }
1253};
1254
1255/* turn on/off EAPD (+ mute HP) as a master switch */
1256static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1257 struct snd_ctl_elem_value *ucontrol)
1258{
1259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1260 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001261 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262
Tobin Davis82f30042007-02-13 12:45:44 +01001263 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001264 return 0;
1265
Tobin Davis82f30042007-02-13 12:45:44 +01001266 /* toggle internal speakers mute depending of presence of
1267 * the headphone jack
1268 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001269 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001270 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1271 * pin widgets unlike other codecs. In this case, we need to
1272 * set index 0x01 for the volume from the mixer amp 0x19.
1273 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001274 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001275 HDA_AMP_MUTE, bits);
1276 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1277 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1278 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001279 return 1;
1280}
1281
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282/* mute internal speaker if HP is plugged */
1283static void cxt5047_hp_automute(struct hda_codec *codec)
1284{
Tobin Davis82f30042007-02-13 12:45:44 +01001285 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001286 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287
Takashi Iwaid56757a2009-11-18 08:00:14 +01001288 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001289
Takashi Iwai47fd8302007-08-10 17:11:07 +02001290 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001291 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001292 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001293 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001294}
1295
1296/* toggle input of built-in and mic jack appropriately */
1297static void cxt5047_hp_automic(struct hda_codec *codec)
1298{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001299 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001300 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1301 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001302 {}
1303 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001304 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001305 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1306 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001307 {}
1308 };
1309 unsigned int present;
1310
Takashi Iwaid56757a2009-11-18 08:00:14 +01001311 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 if (present)
1313 snd_hda_sequence_write(codec, mic_jack_on);
1314 else
1315 snd_hda_sequence_write(codec, mic_jack_off);
1316}
1317
1318/* unsolicited event for HP jack sensing */
1319static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1320 unsigned int res)
1321{
Marc Boucher9f113e02008-01-22 15:18:08 +01001322 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001323 case CONEXANT_HP_EVENT:
1324 cxt5047_hp_automute(codec);
1325 break;
1326 case CONEXANT_MIC_EVENT:
1327 cxt5047_hp_automic(codec);
1328 break;
1329 }
1330}
1331
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001332static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001333 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1334 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001335 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001336 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1337 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001340 {
1341 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1342 .name = "Master Playback Switch",
1343 .info = cxt_eapd_info,
1344 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001345 .put = cxt5047_hp_master_sw_put,
1346 .private_value = 0x13,
1347 },
1348
1349 {}
1350};
1351
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001352static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001353 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001354 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001355 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1356 {}
1357};
1358
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001359static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001360 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361 { } /* end */
1362};
1363
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001364static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001365 /* Line in, Mic, Built-in Mic */
1366 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1367 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1368 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001369 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001370 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001371 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1372 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001373 /* Record selector: Mic */
1374 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1375 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1376 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1377 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001378 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1379 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1380 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1381 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 /* SPDIF route: PCM */
1383 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001384 /* Enable unsolicited events */
1385 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1386 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 { } /* end */
1388};
1389
1390/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001391static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001392 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393 {}
1394};
1395
1396/* Test configuration for debugging, modelled after the ALC260 test
1397 * configuration.
1398 */
1399#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001400static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001401 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001403 { "LINE1 pin", 0x0 },
1404 { "MIC1 pin", 0x1 },
1405 { "MIC2 pin", 0x2 },
1406 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001407 },
1408};
1409
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001410static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001411
1412 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001413 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1415 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001417 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001421 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001425
1426 /* Modes for retasking pin widgets */
1427 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1428 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1429
Tobin Davis82f30042007-02-13 12:45:44 +01001430 /* EAPD Switch Control */
1431 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1432
Tobin Davisc9b443d2006-11-14 12:13:39 +01001433 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001434 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1435 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1436 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1437 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1438 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1439 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1440 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1441 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001442
Tobin Davis82f30042007-02-13 12:45:44 +01001443 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1444 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1445 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1446 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1447 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1448 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1449 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1450 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001451 {
1452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1453 .name = "Input Source",
1454 .info = conexant_mux_enum_info,
1455 .get = conexant_mux_enum_get,
1456 .put = conexant_mux_enum_put,
1457 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001458 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001459
Tobin Davisc9b443d2006-11-14 12:13:39 +01001460 { } /* end */
1461};
1462
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001463static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001464 /* Enable retasking pins as output, initially without power amp */
1465 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1466 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1467 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468
1469 /* Disable digital (SPDIF) pins initially, but users can enable
1470 * them via a mixer switch. In the case of SPDIF-out, this initverb
1471 * payload also sets the generation to 0, output to be in "consumer"
1472 * PCM format, copyright asserted, no pre-emphasis and no validity
1473 * control.
1474 */
1475 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1476
1477 /* Ensure mic1, mic2, line1 pin widgets take input from the
1478 * OUT1 sum bus when acting as an output.
1479 */
1480 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1481 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1482
1483 /* Start with output sum widgets muted and their output gains at min */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1486
1487 /* Unmute retasking pin widget output buffers since the default
1488 * state appears to be output. As the pin mode is changed by the
1489 * user the pin mode control will take care of enabling the pin's
1490 * input/output buffers as needed.
1491 */
1492 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1493 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1494 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1495
1496 /* Mute capture amp left and right */
1497 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1498
1499 /* Set ADC connection select to match default mixer setting (mic1
1500 * pin)
1501 */
1502 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1503
1504 /* Mute all inputs to mixer widget (even unconnected ones) */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1507 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1508 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1509 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1510 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1511 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1512 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1513
1514 { }
1515};
1516#endif
1517
1518
1519/* initialize jack-sensing, too */
1520static int cxt5047_hp_init(struct hda_codec *codec)
1521{
1522 conexant_init(codec);
1523 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524 return 0;
1525}
1526
1527
1528enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001529 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1530 CXT5047_LAPTOP_HP, /* Some HP laptops */
1531 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532#ifdef CONFIG_SND_DEBUG
1533 CXT5047_TEST,
1534#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001535 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001536 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001537};
1538
Takashi Iwaiea734962011-01-17 11:29:34 +01001539static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001540 [CXT5047_LAPTOP] = "laptop",
1541 [CXT5047_LAPTOP_HP] = "laptop-hp",
1542 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001544 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001546 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001547};
1548
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001549static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001550 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001551 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1552 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001553 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001554 {}
1555};
1556
1557static int patch_cxt5047(struct hda_codec *codec)
1558{
1559 struct conexant_spec *spec;
1560 int board_config;
1561
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001562 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1563 cxt5047_models,
1564 cxt5047_cfg_tbl);
1565#if 0 /* not enabled as default, as BIOS often broken for this codec */
1566 if (board_config < 0)
1567 board_config = CXT5047_AUTO;
1568#endif
1569 if (board_config == CXT5047_AUTO)
1570 return patch_conexant_auto(codec);
1571
Tobin Davisc9b443d2006-11-14 12:13:39 +01001572 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1573 if (!spec)
1574 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001576 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001577
1578 spec->multiout.max_channels = 2;
1579 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1580 spec->multiout.dac_nids = cxt5047_dac_nids;
1581 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1582 spec->num_adc_nids = 1;
1583 spec->adc_nids = cxt5047_adc_nids;
1584 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001585 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001586 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001587 spec->num_init_verbs = 1;
1588 spec->init_verbs[0] = cxt5047_init_verbs;
1589 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001590 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1591 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592
1593 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594
Tobin Davisc9b443d2006-11-14 12:13:39 +01001595 switch (board_config) {
1596 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001597 spec->num_mixers = 2;
1598 spec->mixers[1] = cxt5047_hp_spk_mixers;
1599 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001600 break;
1601 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001602 spec->num_mixers = 2;
1603 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001604 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001605 codec->patch_ops.init = cxt5047_hp_init;
1606 break;
1607 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001608 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001609 spec->num_mixers = 2;
1610 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001611 spec->num_init_verbs = 2;
1612 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001613 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614 break;
1615#ifdef CONFIG_SND_DEBUG
1616 case CXT5047_TEST:
1617 spec->input_mux = &cxt5047_test_capture_source;
1618 spec->mixers[0] = cxt5047_test_mixer;
1619 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001620 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001621#endif
1622 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001623 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001624
1625 switch (codec->subsystem_id >> 16) {
1626 case 0x103c:
1627 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1628 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1629 * with 0 dB offset 0x17)
1630 */
1631 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1632 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1633 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1634 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1635 (1 << AC_AMPCAP_MUTE_SHIFT));
1636 break;
1637 }
1638
Tobin Davisc9b443d2006-11-14 12:13:39 +01001639 return 0;
1640}
1641
Takashi Iwai461e2c72008-01-25 11:35:17 +01001642/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001643static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1644static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001645
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001646static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001647 { 2, NULL },
1648};
1649
1650static void cxt5051_update_speaker(struct hda_codec *codec)
1651{
1652 struct conexant_spec *spec = codec->spec;
1653 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001654 /* headphone pin */
1655 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1656 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1657 pinctl);
1658 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001659 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1660 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1661 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001662 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1663 if (spec->ideapad)
1664 snd_hda_codec_write(codec, 0x1b, 0,
1665 AC_VERB_SET_PIN_WIDGET_CONTROL,
1666 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001667}
1668
1669/* turn on/off EAPD (+ mute HP) as a master switch */
1670static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1671 struct snd_ctl_elem_value *ucontrol)
1672{
1673 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1674
1675 if (!cxt_eapd_put(kcontrol, ucontrol))
1676 return 0;
1677 cxt5051_update_speaker(codec);
1678 return 1;
1679}
1680
1681/* toggle input of built-in and mic jack appropriately */
1682static void cxt5051_portb_automic(struct hda_codec *codec)
1683{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001684 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001685 unsigned int present;
1686
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001687 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001688 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001689 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001690 snd_hda_codec_write(codec, 0x14, 0,
1691 AC_VERB_SET_CONNECT_SEL,
1692 present ? 0x01 : 0x00);
1693}
1694
1695/* switch the current ADC according to the jack state */
1696static void cxt5051_portc_automic(struct hda_codec *codec)
1697{
1698 struct conexant_spec *spec = codec->spec;
1699 unsigned int present;
1700 hda_nid_t new_adc;
1701
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001702 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001703 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001704 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001705 if (present)
1706 spec->cur_adc_idx = 1;
1707 else
1708 spec->cur_adc_idx = 0;
1709 new_adc = spec->adc_nids[spec->cur_adc_idx];
1710 if (spec->cur_adc && spec->cur_adc != new_adc) {
1711 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001712 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001713 spec->cur_adc = new_adc;
1714 snd_hda_codec_setup_stream(codec, new_adc,
1715 spec->cur_adc_stream_tag, 0,
1716 spec->cur_adc_format);
1717 }
1718}
1719
1720/* mute internal speaker if HP is plugged */
1721static void cxt5051_hp_automute(struct hda_codec *codec)
1722{
1723 struct conexant_spec *spec = codec->spec;
1724
Takashi Iwaid56757a2009-11-18 08:00:14 +01001725 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001726 cxt5051_update_speaker(codec);
1727}
1728
1729/* unsolicited event for HP jack sensing */
1730static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1731 unsigned int res)
1732{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001733 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001734 switch (res >> 26) {
1735 case CONEXANT_HP_EVENT:
1736 cxt5051_hp_automute(codec);
1737 break;
1738 case CXT5051_PORTB_EVENT:
1739 cxt5051_portb_automic(codec);
1740 break;
1741 case CXT5051_PORTC_EVENT:
1742 cxt5051_portc_automic(codec);
1743 break;
1744 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001745 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001746}
1747
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001748static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1750 {
1751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1752 .name = "Master Playback Switch",
1753 .info = cxt_eapd_info,
1754 .get = cxt_eapd_get,
1755 .put = cxt5051_hp_master_sw_put,
1756 .private_value = 0x1a,
1757 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001758 {}
1759};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001760
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001761static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001762 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1763 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001764 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1765 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001766 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1767 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001768 {}
1769};
1770
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001771static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001772 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1773 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001774 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1775 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001776 {}
1777};
1778
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001779static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001780 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1781 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001782 {}
1783};
1784
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001785static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001786 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1787 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001788 {}
1789};
1790
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001791static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001792 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1793 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001794 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1795 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001796 {}
1797};
1798
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001799static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001800 /* Line in, Mic */
1801 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1802 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1803 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1804 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1805 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1806 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1807 /* SPK */
1808 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1809 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1810 /* HP, Amp */
1811 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1812 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1813 /* DAC1 */
1814 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001815 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1818 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1819 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001820 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001821 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1822 /* EAPD */
1823 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1824 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001825 { } /* end */
1826};
1827
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001828static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001829 /* Line in, Mic */
1830 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1831 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1832 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1833 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1834 /* SPK */
1835 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1836 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1837 /* HP, Amp */
1838 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1839 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1840 /* DAC1 */
1841 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001842 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1844 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1845 /* SPDIF route: PCM */
1846 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1847 /* EAPD */
1848 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1849 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001850 { } /* end */
1851};
1852
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001853static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001854 /* Line in, Mic */
1855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1856 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1857 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1858 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1859 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1860 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1861 /* SPK */
1862 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1863 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1864 /* HP, Amp */
1865 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1866 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1867 /* Docking HP */
1868 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1869 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1870 /* DAC1 */
1871 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001872 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001873 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1874 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1875 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1876 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001877 {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 -05001878 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1879 /* EAPD */
1880 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1881 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001882 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1883 { } /* end */
1884};
1885
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001886static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001887 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001889 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1890 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1891 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1892 /* SPK */
1893 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1894 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1895 /* HP, Amp */
1896 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1897 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1898 /* DAC1 */
1899 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001900 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001901 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1902 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1903 /* SPDIF route: PCM */
1904 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1905 /* EAPD */
1906 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1907 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001908 { } /* end */
1909};
1910
Takashi Iwai6953e552010-01-24 11:00:27 +01001911static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1912 unsigned int event)
1913{
1914 snd_hda_codec_write(codec, nid, 0,
1915 AC_VERB_SET_UNSOLICITED_ENABLE,
1916 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001917 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1918 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001919}
1920
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001921static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001922 /* Subwoofer */
1923 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1924 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1925 { } /* end */
1926};
1927
Takashi Iwai461e2c72008-01-25 11:35:17 +01001928/* initialize jack-sensing, too */
1929static int cxt5051_init(struct hda_codec *codec)
1930{
Takashi Iwai6953e552010-01-24 11:00:27 +01001931 struct conexant_spec *spec = codec->spec;
1932
Takashi Iwai461e2c72008-01-25 11:35:17 +01001933 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001934 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001935
1936 if (spec->auto_mic & AUTO_MIC_PORTB)
1937 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1938 if (spec->auto_mic & AUTO_MIC_PORTC)
1939 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1940
Takashi Iwai461e2c72008-01-25 11:35:17 +01001941 if (codec->patch_ops.unsol_event) {
1942 cxt5051_hp_automute(codec);
1943 cxt5051_portb_automic(codec);
1944 cxt5051_portc_automic(codec);
1945 }
1946 return 0;
1947}
1948
1949
1950enum {
1951 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1952 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001953 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001954 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001955 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001956 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001957 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001958 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001959 CXT5051_MODELS
1960};
1961
Takashi Iwaiea734962011-01-17 11:29:34 +01001962static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001963 [CXT5051_LAPTOP] = "laptop",
1964 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001965 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001966 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001967 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001968 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001969 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001970 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001971};
1972
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001973static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001974 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001975 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001976 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001977 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001978 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1979 CXT5051_LAPTOP),
1980 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001981 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001982 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001983 {}
1984};
1985
1986static int patch_cxt5051(struct hda_codec *codec)
1987{
1988 struct conexant_spec *spec;
1989 int board_config;
1990
Takashi Iwai6764bce2011-05-13 16:52:25 +02001991 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1992 cxt5051_models,
1993 cxt5051_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001994#if 0 /* use the old method just for safety */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001995 if (board_config < 0)
1996 board_config = CXT5051_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001997#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001998 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001999 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02002000
Takashi Iwai461e2c72008-01-25 11:35:17 +01002001 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2002 if (!spec)
2003 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002004 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002005 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002006
2007 codec->patch_ops = conexant_patch_ops;
2008 codec->patch_ops.init = cxt5051_init;
2009
2010 spec->multiout.max_channels = 2;
2011 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2012 spec->multiout.dac_nids = cxt5051_dac_nids;
2013 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2014 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2015 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002016 spec->num_mixers = 2;
2017 spec->mixers[0] = cxt5051_capture_mixers;
2018 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002019 spec->num_init_verbs = 1;
2020 spec->init_verbs[0] = cxt5051_init_verbs;
2021 spec->spdif_route = 0;
2022 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2023 spec->channel_mode = cxt5051_modes;
2024 spec->cur_adc = 0;
2025 spec->cur_adc_idx = 0;
2026
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002027 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2028
Takashi Iwai79d7d532009-03-04 09:03:50 +01002029 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2030
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002031 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002032 switch (board_config) {
2033 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002034 spec->mixers[0] = cxt5051_hp_mixers;
2035 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002036 case CXT5051_HP_DV6736:
2037 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2038 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002039 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002040 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002041 case CXT5051_LENOVO_X200:
2042 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002043 /* Thinkpad X301 does not have S/PDIF wired and no ability
2044 to use a docking station. */
2045 if (codec->subsystem_id == 0x17aa211f)
2046 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002047 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002048 case CXT5051_F700:
2049 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2050 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002051 spec->auto_mic = 0;
2052 break;
2053 case CXT5051_TOSHIBA:
2054 spec->mixers[0] = cxt5051_toshiba_mixers;
2055 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002056 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002057 case CXT5051_IDEAPAD:
2058 spec->init_verbs[spec->num_init_verbs++] =
2059 cxt5051_ideapad_init_verbs;
2060 spec->ideapad = 1;
2061 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002062 }
2063
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002064 if (spec->beep_amp)
2065 snd_hda_attach_beep_device(codec, spec->beep_amp);
2066
Takashi Iwai461e2c72008-01-25 11:35:17 +01002067 return 0;
2068}
2069
Daniel Drake0fb67e92009-07-16 14:46:57 +01002070/* Conexant 5066 specific */
2071
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002072static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2073static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2074static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2075static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002076
Daniel Drakedbaccc02009-11-09 15:17:24 +00002077/* OLPC's microphone port is DC coupled for use with external sensors,
2078 * therefore we use a 50% mic bias in order to center the input signal with
2079 * the DC input range of the codec. */
2080#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2081
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002082static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002083 { 2, NULL },
2084};
2085
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002086#define HP_PRESENT_PORT_A (1 << 0)
2087#define HP_PRESENT_PORT_D (1 << 1)
2088#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2089#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2090
Daniel Drake0fb67e92009-07-16 14:46:57 +01002091static void cxt5066_update_speaker(struct hda_codec *codec)
2092{
2093 struct conexant_spec *spec = codec->spec;
2094 unsigned int pinctl;
2095
John Baboval3a253442010-12-02 11:21:31 -05002096 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2097 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002098
2099 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002100 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002101 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2102 pinctl);
2103
2104 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002105 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2106 if (spec->dell_automute || spec->thinkpad) {
2107 /* Mute if Port A is connected */
2108 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002109 pinctl = 0;
2110 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002111 /* Thinkpad/Dell doesn't give pin-D status */
2112 if (!hp_port_d_present(spec))
2113 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002114 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002115 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2116 pinctl);
2117
2118 /* CLASS_D AMP */
2119 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2120 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2121 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002122}
2123
2124/* turn on/off EAPD (+ mute HP) as a master switch */
2125static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2126 struct snd_ctl_elem_value *ucontrol)
2127{
2128 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2129
2130 if (!cxt_eapd_put(kcontrol, ucontrol))
2131 return 0;
2132
2133 cxt5066_update_speaker(codec);
2134 return 1;
2135}
2136
Daniel Drakec4cfe662010-01-07 13:47:04 +01002137static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2138 .num_items = 3,
2139 .items = {
2140 { "Off", PIN_IN },
2141 { "50%", PIN_VREF50 },
2142 { "80%", PIN_VREF80 },
2143 },
2144};
2145
2146static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2147{
2148 struct conexant_spec *spec = codec->spec;
2149 /* Even though port F is the DC input, the bias is controlled on port B.
2150 * we also leave that port as an active input (but unselected) in DC mode
2151 * just in case that is necessary to make the bias setting take effect. */
2152 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2153 AC_VERB_SET_PIN_WIDGET_CONTROL,
2154 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2155}
2156
Daniel Drake75f89912010-01-07 13:46:25 +01002157/* OLPC defers mic widget control until when capture is started because the
2158 * microphone LED comes on as soon as these settings are put in place. if we
2159 * did this before recording, it would give the false indication that recording
2160 * is happening when it is not. */
2161static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002162{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002163 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002164 if (!spec->recording)
2165 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002166
Daniel Drakec4cfe662010-01-07 13:47:04 +01002167 if (spec->dc_enable) {
2168 /* in DC mode we ignore presence detection and just use the jack
2169 * through our special DC port */
2170 const struct hda_verb enable_dc_mode[] = {
2171 /* disble internal mic, port C */
2172 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2173
2174 /* enable DC capture, port F */
2175 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2176 {},
2177 };
2178
2179 snd_hda_sequence_write(codec, enable_dc_mode);
2180 /* port B input disabled (and bias set) through the following call */
2181 cxt5066_set_olpc_dc_bias(codec);
2182 return;
2183 }
2184
2185 /* disable DC (port F) */
2186 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2187
Daniel Drake75f89912010-01-07 13:46:25 +01002188 /* external mic, port B */
2189 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2190 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002191
Daniel Drake75f89912010-01-07 13:46:25 +01002192 /* internal mic, port C */
2193 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2194 spec->ext_mic_present ? 0 : PIN_VREF80);
2195}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002196
Daniel Drake75f89912010-01-07 13:46:25 +01002197/* toggle input of built-in and mic jack appropriately */
2198static void cxt5066_olpc_automic(struct hda_codec *codec)
2199{
2200 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002201 unsigned int present;
2202
Daniel Drakec4cfe662010-01-07 13:47:04 +01002203 if (spec->dc_enable) /* don't do presence detection in DC mode */
2204 return;
2205
Daniel Drake75f89912010-01-07 13:46:25 +01002206 present = snd_hda_codec_read(codec, 0x1a, 0,
2207 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2208 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002209 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002210 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002211 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002212
2213 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2214 present ? 0 : 1);
2215 spec->ext_mic_present = !!present;
2216
2217 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002218}
2219
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002220/* toggle input of built-in digital mic and mic jack appropriately */
2221static void cxt5066_vostro_automic(struct hda_codec *codec)
2222{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002223 unsigned int present;
2224
2225 struct hda_verb ext_mic_present[] = {
2226 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002227 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002228
2229 /* switch to external mic input */
2230 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2231 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2232
2233 /* disable internal digital mic */
2234 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2235 {}
2236 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002237 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002238 /* enable internal mic, port C */
2239 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2240
2241 /* switch to internal mic input */
2242 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2243
2244 /* disable external mic, port B */
2245 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2246 {}
2247 };
2248
2249 present = snd_hda_jack_detect(codec, 0x1a);
2250 if (present) {
2251 snd_printdd("CXT5066: external microphone detected\n");
2252 snd_hda_sequence_write(codec, ext_mic_present);
2253 } else {
2254 snd_printdd("CXT5066: external microphone absent\n");
2255 snd_hda_sequence_write(codec, ext_mic_absent);
2256 }
2257}
2258
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002259/* toggle input of built-in digital mic and mic jack appropriately */
2260static void cxt5066_ideapad_automic(struct hda_codec *codec)
2261{
2262 unsigned int present;
2263
2264 struct hda_verb ext_mic_present[] = {
2265 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2266 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2267 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2268 {}
2269 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002270 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002271 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2272 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2273 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2274 {}
2275 };
2276
2277 present = snd_hda_jack_detect(codec, 0x1b);
2278 if (present) {
2279 snd_printdd("CXT5066: external microphone detected\n");
2280 snd_hda_sequence_write(codec, ext_mic_present);
2281 } else {
2282 snd_printdd("CXT5066: external microphone absent\n");
2283 snd_hda_sequence_write(codec, ext_mic_absent);
2284 }
2285}
2286
David Henningssona1d69062011-01-21 13:33:28 +01002287
2288/* toggle input of built-in digital mic and mic jack appropriately */
2289static void cxt5066_asus_automic(struct hda_codec *codec)
2290{
2291 unsigned int present;
2292
2293 present = snd_hda_jack_detect(codec, 0x1b);
2294 snd_printdd("CXT5066: external microphone present=%d\n", present);
2295 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2296 present ? 1 : 0);
2297}
2298
2299
David Henningsson048e78a2010-09-02 08:35:47 +02002300/* toggle input of built-in digital mic and mic jack appropriately */
2301static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2302{
2303 unsigned int present;
2304
2305 present = snd_hda_jack_detect(codec, 0x1b);
2306 snd_printdd("CXT5066: external microphone present=%d\n", present);
2307 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2308 present ? 1 : 3);
2309}
2310
2311
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002312/* toggle input of built-in digital mic and mic jack appropriately
2313 order is: external mic -> dock mic -> interal mic */
2314static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2315{
2316 unsigned int ext_present, dock_present;
2317
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002318 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002319 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2320 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2321 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2322 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2323 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2324 {}
2325 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002326 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002327 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2328 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2329 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2330 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2331 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2332 {}
2333 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002334 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002335 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2336 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2337 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2338 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2339 {}
2340 };
2341
2342 ext_present = snd_hda_jack_detect(codec, 0x1b);
2343 dock_present = snd_hda_jack_detect(codec, 0x1a);
2344 if (ext_present) {
2345 snd_printdd("CXT5066: external microphone detected\n");
2346 snd_hda_sequence_write(codec, ext_mic_present);
2347 } else if (dock_present) {
2348 snd_printdd("CXT5066: dock microphone detected\n");
2349 snd_hda_sequence_write(codec, dock_mic_present);
2350 } else {
2351 snd_printdd("CXT5066: external microphone absent\n");
2352 snd_hda_sequence_write(codec, ext_mic_absent);
2353 }
2354}
2355
Daniel Drake0fb67e92009-07-16 14:46:57 +01002356/* mute internal speaker if HP is plugged */
2357static void cxt5066_hp_automute(struct hda_codec *codec)
2358{
2359 struct conexant_spec *spec = codec->spec;
2360 unsigned int portA, portD;
2361
2362 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002363 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002364
2365 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002366 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002368 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2369 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002370 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2371 portA, portD, spec->hp_present);
2372 cxt5066_update_speaker(codec);
2373}
2374
David Henningsson02b6b5b2011-01-21 13:27:39 +01002375/* Dispatch the right mic autoswitch function */
2376static void cxt5066_automic(struct hda_codec *codec)
2377{
2378 struct conexant_spec *spec = codec->spec;
2379
2380 if (spec->dell_vostro)
2381 cxt5066_vostro_automic(codec);
2382 else if (spec->ideapad)
2383 cxt5066_ideapad_automic(codec);
2384 else if (spec->thinkpad)
2385 cxt5066_thinkpad_automic(codec);
2386 else if (spec->hp_laptop)
2387 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002388 else if (spec->asus)
2389 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002390}
2391
Daniel Drake0fb67e92009-07-16 14:46:57 +01002392/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002393static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002394{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002395 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002396 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2397 switch (res >> 26) {
2398 case CONEXANT_HP_EVENT:
2399 cxt5066_hp_automute(codec);
2400 break;
2401 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002402 /* ignore mic events in DC mode; we're always using the jack */
2403 if (!spec->dc_enable)
2404 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002405 break;
2406 }
2407}
2408
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002409/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002410static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002411{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002412 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002413 switch (res >> 26) {
2414 case CONEXANT_HP_EVENT:
2415 cxt5066_hp_automute(codec);
2416 break;
2417 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002418 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002419 break;
2420 }
2421}
2422
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002423
Daniel Drake0fb67e92009-07-16 14:46:57 +01002424static const struct hda_input_mux cxt5066_analog_mic_boost = {
2425 .num_items = 5,
2426 .items = {
2427 { "0dB", 0 },
2428 { "10dB", 1 },
2429 { "20dB", 2 },
2430 { "30dB", 3 },
2431 { "40dB", 4 },
2432 },
2433};
2434
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002435static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002436{
2437 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002438 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002439 AC_VERB_SET_AMP_GAIN_MUTE,
2440 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2441 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002442 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002443 /* adjust the internal mic as well...it is not through 0x17 */
2444 snd_hda_codec_write_cache(codec, 0x23, 0,
2445 AC_VERB_SET_AMP_GAIN_MUTE,
2446 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2447 cxt5066_analog_mic_boost.
2448 items[spec->mic_boost].index);
2449 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002450}
2451
Daniel Drake0fb67e92009-07-16 14:46:57 +01002452static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2453 struct snd_ctl_elem_info *uinfo)
2454{
2455 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2456}
2457
2458static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2459 struct snd_ctl_elem_value *ucontrol)
2460{
2461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002462 struct conexant_spec *spec = codec->spec;
2463 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002464 return 0;
2465}
2466
2467static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2468 struct snd_ctl_elem_value *ucontrol)
2469{
2470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002471 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002472 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2473 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002474 idx = ucontrol->value.enumerated.item[0];
2475 if (idx >= imux->num_items)
2476 idx = imux->num_items - 1;
2477
Daniel Drakec4cfe662010-01-07 13:47:04 +01002478 spec->mic_boost = idx;
2479 if (!spec->dc_enable)
2480 cxt5066_set_mic_boost(codec);
2481 return 1;
2482}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002483
Daniel Drakec4cfe662010-01-07 13:47:04 +01002484static void cxt5066_enable_dc(struct hda_codec *codec)
2485{
2486 const struct hda_verb enable_dc_mode[] = {
2487 /* disable gain */
2488 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489
2490 /* switch to DC input */
2491 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2492 {}
2493 };
2494
2495 /* configure as input source */
2496 snd_hda_sequence_write(codec, enable_dc_mode);
2497 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2498}
2499
2500static void cxt5066_disable_dc(struct hda_codec *codec)
2501{
2502 /* reconfigure input source */
2503 cxt5066_set_mic_boost(codec);
2504 /* automic also selects the right mic if we're recording */
2505 cxt5066_olpc_automic(codec);
2506}
2507
2508static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2509 struct snd_ctl_elem_value *ucontrol)
2510{
2511 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2512 struct conexant_spec *spec = codec->spec;
2513 ucontrol->value.integer.value[0] = spec->dc_enable;
2514 return 0;
2515}
2516
2517static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2518 struct snd_ctl_elem_value *ucontrol)
2519{
2520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2521 struct conexant_spec *spec = codec->spec;
2522 int dc_enable = !!ucontrol->value.integer.value[0];
2523
2524 if (dc_enable == spec->dc_enable)
2525 return 0;
2526
2527 spec->dc_enable = dc_enable;
2528 if (dc_enable)
2529 cxt5066_enable_dc(codec);
2530 else
2531 cxt5066_disable_dc(codec);
2532
2533 return 1;
2534}
2535
2536static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2537 struct snd_ctl_elem_info *uinfo)
2538{
2539 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2540}
2541
2542static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2543 struct snd_ctl_elem_value *ucontrol)
2544{
2545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2546 struct conexant_spec *spec = codec->spec;
2547 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2548 return 0;
2549}
2550
2551static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2552 struct snd_ctl_elem_value *ucontrol)
2553{
2554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2555 struct conexant_spec *spec = codec->spec;
2556 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2557 unsigned int idx;
2558
2559 idx = ucontrol->value.enumerated.item[0];
2560 if (idx >= imux->num_items)
2561 idx = imux->num_items - 1;
2562
2563 spec->dc_input_bias = idx;
2564 if (spec->dc_enable)
2565 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002566 return 1;
2567}
2568
Daniel Drake75f89912010-01-07 13:46:25 +01002569static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2570{
2571 struct conexant_spec *spec = codec->spec;
2572 /* mark as recording and configure the microphone widget so that the
2573 * recording LED comes on. */
2574 spec->recording = 1;
2575 cxt5066_olpc_select_mic(codec);
2576}
2577
2578static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2579{
2580 struct conexant_spec *spec = codec->spec;
2581 const struct hda_verb disable_mics[] = {
2582 /* disable external mic, port B */
2583 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2584
2585 /* disble internal mic, port C */
2586 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002587
2588 /* disable DC capture, port F */
2589 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002590 {},
2591 };
2592
2593 snd_hda_sequence_write(codec, disable_mics);
2594 spec->recording = 0;
2595}
2596
Andy Robinsonf6a24912011-01-24 10:12:37 -05002597static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002598 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002599 int num_pins)
2600{
2601 struct conexant_spec *spec = codec->spec;
2602 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2603 int i;
2604
2605 for (i = 0; i < num_pins; i++, dig_pins++) {
2606 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2607 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2608 continue;
2609 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2610 continue;
2611 if (spec->slave_dig_outs[0])
2612 nid_loc++;
2613 else
2614 nid_loc = spec->slave_dig_outs;
2615 }
2616}
2617
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002618static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002619 .num_items = 4,
2620 .items = {
2621 { "Mic B", 0 },
2622 { "Mic C", 1 },
2623 { "Mic E", 2 },
2624 { "Mic F", 3 },
2625 },
2626};
2627
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002628static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002629 .ops = &snd_hda_bind_vol,
2630 .values = {
2631 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2632 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2633 0
2634 },
2635};
2636
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002637static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002638 .ops = &snd_hda_bind_sw,
2639 .values = {
2640 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2641 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2642 0
2643 },
2644};
2645
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002646static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002647 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2648 {}
2649};
2650
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002651static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002652 {
2653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2654 .name = "Master Playback Volume",
2655 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2656 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2657 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002658 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002659 .info = snd_hda_mixer_amp_volume_info,
2660 .get = snd_hda_mixer_amp_volume_get,
2661 .put = snd_hda_mixer_amp_volume_put,
2662 .tlv = { .c = snd_hda_mixer_amp_tlv },
2663 /* offset by 28 volume steps to limit minimum gain to -46dB */
2664 .private_value =
2665 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2666 },
2667 {}
2668};
2669
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002670static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002671 {
2672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2673 .name = "DC Mode Enable Switch",
2674 .info = snd_ctl_boolean_mono_info,
2675 .get = cxt5066_olpc_dc_get,
2676 .put = cxt5066_olpc_dc_put,
2677 },
2678 {
2679 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2680 .name = "DC Input Bias Enum",
2681 .info = cxt5066_olpc_dc_bias_enum_info,
2682 .get = cxt5066_olpc_dc_bias_enum_get,
2683 .put = cxt5066_olpc_dc_bias_enum_put,
2684 },
2685 {}
2686};
2687
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002688static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002689 {
2690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2691 .name = "Master Playback Switch",
2692 .info = cxt_eapd_info,
2693 .get = cxt_eapd_get,
2694 .put = cxt5066_hp_master_sw_put,
2695 .private_value = 0x1d,
2696 },
2697
2698 {
2699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002700 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002701 .info = cxt5066_mic_boost_mux_enum_info,
2702 .get = cxt5066_mic_boost_mux_enum_get,
2703 .put = cxt5066_mic_boost_mux_enum_put,
2704 },
2705
2706 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2707 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2708 {}
2709};
2710
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002711static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002712 {
2713 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002714 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002715 .info = cxt5066_mic_boost_mux_enum_info,
2716 .get = cxt5066_mic_boost_mux_enum_get,
2717 .put = cxt5066_mic_boost_mux_enum_put,
2718 .private_value = 0x23 | 0x100,
2719 },
2720 {}
2721};
2722
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002723static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002724 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2725 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2726 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2727 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2728
2729 /* Speakers */
2730 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2731 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2732
2733 /* HP, Amp */
2734 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2735 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2736
2737 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2738 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2739
2740 /* DAC1 */
2741 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2742
2743 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2744 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2745 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2746 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2747 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2748 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2749
2750 /* no digital microphone support yet */
2751 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2752
2753 /* Audio input selector */
2754 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2755
2756 /* SPDIF route: PCM */
2757 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2758 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2759
2760 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2761 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2762
2763 /* EAPD */
2764 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2765
2766 /* not handling these yet */
2767 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2768 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2769 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2770 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2771 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2772 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2773 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2774 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2775 { } /* end */
2776};
2777
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002778static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002779 /* Port A: headphones */
2780 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2781 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2782
2783 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002784 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002785
2786 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002787 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002788
2789 /* Port D: unused */
2790 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2791
2792 /* Port E: unused, but has primary EAPD */
2793 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2794 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2795
Daniel Drakec4cfe662010-01-07 13:47:04 +01002796 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002797 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2798
2799 /* Port G: internal speakers */
2800 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2801 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2802
2803 /* DAC1 */
2804 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2805
2806 /* DAC2: unused */
2807 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2808
2809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2814 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2815 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2816 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2817 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2818 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2819 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2820 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2821
2822 /* Disable digital microphone port */
2823 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824
2825 /* Audio input selectors */
2826 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2827 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2828
2829 /* Disable SPDIF */
2830 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2832
2833 /* enable unsolicited events for Port A and B */
2834 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2835 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2836 { } /* end */
2837};
2838
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002839static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002840 /* Port A: headphones */
2841 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2842 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2843
2844 /* Port B: external microphone */
2845 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2846
2847 /* Port C: unused */
2848 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2849
2850 /* Port D: unused */
2851 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2852
2853 /* Port E: unused, but has primary EAPD */
2854 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2856
2857 /* Port F: unused */
2858 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2859
2860 /* Port G: internal speakers */
2861 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2862 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2863
2864 /* DAC1 */
2865 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2866
2867 /* DAC2: unused */
2868 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2869
2870 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2871 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2872 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2873 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2874 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2875 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2876 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2877 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2878 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2879 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2880 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2881 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2882
2883 /* Digital microphone port */
2884 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2885
2886 /* Audio input selectors */
2887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2888 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2889
2890 /* Disable SPDIF */
2891 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2892 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2893
2894 /* enable unsolicited events for Port A and B */
2895 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2896 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2897 { } /* end */
2898};
2899
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002900static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002901 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2902 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2903 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2904 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2905
2906 /* Speakers */
2907 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2908 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2909
2910 /* HP, Amp */
2911 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2912 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2913
2914 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2915 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2916
2917 /* DAC1 */
2918 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2919
2920 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2921 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2922 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2923 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2924 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2925 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2926 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2927
2928 /* Audio input selector */
2929 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2930 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2931
2932 /* SPDIF route: PCM */
2933 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2934 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2935
2936 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2937 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2938
2939 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002940 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002941
2942 /* EAPD */
2943 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2944
2945 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2946 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2947 { } /* end */
2948};
2949
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002950static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002951 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2952 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2953
2954 /* Port G: internal speakers */
2955 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2956 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2957
2958 /* Port A: HP, Amp */
2959 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2960 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2961
2962 /* Port B: Mic Dock */
2963 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2964
2965 /* Port C: Mic */
2966 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2967
2968 /* Port D: HP Dock, Amp */
2969 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2970 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2971
2972 /* DAC1 */
2973 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2974
2975 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2976 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2977 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2978 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2979 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2980 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2981 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2982
2983 /* Audio input selector */
2984 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2985 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2986
2987 /* SPDIF route: PCM */
2988 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2989 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2990
2991 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2992 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2993
2994 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002995 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002996
2997 /* EAPD */
2998 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2999
3000 /* enable unsolicited events for Port A, B, C and D */
3001 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3002 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3003 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3004 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3005 { } /* end */
3006};
3007
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003008static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01003009 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3010 { } /* end */
3011};
3012
David Henningsson048e78a2010-09-02 08:35:47 +02003013
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003014static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02003015 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3016 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3017 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3018 { } /* end */
3019};
3020
Daniel Drake0fb67e92009-07-16 14:46:57 +01003021/* initialize jack-sensing, too */
3022static int cxt5066_init(struct hda_codec *codec)
3023{
3024 snd_printdd("CXT5066: init\n");
3025 conexant_init(codec);
3026 if (codec->patch_ops.unsol_event) {
3027 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003028 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003029 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003030 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003031 return 0;
3032}
3033
Daniel Drake75f89912010-01-07 13:46:25 +01003034static int cxt5066_olpc_init(struct hda_codec *codec)
3035{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003036 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003037 snd_printdd("CXT5066: init\n");
3038 conexant_init(codec);
3039 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003040 if (!spec->dc_enable) {
3041 cxt5066_set_mic_boost(codec);
3042 cxt5066_olpc_automic(codec);
3043 } else {
3044 cxt5066_enable_dc(codec);
3045 }
Daniel Drake75f89912010-01-07 13:46:25 +01003046 return 0;
3047}
3048
Daniel Drake0fb67e92009-07-16 14:46:57 +01003049enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003050 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003051 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3052 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003053 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003054 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003055 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003056 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003057 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003058 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003059 CXT5066_MODELS
3060};
3061
Takashi Iwaiea734962011-01-17 11:29:34 +01003062static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003063 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003064 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3065 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003066 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003067 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003068 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003069 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003070 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003071 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003072};
3073
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003074static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003075 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003076 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003077 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003078 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003079 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003080 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003081 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3082 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003083 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003084 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003085 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003086 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003087 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003088 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003089 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003090 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3091 CXT5066_LAPTOP),
3092 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003093 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003094 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003095 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003096 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003097 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003098 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003099 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003100 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003101 {}
3102};
3103
3104static int patch_cxt5066(struct hda_codec *codec)
3105{
3106 struct conexant_spec *spec;
3107 int board_config;
3108
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003109 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3110 cxt5066_models, cxt5066_cfg_tbl);
3111#if 0 /* use the old method just for safety */
3112 if (board_config < 0)
3113 board_config = CXT5066_AUTO;
3114#endif
3115 if (board_config == CXT5066_AUTO)
3116 return patch_conexant_auto(codec);
3117
Daniel Drake0fb67e92009-07-16 14:46:57 +01003118 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3119 if (!spec)
3120 return -ENOMEM;
3121 codec->spec = spec;
3122
3123 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003124 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003125
3126 spec->dell_automute = 0;
3127 spec->multiout.max_channels = 2;
3128 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3129 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003130 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3131 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003132 spec->num_adc_nids = 1;
3133 spec->adc_nids = cxt5066_adc_nids;
3134 spec->capsrc_nids = cxt5066_capsrc_nids;
3135 spec->input_mux = &cxt5066_capture_source;
3136
3137 spec->port_d_mode = PIN_HP;
3138
3139 spec->num_init_verbs = 1;
3140 spec->init_verbs[0] = cxt5066_init_verbs;
3141 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3142 spec->channel_mode = cxt5066_modes;
3143 spec->cur_adc = 0;
3144 spec->cur_adc_idx = 0;
3145
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003146 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3147
Daniel Drake0fb67e92009-07-16 14:46:57 +01003148 switch (board_config) {
3149 default:
3150 case CXT5066_LAPTOP:
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3152 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3153 break;
3154 case CXT5066_DELL_LAPTOP:
3155 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3156 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3157
3158 spec->port_d_mode = PIN_OUT;
3159 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3160 spec->num_init_verbs++;
3161 spec->dell_automute = 1;
3162 break;
David Henningssona1d69062011-01-21 13:33:28 +01003163 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003164 case CXT5066_HP_LAPTOP:
3165 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003166 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003167 spec->init_verbs[spec->num_init_verbs] =
3168 cxt5066_init_verbs_hp_laptop;
3169 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003170 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3171 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003172 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3173 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3174 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003175 if (board_config == CXT5066_HP_LAPTOP)
3176 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003177 /* input source automatically selected */
3178 spec->input_mux = NULL;
3179 spec->port_d_mode = 0;
3180 spec->mic_boost = 3; /* default 30dB gain */
3181 break;
3182
Daniel Drake0fb67e92009-07-16 14:46:57 +01003183 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003184 codec->patch_ops.init = cxt5066_olpc_init;
3185 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003186 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3187 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003188 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003189 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3190 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003191 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003192
3193 /* no S/PDIF out */
3194 spec->multiout.dig_out_nid = 0;
3195
3196 /* input source automatically selected */
3197 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003198
3199 /* our capture hooks which allow us to turn on the microphone LED
3200 * at the right time */
3201 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3202 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003203 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003204 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003205 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003206 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003207 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3208 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3209 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003210 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003211 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003212 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003213 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003214
3215 /* no S/PDIF out */
3216 spec->multiout.dig_out_nid = 0;
3217
3218 /* input source automatically selected */
3219 spec->input_mux = NULL;
3220 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003221 case CXT5066_IDEAPAD:
3222 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003223 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003224 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3225 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3226 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3227 spec->port_d_mode = 0;
3228 spec->ideapad = 1;
3229 spec->mic_boost = 2; /* default 20dB gain */
3230
3231 /* no S/PDIF out */
3232 spec->multiout.dig_out_nid = 0;
3233
3234 /* input source automatically selected */
3235 spec->input_mux = NULL;
3236 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003237 case CXT5066_THINKPAD:
3238 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003239 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003240 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3241 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3242 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3243 spec->thinkpad = 1;
3244 spec->port_d_mode = PIN_OUT;
3245 spec->mic_boost = 2; /* default 20dB gain */
3246
3247 /* no S/PDIF out */
3248 spec->multiout.dig_out_nid = 0;
3249
3250 /* input source automatically selected */
3251 spec->input_mux = NULL;
3252 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003253 }
3254
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003255 if (spec->beep_amp)
3256 snd_hda_attach_beep_device(codec, spec->beep_amp);
3257
Daniel Drake0fb67e92009-07-16 14:46:57 +01003258 return 0;
3259}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003260
3261/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003262 * Automatic parser for CX20641 & co
3263 */
3264
Takashi Iwai6764bce2011-05-13 16:52:25 +02003265static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3266 struct hda_codec *codec,
3267 unsigned int stream_tag,
3268 unsigned int format,
3269 struct snd_pcm_substream *substream)
3270{
3271 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003272 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003273 if (spec->adc_switching) {
3274 spec->cur_adc = adc;
3275 spec->cur_adc_stream_tag = stream_tag;
3276 spec->cur_adc_format = format;
3277 }
3278 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3279 return 0;
3280}
3281
3282static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3283 struct hda_codec *codec,
3284 struct snd_pcm_substream *substream)
3285{
3286 struct conexant_spec *spec = codec->spec;
3287 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3288 spec->cur_adc = 0;
3289 return 0;
3290}
3291
3292static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3293 .substreams = 1,
3294 .channels_min = 2,
3295 .channels_max = 2,
3296 .nid = 0, /* fill later */
3297 .ops = {
3298 .prepare = cx_auto_capture_pcm_prepare,
3299 .cleanup = cx_auto_capture_pcm_cleanup
3300 },
3301};
3302
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003303static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003304
3305/* get the connection index of @nid in the widget @mux */
3306static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3307 hda_nid_t nid)
3308{
3309 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3310 int i, nums;
3311
3312 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3313 for (i = 0; i < nums; i++)
3314 if (conn[i] == nid)
3315 return i;
3316 return -1;
3317}
3318
3319/* get an unassigned DAC from the given list.
3320 * Return the nid if found and reduce the DAC list, or return zero if
3321 * not found
3322 */
3323static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3324 hda_nid_t *dacs, int *num_dacs)
3325{
3326 int i, nums = *num_dacs;
3327 hda_nid_t ret = 0;
3328
3329 for (i = 0; i < nums; i++) {
3330 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3331 ret = dacs[i];
3332 break;
3333 }
3334 }
3335 if (!ret)
3336 return 0;
3337 if (--nums > 0)
3338 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3339 *num_dacs = nums;
3340 return ret;
3341}
3342
3343#define MAX_AUTO_DACS 5
3344
3345/* fill analog DAC list from the widget tree */
3346static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3347{
3348 hda_nid_t nid, end_nid;
3349 int nums = 0;
3350
3351 end_nid = codec->start_nid + codec->num_nodes;
3352 for (nid = codec->start_nid; nid < end_nid; nid++) {
3353 unsigned int wcaps = get_wcaps(codec, nid);
3354 unsigned int type = get_wcaps_type(wcaps);
3355 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3356 dacs[nums++] = nid;
3357 if (nums >= MAX_AUTO_DACS)
3358 break;
3359 }
3360 }
3361 return nums;
3362}
3363
3364/* fill pin_dac_pair list from the pin and dac list */
3365static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3366 int num_pins, hda_nid_t *dacs, int *rest,
3367 struct pin_dac_pair *filled, int type)
3368{
3369 int i, nums;
3370
3371 nums = 0;
3372 for (i = 0; i < num_pins; i++) {
3373 filled[nums].pin = pins[i];
3374 filled[nums].type = type;
3375 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3376 nums++;
3377 }
3378 return nums;
3379}
3380
3381/* parse analog output paths */
3382static void cx_auto_parse_output(struct hda_codec *codec)
3383{
3384 struct conexant_spec *spec = codec->spec;
3385 struct auto_pin_cfg *cfg = &spec->autocfg;
3386 hda_nid_t dacs[MAX_AUTO_DACS];
3387 int i, j, nums, rest;
3388
3389 rest = fill_cx_auto_dacs(codec, dacs);
3390 /* parse all analog output pins */
3391 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3392 dacs, &rest, spec->dac_info,
3393 AUTO_PIN_LINE_OUT);
3394 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3395 dacs, &rest, spec->dac_info + nums,
3396 AUTO_PIN_HP_OUT);
3397 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3398 dacs, &rest, spec->dac_info + nums,
3399 AUTO_PIN_SPEAKER_OUT);
3400 spec->dac_info_filled = nums;
3401 /* fill multiout struct */
3402 for (i = 0; i < nums; i++) {
3403 hda_nid_t dac = spec->dac_info[i].dac;
3404 if (!dac)
3405 continue;
3406 switch (spec->dac_info[i].type) {
3407 case AUTO_PIN_LINE_OUT:
3408 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3409 spec->multiout.num_dacs++;
3410 break;
3411 case AUTO_PIN_HP_OUT:
3412 case AUTO_PIN_SPEAKER_OUT:
3413 if (!spec->multiout.hp_nid) {
3414 spec->multiout.hp_nid = dac;
3415 break;
3416 }
3417 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3418 if (!spec->multiout.extra_out_nid[j]) {
3419 spec->multiout.extra_out_nid[j] = dac;
3420 break;
3421 }
3422 break;
3423 }
3424 }
3425 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003426 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003427
Takashi Iwai03697e22011-05-17 09:53:31 +02003428 for (i = 0; i < cfg->hp_outs; i++) {
3429 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3430 spec->auto_mute = 1;
3431 break;
3432 }
3433 }
3434 if (spec->auto_mute && cfg->line_out_pins[0] &&
3435 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3436 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3437 for (i = 0; i < cfg->line_outs; i++) {
3438 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3439 spec->detect_line = 1;
3440 break;
3441 }
3442 }
3443 spec->automute_lines = spec->detect_line;
3444 }
3445
Takashi Iwaif2e57312010-09-15 10:07:08 +02003446 spec->vmaster_nid = spec->private_dac_nids[0];
3447}
3448
Takashi Iwaida339862011-05-13 16:24:15 +02003449static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3450 hda_nid_t *pins, bool on);
3451
Takashi Iwai03697e22011-05-17 09:53:31 +02003452static void do_automute(struct hda_codec *codec, int num_pins,
3453 hda_nid_t *pins, bool on)
3454{
3455 int i;
3456 for (i = 0; i < num_pins; i++)
3457 snd_hda_codec_write(codec, pins[i], 0,
3458 AC_VERB_SET_PIN_WIDGET_CONTROL,
3459 on ? PIN_OUT : 0);
3460 cx_auto_turn_eapd(codec, num_pins, pins, on);
3461}
3462
3463static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3464{
3465 int i, present = 0;
3466
3467 for (i = 0; i < num_pins; i++) {
3468 hda_nid_t nid = pins[i];
3469 if (!nid || !is_jack_detectable(codec, nid))
3470 break;
3471 snd_hda_input_jack_report(codec, nid);
3472 present |= snd_hda_jack_detect(codec, nid);
3473 }
3474 return present;
3475}
3476
Takashi Iwaif2e57312010-09-15 10:07:08 +02003477/* auto-mute/unmute speaker and line outs according to headphone jack */
Takashi Iwai03697e22011-05-17 09:53:31 +02003478static void cx_auto_update_speakers(struct hda_codec *codec)
3479{
3480 struct conexant_spec *spec = codec->spec;
3481 struct auto_pin_cfg *cfg = &spec->autocfg;
3482 int on;
3483
3484 if (!spec->auto_mute)
3485 on = 0;
3486 else
3487 on = spec->hp_present | spec->line_present;
3488 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3489 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, !on);
3490
3491 /* toggle line-out mutes if needed, too */
3492 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3493 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3494 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3495 return;
3496 if (!spec->automute_lines || !spec->auto_mute)
3497 on = 0;
3498 else
3499 on = spec->hp_present;
3500 do_automute(codec, cfg->line_outs, cfg->line_out_pins, !on);
3501}
3502
Takashi Iwaif2e57312010-09-15 10:07:08 +02003503static void cx_auto_hp_automute(struct hda_codec *codec)
3504{
3505 struct conexant_spec *spec = codec->spec;
3506 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003507
3508 if (!spec->auto_mute)
3509 return;
Takashi Iwai03697e22011-05-17 09:53:31 +02003510 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3511 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003512}
3513
Takashi Iwai03697e22011-05-17 09:53:31 +02003514static void cx_auto_line_automute(struct hda_codec *codec)
3515{
3516 struct conexant_spec *spec = codec->spec;
3517 struct auto_pin_cfg *cfg = &spec->autocfg;
3518
3519 if (!spec->auto_mute || !spec->detect_line)
3520 return;
3521 spec->line_present = detect_jacks(codec, cfg->line_outs,
3522 cfg->line_out_pins);
3523 cx_auto_update_speakers(codec);
3524}
3525
3526static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3527 struct snd_ctl_elem_info *uinfo)
3528{
3529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3530 struct conexant_spec *spec = codec->spec;
3531 static const char * const texts2[] = {
3532 "Disabled", "Enabled"
3533 };
3534 static const char * const texts3[] = {
3535 "Disabled", "Speaker Only", "Line-Out+Speaker"
3536 };
3537 const char * const *texts;
3538
3539 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3540 uinfo->count = 1;
3541 if (spec->automute_hp_lo) {
3542 uinfo->value.enumerated.items = 3;
3543 texts = texts3;
3544 } else {
3545 uinfo->value.enumerated.items = 2;
3546 texts = texts2;
3547 }
3548 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3549 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3550 strcpy(uinfo->value.enumerated.name,
3551 texts[uinfo->value.enumerated.item]);
3552 return 0;
3553}
3554
3555static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3556 struct snd_ctl_elem_value *ucontrol)
3557{
3558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3559 struct conexant_spec *spec = codec->spec;
3560 unsigned int val;
3561 if (!spec->auto_mute)
3562 val = 0;
3563 else if (!spec->automute_lines)
3564 val = 1;
3565 else
3566 val = 2;
3567 ucontrol->value.enumerated.item[0] = val;
3568 return 0;
3569}
3570
3571static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3572 struct snd_ctl_elem_value *ucontrol)
3573{
3574 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3575 struct conexant_spec *spec = codec->spec;
3576
3577 switch (ucontrol->value.enumerated.item[0]) {
3578 case 0:
3579 if (!spec->auto_mute)
3580 return 0;
3581 spec->auto_mute = 0;
3582 break;
3583 case 1:
3584 if (spec->auto_mute && !spec->automute_lines)
3585 return 0;
3586 spec->auto_mute = 1;
3587 spec->automute_lines = 0;
3588 break;
3589 case 2:
3590 if (!spec->automute_hp_lo)
3591 return -EINVAL;
3592 if (spec->auto_mute && spec->automute_lines)
3593 return 0;
3594 spec->auto_mute = 1;
3595 spec->automute_lines = 1;
3596 break;
3597 default:
3598 return -EINVAL;
3599 }
3600 cx_auto_update_speakers(codec);
3601 return 1;
3602}
3603
3604static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3605 {
3606 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3607 .name = "Auto-Mute Mode",
3608 .info = cx_automute_mode_info,
3609 .get = cx_automute_mode_get,
3610 .put = cx_automute_mode_put,
3611 },
3612 { }
3613};
3614
Takashi Iwai6764bce2011-05-13 16:52:25 +02003615static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3616 struct snd_ctl_elem_info *uinfo)
3617{
3618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3619 struct conexant_spec *spec = codec->spec;
3620
3621 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3622}
3623
3624static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3625 struct snd_ctl_elem_value *ucontrol)
3626{
3627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3628 struct conexant_spec *spec = codec->spec;
3629
3630 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3631 return 0;
3632}
3633
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003634/* look for the route the given pin from mux and return the index;
3635 * if do_select is set, actually select the route.
3636 */
3637static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003638 hda_nid_t pin, hda_nid_t *srcp,
3639 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003640{
3641 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3642 int i, nums;
3643
Takashi Iwaicf27f292011-05-16 11:33:02 +02003644 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3645 case AC_WID_AUD_IN:
3646 case AC_WID_AUD_SEL:
3647 case AC_WID_AUD_MIX:
3648 break;
3649 default:
3650 return -1;
3651 }
3652
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003653 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3654 for (i = 0; i < nums; i++)
3655 if (conn[i] == pin) {
3656 if (do_select)
3657 snd_hda_codec_write(codec, mux, 0,
3658 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003659 if (srcp)
3660 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003661 return i;
3662 }
3663 depth++;
3664 if (depth == 2)
3665 return -1;
3666 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003667 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003668 do_select, depth);
3669 if (ret >= 0) {
3670 if (do_select)
3671 snd_hda_codec_write(codec, mux, 0,
3672 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003673 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003674 }
3675 }
3676 return -1;
3677}
3678
3679static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3680 hda_nid_t pin)
3681{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003682 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003683}
3684
3685static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3686 hda_nid_t pin)
3687{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003688 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003689}
3690
Takashi Iwai6764bce2011-05-13 16:52:25 +02003691static int cx_auto_mux_enum_update(struct hda_codec *codec,
3692 const struct hda_input_mux *imux,
3693 unsigned int idx)
3694{
3695 struct conexant_spec *spec = codec->spec;
3696 hda_nid_t adc;
3697
3698 if (!imux->num_items)
3699 return 0;
3700 if (idx >= imux->num_items)
3701 idx = imux->num_items - 1;
3702 if (spec->cur_mux[0] == idx)
3703 return 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003704 adc = spec->imux_info[idx].adc;
3705 select_input_connection(codec, spec->imux_info[idx].adc,
3706 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003707 if (spec->cur_adc && spec->cur_adc != adc) {
3708 /* stream is running, let's swap the current ADC */
3709 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3710 spec->cur_adc = adc;
3711 snd_hda_codec_setup_stream(codec, adc,
3712 spec->cur_adc_stream_tag, 0,
3713 spec->cur_adc_format);
3714 }
3715 spec->cur_mux[0] = idx;
3716 return 1;
3717}
3718
3719static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3720 struct snd_ctl_elem_value *ucontrol)
3721{
3722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3723 struct conexant_spec *spec = codec->spec;
3724
3725 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3726 ucontrol->value.enumerated.item[0]);
3727}
3728
3729static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3730 {
3731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3732 .name = "Capture Source",
3733 .info = cx_auto_mux_enum_info,
3734 .get = cx_auto_mux_enum_get,
3735 .put = cx_auto_mux_enum_put
3736 },
3737 {}
3738};
3739
Takashi Iwaif2e57312010-09-15 10:07:08 +02003740/* automatic switch internal and external mic */
3741static void cx_auto_automic(struct hda_codec *codec)
3742{
3743 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003744 int ext_idx = spec->auto_mic_ext;
3745
3746 if (!spec->auto_mic)
3747 return;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003748 if (snd_hda_jack_detect(codec, spec->imux_info[ext_idx].pin))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003749 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3750 else
3751 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003752}
3753
3754static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3755{
3756 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3757 switch (res >> 26) {
3758 case CONEXANT_HP_EVENT:
3759 cx_auto_hp_automute(codec);
Takashi Iwai03697e22011-05-17 09:53:31 +02003760 break;
3761 case CONEXANT_LINE_EVENT:
3762 cx_auto_line_automute(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003763 break;
3764 case CONEXANT_MIC_EVENT:
3765 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003766 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003767 break;
3768 }
3769}
3770
Takashi Iwaif2e57312010-09-15 10:07:08 +02003771/* return true if it's an internal-mic pin */
3772static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3773{
3774 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3775 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003776 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003777}
3778
3779/* return true if it's an external-mic pin */
3780static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3781{
3782 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3783 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003784 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
Takashi Iwai03697e22011-05-17 09:53:31 +02003785 is_jack_detectable(codec, pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003786}
3787
3788/* check whether the pin config is suitable for auto-mic switching;
3789 * auto-mic is enabled only when one int-mic and one-ext mic exist
3790 */
3791static void cx_auto_check_auto_mic(struct hda_codec *codec)
3792{
3793 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003794
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003795 if (is_ext_mic(codec, spec->imux_info[0].pin) &&
3796 is_int_mic(codec, spec->imux_info[1].pin)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003797 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003798 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003799 return;
3800 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003801 if (is_int_mic(codec, spec->imux_info[0].pin) &&
3802 is_ext_mic(codec, spec->imux_info[1].pin)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003803 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003804 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003805 return;
3806 }
3807}
3808
3809static void cx_auto_parse_input(struct hda_codec *codec)
3810{
3811 struct conexant_spec *spec = codec->spec;
3812 struct auto_pin_cfg *cfg = &spec->autocfg;
3813 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003814 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003815
3816 imux = &spec->private_imux;
3817 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003818 for (j = 0; j < spec->num_adc_nids; j++) {
3819 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003820 int idx = get_input_connection(codec, adc,
3821 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003822 if (idx >= 0) {
3823 const char *label;
3824 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003825 spec->imux_info[imux->num_items].index = i;
3826 spec->imux_info[imux->num_items].boost = 0;
3827 spec->imux_info[imux->num_items].adc = adc;
3828 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003829 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003830 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003831 break;
3832 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003833 }
3834 }
3835 if (imux->num_items == 2 && cfg->num_inputs == 2)
3836 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003837 if (imux->num_items > 1 && !spec->auto_mic) {
3838 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003839 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003840 spec->adc_switching = 1;
3841 break;
3842 }
3843 }
3844 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003845}
3846
3847/* get digital-input audio widget corresponding to the given pin */
3848static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3849{
3850 hda_nid_t nid, end_nid;
3851
3852 end_nid = codec->start_nid + codec->num_nodes;
3853 for (nid = codec->start_nid; nid < end_nid; nid++) {
3854 unsigned int wcaps = get_wcaps(codec, nid);
3855 unsigned int type = get_wcaps_type(wcaps);
3856 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3857 if (get_connection_index(codec, nid, pin) >= 0)
3858 return nid;
3859 }
3860 }
3861 return 0;
3862}
3863
3864static void cx_auto_parse_digital(struct hda_codec *codec)
3865{
3866 struct conexant_spec *spec = codec->spec;
3867 struct auto_pin_cfg *cfg = &spec->autocfg;
3868 hda_nid_t nid;
3869
3870 if (cfg->dig_outs &&
3871 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3872 spec->multiout.dig_out_nid = nid;
3873 if (cfg->dig_in_pin)
3874 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3875}
3876
3877#ifdef CONFIG_SND_HDA_INPUT_BEEP
3878static void cx_auto_parse_beep(struct hda_codec *codec)
3879{
3880 struct conexant_spec *spec = codec->spec;
3881 hda_nid_t nid, end_nid;
3882
3883 end_nid = codec->start_nid + codec->num_nodes;
3884 for (nid = codec->start_nid; nid < end_nid; nid++)
3885 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3886 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3887 break;
3888 }
3889}
3890#else
3891#define cx_auto_parse_beep(codec)
3892#endif
3893
3894static int cx_auto_parse_auto_config(struct hda_codec *codec)
3895{
3896 struct conexant_spec *spec = codec->spec;
3897 int err;
3898
3899 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3900 if (err < 0)
3901 return err;
3902
3903 cx_auto_parse_output(codec);
3904 cx_auto_parse_input(codec);
3905 cx_auto_parse_digital(codec);
3906 cx_auto_parse_beep(codec);
3907 return 0;
3908}
3909
Takashi Iwaida339862011-05-13 16:24:15 +02003910static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3911 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003912{
3913 int i;
3914 for (i = 0; i < num_pins; i++) {
3915 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3916 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003917 AC_VERB_SET_EAPD_BTLENABLE,
3918 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003919 }
3920}
3921
3922static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3923 hda_nid_t src)
3924{
3925 int idx = get_connection_index(codec, pin, src);
3926 if (idx >= 0)
3927 snd_hda_codec_write(codec, pin, 0,
3928 AC_VERB_SET_CONNECT_SEL, idx);
3929}
3930
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003931static void mute_outputs(struct hda_codec *codec, int num_nids,
3932 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003933{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003934 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003935
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003936 for (i = 0; i < num_nids; i++) {
3937 hda_nid_t nid = nids[i];
3938 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3939 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003940 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3941 val = AMP_OUT_MUTE;
3942 else
3943 val = AMP_OUT_ZERO;
3944 snd_hda_codec_write(codec, nid, 0,
3945 AC_VERB_SET_AMP_GAIN_MUTE, val);
3946 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003947}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003948
Takashi Iwai03697e22011-05-17 09:53:31 +02003949static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3950 hda_nid_t *pins, unsigned int tag)
3951{
3952 int i;
3953 for (i = 0; i < num_pins; i++)
3954 snd_hda_codec_write(codec, pins[i], 0,
3955 AC_VERB_SET_UNSOLICITED_ENABLE,
3956 AC_USRSP_EN | tag);
3957}
3958
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003959static void cx_auto_init_output(struct hda_codec *codec)
3960{
3961 struct conexant_spec *spec = codec->spec;
3962 struct auto_pin_cfg *cfg = &spec->autocfg;
3963 hda_nid_t nid;
3964 int i;
3965
3966 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003967 for (i = 0; i < cfg->hp_outs; i++)
3968 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3969 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003970 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3971 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3972 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003973 for (i = 0; i < spec->dac_info_filled; i++) {
3974 nid = spec->dac_info[i].dac;
3975 if (!nid)
3976 nid = spec->multiout.dac_nids[0];
3977 select_connection(codec, spec->dac_info[i].pin, nid);
3978 }
Takashi Iwai03697e22011-05-17 09:53:31 +02003979 if (spec->auto_mute) {
3980 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3981 CONEXANT_HP_EVENT);
3982 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3983 cfg->hp_pins);
3984 if (spec->detect_line) {
3985 enable_unsol_pins(codec, cfg->line_outs,
3986 cfg->line_out_pins,
3987 CONEXANT_LINE_EVENT);
3988 spec->line_present =
3989 detect_jacks(codec, cfg->line_outs,
3990 cfg->line_out_pins);
3991 }
3992 }
3993 cx_auto_update_speakers(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003994}
3995
3996static void cx_auto_init_input(struct hda_codec *codec)
3997{
3998 struct conexant_spec *spec = codec->spec;
3999 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004000 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004001
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004002 for (i = 0; i < spec->num_adc_nids; i++) {
4003 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004004 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4005 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02004006 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4007 val = AMP_IN_MUTE(0);
4008 else
4009 val = AMP_IN_UNMUTE(0);
4010 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4011 val);
4012 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004013
4014 for (i = 0; i < cfg->num_inputs; i++) {
4015 unsigned int type;
4016 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4017 type = PIN_VREF80;
4018 else
4019 type = PIN_IN;
4020 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4021 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4022 }
4023
4024 if (spec->auto_mic) {
4025 int ext_idx = spec->auto_mic_ext;
4026 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
4027 AC_VERB_SET_UNSOLICITED_ENABLE,
4028 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4029 cx_auto_automic(codec);
4030 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004031 select_input_connection(codec, spec->imux_info[0].adc,
4032 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004033 }
4034}
4035
4036static void cx_auto_init_digital(struct hda_codec *codec)
4037{
4038 struct conexant_spec *spec = codec->spec;
4039 struct auto_pin_cfg *cfg = &spec->autocfg;
4040
4041 if (spec->multiout.dig_out_nid)
4042 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4043 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4044 if (spec->dig_in_nid)
4045 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4046 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4047}
4048
4049static int cx_auto_init(struct hda_codec *codec)
4050{
4051 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4052 cx_auto_init_output(codec);
4053 cx_auto_init_input(codec);
4054 cx_auto_init_digital(codec);
4055 return 0;
4056}
4057
David Henningsson983345e2011-02-15 19:57:09 +01004058static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02004059 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01004060 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02004061{
4062 static char name[32];
4063 static struct snd_kcontrol_new knew[] = {
4064 HDA_CODEC_VOLUME(name, 0, 0, 0),
4065 HDA_CODEC_MUTE(name, 0, 0, 0),
4066 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004067 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004068 int i, err;
4069
4070 for (i = 0; i < 2; i++) {
4071 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01004072 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4073 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004074 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4075 knew[i].index = cidx;
4076 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4077 kctl = snd_ctl_new1(&knew[i], codec);
4078 if (!kctl)
4079 return -ENOMEM;
4080 err = snd_hda_ctl_add(codec, nid, kctl);
4081 if (err < 0)
4082 return err;
4083 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4084 break;
4085 }
4086 return 0;
4087}
4088
David Henningsson983345e2011-02-15 19:57:09 +01004089#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4090 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4091
Takashi Iwaif2e57312010-09-15 10:07:08 +02004092#define cx_auto_add_pb_volume(codec, nid, str, idx) \
4093 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4094
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004095static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4096 hda_nid_t pin, const char *name, int idx)
4097{
4098 unsigned int caps;
4099 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4100 if (caps & AC_AMPCAP_NUM_STEPS)
4101 return cx_auto_add_pb_volume(codec, dac, name, idx);
4102 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4103 if (caps & AC_AMPCAP_NUM_STEPS)
4104 return cx_auto_add_pb_volume(codec, pin, name, idx);
4105 return 0;
4106}
4107
Takashi Iwaif2e57312010-09-15 10:07:08 +02004108static int cx_auto_build_output_controls(struct hda_codec *codec)
4109{
4110 struct conexant_spec *spec = codec->spec;
4111 int i, err;
4112 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01004113 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02004114
4115 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004116 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4117 spec->dac_info[0].pin,
4118 "Master", 0);
4119
Takashi Iwaif2e57312010-09-15 10:07:08 +02004120 for (i = 0; i < spec->dac_info_filled; i++) {
4121 const char *label;
4122 int idx, type;
4123 if (!spec->dac_info[i].dac)
4124 continue;
4125 type = spec->dac_info[i].type;
4126 if (type == AUTO_PIN_LINE_OUT)
4127 type = spec->autocfg.line_out_type;
4128 switch (type) {
4129 case AUTO_PIN_LINE_OUT:
4130 default:
4131 label = texts[num_line++];
4132 idx = 0;
4133 break;
4134 case AUTO_PIN_HP_OUT:
4135 label = "Headphone";
4136 idx = num_hp++;
4137 break;
4138 case AUTO_PIN_SPEAKER_OUT:
4139 label = "Speaker";
4140 idx = num_spk++;
4141 break;
4142 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004143 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
4144 spec->dac_info[i].pin,
4145 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004146 if (err < 0)
4147 return err;
4148 }
Takashi Iwai03697e22011-05-17 09:53:31 +02004149
4150 if (spec->auto_mute) {
4151 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4152 if (err < 0)
4153 return err;
4154 }
4155
Takashi Iwaif2e57312010-09-15 10:07:08 +02004156 return 0;
4157}
4158
Takashi Iwai6764bce2011-05-13 16:52:25 +02004159static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4160 const char *label, const char *pfx,
4161 int cidx)
4162{
4163 struct conexant_spec *spec = codec->spec;
4164 int i;
4165
4166 for (i = 0; i < spec->num_adc_nids; i++) {
4167 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004168 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004169 if (idx < 0)
4170 continue;
4171 return cx_auto_add_volume_idx(codec, label, pfx,
4172 cidx, adc_nid, HDA_INPUT, idx);
4173 }
4174 return 0;
4175}
4176
Takashi Iwaicf27f292011-05-16 11:33:02 +02004177static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4178 const char *label, int cidx)
4179{
4180 struct conexant_spec *spec = codec->spec;
4181 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004182 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004183
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004184 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004185 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4186 return cx_auto_add_volume(codec, label, " Boost", cidx,
4187 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004188 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4189 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004190 if (con < 0)
4191 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004192 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004193 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004194 return 0; /* already present */
4195 }
4196
4197 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004198 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004199 return cx_auto_add_volume(codec, label, " Boost", 0,
4200 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004201 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004202 return 0;
4203}
4204
Takashi Iwaif2e57312010-09-15 10:07:08 +02004205static int cx_auto_build_input_controls(struct hda_codec *codec)
4206{
4207 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004208 struct hda_input_mux *imux = &spec->private_imux;
4209 const char *prev_label;
4210 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004211 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004212 int multi_connection;
4213
4214 multi_connection = 0;
4215 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004216 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4217 spec->imux_info[i].pin);
4218 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004219 if (i > 0 && input_conn[i] != input_conn[0])
4220 multi_connection = 1;
4221 }
David Henningsson983345e2011-02-15 19:57:09 +01004222
Takashi Iwaif2e57312010-09-15 10:07:08 +02004223 prev_label = NULL;
4224 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004225 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004226 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004227 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004228
Takashi Iwaicf27f292011-05-16 11:33:02 +02004229 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004230 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004231 if (label == prev_label)
4232 cidx++;
4233 else
4234 cidx = 0;
4235 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004236
Takashi Iwaicf27f292011-05-16 11:33:02 +02004237 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4238 if (err < 0)
4239 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004240
Takashi Iwaicf27f292011-05-16 11:33:02 +02004241 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004242 if (i > 0)
4243 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004244 err = cx_auto_add_capture_volume(codec, nid,
4245 "Capture", "", cidx);
4246 } else {
4247 err = cx_auto_add_capture_volume(codec, nid,
4248 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004249 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004250 if (err < 0)
4251 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004252 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004253
4254 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4255 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4256 if (err < 0)
4257 return err;
4258 }
4259
Takashi Iwaif2e57312010-09-15 10:07:08 +02004260 return 0;
4261}
4262
4263static int cx_auto_build_controls(struct hda_codec *codec)
4264{
4265 int err;
4266
4267 err = cx_auto_build_output_controls(codec);
4268 if (err < 0)
4269 return err;
4270 err = cx_auto_build_input_controls(codec);
4271 if (err < 0)
4272 return err;
4273 return conexant_build_controls(codec);
4274}
4275
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004276static int cx_auto_search_adcs(struct hda_codec *codec)
4277{
4278 struct conexant_spec *spec = codec->spec;
4279 hda_nid_t nid, end_nid;
4280
4281 end_nid = codec->start_nid + codec->num_nodes;
4282 for (nid = codec->start_nid; nid < end_nid; nid++) {
4283 unsigned int caps = get_wcaps(codec, nid);
4284 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4285 continue;
4286 if (caps & AC_WCAP_DIGITAL)
4287 continue;
4288 if (snd_BUG_ON(spec->num_adc_nids >=
4289 ARRAY_SIZE(spec->private_adc_nids)))
4290 break;
4291 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4292 }
4293 spec->adc_nids = spec->private_adc_nids;
4294 return 0;
4295}
4296
4297
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004298static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004299 .build_controls = cx_auto_build_controls,
4300 .build_pcms = conexant_build_pcms,
4301 .init = cx_auto_init,
4302 .free = conexant_free,
4303 .unsol_event = cx_auto_unsol_event,
4304#ifdef CONFIG_SND_HDA_POWER_SAVE
4305 .suspend = conexant_suspend,
4306#endif
4307 .reboot_notify = snd_hda_shutup_pins,
4308};
4309
4310static int patch_conexant_auto(struct hda_codec *codec)
4311{
4312 struct conexant_spec *spec;
4313 int err;
4314
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004315 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4316 codec->chip_name);
4317
Takashi Iwaif2e57312010-09-15 10:07:08 +02004318 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4319 if (!spec)
4320 return -ENOMEM;
4321 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004322 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004323 err = cx_auto_search_adcs(codec);
4324 if (err < 0)
4325 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004326 err = cx_auto_parse_auto_config(codec);
4327 if (err < 0) {
4328 kfree(codec->spec);
4329 codec->spec = NULL;
4330 return err;
4331 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004332 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004333 codec->patch_ops = cx_auto_patch_ops;
4334 if (spec->beep_amp)
4335 snd_hda_attach_beep_device(codec, spec->beep_amp);
4336 return 0;
4337}
4338
4339/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004340 */
4341
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004342static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004343 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4344 .patch = patch_cxt5045 },
4345 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4346 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004347 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4348 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004349 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4350 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004351 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4352 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004353 { .id = 0x14f15068, .name = "CX20584",
4354 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004355 { .id = 0x14f15069, .name = "CX20585",
4356 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004357 { .id = 0x14f1506e, .name = "CX20590",
4358 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004359 { .id = 0x14f15097, .name = "CX20631",
4360 .patch = patch_conexant_auto },
4361 { .id = 0x14f15098, .name = "CX20632",
4362 .patch = patch_conexant_auto },
4363 { .id = 0x14f150a1, .name = "CX20641",
4364 .patch = patch_conexant_auto },
4365 { .id = 0x14f150a2, .name = "CX20642",
4366 .patch = patch_conexant_auto },
4367 { .id = 0x14f150ab, .name = "CX20651",
4368 .patch = patch_conexant_auto },
4369 { .id = 0x14f150ac, .name = "CX20652",
4370 .patch = patch_conexant_auto },
4371 { .id = 0x14f150b8, .name = "CX20664",
4372 .patch = patch_conexant_auto },
4373 { .id = 0x14f150b9, .name = "CX20665",
4374 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004375 {} /* terminator */
4376};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004377
4378MODULE_ALIAS("snd-hda-codec-id:14f15045");
4379MODULE_ALIAS("snd-hda-codec-id:14f15047");
4380MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004381MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004382MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004383MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004384MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004385MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004386MODULE_ALIAS("snd-hda-codec-id:14f15097");
4387MODULE_ALIAS("snd-hda-codec-id:14f15098");
4388MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4389MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4390MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4391MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4392MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4393MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004394
4395MODULE_LICENSE("GPL");
4396MODULE_DESCRIPTION("Conexant HD-audio codec");
4397
4398static struct hda_codec_preset_list conexant_list = {
4399 .preset = snd_hda_preset_conexant,
4400 .owner = THIS_MODULE,
4401};
4402
4403static int __init patch_conexant_init(void)
4404{
4405 return snd_hda_add_codec_preset(&conexant_list);
4406}
4407
4408static void __exit patch_conexant_exit(void)
4409{
4410 snd_hda_delete_codec_preset(&conexant_list);
4411}
4412
4413module_init(patch_conexant_init)
4414module_exit(patch_conexant_exit)