blob: ed983a0b0dc11b6251ffbb341959c9bbff10eb18 [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 Iwaicf27f292011-05-16 11:33:02 +0200111 int imux_cfg_idx[HDA_MAX_NUM_INPUTS]; /* corresponding autocfg.input */
Takashi Iwaif9759302011-05-16 11:45:15 +0200112 hda_nid_t imux_boost_nid[HDA_MAX_NUM_INPUTS]; /* boost widget */
Takashi Iwai6764bce2011-05-13 16:52:25 +0200113 hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS];
Takashi Iwaif6100bb2011-05-13 18:26:39 +0200114 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200115 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200116 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200117 struct pin_dac_pair dac_info[8];
118 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100119
Daniel Drake0fb67e92009-07-16 14:46:57 +0100120 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200121 unsigned int auto_mute:1; /* used in auto-parser */
122 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500123 unsigned int dell_vostro:1;
124 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200125 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200126 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100127 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100128
Takashi Iwai6764bce2011-05-13 16:52:25 +0200129 unsigned int adc_switching:1;
130
Daniel Drake75f89912010-01-07 13:46:25 +0100131 unsigned int ext_mic_present;
132 unsigned int recording;
133 void (*capture_prepare)(struct hda_codec *codec);
134 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100135
136 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
137 * through the microphone jack.
138 * When the user enables this through a mixer switch, both internal and
139 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
140 * we also allow the bias to be configured through a separate mixer
141 * control. */
142 unsigned int dc_enable;
143 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
144 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200145
146 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100147};
148
149static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
150 struct hda_codec *codec,
151 struct snd_pcm_substream *substream)
152{
153 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100154 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
155 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100156}
157
158static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 unsigned int stream_tag,
161 unsigned int format,
162 struct snd_pcm_substream *substream)
163{
164 struct conexant_spec *spec = codec->spec;
165 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
166 stream_tag,
167 format, substream);
168}
169
170static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
175 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
176}
177
178/*
179 * Digital out
180 */
181static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
182 struct hda_codec *codec,
183 struct snd_pcm_substream *substream)
184{
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
187}
188
189static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
190 struct hda_codec *codec,
191 struct snd_pcm_substream *substream)
192{
193 struct conexant_spec *spec = codec->spec;
194 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
195}
196
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200197static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
198 struct hda_codec *codec,
199 unsigned int stream_tag,
200 unsigned int format,
201 struct snd_pcm_substream *substream)
202{
203 struct conexant_spec *spec = codec->spec;
204 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
205 stream_tag,
206 format, substream);
207}
208
Tobin Davisc9b443d2006-11-14 12:13:39 +0100209/*
210 * Analog capture
211 */
212static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
213 struct hda_codec *codec,
214 unsigned int stream_tag,
215 unsigned int format,
216 struct snd_pcm_substream *substream)
217{
218 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100219 if (spec->capture_prepare)
220 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100221 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
222 stream_tag, 0, format);
223 return 0;
224}
225
226static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
227 struct hda_codec *codec,
228 struct snd_pcm_substream *substream)
229{
230 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100231 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100232 if (spec->capture_cleanup)
233 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100234 return 0;
235}
236
237
238
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200239static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100240 .substreams = 1,
241 .channels_min = 2,
242 .channels_max = 2,
243 .nid = 0, /* fill later */
244 .ops = {
245 .open = conexant_playback_pcm_open,
246 .prepare = conexant_playback_pcm_prepare,
247 .cleanup = conexant_playback_pcm_cleanup
248 },
249};
250
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200251static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100252 .substreams = 1,
253 .channels_min = 2,
254 .channels_max = 2,
255 .nid = 0, /* fill later */
256 .ops = {
257 .prepare = conexant_capture_pcm_prepare,
258 .cleanup = conexant_capture_pcm_cleanup
259 },
260};
261
262
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200263static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100264 .substreams = 1,
265 .channels_min = 2,
266 .channels_max = 2,
267 .nid = 0, /* fill later */
268 .ops = {
269 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200270 .close = conexant_dig_playback_pcm_close,
271 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100272 },
273};
274
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200275static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100276 .substreams = 1,
277 .channels_min = 2,
278 .channels_max = 2,
279 /* NID is set in alc_build_pcms */
280};
281
Takashi Iwai461e2c72008-01-25 11:35:17 +0100282static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 unsigned int stream_tag,
285 unsigned int format,
286 struct snd_pcm_substream *substream)
287{
288 struct conexant_spec *spec = codec->spec;
289 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
290 spec->cur_adc_stream_tag = stream_tag;
291 spec->cur_adc_format = format;
292 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
293 return 0;
294}
295
296static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
297 struct hda_codec *codec,
298 struct snd_pcm_substream *substream)
299{
300 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100301 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100302 spec->cur_adc = 0;
303 return 0;
304}
305
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200306static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100307 .substreams = 1,
308 .channels_min = 2,
309 .channels_max = 2,
310 .nid = 0, /* fill later */
311 .ops = {
312 .prepare = cx5051_capture_pcm_prepare,
313 .cleanup = cx5051_capture_pcm_cleanup
314 },
315};
316
Tobin Davisc9b443d2006-11-14 12:13:39 +0100317static int conexant_build_pcms(struct hda_codec *codec)
318{
319 struct conexant_spec *spec = codec->spec;
320 struct hda_pcm *info = spec->pcm_rec;
321
322 codec->num_pcms = 1;
323 codec->pcm_info = info;
324
325 info->name = "CONEXANT Analog";
326 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
327 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
328 spec->multiout.max_channels;
329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
330 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200331 if (spec->capture_stream)
332 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
333 else {
334 if (codec->vendor_id == 0x14f15051)
335 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
336 cx5051_pcm_analog_capture;
337 else {
338 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
339 conexant_pcm_analog_capture;
340 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
341 spec->num_adc_nids;
342 }
343 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100344 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
345
346 if (spec->multiout.dig_out_nid) {
347 info++;
348 codec->num_pcms++;
349 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100350 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100351 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
352 conexant_pcm_digital_playback;
353 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
354 spec->multiout.dig_out_nid;
355 if (spec->dig_in_nid) {
356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
357 conexant_pcm_digital_capture;
358 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
359 spec->dig_in_nid;
360 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500361 if (spec->slave_dig_outs[0])
362 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100363 }
364
365 return 0;
366}
367
368static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
369 struct snd_ctl_elem_info *uinfo)
370{
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct conexant_spec *spec = codec->spec;
373
374 return snd_hda_input_mux_info(spec->input_mux, uinfo);
375}
376
377static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_value *ucontrol)
379{
380 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
381 struct conexant_spec *spec = codec->spec;
382 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
383
384 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
385 return 0;
386}
387
388static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_value *ucontrol)
390{
391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
392 struct conexant_spec *spec = codec->spec;
393 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
394
395 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
396 spec->capsrc_nids[adc_idx],
397 &spec->cur_mux[adc_idx]);
398}
399
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100400static int conexant_init_jacks(struct hda_codec *codec)
401{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100402#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100403 struct conexant_spec *spec = codec->spec;
404 int i;
405
406 for (i = 0; i < spec->num_init_verbs; i++) {
407 const struct hda_verb *hv;
408
409 hv = spec->init_verbs[i];
410 while (hv->nid) {
411 int err = 0;
412 switch (hv->param ^ AC_USRSP_EN) {
413 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100414 err = snd_hda_input_jack_add(codec, hv->nid,
415 SND_JACK_HEADPHONE, NULL);
416 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100417 break;
418 case CXT5051_PORTC_EVENT:
419 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100420 err = snd_hda_input_jack_add(codec, hv->nid,
421 SND_JACK_MICROPHONE, NULL);
422 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100423 break;
424 }
425 if (err < 0)
426 return err;
427 ++hv;
428 }
429 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100430#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100431 return 0;
432}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100433
Tobin Davisc9b443d2006-11-14 12:13:39 +0100434static int conexant_init(struct hda_codec *codec)
435{
436 struct conexant_spec *spec = codec->spec;
437 int i;
438
439 for (i = 0; i < spec->num_init_verbs; i++)
440 snd_hda_sequence_write(codec, spec->init_verbs[i]);
441 return 0;
442}
443
444static void conexant_free(struct hda_codec *codec)
445{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100446 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200447 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100448 kfree(codec->spec);
449}
450
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200451static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100452 {
453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
454 .name = "Capture Source",
455 .info = conexant_mux_enum_info,
456 .get = conexant_mux_enum_get,
457 .put = conexant_mux_enum_put
458 },
459 {}
460};
461
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200462#ifdef CONFIG_SND_HDA_INPUT_BEEP
463/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200464static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200465 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
466 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
467 { } /* end */
468};
469#endif
470
Takashi Iwaiea734962011-01-17 11:29:34 +0100471static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100472 "Headphone Playback Volume",
473 "Speaker Playback Volume",
474 NULL
475};
476
Takashi Iwaiea734962011-01-17 11:29:34 +0100477static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100478 "Headphone Playback Switch",
479 "Speaker Playback Switch",
480 NULL
481};
482
Tobin Davisc9b443d2006-11-14 12:13:39 +0100483static int conexant_build_controls(struct hda_codec *codec)
484{
485 struct conexant_spec *spec = codec->spec;
486 unsigned int i;
487 int err;
488
489 for (i = 0; i < spec->num_mixers; i++) {
490 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
491 if (err < 0)
492 return err;
493 }
494 if (spec->multiout.dig_out_nid) {
495 err = snd_hda_create_spdif_out_ctls(codec,
496 spec->multiout.dig_out_nid);
497 if (err < 0)
498 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100499 err = snd_hda_create_spdif_share_sw(codec,
500 &spec->multiout);
501 if (err < 0)
502 return err;
503 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100504 }
505 if (spec->dig_in_nid) {
506 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
507 if (err < 0)
508 return err;
509 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100510
511 /* if we have no master control, let's create it */
512 if (spec->vmaster_nid &&
513 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
514 unsigned int vmaster_tlv[4];
515 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
516 HDA_OUTPUT, vmaster_tlv);
517 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
518 vmaster_tlv, slave_vols);
519 if (err < 0)
520 return err;
521 }
522 if (spec->vmaster_nid &&
523 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
524 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
525 NULL, slave_sws);
526 if (err < 0)
527 return err;
528 }
529
Takashi Iwaib880c742009-03-10 14:41:05 +0100530 if (spec->input_mux) {
531 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
532 if (err < 0)
533 return err;
534 }
535
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200536#ifdef CONFIG_SND_HDA_INPUT_BEEP
537 /* create beep controls if needed */
538 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200539 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200540 for (knew = cxt_beep_mixer; knew->name; knew++) {
541 struct snd_kcontrol *kctl;
542 kctl = snd_ctl_new1(knew, codec);
543 if (!kctl)
544 return -ENOMEM;
545 kctl->private_value = spec->beep_amp;
546 err = snd_hda_ctl_add(codec, 0, kctl);
547 if (err < 0)
548 return err;
549 }
550 }
551#endif
552
Tobin Davisc9b443d2006-11-14 12:13:39 +0100553 return 0;
554}
555
Takashi Iwai697c3732010-07-30 11:28:02 +0200556#ifdef CONFIG_SND_HDA_POWER_SAVE
557static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
558{
559 snd_hda_shutup_pins(codec);
560 return 0;
561}
562#endif
563
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200564static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100565 .build_controls = conexant_build_controls,
566 .build_pcms = conexant_build_pcms,
567 .init = conexant_init,
568 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200569#ifdef CONFIG_SND_HDA_POWER_SAVE
570 .suspend = conexant_suspend,
571#endif
572 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100573};
574
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200575#ifdef CONFIG_SND_HDA_INPUT_BEEP
576#define set_beep_amp(spec, nid, idx, dir) \
577 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
578#else
579#define set_beep_amp(spec, nid, idx, dir) /* NOP */
580#endif
581
Takashi Iwai6764bce2011-05-13 16:52:25 +0200582static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583/*
584 * EAPD control
585 * the private value = nid | (invert << 8)
586 */
587
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200588#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100589
Tobin Davis82f30042007-02-13 12:45:44 +0100590static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591 struct snd_ctl_elem_value *ucontrol)
592{
593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
594 struct conexant_spec *spec = codec->spec;
595 int invert = (kcontrol->private_value >> 8) & 1;
596 if (invert)
597 ucontrol->value.integer.value[0] = !spec->cur_eapd;
598 else
599 ucontrol->value.integer.value[0] = spec->cur_eapd;
600 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100601
Tobin Davisc9b443d2006-11-14 12:13:39 +0100602}
603
Tobin Davis82f30042007-02-13 12:45:44 +0100604static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100605 struct snd_ctl_elem_value *ucontrol)
606{
607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
608 struct conexant_spec *spec = codec->spec;
609 int invert = (kcontrol->private_value >> 8) & 1;
610 hda_nid_t nid = kcontrol->private_value & 0xff;
611 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100612
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100613 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100614 if (invert)
615 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200616 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100617 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100618
Tobin Davisc9b443d2006-11-14 12:13:39 +0100619 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200620 snd_hda_codec_write_cache(codec, nid,
621 0, AC_VERB_SET_EAPD_BTLENABLE,
622 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623 return 1;
624}
625
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100626/* controls for test mode */
627#ifdef CONFIG_SND_DEBUG
628
Tobin Davis82f30042007-02-13 12:45:44 +0100629#define CXT_EAPD_SWITCH(xname, nid, mask) \
630 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
631 .info = cxt_eapd_info, \
632 .get = cxt_eapd_get, \
633 .put = cxt_eapd_put, \
634 .private_value = nid | (mask<<16) }
635
636
637
Tobin Davisc9b443d2006-11-14 12:13:39 +0100638static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_info *uinfo)
640{
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct conexant_spec *spec = codec->spec;
643 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
644 spec->num_channel_mode);
645}
646
647static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct conexant_spec *spec = codec->spec;
652 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
653 spec->num_channel_mode,
654 spec->multiout.max_channels);
655}
656
657static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_value *ucontrol)
659{
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct conexant_spec *spec = codec->spec;
662 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
663 spec->num_channel_mode,
664 &spec->multiout.max_channels);
665 if (err >= 0 && spec->need_dac_fix)
666 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
667 return err;
668}
669
670#define CXT_PIN_MODE(xname, nid, dir) \
671 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
672 .info = conexant_ch_mode_info, \
673 .get = conexant_ch_mode_get, \
674 .put = conexant_ch_mode_put, \
675 .private_value = nid | (dir<<16) }
676
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100677#endif /* CONFIG_SND_DEBUG */
678
Tobin Davisc9b443d2006-11-14 12:13:39 +0100679/* Conexant 5045 specific */
680
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200681static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
682static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
683static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100684#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100685
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200686static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100687 { 2, NULL },
688};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200690static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100691 .num_items = 2,
692 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100693 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100694 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695 }
696};
697
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200698static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200699 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100700 .items = {
701 { "IntMic", 0x1 },
702 { "ExtMic", 0x2 },
703 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200704 { "CD", 0x4 },
705 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100706 }
707};
708
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200709static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100710 .num_items = 2,
711 .items = {
712 { "ExtMic", 0x1 },
713 { "IntMic", 0x2 },
714 }
715};
716
Tobin Davisc9b443d2006-11-14 12:13:39 +0100717/* turn on/off EAPD (+ mute HP) as a master switch */
718static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
719 struct snd_ctl_elem_value *ucontrol)
720{
721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100723 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100724
Tobin Davis82f30042007-02-13 12:45:44 +0100725 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100726 return 0;
727
Tobin Davis82f30042007-02-13 12:45:44 +0100728 /* toggle internal speakers mute depending of presence of
729 * the headphone jack
730 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200731 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
732 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
733 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100734
Takashi Iwai47fd8302007-08-10 17:11:07 +0200735 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
736 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
737 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100738 return 1;
739}
740
741/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200742static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200743 .ops = &snd_hda_bind_vol,
744 .values = {
745 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
746 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
747 0
748 },
749};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100750
Tobin Davis7f296732007-03-12 11:39:01 +0100751/* toggle input of built-in and mic jack appropriately */
752static void cxt5045_hp_automic(struct hda_codec *codec)
753{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200754 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
756 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
757 {}
758 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200759 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100760 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
762 {}
763 };
764 unsigned int present;
765
Takashi Iwaid56757a2009-11-18 08:00:14 +0100766 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100767 if (present)
768 snd_hda_sequence_write(codec, mic_jack_on);
769 else
770 snd_hda_sequence_write(codec, mic_jack_off);
771}
772
Tobin Davisc9b443d2006-11-14 12:13:39 +0100773
774/* mute internal speaker if HP is plugged */
775static void cxt5045_hp_automute(struct hda_codec *codec)
776{
Tobin Davis82f30042007-02-13 12:45:44 +0100777 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100778 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100779
Takashi Iwaid56757a2009-11-18 08:00:14 +0100780 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100781
Takashi Iwai47fd8302007-08-10 17:11:07 +0200782 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
783 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
784 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100785}
786
787/* unsolicited event for HP jack sensing */
788static void cxt5045_hp_unsol_event(struct hda_codec *codec,
789 unsigned int res)
790{
791 res >>= 26;
792 switch (res) {
793 case CONEXANT_HP_EVENT:
794 cxt5045_hp_automute(codec);
795 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100796 case CONEXANT_MIC_EVENT:
797 cxt5045_hp_automic(codec);
798 break;
799
Tobin Davisc9b443d2006-11-14 12:13:39 +0100800 }
801}
802
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200803static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100804 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
805 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100806 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
807 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200808 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
809 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100810 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
811 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100812 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
813 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200814 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100815 {
816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
817 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100818 .info = cxt_eapd_info,
819 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100820 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100821 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100822 },
823
824 {}
825};
826
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200827static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200828 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
829 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
830 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
831 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
832
Jiang Zhe5218c892008-01-17 11:18:41 +0100833 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
834 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
835 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
836 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
837
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200838 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
839 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
840
Jiang Zhe5218c892008-01-17 11:18:41 +0100841 {}
842};
843
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200844static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100845 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
846 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100847 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
848 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100849 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
850 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100851 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
852 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100853 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
854 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100855 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
856 {
857 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
858 .name = "Master Playback Switch",
859 .info = cxt_eapd_info,
860 .get = cxt_eapd_get,
861 .put = cxt5045_hp_master_sw_put,
862 .private_value = 0x10,
863 },
864
865 {}
866};
867
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200868static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100869 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200870 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100871 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100872 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200873 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
874 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
875 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
876 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
878 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
881 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100882 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100883 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100884 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100885 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
886 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100887 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100888 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100889 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100890 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100891 { } /* end */
892};
893
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200894static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100895 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100896 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
897 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
898 /* Line In,HP, Amp */
899 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
900 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
901 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
902 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
905 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
906 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
907 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100908 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100909 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
910 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
911 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
912 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100913 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100914 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
915 /* EAPD */
916 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
917 { } /* end */
918};
Tobin Davis7f296732007-03-12 11:39:01 +0100919
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200920static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100921 /* pin sensing on HP jack */
922 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200923 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100924};
925
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200926static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100927 /* pin sensing on HP jack */
928 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200929 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100930};
931
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932#ifdef CONFIG_SND_DEBUG
933/* Test configuration for debugging, modelled after the ALC260 test
934 * configuration.
935 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200936static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100937 .num_items = 5,
938 .items = {
939 { "MIXER", 0x0 },
940 { "MIC1 pin", 0x1 },
941 { "LINE1 pin", 0x2 },
942 { "HP-OUT pin", 0x3 },
943 { "CD pin", 0x4 },
944 },
945};
946
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200947static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100948
949 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100950 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
951 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100952 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
953 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
954 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
955 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956
957 /* Modes for retasking pin widgets */
958 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
959 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
960
Tobin Davis82f30042007-02-13 12:45:44 +0100961 /* EAPD Switch Control */
962 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
963
Tobin Davisc9b443d2006-11-14 12:13:39 +0100964 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100965
Tobin Davis7f296732007-03-12 11:39:01 +0100966 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
967 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
968 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
969 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
970 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
971 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
972 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
973 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
974 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
975 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100976 {
977 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
978 .name = "Input Source",
979 .info = conexant_mux_enum_info,
980 .get = conexant_mux_enum_get,
981 .put = conexant_mux_enum_put,
982 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200983 /* Audio input controls */
984 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
985 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
986 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
987 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
988 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
989 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
990 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
991 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
992 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
993 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100994 { } /* end */
995};
996
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200997static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100998 /* Set connections */
999 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1000 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1001 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002 /* Enable retasking pins as output, initially without power amp */
1003 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001004 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001005
1006 /* Disable digital (SPDIF) pins initially, but users can enable
1007 * them via a mixer switch. In the case of SPDIF-out, this initverb
1008 * payload also sets the generation to 0, output to be in "consumer"
1009 * PCM format, copyright asserted, no pre-emphasis and no validity
1010 * control.
1011 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001012 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1013 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001014
1015 /* Start with output sum widgets muted and their output gains at min */
1016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1017 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1018
1019 /* Unmute retasking pin widget output buffers since the default
1020 * state appears to be output. As the pin mode is changed by the
1021 * user the pin mode control will take care of enabling the pin's
1022 * input/output buffers as needed.
1023 */
1024 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1025 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1026
1027 /* Mute capture amp left and right */
1028 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1029
1030 /* Set ADC connection select to match default mixer setting (mic1
1031 * pin)
1032 */
1033 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001034 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001035
1036 /* Mute all inputs to mixer widget (even unconnected ones) */
1037 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1038 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1039 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1040 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1041 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1042
1043 { }
1044};
1045#endif
1046
1047
1048/* initialize jack-sensing, too */
1049static int cxt5045_init(struct hda_codec *codec)
1050{
1051 conexant_init(codec);
1052 cxt5045_hp_automute(codec);
1053 return 0;
1054}
1055
1056
1057enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001058 CXT5045_LAPTOP_HPSENSE,
1059 CXT5045_LAPTOP_MICSENSE,
1060 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001061 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001062 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001063#ifdef CONFIG_SND_DEBUG
1064 CXT5045_TEST,
1065#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001066 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001067 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001068};
1069
Takashi Iwaiea734962011-01-17 11:29:34 +01001070static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001071 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1072 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1073 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1074 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001075 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001076#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001077 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001078#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001079 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001080};
1081
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001082static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001083 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001084 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1085 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001086 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001087 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001088 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1089 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001090 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1091 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001092 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1093 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1094 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001095 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1096 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001097 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001098 {}
1099};
1100
1101static int patch_cxt5045(struct hda_codec *codec)
1102{
1103 struct conexant_spec *spec;
1104 int board_config;
1105
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001106 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1107 cxt5045_models,
1108 cxt5045_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001109#if 0 /* use the old method just for safety */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001110 if (board_config < 0)
1111 board_config = CXT5045_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001112#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001113 if (board_config == CXT5045_AUTO)
1114 return patch_conexant_auto(codec);
1115
Tobin Davisc9b443d2006-11-14 12:13:39 +01001116 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1117 if (!spec)
1118 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001119 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001120 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001121
1122 spec->multiout.max_channels = 2;
1123 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1124 spec->multiout.dac_nids = cxt5045_dac_nids;
1125 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1126 spec->num_adc_nids = 1;
1127 spec->adc_nids = cxt5045_adc_nids;
1128 spec->capsrc_nids = cxt5045_capsrc_nids;
1129 spec->input_mux = &cxt5045_capture_source;
1130 spec->num_mixers = 1;
1131 spec->mixers[0] = cxt5045_mixers;
1132 spec->num_init_verbs = 1;
1133 spec->init_verbs[0] = cxt5045_init_verbs;
1134 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001135 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1136 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001137
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001138 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001139
1140 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001141
Tobin Davisc9b443d2006-11-14 12:13:39 +01001142 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001143 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001144 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001145 spec->input_mux = &cxt5045_capture_source;
1146 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001147 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1148 spec->mixers[0] = cxt5045_mixers;
1149 codec->patch_ops.init = cxt5045_init;
1150 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001151 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001152 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001153 spec->input_mux = &cxt5045_capture_source;
1154 spec->num_init_verbs = 2;
1155 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001156 spec->mixers[0] = cxt5045_mixers;
1157 codec->patch_ops.init = cxt5045_init;
1158 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001159 default:
1160 case CXT5045_LAPTOP_HPMICSENSE:
1161 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1162 spec->input_mux = &cxt5045_capture_source;
1163 spec->num_init_verbs = 3;
1164 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1165 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1166 spec->mixers[0] = cxt5045_mixers;
1167 codec->patch_ops.init = cxt5045_init;
1168 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001169 case CXT5045_BENQ:
1170 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1171 spec->input_mux = &cxt5045_capture_source_benq;
1172 spec->num_init_verbs = 1;
1173 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1174 spec->mixers[0] = cxt5045_mixers;
1175 spec->mixers[1] = cxt5045_benq_mixers;
1176 spec->num_mixers = 2;
1177 codec->patch_ops.init = cxt5045_init;
1178 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001179 case CXT5045_LAPTOP_HP530:
1180 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1181 spec->input_mux = &cxt5045_capture_source_hp530;
1182 spec->num_init_verbs = 2;
1183 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers_hp530;
1185 codec->patch_ops.init = cxt5045_init;
1186 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187#ifdef CONFIG_SND_DEBUG
1188 case CXT5045_TEST:
1189 spec->input_mux = &cxt5045_test_capture_source;
1190 spec->mixers[0] = cxt5045_test_mixer;
1191 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001192 break;
1193
Tobin Davisc9b443d2006-11-14 12:13:39 +01001194#endif
1195 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001196
Takashi Iwai031005f2008-06-26 14:49:58 +02001197 switch (codec->subsystem_id >> 16) {
1198 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001199 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001200 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001201 case 0x17aa:
1202 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1203 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1204 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001205 */
1206 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1207 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1208 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1209 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1210 (1 << AC_AMPCAP_MUTE_SHIFT));
1211 break;
1212 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001213
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001214 if (spec->beep_amp)
1215 snd_hda_attach_beep_device(codec, spec->beep_amp);
1216
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217 return 0;
1218}
1219
1220
1221/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001222#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001224static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1225static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1226static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001228static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001229 { 2, NULL },
1230};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001232static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001233 .num_items = 2,
1234 .items = {
1235 { "ExtMic", 0x2 },
1236 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001237 }
1238};
1239
1240/* turn on/off EAPD (+ mute HP) as a master switch */
1241static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1242 struct snd_ctl_elem_value *ucontrol)
1243{
1244 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1245 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001246 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247
Tobin Davis82f30042007-02-13 12:45:44 +01001248 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001249 return 0;
1250
Tobin Davis82f30042007-02-13 12:45:44 +01001251 /* toggle internal speakers mute depending of presence of
1252 * the headphone jack
1253 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001254 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001255 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1256 * pin widgets unlike other codecs. In this case, we need to
1257 * set index 0x01 for the volume from the mixer amp 0x19.
1258 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001259 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001260 HDA_AMP_MUTE, bits);
1261 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1262 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1263 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001264 return 1;
1265}
1266
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267/* mute internal speaker if HP is plugged */
1268static void cxt5047_hp_automute(struct hda_codec *codec)
1269{
Tobin Davis82f30042007-02-13 12:45:44 +01001270 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001271 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001272
Takashi Iwaid56757a2009-11-18 08:00:14 +01001273 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001274
Takashi Iwai47fd8302007-08-10 17:11:07 +02001275 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001276 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001277 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001278 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001279}
1280
1281/* toggle input of built-in and mic jack appropriately */
1282static void cxt5047_hp_automic(struct hda_codec *codec)
1283{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001284 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001285 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1286 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287 {}
1288 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001289 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001290 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1291 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001292 {}
1293 };
1294 unsigned int present;
1295
Takashi Iwaid56757a2009-11-18 08:00:14 +01001296 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 if (present)
1298 snd_hda_sequence_write(codec, mic_jack_on);
1299 else
1300 snd_hda_sequence_write(codec, mic_jack_off);
1301}
1302
1303/* unsolicited event for HP jack sensing */
1304static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1305 unsigned int res)
1306{
Marc Boucher9f113e02008-01-22 15:18:08 +01001307 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308 case CONEXANT_HP_EVENT:
1309 cxt5047_hp_automute(codec);
1310 break;
1311 case CONEXANT_MIC_EVENT:
1312 cxt5047_hp_automic(codec);
1313 break;
1314 }
1315}
1316
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001317static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001318 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1319 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001320 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1322 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1323 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1324 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001325 {
1326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1327 .name = "Master Playback Switch",
1328 .info = cxt_eapd_info,
1329 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001330 .put = cxt5047_hp_master_sw_put,
1331 .private_value = 0x13,
1332 },
1333
1334 {}
1335};
1336
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001337static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001338 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001339 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001340 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1341 {}
1342};
1343
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001344static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001345 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 { } /* end */
1347};
1348
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001349static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001350 /* Line in, Mic, Built-in Mic */
1351 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1352 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1353 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001354 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001355 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001356 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1357 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001358 /* Record selector: Mic */
1359 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1360 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1361 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1362 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001363 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1365 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1366 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 /* SPDIF route: PCM */
1368 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001369 /* Enable unsolicited events */
1370 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1371 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001372 { } /* end */
1373};
1374
1375/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001376static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001377 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001378 {}
1379};
1380
1381/* Test configuration for debugging, modelled after the ALC260 test
1382 * configuration.
1383 */
1384#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001385static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001386 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001388 { "LINE1 pin", 0x0 },
1389 { "MIC1 pin", 0x1 },
1390 { "MIC2 pin", 0x2 },
1391 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001392 },
1393};
1394
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001395static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001396
1397 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001398 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1400 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1404 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001406 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1408 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001410
1411 /* Modes for retasking pin widgets */
1412 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1413 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1414
Tobin Davis82f30042007-02-13 12:45:44 +01001415 /* EAPD Switch Control */
1416 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1417
Tobin Davisc9b443d2006-11-14 12:13:39 +01001418 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001419 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1420 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1421 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1422 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1423 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1424 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1425 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1426 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001427
Tobin Davis82f30042007-02-13 12:45:44 +01001428 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1429 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1430 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1431 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1432 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1433 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1434 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1435 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001436 {
1437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1438 .name = "Input Source",
1439 .info = conexant_mux_enum_info,
1440 .get = conexant_mux_enum_get,
1441 .put = conexant_mux_enum_put,
1442 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001443 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001444
Tobin Davisc9b443d2006-11-14 12:13:39 +01001445 { } /* end */
1446};
1447
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001448static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001449 /* Enable retasking pins as output, initially without power amp */
1450 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1451 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1452 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1453
1454 /* Disable digital (SPDIF) pins initially, but users can enable
1455 * them via a mixer switch. In the case of SPDIF-out, this initverb
1456 * payload also sets the generation to 0, output to be in "consumer"
1457 * PCM format, copyright asserted, no pre-emphasis and no validity
1458 * control.
1459 */
1460 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1461
1462 /* Ensure mic1, mic2, line1 pin widgets take input from the
1463 * OUT1 sum bus when acting as an output.
1464 */
1465 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1466 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1467
1468 /* Start with output sum widgets muted and their output gains at min */
1469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1470 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1471
1472 /* Unmute retasking pin widget output buffers since the default
1473 * state appears to be output. As the pin mode is changed by the
1474 * user the pin mode control will take care of enabling the pin's
1475 * input/output buffers as needed.
1476 */
1477 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1478 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1479 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1480
1481 /* Mute capture amp left and right */
1482 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1483
1484 /* Set ADC connection select to match default mixer setting (mic1
1485 * pin)
1486 */
1487 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1488
1489 /* Mute all inputs to mixer widget (even unconnected ones) */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1492 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1494 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1495 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1497 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1498
1499 { }
1500};
1501#endif
1502
1503
1504/* initialize jack-sensing, too */
1505static int cxt5047_hp_init(struct hda_codec *codec)
1506{
1507 conexant_init(codec);
1508 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509 return 0;
1510}
1511
1512
1513enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001514 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1515 CXT5047_LAPTOP_HP, /* Some HP laptops */
1516 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001517#ifdef CONFIG_SND_DEBUG
1518 CXT5047_TEST,
1519#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001520 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001521 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522};
1523
Takashi Iwaiea734962011-01-17 11:29:34 +01001524static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001525 [CXT5047_LAPTOP] = "laptop",
1526 [CXT5047_LAPTOP_HP] = "laptop-hp",
1527 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001529 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001531 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001532};
1533
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001534static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001535 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001536 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1537 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001538 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001539 {}
1540};
1541
1542static int patch_cxt5047(struct hda_codec *codec)
1543{
1544 struct conexant_spec *spec;
1545 int board_config;
1546
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001547 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1548 cxt5047_models,
1549 cxt5047_cfg_tbl);
1550#if 0 /* not enabled as default, as BIOS often broken for this codec */
1551 if (board_config < 0)
1552 board_config = CXT5047_AUTO;
1553#endif
1554 if (board_config == CXT5047_AUTO)
1555 return patch_conexant_auto(codec);
1556
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1558 if (!spec)
1559 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001561 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562
1563 spec->multiout.max_channels = 2;
1564 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1565 spec->multiout.dac_nids = cxt5047_dac_nids;
1566 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1567 spec->num_adc_nids = 1;
1568 spec->adc_nids = cxt5047_adc_nids;
1569 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001571 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001572 spec->num_init_verbs = 1;
1573 spec->init_verbs[0] = cxt5047_init_verbs;
1574 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001575 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1576 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001577
1578 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001579
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580 switch (board_config) {
1581 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001582 spec->num_mixers = 2;
1583 spec->mixers[1] = cxt5047_hp_spk_mixers;
1584 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001585 break;
1586 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001587 spec->num_mixers = 2;
1588 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001589 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001590 codec->patch_ops.init = cxt5047_hp_init;
1591 break;
1592 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001593 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001594 spec->num_mixers = 2;
1595 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596 spec->num_init_verbs = 2;
1597 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001598 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001599 break;
1600#ifdef CONFIG_SND_DEBUG
1601 case CXT5047_TEST:
1602 spec->input_mux = &cxt5047_test_capture_source;
1603 spec->mixers[0] = cxt5047_test_mixer;
1604 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001605 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001606#endif
1607 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001608 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001609
1610 switch (codec->subsystem_id >> 16) {
1611 case 0x103c:
1612 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1613 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1614 * with 0 dB offset 0x17)
1615 */
1616 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1617 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1618 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1619 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1620 (1 << AC_AMPCAP_MUTE_SHIFT));
1621 break;
1622 }
1623
Tobin Davisc9b443d2006-11-14 12:13:39 +01001624 return 0;
1625}
1626
Takashi Iwai461e2c72008-01-25 11:35:17 +01001627/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001628static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1629static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001630
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001631static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001632 { 2, NULL },
1633};
1634
1635static void cxt5051_update_speaker(struct hda_codec *codec)
1636{
1637 struct conexant_spec *spec = codec->spec;
1638 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001639 /* headphone pin */
1640 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1641 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1642 pinctl);
1643 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001644 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1645 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1646 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001647 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1648 if (spec->ideapad)
1649 snd_hda_codec_write(codec, 0x1b, 0,
1650 AC_VERB_SET_PIN_WIDGET_CONTROL,
1651 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001652}
1653
1654/* turn on/off EAPD (+ mute HP) as a master switch */
1655static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1656 struct snd_ctl_elem_value *ucontrol)
1657{
1658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1659
1660 if (!cxt_eapd_put(kcontrol, ucontrol))
1661 return 0;
1662 cxt5051_update_speaker(codec);
1663 return 1;
1664}
1665
1666/* toggle input of built-in and mic jack appropriately */
1667static void cxt5051_portb_automic(struct hda_codec *codec)
1668{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001669 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001670 unsigned int present;
1671
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001672 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001673 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001674 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001675 snd_hda_codec_write(codec, 0x14, 0,
1676 AC_VERB_SET_CONNECT_SEL,
1677 present ? 0x01 : 0x00);
1678}
1679
1680/* switch the current ADC according to the jack state */
1681static void cxt5051_portc_automic(struct hda_codec *codec)
1682{
1683 struct conexant_spec *spec = codec->spec;
1684 unsigned int present;
1685 hda_nid_t new_adc;
1686
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001687 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001688 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001689 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001690 if (present)
1691 spec->cur_adc_idx = 1;
1692 else
1693 spec->cur_adc_idx = 0;
1694 new_adc = spec->adc_nids[spec->cur_adc_idx];
1695 if (spec->cur_adc && spec->cur_adc != new_adc) {
1696 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001697 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001698 spec->cur_adc = new_adc;
1699 snd_hda_codec_setup_stream(codec, new_adc,
1700 spec->cur_adc_stream_tag, 0,
1701 spec->cur_adc_format);
1702 }
1703}
1704
1705/* mute internal speaker if HP is plugged */
1706static void cxt5051_hp_automute(struct hda_codec *codec)
1707{
1708 struct conexant_spec *spec = codec->spec;
1709
Takashi Iwaid56757a2009-11-18 08:00:14 +01001710 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001711 cxt5051_update_speaker(codec);
1712}
1713
1714/* unsolicited event for HP jack sensing */
1715static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1716 unsigned int res)
1717{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001718 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 switch (res >> 26) {
1720 case CONEXANT_HP_EVENT:
1721 cxt5051_hp_automute(codec);
1722 break;
1723 case CXT5051_PORTB_EVENT:
1724 cxt5051_portb_automic(codec);
1725 break;
1726 case CXT5051_PORTC_EVENT:
1727 cxt5051_portc_automic(codec);
1728 break;
1729 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001730 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001731}
1732
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001733static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001734 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1735 {
1736 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1737 .name = "Master Playback Switch",
1738 .info = cxt_eapd_info,
1739 .get = cxt_eapd_get,
1740 .put = cxt5051_hp_master_sw_put,
1741 .private_value = 0x1a,
1742 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001743 {}
1744};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001745
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001746static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001747 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1748 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001749 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1750 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001751 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1752 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001753 {}
1754};
1755
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001756static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001757 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1758 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001759 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1760 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001761 {}
1762};
1763
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001764static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001765 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1766 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001767 {}
1768};
1769
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001770static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001771 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1772 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001773 {}
1774};
1775
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001776static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001777 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1778 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001779 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1780 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001781 {}
1782};
1783
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001784static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001785 /* Line in, Mic */
1786 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1787 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1788 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1789 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1790 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1791 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1792 /* SPK */
1793 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1794 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1795 /* HP, Amp */
1796 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1797 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1798 /* DAC1 */
1799 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001800 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001801 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1802 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1803 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1804 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001805 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001806 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1807 /* EAPD */
1808 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1809 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001810 { } /* end */
1811};
1812
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001813static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001814 /* Line in, Mic */
1815 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1816 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1817 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1818 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1819 /* SPK */
1820 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1821 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1822 /* HP, Amp */
1823 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1824 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1825 /* DAC1 */
1826 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001827 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001828 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1829 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1830 /* SPDIF route: PCM */
1831 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1832 /* EAPD */
1833 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1834 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001835 { } /* end */
1836};
1837
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001838static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001839 /* Line in, Mic */
1840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1841 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1842 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1843 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1844 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1845 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1846 /* SPK */
1847 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1849 /* HP, Amp */
1850 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1851 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1852 /* Docking HP */
1853 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1854 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1855 /* DAC1 */
1856 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001857 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001858 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1859 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1860 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1861 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001862 {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 -05001863 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1864 /* EAPD */
1865 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1866 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001867 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1868 { } /* end */
1869};
1870
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001871static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001872 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001874 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1875 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1876 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1877 /* SPK */
1878 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1879 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1880 /* HP, Amp */
1881 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1882 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1883 /* DAC1 */
1884 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001885 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1887 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1888 /* SPDIF route: PCM */
1889 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1890 /* EAPD */
1891 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1892 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001893 { } /* end */
1894};
1895
Takashi Iwai6953e552010-01-24 11:00:27 +01001896static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1897 unsigned int event)
1898{
1899 snd_hda_codec_write(codec, nid, 0,
1900 AC_VERB_SET_UNSOLICITED_ENABLE,
1901 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001902 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1903 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001904}
1905
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001906static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001907 /* Subwoofer */
1908 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1909 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1910 { } /* end */
1911};
1912
Takashi Iwai461e2c72008-01-25 11:35:17 +01001913/* initialize jack-sensing, too */
1914static int cxt5051_init(struct hda_codec *codec)
1915{
Takashi Iwai6953e552010-01-24 11:00:27 +01001916 struct conexant_spec *spec = codec->spec;
1917
Takashi Iwai461e2c72008-01-25 11:35:17 +01001918 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001919 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001920
1921 if (spec->auto_mic & AUTO_MIC_PORTB)
1922 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1923 if (spec->auto_mic & AUTO_MIC_PORTC)
1924 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1925
Takashi Iwai461e2c72008-01-25 11:35:17 +01001926 if (codec->patch_ops.unsol_event) {
1927 cxt5051_hp_automute(codec);
1928 cxt5051_portb_automic(codec);
1929 cxt5051_portc_automic(codec);
1930 }
1931 return 0;
1932}
1933
1934
1935enum {
1936 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1937 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001938 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001939 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001940 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001941 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001942 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001943 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001944 CXT5051_MODELS
1945};
1946
Takashi Iwaiea734962011-01-17 11:29:34 +01001947static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001948 [CXT5051_LAPTOP] = "laptop",
1949 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001950 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001951 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001952 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001953 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001954 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001955 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001956};
1957
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001958static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001959 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001960 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001961 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001962 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001963 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1964 CXT5051_LAPTOP),
1965 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001966 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001967 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001968 {}
1969};
1970
1971static int patch_cxt5051(struct hda_codec *codec)
1972{
1973 struct conexant_spec *spec;
1974 int board_config;
1975
Takashi Iwai6764bce2011-05-13 16:52:25 +02001976 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1977 cxt5051_models,
1978 cxt5051_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001979#if 0 /* use the old method just for safety */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001980 if (board_config < 0)
1981 board_config = CXT5051_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001982#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001983 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001984 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001985
Takashi Iwai461e2c72008-01-25 11:35:17 +01001986 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1987 if (!spec)
1988 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001989 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001990 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001991
1992 codec->patch_ops = conexant_patch_ops;
1993 codec->patch_ops.init = cxt5051_init;
1994
1995 spec->multiout.max_channels = 2;
1996 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1997 spec->multiout.dac_nids = cxt5051_dac_nids;
1998 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1999 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2000 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002001 spec->num_mixers = 2;
2002 spec->mixers[0] = cxt5051_capture_mixers;
2003 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002004 spec->num_init_verbs = 1;
2005 spec->init_verbs[0] = cxt5051_init_verbs;
2006 spec->spdif_route = 0;
2007 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2008 spec->channel_mode = cxt5051_modes;
2009 spec->cur_adc = 0;
2010 spec->cur_adc_idx = 0;
2011
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002012 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2013
Takashi Iwai79d7d532009-03-04 09:03:50 +01002014 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2015
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002016 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002017 switch (board_config) {
2018 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002019 spec->mixers[0] = cxt5051_hp_mixers;
2020 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002021 case CXT5051_HP_DV6736:
2022 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2023 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002024 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002025 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002026 case CXT5051_LENOVO_X200:
2027 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002028 /* Thinkpad X301 does not have S/PDIF wired and no ability
2029 to use a docking station. */
2030 if (codec->subsystem_id == 0x17aa211f)
2031 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002032 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002033 case CXT5051_F700:
2034 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2035 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002036 spec->auto_mic = 0;
2037 break;
2038 case CXT5051_TOSHIBA:
2039 spec->mixers[0] = cxt5051_toshiba_mixers;
2040 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002041 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002042 case CXT5051_IDEAPAD:
2043 spec->init_verbs[spec->num_init_verbs++] =
2044 cxt5051_ideapad_init_verbs;
2045 spec->ideapad = 1;
2046 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002047 }
2048
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002049 if (spec->beep_amp)
2050 snd_hda_attach_beep_device(codec, spec->beep_amp);
2051
Takashi Iwai461e2c72008-01-25 11:35:17 +01002052 return 0;
2053}
2054
Daniel Drake0fb67e92009-07-16 14:46:57 +01002055/* Conexant 5066 specific */
2056
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002057static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2058static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2059static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2060static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002061
Daniel Drakedbaccc02009-11-09 15:17:24 +00002062/* OLPC's microphone port is DC coupled for use with external sensors,
2063 * therefore we use a 50% mic bias in order to center the input signal with
2064 * the DC input range of the codec. */
2065#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2066
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002067static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002068 { 2, NULL },
2069};
2070
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002071#define HP_PRESENT_PORT_A (1 << 0)
2072#define HP_PRESENT_PORT_D (1 << 1)
2073#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2074#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2075
Daniel Drake0fb67e92009-07-16 14:46:57 +01002076static void cxt5066_update_speaker(struct hda_codec *codec)
2077{
2078 struct conexant_spec *spec = codec->spec;
2079 unsigned int pinctl;
2080
John Baboval3a253442010-12-02 11:21:31 -05002081 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2082 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002083
2084 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002085 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002086 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2087 pinctl);
2088
2089 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002090 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2091 if (spec->dell_automute || spec->thinkpad) {
2092 /* Mute if Port A is connected */
2093 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002094 pinctl = 0;
2095 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002096 /* Thinkpad/Dell doesn't give pin-D status */
2097 if (!hp_port_d_present(spec))
2098 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002099 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002100 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2101 pinctl);
2102
2103 /* CLASS_D AMP */
2104 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2105 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2106 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002107}
2108
2109/* turn on/off EAPD (+ mute HP) as a master switch */
2110static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2111 struct snd_ctl_elem_value *ucontrol)
2112{
2113 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2114
2115 if (!cxt_eapd_put(kcontrol, ucontrol))
2116 return 0;
2117
2118 cxt5066_update_speaker(codec);
2119 return 1;
2120}
2121
Daniel Drakec4cfe662010-01-07 13:47:04 +01002122static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2123 .num_items = 3,
2124 .items = {
2125 { "Off", PIN_IN },
2126 { "50%", PIN_VREF50 },
2127 { "80%", PIN_VREF80 },
2128 },
2129};
2130
2131static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2132{
2133 struct conexant_spec *spec = codec->spec;
2134 /* Even though port F is the DC input, the bias is controlled on port B.
2135 * we also leave that port as an active input (but unselected) in DC mode
2136 * just in case that is necessary to make the bias setting take effect. */
2137 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2138 AC_VERB_SET_PIN_WIDGET_CONTROL,
2139 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2140}
2141
Daniel Drake75f89912010-01-07 13:46:25 +01002142/* OLPC defers mic widget control until when capture is started because the
2143 * microphone LED comes on as soon as these settings are put in place. if we
2144 * did this before recording, it would give the false indication that recording
2145 * is happening when it is not. */
2146static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002147{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002148 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002149 if (!spec->recording)
2150 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002151
Daniel Drakec4cfe662010-01-07 13:47:04 +01002152 if (spec->dc_enable) {
2153 /* in DC mode we ignore presence detection and just use the jack
2154 * through our special DC port */
2155 const struct hda_verb enable_dc_mode[] = {
2156 /* disble internal mic, port C */
2157 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2158
2159 /* enable DC capture, port F */
2160 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2161 {},
2162 };
2163
2164 snd_hda_sequence_write(codec, enable_dc_mode);
2165 /* port B input disabled (and bias set) through the following call */
2166 cxt5066_set_olpc_dc_bias(codec);
2167 return;
2168 }
2169
2170 /* disable DC (port F) */
2171 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2172
Daniel Drake75f89912010-01-07 13:46:25 +01002173 /* external mic, port B */
2174 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2175 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002176
Daniel Drake75f89912010-01-07 13:46:25 +01002177 /* internal mic, port C */
2178 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2179 spec->ext_mic_present ? 0 : PIN_VREF80);
2180}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002181
Daniel Drake75f89912010-01-07 13:46:25 +01002182/* toggle input of built-in and mic jack appropriately */
2183static void cxt5066_olpc_automic(struct hda_codec *codec)
2184{
2185 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002186 unsigned int present;
2187
Daniel Drakec4cfe662010-01-07 13:47:04 +01002188 if (spec->dc_enable) /* don't do presence detection in DC mode */
2189 return;
2190
Daniel Drake75f89912010-01-07 13:46:25 +01002191 present = snd_hda_codec_read(codec, 0x1a, 0,
2192 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2193 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002194 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002195 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002196 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002197
2198 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2199 present ? 0 : 1);
2200 spec->ext_mic_present = !!present;
2201
2202 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002203}
2204
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002205/* toggle input of built-in digital mic and mic jack appropriately */
2206static void cxt5066_vostro_automic(struct hda_codec *codec)
2207{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002208 unsigned int present;
2209
2210 struct hda_verb ext_mic_present[] = {
2211 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002212 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002213
2214 /* switch to external mic input */
2215 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2216 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2217
2218 /* disable internal digital mic */
2219 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2220 {}
2221 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002222 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002223 /* enable internal mic, port C */
2224 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2225
2226 /* switch to internal mic input */
2227 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2228
2229 /* disable external mic, port B */
2230 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2231 {}
2232 };
2233
2234 present = snd_hda_jack_detect(codec, 0x1a);
2235 if (present) {
2236 snd_printdd("CXT5066: external microphone detected\n");
2237 snd_hda_sequence_write(codec, ext_mic_present);
2238 } else {
2239 snd_printdd("CXT5066: external microphone absent\n");
2240 snd_hda_sequence_write(codec, ext_mic_absent);
2241 }
2242}
2243
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002244/* toggle input of built-in digital mic and mic jack appropriately */
2245static void cxt5066_ideapad_automic(struct hda_codec *codec)
2246{
2247 unsigned int present;
2248
2249 struct hda_verb ext_mic_present[] = {
2250 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2251 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2252 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2253 {}
2254 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002255 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002256 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2257 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2258 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2259 {}
2260 };
2261
2262 present = snd_hda_jack_detect(codec, 0x1b);
2263 if (present) {
2264 snd_printdd("CXT5066: external microphone detected\n");
2265 snd_hda_sequence_write(codec, ext_mic_present);
2266 } else {
2267 snd_printdd("CXT5066: external microphone absent\n");
2268 snd_hda_sequence_write(codec, ext_mic_absent);
2269 }
2270}
2271
David Henningssona1d69062011-01-21 13:33:28 +01002272
2273/* toggle input of built-in digital mic and mic jack appropriately */
2274static void cxt5066_asus_automic(struct hda_codec *codec)
2275{
2276 unsigned int present;
2277
2278 present = snd_hda_jack_detect(codec, 0x1b);
2279 snd_printdd("CXT5066: external microphone present=%d\n", present);
2280 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2281 present ? 1 : 0);
2282}
2283
2284
David Henningsson048e78a2010-09-02 08:35:47 +02002285/* toggle input of built-in digital mic and mic jack appropriately */
2286static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2287{
2288 unsigned int present;
2289
2290 present = snd_hda_jack_detect(codec, 0x1b);
2291 snd_printdd("CXT5066: external microphone present=%d\n", present);
2292 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2293 present ? 1 : 3);
2294}
2295
2296
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002297/* toggle input of built-in digital mic and mic jack appropriately
2298 order is: external mic -> dock mic -> interal mic */
2299static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2300{
2301 unsigned int ext_present, dock_present;
2302
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002303 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002304 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2305 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2306 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2307 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2308 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2309 {}
2310 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002311 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002312 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2313 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2314 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2315 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2316 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2317 {}
2318 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002319 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002320 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2321 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2322 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2323 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2324 {}
2325 };
2326
2327 ext_present = snd_hda_jack_detect(codec, 0x1b);
2328 dock_present = snd_hda_jack_detect(codec, 0x1a);
2329 if (ext_present) {
2330 snd_printdd("CXT5066: external microphone detected\n");
2331 snd_hda_sequence_write(codec, ext_mic_present);
2332 } else if (dock_present) {
2333 snd_printdd("CXT5066: dock microphone detected\n");
2334 snd_hda_sequence_write(codec, dock_mic_present);
2335 } else {
2336 snd_printdd("CXT5066: external microphone absent\n");
2337 snd_hda_sequence_write(codec, ext_mic_absent);
2338 }
2339}
2340
Daniel Drake0fb67e92009-07-16 14:46:57 +01002341/* mute internal speaker if HP is plugged */
2342static void cxt5066_hp_automute(struct hda_codec *codec)
2343{
2344 struct conexant_spec *spec = codec->spec;
2345 unsigned int portA, portD;
2346
2347 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002348 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002349
2350 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002351 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002352
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002353 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2354 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002355 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2356 portA, portD, spec->hp_present);
2357 cxt5066_update_speaker(codec);
2358}
2359
David Henningsson02b6b5b2011-01-21 13:27:39 +01002360/* Dispatch the right mic autoswitch function */
2361static void cxt5066_automic(struct hda_codec *codec)
2362{
2363 struct conexant_spec *spec = codec->spec;
2364
2365 if (spec->dell_vostro)
2366 cxt5066_vostro_automic(codec);
2367 else if (spec->ideapad)
2368 cxt5066_ideapad_automic(codec);
2369 else if (spec->thinkpad)
2370 cxt5066_thinkpad_automic(codec);
2371 else if (spec->hp_laptop)
2372 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002373 else if (spec->asus)
2374 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002375}
2376
Daniel Drake0fb67e92009-07-16 14:46:57 +01002377/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002378static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002379{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002380 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002381 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2382 switch (res >> 26) {
2383 case CONEXANT_HP_EVENT:
2384 cxt5066_hp_automute(codec);
2385 break;
2386 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002387 /* ignore mic events in DC mode; we're always using the jack */
2388 if (!spec->dc_enable)
2389 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002390 break;
2391 }
2392}
2393
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002394/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002395static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002396{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002397 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002398 switch (res >> 26) {
2399 case CONEXANT_HP_EVENT:
2400 cxt5066_hp_automute(codec);
2401 break;
2402 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002403 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002404 break;
2405 }
2406}
2407
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002408
Daniel Drake0fb67e92009-07-16 14:46:57 +01002409static const struct hda_input_mux cxt5066_analog_mic_boost = {
2410 .num_items = 5,
2411 .items = {
2412 { "0dB", 0 },
2413 { "10dB", 1 },
2414 { "20dB", 2 },
2415 { "30dB", 3 },
2416 { "40dB", 4 },
2417 },
2418};
2419
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002420static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002421{
2422 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002423 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002424 AC_VERB_SET_AMP_GAIN_MUTE,
2425 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2426 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002427 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002428 /* adjust the internal mic as well...it is not through 0x17 */
2429 snd_hda_codec_write_cache(codec, 0x23, 0,
2430 AC_VERB_SET_AMP_GAIN_MUTE,
2431 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2432 cxt5066_analog_mic_boost.
2433 items[spec->mic_boost].index);
2434 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002435}
2436
Daniel Drake0fb67e92009-07-16 14:46:57 +01002437static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2438 struct snd_ctl_elem_info *uinfo)
2439{
2440 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2441}
2442
2443static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2444 struct snd_ctl_elem_value *ucontrol)
2445{
2446 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002447 struct conexant_spec *spec = codec->spec;
2448 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002449 return 0;
2450}
2451
2452static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2453 struct snd_ctl_elem_value *ucontrol)
2454{
2455 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002456 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002457 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2458 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002459 idx = ucontrol->value.enumerated.item[0];
2460 if (idx >= imux->num_items)
2461 idx = imux->num_items - 1;
2462
Daniel Drakec4cfe662010-01-07 13:47:04 +01002463 spec->mic_boost = idx;
2464 if (!spec->dc_enable)
2465 cxt5066_set_mic_boost(codec);
2466 return 1;
2467}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002468
Daniel Drakec4cfe662010-01-07 13:47:04 +01002469static void cxt5066_enable_dc(struct hda_codec *codec)
2470{
2471 const struct hda_verb enable_dc_mode[] = {
2472 /* disable gain */
2473 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2474
2475 /* switch to DC input */
2476 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2477 {}
2478 };
2479
2480 /* configure as input source */
2481 snd_hda_sequence_write(codec, enable_dc_mode);
2482 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2483}
2484
2485static void cxt5066_disable_dc(struct hda_codec *codec)
2486{
2487 /* reconfigure input source */
2488 cxt5066_set_mic_boost(codec);
2489 /* automic also selects the right mic if we're recording */
2490 cxt5066_olpc_automic(codec);
2491}
2492
2493static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2494 struct snd_ctl_elem_value *ucontrol)
2495{
2496 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2497 struct conexant_spec *spec = codec->spec;
2498 ucontrol->value.integer.value[0] = spec->dc_enable;
2499 return 0;
2500}
2501
2502static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2503 struct snd_ctl_elem_value *ucontrol)
2504{
2505 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2506 struct conexant_spec *spec = codec->spec;
2507 int dc_enable = !!ucontrol->value.integer.value[0];
2508
2509 if (dc_enable == spec->dc_enable)
2510 return 0;
2511
2512 spec->dc_enable = dc_enable;
2513 if (dc_enable)
2514 cxt5066_enable_dc(codec);
2515 else
2516 cxt5066_disable_dc(codec);
2517
2518 return 1;
2519}
2520
2521static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2522 struct snd_ctl_elem_info *uinfo)
2523{
2524 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2525}
2526
2527static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2528 struct snd_ctl_elem_value *ucontrol)
2529{
2530 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2531 struct conexant_spec *spec = codec->spec;
2532 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2533 return 0;
2534}
2535
2536static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2537 struct snd_ctl_elem_value *ucontrol)
2538{
2539 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2540 struct conexant_spec *spec = codec->spec;
2541 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2542 unsigned int idx;
2543
2544 idx = ucontrol->value.enumerated.item[0];
2545 if (idx >= imux->num_items)
2546 idx = imux->num_items - 1;
2547
2548 spec->dc_input_bias = idx;
2549 if (spec->dc_enable)
2550 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002551 return 1;
2552}
2553
Daniel Drake75f89912010-01-07 13:46:25 +01002554static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2555{
2556 struct conexant_spec *spec = codec->spec;
2557 /* mark as recording and configure the microphone widget so that the
2558 * recording LED comes on. */
2559 spec->recording = 1;
2560 cxt5066_olpc_select_mic(codec);
2561}
2562
2563static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2564{
2565 struct conexant_spec *spec = codec->spec;
2566 const struct hda_verb disable_mics[] = {
2567 /* disable external mic, port B */
2568 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2569
2570 /* disble internal mic, port C */
2571 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002572
2573 /* disable DC capture, port F */
2574 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002575 {},
2576 };
2577
2578 snd_hda_sequence_write(codec, disable_mics);
2579 spec->recording = 0;
2580}
2581
Andy Robinsonf6a24912011-01-24 10:12:37 -05002582static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002583 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002584 int num_pins)
2585{
2586 struct conexant_spec *spec = codec->spec;
2587 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2588 int i;
2589
2590 for (i = 0; i < num_pins; i++, dig_pins++) {
2591 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2592 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2593 continue;
2594 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2595 continue;
2596 if (spec->slave_dig_outs[0])
2597 nid_loc++;
2598 else
2599 nid_loc = spec->slave_dig_outs;
2600 }
2601}
2602
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002603static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002604 .num_items = 4,
2605 .items = {
2606 { "Mic B", 0 },
2607 { "Mic C", 1 },
2608 { "Mic E", 2 },
2609 { "Mic F", 3 },
2610 },
2611};
2612
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002613static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002614 .ops = &snd_hda_bind_vol,
2615 .values = {
2616 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2617 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2618 0
2619 },
2620};
2621
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002622static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002623 .ops = &snd_hda_bind_sw,
2624 .values = {
2625 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2626 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2627 0
2628 },
2629};
2630
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002631static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002632 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2633 {}
2634};
2635
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002636static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002637 {
2638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2639 .name = "Master Playback Volume",
2640 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2641 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2642 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002643 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002644 .info = snd_hda_mixer_amp_volume_info,
2645 .get = snd_hda_mixer_amp_volume_get,
2646 .put = snd_hda_mixer_amp_volume_put,
2647 .tlv = { .c = snd_hda_mixer_amp_tlv },
2648 /* offset by 28 volume steps to limit minimum gain to -46dB */
2649 .private_value =
2650 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2651 },
2652 {}
2653};
2654
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002655static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002656 {
2657 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2658 .name = "DC Mode Enable Switch",
2659 .info = snd_ctl_boolean_mono_info,
2660 .get = cxt5066_olpc_dc_get,
2661 .put = cxt5066_olpc_dc_put,
2662 },
2663 {
2664 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2665 .name = "DC Input Bias Enum",
2666 .info = cxt5066_olpc_dc_bias_enum_info,
2667 .get = cxt5066_olpc_dc_bias_enum_get,
2668 .put = cxt5066_olpc_dc_bias_enum_put,
2669 },
2670 {}
2671};
2672
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002673static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002674 {
2675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2676 .name = "Master Playback Switch",
2677 .info = cxt_eapd_info,
2678 .get = cxt_eapd_get,
2679 .put = cxt5066_hp_master_sw_put,
2680 .private_value = 0x1d,
2681 },
2682
2683 {
2684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002685 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002686 .info = cxt5066_mic_boost_mux_enum_info,
2687 .get = cxt5066_mic_boost_mux_enum_get,
2688 .put = cxt5066_mic_boost_mux_enum_put,
2689 },
2690
2691 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2692 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2693 {}
2694};
2695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002696static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002697 {
2698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002699 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002700 .info = cxt5066_mic_boost_mux_enum_info,
2701 .get = cxt5066_mic_boost_mux_enum_get,
2702 .put = cxt5066_mic_boost_mux_enum_put,
2703 .private_value = 0x23 | 0x100,
2704 },
2705 {}
2706};
2707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002708static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002709 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2710 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2711 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2712 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2713
2714 /* Speakers */
2715 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2716 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2717
2718 /* HP, Amp */
2719 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2720 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2721
2722 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2723 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2724
2725 /* DAC1 */
2726 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2727
2728 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2729 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2730 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2731 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2732 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2733 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2734
2735 /* no digital microphone support yet */
2736 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2737
2738 /* Audio input selector */
2739 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2740
2741 /* SPDIF route: PCM */
2742 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2743 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2744
2745 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2746 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2747
2748 /* EAPD */
2749 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2750
2751 /* not handling these yet */
2752 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2753 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2754 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2755 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2756 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2757 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2758 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2759 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2760 { } /* end */
2761};
2762
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002763static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002764 /* Port A: headphones */
2765 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2766 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2767
2768 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002769 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002770
2771 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002772 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002773
2774 /* Port D: unused */
2775 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2776
2777 /* Port E: unused, but has primary EAPD */
2778 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2779 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2780
Daniel Drakec4cfe662010-01-07 13:47:04 +01002781 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002782 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2783
2784 /* Port G: internal speakers */
2785 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2786 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2787
2788 /* DAC1 */
2789 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2790
2791 /* DAC2: unused */
2792 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2793
2794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2796 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2797 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2798 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2799 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2800 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2801 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2802 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2803 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2804 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2805 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2806
2807 /* Disable digital microphone port */
2808 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2809
2810 /* Audio input selectors */
2811 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2812 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2813
2814 /* Disable SPDIF */
2815 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2816 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2817
2818 /* enable unsolicited events for Port A and B */
2819 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2820 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2821 { } /* end */
2822};
2823
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002824static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002825 /* Port A: headphones */
2826 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2827 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2828
2829 /* Port B: external microphone */
2830 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831
2832 /* Port C: unused */
2833 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2834
2835 /* Port D: unused */
2836 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2837
2838 /* Port E: unused, but has primary EAPD */
2839 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2840 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2841
2842 /* Port F: unused */
2843 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2844
2845 /* Port G: internal speakers */
2846 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2847 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2848
2849 /* DAC1 */
2850 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2851
2852 /* DAC2: unused */
2853 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2854
2855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2857 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2858 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2859 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2860 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2861 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2862 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2863 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2864 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2865 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2866 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2867
2868 /* Digital microphone port */
2869 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2870
2871 /* Audio input selectors */
2872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2873 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2874
2875 /* Disable SPDIF */
2876 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2877 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2878
2879 /* enable unsolicited events for Port A and B */
2880 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2881 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2882 { } /* end */
2883};
2884
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002885static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002886 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2887 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2888 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2889 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2890
2891 /* Speakers */
2892 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2893 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2894
2895 /* HP, Amp */
2896 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2897 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2898
2899 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2900 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2901
2902 /* DAC1 */
2903 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2904
2905 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2906 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2907 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2910 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2911 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2912
2913 /* Audio input selector */
2914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2915 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2916
2917 /* SPDIF route: PCM */
2918 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2919 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2920
2921 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2922 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2923
2924 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002925 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002926
2927 /* EAPD */
2928 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2929
2930 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2931 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2932 { } /* end */
2933};
2934
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002935static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002936 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2937 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2938
2939 /* Port G: internal speakers */
2940 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2941 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2942
2943 /* Port A: HP, Amp */
2944 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2945 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2946
2947 /* Port B: Mic Dock */
2948 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2949
2950 /* Port C: Mic */
2951 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2952
2953 /* Port D: HP Dock, Amp */
2954 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2955 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2956
2957 /* DAC1 */
2958 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2959
2960 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2961 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2962 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2963 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2964 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2965 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2966 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2967
2968 /* Audio input selector */
2969 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2970 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2971
2972 /* SPDIF route: PCM */
2973 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2974 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2975
2976 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2977 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2978
2979 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002980 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002981
2982 /* EAPD */
2983 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2984
2985 /* enable unsolicited events for Port A, B, C and D */
2986 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2987 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2988 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2989 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2990 { } /* end */
2991};
2992
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002993static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002994 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2995 { } /* end */
2996};
2997
David Henningsson048e78a2010-09-02 08:35:47 +02002998
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002999static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02003000 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3001 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3002 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3003 { } /* end */
3004};
3005
Daniel Drake0fb67e92009-07-16 14:46:57 +01003006/* initialize jack-sensing, too */
3007static int cxt5066_init(struct hda_codec *codec)
3008{
3009 snd_printdd("CXT5066: init\n");
3010 conexant_init(codec);
3011 if (codec->patch_ops.unsol_event) {
3012 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003013 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003014 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003015 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003016 return 0;
3017}
3018
Daniel Drake75f89912010-01-07 13:46:25 +01003019static int cxt5066_olpc_init(struct hda_codec *codec)
3020{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003021 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003022 snd_printdd("CXT5066: init\n");
3023 conexant_init(codec);
3024 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003025 if (!spec->dc_enable) {
3026 cxt5066_set_mic_boost(codec);
3027 cxt5066_olpc_automic(codec);
3028 } else {
3029 cxt5066_enable_dc(codec);
3030 }
Daniel Drake75f89912010-01-07 13:46:25 +01003031 return 0;
3032}
3033
Daniel Drake0fb67e92009-07-16 14:46:57 +01003034enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003035 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003036 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3037 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003038 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003039 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003040 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003041 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003042 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003043 CXT5066_MODELS
3044};
3045
Takashi Iwaiea734962011-01-17 11:29:34 +01003046static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003047 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003048 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3049 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003050 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003051 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003052 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003053 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003054 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003055};
3056
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003057static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003058 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003059 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003060 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003061 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003062 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003063 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003064 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3065 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003066 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003067 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003068 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003069 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003070 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003071 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003072 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003073 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3074 CXT5066_LAPTOP),
3075 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003076 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003077 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003078 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003079 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003080 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003081 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003082 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003083 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003084 {}
3085};
3086
3087static int patch_cxt5066(struct hda_codec *codec)
3088{
3089 struct conexant_spec *spec;
3090 int board_config;
3091
3092 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3093 if (!spec)
3094 return -ENOMEM;
3095 codec->spec = spec;
3096
3097 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003098 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003099
3100 spec->dell_automute = 0;
3101 spec->multiout.max_channels = 2;
3102 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3103 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003104 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3105 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003106 spec->num_adc_nids = 1;
3107 spec->adc_nids = cxt5066_adc_nids;
3108 spec->capsrc_nids = cxt5066_capsrc_nids;
3109 spec->input_mux = &cxt5066_capture_source;
3110
3111 spec->port_d_mode = PIN_HP;
3112
3113 spec->num_init_verbs = 1;
3114 spec->init_verbs[0] = cxt5066_init_verbs;
3115 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3116 spec->channel_mode = cxt5066_modes;
3117 spec->cur_adc = 0;
3118 spec->cur_adc_idx = 0;
3119
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003120 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3121
Daniel Drake0fb67e92009-07-16 14:46:57 +01003122 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3123 cxt5066_models, cxt5066_cfg_tbl);
3124 switch (board_config) {
3125 default:
3126 case CXT5066_LAPTOP:
3127 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3128 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3129 break;
3130 case CXT5066_DELL_LAPTOP:
3131 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3132 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3133
3134 spec->port_d_mode = PIN_OUT;
3135 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3136 spec->num_init_verbs++;
3137 spec->dell_automute = 1;
3138 break;
David Henningssona1d69062011-01-21 13:33:28 +01003139 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003140 case CXT5066_HP_LAPTOP:
3141 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003142 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003143 spec->init_verbs[spec->num_init_verbs] =
3144 cxt5066_init_verbs_hp_laptop;
3145 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003146 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3147 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003148 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3149 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3150 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003151 if (board_config == CXT5066_HP_LAPTOP)
3152 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003153 /* input source automatically selected */
3154 spec->input_mux = NULL;
3155 spec->port_d_mode = 0;
3156 spec->mic_boost = 3; /* default 30dB gain */
3157 break;
3158
Daniel Drake0fb67e92009-07-16 14:46:57 +01003159 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003160 codec->patch_ops.init = cxt5066_olpc_init;
3161 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003162 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3163 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003164 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003165 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3166 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003167 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003168
3169 /* no S/PDIF out */
3170 spec->multiout.dig_out_nid = 0;
3171
3172 /* input source automatically selected */
3173 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003174
3175 /* our capture hooks which allow us to turn on the microphone LED
3176 * at the right time */
3177 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3178 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003179 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003180 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003181 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003182 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003183 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3184 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3185 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003186 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003187 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003188 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003189 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003190
3191 /* no S/PDIF out */
3192 spec->multiout.dig_out_nid = 0;
3193
3194 /* input source automatically selected */
3195 spec->input_mux = NULL;
3196 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003197 case CXT5066_IDEAPAD:
3198 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003199 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003200 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3201 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3202 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3203 spec->port_d_mode = 0;
3204 spec->ideapad = 1;
3205 spec->mic_boost = 2; /* default 20dB gain */
3206
3207 /* no S/PDIF out */
3208 spec->multiout.dig_out_nid = 0;
3209
3210 /* input source automatically selected */
3211 spec->input_mux = NULL;
3212 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003213 case CXT5066_THINKPAD:
3214 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003215 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003216 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3217 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3218 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3219 spec->thinkpad = 1;
3220 spec->port_d_mode = PIN_OUT;
3221 spec->mic_boost = 2; /* default 20dB gain */
3222
3223 /* no S/PDIF out */
3224 spec->multiout.dig_out_nid = 0;
3225
3226 /* input source automatically selected */
3227 spec->input_mux = NULL;
3228 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003229 }
3230
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003231 if (spec->beep_amp)
3232 snd_hda_attach_beep_device(codec, spec->beep_amp);
3233
Daniel Drake0fb67e92009-07-16 14:46:57 +01003234 return 0;
3235}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003236
3237/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003238 * Automatic parser for CX20641 & co
3239 */
3240
Takashi Iwai6764bce2011-05-13 16:52:25 +02003241static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3242 struct hda_codec *codec,
3243 unsigned int stream_tag,
3244 unsigned int format,
3245 struct snd_pcm_substream *substream)
3246{
3247 struct conexant_spec *spec = codec->spec;
3248 hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]];
3249 if (spec->adc_switching) {
3250 spec->cur_adc = adc;
3251 spec->cur_adc_stream_tag = stream_tag;
3252 spec->cur_adc_format = format;
3253 }
3254 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3255 return 0;
3256}
3257
3258static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3259 struct hda_codec *codec,
3260 struct snd_pcm_substream *substream)
3261{
3262 struct conexant_spec *spec = codec->spec;
3263 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3264 spec->cur_adc = 0;
3265 return 0;
3266}
3267
3268static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3269 .substreams = 1,
3270 .channels_min = 2,
3271 .channels_max = 2,
3272 .nid = 0, /* fill later */
3273 .ops = {
3274 .prepare = cx_auto_capture_pcm_prepare,
3275 .cleanup = cx_auto_capture_pcm_cleanup
3276 },
3277};
3278
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003279static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003280
3281/* get the connection index of @nid in the widget @mux */
3282static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3283 hda_nid_t nid)
3284{
3285 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3286 int i, nums;
3287
3288 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3289 for (i = 0; i < nums; i++)
3290 if (conn[i] == nid)
3291 return i;
3292 return -1;
3293}
3294
3295/* get an unassigned DAC from the given list.
3296 * Return the nid if found and reduce the DAC list, or return zero if
3297 * not found
3298 */
3299static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3300 hda_nid_t *dacs, int *num_dacs)
3301{
3302 int i, nums = *num_dacs;
3303 hda_nid_t ret = 0;
3304
3305 for (i = 0; i < nums; i++) {
3306 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3307 ret = dacs[i];
3308 break;
3309 }
3310 }
3311 if (!ret)
3312 return 0;
3313 if (--nums > 0)
3314 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3315 *num_dacs = nums;
3316 return ret;
3317}
3318
3319#define MAX_AUTO_DACS 5
3320
3321/* fill analog DAC list from the widget tree */
3322static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3323{
3324 hda_nid_t nid, end_nid;
3325 int nums = 0;
3326
3327 end_nid = codec->start_nid + codec->num_nodes;
3328 for (nid = codec->start_nid; nid < end_nid; nid++) {
3329 unsigned int wcaps = get_wcaps(codec, nid);
3330 unsigned int type = get_wcaps_type(wcaps);
3331 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3332 dacs[nums++] = nid;
3333 if (nums >= MAX_AUTO_DACS)
3334 break;
3335 }
3336 }
3337 return nums;
3338}
3339
3340/* fill pin_dac_pair list from the pin and dac list */
3341static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3342 int num_pins, hda_nid_t *dacs, int *rest,
3343 struct pin_dac_pair *filled, int type)
3344{
3345 int i, nums;
3346
3347 nums = 0;
3348 for (i = 0; i < num_pins; i++) {
3349 filled[nums].pin = pins[i];
3350 filled[nums].type = type;
3351 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3352 nums++;
3353 }
3354 return nums;
3355}
3356
3357/* parse analog output paths */
3358static void cx_auto_parse_output(struct hda_codec *codec)
3359{
3360 struct conexant_spec *spec = codec->spec;
3361 struct auto_pin_cfg *cfg = &spec->autocfg;
3362 hda_nid_t dacs[MAX_AUTO_DACS];
3363 int i, j, nums, rest;
3364
3365 rest = fill_cx_auto_dacs(codec, dacs);
3366 /* parse all analog output pins */
3367 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3368 dacs, &rest, spec->dac_info,
3369 AUTO_PIN_LINE_OUT);
3370 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3371 dacs, &rest, spec->dac_info + nums,
3372 AUTO_PIN_HP_OUT);
3373 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3374 dacs, &rest, spec->dac_info + nums,
3375 AUTO_PIN_SPEAKER_OUT);
3376 spec->dac_info_filled = nums;
3377 /* fill multiout struct */
3378 for (i = 0; i < nums; i++) {
3379 hda_nid_t dac = spec->dac_info[i].dac;
3380 if (!dac)
3381 continue;
3382 switch (spec->dac_info[i].type) {
3383 case AUTO_PIN_LINE_OUT:
3384 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3385 spec->multiout.num_dacs++;
3386 break;
3387 case AUTO_PIN_HP_OUT:
3388 case AUTO_PIN_SPEAKER_OUT:
3389 if (!spec->multiout.hp_nid) {
3390 spec->multiout.hp_nid = dac;
3391 break;
3392 }
3393 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3394 if (!spec->multiout.extra_out_nid[j]) {
3395 spec->multiout.extra_out_nid[j] = dac;
3396 break;
3397 }
3398 break;
3399 }
3400 }
3401 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003402 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003403
3404 if (cfg->hp_outs > 0)
3405 spec->auto_mute = 1;
3406 spec->vmaster_nid = spec->private_dac_nids[0];
3407}
3408
Takashi Iwaida339862011-05-13 16:24:15 +02003409static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3410 hda_nid_t *pins, bool on);
3411
Takashi Iwaif2e57312010-09-15 10:07:08 +02003412/* auto-mute/unmute speaker and line outs according to headphone jack */
3413static void cx_auto_hp_automute(struct hda_codec *codec)
3414{
3415 struct conexant_spec *spec = codec->spec;
3416 struct auto_pin_cfg *cfg = &spec->autocfg;
3417 int i, present;
3418
3419 if (!spec->auto_mute)
3420 return;
3421 present = 0;
3422 for (i = 0; i < cfg->hp_outs; i++) {
3423 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3424 present = 1;
3425 break;
3426 }
3427 }
Takashi Iwaida339862011-05-13 16:24:15 +02003428 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003429 for (i = 0; i < cfg->line_outs; i++) {
3430 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3431 AC_VERB_SET_PIN_WIDGET_CONTROL,
3432 present ? 0 : PIN_OUT);
3433 }
Takashi Iwaida339862011-05-13 16:24:15 +02003434 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003435 for (i = 0; !present && i < cfg->line_outs; i++)
3436 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3437 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003438 for (i = 0; i < cfg->speaker_outs; i++) {
3439 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3440 AC_VERB_SET_PIN_WIDGET_CONTROL,
3441 present ? 0 : PIN_OUT);
3442 }
Takashi Iwaida339862011-05-13 16:24:15 +02003443 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003444}
3445
Takashi Iwai6764bce2011-05-13 16:52:25 +02003446static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3447 struct snd_ctl_elem_info *uinfo)
3448{
3449 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3450 struct conexant_spec *spec = codec->spec;
3451
3452 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3453}
3454
3455static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3456 struct snd_ctl_elem_value *ucontrol)
3457{
3458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3459 struct conexant_spec *spec = codec->spec;
3460
3461 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3462 return 0;
3463}
3464
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003465/* look for the route the given pin from mux and return the index;
3466 * if do_select is set, actually select the route.
3467 */
3468static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003469 hda_nid_t pin, hda_nid_t *srcp,
3470 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003471{
3472 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3473 int i, nums;
3474
Takashi Iwaicf27f292011-05-16 11:33:02 +02003475 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3476 case AC_WID_AUD_IN:
3477 case AC_WID_AUD_SEL:
3478 case AC_WID_AUD_MIX:
3479 break;
3480 default:
3481 return -1;
3482 }
3483
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003484 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3485 for (i = 0; i < nums; i++)
3486 if (conn[i] == pin) {
3487 if (do_select)
3488 snd_hda_codec_write(codec, mux, 0,
3489 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003490 if (srcp)
3491 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003492 return i;
3493 }
3494 depth++;
3495 if (depth == 2)
3496 return -1;
3497 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003498 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003499 do_select, depth);
3500 if (ret >= 0) {
3501 if (do_select)
3502 snd_hda_codec_write(codec, mux, 0,
3503 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003504 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003505 }
3506 }
3507 return -1;
3508}
3509
3510static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3511 hda_nid_t pin)
3512{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003513 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003514}
3515
3516static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3517 hda_nid_t pin)
3518{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003519 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003520}
3521
Takashi Iwai6764bce2011-05-13 16:52:25 +02003522static int cx_auto_mux_enum_update(struct hda_codec *codec,
3523 const struct hda_input_mux *imux,
3524 unsigned int idx)
3525{
3526 struct conexant_spec *spec = codec->spec;
3527 hda_nid_t adc;
3528
3529 if (!imux->num_items)
3530 return 0;
3531 if (idx >= imux->num_items)
3532 idx = imux->num_items - 1;
3533 if (spec->cur_mux[0] == idx)
3534 return 0;
3535 adc = spec->imux_adcs[idx];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003536 select_input_connection(codec, spec->imux_adcs[idx],
3537 spec->imux_pins[idx]);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003538 if (spec->cur_adc && spec->cur_adc != adc) {
3539 /* stream is running, let's swap the current ADC */
3540 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3541 spec->cur_adc = adc;
3542 snd_hda_codec_setup_stream(codec, adc,
3543 spec->cur_adc_stream_tag, 0,
3544 spec->cur_adc_format);
3545 }
3546 spec->cur_mux[0] = idx;
3547 return 1;
3548}
3549
3550static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3551 struct snd_ctl_elem_value *ucontrol)
3552{
3553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3554 struct conexant_spec *spec = codec->spec;
3555
3556 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3557 ucontrol->value.enumerated.item[0]);
3558}
3559
3560static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3561 {
3562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3563 .name = "Capture Source",
3564 .info = cx_auto_mux_enum_info,
3565 .get = cx_auto_mux_enum_get,
3566 .put = cx_auto_mux_enum_put
3567 },
3568 {}
3569};
3570
Takashi Iwaif2e57312010-09-15 10:07:08 +02003571/* automatic switch internal and external mic */
3572static void cx_auto_automic(struct hda_codec *codec)
3573{
3574 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003575 int ext_idx = spec->auto_mic_ext;
3576
3577 if (!spec->auto_mic)
3578 return;
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003579 if (snd_hda_jack_detect(codec, spec->imux_pins[ext_idx]))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003580 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3581 else
3582 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003583}
3584
3585static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3586{
3587 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3588 switch (res >> 26) {
3589 case CONEXANT_HP_EVENT:
3590 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003591 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003592 break;
3593 case CONEXANT_MIC_EVENT:
3594 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003595 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003596 break;
3597 }
3598}
3599
Takashi Iwaif2e57312010-09-15 10:07:08 +02003600/* return true if it's an internal-mic pin */
3601static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3602{
3603 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3604 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003605 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003606}
3607
3608/* return true if it's an external-mic pin */
3609static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3610{
3611 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3612 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003613 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3614 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003615}
3616
3617/* check whether the pin config is suitable for auto-mic switching;
3618 * auto-mic is enabled only when one int-mic and one-ext mic exist
3619 */
3620static void cx_auto_check_auto_mic(struct hda_codec *codec)
3621{
3622 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003623
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003624 if (is_ext_mic(codec, spec->imux_pins[0]) &&
3625 is_int_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003626 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003627 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003628 return;
3629 }
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003630 if (is_int_mic(codec, spec->imux_pins[0]) &&
3631 is_ext_mic(codec, spec->imux_pins[1])) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003632 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003633 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003634 return;
3635 }
3636}
3637
3638static void cx_auto_parse_input(struct hda_codec *codec)
3639{
3640 struct conexant_spec *spec = codec->spec;
3641 struct auto_pin_cfg *cfg = &spec->autocfg;
3642 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003643 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003644
3645 imux = &spec->private_imux;
3646 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003647 for (j = 0; j < spec->num_adc_nids; j++) {
3648 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003649 int idx = get_input_connection(codec, adc,
3650 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003651 if (idx >= 0) {
3652 const char *label;
3653 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003654 spec->imux_cfg_idx[imux->num_items] = i;
Takashi Iwaif9759302011-05-16 11:45:15 +02003655 spec->imux_boost_nid[imux->num_items] = 0;
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003656 spec->imux_adcs[imux->num_items] = adc;
3657 spec->imux_pins[imux->num_items] =
3658 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003659 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003660 break;
3661 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003662 }
3663 }
3664 if (imux->num_items == 2 && cfg->num_inputs == 2)
3665 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003666 if (imux->num_items > 1 && !spec->auto_mic) {
3667 for (i = 1; i < imux->num_items; i++) {
3668 if (spec->imux_adcs[i] != spec->imux_adcs[0]) {
3669 spec->adc_switching = 1;
3670 break;
3671 }
3672 }
3673 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003674}
3675
3676/* get digital-input audio widget corresponding to the given pin */
3677static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3678{
3679 hda_nid_t nid, end_nid;
3680
3681 end_nid = codec->start_nid + codec->num_nodes;
3682 for (nid = codec->start_nid; nid < end_nid; nid++) {
3683 unsigned int wcaps = get_wcaps(codec, nid);
3684 unsigned int type = get_wcaps_type(wcaps);
3685 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3686 if (get_connection_index(codec, nid, pin) >= 0)
3687 return nid;
3688 }
3689 }
3690 return 0;
3691}
3692
3693static void cx_auto_parse_digital(struct hda_codec *codec)
3694{
3695 struct conexant_spec *spec = codec->spec;
3696 struct auto_pin_cfg *cfg = &spec->autocfg;
3697 hda_nid_t nid;
3698
3699 if (cfg->dig_outs &&
3700 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3701 spec->multiout.dig_out_nid = nid;
3702 if (cfg->dig_in_pin)
3703 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3704}
3705
3706#ifdef CONFIG_SND_HDA_INPUT_BEEP
3707static void cx_auto_parse_beep(struct hda_codec *codec)
3708{
3709 struct conexant_spec *spec = codec->spec;
3710 hda_nid_t nid, end_nid;
3711
3712 end_nid = codec->start_nid + codec->num_nodes;
3713 for (nid = codec->start_nid; nid < end_nid; nid++)
3714 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3715 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3716 break;
3717 }
3718}
3719#else
3720#define cx_auto_parse_beep(codec)
3721#endif
3722
3723static int cx_auto_parse_auto_config(struct hda_codec *codec)
3724{
3725 struct conexant_spec *spec = codec->spec;
3726 int err;
3727
3728 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3729 if (err < 0)
3730 return err;
3731
3732 cx_auto_parse_output(codec);
3733 cx_auto_parse_input(codec);
3734 cx_auto_parse_digital(codec);
3735 cx_auto_parse_beep(codec);
3736 return 0;
3737}
3738
Takashi Iwaida339862011-05-13 16:24:15 +02003739static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3740 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003741{
3742 int i;
3743 for (i = 0; i < num_pins; i++) {
3744 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3745 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003746 AC_VERB_SET_EAPD_BTLENABLE,
3747 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003748 }
3749}
3750
3751static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3752 hda_nid_t src)
3753{
3754 int idx = get_connection_index(codec, pin, src);
3755 if (idx >= 0)
3756 snd_hda_codec_write(codec, pin, 0,
3757 AC_VERB_SET_CONNECT_SEL, idx);
3758}
3759
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003760static void mute_outputs(struct hda_codec *codec, int num_nids,
3761 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003762{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003763 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003764
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003765 for (i = 0; i < num_nids; i++) {
3766 hda_nid_t nid = nids[i];
3767 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3768 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003769 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3770 val = AMP_OUT_MUTE;
3771 else
3772 val = AMP_OUT_ZERO;
3773 snd_hda_codec_write(codec, nid, 0,
3774 AC_VERB_SET_AMP_GAIN_MUTE, val);
3775 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003776}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003777
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003778static void cx_auto_init_output(struct hda_codec *codec)
3779{
3780 struct conexant_spec *spec = codec->spec;
3781 struct auto_pin_cfg *cfg = &spec->autocfg;
3782 hda_nid_t nid;
3783 int i;
3784
3785 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003786 for (i = 0; i < cfg->hp_outs; i++)
3787 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3788 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003789 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3790 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3791 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003792 if (spec->auto_mute) {
3793 for (i = 0; i < cfg->hp_outs; i++) {
3794 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3795 AC_VERB_SET_UNSOLICITED_ENABLE,
3796 AC_USRSP_EN | CONEXANT_HP_EVENT);
3797 }
3798 cx_auto_hp_automute(codec);
3799 } else {
3800 for (i = 0; i < cfg->line_outs; i++)
3801 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3802 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3803 for (i = 0; i < cfg->speaker_outs; i++)
3804 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3805 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003806 /* turn on EAPD */
3807 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3808 true);
3809 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3810 true);
3811 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3812 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003813 }
3814
3815 for (i = 0; i < spec->dac_info_filled; i++) {
3816 nid = spec->dac_info[i].dac;
3817 if (!nid)
3818 nid = spec->multiout.dac_nids[0];
3819 select_connection(codec, spec->dac_info[i].pin, nid);
3820 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003821}
3822
3823static void cx_auto_init_input(struct hda_codec *codec)
3824{
3825 struct conexant_spec *spec = codec->spec;
3826 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003827 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003828
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003829 for (i = 0; i < spec->num_adc_nids; i++) {
3830 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003831 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3832 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003833 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3834 val = AMP_IN_MUTE(0);
3835 else
3836 val = AMP_IN_UNMUTE(0);
3837 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3838 val);
3839 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003840
3841 for (i = 0; i < cfg->num_inputs; i++) {
3842 unsigned int type;
3843 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3844 type = PIN_VREF80;
3845 else
3846 type = PIN_IN;
3847 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3848 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3849 }
3850
3851 if (spec->auto_mic) {
3852 int ext_idx = spec->auto_mic_ext;
3853 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3854 AC_VERB_SET_UNSOLICITED_ENABLE,
3855 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3856 cx_auto_automic(codec);
3857 } else {
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003858 select_input_connection(codec, spec->imux_adcs[0],
3859 spec->imux_pins[0]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003860 }
3861}
3862
3863static void cx_auto_init_digital(struct hda_codec *codec)
3864{
3865 struct conexant_spec *spec = codec->spec;
3866 struct auto_pin_cfg *cfg = &spec->autocfg;
3867
3868 if (spec->multiout.dig_out_nid)
3869 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3870 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3871 if (spec->dig_in_nid)
3872 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3873 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3874}
3875
3876static int cx_auto_init(struct hda_codec *codec)
3877{
3878 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3879 cx_auto_init_output(codec);
3880 cx_auto_init_input(codec);
3881 cx_auto_init_digital(codec);
3882 return 0;
3883}
3884
David Henningsson983345e2011-02-15 19:57:09 +01003885static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003886 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003887 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003888{
3889 static char name[32];
3890 static struct snd_kcontrol_new knew[] = {
3891 HDA_CODEC_VOLUME(name, 0, 0, 0),
3892 HDA_CODEC_MUTE(name, 0, 0, 0),
3893 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003894 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003895 int i, err;
3896
3897 for (i = 0; i < 2; i++) {
3898 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003899 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3900 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003901 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3902 knew[i].index = cidx;
3903 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3904 kctl = snd_ctl_new1(&knew[i], codec);
3905 if (!kctl)
3906 return -ENOMEM;
3907 err = snd_hda_ctl_add(codec, nid, kctl);
3908 if (err < 0)
3909 return err;
3910 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3911 break;
3912 }
3913 return 0;
3914}
3915
David Henningsson983345e2011-02-15 19:57:09 +01003916#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3917 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3918
Takashi Iwaif2e57312010-09-15 10:07:08 +02003919#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3920 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3921
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003922static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3923 hda_nid_t pin, const char *name, int idx)
3924{
3925 unsigned int caps;
3926 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3927 if (caps & AC_AMPCAP_NUM_STEPS)
3928 return cx_auto_add_pb_volume(codec, dac, name, idx);
3929 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3930 if (caps & AC_AMPCAP_NUM_STEPS)
3931 return cx_auto_add_pb_volume(codec, pin, name, idx);
3932 return 0;
3933}
3934
Takashi Iwaif2e57312010-09-15 10:07:08 +02003935static int cx_auto_build_output_controls(struct hda_codec *codec)
3936{
3937 struct conexant_spec *spec = codec->spec;
3938 int i, err;
3939 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003940 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003941
3942 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003943 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3944 spec->dac_info[0].pin,
3945 "Master", 0);
3946
Takashi Iwaif2e57312010-09-15 10:07:08 +02003947 for (i = 0; i < spec->dac_info_filled; i++) {
3948 const char *label;
3949 int idx, type;
3950 if (!spec->dac_info[i].dac)
3951 continue;
3952 type = spec->dac_info[i].type;
3953 if (type == AUTO_PIN_LINE_OUT)
3954 type = spec->autocfg.line_out_type;
3955 switch (type) {
3956 case AUTO_PIN_LINE_OUT:
3957 default:
3958 label = texts[num_line++];
3959 idx = 0;
3960 break;
3961 case AUTO_PIN_HP_OUT:
3962 label = "Headphone";
3963 idx = num_hp++;
3964 break;
3965 case AUTO_PIN_SPEAKER_OUT:
3966 label = "Speaker";
3967 idx = num_spk++;
3968 break;
3969 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003970 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3971 spec->dac_info[i].pin,
3972 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003973 if (err < 0)
3974 return err;
3975 }
3976 return 0;
3977}
3978
Takashi Iwai6764bce2011-05-13 16:52:25 +02003979static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3980 const char *label, const char *pfx,
3981 int cidx)
3982{
3983 struct conexant_spec *spec = codec->spec;
3984 int i;
3985
3986 for (i = 0; i < spec->num_adc_nids; i++) {
3987 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003988 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003989 if (idx < 0)
3990 continue;
3991 return cx_auto_add_volume_idx(codec, label, pfx,
3992 cidx, adc_nid, HDA_INPUT, idx);
3993 }
3994 return 0;
3995}
3996
Takashi Iwaicf27f292011-05-16 11:33:02 +02003997static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
3998 const char *label, int cidx)
3999{
4000 struct conexant_spec *spec = codec->spec;
4001 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004002 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004003
4004 nid = spec->imux_pins[idx];
4005 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4006 return cx_auto_add_volume(codec, label, " Boost", cidx,
4007 nid, HDA_INPUT);
4008 con = __select_input_connection(codec, spec->imux_adcs[idx], nid, &mux,
4009 false, 0);
4010 if (con < 0)
4011 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004012 for (i = 0; i < idx; i++) {
4013 if (spec->imux_boost_nid[i] == mux)
4014 return 0; /* already present */
4015 }
4016
4017 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4018 spec->imux_boost_nid[idx] = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004019 return cx_auto_add_volume(codec, label, " Boost", 0,
4020 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004021 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004022 return 0;
4023}
4024
Takashi Iwaif2e57312010-09-15 10:07:08 +02004025static int cx_auto_build_input_controls(struct hda_codec *codec)
4026{
4027 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004028 struct hda_input_mux *imux = &spec->private_imux;
4029 const char *prev_label;
4030 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004031 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004032 int multi_connection;
4033
4034 multi_connection = 0;
4035 for (i = 0; i < imux->num_items; i++) {
4036 cidx = get_input_connection(codec, spec->imux_adcs[i],
4037 spec->imux_pins[i]);
4038 input_conn[i] = (spec->imux_adcs[i] << 8) | cidx;
4039 if (i > 0 && input_conn[i] != input_conn[0])
4040 multi_connection = 1;
4041 }
David Henningsson983345e2011-02-15 19:57:09 +01004042
Takashi Iwaif2e57312010-09-15 10:07:08 +02004043 prev_label = NULL;
4044 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004045 for (i = 0; i < imux->num_items; i++) {
4046 hda_nid_t nid = spec->imux_pins[i];
Takashi Iwaif2e57312010-09-15 10:07:08 +02004047 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004048
Takashi Iwaicf27f292011-05-16 11:33:02 +02004049 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4050 spec->imux_cfg_idx[i]);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004051 if (label == prev_label)
4052 cidx++;
4053 else
4054 cidx = 0;
4055 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004056
Takashi Iwaicf27f292011-05-16 11:33:02 +02004057 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4058 if (err < 0)
4059 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004060
Takashi Iwaicf27f292011-05-16 11:33:02 +02004061 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004062 if (i > 0)
4063 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004064 err = cx_auto_add_capture_volume(codec, nid,
4065 "Capture", "", cidx);
4066 } else {
4067 err = cx_auto_add_capture_volume(codec, nid,
4068 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004069 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004070 if (err < 0)
4071 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004072 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004073
4074 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4075 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4076 if (err < 0)
4077 return err;
4078 }
4079
Takashi Iwaif2e57312010-09-15 10:07:08 +02004080 return 0;
4081}
4082
4083static int cx_auto_build_controls(struct hda_codec *codec)
4084{
4085 int err;
4086
4087 err = cx_auto_build_output_controls(codec);
4088 if (err < 0)
4089 return err;
4090 err = cx_auto_build_input_controls(codec);
4091 if (err < 0)
4092 return err;
4093 return conexant_build_controls(codec);
4094}
4095
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004096static int cx_auto_search_adcs(struct hda_codec *codec)
4097{
4098 struct conexant_spec *spec = codec->spec;
4099 hda_nid_t nid, end_nid;
4100
4101 end_nid = codec->start_nid + codec->num_nodes;
4102 for (nid = codec->start_nid; nid < end_nid; nid++) {
4103 unsigned int caps = get_wcaps(codec, nid);
4104 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4105 continue;
4106 if (caps & AC_WCAP_DIGITAL)
4107 continue;
4108 if (snd_BUG_ON(spec->num_adc_nids >=
4109 ARRAY_SIZE(spec->private_adc_nids)))
4110 break;
4111 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4112 }
4113 spec->adc_nids = spec->private_adc_nids;
4114 return 0;
4115}
4116
4117
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004118static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004119 .build_controls = cx_auto_build_controls,
4120 .build_pcms = conexant_build_pcms,
4121 .init = cx_auto_init,
4122 .free = conexant_free,
4123 .unsol_event = cx_auto_unsol_event,
4124#ifdef CONFIG_SND_HDA_POWER_SAVE
4125 .suspend = conexant_suspend,
4126#endif
4127 .reboot_notify = snd_hda_shutup_pins,
4128};
4129
4130static int patch_conexant_auto(struct hda_codec *codec)
4131{
4132 struct conexant_spec *spec;
4133 int err;
4134
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004135 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4136 codec->chip_name);
4137
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4139 if (!spec)
4140 return -ENOMEM;
4141 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004142 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004143 err = cx_auto_search_adcs(codec);
4144 if (err < 0)
4145 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004146 err = cx_auto_parse_auto_config(codec);
4147 if (err < 0) {
4148 kfree(codec->spec);
4149 codec->spec = NULL;
4150 return err;
4151 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004152 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004153 codec->patch_ops = cx_auto_patch_ops;
4154 if (spec->beep_amp)
4155 snd_hda_attach_beep_device(codec, spec->beep_amp);
4156 return 0;
4157}
4158
4159/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004160 */
4161
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004162static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004163 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4164 .patch = patch_cxt5045 },
4165 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4166 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004167 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4168 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004169 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4170 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004171 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4172 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004173 { .id = 0x14f15068, .name = "CX20584",
4174 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004175 { .id = 0x14f15069, .name = "CX20585",
4176 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004177 { .id = 0x14f1506e, .name = "CX20590",
4178 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004179 { .id = 0x14f15097, .name = "CX20631",
4180 .patch = patch_conexant_auto },
4181 { .id = 0x14f15098, .name = "CX20632",
4182 .patch = patch_conexant_auto },
4183 { .id = 0x14f150a1, .name = "CX20641",
4184 .patch = patch_conexant_auto },
4185 { .id = 0x14f150a2, .name = "CX20642",
4186 .patch = patch_conexant_auto },
4187 { .id = 0x14f150ab, .name = "CX20651",
4188 .patch = patch_conexant_auto },
4189 { .id = 0x14f150ac, .name = "CX20652",
4190 .patch = patch_conexant_auto },
4191 { .id = 0x14f150b8, .name = "CX20664",
4192 .patch = patch_conexant_auto },
4193 { .id = 0x14f150b9, .name = "CX20665",
4194 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004195 {} /* terminator */
4196};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004197
4198MODULE_ALIAS("snd-hda-codec-id:14f15045");
4199MODULE_ALIAS("snd-hda-codec-id:14f15047");
4200MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004201MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004202MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004203MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004204MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004205MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004206MODULE_ALIAS("snd-hda-codec-id:14f15097");
4207MODULE_ALIAS("snd-hda-codec-id:14f15098");
4208MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4209MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4210MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4211MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4212MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4213MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004214
4215MODULE_LICENSE("GPL");
4216MODULE_DESCRIPTION("Conexant HD-audio codec");
4217
4218static struct hda_codec_preset_list conexant_list = {
4219 .preset = snd_hda_preset_conexant,
4220 .owner = THIS_MODULE,
4221};
4222
4223static int __init patch_conexant_init(void)
4224{
4225 return snd_hda_add_codec_preset(&conexant_list);
4226}
4227
4228static void __exit patch_conexant_exit(void)
4229{
4230 snd_hda_delete_codec_preset(&conexant_list);
4231}
4232
4233module_init(patch_conexant_init)
4234module_exit(patch_conexant_exit)