blob: 6c9abee9ce82060d180a194dd8ad791804608589 [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
42
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010043/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010045#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046#define CXT5051_PORTB_EVENT 0x38
47#define CXT5051_PORTC_EVENT 0x39
48
Takashi Iwaifaddaa52010-01-23 22:31:36 +010049#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051
Takashi Iwaif2e57312010-09-15 10:07:08 +020052struct pin_dac_pair {
53 hda_nid_t pin;
54 hda_nid_t dac;
55 int type;
56};
57
Tobin Davisc9b443d2006-11-14 12:13:39 +010058struct conexant_spec {
59
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020060 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010061 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010062 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010063
64 const struct hda_verb *init_verbs[5]; /* initialization verbs
65 * don't forget NULL
66 * termination!
67 */
68 unsigned int num_init_verbs;
69
70 /* playback */
71 struct hda_multi_out multiout; /* playback set-up
72 * max_channels, dacs must be set
73 * dig_out_nid and hp_nid are optional
74 */
75 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010076 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010077 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020078 int auto_mic_ext; /* imux_pins[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010079 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050080 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010081
82 /* capture */
83 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020084 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010085 hda_nid_t dig_in_nid; /* digital-in NID; optional */
86
Takashi Iwai461e2c72008-01-25 11:35:17 +010087 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
91
Takashi Iwai6764bce2011-05-13 16:52:25 +020092 const struct hda_pcm_stream *capture_stream;
93
Tobin Davisc9b443d2006-11-14 12:13:39 +010094 /* capture source */
95 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020096 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010097 unsigned int cur_mux[3];
98
99 /* channel model */
100 const struct hda_channel_mode *channel_mode;
101 int num_channel_mode;
102
103 /* PCM information */
104 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
105
Tobin Davisc9b443d2006-11-14 12:13:39 +0100106 unsigned int spdif_route;
107
108 /* dynamic controls, init_verbs and input_mux */
109 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100110 struct hda_input_mux private_imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200111 hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS];
Takashi Iwaif6100bb2011-05-13 18:26:39 +0200112 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200113 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200114 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200115 struct pin_dac_pair dac_info[8];
116 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100117
Daniel Drake0fb67e92009-07-16 14:46:57 +0100118 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200119 unsigned int auto_mute:1; /* used in auto-parser */
120 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500121 unsigned int dell_vostro:1;
122 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200123 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200124 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100125 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100126
Takashi Iwai6764bce2011-05-13 16:52:25 +0200127 unsigned int adc_switching:1;
128
Daniel Drake75f89912010-01-07 13:46:25 +0100129 unsigned int ext_mic_present;
130 unsigned int recording;
131 void (*capture_prepare)(struct hda_codec *codec);
132 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100133
134 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
135 * through the microphone jack.
136 * When the user enables this through a mixer switch, both internal and
137 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
138 * we also allow the bias to be configured through a separate mixer
139 * control. */
140 unsigned int dc_enable;
141 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
142 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200143
144 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100145};
146
147static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
148 struct hda_codec *codec,
149 struct snd_pcm_substream *substream)
150{
151 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100152 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
153 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100154}
155
156static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 unsigned int stream_tag,
159 unsigned int format,
160 struct snd_pcm_substream *substream)
161{
162 struct conexant_spec *spec = codec->spec;
163 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
164 stream_tag,
165 format, substream);
166}
167
168static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
170 struct snd_pcm_substream *substream)
171{
172 struct conexant_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
174}
175
176/*
177 * Digital out
178 */
179static int conexant_dig_playback_pcm_open(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_dig_open(codec, &spec->multiout);
185}
186
187static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 struct snd_pcm_substream *substream)
190{
191 struct conexant_spec *spec = codec->spec;
192 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
193}
194
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200195static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
196 struct hda_codec *codec,
197 unsigned int stream_tag,
198 unsigned int format,
199 struct snd_pcm_substream *substream)
200{
201 struct conexant_spec *spec = codec->spec;
202 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
203 stream_tag,
204 format, substream);
205}
206
Tobin Davisc9b443d2006-11-14 12:13:39 +0100207/*
208 * Analog capture
209 */
210static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 unsigned int stream_tag,
213 unsigned int format,
214 struct snd_pcm_substream *substream)
215{
216 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100217 if (spec->capture_prepare)
218 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100219 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
220 stream_tag, 0, format);
221 return 0;
222}
223
224static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
225 struct hda_codec *codec,
226 struct snd_pcm_substream *substream)
227{
228 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100229 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100230 if (spec->capture_cleanup)
231 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100232 return 0;
233}
234
235
236
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200237static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100238 .substreams = 1,
239 .channels_min = 2,
240 .channels_max = 2,
241 .nid = 0, /* fill later */
242 .ops = {
243 .open = conexant_playback_pcm_open,
244 .prepare = conexant_playback_pcm_prepare,
245 .cleanup = conexant_playback_pcm_cleanup
246 },
247};
248
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200249static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 2,
253 .nid = 0, /* fill later */
254 .ops = {
255 .prepare = conexant_capture_pcm_prepare,
256 .cleanup = conexant_capture_pcm_cleanup
257 },
258};
259
260
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200261static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100262 .substreams = 1,
263 .channels_min = 2,
264 .channels_max = 2,
265 .nid = 0, /* fill later */
266 .ops = {
267 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200268 .close = conexant_dig_playback_pcm_close,
269 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100270 },
271};
272
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200273static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100274 .substreams = 1,
275 .channels_min = 2,
276 .channels_max = 2,
277 /* NID is set in alc_build_pcms */
278};
279
Takashi Iwai461e2c72008-01-25 11:35:17 +0100280static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
281 struct hda_codec *codec,
282 unsigned int stream_tag,
283 unsigned int format,
284 struct snd_pcm_substream *substream)
285{
286 struct conexant_spec *spec = codec->spec;
287 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
288 spec->cur_adc_stream_tag = stream_tag;
289 spec->cur_adc_format = format;
290 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
291 return 0;
292}
293
294static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
295 struct hda_codec *codec,
296 struct snd_pcm_substream *substream)
297{
298 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100299 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100300 spec->cur_adc = 0;
301 return 0;
302}
303
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200304static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100305 .substreams = 1,
306 .channels_min = 2,
307 .channels_max = 2,
308 .nid = 0, /* fill later */
309 .ops = {
310 .prepare = cx5051_capture_pcm_prepare,
311 .cleanup = cx5051_capture_pcm_cleanup
312 },
313};
314
Tobin Davisc9b443d2006-11-14 12:13:39 +0100315static int conexant_build_pcms(struct hda_codec *codec)
316{
317 struct conexant_spec *spec = codec->spec;
318 struct hda_pcm *info = spec->pcm_rec;
319
320 codec->num_pcms = 1;
321 codec->pcm_info = info;
322
323 info->name = "CONEXANT Analog";
324 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
325 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
326 spec->multiout.max_channels;
327 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
328 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200329 if (spec->capture_stream)
330 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
331 else {
332 if (codec->vendor_id == 0x14f15051)
333 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
334 cx5051_pcm_analog_capture;
335 else {
336 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
337 conexant_pcm_analog_capture;
338 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
339 spec->num_adc_nids;
340 }
341 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100342 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
343
344 if (spec->multiout.dig_out_nid) {
345 info++;
346 codec->num_pcms++;
347 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100348 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
350 conexant_pcm_digital_playback;
351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
352 spec->multiout.dig_out_nid;
353 if (spec->dig_in_nid) {
354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
355 conexant_pcm_digital_capture;
356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
357 spec->dig_in_nid;
358 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500359 if (spec->slave_dig_outs[0])
360 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100361 }
362
363 return 0;
364}
365
366static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
367 struct snd_ctl_elem_info *uinfo)
368{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 struct conexant_spec *spec = codec->spec;
371
372 return snd_hda_input_mux_info(spec->input_mux, uinfo);
373}
374
375static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
376 struct snd_ctl_elem_value *ucontrol)
377{
378 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
379 struct conexant_spec *spec = codec->spec;
380 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
381
382 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
383 return 0;
384}
385
386static int conexant_mux_enum_put(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 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
394 spec->capsrc_nids[adc_idx],
395 &spec->cur_mux[adc_idx]);
396}
397
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100398static int conexant_init_jacks(struct hda_codec *codec)
399{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100400#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100401 struct conexant_spec *spec = codec->spec;
402 int i;
403
404 for (i = 0; i < spec->num_init_verbs; i++) {
405 const struct hda_verb *hv;
406
407 hv = spec->init_verbs[i];
408 while (hv->nid) {
409 int err = 0;
410 switch (hv->param ^ AC_USRSP_EN) {
411 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100412 err = snd_hda_input_jack_add(codec, hv->nid,
413 SND_JACK_HEADPHONE, NULL);
414 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100415 break;
416 case CXT5051_PORTC_EVENT:
417 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100418 err = snd_hda_input_jack_add(codec, hv->nid,
419 SND_JACK_MICROPHONE, NULL);
420 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100421 break;
422 }
423 if (err < 0)
424 return err;
425 ++hv;
426 }
427 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100428#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100429 return 0;
430}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100431
Tobin Davisc9b443d2006-11-14 12:13:39 +0100432static int conexant_init(struct hda_codec *codec)
433{
434 struct conexant_spec *spec = codec->spec;
435 int i;
436
437 for (i = 0; i < spec->num_init_verbs; i++)
438 snd_hda_sequence_write(codec, spec->init_verbs[i]);
439 return 0;
440}
441
442static void conexant_free(struct hda_codec *codec)
443{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100444 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200445 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100446 kfree(codec->spec);
447}
448
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200449static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100450 {
451 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
452 .name = "Capture Source",
453 .info = conexant_mux_enum_info,
454 .get = conexant_mux_enum_get,
455 .put = conexant_mux_enum_put
456 },
457 {}
458};
459
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200460#ifdef CONFIG_SND_HDA_INPUT_BEEP
461/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200462static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200463 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
464 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
465 { } /* end */
466};
467#endif
468
Takashi Iwaiea734962011-01-17 11:29:34 +0100469static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100470 "Headphone Playback Volume",
471 "Speaker Playback Volume",
472 NULL
473};
474
Takashi Iwaiea734962011-01-17 11:29:34 +0100475static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100476 "Headphone Playback Switch",
477 "Speaker Playback Switch",
478 NULL
479};
480
Tobin Davisc9b443d2006-11-14 12:13:39 +0100481static int conexant_build_controls(struct hda_codec *codec)
482{
483 struct conexant_spec *spec = codec->spec;
484 unsigned int i;
485 int err;
486
487 for (i = 0; i < spec->num_mixers; i++) {
488 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
489 if (err < 0)
490 return err;
491 }
492 if (spec->multiout.dig_out_nid) {
493 err = snd_hda_create_spdif_out_ctls(codec,
494 spec->multiout.dig_out_nid);
495 if (err < 0)
496 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100497 err = snd_hda_create_spdif_share_sw(codec,
498 &spec->multiout);
499 if (err < 0)
500 return err;
501 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100502 }
503 if (spec->dig_in_nid) {
504 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
505 if (err < 0)
506 return err;
507 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100508
509 /* if we have no master control, let's create it */
510 if (spec->vmaster_nid &&
511 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
512 unsigned int vmaster_tlv[4];
513 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
514 HDA_OUTPUT, vmaster_tlv);
515 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
516 vmaster_tlv, slave_vols);
517 if (err < 0)
518 return err;
519 }
520 if (spec->vmaster_nid &&
521 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
522 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
523 NULL, slave_sws);
524 if (err < 0)
525 return err;
526 }
527
Takashi Iwaib880c742009-03-10 14:41:05 +0100528 if (spec->input_mux) {
529 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
530 if (err < 0)
531 return err;
532 }
533
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200534#ifdef CONFIG_SND_HDA_INPUT_BEEP
535 /* create beep controls if needed */
536 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200537 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200538 for (knew = cxt_beep_mixer; knew->name; knew++) {
539 struct snd_kcontrol *kctl;
540 kctl = snd_ctl_new1(knew, codec);
541 if (!kctl)
542 return -ENOMEM;
543 kctl->private_value = spec->beep_amp;
544 err = snd_hda_ctl_add(codec, 0, kctl);
545 if (err < 0)
546 return err;
547 }
548 }
549#endif
550
Tobin Davisc9b443d2006-11-14 12:13:39 +0100551 return 0;
552}
553
Takashi Iwai697c3732010-07-30 11:28:02 +0200554#ifdef CONFIG_SND_HDA_POWER_SAVE
555static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
556{
557 snd_hda_shutup_pins(codec);
558 return 0;
559}
560#endif
561
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200562static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100563 .build_controls = conexant_build_controls,
564 .build_pcms = conexant_build_pcms,
565 .init = conexant_init,
566 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200567#ifdef CONFIG_SND_HDA_POWER_SAVE
568 .suspend = conexant_suspend,
569#endif
570 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100571};
572
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200573#ifdef CONFIG_SND_HDA_INPUT_BEEP
574#define set_beep_amp(spec, nid, idx, dir) \
575 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
576#else
577#define set_beep_amp(spec, nid, idx, dir) /* NOP */
578#endif
579
Takashi Iwai6764bce2011-05-13 16:52:25 +0200580static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100581/*
582 * EAPD control
583 * the private value = nid | (invert << 8)
584 */
585
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200586#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587
Tobin Davis82f30042007-02-13 12:45:44 +0100588static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100589 struct snd_ctl_elem_value *ucontrol)
590{
591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
592 struct conexant_spec *spec = codec->spec;
593 int invert = (kcontrol->private_value >> 8) & 1;
594 if (invert)
595 ucontrol->value.integer.value[0] = !spec->cur_eapd;
596 else
597 ucontrol->value.integer.value[0] = spec->cur_eapd;
598 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100599
Tobin Davisc9b443d2006-11-14 12:13:39 +0100600}
601
Tobin Davis82f30042007-02-13 12:45:44 +0100602static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100603 struct snd_ctl_elem_value *ucontrol)
604{
605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct conexant_spec *spec = codec->spec;
607 int invert = (kcontrol->private_value >> 8) & 1;
608 hda_nid_t nid = kcontrol->private_value & 0xff;
609 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100610
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100611 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100612 if (invert)
613 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200614 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100615 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100616
Tobin Davisc9b443d2006-11-14 12:13:39 +0100617 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200618 snd_hda_codec_write_cache(codec, nid,
619 0, AC_VERB_SET_EAPD_BTLENABLE,
620 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100621 return 1;
622}
623
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100624/* controls for test mode */
625#ifdef CONFIG_SND_DEBUG
626
Tobin Davis82f30042007-02-13 12:45:44 +0100627#define CXT_EAPD_SWITCH(xname, nid, mask) \
628 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
629 .info = cxt_eapd_info, \
630 .get = cxt_eapd_get, \
631 .put = cxt_eapd_put, \
632 .private_value = nid | (mask<<16) }
633
634
635
Tobin Davisc9b443d2006-11-14 12:13:39 +0100636static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_info *uinfo)
638{
639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640 struct conexant_spec *spec = codec->spec;
641 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
642 spec->num_channel_mode);
643}
644
645static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_value *ucontrol)
647{
648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
649 struct conexant_spec *spec = codec->spec;
650 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
651 spec->num_channel_mode,
652 spec->multiout.max_channels);
653}
654
655static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
656 struct snd_ctl_elem_value *ucontrol)
657{
658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659 struct conexant_spec *spec = codec->spec;
660 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
661 spec->num_channel_mode,
662 &spec->multiout.max_channels);
663 if (err >= 0 && spec->need_dac_fix)
664 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
665 return err;
666}
667
668#define CXT_PIN_MODE(xname, nid, dir) \
669 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
670 .info = conexant_ch_mode_info, \
671 .get = conexant_ch_mode_get, \
672 .put = conexant_ch_mode_put, \
673 .private_value = nid | (dir<<16) }
674
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100675#endif /* CONFIG_SND_DEBUG */
676
Tobin Davisc9b443d2006-11-14 12:13:39 +0100677/* Conexant 5045 specific */
678
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200679static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
680static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
681static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100682#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100683
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200684static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100685 { 2, NULL },
686};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100687
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200688static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689 .num_items = 2,
690 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100691 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100692 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100693 }
694};
695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200696static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200697 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100698 .items = {
699 { "IntMic", 0x1 },
700 { "ExtMic", 0x2 },
701 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200702 { "CD", 0x4 },
703 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100704 }
705};
706
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200707static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100708 .num_items = 2,
709 .items = {
710 { "ExtMic", 0x1 },
711 { "IntMic", 0x2 },
712 }
713};
714
Tobin Davisc9b443d2006-11-14 12:13:39 +0100715/* turn on/off EAPD (+ mute HP) as a master switch */
716static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
717 struct snd_ctl_elem_value *ucontrol)
718{
719 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
720 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100721 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100722
Tobin Davis82f30042007-02-13 12:45:44 +0100723 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100724 return 0;
725
Tobin Davis82f30042007-02-13 12:45:44 +0100726 /* toggle internal speakers mute depending of presence of
727 * the headphone jack
728 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200729 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
730 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
731 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100732
Takashi Iwai47fd8302007-08-10 17:11:07 +0200733 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
734 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
735 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100736 return 1;
737}
738
739/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200740static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200741 .ops = &snd_hda_bind_vol,
742 .values = {
743 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
744 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
745 0
746 },
747};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100748
Tobin Davis7f296732007-03-12 11:39:01 +0100749/* toggle input of built-in and mic jack appropriately */
750static void cxt5045_hp_automic(struct hda_codec *codec)
751{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200752 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100753 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
754 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
755 {}
756 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200757 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100758 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
759 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
760 {}
761 };
762 unsigned int present;
763
Takashi Iwaid56757a2009-11-18 08:00:14 +0100764 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100765 if (present)
766 snd_hda_sequence_write(codec, mic_jack_on);
767 else
768 snd_hda_sequence_write(codec, mic_jack_off);
769}
770
Tobin Davisc9b443d2006-11-14 12:13:39 +0100771
772/* mute internal speaker if HP is plugged */
773static void cxt5045_hp_automute(struct hda_codec *codec)
774{
Tobin Davis82f30042007-02-13 12:45:44 +0100775 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100776 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100777
Takashi Iwaid56757a2009-11-18 08:00:14 +0100778 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100779
Takashi Iwai47fd8302007-08-10 17:11:07 +0200780 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
781 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
782 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783}
784
785/* unsolicited event for HP jack sensing */
786static void cxt5045_hp_unsol_event(struct hda_codec *codec,
787 unsigned int res)
788{
789 res >>= 26;
790 switch (res) {
791 case CONEXANT_HP_EVENT:
792 cxt5045_hp_automute(codec);
793 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100794 case CONEXANT_MIC_EVENT:
795 cxt5045_hp_automic(codec);
796 break;
797
Tobin Davisc9b443d2006-11-14 12:13:39 +0100798 }
799}
800
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200801static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100802 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
803 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100804 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
805 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200806 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
807 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100808 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
809 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100810 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
811 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200812 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100813 {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100816 .info = cxt_eapd_info,
817 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100819 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100820 },
821
822 {}
823};
824
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200825static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200826 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
827 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
828 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
829 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
830
Jiang Zhe5218c892008-01-17 11:18:41 +0100831 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
832 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
833 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
834 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
835
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200836 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
837 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
838
Jiang Zhe5218c892008-01-17 11:18:41 +0100839 {}
840};
841
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200842static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100843 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
844 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100845 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
846 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100847 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
848 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100849 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
850 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100851 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
852 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100853 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
854 {
855 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
856 .name = "Master Playback Switch",
857 .info = cxt_eapd_info,
858 .get = cxt_eapd_get,
859 .put = cxt5045_hp_master_sw_put,
860 .private_value = 0x10,
861 },
862
863 {}
864};
865
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200866static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200868 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100869 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100870 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200871 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
872 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
873 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
874 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
878 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100880 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100881 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100882 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100883 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
884 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100885 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100886 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100888 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100889 { } /* end */
890};
891
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200892static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100893 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100894 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
895 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
896 /* Line In,HP, Amp */
897 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
898 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
899 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
900 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
901 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
905 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100906 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100907 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
908 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
909 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
910 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100911 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100912 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
913 /* EAPD */
914 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
915 { } /* end */
916};
Tobin Davis7f296732007-03-12 11:39:01 +0100917
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200918static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100919 /* pin sensing on HP jack */
920 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200921 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100922};
923
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200924static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100925 /* pin sensing on HP jack */
926 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200927 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100928};
929
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930#ifdef CONFIG_SND_DEBUG
931/* Test configuration for debugging, modelled after the ALC260 test
932 * configuration.
933 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200934static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100935 .num_items = 5,
936 .items = {
937 { "MIXER", 0x0 },
938 { "MIC1 pin", 0x1 },
939 { "LINE1 pin", 0x2 },
940 { "HP-OUT pin", 0x3 },
941 { "CD pin", 0x4 },
942 },
943};
944
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200945static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946
947 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100948 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
949 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100950 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
951 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
952 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
953 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100954
955 /* Modes for retasking pin widgets */
956 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
957 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
958
Tobin Davis82f30042007-02-13 12:45:44 +0100959 /* EAPD Switch Control */
960 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
961
Tobin Davisc9b443d2006-11-14 12:13:39 +0100962 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100963
Tobin Davis7f296732007-03-12 11:39:01 +0100964 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
965 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
966 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
967 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
968 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
969 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
970 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
971 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
972 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
973 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100974 {
975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
976 .name = "Input Source",
977 .info = conexant_mux_enum_info,
978 .get = conexant_mux_enum_get,
979 .put = conexant_mux_enum_put,
980 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200981 /* Audio input controls */
982 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
983 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
984 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
985 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
986 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
987 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
988 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
989 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
990 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
991 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100992 { } /* end */
993};
994
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200995static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100996 /* Set connections */
997 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
998 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
999 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001000 /* Enable retasking pins as output, initially without power amp */
1001 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001002 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001003
1004 /* Disable digital (SPDIF) pins initially, but users can enable
1005 * them via a mixer switch. In the case of SPDIF-out, this initverb
1006 * payload also sets the generation to 0, output to be in "consumer"
1007 * PCM format, copyright asserted, no pre-emphasis and no validity
1008 * control.
1009 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001010 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1011 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012
1013 /* Start with output sum widgets muted and their output gains at min */
1014 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1016
1017 /* Unmute retasking pin widget output buffers since the default
1018 * state appears to be output. As the pin mode is changed by the
1019 * user the pin mode control will take care of enabling the pin's
1020 * input/output buffers as needed.
1021 */
1022 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1023 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1024
1025 /* Mute capture amp left and right */
1026 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1027
1028 /* Set ADC connection select to match default mixer setting (mic1
1029 * pin)
1030 */
1031 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001032 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033
1034 /* Mute all inputs to mixer widget (even unconnected ones) */
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1037 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1038 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1039 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1040
1041 { }
1042};
1043#endif
1044
1045
1046/* initialize jack-sensing, too */
1047static int cxt5045_init(struct hda_codec *codec)
1048{
1049 conexant_init(codec);
1050 cxt5045_hp_automute(codec);
1051 return 0;
1052}
1053
1054
1055enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001056 CXT5045_LAPTOP_HPSENSE,
1057 CXT5045_LAPTOP_MICSENSE,
1058 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001059 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001060 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001061#ifdef CONFIG_SND_DEBUG
1062 CXT5045_TEST,
1063#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001064 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001065 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001066};
1067
Takashi Iwaiea734962011-01-17 11:29:34 +01001068static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001069 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1070 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1071 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1072 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001073 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001075 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001076#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001077 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001078};
1079
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001080static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001081 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001082 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1083 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001084 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001085 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001086 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1087 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001088 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1089 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001090 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1091 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1092 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001093 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1094 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001095 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001096 {}
1097};
1098
1099static int patch_cxt5045(struct hda_codec *codec)
1100{
1101 struct conexant_spec *spec;
1102 int board_config;
1103
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001104 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1105 cxt5045_models,
1106 cxt5045_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001107#if 0 /* use the old method just for safety */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001108 if (board_config < 0)
1109 board_config = CXT5045_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001110#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001111 if (board_config == CXT5045_AUTO)
1112 return patch_conexant_auto(codec);
1113
Tobin Davisc9b443d2006-11-14 12:13:39 +01001114 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1115 if (!spec)
1116 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001118 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001119
1120 spec->multiout.max_channels = 2;
1121 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1122 spec->multiout.dac_nids = cxt5045_dac_nids;
1123 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1124 spec->num_adc_nids = 1;
1125 spec->adc_nids = cxt5045_adc_nids;
1126 spec->capsrc_nids = cxt5045_capsrc_nids;
1127 spec->input_mux = &cxt5045_capture_source;
1128 spec->num_mixers = 1;
1129 spec->mixers[0] = cxt5045_mixers;
1130 spec->num_init_verbs = 1;
1131 spec->init_verbs[0] = cxt5045_init_verbs;
1132 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001133 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1134 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001135
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001136 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137
1138 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001139
Tobin Davisc9b443d2006-11-14 12:13:39 +01001140 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001141 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001142 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001143 spec->input_mux = &cxt5045_capture_source;
1144 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001145 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1146 spec->mixers[0] = cxt5045_mixers;
1147 codec->patch_ops.init = cxt5045_init;
1148 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001149 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001150 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001151 spec->input_mux = &cxt5045_capture_source;
1152 spec->num_init_verbs = 2;
1153 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001154 spec->mixers[0] = cxt5045_mixers;
1155 codec->patch_ops.init = cxt5045_init;
1156 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001157 default:
1158 case CXT5045_LAPTOP_HPMICSENSE:
1159 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1160 spec->input_mux = &cxt5045_capture_source;
1161 spec->num_init_verbs = 3;
1162 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1163 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1164 spec->mixers[0] = cxt5045_mixers;
1165 codec->patch_ops.init = cxt5045_init;
1166 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001167 case CXT5045_BENQ:
1168 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1169 spec->input_mux = &cxt5045_capture_source_benq;
1170 spec->num_init_verbs = 1;
1171 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1172 spec->mixers[0] = cxt5045_mixers;
1173 spec->mixers[1] = cxt5045_benq_mixers;
1174 spec->num_mixers = 2;
1175 codec->patch_ops.init = cxt5045_init;
1176 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001177 case CXT5045_LAPTOP_HP530:
1178 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1179 spec->input_mux = &cxt5045_capture_source_hp530;
1180 spec->num_init_verbs = 2;
1181 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1182 spec->mixers[0] = cxt5045_mixers_hp530;
1183 codec->patch_ops.init = cxt5045_init;
1184 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185#ifdef CONFIG_SND_DEBUG
1186 case CXT5045_TEST:
1187 spec->input_mux = &cxt5045_test_capture_source;
1188 spec->mixers[0] = cxt5045_test_mixer;
1189 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001190 break;
1191
Tobin Davisc9b443d2006-11-14 12:13:39 +01001192#endif
1193 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001194
Takashi Iwai031005f2008-06-26 14:49:58 +02001195 switch (codec->subsystem_id >> 16) {
1196 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001197 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001198 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001199 case 0x17aa:
1200 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1201 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1202 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001203 */
1204 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1205 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1206 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1207 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1208 (1 << AC_AMPCAP_MUTE_SHIFT));
1209 break;
1210 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001211
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001212 if (spec->beep_amp)
1213 snd_hda_attach_beep_device(codec, spec->beep_amp);
1214
Tobin Davisc9b443d2006-11-14 12:13:39 +01001215 return 0;
1216}
1217
1218
1219/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001220#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001222static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1223static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1224static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001225
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001226static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001227 { 2, NULL },
1228};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001229
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001230static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001231 .num_items = 2,
1232 .items = {
1233 { "ExtMic", 0x2 },
1234 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001235 }
1236};
1237
1238/* turn on/off EAPD (+ mute HP) as a master switch */
1239static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1240 struct snd_ctl_elem_value *ucontrol)
1241{
1242 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1243 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001244 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245
Tobin Davis82f30042007-02-13 12:45:44 +01001246 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247 return 0;
1248
Tobin Davis82f30042007-02-13 12:45:44 +01001249 /* toggle internal speakers mute depending of presence of
1250 * the headphone jack
1251 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001252 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001253 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1254 * pin widgets unlike other codecs. In this case, we need to
1255 * set index 0x01 for the volume from the mixer amp 0x19.
1256 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001257 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001258 HDA_AMP_MUTE, bits);
1259 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1260 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1261 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262 return 1;
1263}
1264
Tobin Davisc9b443d2006-11-14 12:13:39 +01001265/* mute internal speaker if HP is plugged */
1266static void cxt5047_hp_automute(struct hda_codec *codec)
1267{
Tobin Davis82f30042007-02-13 12:45:44 +01001268 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001269 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001270
Takashi Iwaid56757a2009-11-18 08:00:14 +01001271 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001272
Takashi Iwai47fd8302007-08-10 17:11:07 +02001273 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001274 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001275 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001276 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001277}
1278
1279/* toggle input of built-in and mic jack appropriately */
1280static void cxt5047_hp_automic(struct hda_codec *codec)
1281{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001282 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001283 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1284 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 {}
1286 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001287 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001288 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1289 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001290 {}
1291 };
1292 unsigned int present;
1293
Takashi Iwaid56757a2009-11-18 08:00:14 +01001294 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001295 if (present)
1296 snd_hda_sequence_write(codec, mic_jack_on);
1297 else
1298 snd_hda_sequence_write(codec, mic_jack_off);
1299}
1300
1301/* unsolicited event for HP jack sensing */
1302static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1303 unsigned int res)
1304{
Marc Boucher9f113e02008-01-22 15:18:08 +01001305 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001306 case CONEXANT_HP_EVENT:
1307 cxt5047_hp_automute(codec);
1308 break;
1309 case CONEXANT_MIC_EVENT:
1310 cxt5047_hp_automic(codec);
1311 break;
1312 }
1313}
1314
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001315static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001316 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1317 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001318 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001319 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1320 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1321 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1322 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001323 {
1324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1325 .name = "Master Playback Switch",
1326 .info = cxt_eapd_info,
1327 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328 .put = cxt5047_hp_master_sw_put,
1329 .private_value = 0x13,
1330 },
1331
1332 {}
1333};
1334
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001335static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001336 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001337 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001338 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1339 {}
1340};
1341
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001342static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001343 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 { } /* end */
1345};
1346
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001347static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001348 /* Line in, Mic, Built-in Mic */
1349 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1350 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1351 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001352 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001353 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001354 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1355 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001356 /* Record selector: Mic */
1357 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1358 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1359 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1360 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1362 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1363 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001365 /* SPDIF route: PCM */
1366 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001367 /* Enable unsolicited events */
1368 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1369 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370 { } /* end */
1371};
1372
1373/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001374static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001375 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001376 {}
1377};
1378
1379/* Test configuration for debugging, modelled after the ALC260 test
1380 * configuration.
1381 */
1382#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001383static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001384 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001385 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001386 { "LINE1 pin", 0x0 },
1387 { "MIC1 pin", 0x1 },
1388 { "MIC2 pin", 0x2 },
1389 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001390 },
1391};
1392
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001393static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001394
1395 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001396 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1398 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001400 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001404 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1406 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001408
1409 /* Modes for retasking pin widgets */
1410 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1411 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1412
Tobin Davis82f30042007-02-13 12:45:44 +01001413 /* EAPD Switch Control */
1414 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1415
Tobin Davisc9b443d2006-11-14 12:13:39 +01001416 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001417 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1418 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1419 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1420 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1421 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1422 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1423 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1424 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001425
Tobin Davis82f30042007-02-13 12:45:44 +01001426 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1427 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1429 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1430 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1431 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1432 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1433 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001434 {
1435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1436 .name = "Input Source",
1437 .info = conexant_mux_enum_info,
1438 .get = conexant_mux_enum_get,
1439 .put = conexant_mux_enum_put,
1440 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001441 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001442
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443 { } /* end */
1444};
1445
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001446static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001447 /* Enable retasking pins as output, initially without power amp */
1448 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1449 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1450 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1451
1452 /* Disable digital (SPDIF) pins initially, but users can enable
1453 * them via a mixer switch. In the case of SPDIF-out, this initverb
1454 * payload also sets the generation to 0, output to be in "consumer"
1455 * PCM format, copyright asserted, no pre-emphasis and no validity
1456 * control.
1457 */
1458 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1459
1460 /* Ensure mic1, mic2, line1 pin widgets take input from the
1461 * OUT1 sum bus when acting as an output.
1462 */
1463 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1464 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1465
1466 /* Start with output sum widgets muted and their output gains at min */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1469
1470 /* Unmute retasking pin widget output buffers since the default
1471 * state appears to be output. As the pin mode is changed by the
1472 * user the pin mode control will take care of enabling the pin's
1473 * input/output buffers as needed.
1474 */
1475 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1476 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1477 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1478
1479 /* Mute capture amp left and right */
1480 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1481
1482 /* Set ADC connection select to match default mixer setting (mic1
1483 * pin)
1484 */
1485 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1486
1487 /* Mute all inputs to mixer widget (even unconnected ones) */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1492 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1494 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1495 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1496
1497 { }
1498};
1499#endif
1500
1501
1502/* initialize jack-sensing, too */
1503static int cxt5047_hp_init(struct hda_codec *codec)
1504{
1505 conexant_init(codec);
1506 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001507 return 0;
1508}
1509
1510
1511enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001512 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1513 CXT5047_LAPTOP_HP, /* Some HP laptops */
1514 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001515#ifdef CONFIG_SND_DEBUG
1516 CXT5047_TEST,
1517#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001518 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001519 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001520};
1521
Takashi Iwaiea734962011-01-17 11:29:34 +01001522static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001523 [CXT5047_LAPTOP] = "laptop",
1524 [CXT5047_LAPTOP_HP] = "laptop-hp",
1525 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001526#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001527 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001529 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530};
1531
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001532static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001533 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001534 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1535 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001536 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001537 {}
1538};
1539
1540static int patch_cxt5047(struct hda_codec *codec)
1541{
1542 struct conexant_spec *spec;
1543 int board_config;
1544
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001545 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1546 cxt5047_models,
1547 cxt5047_cfg_tbl);
1548#if 0 /* not enabled as default, as BIOS often broken for this codec */
1549 if (board_config < 0)
1550 board_config = CXT5047_AUTO;
1551#endif
1552 if (board_config == CXT5047_AUTO)
1553 return patch_conexant_auto(codec);
1554
Tobin Davisc9b443d2006-11-14 12:13:39 +01001555 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1556 if (!spec)
1557 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001559 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560
1561 spec->multiout.max_channels = 2;
1562 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1563 spec->multiout.dac_nids = cxt5047_dac_nids;
1564 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1565 spec->num_adc_nids = 1;
1566 spec->adc_nids = cxt5047_adc_nids;
1567 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001568 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001569 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 spec->num_init_verbs = 1;
1571 spec->init_verbs[0] = cxt5047_init_verbs;
1572 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001573 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1574 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575
1576 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001577
Tobin Davisc9b443d2006-11-14 12:13:39 +01001578 switch (board_config) {
1579 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001580 spec->num_mixers = 2;
1581 spec->mixers[1] = cxt5047_hp_spk_mixers;
1582 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001583 break;
1584 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001585 spec->num_mixers = 2;
1586 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001587 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001588 codec->patch_ops.init = cxt5047_hp_init;
1589 break;
1590 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001591 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001592 spec->num_mixers = 2;
1593 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594 spec->num_init_verbs = 2;
1595 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001596 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001597 break;
1598#ifdef CONFIG_SND_DEBUG
1599 case CXT5047_TEST:
1600 spec->input_mux = &cxt5047_test_capture_source;
1601 spec->mixers[0] = cxt5047_test_mixer;
1602 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001603 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001604#endif
1605 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001606 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001607
1608 switch (codec->subsystem_id >> 16) {
1609 case 0x103c:
1610 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1611 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1612 * with 0 dB offset 0x17)
1613 */
1614 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1615 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1616 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1617 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1618 (1 << AC_AMPCAP_MUTE_SHIFT));
1619 break;
1620 }
1621
Tobin Davisc9b443d2006-11-14 12:13:39 +01001622 return 0;
1623}
1624
Takashi Iwai461e2c72008-01-25 11:35:17 +01001625/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001626static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1627static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001628
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001629static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001630 { 2, NULL },
1631};
1632
1633static void cxt5051_update_speaker(struct hda_codec *codec)
1634{
1635 struct conexant_spec *spec = codec->spec;
1636 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001637 /* headphone pin */
1638 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1639 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1640 pinctl);
1641 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001642 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1643 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1644 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001645 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1646 if (spec->ideapad)
1647 snd_hda_codec_write(codec, 0x1b, 0,
1648 AC_VERB_SET_PIN_WIDGET_CONTROL,
1649 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001650}
1651
1652/* turn on/off EAPD (+ mute HP) as a master switch */
1653static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1654 struct snd_ctl_elem_value *ucontrol)
1655{
1656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1657
1658 if (!cxt_eapd_put(kcontrol, ucontrol))
1659 return 0;
1660 cxt5051_update_speaker(codec);
1661 return 1;
1662}
1663
1664/* toggle input of built-in and mic jack appropriately */
1665static void cxt5051_portb_automic(struct hda_codec *codec)
1666{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001667 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001668 unsigned int present;
1669
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001670 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001671 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001672 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001673 snd_hda_codec_write(codec, 0x14, 0,
1674 AC_VERB_SET_CONNECT_SEL,
1675 present ? 0x01 : 0x00);
1676}
1677
1678/* switch the current ADC according to the jack state */
1679static void cxt5051_portc_automic(struct hda_codec *codec)
1680{
1681 struct conexant_spec *spec = codec->spec;
1682 unsigned int present;
1683 hda_nid_t new_adc;
1684
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001685 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001686 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001687 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001688 if (present)
1689 spec->cur_adc_idx = 1;
1690 else
1691 spec->cur_adc_idx = 0;
1692 new_adc = spec->adc_nids[spec->cur_adc_idx];
1693 if (spec->cur_adc && spec->cur_adc != new_adc) {
1694 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001695 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001696 spec->cur_adc = new_adc;
1697 snd_hda_codec_setup_stream(codec, new_adc,
1698 spec->cur_adc_stream_tag, 0,
1699 spec->cur_adc_format);
1700 }
1701}
1702
1703/* mute internal speaker if HP is plugged */
1704static void cxt5051_hp_automute(struct hda_codec *codec)
1705{
1706 struct conexant_spec *spec = codec->spec;
1707
Takashi Iwaid56757a2009-11-18 08:00:14 +01001708 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001709 cxt5051_update_speaker(codec);
1710}
1711
1712/* unsolicited event for HP jack sensing */
1713static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1714 unsigned int res)
1715{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001716 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001717 switch (res >> 26) {
1718 case CONEXANT_HP_EVENT:
1719 cxt5051_hp_automute(codec);
1720 break;
1721 case CXT5051_PORTB_EVENT:
1722 cxt5051_portb_automic(codec);
1723 break;
1724 case CXT5051_PORTC_EVENT:
1725 cxt5051_portc_automic(codec);
1726 break;
1727 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001728 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001729}
1730
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001731static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1733 {
1734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1735 .name = "Master Playback Switch",
1736 .info = cxt_eapd_info,
1737 .get = cxt_eapd_get,
1738 .put = cxt5051_hp_master_sw_put,
1739 .private_value = 0x1a,
1740 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001741 {}
1742};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001743
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001744static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001745 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1746 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001747 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1748 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001749 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1750 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001751 {}
1752};
1753
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001754static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001755 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1756 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001757 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1758 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001759 {}
1760};
1761
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001762static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001763 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1764 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001765 {}
1766};
1767
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001768static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001769 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1770 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001771 {}
1772};
1773
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001774static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001775 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1776 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001777 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1778 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001779 {}
1780};
1781
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001782static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001783 /* Line in, Mic */
1784 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1785 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1786 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1787 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1788 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1789 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1790 /* SPK */
1791 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1792 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1793 /* HP, Amp */
1794 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1795 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1796 /* DAC1 */
1797 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001798 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001799 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1801 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1802 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001803 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001804 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1805 /* EAPD */
1806 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1807 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001808 { } /* end */
1809};
1810
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001811static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001812 /* Line in, Mic */
1813 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1814 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1815 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1816 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1817 /* SPK */
1818 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1819 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1820 /* HP, Amp */
1821 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1822 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1823 /* DAC1 */
1824 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001825 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001826 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1827 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1828 /* SPDIF route: PCM */
1829 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1830 /* EAPD */
1831 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1832 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001833 { } /* end */
1834};
1835
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001836static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001837 /* Line in, Mic */
1838 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1839 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1840 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1841 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1842 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1843 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1844 /* SPK */
1845 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1846 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1847 /* HP, Amp */
1848 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1849 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1850 /* Docking HP */
1851 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1852 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1853 /* DAC1 */
1854 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001855 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1857 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1858 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1859 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001860 {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 -05001861 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1862 /* EAPD */
1863 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1864 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001865 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1866 { } /* end */
1867};
1868
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001869static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001870 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001871 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001872 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1873 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1874 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1875 /* SPK */
1876 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1877 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1878 /* HP, Amp */
1879 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1880 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1881 /* DAC1 */
1882 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001883 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001884 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1885 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1886 /* SPDIF route: PCM */
1887 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1888 /* EAPD */
1889 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1890 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001891 { } /* end */
1892};
1893
Takashi Iwai6953e552010-01-24 11:00:27 +01001894static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1895 unsigned int event)
1896{
1897 snd_hda_codec_write(codec, nid, 0,
1898 AC_VERB_SET_UNSOLICITED_ENABLE,
1899 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001900 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1901 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001902}
1903
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001904static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001905 /* Subwoofer */
1906 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1907 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1908 { } /* end */
1909};
1910
Takashi Iwai461e2c72008-01-25 11:35:17 +01001911/* initialize jack-sensing, too */
1912static int cxt5051_init(struct hda_codec *codec)
1913{
Takashi Iwai6953e552010-01-24 11:00:27 +01001914 struct conexant_spec *spec = codec->spec;
1915
Takashi Iwai461e2c72008-01-25 11:35:17 +01001916 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001917 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001918
1919 if (spec->auto_mic & AUTO_MIC_PORTB)
1920 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1921 if (spec->auto_mic & AUTO_MIC_PORTC)
1922 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1923
Takashi Iwai461e2c72008-01-25 11:35:17 +01001924 if (codec->patch_ops.unsol_event) {
1925 cxt5051_hp_automute(codec);
1926 cxt5051_portb_automic(codec);
1927 cxt5051_portc_automic(codec);
1928 }
1929 return 0;
1930}
1931
1932
1933enum {
1934 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1935 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001936 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001937 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001938 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001939 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001940 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001941 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001942 CXT5051_MODELS
1943};
1944
Takashi Iwaiea734962011-01-17 11:29:34 +01001945static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001946 [CXT5051_LAPTOP] = "laptop",
1947 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001948 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001949 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001950 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001951 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001952 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001953 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001954};
1955
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001956static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001957 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001958 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001959 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001960 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001961 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1962 CXT5051_LAPTOP),
1963 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001964 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001965 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966 {}
1967};
1968
1969static int patch_cxt5051(struct hda_codec *codec)
1970{
1971 struct conexant_spec *spec;
1972 int board_config;
1973
Takashi Iwai6764bce2011-05-13 16:52:25 +02001974 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1975 cxt5051_models,
1976 cxt5051_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001977#if 0 /* use the old method just for safety */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001978 if (board_config < 0)
1979 board_config = CXT5051_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001980#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001981 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001982 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001983
Takashi Iwai461e2c72008-01-25 11:35:17 +01001984 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1985 if (!spec)
1986 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001987 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001988 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001989
1990 codec->patch_ops = conexant_patch_ops;
1991 codec->patch_ops.init = cxt5051_init;
1992
1993 spec->multiout.max_channels = 2;
1994 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1995 spec->multiout.dac_nids = cxt5051_dac_nids;
1996 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1997 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1998 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001999 spec->num_mixers = 2;
2000 spec->mixers[0] = cxt5051_capture_mixers;
2001 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002002 spec->num_init_verbs = 1;
2003 spec->init_verbs[0] = cxt5051_init_verbs;
2004 spec->spdif_route = 0;
2005 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2006 spec->channel_mode = cxt5051_modes;
2007 spec->cur_adc = 0;
2008 spec->cur_adc_idx = 0;
2009
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002010 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2011
Takashi Iwai79d7d532009-03-04 09:03:50 +01002012 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2013
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002014 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002015 switch (board_config) {
2016 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002017 spec->mixers[0] = cxt5051_hp_mixers;
2018 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002019 case CXT5051_HP_DV6736:
2020 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2021 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002022 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002023 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002024 case CXT5051_LENOVO_X200:
2025 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002026 /* Thinkpad X301 does not have S/PDIF wired and no ability
2027 to use a docking station. */
2028 if (codec->subsystem_id == 0x17aa211f)
2029 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002030 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002031 case CXT5051_F700:
2032 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2033 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002034 spec->auto_mic = 0;
2035 break;
2036 case CXT5051_TOSHIBA:
2037 spec->mixers[0] = cxt5051_toshiba_mixers;
2038 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002039 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002040 case CXT5051_IDEAPAD:
2041 spec->init_verbs[spec->num_init_verbs++] =
2042 cxt5051_ideapad_init_verbs;
2043 spec->ideapad = 1;
2044 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002045 }
2046
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002047 if (spec->beep_amp)
2048 snd_hda_attach_beep_device(codec, spec->beep_amp);
2049
Takashi Iwai461e2c72008-01-25 11:35:17 +01002050 return 0;
2051}
2052
Daniel Drake0fb67e92009-07-16 14:46:57 +01002053/* Conexant 5066 specific */
2054
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002055static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2056static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2057static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2058static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002059
Daniel Drakedbaccc02009-11-09 15:17:24 +00002060/* OLPC's microphone port is DC coupled for use with external sensors,
2061 * therefore we use a 50% mic bias in order to center the input signal with
2062 * the DC input range of the codec. */
2063#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2064
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002065static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002066 { 2, NULL },
2067};
2068
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002069#define HP_PRESENT_PORT_A (1 << 0)
2070#define HP_PRESENT_PORT_D (1 << 1)
2071#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2072#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2073
Daniel Drake0fb67e92009-07-16 14:46:57 +01002074static void cxt5066_update_speaker(struct hda_codec *codec)
2075{
2076 struct conexant_spec *spec = codec->spec;
2077 unsigned int pinctl;
2078
John Baboval3a253442010-12-02 11:21:31 -05002079 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2080 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002081
2082 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002083 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002084 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2085 pinctl);
2086
2087 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002088 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2089 if (spec->dell_automute || spec->thinkpad) {
2090 /* Mute if Port A is connected */
2091 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002092 pinctl = 0;
2093 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002094 /* Thinkpad/Dell doesn't give pin-D status */
2095 if (!hp_port_d_present(spec))
2096 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002097 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002098 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2099 pinctl);
2100
2101 /* CLASS_D AMP */
2102 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2103 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2104 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002105}
2106
2107/* turn on/off EAPD (+ mute HP) as a master switch */
2108static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2109 struct snd_ctl_elem_value *ucontrol)
2110{
2111 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2112
2113 if (!cxt_eapd_put(kcontrol, ucontrol))
2114 return 0;
2115
2116 cxt5066_update_speaker(codec);
2117 return 1;
2118}
2119
Daniel Drakec4cfe662010-01-07 13:47:04 +01002120static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2121 .num_items = 3,
2122 .items = {
2123 { "Off", PIN_IN },
2124 { "50%", PIN_VREF50 },
2125 { "80%", PIN_VREF80 },
2126 },
2127};
2128
2129static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2130{
2131 struct conexant_spec *spec = codec->spec;
2132 /* Even though port F is the DC input, the bias is controlled on port B.
2133 * we also leave that port as an active input (but unselected) in DC mode
2134 * just in case that is necessary to make the bias setting take effect. */
2135 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2136 AC_VERB_SET_PIN_WIDGET_CONTROL,
2137 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2138}
2139
Daniel Drake75f89912010-01-07 13:46:25 +01002140/* OLPC defers mic widget control until when capture is started because the
2141 * microphone LED comes on as soon as these settings are put in place. if we
2142 * did this before recording, it would give the false indication that recording
2143 * is happening when it is not. */
2144static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002145{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002146 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002147 if (!spec->recording)
2148 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002149
Daniel Drakec4cfe662010-01-07 13:47:04 +01002150 if (spec->dc_enable) {
2151 /* in DC mode we ignore presence detection and just use the jack
2152 * through our special DC port */
2153 const struct hda_verb enable_dc_mode[] = {
2154 /* disble internal mic, port C */
2155 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2156
2157 /* enable DC capture, port F */
2158 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2159 {},
2160 };
2161
2162 snd_hda_sequence_write(codec, enable_dc_mode);
2163 /* port B input disabled (and bias set) through the following call */
2164 cxt5066_set_olpc_dc_bias(codec);
2165 return;
2166 }
2167
2168 /* disable DC (port F) */
2169 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2170
Daniel Drake75f89912010-01-07 13:46:25 +01002171 /* external mic, port B */
2172 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2173 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002174
Daniel Drake75f89912010-01-07 13:46:25 +01002175 /* internal mic, port C */
2176 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2177 spec->ext_mic_present ? 0 : PIN_VREF80);
2178}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002179
Daniel Drake75f89912010-01-07 13:46:25 +01002180/* toggle input of built-in and mic jack appropriately */
2181static void cxt5066_olpc_automic(struct hda_codec *codec)
2182{
2183 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002184 unsigned int present;
2185
Daniel Drakec4cfe662010-01-07 13:47:04 +01002186 if (spec->dc_enable) /* don't do presence detection in DC mode */
2187 return;
2188
Daniel Drake75f89912010-01-07 13:46:25 +01002189 present = snd_hda_codec_read(codec, 0x1a, 0,
2190 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2191 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002192 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002193 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002194 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002195
2196 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2197 present ? 0 : 1);
2198 spec->ext_mic_present = !!present;
2199
2200 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002201}
2202
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002203/* toggle input of built-in digital mic and mic jack appropriately */
2204static void cxt5066_vostro_automic(struct hda_codec *codec)
2205{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002206 unsigned int present;
2207
2208 struct hda_verb ext_mic_present[] = {
2209 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002210 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002211
2212 /* switch to external mic input */
2213 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2214 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2215
2216 /* disable internal digital mic */
2217 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2218 {}
2219 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002220 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002221 /* enable internal mic, port C */
2222 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2223
2224 /* switch to internal mic input */
2225 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2226
2227 /* disable external mic, port B */
2228 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2229 {}
2230 };
2231
2232 present = snd_hda_jack_detect(codec, 0x1a);
2233 if (present) {
2234 snd_printdd("CXT5066: external microphone detected\n");
2235 snd_hda_sequence_write(codec, ext_mic_present);
2236 } else {
2237 snd_printdd("CXT5066: external microphone absent\n");
2238 snd_hda_sequence_write(codec, ext_mic_absent);
2239 }
2240}
2241
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002242/* toggle input of built-in digital mic and mic jack appropriately */
2243static void cxt5066_ideapad_automic(struct hda_codec *codec)
2244{
2245 unsigned int present;
2246
2247 struct hda_verb ext_mic_present[] = {
2248 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2249 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2250 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2251 {}
2252 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002253 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002254 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2255 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2256 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2257 {}
2258 };
2259
2260 present = snd_hda_jack_detect(codec, 0x1b);
2261 if (present) {
2262 snd_printdd("CXT5066: external microphone detected\n");
2263 snd_hda_sequence_write(codec, ext_mic_present);
2264 } else {
2265 snd_printdd("CXT5066: external microphone absent\n");
2266 snd_hda_sequence_write(codec, ext_mic_absent);
2267 }
2268}
2269
David Henningssona1d69062011-01-21 13:33:28 +01002270
2271/* toggle input of built-in digital mic and mic jack appropriately */
2272static void cxt5066_asus_automic(struct hda_codec *codec)
2273{
2274 unsigned int present;
2275
2276 present = snd_hda_jack_detect(codec, 0x1b);
2277 snd_printdd("CXT5066: external microphone present=%d\n", present);
2278 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2279 present ? 1 : 0);
2280}
2281
2282
David Henningsson048e78a2010-09-02 08:35:47 +02002283/* toggle input of built-in digital mic and mic jack appropriately */
2284static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2285{
2286 unsigned int present;
2287
2288 present = snd_hda_jack_detect(codec, 0x1b);
2289 snd_printdd("CXT5066: external microphone present=%d\n", present);
2290 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2291 present ? 1 : 3);
2292}
2293
2294
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002295/* toggle input of built-in digital mic and mic jack appropriately
2296 order is: external mic -> dock mic -> interal mic */
2297static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2298{
2299 unsigned int ext_present, dock_present;
2300
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002301 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002302 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2303 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2304 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2305 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2307 {}
2308 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002309 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002310 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2311 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2312 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2313 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2314 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2315 {}
2316 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002317 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002318 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2319 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2320 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2321 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2322 {}
2323 };
2324
2325 ext_present = snd_hda_jack_detect(codec, 0x1b);
2326 dock_present = snd_hda_jack_detect(codec, 0x1a);
2327 if (ext_present) {
2328 snd_printdd("CXT5066: external microphone detected\n");
2329 snd_hda_sequence_write(codec, ext_mic_present);
2330 } else if (dock_present) {
2331 snd_printdd("CXT5066: dock microphone detected\n");
2332 snd_hda_sequence_write(codec, dock_mic_present);
2333 } else {
2334 snd_printdd("CXT5066: external microphone absent\n");
2335 snd_hda_sequence_write(codec, ext_mic_absent);
2336 }
2337}
2338
Daniel Drake0fb67e92009-07-16 14:46:57 +01002339/* mute internal speaker if HP is plugged */
2340static void cxt5066_hp_automute(struct hda_codec *codec)
2341{
2342 struct conexant_spec *spec = codec->spec;
2343 unsigned int portA, portD;
2344
2345 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002346 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002347
2348 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002349 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002350
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002351 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2352 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002353 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2354 portA, portD, spec->hp_present);
2355 cxt5066_update_speaker(codec);
2356}
2357
David Henningsson02b6b5b2011-01-21 13:27:39 +01002358/* Dispatch the right mic autoswitch function */
2359static void cxt5066_automic(struct hda_codec *codec)
2360{
2361 struct conexant_spec *spec = codec->spec;
2362
2363 if (spec->dell_vostro)
2364 cxt5066_vostro_automic(codec);
2365 else if (spec->ideapad)
2366 cxt5066_ideapad_automic(codec);
2367 else if (spec->thinkpad)
2368 cxt5066_thinkpad_automic(codec);
2369 else if (spec->hp_laptop)
2370 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002371 else if (spec->asus)
2372 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002373}
2374
Daniel Drake0fb67e92009-07-16 14:46:57 +01002375/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002376static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002377{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002378 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002379 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2380 switch (res >> 26) {
2381 case CONEXANT_HP_EVENT:
2382 cxt5066_hp_automute(codec);
2383 break;
2384 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002385 /* ignore mic events in DC mode; we're always using the jack */
2386 if (!spec->dc_enable)
2387 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002388 break;
2389 }
2390}
2391
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002392/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002393static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002394{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002395 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002396 switch (res >> 26) {
2397 case CONEXANT_HP_EVENT:
2398 cxt5066_hp_automute(codec);
2399 break;
2400 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002401 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002402 break;
2403 }
2404}
2405
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002406
Daniel Drake0fb67e92009-07-16 14:46:57 +01002407static const struct hda_input_mux cxt5066_analog_mic_boost = {
2408 .num_items = 5,
2409 .items = {
2410 { "0dB", 0 },
2411 { "10dB", 1 },
2412 { "20dB", 2 },
2413 { "30dB", 3 },
2414 { "40dB", 4 },
2415 },
2416};
2417
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002418static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002419{
2420 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002421 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002422 AC_VERB_SET_AMP_GAIN_MUTE,
2423 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2424 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002425 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002426 /* adjust the internal mic as well...it is not through 0x17 */
2427 snd_hda_codec_write_cache(codec, 0x23, 0,
2428 AC_VERB_SET_AMP_GAIN_MUTE,
2429 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2430 cxt5066_analog_mic_boost.
2431 items[spec->mic_boost].index);
2432 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002433}
2434
Daniel Drake0fb67e92009-07-16 14:46:57 +01002435static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2436 struct snd_ctl_elem_info *uinfo)
2437{
2438 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2439}
2440
2441static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2442 struct snd_ctl_elem_value *ucontrol)
2443{
2444 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002445 struct conexant_spec *spec = codec->spec;
2446 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002447 return 0;
2448}
2449
2450static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2451 struct snd_ctl_elem_value *ucontrol)
2452{
2453 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002454 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002455 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2456 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002457 idx = ucontrol->value.enumerated.item[0];
2458 if (idx >= imux->num_items)
2459 idx = imux->num_items - 1;
2460
Daniel Drakec4cfe662010-01-07 13:47:04 +01002461 spec->mic_boost = idx;
2462 if (!spec->dc_enable)
2463 cxt5066_set_mic_boost(codec);
2464 return 1;
2465}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002466
Daniel Drakec4cfe662010-01-07 13:47:04 +01002467static void cxt5066_enable_dc(struct hda_codec *codec)
2468{
2469 const struct hda_verb enable_dc_mode[] = {
2470 /* disable gain */
2471 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2472
2473 /* switch to DC input */
2474 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2475 {}
2476 };
2477
2478 /* configure as input source */
2479 snd_hda_sequence_write(codec, enable_dc_mode);
2480 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2481}
2482
2483static void cxt5066_disable_dc(struct hda_codec *codec)
2484{
2485 /* reconfigure input source */
2486 cxt5066_set_mic_boost(codec);
2487 /* automic also selects the right mic if we're recording */
2488 cxt5066_olpc_automic(codec);
2489}
2490
2491static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2492 struct snd_ctl_elem_value *ucontrol)
2493{
2494 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2495 struct conexant_spec *spec = codec->spec;
2496 ucontrol->value.integer.value[0] = spec->dc_enable;
2497 return 0;
2498}
2499
2500static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2501 struct snd_ctl_elem_value *ucontrol)
2502{
2503 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2504 struct conexant_spec *spec = codec->spec;
2505 int dc_enable = !!ucontrol->value.integer.value[0];
2506
2507 if (dc_enable == spec->dc_enable)
2508 return 0;
2509
2510 spec->dc_enable = dc_enable;
2511 if (dc_enable)
2512 cxt5066_enable_dc(codec);
2513 else
2514 cxt5066_disable_dc(codec);
2515
2516 return 1;
2517}
2518
2519static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2520 struct snd_ctl_elem_info *uinfo)
2521{
2522 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2523}
2524
2525static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2526 struct snd_ctl_elem_value *ucontrol)
2527{
2528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2529 struct conexant_spec *spec = codec->spec;
2530 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2531 return 0;
2532}
2533
2534static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2535 struct snd_ctl_elem_value *ucontrol)
2536{
2537 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2538 struct conexant_spec *spec = codec->spec;
2539 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2540 unsigned int idx;
2541
2542 idx = ucontrol->value.enumerated.item[0];
2543 if (idx >= imux->num_items)
2544 idx = imux->num_items - 1;
2545
2546 spec->dc_input_bias = idx;
2547 if (spec->dc_enable)
2548 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002549 return 1;
2550}
2551
Daniel Drake75f89912010-01-07 13:46:25 +01002552static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2553{
2554 struct conexant_spec *spec = codec->spec;
2555 /* mark as recording and configure the microphone widget so that the
2556 * recording LED comes on. */
2557 spec->recording = 1;
2558 cxt5066_olpc_select_mic(codec);
2559}
2560
2561static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2562{
2563 struct conexant_spec *spec = codec->spec;
2564 const struct hda_verb disable_mics[] = {
2565 /* disable external mic, port B */
2566 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2567
2568 /* disble internal mic, port C */
2569 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002570
2571 /* disable DC capture, port F */
2572 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002573 {},
2574 };
2575
2576 snd_hda_sequence_write(codec, disable_mics);
2577 spec->recording = 0;
2578}
2579
Andy Robinsonf6a24912011-01-24 10:12:37 -05002580static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002581 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002582 int num_pins)
2583{
2584 struct conexant_spec *spec = codec->spec;
2585 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2586 int i;
2587
2588 for (i = 0; i < num_pins; i++, dig_pins++) {
2589 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2590 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2591 continue;
2592 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2593 continue;
2594 if (spec->slave_dig_outs[0])
2595 nid_loc++;
2596 else
2597 nid_loc = spec->slave_dig_outs;
2598 }
2599}
2600
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002601static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002602 .num_items = 4,
2603 .items = {
2604 { "Mic B", 0 },
2605 { "Mic C", 1 },
2606 { "Mic E", 2 },
2607 { "Mic F", 3 },
2608 },
2609};
2610
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002611static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002612 .ops = &snd_hda_bind_vol,
2613 .values = {
2614 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2615 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2616 0
2617 },
2618};
2619
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002620static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002621 .ops = &snd_hda_bind_sw,
2622 .values = {
2623 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2624 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2625 0
2626 },
2627};
2628
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002629static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002630 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2631 {}
2632};
2633
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002634static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002635 {
2636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2637 .name = "Master Playback Volume",
2638 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2639 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2640 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002641 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002642 .info = snd_hda_mixer_amp_volume_info,
2643 .get = snd_hda_mixer_amp_volume_get,
2644 .put = snd_hda_mixer_amp_volume_put,
2645 .tlv = { .c = snd_hda_mixer_amp_tlv },
2646 /* offset by 28 volume steps to limit minimum gain to -46dB */
2647 .private_value =
2648 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2649 },
2650 {}
2651};
2652
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002653static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002654 {
2655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2656 .name = "DC Mode Enable Switch",
2657 .info = snd_ctl_boolean_mono_info,
2658 .get = cxt5066_olpc_dc_get,
2659 .put = cxt5066_olpc_dc_put,
2660 },
2661 {
2662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2663 .name = "DC Input Bias Enum",
2664 .info = cxt5066_olpc_dc_bias_enum_info,
2665 .get = cxt5066_olpc_dc_bias_enum_get,
2666 .put = cxt5066_olpc_dc_bias_enum_put,
2667 },
2668 {}
2669};
2670
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002671static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002672 {
2673 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2674 .name = "Master Playback Switch",
2675 .info = cxt_eapd_info,
2676 .get = cxt_eapd_get,
2677 .put = cxt5066_hp_master_sw_put,
2678 .private_value = 0x1d,
2679 },
2680
2681 {
2682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002683 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002684 .info = cxt5066_mic_boost_mux_enum_info,
2685 .get = cxt5066_mic_boost_mux_enum_get,
2686 .put = cxt5066_mic_boost_mux_enum_put,
2687 },
2688
2689 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2690 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2691 {}
2692};
2693
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002694static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002695 {
2696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002697 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002698 .info = cxt5066_mic_boost_mux_enum_info,
2699 .get = cxt5066_mic_boost_mux_enum_get,
2700 .put = cxt5066_mic_boost_mux_enum_put,
2701 .private_value = 0x23 | 0x100,
2702 },
2703 {}
2704};
2705
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002706static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002707 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2708 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2709 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2710 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2711
2712 /* Speakers */
2713 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2714 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2715
2716 /* HP, Amp */
2717 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2718 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2719
2720 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2721 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2722
2723 /* DAC1 */
2724 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2725
2726 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2727 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2729 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2730 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2731 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2732
2733 /* no digital microphone support yet */
2734 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2735
2736 /* Audio input selector */
2737 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2738
2739 /* SPDIF route: PCM */
2740 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2741 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2742
2743 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2744 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2745
2746 /* EAPD */
2747 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2748
2749 /* not handling these yet */
2750 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2751 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2752 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2753 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2754 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2755 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2756 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2757 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2758 { } /* end */
2759};
2760
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002761static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002762 /* Port A: headphones */
2763 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2764 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2765
2766 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002767 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002768
2769 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002770 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002771
2772 /* Port D: unused */
2773 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2774
2775 /* Port E: unused, but has primary EAPD */
2776 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2777 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2778
Daniel Drakec4cfe662010-01-07 13:47:04 +01002779 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002780 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2781
2782 /* Port G: internal speakers */
2783 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2784 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2785
2786 /* DAC1 */
2787 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2788
2789 /* DAC2: unused */
2790 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2791
2792 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2793 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2796 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2797 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2798 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2799 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2800 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2801 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2802 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2803 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2804
2805 /* Disable digital microphone port */
2806 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2807
2808 /* Audio input selectors */
2809 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2810 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2811
2812 /* Disable SPDIF */
2813 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2814 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815
2816 /* enable unsolicited events for Port A and B */
2817 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2818 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2819 { } /* end */
2820};
2821
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002822static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002823 /* Port A: headphones */
2824 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2825 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2826
2827 /* Port B: external microphone */
2828 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2829
2830 /* Port C: unused */
2831 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2832
2833 /* Port D: unused */
2834 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2835
2836 /* Port E: unused, but has primary EAPD */
2837 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2838 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2839
2840 /* Port F: unused */
2841 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2842
2843 /* Port G: internal speakers */
2844 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2845 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2846
2847 /* DAC1 */
2848 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2849
2850 /* DAC2: unused */
2851 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2852
2853 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2854 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2857 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2858 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2859 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2860 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2861 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2862 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2863 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2864 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2865
2866 /* Digital microphone port */
2867 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2868
2869 /* Audio input selectors */
2870 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2871 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2872
2873 /* Disable SPDIF */
2874 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2875 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2876
2877 /* enable unsolicited events for Port A and B */
2878 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2879 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2880 { } /* end */
2881};
2882
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002883static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002884 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2885 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2886 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2887 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2888
2889 /* Speakers */
2890 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2891 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2892
2893 /* HP, Amp */
2894 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2895 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2896
2897 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2898 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2899
2900 /* DAC1 */
2901 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2902
2903 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2906 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2907 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2909 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2910
2911 /* Audio input selector */
2912 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2913 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2914
2915 /* SPDIF route: PCM */
2916 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2917 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2918
2919 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2920 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2921
2922 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002923 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002924
2925 /* EAPD */
2926 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2927
2928 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2929 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2930 { } /* end */
2931};
2932
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002933static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002934 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2935 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2936
2937 /* Port G: internal speakers */
2938 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2939 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2940
2941 /* Port A: HP, Amp */
2942 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2943 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2944
2945 /* Port B: Mic Dock */
2946 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2947
2948 /* Port C: Mic */
2949 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2950
2951 /* Port D: HP Dock, Amp */
2952 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2953 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2954
2955 /* DAC1 */
2956 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2957
2958 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2959 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2960 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2961 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2962 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2963 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2964 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2965
2966 /* Audio input selector */
2967 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2968 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2969
2970 /* SPDIF route: PCM */
2971 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2972 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2973
2974 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2975 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2976
2977 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002978 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002979
2980 /* EAPD */
2981 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2982
2983 /* enable unsolicited events for Port A, B, C and D */
2984 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2985 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2986 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2987 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2988 { } /* end */
2989};
2990
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002991static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002992 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2993 { } /* end */
2994};
2995
David Henningsson048e78a2010-09-02 08:35:47 +02002996
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002997static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002998 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2999 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3000 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3001 { } /* end */
3002};
3003
Daniel Drake0fb67e92009-07-16 14:46:57 +01003004/* initialize jack-sensing, too */
3005static int cxt5066_init(struct hda_codec *codec)
3006{
3007 snd_printdd("CXT5066: init\n");
3008 conexant_init(codec);
3009 if (codec->patch_ops.unsol_event) {
3010 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003011 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003012 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003013 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003014 return 0;
3015}
3016
Daniel Drake75f89912010-01-07 13:46:25 +01003017static int cxt5066_olpc_init(struct hda_codec *codec)
3018{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003019 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003020 snd_printdd("CXT5066: init\n");
3021 conexant_init(codec);
3022 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003023 if (!spec->dc_enable) {
3024 cxt5066_set_mic_boost(codec);
3025 cxt5066_olpc_automic(codec);
3026 } else {
3027 cxt5066_enable_dc(codec);
3028 }
Daniel Drake75f89912010-01-07 13:46:25 +01003029 return 0;
3030}
3031
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003033 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003034 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3035 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003036 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003037 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003038 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003039 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003040 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003041 CXT5066_MODELS
3042};
3043
Takashi Iwaiea734962011-01-17 11:29:34 +01003044static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003045 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003046 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3047 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003048 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003049 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003050 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003051 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003052 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003053};
3054
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003055static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003056 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003057 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003058 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003059 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003060 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003061 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003062 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3063 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003064 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003065 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003066 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003067 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003068 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003069 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003070 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003071 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3072 CXT5066_LAPTOP),
3073 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003074 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003075 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003076 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003077 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003078 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003079 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003080 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003081 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003082 {}
3083};
3084
3085static int patch_cxt5066(struct hda_codec *codec)
3086{
3087 struct conexant_spec *spec;
3088 int board_config;
3089
3090 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3091 if (!spec)
3092 return -ENOMEM;
3093 codec->spec = spec;
3094
3095 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003096 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003097
3098 spec->dell_automute = 0;
3099 spec->multiout.max_channels = 2;
3100 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3101 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003102 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3103 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003104 spec->num_adc_nids = 1;
3105 spec->adc_nids = cxt5066_adc_nids;
3106 spec->capsrc_nids = cxt5066_capsrc_nids;
3107 spec->input_mux = &cxt5066_capture_source;
3108
3109 spec->port_d_mode = PIN_HP;
3110
3111 spec->num_init_verbs = 1;
3112 spec->init_verbs[0] = cxt5066_init_verbs;
3113 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3114 spec->channel_mode = cxt5066_modes;
3115 spec->cur_adc = 0;
3116 spec->cur_adc_idx = 0;
3117
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003118 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3119
Daniel Drake0fb67e92009-07-16 14:46:57 +01003120 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3121 cxt5066_models, cxt5066_cfg_tbl);
3122 switch (board_config) {
3123 default:
3124 case CXT5066_LAPTOP:
3125 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3126 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3127 break;
3128 case CXT5066_DELL_LAPTOP:
3129 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3130 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3131
3132 spec->port_d_mode = PIN_OUT;
3133 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3134 spec->num_init_verbs++;
3135 spec->dell_automute = 1;
3136 break;
David Henningssona1d69062011-01-21 13:33:28 +01003137 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003138 case CXT5066_HP_LAPTOP:
3139 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003140 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003141 spec->init_verbs[spec->num_init_verbs] =
3142 cxt5066_init_verbs_hp_laptop;
3143 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003144 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3145 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003146 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3148 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003149 if (board_config == CXT5066_HP_LAPTOP)
3150 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003151 /* input source automatically selected */
3152 spec->input_mux = NULL;
3153 spec->port_d_mode = 0;
3154 spec->mic_boost = 3; /* default 30dB gain */
3155 break;
3156
Daniel Drake0fb67e92009-07-16 14:46:57 +01003157 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003158 codec->patch_ops.init = cxt5066_olpc_init;
3159 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003160 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3161 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003162 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003163 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3164 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003165 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003166
3167 /* no S/PDIF out */
3168 spec->multiout.dig_out_nid = 0;
3169
3170 /* input source automatically selected */
3171 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003172
3173 /* our capture hooks which allow us to turn on the microphone LED
3174 * at the right time */
3175 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3176 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003177 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003178 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003179 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003180 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003181 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3182 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3183 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003184 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003185 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003186 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003187 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003188
3189 /* no S/PDIF out */
3190 spec->multiout.dig_out_nid = 0;
3191
3192 /* input source automatically selected */
3193 spec->input_mux = NULL;
3194 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003195 case CXT5066_IDEAPAD:
3196 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003197 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003198 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3199 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3200 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3201 spec->port_d_mode = 0;
3202 spec->ideapad = 1;
3203 spec->mic_boost = 2; /* default 20dB gain */
3204
3205 /* no S/PDIF out */
3206 spec->multiout.dig_out_nid = 0;
3207
3208 /* input source automatically selected */
3209 spec->input_mux = NULL;
3210 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003211 case CXT5066_THINKPAD:
3212 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003213 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003214 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3215 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3216 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3217 spec->thinkpad = 1;
3218 spec->port_d_mode = PIN_OUT;
3219 spec->mic_boost = 2; /* default 20dB gain */
3220
3221 /* no S/PDIF out */
3222 spec->multiout.dig_out_nid = 0;
3223
3224 /* input source automatically selected */
3225 spec->input_mux = NULL;
3226 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003227 }
3228
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003229 if (spec->beep_amp)
3230 snd_hda_attach_beep_device(codec, spec->beep_amp);
3231
Daniel Drake0fb67e92009-07-16 14:46:57 +01003232 return 0;
3233}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003234
3235/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003236 * Automatic parser for CX20641 & co
3237 */
3238
Takashi Iwai6764bce2011-05-13 16:52:25 +02003239static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3240 struct hda_codec *codec,
3241 unsigned int stream_tag,
3242 unsigned int format,
3243 struct snd_pcm_substream *substream)
3244{
3245 struct conexant_spec *spec = codec->spec;
3246 hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]];
3247 if (spec->adc_switching) {
3248 spec->cur_adc = adc;
3249 spec->cur_adc_stream_tag = stream_tag;
3250 spec->cur_adc_format = format;
3251 }
3252 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3253 return 0;
3254}
3255
3256static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3257 struct hda_codec *codec,
3258 struct snd_pcm_substream *substream)
3259{
3260 struct conexant_spec *spec = codec->spec;
3261 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3262 spec->cur_adc = 0;
3263 return 0;
3264}
3265
3266static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3267 .substreams = 1,
3268 .channels_min = 2,
3269 .channels_max = 2,
3270 .nid = 0, /* fill later */
3271 .ops = {
3272 .prepare = cx_auto_capture_pcm_prepare,
3273 .cleanup = cx_auto_capture_pcm_cleanup
3274 },
3275};
3276
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003277static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003278
3279/* get the connection index of @nid in the widget @mux */
3280static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3281 hda_nid_t nid)
3282{
3283 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3284 int i, nums;
3285
3286 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3287 for (i = 0; i < nums; i++)
3288 if (conn[i] == nid)
3289 return i;
3290 return -1;
3291}
3292
3293/* get an unassigned DAC from the given list.
3294 * Return the nid if found and reduce the DAC list, or return zero if
3295 * not found
3296 */
3297static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3298 hda_nid_t *dacs, int *num_dacs)
3299{
3300 int i, nums = *num_dacs;
3301 hda_nid_t ret = 0;
3302
3303 for (i = 0; i < nums; i++) {
3304 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3305 ret = dacs[i];
3306 break;
3307 }
3308 }
3309 if (!ret)
3310 return 0;
3311 if (--nums > 0)
3312 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3313 *num_dacs = nums;
3314 return ret;
3315}
3316
3317#define MAX_AUTO_DACS 5
3318
3319/* fill analog DAC list from the widget tree */
3320static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3321{
3322 hda_nid_t nid, end_nid;
3323 int nums = 0;
3324
3325 end_nid = codec->start_nid + codec->num_nodes;
3326 for (nid = codec->start_nid; nid < end_nid; nid++) {
3327 unsigned int wcaps = get_wcaps(codec, nid);
3328 unsigned int type = get_wcaps_type(wcaps);
3329 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3330 dacs[nums++] = nid;
3331 if (nums >= MAX_AUTO_DACS)
3332 break;
3333 }
3334 }
3335 return nums;
3336}
3337
3338/* fill pin_dac_pair list from the pin and dac list */
3339static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3340 int num_pins, hda_nid_t *dacs, int *rest,
3341 struct pin_dac_pair *filled, int type)
3342{
3343 int i, nums;
3344
3345 nums = 0;
3346 for (i = 0; i < num_pins; i++) {
3347 filled[nums].pin = pins[i];
3348 filled[nums].type = type;
3349 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3350 nums++;
3351 }
3352 return nums;
3353}
3354
3355/* parse analog output paths */
3356static void cx_auto_parse_output(struct hda_codec *codec)
3357{
3358 struct conexant_spec *spec = codec->spec;
3359 struct auto_pin_cfg *cfg = &spec->autocfg;
3360 hda_nid_t dacs[MAX_AUTO_DACS];
3361 int i, j, nums, rest;
3362
3363 rest = fill_cx_auto_dacs(codec, dacs);
3364 /* parse all analog output pins */
3365 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3366 dacs, &rest, spec->dac_info,
3367 AUTO_PIN_LINE_OUT);
3368 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3369 dacs, &rest, spec->dac_info + nums,
3370 AUTO_PIN_HP_OUT);
3371 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3372 dacs, &rest, spec->dac_info + nums,
3373 AUTO_PIN_SPEAKER_OUT);
3374 spec->dac_info_filled = nums;
3375 /* fill multiout struct */
3376 for (i = 0; i < nums; i++) {
3377 hda_nid_t dac = spec->dac_info[i].dac;
3378 if (!dac)
3379 continue;
3380 switch (spec->dac_info[i].type) {
3381 case AUTO_PIN_LINE_OUT:
3382 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3383 spec->multiout.num_dacs++;
3384 break;
3385 case AUTO_PIN_HP_OUT:
3386 case AUTO_PIN_SPEAKER_OUT:
3387 if (!spec->multiout.hp_nid) {
3388 spec->multiout.hp_nid = dac;
3389 break;
3390 }
3391 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3392 if (!spec->multiout.extra_out_nid[j]) {
3393 spec->multiout.extra_out_nid[j] = dac;
3394 break;
3395 }
3396 break;
3397 }
3398 }
3399 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003400 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003401
3402 if (cfg->hp_outs > 0)
3403 spec->auto_mute = 1;
3404 spec->vmaster_nid = spec->private_dac_nids[0];
3405}
3406
Takashi Iwaida339862011-05-13 16:24:15 +02003407static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3408 hda_nid_t *pins, bool on);
3409
Takashi Iwaif2e57312010-09-15 10:07:08 +02003410/* auto-mute/unmute speaker and line outs according to headphone jack */
3411static void cx_auto_hp_automute(struct hda_codec *codec)
3412{
3413 struct conexant_spec *spec = codec->spec;
3414 struct auto_pin_cfg *cfg = &spec->autocfg;
3415 int i, present;
3416
3417 if (!spec->auto_mute)
3418 return;
3419 present = 0;
3420 for (i = 0; i < cfg->hp_outs; i++) {
3421 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3422 present = 1;
3423 break;
3424 }
3425 }
Takashi Iwaida339862011-05-13 16:24:15 +02003426 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003427 for (i = 0; i < cfg->line_outs; i++) {
3428 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3429 AC_VERB_SET_PIN_WIDGET_CONTROL,
3430 present ? 0 : PIN_OUT);
3431 }
Takashi Iwaida339862011-05-13 16:24:15 +02003432 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003433 for (i = 0; !present && i < cfg->line_outs; i++)
3434 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3435 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003436 for (i = 0; i < cfg->speaker_outs; i++) {
3437 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3438 AC_VERB_SET_PIN_WIDGET_CONTROL,
3439 present ? 0 : PIN_OUT);
3440 }
Takashi Iwaida339862011-05-13 16:24:15 +02003441 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003442}
3443
Takashi Iwai6764bce2011-05-13 16:52:25 +02003444static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3445 struct snd_ctl_elem_info *uinfo)
3446{
3447 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3448 struct conexant_spec *spec = codec->spec;
3449
3450 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3451}
3452
3453static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3454 struct snd_ctl_elem_value *ucontrol)
3455{
3456 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3457 struct conexant_spec *spec = codec->spec;
3458
3459 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3460 return 0;
3461}
3462
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003463/* look for the route the given pin from mux and return the index;
3464 * if do_select is set, actually select the route.
3465 */
3466static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3467 hda_nid_t pin, bool do_select, int depth)
3468{
3469 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3470 int i, nums;
3471
3472 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3473 for (i = 0; i < nums; i++)
3474 if (conn[i] == pin) {
3475 if (do_select)
3476 snd_hda_codec_write(codec, mux, 0,
3477 AC_VERB_SET_CONNECT_SEL, i);
3478 return i;
3479 }
3480 depth++;
3481 if (depth == 2)
3482 return -1;
3483 for (i = 0; i < nums; i++) {
3484 int ret = __select_input_connection(codec, conn[i], pin,
3485 do_select, depth);
3486 if (ret >= 0) {
3487 if (do_select)
3488 snd_hda_codec_write(codec, mux, 0,
3489 AC_VERB_SET_CONNECT_SEL, i);
3490 return ret;
3491 }
3492 }
3493 return -1;
3494}
3495
3496static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3497 hda_nid_t pin)
3498{
3499 __select_input_connection(codec, mux, pin, true, 0);
3500}
3501
3502static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3503 hda_nid_t pin)
3504{
3505 return __select_input_connection(codec, mux, pin, false, 0);
3506}
3507
Takashi Iwai6764bce2011-05-13 16:52:25 +02003508static int cx_auto_mux_enum_update(struct hda_codec *codec,
3509 const struct hda_input_mux *imux,
3510 unsigned int idx)
3511{
3512 struct conexant_spec *spec = codec->spec;
3513 hda_nid_t adc;
3514
3515 if (!imux->num_items)
3516 return 0;
3517 if (idx >= imux->num_items)
3518 idx = imux->num_items - 1;
3519 if (spec->cur_mux[0] == idx)
3520 return 0;
3521 adc = spec->imux_adcs[idx];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003522 select_input_connection(codec, spec->imux_adcs[idx],
3523 spec->imux_pins[idx]);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003524 if (spec->cur_adc && spec->cur_adc != adc) {
3525 /* stream is running, let's swap the current ADC */
3526 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3527 spec->cur_adc = adc;
3528 snd_hda_codec_setup_stream(codec, adc,
3529 spec->cur_adc_stream_tag, 0,
3530 spec->cur_adc_format);
3531 }
3532 spec->cur_mux[0] = idx;
3533 return 1;
3534}
3535
3536static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3537 struct snd_ctl_elem_value *ucontrol)
3538{
3539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3540 struct conexant_spec *spec = codec->spec;
3541
3542 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3543 ucontrol->value.enumerated.item[0]);
3544}
3545
3546static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3547 {
3548 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3549 .name = "Capture Source",
3550 .info = cx_auto_mux_enum_info,
3551 .get = cx_auto_mux_enum_get,
3552 .put = cx_auto_mux_enum_put
3553 },
3554 {}
3555};
3556
Takashi Iwaif2e57312010-09-15 10:07:08 +02003557/* automatic switch internal and external mic */
3558static void cx_auto_automic(struct hda_codec *codec)
3559{
3560 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003561 int ext_idx = spec->auto_mic_ext;
3562
3563 if (!spec->auto_mic)
3564 return;
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003565 if (snd_hda_jack_detect(codec, spec->imux_pins[ext_idx]))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003566 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3567 else
3568 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003569}
3570
3571static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3572{
3573 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3574 switch (res >> 26) {
3575 case CONEXANT_HP_EVENT:
3576 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003577 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003578 break;
3579 case CONEXANT_MIC_EVENT:
3580 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003581 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003582 break;
3583 }
3584}
3585
Takashi Iwaif2e57312010-09-15 10:07:08 +02003586/* return true if it's an internal-mic pin */
3587static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3588{
3589 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3590 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003591 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003592}
3593
3594/* return true if it's an external-mic pin */
3595static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3596{
3597 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3598 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003599 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3600 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003601}
3602
3603/* check whether the pin config is suitable for auto-mic switching;
3604 * auto-mic is enabled only when one int-mic and one-ext mic exist
3605 */
3606static void cx_auto_check_auto_mic(struct hda_codec *codec)
3607{
3608 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003609
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003610 if (is_ext_mic(codec, spec->imux_pins[0]) &&
3611 is_int_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003612 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003613 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003614 return;
3615 }
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003616 if (is_int_mic(codec, spec->imux_pins[0]) &&
3617 is_ext_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003618 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003619 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003620 return;
3621 }
3622}
3623
3624static void cx_auto_parse_input(struct hda_codec *codec)
3625{
3626 struct conexant_spec *spec = codec->spec;
3627 struct auto_pin_cfg *cfg = &spec->autocfg;
3628 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003629 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003630
3631 imux = &spec->private_imux;
3632 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003633 for (j = 0; j < spec->num_adc_nids; j++) {
3634 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003635 int idx = get_input_connection(codec, adc,
3636 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003637 if (idx >= 0) {
3638 const char *label;
3639 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003640 spec->imux_adcs[imux->num_items] = adc;
3641 spec->imux_pins[imux->num_items] =
3642 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003643 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003644 break;
3645 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003646 }
3647 }
3648 if (imux->num_items == 2 && cfg->num_inputs == 2)
3649 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003650 if (imux->num_items > 1 && !spec->auto_mic) {
3651 for (i = 1; i < imux->num_items; i++) {
3652 if (spec->imux_adcs[i] != spec->imux_adcs[0]) {
3653 spec->adc_switching = 1;
3654 break;
3655 }
3656 }
3657 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003658}
3659
3660/* get digital-input audio widget corresponding to the given pin */
3661static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3662{
3663 hda_nid_t nid, end_nid;
3664
3665 end_nid = codec->start_nid + codec->num_nodes;
3666 for (nid = codec->start_nid; nid < end_nid; nid++) {
3667 unsigned int wcaps = get_wcaps(codec, nid);
3668 unsigned int type = get_wcaps_type(wcaps);
3669 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3670 if (get_connection_index(codec, nid, pin) >= 0)
3671 return nid;
3672 }
3673 }
3674 return 0;
3675}
3676
3677static void cx_auto_parse_digital(struct hda_codec *codec)
3678{
3679 struct conexant_spec *spec = codec->spec;
3680 struct auto_pin_cfg *cfg = &spec->autocfg;
3681 hda_nid_t nid;
3682
3683 if (cfg->dig_outs &&
3684 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3685 spec->multiout.dig_out_nid = nid;
3686 if (cfg->dig_in_pin)
3687 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3688}
3689
3690#ifdef CONFIG_SND_HDA_INPUT_BEEP
3691static void cx_auto_parse_beep(struct hda_codec *codec)
3692{
3693 struct conexant_spec *spec = codec->spec;
3694 hda_nid_t nid, end_nid;
3695
3696 end_nid = codec->start_nid + codec->num_nodes;
3697 for (nid = codec->start_nid; nid < end_nid; nid++)
3698 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3699 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3700 break;
3701 }
3702}
3703#else
3704#define cx_auto_parse_beep(codec)
3705#endif
3706
3707static int cx_auto_parse_auto_config(struct hda_codec *codec)
3708{
3709 struct conexant_spec *spec = codec->spec;
3710 int err;
3711
3712 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3713 if (err < 0)
3714 return err;
3715
3716 cx_auto_parse_output(codec);
3717 cx_auto_parse_input(codec);
3718 cx_auto_parse_digital(codec);
3719 cx_auto_parse_beep(codec);
3720 return 0;
3721}
3722
Takashi Iwaida339862011-05-13 16:24:15 +02003723static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3724 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003725{
3726 int i;
3727 for (i = 0; i < num_pins; i++) {
3728 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3729 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003730 AC_VERB_SET_EAPD_BTLENABLE,
3731 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003732 }
3733}
3734
3735static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3736 hda_nid_t src)
3737{
3738 int idx = get_connection_index(codec, pin, src);
3739 if (idx >= 0)
3740 snd_hda_codec_write(codec, pin, 0,
3741 AC_VERB_SET_CONNECT_SEL, idx);
3742}
3743
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003744static void mute_outputs(struct hda_codec *codec, int num_nids,
3745 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003746{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003747 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003748
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003749 for (i = 0; i < num_nids; i++) {
3750 hda_nid_t nid = nids[i];
3751 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3752 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003753 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3754 val = AMP_OUT_MUTE;
3755 else
3756 val = AMP_OUT_ZERO;
3757 snd_hda_codec_write(codec, nid, 0,
3758 AC_VERB_SET_AMP_GAIN_MUTE, val);
3759 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003760}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003761
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003762static void cx_auto_init_output(struct hda_codec *codec)
3763{
3764 struct conexant_spec *spec = codec->spec;
3765 struct auto_pin_cfg *cfg = &spec->autocfg;
3766 hda_nid_t nid;
3767 int i;
3768
3769 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003770 for (i = 0; i < cfg->hp_outs; i++)
3771 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3772 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003773 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3774 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3775 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003776 if (spec->auto_mute) {
3777 for (i = 0; i < cfg->hp_outs; i++) {
3778 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3779 AC_VERB_SET_UNSOLICITED_ENABLE,
3780 AC_USRSP_EN | CONEXANT_HP_EVENT);
3781 }
3782 cx_auto_hp_automute(codec);
3783 } else {
3784 for (i = 0; i < cfg->line_outs; i++)
3785 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3786 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3787 for (i = 0; i < cfg->speaker_outs; i++)
3788 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3789 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003790 /* turn on EAPD */
3791 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3792 true);
3793 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3794 true);
3795 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3796 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003797 }
3798
3799 for (i = 0; i < spec->dac_info_filled; i++) {
3800 nid = spec->dac_info[i].dac;
3801 if (!nid)
3802 nid = spec->multiout.dac_nids[0];
3803 select_connection(codec, spec->dac_info[i].pin, nid);
3804 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003805}
3806
3807static void cx_auto_init_input(struct hda_codec *codec)
3808{
3809 struct conexant_spec *spec = codec->spec;
3810 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003811 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003812
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003813 for (i = 0; i < spec->num_adc_nids; i++) {
3814 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003815 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3816 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003817 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3818 val = AMP_IN_MUTE(0);
3819 else
3820 val = AMP_IN_UNMUTE(0);
3821 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3822 val);
3823 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003824
3825 for (i = 0; i < cfg->num_inputs; i++) {
3826 unsigned int type;
3827 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3828 type = PIN_VREF80;
3829 else
3830 type = PIN_IN;
3831 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3832 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3833 }
3834
3835 if (spec->auto_mic) {
3836 int ext_idx = spec->auto_mic_ext;
3837 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3838 AC_VERB_SET_UNSOLICITED_ENABLE,
3839 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3840 cx_auto_automic(codec);
3841 } else {
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003842 select_input_connection(codec, spec->imux_adcs[0],
3843 spec->imux_pins[0]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003844 }
3845}
3846
3847static void cx_auto_init_digital(struct hda_codec *codec)
3848{
3849 struct conexant_spec *spec = codec->spec;
3850 struct auto_pin_cfg *cfg = &spec->autocfg;
3851
3852 if (spec->multiout.dig_out_nid)
3853 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3854 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3855 if (spec->dig_in_nid)
3856 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3857 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3858}
3859
3860static int cx_auto_init(struct hda_codec *codec)
3861{
3862 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3863 cx_auto_init_output(codec);
3864 cx_auto_init_input(codec);
3865 cx_auto_init_digital(codec);
3866 return 0;
3867}
3868
David Henningsson983345e2011-02-15 19:57:09 +01003869static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003870 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003871 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003872{
3873 static char name[32];
3874 static struct snd_kcontrol_new knew[] = {
3875 HDA_CODEC_VOLUME(name, 0, 0, 0),
3876 HDA_CODEC_MUTE(name, 0, 0, 0),
3877 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003878 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003879 int i, err;
3880
3881 for (i = 0; i < 2; i++) {
3882 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003883 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3884 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003885 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3886 knew[i].index = cidx;
3887 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3888 kctl = snd_ctl_new1(&knew[i], codec);
3889 if (!kctl)
3890 return -ENOMEM;
3891 err = snd_hda_ctl_add(codec, nid, kctl);
3892 if (err < 0)
3893 return err;
3894 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3895 break;
3896 }
3897 return 0;
3898}
3899
David Henningsson983345e2011-02-15 19:57:09 +01003900#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3901 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3902
Takashi Iwaif2e57312010-09-15 10:07:08 +02003903#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3904 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3905
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003906static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3907 hda_nid_t pin, const char *name, int idx)
3908{
3909 unsigned int caps;
3910 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3911 if (caps & AC_AMPCAP_NUM_STEPS)
3912 return cx_auto_add_pb_volume(codec, dac, name, idx);
3913 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3914 if (caps & AC_AMPCAP_NUM_STEPS)
3915 return cx_auto_add_pb_volume(codec, pin, name, idx);
3916 return 0;
3917}
3918
Takashi Iwaif2e57312010-09-15 10:07:08 +02003919static int cx_auto_build_output_controls(struct hda_codec *codec)
3920{
3921 struct conexant_spec *spec = codec->spec;
3922 int i, err;
3923 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003924 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003925
3926 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003927 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3928 spec->dac_info[0].pin,
3929 "Master", 0);
3930
Takashi Iwaif2e57312010-09-15 10:07:08 +02003931 for (i = 0; i < spec->dac_info_filled; i++) {
3932 const char *label;
3933 int idx, type;
3934 if (!spec->dac_info[i].dac)
3935 continue;
3936 type = spec->dac_info[i].type;
3937 if (type == AUTO_PIN_LINE_OUT)
3938 type = spec->autocfg.line_out_type;
3939 switch (type) {
3940 case AUTO_PIN_LINE_OUT:
3941 default:
3942 label = texts[num_line++];
3943 idx = 0;
3944 break;
3945 case AUTO_PIN_HP_OUT:
3946 label = "Headphone";
3947 idx = num_hp++;
3948 break;
3949 case AUTO_PIN_SPEAKER_OUT:
3950 label = "Speaker";
3951 idx = num_spk++;
3952 break;
3953 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003954 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3955 spec->dac_info[i].pin,
3956 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003957 if (err < 0)
3958 return err;
3959 }
3960 return 0;
3961}
3962
Takashi Iwai6764bce2011-05-13 16:52:25 +02003963static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3964 const char *label, const char *pfx,
3965 int cidx)
3966{
3967 struct conexant_spec *spec = codec->spec;
3968 int i;
3969
3970 for (i = 0; i < spec->num_adc_nids; i++) {
3971 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003972 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003973 if (idx < 0)
3974 continue;
3975 return cx_auto_add_volume_idx(codec, label, pfx,
3976 cidx, adc_nid, HDA_INPUT, idx);
3977 }
3978 return 0;
3979}
3980
Takashi Iwaif2e57312010-09-15 10:07:08 +02003981static int cx_auto_build_input_controls(struct hda_codec *codec)
3982{
3983 struct conexant_spec *spec = codec->spec;
3984 struct auto_pin_cfg *cfg = &spec->autocfg;
3985 static const char *prev_label;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003986 int i, err, cidx;
David Henningsson983345e2011-02-15 19:57:09 +01003987
Takashi Iwaif2e57312010-09-15 10:07:08 +02003988 prev_label = NULL;
3989 cidx = 0;
3990 for (i = 0; i < cfg->num_inputs; i++) {
3991 hda_nid_t nid = cfg->inputs[i].pin;
3992 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01003993 int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
David Henningsson983345e2011-02-15 19:57:09 +01003994
Takashi Iwaif2e57312010-09-15 10:07:08 +02003995 label = hda_get_autocfg_input_label(codec, cfg, i);
3996 if (label == prev_label)
3997 cidx++;
3998 else
3999 cidx = 0;
4000 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004001
4002 if (pin_amp) {
4003 err = cx_auto_add_volume(codec, label, " Boost", cidx,
4004 nid, HDA_INPUT);
4005 if (err < 0)
4006 return err;
4007 }
4008
Takashi Iwai6764bce2011-05-13 16:52:25 +02004009 if (cfg->num_inputs == 1) {
4010 err = cx_auto_add_capture_volume(codec, nid,
4011 "Capture", "", cidx);
4012 } else {
4013 err = cx_auto_add_capture_volume(codec, nid,
4014 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004015 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004016 if (err < 0)
4017 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004018 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004019
4020 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4021 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4022 if (err < 0)
4023 return err;
4024 }
4025
Takashi Iwaif2e57312010-09-15 10:07:08 +02004026 return 0;
4027}
4028
4029static int cx_auto_build_controls(struct hda_codec *codec)
4030{
4031 int err;
4032
4033 err = cx_auto_build_output_controls(codec);
4034 if (err < 0)
4035 return err;
4036 err = cx_auto_build_input_controls(codec);
4037 if (err < 0)
4038 return err;
4039 return conexant_build_controls(codec);
4040}
4041
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004042static int cx_auto_search_adcs(struct hda_codec *codec)
4043{
4044 struct conexant_spec *spec = codec->spec;
4045 hda_nid_t nid, end_nid;
4046
4047 end_nid = codec->start_nid + codec->num_nodes;
4048 for (nid = codec->start_nid; nid < end_nid; nid++) {
4049 unsigned int caps = get_wcaps(codec, nid);
4050 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4051 continue;
4052 if (caps & AC_WCAP_DIGITAL)
4053 continue;
4054 if (snd_BUG_ON(spec->num_adc_nids >=
4055 ARRAY_SIZE(spec->private_adc_nids)))
4056 break;
4057 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4058 }
4059 spec->adc_nids = spec->private_adc_nids;
4060 return 0;
4061}
4062
4063
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004064static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004065 .build_controls = cx_auto_build_controls,
4066 .build_pcms = conexant_build_pcms,
4067 .init = cx_auto_init,
4068 .free = conexant_free,
4069 .unsol_event = cx_auto_unsol_event,
4070#ifdef CONFIG_SND_HDA_POWER_SAVE
4071 .suspend = conexant_suspend,
4072#endif
4073 .reboot_notify = snd_hda_shutup_pins,
4074};
4075
4076static int patch_conexant_auto(struct hda_codec *codec)
4077{
4078 struct conexant_spec *spec;
4079 int err;
4080
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004081 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4082 codec->chip_name);
4083
Takashi Iwaif2e57312010-09-15 10:07:08 +02004084 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4085 if (!spec)
4086 return -ENOMEM;
4087 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004088 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004089 err = cx_auto_search_adcs(codec);
4090 if (err < 0)
4091 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004092 err = cx_auto_parse_auto_config(codec);
4093 if (err < 0) {
4094 kfree(codec->spec);
4095 codec->spec = NULL;
4096 return err;
4097 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004098 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004099 codec->patch_ops = cx_auto_patch_ops;
4100 if (spec->beep_amp)
4101 snd_hda_attach_beep_device(codec, spec->beep_amp);
4102 return 0;
4103}
4104
4105/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004106 */
4107
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004108static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004109 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4110 .patch = patch_cxt5045 },
4111 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4112 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004113 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4114 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004115 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4116 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004117 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4118 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004119 { .id = 0x14f15068, .name = "CX20584",
4120 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004121 { .id = 0x14f15069, .name = "CX20585",
4122 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004123 { .id = 0x14f1506e, .name = "CX20590",
4124 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004125 { .id = 0x14f15097, .name = "CX20631",
4126 .patch = patch_conexant_auto },
4127 { .id = 0x14f15098, .name = "CX20632",
4128 .patch = patch_conexant_auto },
4129 { .id = 0x14f150a1, .name = "CX20641",
4130 .patch = patch_conexant_auto },
4131 { .id = 0x14f150a2, .name = "CX20642",
4132 .patch = patch_conexant_auto },
4133 { .id = 0x14f150ab, .name = "CX20651",
4134 .patch = patch_conexant_auto },
4135 { .id = 0x14f150ac, .name = "CX20652",
4136 .patch = patch_conexant_auto },
4137 { .id = 0x14f150b8, .name = "CX20664",
4138 .patch = patch_conexant_auto },
4139 { .id = 0x14f150b9, .name = "CX20665",
4140 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004141 {} /* terminator */
4142};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004143
4144MODULE_ALIAS("snd-hda-codec-id:14f15045");
4145MODULE_ALIAS("snd-hda-codec-id:14f15047");
4146MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004147MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004148MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004149MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004150MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004151MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004152MODULE_ALIAS("snd-hda-codec-id:14f15097");
4153MODULE_ALIAS("snd-hda-codec-id:14f15098");
4154MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4155MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4156MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4157MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4158MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4159MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004160
4161MODULE_LICENSE("GPL");
4162MODULE_DESCRIPTION("Conexant HD-audio codec");
4163
4164static struct hda_codec_preset_list conexant_list = {
4165 .preset = snd_hda_preset_conexant,
4166 .owner = THIS_MODULE,
4167};
4168
4169static int __init patch_conexant_init(void)
4170{
4171 return snd_hda_add_codec_preset(&conexant_list);
4172}
4173
4174static void __exit patch_conexant_exit(void)
4175{
4176 snd_hda_delete_codec_preset(&conexant_list);
4177}
4178
4179module_init(patch_conexant_init)
4180module_exit(patch_conexant_exit)