blob: ebce2fe3aec2590fd0cab52f366be1defebcfaa5 [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);
1107 if (board_config < 0)
1108 board_config = CXT5045_AUTO;
1109 if (board_config == CXT5045_AUTO)
1110 return patch_conexant_auto(codec);
1111
Tobin Davisc9b443d2006-11-14 12:13:39 +01001112 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1113 if (!spec)
1114 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001115 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001116 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117
1118 spec->multiout.max_channels = 2;
1119 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1120 spec->multiout.dac_nids = cxt5045_dac_nids;
1121 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1122 spec->num_adc_nids = 1;
1123 spec->adc_nids = cxt5045_adc_nids;
1124 spec->capsrc_nids = cxt5045_capsrc_nids;
1125 spec->input_mux = &cxt5045_capture_source;
1126 spec->num_mixers = 1;
1127 spec->mixers[0] = cxt5045_mixers;
1128 spec->num_init_verbs = 1;
1129 spec->init_verbs[0] = cxt5045_init_verbs;
1130 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001131 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1132 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001133
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001134 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135
1136 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001137
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001139 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001140 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001141 spec->input_mux = &cxt5045_capture_source;
1142 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001143 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1144 spec->mixers[0] = cxt5045_mixers;
1145 codec->patch_ops.init = cxt5045_init;
1146 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001147 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001148 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001149 spec->input_mux = &cxt5045_capture_source;
1150 spec->num_init_verbs = 2;
1151 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001152 spec->mixers[0] = cxt5045_mixers;
1153 codec->patch_ops.init = cxt5045_init;
1154 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001155 default:
1156 case CXT5045_LAPTOP_HPMICSENSE:
1157 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1158 spec->input_mux = &cxt5045_capture_source;
1159 spec->num_init_verbs = 3;
1160 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1161 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1162 spec->mixers[0] = cxt5045_mixers;
1163 codec->patch_ops.init = cxt5045_init;
1164 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001165 case CXT5045_BENQ:
1166 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1167 spec->input_mux = &cxt5045_capture_source_benq;
1168 spec->num_init_verbs = 1;
1169 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1170 spec->mixers[0] = cxt5045_mixers;
1171 spec->mixers[1] = cxt5045_benq_mixers;
1172 spec->num_mixers = 2;
1173 codec->patch_ops.init = cxt5045_init;
1174 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001175 case CXT5045_LAPTOP_HP530:
1176 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1177 spec->input_mux = &cxt5045_capture_source_hp530;
1178 spec->num_init_verbs = 2;
1179 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1180 spec->mixers[0] = cxt5045_mixers_hp530;
1181 codec->patch_ops.init = cxt5045_init;
1182 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001183#ifdef CONFIG_SND_DEBUG
1184 case CXT5045_TEST:
1185 spec->input_mux = &cxt5045_test_capture_source;
1186 spec->mixers[0] = cxt5045_test_mixer;
1187 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001188 break;
1189
Tobin Davisc9b443d2006-11-14 12:13:39 +01001190#endif
1191 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001192
Takashi Iwai031005f2008-06-26 14:49:58 +02001193 switch (codec->subsystem_id >> 16) {
1194 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001195 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001196 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001197 case 0x17aa:
1198 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1199 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1200 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001201 */
1202 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1203 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1204 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1205 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1206 (1 << AC_AMPCAP_MUTE_SHIFT));
1207 break;
1208 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001209
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001210 if (spec->beep_amp)
1211 snd_hda_attach_beep_device(codec, spec->beep_amp);
1212
Tobin Davisc9b443d2006-11-14 12:13:39 +01001213 return 0;
1214}
1215
1216
1217/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001218#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001219
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001220static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1221static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1222static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001224static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001225 { 2, NULL },
1226};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001228static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001229 .num_items = 2,
1230 .items = {
1231 { "ExtMic", 0x2 },
1232 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233 }
1234};
1235
1236/* turn on/off EAPD (+ mute HP) as a master switch */
1237static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1238 struct snd_ctl_elem_value *ucontrol)
1239{
1240 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1241 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001242 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001243
Tobin Davis82f30042007-02-13 12:45:44 +01001244 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001245 return 0;
1246
Tobin Davis82f30042007-02-13 12:45:44 +01001247 /* toggle internal speakers mute depending of presence of
1248 * the headphone jack
1249 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001250 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001251 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1252 * pin widgets unlike other codecs. In this case, we need to
1253 * set index 0x01 for the volume from the mixer amp 0x19.
1254 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001255 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001256 HDA_AMP_MUTE, bits);
1257 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1258 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1259 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001260 return 1;
1261}
1262
Tobin Davisc9b443d2006-11-14 12:13:39 +01001263/* mute internal speaker if HP is plugged */
1264static void cxt5047_hp_automute(struct hda_codec *codec)
1265{
Tobin Davis82f30042007-02-13 12:45:44 +01001266 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001267 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001268
Takashi Iwaid56757a2009-11-18 08:00:14 +01001269 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001270
Takashi Iwai47fd8302007-08-10 17:11:07 +02001271 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001272 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001273 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001274 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001275}
1276
1277/* toggle input of built-in and mic jack appropriately */
1278static void cxt5047_hp_automic(struct hda_codec *codec)
1279{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001280 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001281 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1282 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283 {}
1284 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001285 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001286 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1287 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001288 {}
1289 };
1290 unsigned int present;
1291
Takashi Iwaid56757a2009-11-18 08:00:14 +01001292 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001293 if (present)
1294 snd_hda_sequence_write(codec, mic_jack_on);
1295 else
1296 snd_hda_sequence_write(codec, mic_jack_off);
1297}
1298
1299/* unsolicited event for HP jack sensing */
1300static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1301 unsigned int res)
1302{
Marc Boucher9f113e02008-01-22 15:18:08 +01001303 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001304 case CONEXANT_HP_EVENT:
1305 cxt5047_hp_automute(codec);
1306 break;
1307 case CONEXANT_MIC_EVENT:
1308 cxt5047_hp_automic(codec);
1309 break;
1310 }
1311}
1312
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001313static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001314 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1315 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001316 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001317 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1318 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1319 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1320 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001321 {
1322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1323 .name = "Master Playback Switch",
1324 .info = cxt_eapd_info,
1325 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326 .put = cxt5047_hp_master_sw_put,
1327 .private_value = 0x13,
1328 },
1329
1330 {}
1331};
1332
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001333static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001334 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001335 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001336 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1337 {}
1338};
1339
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001340static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001341 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001342 { } /* end */
1343};
1344
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001345static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 /* Line in, Mic, Built-in Mic */
1347 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1348 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1349 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001350 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001351 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001352 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1353 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001354 /* Record selector: Mic */
1355 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1356 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1357 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1358 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001359 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1360 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1361 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1362 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001363 /* SPDIF route: PCM */
1364 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001365 /* Enable unsolicited events */
1366 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1367 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001368 { } /* end */
1369};
1370
1371/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001372static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001373 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001374 {}
1375};
1376
1377/* Test configuration for debugging, modelled after the ALC260 test
1378 * configuration.
1379 */
1380#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001381static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001382 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001383 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001384 { "LINE1 pin", 0x0 },
1385 { "MIC1 pin", 0x1 },
1386 { "MIC2 pin", 0x2 },
1387 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388 },
1389};
1390
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001391static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001392
1393 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001394 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1396 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001398 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001402 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1404 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406
1407 /* Modes for retasking pin widgets */
1408 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1409 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1410
Tobin Davis82f30042007-02-13 12:45:44 +01001411 /* EAPD Switch Control */
1412 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1413
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001415 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1416 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1417 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1418 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1419 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1420 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1421 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1422 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001423
Tobin Davis82f30042007-02-13 12:45:44 +01001424 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1425 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1427 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1429 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1430 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1431 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001432 {
1433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1434 .name = "Input Source",
1435 .info = conexant_mux_enum_info,
1436 .get = conexant_mux_enum_get,
1437 .put = conexant_mux_enum_put,
1438 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001439 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001440
Tobin Davisc9b443d2006-11-14 12:13:39 +01001441 { } /* end */
1442};
1443
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001444static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445 /* Enable retasking pins as output, initially without power amp */
1446 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1448 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1449
1450 /* Disable digital (SPDIF) pins initially, but users can enable
1451 * them via a mixer switch. In the case of SPDIF-out, this initverb
1452 * payload also sets the generation to 0, output to be in "consumer"
1453 * PCM format, copyright asserted, no pre-emphasis and no validity
1454 * control.
1455 */
1456 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1457
1458 /* Ensure mic1, mic2, line1 pin widgets take input from the
1459 * OUT1 sum bus when acting as an output.
1460 */
1461 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1462 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1463
1464 /* Start with output sum widgets muted and their output gains at min */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1467
1468 /* Unmute retasking pin widget output buffers since the default
1469 * state appears to be output. As the pin mode is changed by the
1470 * user the pin mode control will take care of enabling the pin's
1471 * input/output buffers as needed.
1472 */
1473 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1475 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1476
1477 /* Mute capture amp left and right */
1478 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1479
1480 /* Set ADC connection select to match default mixer setting (mic1
1481 * pin)
1482 */
1483 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1484
1485 /* Mute all inputs to mixer widget (even unconnected ones) */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1492 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1494
1495 { }
1496};
1497#endif
1498
1499
1500/* initialize jack-sensing, too */
1501static int cxt5047_hp_init(struct hda_codec *codec)
1502{
1503 conexant_init(codec);
1504 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001505 return 0;
1506}
1507
1508
1509enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001510 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1511 CXT5047_LAPTOP_HP, /* Some HP laptops */
1512 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001513#ifdef CONFIG_SND_DEBUG
1514 CXT5047_TEST,
1515#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001516 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001517 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001518};
1519
Takashi Iwaiea734962011-01-17 11:29:34 +01001520static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001521 [CXT5047_LAPTOP] = "laptop",
1522 [CXT5047_LAPTOP_HP] = "laptop-hp",
1523 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001525 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001526#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001527 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001528};
1529
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001530static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001531 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001532 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1533 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001534 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001535 {}
1536};
1537
1538static int patch_cxt5047(struct hda_codec *codec)
1539{
1540 struct conexant_spec *spec;
1541 int board_config;
1542
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001543 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1544 cxt5047_models,
1545 cxt5047_cfg_tbl);
1546#if 0 /* not enabled as default, as BIOS often broken for this codec */
1547 if (board_config < 0)
1548 board_config = CXT5047_AUTO;
1549#endif
1550 if (board_config == CXT5047_AUTO)
1551 return patch_conexant_auto(codec);
1552
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1554 if (!spec)
1555 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001556 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001557 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558
1559 spec->multiout.max_channels = 2;
1560 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1561 spec->multiout.dac_nids = cxt5047_dac_nids;
1562 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1563 spec->num_adc_nids = 1;
1564 spec->adc_nids = cxt5047_adc_nids;
1565 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001566 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001567 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001568 spec->num_init_verbs = 1;
1569 spec->init_verbs[0] = cxt5047_init_verbs;
1570 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001571 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1572 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001573
1574 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576 switch (board_config) {
1577 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001578 spec->num_mixers = 2;
1579 spec->mixers[1] = cxt5047_hp_spk_mixers;
1580 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001581 break;
1582 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001583 spec->num_mixers = 2;
1584 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001585 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001586 codec->patch_ops.init = cxt5047_hp_init;
1587 break;
1588 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001589 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001590 spec->num_mixers = 2;
1591 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592 spec->num_init_verbs = 2;
1593 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001594 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001595 break;
1596#ifdef CONFIG_SND_DEBUG
1597 case CXT5047_TEST:
1598 spec->input_mux = &cxt5047_test_capture_source;
1599 spec->mixers[0] = cxt5047_test_mixer;
1600 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001601 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001602#endif
1603 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001604 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001605
1606 switch (codec->subsystem_id >> 16) {
1607 case 0x103c:
1608 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1609 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1610 * with 0 dB offset 0x17)
1611 */
1612 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1613 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1614 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1615 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1616 (1 << AC_AMPCAP_MUTE_SHIFT));
1617 break;
1618 }
1619
Tobin Davisc9b443d2006-11-14 12:13:39 +01001620 return 0;
1621}
1622
Takashi Iwai461e2c72008-01-25 11:35:17 +01001623/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001624static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1625static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001626
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001627static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001628 { 2, NULL },
1629};
1630
1631static void cxt5051_update_speaker(struct hda_codec *codec)
1632{
1633 struct conexant_spec *spec = codec->spec;
1634 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001635 /* headphone pin */
1636 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1637 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1638 pinctl);
1639 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001640 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1641 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1642 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001643 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1644 if (spec->ideapad)
1645 snd_hda_codec_write(codec, 0x1b, 0,
1646 AC_VERB_SET_PIN_WIDGET_CONTROL,
1647 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001648}
1649
1650/* turn on/off EAPD (+ mute HP) as a master switch */
1651static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1652 struct snd_ctl_elem_value *ucontrol)
1653{
1654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1655
1656 if (!cxt_eapd_put(kcontrol, ucontrol))
1657 return 0;
1658 cxt5051_update_speaker(codec);
1659 return 1;
1660}
1661
1662/* toggle input of built-in and mic jack appropriately */
1663static void cxt5051_portb_automic(struct hda_codec *codec)
1664{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001665 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001666 unsigned int present;
1667
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001668 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001669 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001670 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001671 snd_hda_codec_write(codec, 0x14, 0,
1672 AC_VERB_SET_CONNECT_SEL,
1673 present ? 0x01 : 0x00);
1674}
1675
1676/* switch the current ADC according to the jack state */
1677static void cxt5051_portc_automic(struct hda_codec *codec)
1678{
1679 struct conexant_spec *spec = codec->spec;
1680 unsigned int present;
1681 hda_nid_t new_adc;
1682
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001683 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001684 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001685 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001686 if (present)
1687 spec->cur_adc_idx = 1;
1688 else
1689 spec->cur_adc_idx = 0;
1690 new_adc = spec->adc_nids[spec->cur_adc_idx];
1691 if (spec->cur_adc && spec->cur_adc != new_adc) {
1692 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001693 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001694 spec->cur_adc = new_adc;
1695 snd_hda_codec_setup_stream(codec, new_adc,
1696 spec->cur_adc_stream_tag, 0,
1697 spec->cur_adc_format);
1698 }
1699}
1700
1701/* mute internal speaker if HP is plugged */
1702static void cxt5051_hp_automute(struct hda_codec *codec)
1703{
1704 struct conexant_spec *spec = codec->spec;
1705
Takashi Iwaid56757a2009-11-18 08:00:14 +01001706 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001707 cxt5051_update_speaker(codec);
1708}
1709
1710/* unsolicited event for HP jack sensing */
1711static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1712 unsigned int res)
1713{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001714 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 switch (res >> 26) {
1716 case CONEXANT_HP_EVENT:
1717 cxt5051_hp_automute(codec);
1718 break;
1719 case CXT5051_PORTB_EVENT:
1720 cxt5051_portb_automic(codec);
1721 break;
1722 case CXT5051_PORTC_EVENT:
1723 cxt5051_portc_automic(codec);
1724 break;
1725 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001726 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001727}
1728
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001729static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001730 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1731 {
1732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1733 .name = "Master Playback Switch",
1734 .info = cxt_eapd_info,
1735 .get = cxt_eapd_get,
1736 .put = cxt5051_hp_master_sw_put,
1737 .private_value = 0x1a,
1738 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001739 {}
1740};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001741
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001742static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001743 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1744 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001745 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1746 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001747 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1748 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749 {}
1750};
1751
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001752static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001753 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1754 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001755 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1756 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001757 {}
1758};
1759
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001760static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac6002010-01-23 22:29:54 +01001761 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1762 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001763 {}
1764};
1765
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001766static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001767 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1768 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001769 {}
1770};
1771
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001772static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001773 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1774 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001775 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1776 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001777 {}
1778};
1779
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001780static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001781 /* Line in, Mic */
1782 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1783 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1784 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1785 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1786 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1787 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1788 /* SPK */
1789 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1790 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1791 /* HP, Amp */
1792 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1793 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1794 /* DAC1 */
1795 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001796 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001797 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1798 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1799 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1800 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001801 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001802 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1803 /* EAPD */
1804 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1805 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001806 { } /* end */
1807};
1808
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001809static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001810 /* Line in, Mic */
1811 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1812 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1813 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1814 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1815 /* SPK */
1816 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1817 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1818 /* HP, Amp */
1819 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1820 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1821 /* DAC1 */
1822 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001823 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1825 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1826 /* SPDIF route: PCM */
1827 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1828 /* EAPD */
1829 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1830 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001831 { } /* end */
1832};
1833
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001834static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001835 /* Line in, Mic */
1836 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1837 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1838 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1839 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1840 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1841 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1842 /* SPK */
1843 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1844 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1845 /* HP, Amp */
1846 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1847 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1848 /* Docking HP */
1849 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1850 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1851 /* DAC1 */
1852 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001853 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001854 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1856 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1857 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001858 {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 -05001859 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1860 /* EAPD */
1861 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1862 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001863 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1864 { } /* end */
1865};
1866
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001867static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001868 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001870 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1871 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1872 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1873 /* SPK */
1874 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1876 /* HP, Amp */
1877 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1878 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1879 /* DAC1 */
1880 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001881 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001882 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1883 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1884 /* SPDIF route: PCM */
1885 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1886 /* EAPD */
1887 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1888 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001889 { } /* end */
1890};
1891
Takashi Iwai6953e552010-01-24 11:00:27 +01001892static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1893 unsigned int event)
1894{
1895 snd_hda_codec_write(codec, nid, 0,
1896 AC_VERB_SET_UNSOLICITED_ENABLE,
1897 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001898 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1899 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001900}
1901
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001902static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001903 /* Subwoofer */
1904 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1905 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1906 { } /* end */
1907};
1908
Takashi Iwai461e2c72008-01-25 11:35:17 +01001909/* initialize jack-sensing, too */
1910static int cxt5051_init(struct hda_codec *codec)
1911{
Takashi Iwai6953e552010-01-24 11:00:27 +01001912 struct conexant_spec *spec = codec->spec;
1913
Takashi Iwai461e2c72008-01-25 11:35:17 +01001914 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001915 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001916
1917 if (spec->auto_mic & AUTO_MIC_PORTB)
1918 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1919 if (spec->auto_mic & AUTO_MIC_PORTC)
1920 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1921
Takashi Iwai461e2c72008-01-25 11:35:17 +01001922 if (codec->patch_ops.unsol_event) {
1923 cxt5051_hp_automute(codec);
1924 cxt5051_portb_automic(codec);
1925 cxt5051_portc_automic(codec);
1926 }
1927 return 0;
1928}
1929
1930
1931enum {
1932 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1933 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001934 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001935 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001936 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001937 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001938 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001939 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001940 CXT5051_MODELS
1941};
1942
Takashi Iwaiea734962011-01-17 11:29:34 +01001943static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001944 [CXT5051_LAPTOP] = "laptop",
1945 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001946 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001947 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001948 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001949 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001950 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001951 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001952};
1953
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001954static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001955 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001956 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001957 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001958 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001959 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1960 CXT5051_LAPTOP),
1961 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001962 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001963 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001964 {}
1965};
1966
1967static int patch_cxt5051(struct hda_codec *codec)
1968{
1969 struct conexant_spec *spec;
1970 int board_config;
1971
Takashi Iwai6764bce2011-05-13 16:52:25 +02001972 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1973 cxt5051_models,
1974 cxt5051_cfg_tbl);
1975 if (board_config < 0)
1976 board_config = CXT5051_AUTO;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001977 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001978 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001979
Takashi Iwai461e2c72008-01-25 11:35:17 +01001980 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1981 if (!spec)
1982 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001983 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001984 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001985
1986 codec->patch_ops = conexant_patch_ops;
1987 codec->patch_ops.init = cxt5051_init;
1988
1989 spec->multiout.max_channels = 2;
1990 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1991 spec->multiout.dac_nids = cxt5051_dac_nids;
1992 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1993 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1994 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001995 spec->num_mixers = 2;
1996 spec->mixers[0] = cxt5051_capture_mixers;
1997 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001998 spec->num_init_verbs = 1;
1999 spec->init_verbs[0] = cxt5051_init_verbs;
2000 spec->spdif_route = 0;
2001 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2002 spec->channel_mode = cxt5051_modes;
2003 spec->cur_adc = 0;
2004 spec->cur_adc_idx = 0;
2005
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002006 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2007
Takashi Iwai79d7d532009-03-04 09:03:50 +01002008 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2009
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002010 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002011 switch (board_config) {
2012 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002013 spec->mixers[0] = cxt5051_hp_mixers;
2014 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002015 case CXT5051_HP_DV6736:
2016 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2017 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002018 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002019 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002020 case CXT5051_LENOVO_X200:
2021 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002022 /* Thinkpad X301 does not have S/PDIF wired and no ability
2023 to use a docking station. */
2024 if (codec->subsystem_id == 0x17aa211f)
2025 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002026 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002027 case CXT5051_F700:
2028 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2029 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002030 spec->auto_mic = 0;
2031 break;
2032 case CXT5051_TOSHIBA:
2033 spec->mixers[0] = cxt5051_toshiba_mixers;
2034 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002035 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002036 case CXT5051_IDEAPAD:
2037 spec->init_verbs[spec->num_init_verbs++] =
2038 cxt5051_ideapad_init_verbs;
2039 spec->ideapad = 1;
2040 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002041 }
2042
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002043 if (spec->beep_amp)
2044 snd_hda_attach_beep_device(codec, spec->beep_amp);
2045
Takashi Iwai461e2c72008-01-25 11:35:17 +01002046 return 0;
2047}
2048
Daniel Drake0fb67e92009-07-16 14:46:57 +01002049/* Conexant 5066 specific */
2050
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002051static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2052static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2053static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2054static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002055
Daniel Drakedbaccc02009-11-09 15:17:24 +00002056/* OLPC's microphone port is DC coupled for use with external sensors,
2057 * therefore we use a 50% mic bias in order to center the input signal with
2058 * the DC input range of the codec. */
2059#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2060
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002061static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002062 { 2, NULL },
2063};
2064
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002065#define HP_PRESENT_PORT_A (1 << 0)
2066#define HP_PRESENT_PORT_D (1 << 1)
2067#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2068#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2069
Daniel Drake0fb67e92009-07-16 14:46:57 +01002070static void cxt5066_update_speaker(struct hda_codec *codec)
2071{
2072 struct conexant_spec *spec = codec->spec;
2073 unsigned int pinctl;
2074
John Baboval3a253442010-12-02 11:21:31 -05002075 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2076 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002077
2078 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002079 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002080 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2081 pinctl);
2082
2083 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002084 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2085 if (spec->dell_automute || spec->thinkpad) {
2086 /* Mute if Port A is connected */
2087 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002088 pinctl = 0;
2089 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002090 /* Thinkpad/Dell doesn't give pin-D status */
2091 if (!hp_port_d_present(spec))
2092 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002093 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002094 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2095 pinctl);
2096
2097 /* CLASS_D AMP */
2098 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2099 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2100 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002101}
2102
2103/* turn on/off EAPD (+ mute HP) as a master switch */
2104static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2105 struct snd_ctl_elem_value *ucontrol)
2106{
2107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2108
2109 if (!cxt_eapd_put(kcontrol, ucontrol))
2110 return 0;
2111
2112 cxt5066_update_speaker(codec);
2113 return 1;
2114}
2115
Daniel Drakec4cfe662010-01-07 13:47:04 +01002116static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2117 .num_items = 3,
2118 .items = {
2119 { "Off", PIN_IN },
2120 { "50%", PIN_VREF50 },
2121 { "80%", PIN_VREF80 },
2122 },
2123};
2124
2125static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2126{
2127 struct conexant_spec *spec = codec->spec;
2128 /* Even though port F is the DC input, the bias is controlled on port B.
2129 * we also leave that port as an active input (but unselected) in DC mode
2130 * just in case that is necessary to make the bias setting take effect. */
2131 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2132 AC_VERB_SET_PIN_WIDGET_CONTROL,
2133 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2134}
2135
Daniel Drake75f89912010-01-07 13:46:25 +01002136/* OLPC defers mic widget control until when capture is started because the
2137 * microphone LED comes on as soon as these settings are put in place. if we
2138 * did this before recording, it would give the false indication that recording
2139 * is happening when it is not. */
2140static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002141{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002142 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002143 if (!spec->recording)
2144 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002145
Daniel Drakec4cfe662010-01-07 13:47:04 +01002146 if (spec->dc_enable) {
2147 /* in DC mode we ignore presence detection and just use the jack
2148 * through our special DC port */
2149 const struct hda_verb enable_dc_mode[] = {
2150 /* disble internal mic, port C */
2151 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2152
2153 /* enable DC capture, port F */
2154 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2155 {},
2156 };
2157
2158 snd_hda_sequence_write(codec, enable_dc_mode);
2159 /* port B input disabled (and bias set) through the following call */
2160 cxt5066_set_olpc_dc_bias(codec);
2161 return;
2162 }
2163
2164 /* disable DC (port F) */
2165 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2166
Daniel Drake75f89912010-01-07 13:46:25 +01002167 /* external mic, port B */
2168 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2169 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002170
Daniel Drake75f89912010-01-07 13:46:25 +01002171 /* internal mic, port C */
2172 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2173 spec->ext_mic_present ? 0 : PIN_VREF80);
2174}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002175
Daniel Drake75f89912010-01-07 13:46:25 +01002176/* toggle input of built-in and mic jack appropriately */
2177static void cxt5066_olpc_automic(struct hda_codec *codec)
2178{
2179 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002180 unsigned int present;
2181
Daniel Drakec4cfe662010-01-07 13:47:04 +01002182 if (spec->dc_enable) /* don't do presence detection in DC mode */
2183 return;
2184
Daniel Drake75f89912010-01-07 13:46:25 +01002185 present = snd_hda_codec_read(codec, 0x1a, 0,
2186 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2187 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002188 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002189 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002190 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002191
2192 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2193 present ? 0 : 1);
2194 spec->ext_mic_present = !!present;
2195
2196 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002197}
2198
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002199/* toggle input of built-in digital mic and mic jack appropriately */
2200static void cxt5066_vostro_automic(struct hda_codec *codec)
2201{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002202 unsigned int present;
2203
2204 struct hda_verb ext_mic_present[] = {
2205 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002206 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002207
2208 /* switch to external mic input */
2209 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2210 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2211
2212 /* disable internal digital mic */
2213 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2214 {}
2215 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002216 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002217 /* enable internal mic, port C */
2218 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2219
2220 /* switch to internal mic input */
2221 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2222
2223 /* disable external mic, port B */
2224 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2225 {}
2226 };
2227
2228 present = snd_hda_jack_detect(codec, 0x1a);
2229 if (present) {
2230 snd_printdd("CXT5066: external microphone detected\n");
2231 snd_hda_sequence_write(codec, ext_mic_present);
2232 } else {
2233 snd_printdd("CXT5066: external microphone absent\n");
2234 snd_hda_sequence_write(codec, ext_mic_absent);
2235 }
2236}
2237
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002238/* toggle input of built-in digital mic and mic jack appropriately */
2239static void cxt5066_ideapad_automic(struct hda_codec *codec)
2240{
2241 unsigned int present;
2242
2243 struct hda_verb ext_mic_present[] = {
2244 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2245 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2246 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2247 {}
2248 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002249 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002250 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2251 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2252 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2253 {}
2254 };
2255
2256 present = snd_hda_jack_detect(codec, 0x1b);
2257 if (present) {
2258 snd_printdd("CXT5066: external microphone detected\n");
2259 snd_hda_sequence_write(codec, ext_mic_present);
2260 } else {
2261 snd_printdd("CXT5066: external microphone absent\n");
2262 snd_hda_sequence_write(codec, ext_mic_absent);
2263 }
2264}
2265
David Henningssona1d69062011-01-21 13:33:28 +01002266
2267/* toggle input of built-in digital mic and mic jack appropriately */
2268static void cxt5066_asus_automic(struct hda_codec *codec)
2269{
2270 unsigned int present;
2271
2272 present = snd_hda_jack_detect(codec, 0x1b);
2273 snd_printdd("CXT5066: external microphone present=%d\n", present);
2274 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2275 present ? 1 : 0);
2276}
2277
2278
David Henningsson048e78a2010-09-02 08:35:47 +02002279/* toggle input of built-in digital mic and mic jack appropriately */
2280static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2281{
2282 unsigned int present;
2283
2284 present = snd_hda_jack_detect(codec, 0x1b);
2285 snd_printdd("CXT5066: external microphone present=%d\n", present);
2286 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2287 present ? 1 : 3);
2288}
2289
2290
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002291/* toggle input of built-in digital mic and mic jack appropriately
2292 order is: external mic -> dock mic -> interal mic */
2293static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2294{
2295 unsigned int ext_present, dock_present;
2296
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002297 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002298 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2299 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2300 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2301 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2302 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2303 {}
2304 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002305 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002306 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2307 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2308 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2309 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2310 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2311 {}
2312 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002313 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002314 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2315 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2316 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2317 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2318 {}
2319 };
2320
2321 ext_present = snd_hda_jack_detect(codec, 0x1b);
2322 dock_present = snd_hda_jack_detect(codec, 0x1a);
2323 if (ext_present) {
2324 snd_printdd("CXT5066: external microphone detected\n");
2325 snd_hda_sequence_write(codec, ext_mic_present);
2326 } else if (dock_present) {
2327 snd_printdd("CXT5066: dock microphone detected\n");
2328 snd_hda_sequence_write(codec, dock_mic_present);
2329 } else {
2330 snd_printdd("CXT5066: external microphone absent\n");
2331 snd_hda_sequence_write(codec, ext_mic_absent);
2332 }
2333}
2334
Daniel Drake0fb67e92009-07-16 14:46:57 +01002335/* mute internal speaker if HP is plugged */
2336static void cxt5066_hp_automute(struct hda_codec *codec)
2337{
2338 struct conexant_spec *spec = codec->spec;
2339 unsigned int portA, portD;
2340
2341 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002342 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002343
2344 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002345 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002346
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002347 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2348 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002349 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2350 portA, portD, spec->hp_present);
2351 cxt5066_update_speaker(codec);
2352}
2353
David Henningsson02b6b5b2011-01-21 13:27:39 +01002354/* Dispatch the right mic autoswitch function */
2355static void cxt5066_automic(struct hda_codec *codec)
2356{
2357 struct conexant_spec *spec = codec->spec;
2358
2359 if (spec->dell_vostro)
2360 cxt5066_vostro_automic(codec);
2361 else if (spec->ideapad)
2362 cxt5066_ideapad_automic(codec);
2363 else if (spec->thinkpad)
2364 cxt5066_thinkpad_automic(codec);
2365 else if (spec->hp_laptop)
2366 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002367 else if (spec->asus)
2368 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002369}
2370
Daniel Drake0fb67e92009-07-16 14:46:57 +01002371/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002372static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002373{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002374 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002375 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2376 switch (res >> 26) {
2377 case CONEXANT_HP_EVENT:
2378 cxt5066_hp_automute(codec);
2379 break;
2380 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002381 /* ignore mic events in DC mode; we're always using the jack */
2382 if (!spec->dc_enable)
2383 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002384 break;
2385 }
2386}
2387
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002388/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002389static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002390{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002391 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002392 switch (res >> 26) {
2393 case CONEXANT_HP_EVENT:
2394 cxt5066_hp_automute(codec);
2395 break;
2396 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002397 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002398 break;
2399 }
2400}
2401
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002402
Daniel Drake0fb67e92009-07-16 14:46:57 +01002403static const struct hda_input_mux cxt5066_analog_mic_boost = {
2404 .num_items = 5,
2405 .items = {
2406 { "0dB", 0 },
2407 { "10dB", 1 },
2408 { "20dB", 2 },
2409 { "30dB", 3 },
2410 { "40dB", 4 },
2411 },
2412};
2413
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002414static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002415{
2416 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002417 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002418 AC_VERB_SET_AMP_GAIN_MUTE,
2419 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2420 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002421 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002422 /* adjust the internal mic as well...it is not through 0x17 */
2423 snd_hda_codec_write_cache(codec, 0x23, 0,
2424 AC_VERB_SET_AMP_GAIN_MUTE,
2425 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2426 cxt5066_analog_mic_boost.
2427 items[spec->mic_boost].index);
2428 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002429}
2430
Daniel Drake0fb67e92009-07-16 14:46:57 +01002431static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2432 struct snd_ctl_elem_info *uinfo)
2433{
2434 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2435}
2436
2437static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2438 struct snd_ctl_elem_value *ucontrol)
2439{
2440 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002441 struct conexant_spec *spec = codec->spec;
2442 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002443 return 0;
2444}
2445
2446static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2447 struct snd_ctl_elem_value *ucontrol)
2448{
2449 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002450 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002451 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2452 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002453 idx = ucontrol->value.enumerated.item[0];
2454 if (idx >= imux->num_items)
2455 idx = imux->num_items - 1;
2456
Daniel Drakec4cfe662010-01-07 13:47:04 +01002457 spec->mic_boost = idx;
2458 if (!spec->dc_enable)
2459 cxt5066_set_mic_boost(codec);
2460 return 1;
2461}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002462
Daniel Drakec4cfe662010-01-07 13:47:04 +01002463static void cxt5066_enable_dc(struct hda_codec *codec)
2464{
2465 const struct hda_verb enable_dc_mode[] = {
2466 /* disable gain */
2467 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2468
2469 /* switch to DC input */
2470 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2471 {}
2472 };
2473
2474 /* configure as input source */
2475 snd_hda_sequence_write(codec, enable_dc_mode);
2476 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2477}
2478
2479static void cxt5066_disable_dc(struct hda_codec *codec)
2480{
2481 /* reconfigure input source */
2482 cxt5066_set_mic_boost(codec);
2483 /* automic also selects the right mic if we're recording */
2484 cxt5066_olpc_automic(codec);
2485}
2486
2487static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2488 struct snd_ctl_elem_value *ucontrol)
2489{
2490 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2491 struct conexant_spec *spec = codec->spec;
2492 ucontrol->value.integer.value[0] = spec->dc_enable;
2493 return 0;
2494}
2495
2496static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2497 struct snd_ctl_elem_value *ucontrol)
2498{
2499 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2500 struct conexant_spec *spec = codec->spec;
2501 int dc_enable = !!ucontrol->value.integer.value[0];
2502
2503 if (dc_enable == spec->dc_enable)
2504 return 0;
2505
2506 spec->dc_enable = dc_enable;
2507 if (dc_enable)
2508 cxt5066_enable_dc(codec);
2509 else
2510 cxt5066_disable_dc(codec);
2511
2512 return 1;
2513}
2514
2515static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2516 struct snd_ctl_elem_info *uinfo)
2517{
2518 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2519}
2520
2521static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2522 struct snd_ctl_elem_value *ucontrol)
2523{
2524 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2525 struct conexant_spec *spec = codec->spec;
2526 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2527 return 0;
2528}
2529
2530static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2531 struct snd_ctl_elem_value *ucontrol)
2532{
2533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2534 struct conexant_spec *spec = codec->spec;
2535 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2536 unsigned int idx;
2537
2538 idx = ucontrol->value.enumerated.item[0];
2539 if (idx >= imux->num_items)
2540 idx = imux->num_items - 1;
2541
2542 spec->dc_input_bias = idx;
2543 if (spec->dc_enable)
2544 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002545 return 1;
2546}
2547
Daniel Drake75f89912010-01-07 13:46:25 +01002548static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2549{
2550 struct conexant_spec *spec = codec->spec;
2551 /* mark as recording and configure the microphone widget so that the
2552 * recording LED comes on. */
2553 spec->recording = 1;
2554 cxt5066_olpc_select_mic(codec);
2555}
2556
2557static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2558{
2559 struct conexant_spec *spec = codec->spec;
2560 const struct hda_verb disable_mics[] = {
2561 /* disable external mic, port B */
2562 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2563
2564 /* disble internal mic, port C */
2565 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002566
2567 /* disable DC capture, port F */
2568 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002569 {},
2570 };
2571
2572 snd_hda_sequence_write(codec, disable_mics);
2573 spec->recording = 0;
2574}
2575
Andy Robinsonf6a24912011-01-24 10:12:37 -05002576static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002577 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002578 int num_pins)
2579{
2580 struct conexant_spec *spec = codec->spec;
2581 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2582 int i;
2583
2584 for (i = 0; i < num_pins; i++, dig_pins++) {
2585 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2586 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2587 continue;
2588 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2589 continue;
2590 if (spec->slave_dig_outs[0])
2591 nid_loc++;
2592 else
2593 nid_loc = spec->slave_dig_outs;
2594 }
2595}
2596
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002597static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002598 .num_items = 4,
2599 .items = {
2600 { "Mic B", 0 },
2601 { "Mic C", 1 },
2602 { "Mic E", 2 },
2603 { "Mic F", 3 },
2604 },
2605};
2606
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002607static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002608 .ops = &snd_hda_bind_vol,
2609 .values = {
2610 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2611 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2612 0
2613 },
2614};
2615
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002616static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002617 .ops = &snd_hda_bind_sw,
2618 .values = {
2619 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2620 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2621 0
2622 },
2623};
2624
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002625static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002626 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2627 {}
2628};
2629
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002630static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002631 {
2632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2633 .name = "Master Playback Volume",
2634 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2635 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2636 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002637 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002638 .info = snd_hda_mixer_amp_volume_info,
2639 .get = snd_hda_mixer_amp_volume_get,
2640 .put = snd_hda_mixer_amp_volume_put,
2641 .tlv = { .c = snd_hda_mixer_amp_tlv },
2642 /* offset by 28 volume steps to limit minimum gain to -46dB */
2643 .private_value =
2644 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2645 },
2646 {}
2647};
2648
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002649static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002650 {
2651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2652 .name = "DC Mode Enable Switch",
2653 .info = snd_ctl_boolean_mono_info,
2654 .get = cxt5066_olpc_dc_get,
2655 .put = cxt5066_olpc_dc_put,
2656 },
2657 {
2658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2659 .name = "DC Input Bias Enum",
2660 .info = cxt5066_olpc_dc_bias_enum_info,
2661 .get = cxt5066_olpc_dc_bias_enum_get,
2662 .put = cxt5066_olpc_dc_bias_enum_put,
2663 },
2664 {}
2665};
2666
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002667static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002668 {
2669 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2670 .name = "Master Playback Switch",
2671 .info = cxt_eapd_info,
2672 .get = cxt_eapd_get,
2673 .put = cxt5066_hp_master_sw_put,
2674 .private_value = 0x1d,
2675 },
2676
2677 {
2678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002679 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002680 .info = cxt5066_mic_boost_mux_enum_info,
2681 .get = cxt5066_mic_boost_mux_enum_get,
2682 .put = cxt5066_mic_boost_mux_enum_put,
2683 },
2684
2685 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2686 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2687 {}
2688};
2689
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002690static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002691 {
2692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002693 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002694 .info = cxt5066_mic_boost_mux_enum_info,
2695 .get = cxt5066_mic_boost_mux_enum_get,
2696 .put = cxt5066_mic_boost_mux_enum_put,
2697 .private_value = 0x23 | 0x100,
2698 },
2699 {}
2700};
2701
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002702static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002703 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2704 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2705 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2706 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2707
2708 /* Speakers */
2709 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2710 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2711
2712 /* HP, Amp */
2713 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2714 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2715
2716 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2717 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2718
2719 /* DAC1 */
2720 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2721
2722 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2723 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2724 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2725 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2726 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2727 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2728
2729 /* no digital microphone support yet */
2730 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731
2732 /* Audio input selector */
2733 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2734
2735 /* SPDIF route: PCM */
2736 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2737 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2738
2739 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2740 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2741
2742 /* EAPD */
2743 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2744
2745 /* not handling these yet */
2746 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2747 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2748 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2749 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2750 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2751 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2752 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2753 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2754 { } /* end */
2755};
2756
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002757static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002758 /* Port A: headphones */
2759 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2760 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2761
2762 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002763 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002764
2765 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002766 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002767
2768 /* Port D: unused */
2769 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2770
2771 /* Port E: unused, but has primary EAPD */
2772 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2773 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2774
Daniel Drakec4cfe662010-01-07 13:47:04 +01002775 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002776 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2777
2778 /* Port G: internal speakers */
2779 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2780 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2781
2782 /* DAC1 */
2783 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2784
2785 /* DAC2: unused */
2786 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2787
2788 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2790 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2791 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2792 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2793 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2794 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2795 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2796 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2797 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2798 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2799 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2800
2801 /* Disable digital microphone port */
2802 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2803
2804 /* Audio input selectors */
2805 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2806 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2807
2808 /* Disable SPDIF */
2809 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2810 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2811
2812 /* enable unsolicited events for Port A and B */
2813 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2814 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2815 { } /* end */
2816};
2817
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002818static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002819 /* Port A: headphones */
2820 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2822
2823 /* Port B: external microphone */
2824 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2825
2826 /* Port C: unused */
2827 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2828
2829 /* Port D: unused */
2830 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831
2832 /* Port E: unused, but has primary EAPD */
2833 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2834 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2835
2836 /* Port F: unused */
2837 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2838
2839 /* Port G: internal speakers */
2840 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2841 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2842
2843 /* DAC1 */
2844 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2845
2846 /* DAC2: unused */
2847 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2848
2849 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2853 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2854 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2855 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2856 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2857 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2858 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2859 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2860 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2861
2862 /* Digital microphone port */
2863 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2864
2865 /* Audio input selectors */
2866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2867 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2868
2869 /* Disable SPDIF */
2870 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2871 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2872
2873 /* enable unsolicited events for Port A and B */
2874 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2875 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2876 { } /* end */
2877};
2878
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002879static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002880 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2881 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2882 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2883 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2884
2885 /* Speakers */
2886 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2887 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2888
2889 /* HP, Amp */
2890 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2891 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2892
2893 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2894 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2895
2896 /* DAC1 */
2897 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2898
2899 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2900 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2901 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2902 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2903 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2905 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2906
2907 /* Audio input selector */
2908 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2909 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2910
2911 /* SPDIF route: PCM */
2912 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2913 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2914
2915 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2916 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2917
2918 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002919 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002920
2921 /* EAPD */
2922 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2923
2924 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2925 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2926 { } /* end */
2927};
2928
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002929static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002930 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2931 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2932
2933 /* Port G: internal speakers */
2934 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2935 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2936
2937 /* Port A: HP, Amp */
2938 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2939 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2940
2941 /* Port B: Mic Dock */
2942 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2943
2944 /* Port C: Mic */
2945 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2946
2947 /* Port D: HP Dock, Amp */
2948 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2949 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2950
2951 /* DAC1 */
2952 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2953
2954 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2955 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2956 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2957 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2958 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2959 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2960 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2961
2962 /* Audio input selector */
2963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2964 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2965
2966 /* SPDIF route: PCM */
2967 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2968 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2969
2970 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2971 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2972
2973 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002974 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002975
2976 /* EAPD */
2977 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2978
2979 /* enable unsolicited events for Port A, B, C and D */
2980 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2981 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2982 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2983 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2984 { } /* end */
2985};
2986
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002987static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002988 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2989 { } /* end */
2990};
2991
David Henningsson048e78a2010-09-02 08:35:47 +02002992
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002993static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002994 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2995 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2996 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2997 { } /* end */
2998};
2999
Daniel Drake0fb67e92009-07-16 14:46:57 +01003000/* initialize jack-sensing, too */
3001static int cxt5066_init(struct hda_codec *codec)
3002{
3003 snd_printdd("CXT5066: init\n");
3004 conexant_init(codec);
3005 if (codec->patch_ops.unsol_event) {
3006 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003007 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003008 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003009 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003010 return 0;
3011}
3012
Daniel Drake75f89912010-01-07 13:46:25 +01003013static int cxt5066_olpc_init(struct hda_codec *codec)
3014{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003015 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003016 snd_printdd("CXT5066: init\n");
3017 conexant_init(codec);
3018 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003019 if (!spec->dc_enable) {
3020 cxt5066_set_mic_boost(codec);
3021 cxt5066_olpc_automic(codec);
3022 } else {
3023 cxt5066_enable_dc(codec);
3024 }
Daniel Drake75f89912010-01-07 13:46:25 +01003025 return 0;
3026}
3027
Daniel Drake0fb67e92009-07-16 14:46:57 +01003028enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003029 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003030 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3031 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003032 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003033 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003034 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003035 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003036 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003037 CXT5066_MODELS
3038};
3039
Takashi Iwaiea734962011-01-17 11:29:34 +01003040static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003041 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003042 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3043 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003044 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003045 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003046 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003047 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003048 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003049};
3050
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003051static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003052 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003053 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003054 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003055 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003056 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003057 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd224c2011-02-23 13:15:56 +01003058 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3059 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003060 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003061 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003062 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003063 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003064 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003065 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003066 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003067 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3068 CXT5066_LAPTOP),
3069 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003070 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003071 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003072 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003073 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003074 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003075 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003076 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003077 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003078 {}
3079};
3080
3081static int patch_cxt5066(struct hda_codec *codec)
3082{
3083 struct conexant_spec *spec;
3084 int board_config;
3085
3086 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3087 if (!spec)
3088 return -ENOMEM;
3089 codec->spec = spec;
3090
3091 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003092 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003093
3094 spec->dell_automute = 0;
3095 spec->multiout.max_channels = 2;
3096 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3097 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003098 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3099 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003100 spec->num_adc_nids = 1;
3101 spec->adc_nids = cxt5066_adc_nids;
3102 spec->capsrc_nids = cxt5066_capsrc_nids;
3103 spec->input_mux = &cxt5066_capture_source;
3104
3105 spec->port_d_mode = PIN_HP;
3106
3107 spec->num_init_verbs = 1;
3108 spec->init_verbs[0] = cxt5066_init_verbs;
3109 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3110 spec->channel_mode = cxt5066_modes;
3111 spec->cur_adc = 0;
3112 spec->cur_adc_idx = 0;
3113
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003114 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3115
Daniel Drake0fb67e92009-07-16 14:46:57 +01003116 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3117 cxt5066_models, cxt5066_cfg_tbl);
3118 switch (board_config) {
3119 default:
3120 case CXT5066_LAPTOP:
3121 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3122 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3123 break;
3124 case CXT5066_DELL_LAPTOP:
3125 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3126 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3127
3128 spec->port_d_mode = PIN_OUT;
3129 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3130 spec->num_init_verbs++;
3131 spec->dell_automute = 1;
3132 break;
David Henningssona1d69062011-01-21 13:33:28 +01003133 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003134 case CXT5066_HP_LAPTOP:
3135 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003136 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003137 spec->init_verbs[spec->num_init_verbs] =
3138 cxt5066_init_verbs_hp_laptop;
3139 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003140 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3141 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003142 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3143 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3144 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003145 if (board_config == CXT5066_HP_LAPTOP)
3146 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003147 /* input source automatically selected */
3148 spec->input_mux = NULL;
3149 spec->port_d_mode = 0;
3150 spec->mic_boost = 3; /* default 30dB gain */
3151 break;
3152
Daniel Drake0fb67e92009-07-16 14:46:57 +01003153 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003154 codec->patch_ops.init = cxt5066_olpc_init;
3155 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003156 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3157 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003158 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003159 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3160 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003161 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003162
3163 /* no S/PDIF out */
3164 spec->multiout.dig_out_nid = 0;
3165
3166 /* input source automatically selected */
3167 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003168
3169 /* our capture hooks which allow us to turn on the microphone LED
3170 * at the right time */
3171 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3172 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003173 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003174 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003175 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003176 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003177 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3178 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3179 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003180 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003181 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003182 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003183 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003184
3185 /* no S/PDIF out */
3186 spec->multiout.dig_out_nid = 0;
3187
3188 /* input source automatically selected */
3189 spec->input_mux = NULL;
3190 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003191 case CXT5066_IDEAPAD:
3192 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003193 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003194 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3195 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3196 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3197 spec->port_d_mode = 0;
3198 spec->ideapad = 1;
3199 spec->mic_boost = 2; /* default 20dB gain */
3200
3201 /* no S/PDIF out */
3202 spec->multiout.dig_out_nid = 0;
3203
3204 /* input source automatically selected */
3205 spec->input_mux = NULL;
3206 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003207 case CXT5066_THINKPAD:
3208 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003209 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003210 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3211 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3212 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3213 spec->thinkpad = 1;
3214 spec->port_d_mode = PIN_OUT;
3215 spec->mic_boost = 2; /* default 20dB gain */
3216
3217 /* no S/PDIF out */
3218 spec->multiout.dig_out_nid = 0;
3219
3220 /* input source automatically selected */
3221 spec->input_mux = NULL;
3222 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003223 }
3224
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003225 if (spec->beep_amp)
3226 snd_hda_attach_beep_device(codec, spec->beep_amp);
3227
Daniel Drake0fb67e92009-07-16 14:46:57 +01003228 return 0;
3229}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003230
3231/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003232 * Automatic parser for CX20641 & co
3233 */
3234
Takashi Iwai6764bce2011-05-13 16:52:25 +02003235static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3236 struct hda_codec *codec,
3237 unsigned int stream_tag,
3238 unsigned int format,
3239 struct snd_pcm_substream *substream)
3240{
3241 struct conexant_spec *spec = codec->spec;
3242 hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]];
3243 if (spec->adc_switching) {
3244 spec->cur_adc = adc;
3245 spec->cur_adc_stream_tag = stream_tag;
3246 spec->cur_adc_format = format;
3247 }
3248 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3249 return 0;
3250}
3251
3252static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3253 struct hda_codec *codec,
3254 struct snd_pcm_substream *substream)
3255{
3256 struct conexant_spec *spec = codec->spec;
3257 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3258 spec->cur_adc = 0;
3259 return 0;
3260}
3261
3262static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3263 .substreams = 1,
3264 .channels_min = 2,
3265 .channels_max = 2,
3266 .nid = 0, /* fill later */
3267 .ops = {
3268 .prepare = cx_auto_capture_pcm_prepare,
3269 .cleanup = cx_auto_capture_pcm_cleanup
3270 },
3271};
3272
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003273static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003274
3275/* get the connection index of @nid in the widget @mux */
3276static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3277 hda_nid_t nid)
3278{
3279 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3280 int i, nums;
3281
3282 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3283 for (i = 0; i < nums; i++)
3284 if (conn[i] == nid)
3285 return i;
3286 return -1;
3287}
3288
3289/* get an unassigned DAC from the given list.
3290 * Return the nid if found and reduce the DAC list, or return zero if
3291 * not found
3292 */
3293static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3294 hda_nid_t *dacs, int *num_dacs)
3295{
3296 int i, nums = *num_dacs;
3297 hda_nid_t ret = 0;
3298
3299 for (i = 0; i < nums; i++) {
3300 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3301 ret = dacs[i];
3302 break;
3303 }
3304 }
3305 if (!ret)
3306 return 0;
3307 if (--nums > 0)
3308 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3309 *num_dacs = nums;
3310 return ret;
3311}
3312
3313#define MAX_AUTO_DACS 5
3314
3315/* fill analog DAC list from the widget tree */
3316static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3317{
3318 hda_nid_t nid, end_nid;
3319 int nums = 0;
3320
3321 end_nid = codec->start_nid + codec->num_nodes;
3322 for (nid = codec->start_nid; nid < end_nid; nid++) {
3323 unsigned int wcaps = get_wcaps(codec, nid);
3324 unsigned int type = get_wcaps_type(wcaps);
3325 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3326 dacs[nums++] = nid;
3327 if (nums >= MAX_AUTO_DACS)
3328 break;
3329 }
3330 }
3331 return nums;
3332}
3333
3334/* fill pin_dac_pair list from the pin and dac list */
3335static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3336 int num_pins, hda_nid_t *dacs, int *rest,
3337 struct pin_dac_pair *filled, int type)
3338{
3339 int i, nums;
3340
3341 nums = 0;
3342 for (i = 0; i < num_pins; i++) {
3343 filled[nums].pin = pins[i];
3344 filled[nums].type = type;
3345 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3346 nums++;
3347 }
3348 return nums;
3349}
3350
3351/* parse analog output paths */
3352static void cx_auto_parse_output(struct hda_codec *codec)
3353{
3354 struct conexant_spec *spec = codec->spec;
3355 struct auto_pin_cfg *cfg = &spec->autocfg;
3356 hda_nid_t dacs[MAX_AUTO_DACS];
3357 int i, j, nums, rest;
3358
3359 rest = fill_cx_auto_dacs(codec, dacs);
3360 /* parse all analog output pins */
3361 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3362 dacs, &rest, spec->dac_info,
3363 AUTO_PIN_LINE_OUT);
3364 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3365 dacs, &rest, spec->dac_info + nums,
3366 AUTO_PIN_HP_OUT);
3367 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3368 dacs, &rest, spec->dac_info + nums,
3369 AUTO_PIN_SPEAKER_OUT);
3370 spec->dac_info_filled = nums;
3371 /* fill multiout struct */
3372 for (i = 0; i < nums; i++) {
3373 hda_nid_t dac = spec->dac_info[i].dac;
3374 if (!dac)
3375 continue;
3376 switch (spec->dac_info[i].type) {
3377 case AUTO_PIN_LINE_OUT:
3378 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3379 spec->multiout.num_dacs++;
3380 break;
3381 case AUTO_PIN_HP_OUT:
3382 case AUTO_PIN_SPEAKER_OUT:
3383 if (!spec->multiout.hp_nid) {
3384 spec->multiout.hp_nid = dac;
3385 break;
3386 }
3387 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3388 if (!spec->multiout.extra_out_nid[j]) {
3389 spec->multiout.extra_out_nid[j] = dac;
3390 break;
3391 }
3392 break;
3393 }
3394 }
3395 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003396 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003397
3398 if (cfg->hp_outs > 0)
3399 spec->auto_mute = 1;
3400 spec->vmaster_nid = spec->private_dac_nids[0];
3401}
3402
Takashi Iwaida339862011-05-13 16:24:15 +02003403static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3404 hda_nid_t *pins, bool on);
3405
Takashi Iwaif2e57312010-09-15 10:07:08 +02003406/* auto-mute/unmute speaker and line outs according to headphone jack */
3407static void cx_auto_hp_automute(struct hda_codec *codec)
3408{
3409 struct conexant_spec *spec = codec->spec;
3410 struct auto_pin_cfg *cfg = &spec->autocfg;
3411 int i, present;
3412
3413 if (!spec->auto_mute)
3414 return;
3415 present = 0;
3416 for (i = 0; i < cfg->hp_outs; i++) {
3417 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3418 present = 1;
3419 break;
3420 }
3421 }
Takashi Iwaida339862011-05-13 16:24:15 +02003422 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003423 for (i = 0; i < cfg->line_outs; i++) {
3424 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3425 AC_VERB_SET_PIN_WIDGET_CONTROL,
3426 present ? 0 : PIN_OUT);
3427 }
Takashi Iwaida339862011-05-13 16:24:15 +02003428 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003429 for (i = 0; !present && i < cfg->line_outs; i++)
3430 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3431 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003432 for (i = 0; i < cfg->speaker_outs; i++) {
3433 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3434 AC_VERB_SET_PIN_WIDGET_CONTROL,
3435 present ? 0 : PIN_OUT);
3436 }
Takashi Iwaida339862011-05-13 16:24:15 +02003437 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003438}
3439
Takashi Iwai6764bce2011-05-13 16:52:25 +02003440static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3441 struct snd_ctl_elem_info *uinfo)
3442{
3443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3444 struct conexant_spec *spec = codec->spec;
3445
3446 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3447}
3448
3449static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3450 struct snd_ctl_elem_value *ucontrol)
3451{
3452 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3453 struct conexant_spec *spec = codec->spec;
3454
3455 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3456 return 0;
3457}
3458
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003459/* look for the route the given pin from mux and return the index;
3460 * if do_select is set, actually select the route.
3461 */
3462static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3463 hda_nid_t pin, bool do_select, int depth)
3464{
3465 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3466 int i, nums;
3467
3468 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3469 for (i = 0; i < nums; i++)
3470 if (conn[i] == pin) {
3471 if (do_select)
3472 snd_hda_codec_write(codec, mux, 0,
3473 AC_VERB_SET_CONNECT_SEL, i);
3474 return i;
3475 }
3476 depth++;
3477 if (depth == 2)
3478 return -1;
3479 for (i = 0; i < nums; i++) {
3480 int ret = __select_input_connection(codec, conn[i], pin,
3481 do_select, depth);
3482 if (ret >= 0) {
3483 if (do_select)
3484 snd_hda_codec_write(codec, mux, 0,
3485 AC_VERB_SET_CONNECT_SEL, i);
3486 return ret;
3487 }
3488 }
3489 return -1;
3490}
3491
3492static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3493 hda_nid_t pin)
3494{
3495 __select_input_connection(codec, mux, pin, true, 0);
3496}
3497
3498static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3499 hda_nid_t pin)
3500{
3501 return __select_input_connection(codec, mux, pin, false, 0);
3502}
3503
Takashi Iwai6764bce2011-05-13 16:52:25 +02003504static int cx_auto_mux_enum_update(struct hda_codec *codec,
3505 const struct hda_input_mux *imux,
3506 unsigned int idx)
3507{
3508 struct conexant_spec *spec = codec->spec;
3509 hda_nid_t adc;
3510
3511 if (!imux->num_items)
3512 return 0;
3513 if (idx >= imux->num_items)
3514 idx = imux->num_items - 1;
3515 if (spec->cur_mux[0] == idx)
3516 return 0;
3517 adc = spec->imux_adcs[idx];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003518 select_input_connection(codec, spec->imux_adcs[idx],
3519 spec->imux_pins[idx]);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003520 if (spec->cur_adc && spec->cur_adc != adc) {
3521 /* stream is running, let's swap the current ADC */
3522 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3523 spec->cur_adc = adc;
3524 snd_hda_codec_setup_stream(codec, adc,
3525 spec->cur_adc_stream_tag, 0,
3526 spec->cur_adc_format);
3527 }
3528 spec->cur_mux[0] = idx;
3529 return 1;
3530}
3531
3532static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3533 struct snd_ctl_elem_value *ucontrol)
3534{
3535 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3536 struct conexant_spec *spec = codec->spec;
3537
3538 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3539 ucontrol->value.enumerated.item[0]);
3540}
3541
3542static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3543 {
3544 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3545 .name = "Capture Source",
3546 .info = cx_auto_mux_enum_info,
3547 .get = cx_auto_mux_enum_get,
3548 .put = cx_auto_mux_enum_put
3549 },
3550 {}
3551};
3552
Takashi Iwaif2e57312010-09-15 10:07:08 +02003553/* automatic switch internal and external mic */
3554static void cx_auto_automic(struct hda_codec *codec)
3555{
3556 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003557 int ext_idx = spec->auto_mic_ext;
3558
3559 if (!spec->auto_mic)
3560 return;
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003561 if (snd_hda_jack_detect(codec, spec->imux_pins[ext_idx]))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003562 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3563 else
3564 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003565}
3566
3567static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3568{
3569 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3570 switch (res >> 26) {
3571 case CONEXANT_HP_EVENT:
3572 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003573 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003574 break;
3575 case CONEXANT_MIC_EVENT:
3576 cx_auto_automic(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 }
3580}
3581
Takashi Iwaif2e57312010-09-15 10:07:08 +02003582/* return true if it's an internal-mic pin */
3583static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3584{
3585 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3586 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003587 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003588}
3589
3590/* return true if it's an external-mic pin */
3591static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3592{
3593 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3594 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003595 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3596 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003597}
3598
3599/* check whether the pin config is suitable for auto-mic switching;
3600 * auto-mic is enabled only when one int-mic and one-ext mic exist
3601 */
3602static void cx_auto_check_auto_mic(struct hda_codec *codec)
3603{
3604 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003605
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003606 if (is_ext_mic(codec, spec->imux_pins[0]) &&
3607 is_int_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003608 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003609 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003610 return;
3611 }
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003612 if (is_int_mic(codec, spec->imux_pins[0]) &&
3613 is_ext_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003614 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003615 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003616 return;
3617 }
3618}
3619
3620static void cx_auto_parse_input(struct hda_codec *codec)
3621{
3622 struct conexant_spec *spec = codec->spec;
3623 struct auto_pin_cfg *cfg = &spec->autocfg;
3624 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003625 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003626
3627 imux = &spec->private_imux;
3628 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003629 for (j = 0; j < spec->num_adc_nids; j++) {
3630 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003631 int idx = get_input_connection(codec, adc,
3632 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003633 if (idx >= 0) {
3634 const char *label;
3635 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003636 spec->imux_adcs[imux->num_items] = adc;
3637 spec->imux_pins[imux->num_items] =
3638 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003639 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003640 break;
3641 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003642 }
3643 }
3644 if (imux->num_items == 2 && cfg->num_inputs == 2)
3645 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003646 if (imux->num_items > 1 && !spec->auto_mic) {
3647 for (i = 1; i < imux->num_items; i++) {
3648 if (spec->imux_adcs[i] != spec->imux_adcs[0]) {
3649 spec->adc_switching = 1;
3650 break;
3651 }
3652 }
3653 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003654}
3655
3656/* get digital-input audio widget corresponding to the given pin */
3657static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3658{
3659 hda_nid_t nid, end_nid;
3660
3661 end_nid = codec->start_nid + codec->num_nodes;
3662 for (nid = codec->start_nid; nid < end_nid; nid++) {
3663 unsigned int wcaps = get_wcaps(codec, nid);
3664 unsigned int type = get_wcaps_type(wcaps);
3665 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3666 if (get_connection_index(codec, nid, pin) >= 0)
3667 return nid;
3668 }
3669 }
3670 return 0;
3671}
3672
3673static void cx_auto_parse_digital(struct hda_codec *codec)
3674{
3675 struct conexant_spec *spec = codec->spec;
3676 struct auto_pin_cfg *cfg = &spec->autocfg;
3677 hda_nid_t nid;
3678
3679 if (cfg->dig_outs &&
3680 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3681 spec->multiout.dig_out_nid = nid;
3682 if (cfg->dig_in_pin)
3683 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3684}
3685
3686#ifdef CONFIG_SND_HDA_INPUT_BEEP
3687static void cx_auto_parse_beep(struct hda_codec *codec)
3688{
3689 struct conexant_spec *spec = codec->spec;
3690 hda_nid_t nid, end_nid;
3691
3692 end_nid = codec->start_nid + codec->num_nodes;
3693 for (nid = codec->start_nid; nid < end_nid; nid++)
3694 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3695 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3696 break;
3697 }
3698}
3699#else
3700#define cx_auto_parse_beep(codec)
3701#endif
3702
3703static int cx_auto_parse_auto_config(struct hda_codec *codec)
3704{
3705 struct conexant_spec *spec = codec->spec;
3706 int err;
3707
3708 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3709 if (err < 0)
3710 return err;
3711
3712 cx_auto_parse_output(codec);
3713 cx_auto_parse_input(codec);
3714 cx_auto_parse_digital(codec);
3715 cx_auto_parse_beep(codec);
3716 return 0;
3717}
3718
Takashi Iwaida339862011-05-13 16:24:15 +02003719static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3720 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003721{
3722 int i;
3723 for (i = 0; i < num_pins; i++) {
3724 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3725 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003726 AC_VERB_SET_EAPD_BTLENABLE,
3727 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003728 }
3729}
3730
3731static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3732 hda_nid_t src)
3733{
3734 int idx = get_connection_index(codec, pin, src);
3735 if (idx >= 0)
3736 snd_hda_codec_write(codec, pin, 0,
3737 AC_VERB_SET_CONNECT_SEL, idx);
3738}
3739
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003740static void mute_outputs(struct hda_codec *codec, int num_nids,
3741 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003742{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003743 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003744
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003745 for (i = 0; i < num_nids; i++) {
3746 hda_nid_t nid = nids[i];
3747 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3748 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003749 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3750 val = AMP_OUT_MUTE;
3751 else
3752 val = AMP_OUT_ZERO;
3753 snd_hda_codec_write(codec, nid, 0,
3754 AC_VERB_SET_AMP_GAIN_MUTE, val);
3755 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003756}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003757
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003758static void cx_auto_init_output(struct hda_codec *codec)
3759{
3760 struct conexant_spec *spec = codec->spec;
3761 struct auto_pin_cfg *cfg = &spec->autocfg;
3762 hda_nid_t nid;
3763 int i;
3764
3765 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003766 for (i = 0; i < cfg->hp_outs; i++)
3767 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3768 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003769 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3770 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3771 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003772 if (spec->auto_mute) {
3773 for (i = 0; i < cfg->hp_outs; i++) {
3774 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3775 AC_VERB_SET_UNSOLICITED_ENABLE,
3776 AC_USRSP_EN | CONEXANT_HP_EVENT);
3777 }
3778 cx_auto_hp_automute(codec);
3779 } else {
3780 for (i = 0; i < cfg->line_outs; i++)
3781 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3782 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3783 for (i = 0; i < cfg->speaker_outs; i++)
3784 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3785 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003786 /* turn on EAPD */
3787 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3788 true);
3789 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3790 true);
3791 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3792 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003793 }
3794
3795 for (i = 0; i < spec->dac_info_filled; i++) {
3796 nid = spec->dac_info[i].dac;
3797 if (!nid)
3798 nid = spec->multiout.dac_nids[0];
3799 select_connection(codec, spec->dac_info[i].pin, nid);
3800 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003801}
3802
3803static void cx_auto_init_input(struct hda_codec *codec)
3804{
3805 struct conexant_spec *spec = codec->spec;
3806 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003807 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003808
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003809 for (i = 0; i < spec->num_adc_nids; i++) {
3810 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003811 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3812 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003813 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3814 val = AMP_IN_MUTE(0);
3815 else
3816 val = AMP_IN_UNMUTE(0);
3817 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3818 val);
3819 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003820
3821 for (i = 0; i < cfg->num_inputs; i++) {
3822 unsigned int type;
3823 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3824 type = PIN_VREF80;
3825 else
3826 type = PIN_IN;
3827 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3828 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3829 }
3830
3831 if (spec->auto_mic) {
3832 int ext_idx = spec->auto_mic_ext;
3833 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3834 AC_VERB_SET_UNSOLICITED_ENABLE,
3835 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3836 cx_auto_automic(codec);
3837 } else {
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003838 select_input_connection(codec, spec->imux_adcs[0],
3839 spec->imux_pins[0]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003840 }
3841}
3842
3843static void cx_auto_init_digital(struct hda_codec *codec)
3844{
3845 struct conexant_spec *spec = codec->spec;
3846 struct auto_pin_cfg *cfg = &spec->autocfg;
3847
3848 if (spec->multiout.dig_out_nid)
3849 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3850 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3851 if (spec->dig_in_nid)
3852 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3853 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3854}
3855
3856static int cx_auto_init(struct hda_codec *codec)
3857{
3858 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3859 cx_auto_init_output(codec);
3860 cx_auto_init_input(codec);
3861 cx_auto_init_digital(codec);
3862 return 0;
3863}
3864
David Henningsson983345e2011-02-15 19:57:09 +01003865static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003866 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003867 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003868{
3869 static char name[32];
3870 static struct snd_kcontrol_new knew[] = {
3871 HDA_CODEC_VOLUME(name, 0, 0, 0),
3872 HDA_CODEC_MUTE(name, 0, 0, 0),
3873 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003874 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003875 int i, err;
3876
3877 for (i = 0; i < 2; i++) {
3878 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003879 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3880 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003881 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3882 knew[i].index = cidx;
3883 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3884 kctl = snd_ctl_new1(&knew[i], codec);
3885 if (!kctl)
3886 return -ENOMEM;
3887 err = snd_hda_ctl_add(codec, nid, kctl);
3888 if (err < 0)
3889 return err;
3890 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3891 break;
3892 }
3893 return 0;
3894}
3895
David Henningsson983345e2011-02-15 19:57:09 +01003896#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3897 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3898
Takashi Iwaif2e57312010-09-15 10:07:08 +02003899#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3900 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3901
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003902static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3903 hda_nid_t pin, const char *name, int idx)
3904{
3905 unsigned int caps;
3906 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3907 if (caps & AC_AMPCAP_NUM_STEPS)
3908 return cx_auto_add_pb_volume(codec, dac, name, idx);
3909 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3910 if (caps & AC_AMPCAP_NUM_STEPS)
3911 return cx_auto_add_pb_volume(codec, pin, name, idx);
3912 return 0;
3913}
3914
Takashi Iwaif2e57312010-09-15 10:07:08 +02003915static int cx_auto_build_output_controls(struct hda_codec *codec)
3916{
3917 struct conexant_spec *spec = codec->spec;
3918 int i, err;
3919 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003920 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003921
3922 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003923 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3924 spec->dac_info[0].pin,
3925 "Master", 0);
3926
Takashi Iwaif2e57312010-09-15 10:07:08 +02003927 for (i = 0; i < spec->dac_info_filled; i++) {
3928 const char *label;
3929 int idx, type;
3930 if (!spec->dac_info[i].dac)
3931 continue;
3932 type = spec->dac_info[i].type;
3933 if (type == AUTO_PIN_LINE_OUT)
3934 type = spec->autocfg.line_out_type;
3935 switch (type) {
3936 case AUTO_PIN_LINE_OUT:
3937 default:
3938 label = texts[num_line++];
3939 idx = 0;
3940 break;
3941 case AUTO_PIN_HP_OUT:
3942 label = "Headphone";
3943 idx = num_hp++;
3944 break;
3945 case AUTO_PIN_SPEAKER_OUT:
3946 label = "Speaker";
3947 idx = num_spk++;
3948 break;
3949 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003950 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3951 spec->dac_info[i].pin,
3952 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003953 if (err < 0)
3954 return err;
3955 }
3956 return 0;
3957}
3958
Takashi Iwai6764bce2011-05-13 16:52:25 +02003959static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3960 const char *label, const char *pfx,
3961 int cidx)
3962{
3963 struct conexant_spec *spec = codec->spec;
3964 int i;
3965
3966 for (i = 0; i < spec->num_adc_nids; i++) {
3967 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003968 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003969 if (idx < 0)
3970 continue;
3971 return cx_auto_add_volume_idx(codec, label, pfx,
3972 cidx, adc_nid, HDA_INPUT, idx);
3973 }
3974 return 0;
3975}
3976
Takashi Iwaif2e57312010-09-15 10:07:08 +02003977static int cx_auto_build_input_controls(struct hda_codec *codec)
3978{
3979 struct conexant_spec *spec = codec->spec;
3980 struct auto_pin_cfg *cfg = &spec->autocfg;
3981 static const char *prev_label;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003982 int i, err, cidx;
David Henningsson983345e2011-02-15 19:57:09 +01003983
Takashi Iwaif2e57312010-09-15 10:07:08 +02003984 prev_label = NULL;
3985 cidx = 0;
3986 for (i = 0; i < cfg->num_inputs; i++) {
3987 hda_nid_t nid = cfg->inputs[i].pin;
3988 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01003989 int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
David Henningsson983345e2011-02-15 19:57:09 +01003990
Takashi Iwaif2e57312010-09-15 10:07:08 +02003991 label = hda_get_autocfg_input_label(codec, cfg, i);
3992 if (label == prev_label)
3993 cidx++;
3994 else
3995 cidx = 0;
3996 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01003997
3998 if (pin_amp) {
3999 err = cx_auto_add_volume(codec, label, " Boost", cidx,
4000 nid, HDA_INPUT);
4001 if (err < 0)
4002 return err;
4003 }
4004
Takashi Iwai6764bce2011-05-13 16:52:25 +02004005 if (cfg->num_inputs == 1) {
4006 err = cx_auto_add_capture_volume(codec, nid,
4007 "Capture", "", cidx);
4008 } else {
4009 err = cx_auto_add_capture_volume(codec, nid,
4010 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004011 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004012 if (err < 0)
4013 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004014 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004015
4016 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4017 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4018 if (err < 0)
4019 return err;
4020 }
4021
Takashi Iwaif2e57312010-09-15 10:07:08 +02004022 return 0;
4023}
4024
4025static int cx_auto_build_controls(struct hda_codec *codec)
4026{
4027 int err;
4028
4029 err = cx_auto_build_output_controls(codec);
4030 if (err < 0)
4031 return err;
4032 err = cx_auto_build_input_controls(codec);
4033 if (err < 0)
4034 return err;
4035 return conexant_build_controls(codec);
4036}
4037
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004038static int cx_auto_search_adcs(struct hda_codec *codec)
4039{
4040 struct conexant_spec *spec = codec->spec;
4041 hda_nid_t nid, end_nid;
4042
4043 end_nid = codec->start_nid + codec->num_nodes;
4044 for (nid = codec->start_nid; nid < end_nid; nid++) {
4045 unsigned int caps = get_wcaps(codec, nid);
4046 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4047 continue;
4048 if (caps & AC_WCAP_DIGITAL)
4049 continue;
4050 if (snd_BUG_ON(spec->num_adc_nids >=
4051 ARRAY_SIZE(spec->private_adc_nids)))
4052 break;
4053 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4054 }
4055 spec->adc_nids = spec->private_adc_nids;
4056 return 0;
4057}
4058
4059
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004060static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004061 .build_controls = cx_auto_build_controls,
4062 .build_pcms = conexant_build_pcms,
4063 .init = cx_auto_init,
4064 .free = conexant_free,
4065 .unsol_event = cx_auto_unsol_event,
4066#ifdef CONFIG_SND_HDA_POWER_SAVE
4067 .suspend = conexant_suspend,
4068#endif
4069 .reboot_notify = snd_hda_shutup_pins,
4070};
4071
4072static int patch_conexant_auto(struct hda_codec *codec)
4073{
4074 struct conexant_spec *spec;
4075 int err;
4076
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004077 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4078 codec->chip_name);
4079
Takashi Iwaif2e57312010-09-15 10:07:08 +02004080 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4081 if (!spec)
4082 return -ENOMEM;
4083 codec->spec = spec;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004084 err = cx_auto_search_adcs(codec);
4085 if (err < 0)
4086 return err;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004087 switch (codec->vendor_id) {
4088 case 0x14f15051:
Takashi Iwai6764bce2011-05-13 16:52:25 +02004089 codec->pin_amp_workaround = 1;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004090 break;
4091 case 0x14f15045:
4092 codec->pin_amp_workaround = 1;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004093 break;
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02004094 case 0x14f15047:
4095 codec->pin_amp_workaround = 1;
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004096 break;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004097 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02004098 err = cx_auto_parse_auto_config(codec);
4099 if (err < 0) {
4100 kfree(codec->spec);
4101 codec->spec = NULL;
4102 return err;
4103 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004104 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004105 codec->patch_ops = cx_auto_patch_ops;
4106 if (spec->beep_amp)
4107 snd_hda_attach_beep_device(codec, spec->beep_amp);
4108 return 0;
4109}
4110
4111/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004112 */
4113
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004114static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004115 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4116 .patch = patch_cxt5045 },
4117 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4118 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004119 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4120 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004121 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4122 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004123 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4124 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004125 { .id = 0x14f15068, .name = "CX20584",
4126 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004127 { .id = 0x14f15069, .name = "CX20585",
4128 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004129 { .id = 0x14f1506e, .name = "CX20590",
4130 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004131 { .id = 0x14f15097, .name = "CX20631",
4132 .patch = patch_conexant_auto },
4133 { .id = 0x14f15098, .name = "CX20632",
4134 .patch = patch_conexant_auto },
4135 { .id = 0x14f150a1, .name = "CX20641",
4136 .patch = patch_conexant_auto },
4137 { .id = 0x14f150a2, .name = "CX20642",
4138 .patch = patch_conexant_auto },
4139 { .id = 0x14f150ab, .name = "CX20651",
4140 .patch = patch_conexant_auto },
4141 { .id = 0x14f150ac, .name = "CX20652",
4142 .patch = patch_conexant_auto },
4143 { .id = 0x14f150b8, .name = "CX20664",
4144 .patch = patch_conexant_auto },
4145 { .id = 0x14f150b9, .name = "CX20665",
4146 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004147 {} /* terminator */
4148};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004149
4150MODULE_ALIAS("snd-hda-codec-id:14f15045");
4151MODULE_ALIAS("snd-hda-codec-id:14f15047");
4152MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004153MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004154MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004155MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004156MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004157MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004158MODULE_ALIAS("snd-hda-codec-id:14f15097");
4159MODULE_ALIAS("snd-hda-codec-id:14f15098");
4160MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4161MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4162MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4163MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4164MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4165MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004166
4167MODULE_LICENSE("GPL");
4168MODULE_DESCRIPTION("Conexant HD-audio codec");
4169
4170static struct hda_codec_preset_list conexant_list = {
4171 .preset = snd_hda_preset_conexant,
4172 .owner = THIS_MODULE,
4173};
4174
4175static int __init patch_conexant_init(void)
4176{
4177 return snd_hda_add_codec_preset(&conexant_list);
4178}
4179
4180static void __exit patch_conexant_exit(void)
4181{
4182 snd_hda_delete_codec_preset(&conexant_list);
4183}
4184
4185module_init(patch_conexant_init)
4186module_exit(patch_conexant_exit)