blob: 390bc02dcf586b7af0620a74e8d1c35c72d4a485 [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
Takashi Iwai47ad1f42011-05-17 09:15:55 +020058struct imux_info {
59 hda_nid_t pin; /* input pin NID */
60 hda_nid_t adc; /* connected ADC NID */
61 hda_nid_t boost; /* optional boost volume NID */
62 int index; /* corresponding to autocfg.input */
63};
64
Tobin Davisc9b443d2006-11-14 12:13:39 +010065struct conexant_spec {
66
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020067 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010068 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010069 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010070
71 const struct hda_verb *init_verbs[5]; /* initialization verbs
72 * don't forget NULL
73 * termination!
74 */
75 unsigned int num_init_verbs;
76
77 /* playback */
78 struct hda_multi_out multiout; /* playback set-up
79 * max_channels, dacs must be set
80 * dig_out_nid and hp_nid are optional
81 */
82 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010083 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010084 unsigned int auto_mic;
Takashi Iwaif6100bb2011-05-13 18:26:39 +020085 int auto_mic_ext; /* imux_pins[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010086 unsigned int need_dac_fix;
Andy Robinsonf6a24912011-01-24 10:12:37 -050087 hda_nid_t slave_dig_outs[2];
Tobin Davisc9b443d2006-11-14 12:13:39 +010088
89 /* capture */
90 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020091 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010092 hda_nid_t dig_in_nid; /* digital-in NID; optional */
93
Takashi Iwai461e2c72008-01-25 11:35:17 +010094 unsigned int cur_adc_idx;
95 hda_nid_t cur_adc;
96 unsigned int cur_adc_stream_tag;
97 unsigned int cur_adc_format;
98
Takashi Iwai6764bce2011-05-13 16:52:25 +020099 const struct hda_pcm_stream *capture_stream;
100
Tobin Davisc9b443d2006-11-14 12:13:39 +0100101 /* capture source */
102 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200103 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100104 unsigned int cur_mux[3];
105
106 /* channel model */
107 const struct hda_channel_mode *channel_mode;
108 int num_channel_mode;
109
110 /* PCM information */
111 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
112
Tobin Davisc9b443d2006-11-14 12:13:39 +0100113 unsigned int spdif_route;
114
115 /* dynamic controls, init_verbs and input_mux */
116 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100117 struct hda_input_mux private_imux;
Takashi Iwai47ad1f42011-05-17 09:15:55 +0200118 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
Takashi Iwai22ce5f72011-05-15 12:19:29 +0200119 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
Takashi Iwai41923e42007-10-22 17:20:10 +0200120 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200121 struct pin_dac_pair dac_info[8];
122 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100123
Daniel Drake0fb67e92009-07-16 14:46:57 +0100124 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200125 unsigned int auto_mute:1; /* used in auto-parser */
126 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500127 unsigned int dell_vostro:1;
128 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200129 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200130 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100131 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100132
Takashi Iwai6764bce2011-05-13 16:52:25 +0200133 unsigned int adc_switching:1;
134
Daniel Drake75f89912010-01-07 13:46:25 +0100135 unsigned int ext_mic_present;
136 unsigned int recording;
137 void (*capture_prepare)(struct hda_codec *codec);
138 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100139
140 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
141 * through the microphone jack.
142 * When the user enables this through a mixer switch, both internal and
143 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
144 * we also allow the bias to be configured through a separate mixer
145 * control. */
146 unsigned int dc_enable;
147 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
148 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200149
150 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100151};
152
153static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
154 struct hda_codec *codec,
155 struct snd_pcm_substream *substream)
156{
157 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100158 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
159 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100160}
161
162static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
163 struct hda_codec *codec,
164 unsigned int stream_tag,
165 unsigned int format,
166 struct snd_pcm_substream *substream)
167{
168 struct conexant_spec *spec = codec->spec;
169 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
170 stream_tag,
171 format, substream);
172}
173
174static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
175 struct hda_codec *codec,
176 struct snd_pcm_substream *substream)
177{
178 struct conexant_spec *spec = codec->spec;
179 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
180}
181
182/*
183 * Digital out
184 */
185static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
186 struct hda_codec *codec,
187 struct snd_pcm_substream *substream)
188{
189 struct conexant_spec *spec = codec->spec;
190 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
191}
192
193static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
194 struct hda_codec *codec,
195 struct snd_pcm_substream *substream)
196{
197 struct conexant_spec *spec = codec->spec;
198 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
199}
200
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200201static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
202 struct hda_codec *codec,
203 unsigned int stream_tag,
204 unsigned int format,
205 struct snd_pcm_substream *substream)
206{
207 struct conexant_spec *spec = codec->spec;
208 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
209 stream_tag,
210 format, substream);
211}
212
Tobin Davisc9b443d2006-11-14 12:13:39 +0100213/*
214 * Analog capture
215 */
216static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
217 struct hda_codec *codec,
218 unsigned int stream_tag,
219 unsigned int format,
220 struct snd_pcm_substream *substream)
221{
222 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100223 if (spec->capture_prepare)
224 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100225 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
226 stream_tag, 0, format);
227 return 0;
228}
229
230static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 struct snd_pcm_substream *substream)
233{
234 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100235 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100236 if (spec->capture_cleanup)
237 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100238 return 0;
239}
240
241
242
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200243static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100244 .substreams = 1,
245 .channels_min = 2,
246 .channels_max = 2,
247 .nid = 0, /* fill later */
248 .ops = {
249 .open = conexant_playback_pcm_open,
250 .prepare = conexant_playback_pcm_prepare,
251 .cleanup = conexant_playback_pcm_cleanup
252 },
253};
254
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200255static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100256 .substreams = 1,
257 .channels_min = 2,
258 .channels_max = 2,
259 .nid = 0, /* fill later */
260 .ops = {
261 .prepare = conexant_capture_pcm_prepare,
262 .cleanup = conexant_capture_pcm_cleanup
263 },
264};
265
266
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200267static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100268 .substreams = 1,
269 .channels_min = 2,
270 .channels_max = 2,
271 .nid = 0, /* fill later */
272 .ops = {
273 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200274 .close = conexant_dig_playback_pcm_close,
275 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100276 },
277};
278
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200279static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100280 .substreams = 1,
281 .channels_min = 2,
282 .channels_max = 2,
283 /* NID is set in alc_build_pcms */
284};
285
Takashi Iwai461e2c72008-01-25 11:35:17 +0100286static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
287 struct hda_codec *codec,
288 unsigned int stream_tag,
289 unsigned int format,
290 struct snd_pcm_substream *substream)
291{
292 struct conexant_spec *spec = codec->spec;
293 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
294 spec->cur_adc_stream_tag = stream_tag;
295 spec->cur_adc_format = format;
296 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
297 return 0;
298}
299
300static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
301 struct hda_codec *codec,
302 struct snd_pcm_substream *substream)
303{
304 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100305 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100306 spec->cur_adc = 0;
307 return 0;
308}
309
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200310static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100311 .substreams = 1,
312 .channels_min = 2,
313 .channels_max = 2,
314 .nid = 0, /* fill later */
315 .ops = {
316 .prepare = cx5051_capture_pcm_prepare,
317 .cleanup = cx5051_capture_pcm_cleanup
318 },
319};
320
Tobin Davisc9b443d2006-11-14 12:13:39 +0100321static int conexant_build_pcms(struct hda_codec *codec)
322{
323 struct conexant_spec *spec = codec->spec;
324 struct hda_pcm *info = spec->pcm_rec;
325
326 codec->num_pcms = 1;
327 codec->pcm_info = info;
328
329 info->name = "CONEXANT Analog";
330 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
332 spec->multiout.max_channels;
333 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
334 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200335 if (spec->capture_stream)
336 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
337 else {
338 if (codec->vendor_id == 0x14f15051)
339 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
340 cx5051_pcm_analog_capture;
341 else {
342 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
343 conexant_pcm_analog_capture;
344 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
345 spec->num_adc_nids;
346 }
347 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100348 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
349
350 if (spec->multiout.dig_out_nid) {
351 info++;
352 codec->num_pcms++;
353 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100354 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100355 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
356 conexant_pcm_digital_playback;
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
358 spec->multiout.dig_out_nid;
359 if (spec->dig_in_nid) {
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
361 conexant_pcm_digital_capture;
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
363 spec->dig_in_nid;
364 }
Andy Robinsonf6a24912011-01-24 10:12:37 -0500365 if (spec->slave_dig_outs[0])
366 codec->slave_dig_outs = spec->slave_dig_outs;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100367 }
368
369 return 0;
370}
371
372static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
373 struct snd_ctl_elem_info *uinfo)
374{
375 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
376 struct conexant_spec *spec = codec->spec;
377
378 return snd_hda_input_mux_info(spec->input_mux, uinfo);
379}
380
381static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
382 struct snd_ctl_elem_value *ucontrol)
383{
384 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385 struct conexant_spec *spec = codec->spec;
386 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
387
388 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
389 return 0;
390}
391
392static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
393 struct snd_ctl_elem_value *ucontrol)
394{
395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396 struct conexant_spec *spec = codec->spec;
397 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
398
399 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
400 spec->capsrc_nids[adc_idx],
401 &spec->cur_mux[adc_idx]);
402}
403
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100404static int conexant_init_jacks(struct hda_codec *codec)
405{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100406#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100407 struct conexant_spec *spec = codec->spec;
408 int i;
409
410 for (i = 0; i < spec->num_init_verbs; i++) {
411 const struct hda_verb *hv;
412
413 hv = spec->init_verbs[i];
414 while (hv->nid) {
415 int err = 0;
416 switch (hv->param ^ AC_USRSP_EN) {
417 case CONEXANT_HP_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100418 err = snd_hda_input_jack_add(codec, hv->nid,
419 SND_JACK_HEADPHONE, NULL);
420 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100421 break;
422 case CXT5051_PORTC_EVENT:
423 case CONEXANT_MIC_EVENT:
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100424 err = snd_hda_input_jack_add(codec, hv->nid,
425 SND_JACK_MICROPHONE, NULL);
426 snd_hda_input_jack_report(codec, hv->nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100427 break;
428 }
429 if (err < 0)
430 return err;
431 ++hv;
432 }
433 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100434#endif /* CONFIG_SND_HDA_INPUT_JACK */
Takashi Iwai5801f992009-01-27 12:53:22 +0100435 return 0;
436}
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100437
Tobin Davisc9b443d2006-11-14 12:13:39 +0100438static int conexant_init(struct hda_codec *codec)
439{
440 struct conexant_spec *spec = codec->spec;
441 int i;
442
443 for (i = 0; i < spec->num_init_verbs; i++)
444 snd_hda_sequence_write(codec, spec->init_verbs[i]);
445 return 0;
446}
447
448static void conexant_free(struct hda_codec *codec)
449{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100450 snd_hda_input_jack_free(codec);
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200451 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100452 kfree(codec->spec);
453}
454
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200455static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100456 {
457 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
458 .name = "Capture Source",
459 .info = conexant_mux_enum_info,
460 .get = conexant_mux_enum_get,
461 .put = conexant_mux_enum_put
462 },
463 {}
464};
465
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200466#ifdef CONFIG_SND_HDA_INPUT_BEEP
467/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200468static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200469 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
470 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
471 { } /* end */
472};
473#endif
474
Takashi Iwaiea734962011-01-17 11:29:34 +0100475static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100476 "Headphone Playback Volume",
477 "Speaker Playback Volume",
478 NULL
479};
480
Takashi Iwaiea734962011-01-17 11:29:34 +0100481static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100482 "Headphone Playback Switch",
483 "Speaker Playback Switch",
484 NULL
485};
486
Tobin Davisc9b443d2006-11-14 12:13:39 +0100487static int conexant_build_controls(struct hda_codec *codec)
488{
489 struct conexant_spec *spec = codec->spec;
490 unsigned int i;
491 int err;
492
493 for (i = 0; i < spec->num_mixers; i++) {
494 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
495 if (err < 0)
496 return err;
497 }
498 if (spec->multiout.dig_out_nid) {
499 err = snd_hda_create_spdif_out_ctls(codec,
500 spec->multiout.dig_out_nid);
501 if (err < 0)
502 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100503 err = snd_hda_create_spdif_share_sw(codec,
504 &spec->multiout);
505 if (err < 0)
506 return err;
507 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100508 }
509 if (spec->dig_in_nid) {
510 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
511 if (err < 0)
512 return err;
513 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100514
515 /* if we have no master control, let's create it */
516 if (spec->vmaster_nid &&
517 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
518 unsigned int vmaster_tlv[4];
519 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
520 HDA_OUTPUT, vmaster_tlv);
521 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
522 vmaster_tlv, slave_vols);
523 if (err < 0)
524 return err;
525 }
526 if (spec->vmaster_nid &&
527 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
528 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
529 NULL, slave_sws);
530 if (err < 0)
531 return err;
532 }
533
Takashi Iwaib880c742009-03-10 14:41:05 +0100534 if (spec->input_mux) {
535 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
536 if (err < 0)
537 return err;
538 }
539
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200540#ifdef CONFIG_SND_HDA_INPUT_BEEP
541 /* create beep controls if needed */
542 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200543 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200544 for (knew = cxt_beep_mixer; knew->name; knew++) {
545 struct snd_kcontrol *kctl;
546 kctl = snd_ctl_new1(knew, codec);
547 if (!kctl)
548 return -ENOMEM;
549 kctl->private_value = spec->beep_amp;
550 err = snd_hda_ctl_add(codec, 0, kctl);
551 if (err < 0)
552 return err;
553 }
554 }
555#endif
556
Tobin Davisc9b443d2006-11-14 12:13:39 +0100557 return 0;
558}
559
Takashi Iwai697c3732010-07-30 11:28:02 +0200560#ifdef CONFIG_SND_HDA_POWER_SAVE
561static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
562{
563 snd_hda_shutup_pins(codec);
564 return 0;
565}
566#endif
567
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200568static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100569 .build_controls = conexant_build_controls,
570 .build_pcms = conexant_build_pcms,
571 .init = conexant_init,
572 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200573#ifdef CONFIG_SND_HDA_POWER_SAVE
574 .suspend = conexant_suspend,
575#endif
576 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100577};
578
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200579#ifdef CONFIG_SND_HDA_INPUT_BEEP
580#define set_beep_amp(spec, nid, idx, dir) \
581 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
582#else
583#define set_beep_amp(spec, nid, idx, dir) /* NOP */
584#endif
585
Takashi Iwai6764bce2011-05-13 16:52:25 +0200586static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100587/*
588 * EAPD control
589 * the private value = nid | (invert << 8)
590 */
591
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200592#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100593
Tobin Davis82f30042007-02-13 12:45:44 +0100594static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100595 struct snd_ctl_elem_value *ucontrol)
596{
597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598 struct conexant_spec *spec = codec->spec;
599 int invert = (kcontrol->private_value >> 8) & 1;
600 if (invert)
601 ucontrol->value.integer.value[0] = !spec->cur_eapd;
602 else
603 ucontrol->value.integer.value[0] = spec->cur_eapd;
604 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100605
Tobin Davisc9b443d2006-11-14 12:13:39 +0100606}
607
Tobin Davis82f30042007-02-13 12:45:44 +0100608static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100609 struct snd_ctl_elem_value *ucontrol)
610{
611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612 struct conexant_spec *spec = codec->spec;
613 int invert = (kcontrol->private_value >> 8) & 1;
614 hda_nid_t nid = kcontrol->private_value & 0xff;
615 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100616
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100617 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100618 if (invert)
619 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200620 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100621 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100622
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200624 snd_hda_codec_write_cache(codec, nid,
625 0, AC_VERB_SET_EAPD_BTLENABLE,
626 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100627 return 1;
628}
629
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100630/* controls for test mode */
631#ifdef CONFIG_SND_DEBUG
632
Tobin Davis82f30042007-02-13 12:45:44 +0100633#define CXT_EAPD_SWITCH(xname, nid, mask) \
634 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
635 .info = cxt_eapd_info, \
636 .get = cxt_eapd_get, \
637 .put = cxt_eapd_put, \
638 .private_value = nid | (mask<<16) }
639
640
641
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_info *uinfo)
644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct conexant_spec *spec = codec->spec;
647 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
648 spec->num_channel_mode);
649}
650
651static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
653{
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 struct conexant_spec *spec = codec->spec;
656 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
657 spec->num_channel_mode,
658 spec->multiout.max_channels);
659}
660
661static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
662 struct snd_ctl_elem_value *ucontrol)
663{
664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
665 struct conexant_spec *spec = codec->spec;
666 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
667 spec->num_channel_mode,
668 &spec->multiout.max_channels);
669 if (err >= 0 && spec->need_dac_fix)
670 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
671 return err;
672}
673
674#define CXT_PIN_MODE(xname, nid, dir) \
675 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
676 .info = conexant_ch_mode_info, \
677 .get = conexant_ch_mode_get, \
678 .put = conexant_ch_mode_put, \
679 .private_value = nid | (dir<<16) }
680
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100681#endif /* CONFIG_SND_DEBUG */
682
Tobin Davisc9b443d2006-11-14 12:13:39 +0100683/* Conexant 5045 specific */
684
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200685static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
686static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
687static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100688#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200690static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100691 { 2, NULL },
692};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100693
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200694static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695 .num_items = 2,
696 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100697 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100698 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100699 }
700};
701
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200702static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200703 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100704 .items = {
705 { "IntMic", 0x1 },
706 { "ExtMic", 0x2 },
707 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200708 { "CD", 0x4 },
709 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100710 }
711};
712
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200713static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100714 .num_items = 2,
715 .items = {
716 { "ExtMic", 0x1 },
717 { "IntMic", 0x2 },
718 }
719};
720
Tobin Davisc9b443d2006-11-14 12:13:39 +0100721/* turn on/off EAPD (+ mute HP) as a master switch */
722static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_value *ucontrol)
724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100727 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100728
Tobin Davis82f30042007-02-13 12:45:44 +0100729 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100730 return 0;
731
Tobin Davis82f30042007-02-13 12:45:44 +0100732 /* toggle internal speakers mute depending of presence of
733 * the headphone jack
734 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200735 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
736 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
737 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100738
Takashi Iwai47fd8302007-08-10 17:11:07 +0200739 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
740 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
741 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100742 return 1;
743}
744
745/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200746static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200747 .ops = &snd_hda_bind_vol,
748 .values = {
749 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
750 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
751 0
752 },
753};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100754
Tobin Davis7f296732007-03-12 11:39:01 +0100755/* toggle input of built-in and mic jack appropriately */
756static void cxt5045_hp_automic(struct hda_codec *codec)
757{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200758 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100759 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
760 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
761 {}
762 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200763 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100764 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
766 {}
767 };
768 unsigned int present;
769
Takashi Iwaid56757a2009-11-18 08:00:14 +0100770 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100771 if (present)
772 snd_hda_sequence_write(codec, mic_jack_on);
773 else
774 snd_hda_sequence_write(codec, mic_jack_off);
775}
776
Tobin Davisc9b443d2006-11-14 12:13:39 +0100777
778/* mute internal speaker if HP is plugged */
779static void cxt5045_hp_automute(struct hda_codec *codec)
780{
Tobin Davis82f30042007-02-13 12:45:44 +0100781 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100782 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783
Takashi Iwaid56757a2009-11-18 08:00:14 +0100784 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100785
Takashi Iwai47fd8302007-08-10 17:11:07 +0200786 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
787 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
788 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789}
790
791/* unsolicited event for HP jack sensing */
792static void cxt5045_hp_unsol_event(struct hda_codec *codec,
793 unsigned int res)
794{
795 res >>= 26;
796 switch (res) {
797 case CONEXANT_HP_EVENT:
798 cxt5045_hp_automute(codec);
799 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100800 case CONEXANT_MIC_EVENT:
801 cxt5045_hp_automic(codec);
802 break;
803
Tobin Davisc9b443d2006-11-14 12:13:39 +0100804 }
805}
806
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200807static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100808 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
809 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100810 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
811 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200812 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
813 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100814 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
815 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100816 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
817 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200818 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100819 {
820 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
821 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100822 .info = cxt_eapd_info,
823 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100824 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100825 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100826 },
827
828 {}
829};
830
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200831static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200832 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
833 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
834 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
835 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
836
Jiang Zhe5218c892008-01-17 11:18:41 +0100837 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
838 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
839 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
840 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
841
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200842 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
843 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
844
Jiang Zhe5218c892008-01-17 11:18:41 +0100845 {}
846};
847
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200848static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100849 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
850 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100851 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
852 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100853 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
854 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100855 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
856 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100857 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
858 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100859 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
860 {
861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
862 .name = "Master Playback Switch",
863 .info = cxt_eapd_info,
864 .get = cxt_eapd_get,
865 .put = cxt5045_hp_master_sw_put,
866 .private_value = 0x10,
867 },
868
869 {}
870};
871
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200872static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200874 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100875 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100876 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200877 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
878 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
879 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
880 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
881 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
885 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100886 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100887 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100888 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100889 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
890 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100891 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100892 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100893 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100894 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100895 { } /* end */
896};
897
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200898static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100899 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100900 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
901 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
902 /* Line In,HP, Amp */
903 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
904 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
905 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
906 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
907 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
908 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
909 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
910 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
911 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100912 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100913 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
914 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
915 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
916 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100917 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100918 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
919 /* EAPD */
920 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
921 { } /* end */
922};
Tobin Davis7f296732007-03-12 11:39:01 +0100923
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200924static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100925 /* pin sensing on HP jack */
926 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200927 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100928};
929
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200930static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100931 /* pin sensing on HP jack */
932 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200933 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100934};
935
Tobin Davisc9b443d2006-11-14 12:13:39 +0100936#ifdef CONFIG_SND_DEBUG
937/* Test configuration for debugging, modelled after the ALC260 test
938 * configuration.
939 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200940static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941 .num_items = 5,
942 .items = {
943 { "MIXER", 0x0 },
944 { "MIC1 pin", 0x1 },
945 { "LINE1 pin", 0x2 },
946 { "HP-OUT pin", 0x3 },
947 { "CD pin", 0x4 },
948 },
949};
950
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200951static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952
953 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100954 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
955 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100956 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
957 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
958 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
959 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960
961 /* Modes for retasking pin widgets */
962 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
963 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
964
Tobin Davis82f30042007-02-13 12:45:44 +0100965 /* EAPD Switch Control */
966 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
967
Tobin Davisc9b443d2006-11-14 12:13:39 +0100968 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100969
Tobin Davis7f296732007-03-12 11:39:01 +0100970 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
971 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
972 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
973 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
974 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
975 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
976 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
977 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
978 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
979 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100980 {
981 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
982 .name = "Input Source",
983 .info = conexant_mux_enum_info,
984 .get = conexant_mux_enum_get,
985 .put = conexant_mux_enum_put,
986 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200987 /* Audio input controls */
988 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
989 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
990 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
991 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
992 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
993 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
994 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
995 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
996 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
997 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100998 { } /* end */
999};
1000
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001001static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001002 /* Set connections */
1003 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1004 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1005 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001006 /* Enable retasking pins as output, initially without power amp */
1007 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001008 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001009
1010 /* Disable digital (SPDIF) pins initially, but users can enable
1011 * them via a mixer switch. In the case of SPDIF-out, this initverb
1012 * payload also sets the generation to 0, output to be in "consumer"
1013 * PCM format, copyright asserted, no pre-emphasis and no validity
1014 * control.
1015 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001016 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1017 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001018
1019 /* Start with output sum widgets muted and their output gains at min */
1020 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1021 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1022
1023 /* Unmute retasking pin widget output buffers since the default
1024 * state appears to be output. As the pin mode is changed by the
1025 * user the pin mode control will take care of enabling the pin's
1026 * input/output buffers as needed.
1027 */
1028 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1029 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1030
1031 /* Mute capture amp left and right */
1032 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1033
1034 /* Set ADC connection select to match default mixer setting (mic1
1035 * pin)
1036 */
1037 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001038 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001039
1040 /* Mute all inputs to mixer widget (even unconnected ones) */
1041 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1042 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1043 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1044 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1045 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1046
1047 { }
1048};
1049#endif
1050
1051
1052/* initialize jack-sensing, too */
1053static int cxt5045_init(struct hda_codec *codec)
1054{
1055 conexant_init(codec);
1056 cxt5045_hp_automute(codec);
1057 return 0;
1058}
1059
1060
1061enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001062 CXT5045_LAPTOP_HPSENSE,
1063 CXT5045_LAPTOP_MICSENSE,
1064 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001065 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001066 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001067#ifdef CONFIG_SND_DEBUG
1068 CXT5045_TEST,
1069#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001070 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001071 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072};
1073
Takashi Iwaiea734962011-01-17 11:29:34 +01001074static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001075 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1076 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1077 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1078 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001079 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001080#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001081 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001082#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001083 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001084};
1085
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001086static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001087 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001088 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1089 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001090 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001091 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001092 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1093 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001094 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1095 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001096 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1097 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1098 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001099 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1100 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001101 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001102 {}
1103};
1104
1105static int patch_cxt5045(struct hda_codec *codec)
1106{
1107 struct conexant_spec *spec;
1108 int board_config;
1109
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001110 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1111 cxt5045_models,
1112 cxt5045_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001113#if 0 /* use the old method just for safety */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001114 if (board_config < 0)
1115 board_config = CXT5045_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001116#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001117 if (board_config == CXT5045_AUTO)
1118 return patch_conexant_auto(codec);
1119
Tobin Davisc9b443d2006-11-14 12:13:39 +01001120 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1121 if (!spec)
1122 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001123 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001124 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001125
1126 spec->multiout.max_channels = 2;
1127 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1128 spec->multiout.dac_nids = cxt5045_dac_nids;
1129 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1130 spec->num_adc_nids = 1;
1131 spec->adc_nids = cxt5045_adc_nids;
1132 spec->capsrc_nids = cxt5045_capsrc_nids;
1133 spec->input_mux = &cxt5045_capture_source;
1134 spec->num_mixers = 1;
1135 spec->mixers[0] = cxt5045_mixers;
1136 spec->num_init_verbs = 1;
1137 spec->init_verbs[0] = cxt5045_init_verbs;
1138 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001139 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1140 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001141
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001142 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001143
1144 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001145
Tobin Davisc9b443d2006-11-14 12:13:39 +01001146 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001147 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001148 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001149 spec->input_mux = &cxt5045_capture_source;
1150 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001151 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1152 spec->mixers[0] = cxt5045_mixers;
1153 codec->patch_ops.init = cxt5045_init;
1154 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001155 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001156 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001157 spec->input_mux = &cxt5045_capture_source;
1158 spec->num_init_verbs = 2;
1159 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001160 spec->mixers[0] = cxt5045_mixers;
1161 codec->patch_ops.init = cxt5045_init;
1162 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001163 default:
1164 case CXT5045_LAPTOP_HPMICSENSE:
1165 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1166 spec->input_mux = &cxt5045_capture_source;
1167 spec->num_init_verbs = 3;
1168 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1169 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1170 spec->mixers[0] = cxt5045_mixers;
1171 codec->patch_ops.init = cxt5045_init;
1172 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001173 case CXT5045_BENQ:
1174 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1175 spec->input_mux = &cxt5045_capture_source_benq;
1176 spec->num_init_verbs = 1;
1177 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1178 spec->mixers[0] = cxt5045_mixers;
1179 spec->mixers[1] = cxt5045_benq_mixers;
1180 spec->num_mixers = 2;
1181 codec->patch_ops.init = cxt5045_init;
1182 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001183 case CXT5045_LAPTOP_HP530:
1184 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1185 spec->input_mux = &cxt5045_capture_source_hp530;
1186 spec->num_init_verbs = 2;
1187 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1188 spec->mixers[0] = cxt5045_mixers_hp530;
1189 codec->patch_ops.init = cxt5045_init;
1190 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191#ifdef CONFIG_SND_DEBUG
1192 case CXT5045_TEST:
1193 spec->input_mux = &cxt5045_test_capture_source;
1194 spec->mixers[0] = cxt5045_test_mixer;
1195 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001196 break;
1197
Tobin Davisc9b443d2006-11-14 12:13:39 +01001198#endif
1199 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001200
Takashi Iwai031005f2008-06-26 14:49:58 +02001201 switch (codec->subsystem_id >> 16) {
1202 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001203 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001204 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001205 case 0x17aa:
1206 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1207 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1208 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001209 */
1210 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1211 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1212 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1213 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1214 (1 << AC_AMPCAP_MUTE_SHIFT));
1215 break;
1216 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001217
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001218 if (spec->beep_amp)
1219 snd_hda_attach_beep_device(codec, spec->beep_amp);
1220
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221 return 0;
1222}
1223
1224
1225/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001226#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001228static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1229static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1230static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001232static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001233 { 2, NULL },
1234};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001235
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001236static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001237 .num_items = 2,
1238 .items = {
1239 { "ExtMic", 0x2 },
1240 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241 }
1242};
1243
1244/* turn on/off EAPD (+ mute HP) as a master switch */
1245static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1246 struct snd_ctl_elem_value *ucontrol)
1247{
1248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1249 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001250 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001251
Tobin Davis82f30042007-02-13 12:45:44 +01001252 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 return 0;
1254
Tobin Davis82f30042007-02-13 12:45:44 +01001255 /* toggle internal speakers mute depending of presence of
1256 * the headphone jack
1257 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001258 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001259 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1260 * pin widgets unlike other codecs. In this case, we need to
1261 * set index 0x01 for the volume from the mixer amp 0x19.
1262 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001263 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001264 HDA_AMP_MUTE, bits);
1265 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1266 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1267 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001268 return 1;
1269}
1270
Tobin Davisc9b443d2006-11-14 12:13:39 +01001271/* mute internal speaker if HP is plugged */
1272static void cxt5047_hp_automute(struct hda_codec *codec)
1273{
Tobin Davis82f30042007-02-13 12:45:44 +01001274 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001275 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276
Takashi Iwaid56757a2009-11-18 08:00:14 +01001277 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001278
Takashi Iwai47fd8302007-08-10 17:11:07 +02001279 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001280 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001281 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001282 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283}
1284
1285/* toggle input of built-in and mic jack appropriately */
1286static void cxt5047_hp_automic(struct hda_codec *codec)
1287{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001288 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001289 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1290 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291 {}
1292 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001293 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001294 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1295 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001296 {}
1297 };
1298 unsigned int present;
1299
Takashi Iwaid56757a2009-11-18 08:00:14 +01001300 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001301 if (present)
1302 snd_hda_sequence_write(codec, mic_jack_on);
1303 else
1304 snd_hda_sequence_write(codec, mic_jack_off);
1305}
1306
1307/* unsolicited event for HP jack sensing */
1308static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1309 unsigned int res)
1310{
Marc Boucher9f113e02008-01-22 15:18:08 +01001311 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 case CONEXANT_HP_EVENT:
1313 cxt5047_hp_automute(codec);
1314 break;
1315 case CONEXANT_MIC_EVENT:
1316 cxt5047_hp_automic(codec);
1317 break;
1318 }
1319}
1320
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001321static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001322 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1323 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001324 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1326 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1327 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1328 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001329 {
1330 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1331 .name = "Master Playback Switch",
1332 .info = cxt_eapd_info,
1333 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001334 .put = cxt5047_hp_master_sw_put,
1335 .private_value = 0x13,
1336 },
1337
1338 {}
1339};
1340
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001341static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001342 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001343 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001344 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1345 {}
1346};
1347
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001348static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001349 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001350 { } /* end */
1351};
1352
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001353static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001354 /* Line in, Mic, Built-in Mic */
1355 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1356 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1357 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001358 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001359 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001360 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1361 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001362 /* Record selector: Mic */
1363 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1364 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1365 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1366 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1368 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1369 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1370 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001371 /* SPDIF route: PCM */
1372 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001373 /* Enable unsolicited events */
1374 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1375 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001376 { } /* end */
1377};
1378
1379/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001380static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001381 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 {}
1383};
1384
1385/* Test configuration for debugging, modelled after the ALC260 test
1386 * configuration.
1387 */
1388#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001389static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001390 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001391 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001392 { "LINE1 pin", 0x0 },
1393 { "MIC1 pin", 0x1 },
1394 { "MIC2 pin", 0x2 },
1395 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001396 },
1397};
1398
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001399static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001400
1401 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001402 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1404 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1408 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001410 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414
1415 /* Modes for retasking pin widgets */
1416 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1417 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1418
Tobin Davis82f30042007-02-13 12:45:44 +01001419 /* EAPD Switch Control */
1420 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1421
Tobin Davisc9b443d2006-11-14 12:13:39 +01001422 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001423 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1424 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1425 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1426 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1427 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1428 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1429 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1430 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001431
Tobin Davis82f30042007-02-13 12:45:44 +01001432 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1433 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1434 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1435 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1436 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1437 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1438 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1439 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001440 {
1441 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1442 .name = "Input Source",
1443 .info = conexant_mux_enum_info,
1444 .get = conexant_mux_enum_get,
1445 .put = conexant_mux_enum_put,
1446 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001447 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001448
Tobin Davisc9b443d2006-11-14 12:13:39 +01001449 { } /* end */
1450};
1451
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001452static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001453 /* Enable retasking pins as output, initially without power amp */
1454 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1455 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1456 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1457
1458 /* Disable digital (SPDIF) pins initially, but users can enable
1459 * them via a mixer switch. In the case of SPDIF-out, this initverb
1460 * payload also sets the generation to 0, output to be in "consumer"
1461 * PCM format, copyright asserted, no pre-emphasis and no validity
1462 * control.
1463 */
1464 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1465
1466 /* Ensure mic1, mic2, line1 pin widgets take input from the
1467 * OUT1 sum bus when acting as an output.
1468 */
1469 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1470 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1471
1472 /* Start with output sum widgets muted and their output gains at min */
1473 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1474 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1475
1476 /* Unmute retasking pin widget output buffers since the default
1477 * state appears to be output. As the pin mode is changed by the
1478 * user the pin mode control will take care of enabling the pin's
1479 * input/output buffers as needed.
1480 */
1481 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1482 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1483 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1484
1485 /* Mute capture amp left and right */
1486 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1487
1488 /* Set ADC connection select to match default mixer setting (mic1
1489 * pin)
1490 */
1491 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1492
1493 /* Mute all inputs to mixer widget (even unconnected ones) */
1494 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1495 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1497 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1498 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1499 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1501 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1502
1503 { }
1504};
1505#endif
1506
1507
1508/* initialize jack-sensing, too */
1509static int cxt5047_hp_init(struct hda_codec *codec)
1510{
1511 conexant_init(codec);
1512 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001513 return 0;
1514}
1515
1516
1517enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001518 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1519 CXT5047_LAPTOP_HP, /* Some HP laptops */
1520 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001521#ifdef CONFIG_SND_DEBUG
1522 CXT5047_TEST,
1523#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001524 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001525 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001526};
1527
Takashi Iwaiea734962011-01-17 11:29:34 +01001528static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001529 [CXT5047_LAPTOP] = "laptop",
1530 [CXT5047_LAPTOP_HP] = "laptop-hp",
1531 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001533 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001534#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001535 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001536};
1537
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001538static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001539 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001540 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1541 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001542 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543 {}
1544};
1545
1546static int patch_cxt5047(struct hda_codec *codec)
1547{
1548 struct conexant_spec *spec;
1549 int board_config;
1550
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001551 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1552 cxt5047_models,
1553 cxt5047_cfg_tbl);
1554#if 0 /* not enabled as default, as BIOS often broken for this codec */
1555 if (board_config < 0)
1556 board_config = CXT5047_AUTO;
1557#endif
1558 if (board_config == CXT5047_AUTO)
1559 return patch_conexant_auto(codec);
1560
Tobin Davisc9b443d2006-11-14 12:13:39 +01001561 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1562 if (!spec)
1563 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001564 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001565 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001566
1567 spec->multiout.max_channels = 2;
1568 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1569 spec->multiout.dac_nids = cxt5047_dac_nids;
1570 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1571 spec->num_adc_nids = 1;
1572 spec->adc_nids = cxt5047_adc_nids;
1573 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001574 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001575 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576 spec->num_init_verbs = 1;
1577 spec->init_verbs[0] = cxt5047_init_verbs;
1578 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001579 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1580 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001581
1582 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001583
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584 switch (board_config) {
1585 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001586 spec->num_mixers = 2;
1587 spec->mixers[1] = cxt5047_hp_spk_mixers;
1588 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001589 break;
1590 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001591 spec->num_mixers = 2;
1592 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001593 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594 codec->patch_ops.init = cxt5047_hp_init;
1595 break;
1596 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001597 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001598 spec->num_mixers = 2;
1599 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001600 spec->num_init_verbs = 2;
1601 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001602 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001603 break;
1604#ifdef CONFIG_SND_DEBUG
1605 case CXT5047_TEST:
1606 spec->input_mux = &cxt5047_test_capture_source;
1607 spec->mixers[0] = cxt5047_test_mixer;
1608 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001609 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610#endif
1611 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001612 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001613
1614 switch (codec->subsystem_id >> 16) {
1615 case 0x103c:
1616 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1617 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1618 * with 0 dB offset 0x17)
1619 */
1620 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1621 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1622 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1623 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1624 (1 << AC_AMPCAP_MUTE_SHIFT));
1625 break;
1626 }
1627
Tobin Davisc9b443d2006-11-14 12:13:39 +01001628 return 0;
1629}
1630
Takashi Iwai461e2c72008-01-25 11:35:17 +01001631/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001632static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1633static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001634
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001635static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001636 { 2, NULL },
1637};
1638
1639static void cxt5051_update_speaker(struct hda_codec *codec)
1640{
1641 struct conexant_spec *spec = codec->spec;
1642 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001643 /* headphone pin */
1644 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1645 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1646 pinctl);
1647 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001648 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1649 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1650 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001651 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1652 if (spec->ideapad)
1653 snd_hda_codec_write(codec, 0x1b, 0,
1654 AC_VERB_SET_PIN_WIDGET_CONTROL,
1655 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001656}
1657
1658/* turn on/off EAPD (+ mute HP) as a master switch */
1659static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol)
1661{
1662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1663
1664 if (!cxt_eapd_put(kcontrol, ucontrol))
1665 return 0;
1666 cxt5051_update_speaker(codec);
1667 return 1;
1668}
1669
1670/* toggle input of built-in and mic jack appropriately */
1671static void cxt5051_portb_automic(struct hda_codec *codec)
1672{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001673 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001674 unsigned int present;
1675
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001676 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001677 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001678 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 snd_hda_codec_write(codec, 0x14, 0,
1680 AC_VERB_SET_CONNECT_SEL,
1681 present ? 0x01 : 0x00);
1682}
1683
1684/* switch the current ADC according to the jack state */
1685static void cxt5051_portc_automic(struct hda_codec *codec)
1686{
1687 struct conexant_spec *spec = codec->spec;
1688 unsigned int present;
1689 hda_nid_t new_adc;
1690
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001691 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001692 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001693 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001694 if (present)
1695 spec->cur_adc_idx = 1;
1696 else
1697 spec->cur_adc_idx = 0;
1698 new_adc = spec->adc_nids[spec->cur_adc_idx];
1699 if (spec->cur_adc && spec->cur_adc != new_adc) {
1700 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001701 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001702 spec->cur_adc = new_adc;
1703 snd_hda_codec_setup_stream(codec, new_adc,
1704 spec->cur_adc_stream_tag, 0,
1705 spec->cur_adc_format);
1706 }
1707}
1708
1709/* mute internal speaker if HP is plugged */
1710static void cxt5051_hp_automute(struct hda_codec *codec)
1711{
1712 struct conexant_spec *spec = codec->spec;
1713
Takashi Iwaid56757a2009-11-18 08:00:14 +01001714 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 cxt5051_update_speaker(codec);
1716}
1717
1718/* unsolicited event for HP jack sensing */
1719static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1720 unsigned int res)
1721{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001722 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 switch (res >> 26) {
1724 case CONEXANT_HP_EVENT:
1725 cxt5051_hp_automute(codec);
1726 break;
1727 case CXT5051_PORTB_EVENT:
1728 cxt5051_portb_automic(codec);
1729 break;
1730 case CXT5051_PORTC_EVENT:
1731 cxt5051_portc_automic(codec);
1732 break;
1733 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001734 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001735}
1736
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001737static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001738 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1739 {
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1741 .name = "Master Playback Switch",
1742 .info = cxt_eapd_info,
1743 .get = cxt_eapd_get,
1744 .put = cxt5051_hp_master_sw_put,
1745 .private_value = 0x1a,
1746 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001747 {}
1748};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001750static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001751 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1752 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001753 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1754 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001755 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1756 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001757 {}
1758};
1759
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001760static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001761 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1762 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001763 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1764 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001765 {}
1766};
1767
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001768static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001769 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1770 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001771 {}
1772};
1773
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001774static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001775 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1776 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001777 {}
1778};
1779
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001780static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001781 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1782 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001783 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1784 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001785 {}
1786};
1787
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001788static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001789 /* Line in, Mic */
1790 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1791 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1792 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1793 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1794 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1795 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796 /* SPK */
1797 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1798 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1799 /* HP, Amp */
1800 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1802 /* DAC1 */
1803 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001804 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1807 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1808 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001809 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001810 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1811 /* EAPD */
1812 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1813 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001814 { } /* end */
1815};
1816
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001817static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001818 /* Line in, Mic */
1819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1820 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1822 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1823 /* SPK */
1824 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1825 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1826 /* HP, Amp */
1827 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1828 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1829 /* DAC1 */
1830 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001831 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001832 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1833 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1834 /* SPDIF route: PCM */
1835 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1836 /* EAPD */
1837 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1838 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001839 { } /* end */
1840};
1841
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001842static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001843 /* Line in, Mic */
1844 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1845 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1846 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1847 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1848 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1849 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1850 /* SPK */
1851 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1852 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1853 /* HP, Amp */
1854 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1855 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1856 /* Docking HP */
1857 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1858 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1859 /* DAC1 */
1860 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001861 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001862 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1863 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1864 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1865 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001866 {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 -05001867 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1868 /* EAPD */
1869 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1870 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001871 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1872 { } /* end */
1873};
1874
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001875static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001876 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001878 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1879 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1880 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1881 /* SPK */
1882 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1883 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1884 /* HP, Amp */
1885 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1886 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1887 /* DAC1 */
1888 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001889 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1891 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1892 /* SPDIF route: PCM */
1893 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1894 /* EAPD */
1895 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1896 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001897 { } /* end */
1898};
1899
Takashi Iwai6953e552010-01-24 11:00:27 +01001900static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1901 unsigned int event)
1902{
1903 snd_hda_codec_write(codec, nid, 0,
1904 AC_VERB_SET_UNSOLICITED_ENABLE,
1905 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001906 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1907 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001908}
1909
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001910static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001911 /* Subwoofer */
1912 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1913 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1914 { } /* end */
1915};
1916
Takashi Iwai461e2c72008-01-25 11:35:17 +01001917/* initialize jack-sensing, too */
1918static int cxt5051_init(struct hda_codec *codec)
1919{
Takashi Iwai6953e552010-01-24 11:00:27 +01001920 struct conexant_spec *spec = codec->spec;
1921
Takashi Iwai461e2c72008-01-25 11:35:17 +01001922 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001923 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001924
1925 if (spec->auto_mic & AUTO_MIC_PORTB)
1926 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1927 if (spec->auto_mic & AUTO_MIC_PORTC)
1928 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1929
Takashi Iwai461e2c72008-01-25 11:35:17 +01001930 if (codec->patch_ops.unsol_event) {
1931 cxt5051_hp_automute(codec);
1932 cxt5051_portb_automic(codec);
1933 cxt5051_portc_automic(codec);
1934 }
1935 return 0;
1936}
1937
1938
1939enum {
1940 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1941 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001942 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001943 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001944 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001945 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001946 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001947 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001948 CXT5051_MODELS
1949};
1950
Takashi Iwaiea734962011-01-17 11:29:34 +01001951static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001952 [CXT5051_LAPTOP] = "laptop",
1953 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001954 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001955 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001956 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001957 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001958 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001959 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001960};
1961
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001962static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001963 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001964 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001965 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001966 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001967 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1968 CXT5051_LAPTOP),
1969 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001970 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001971 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001972 {}
1973};
1974
1975static int patch_cxt5051(struct hda_codec *codec)
1976{
1977 struct conexant_spec *spec;
1978 int board_config;
1979
Takashi Iwai6764bce2011-05-13 16:52:25 +02001980 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1981 cxt5051_models,
1982 cxt5051_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001983#if 0 /* use the old method just for safety */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001984 if (board_config < 0)
1985 board_config = CXT5051_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001986#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001987 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001988 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001989
Takashi Iwai461e2c72008-01-25 11:35:17 +01001990 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1991 if (!spec)
1992 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001993 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001994 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001995
1996 codec->patch_ops = conexant_patch_ops;
1997 codec->patch_ops.init = cxt5051_init;
1998
1999 spec->multiout.max_channels = 2;
2000 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2001 spec->multiout.dac_nids = cxt5051_dac_nids;
2002 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2003 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2004 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002005 spec->num_mixers = 2;
2006 spec->mixers[0] = cxt5051_capture_mixers;
2007 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002008 spec->num_init_verbs = 1;
2009 spec->init_verbs[0] = cxt5051_init_verbs;
2010 spec->spdif_route = 0;
2011 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2012 spec->channel_mode = cxt5051_modes;
2013 spec->cur_adc = 0;
2014 spec->cur_adc_idx = 0;
2015
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002016 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2017
Takashi Iwai79d7d532009-03-04 09:03:50 +01002018 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2019
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002020 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002021 switch (board_config) {
2022 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002023 spec->mixers[0] = cxt5051_hp_mixers;
2024 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002025 case CXT5051_HP_DV6736:
2026 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2027 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002028 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002029 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002030 case CXT5051_LENOVO_X200:
2031 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002032 /* Thinkpad X301 does not have S/PDIF wired and no ability
2033 to use a docking station. */
2034 if (codec->subsystem_id == 0x17aa211f)
2035 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002036 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002037 case CXT5051_F700:
2038 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2039 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002040 spec->auto_mic = 0;
2041 break;
2042 case CXT5051_TOSHIBA:
2043 spec->mixers[0] = cxt5051_toshiba_mixers;
2044 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002045 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002046 case CXT5051_IDEAPAD:
2047 spec->init_verbs[spec->num_init_verbs++] =
2048 cxt5051_ideapad_init_verbs;
2049 spec->ideapad = 1;
2050 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002051 }
2052
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002053 if (spec->beep_amp)
2054 snd_hda_attach_beep_device(codec, spec->beep_amp);
2055
Takashi Iwai461e2c72008-01-25 11:35:17 +01002056 return 0;
2057}
2058
Daniel Drake0fb67e92009-07-16 14:46:57 +01002059/* Conexant 5066 specific */
2060
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002061static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2062static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2063static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2064static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002065
Daniel Drakedbaccc02009-11-09 15:17:24 +00002066/* OLPC's microphone port is DC coupled for use with external sensors,
2067 * therefore we use a 50% mic bias in order to center the input signal with
2068 * the DC input range of the codec. */
2069#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2070
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002071static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002072 { 2, NULL },
2073};
2074
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002075#define HP_PRESENT_PORT_A (1 << 0)
2076#define HP_PRESENT_PORT_D (1 << 1)
2077#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2078#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2079
Daniel Drake0fb67e92009-07-16 14:46:57 +01002080static void cxt5066_update_speaker(struct hda_codec *codec)
2081{
2082 struct conexant_spec *spec = codec->spec;
2083 unsigned int pinctl;
2084
John Baboval3a253442010-12-02 11:21:31 -05002085 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2086 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002087
2088 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002089 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002090 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2091 pinctl);
2092
2093 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002094 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2095 if (spec->dell_automute || spec->thinkpad) {
2096 /* Mute if Port A is connected */
2097 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002098 pinctl = 0;
2099 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002100 /* Thinkpad/Dell doesn't give pin-D status */
2101 if (!hp_port_d_present(spec))
2102 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002103 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002104 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2105 pinctl);
2106
2107 /* CLASS_D AMP */
2108 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2109 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2110 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002111}
2112
2113/* turn on/off EAPD (+ mute HP) as a master switch */
2114static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2115 struct snd_ctl_elem_value *ucontrol)
2116{
2117 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2118
2119 if (!cxt_eapd_put(kcontrol, ucontrol))
2120 return 0;
2121
2122 cxt5066_update_speaker(codec);
2123 return 1;
2124}
2125
Daniel Drakec4cfe662010-01-07 13:47:04 +01002126static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2127 .num_items = 3,
2128 .items = {
2129 { "Off", PIN_IN },
2130 { "50%", PIN_VREF50 },
2131 { "80%", PIN_VREF80 },
2132 },
2133};
2134
2135static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2136{
2137 struct conexant_spec *spec = codec->spec;
2138 /* Even though port F is the DC input, the bias is controlled on port B.
2139 * we also leave that port as an active input (but unselected) in DC mode
2140 * just in case that is necessary to make the bias setting take effect. */
2141 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2142 AC_VERB_SET_PIN_WIDGET_CONTROL,
2143 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2144}
2145
Daniel Drake75f89912010-01-07 13:46:25 +01002146/* OLPC defers mic widget control until when capture is started because the
2147 * microphone LED comes on as soon as these settings are put in place. if we
2148 * did this before recording, it would give the false indication that recording
2149 * is happening when it is not. */
2150static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002151{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002152 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002153 if (!spec->recording)
2154 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002155
Daniel Drakec4cfe662010-01-07 13:47:04 +01002156 if (spec->dc_enable) {
2157 /* in DC mode we ignore presence detection and just use the jack
2158 * through our special DC port */
2159 const struct hda_verb enable_dc_mode[] = {
2160 /* disble internal mic, port C */
2161 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2162
2163 /* enable DC capture, port F */
2164 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2165 {},
2166 };
2167
2168 snd_hda_sequence_write(codec, enable_dc_mode);
2169 /* port B input disabled (and bias set) through the following call */
2170 cxt5066_set_olpc_dc_bias(codec);
2171 return;
2172 }
2173
2174 /* disable DC (port F) */
2175 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2176
Daniel Drake75f89912010-01-07 13:46:25 +01002177 /* external mic, port B */
2178 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2179 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002180
Daniel Drake75f89912010-01-07 13:46:25 +01002181 /* internal mic, port C */
2182 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2183 spec->ext_mic_present ? 0 : PIN_VREF80);
2184}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002185
Daniel Drake75f89912010-01-07 13:46:25 +01002186/* toggle input of built-in and mic jack appropriately */
2187static void cxt5066_olpc_automic(struct hda_codec *codec)
2188{
2189 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002190 unsigned int present;
2191
Daniel Drakec4cfe662010-01-07 13:47:04 +01002192 if (spec->dc_enable) /* don't do presence detection in DC mode */
2193 return;
2194
Daniel Drake75f89912010-01-07 13:46:25 +01002195 present = snd_hda_codec_read(codec, 0x1a, 0,
2196 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2197 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002198 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002199 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002200 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002201
2202 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2203 present ? 0 : 1);
2204 spec->ext_mic_present = !!present;
2205
2206 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002207}
2208
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002209/* toggle input of built-in digital mic and mic jack appropriately */
2210static void cxt5066_vostro_automic(struct hda_codec *codec)
2211{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002212 unsigned int present;
2213
2214 struct hda_verb ext_mic_present[] = {
2215 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002216 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002217
2218 /* switch to external mic input */
2219 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2220 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2221
2222 /* disable internal digital mic */
2223 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2224 {}
2225 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002226 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002227 /* enable internal mic, port C */
2228 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2229
2230 /* switch to internal mic input */
2231 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2232
2233 /* disable external mic, port B */
2234 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2235 {}
2236 };
2237
2238 present = snd_hda_jack_detect(codec, 0x1a);
2239 if (present) {
2240 snd_printdd("CXT5066: external microphone detected\n");
2241 snd_hda_sequence_write(codec, ext_mic_present);
2242 } else {
2243 snd_printdd("CXT5066: external microphone absent\n");
2244 snd_hda_sequence_write(codec, ext_mic_absent);
2245 }
2246}
2247
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002248/* toggle input of built-in digital mic and mic jack appropriately */
2249static void cxt5066_ideapad_automic(struct hda_codec *codec)
2250{
2251 unsigned int present;
2252
2253 struct hda_verb ext_mic_present[] = {
2254 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2255 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2256 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2257 {}
2258 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002259 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002260 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2261 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2262 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2263 {}
2264 };
2265
2266 present = snd_hda_jack_detect(codec, 0x1b);
2267 if (present) {
2268 snd_printdd("CXT5066: external microphone detected\n");
2269 snd_hda_sequence_write(codec, ext_mic_present);
2270 } else {
2271 snd_printdd("CXT5066: external microphone absent\n");
2272 snd_hda_sequence_write(codec, ext_mic_absent);
2273 }
2274}
2275
David Henningssona1d69062011-01-21 13:33:28 +01002276
2277/* toggle input of built-in digital mic and mic jack appropriately */
2278static void cxt5066_asus_automic(struct hda_codec *codec)
2279{
2280 unsigned int present;
2281
2282 present = snd_hda_jack_detect(codec, 0x1b);
2283 snd_printdd("CXT5066: external microphone present=%d\n", present);
2284 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2285 present ? 1 : 0);
2286}
2287
2288
David Henningsson048e78a2010-09-02 08:35:47 +02002289/* toggle input of built-in digital mic and mic jack appropriately */
2290static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2291{
2292 unsigned int present;
2293
2294 present = snd_hda_jack_detect(codec, 0x1b);
2295 snd_printdd("CXT5066: external microphone present=%d\n", present);
2296 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2297 present ? 1 : 3);
2298}
2299
2300
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002301/* toggle input of built-in digital mic and mic jack appropriately
2302 order is: external mic -> dock mic -> interal mic */
2303static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2304{
2305 unsigned int ext_present, dock_present;
2306
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002307 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002308 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2309 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2310 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2311 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2312 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 {}
2314 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002315 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002316 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2317 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2318 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2319 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2320 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2321 {}
2322 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002323 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002324 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2325 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2326 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2327 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2328 {}
2329 };
2330
2331 ext_present = snd_hda_jack_detect(codec, 0x1b);
2332 dock_present = snd_hda_jack_detect(codec, 0x1a);
2333 if (ext_present) {
2334 snd_printdd("CXT5066: external microphone detected\n");
2335 snd_hda_sequence_write(codec, ext_mic_present);
2336 } else if (dock_present) {
2337 snd_printdd("CXT5066: dock microphone detected\n");
2338 snd_hda_sequence_write(codec, dock_mic_present);
2339 } else {
2340 snd_printdd("CXT5066: external microphone absent\n");
2341 snd_hda_sequence_write(codec, ext_mic_absent);
2342 }
2343}
2344
Daniel Drake0fb67e92009-07-16 14:46:57 +01002345/* mute internal speaker if HP is plugged */
2346static void cxt5066_hp_automute(struct hda_codec *codec)
2347{
2348 struct conexant_spec *spec = codec->spec;
2349 unsigned int portA, portD;
2350
2351 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002352 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002353
2354 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002355 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002356
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002357 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2358 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2360 portA, portD, spec->hp_present);
2361 cxt5066_update_speaker(codec);
2362}
2363
David Henningsson02b6b5b2011-01-21 13:27:39 +01002364/* Dispatch the right mic autoswitch function */
2365static void cxt5066_automic(struct hda_codec *codec)
2366{
2367 struct conexant_spec *spec = codec->spec;
2368
2369 if (spec->dell_vostro)
2370 cxt5066_vostro_automic(codec);
2371 else if (spec->ideapad)
2372 cxt5066_ideapad_automic(codec);
2373 else if (spec->thinkpad)
2374 cxt5066_thinkpad_automic(codec);
2375 else if (spec->hp_laptop)
2376 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002377 else if (spec->asus)
2378 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002379}
2380
Daniel Drake0fb67e92009-07-16 14:46:57 +01002381/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002382static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002383{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002384 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002385 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2386 switch (res >> 26) {
2387 case CONEXANT_HP_EVENT:
2388 cxt5066_hp_automute(codec);
2389 break;
2390 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002391 /* ignore mic events in DC mode; we're always using the jack */
2392 if (!spec->dc_enable)
2393 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002394 break;
2395 }
2396}
2397
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002398/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002399static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002400{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002401 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002402 switch (res >> 26) {
2403 case CONEXANT_HP_EVENT:
2404 cxt5066_hp_automute(codec);
2405 break;
2406 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002407 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002408 break;
2409 }
2410}
2411
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002412
Daniel Drake0fb67e92009-07-16 14:46:57 +01002413static const struct hda_input_mux cxt5066_analog_mic_boost = {
2414 .num_items = 5,
2415 .items = {
2416 { "0dB", 0 },
2417 { "10dB", 1 },
2418 { "20dB", 2 },
2419 { "30dB", 3 },
2420 { "40dB", 4 },
2421 },
2422};
2423
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002424static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002425{
2426 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002427 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002428 AC_VERB_SET_AMP_GAIN_MUTE,
2429 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2430 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002431 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002432 /* adjust the internal mic as well...it is not through 0x17 */
2433 snd_hda_codec_write_cache(codec, 0x23, 0,
2434 AC_VERB_SET_AMP_GAIN_MUTE,
2435 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2436 cxt5066_analog_mic_boost.
2437 items[spec->mic_boost].index);
2438 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002439}
2440
Daniel Drake0fb67e92009-07-16 14:46:57 +01002441static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2442 struct snd_ctl_elem_info *uinfo)
2443{
2444 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2445}
2446
2447static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2448 struct snd_ctl_elem_value *ucontrol)
2449{
2450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002451 struct conexant_spec *spec = codec->spec;
2452 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002453 return 0;
2454}
2455
2456static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2457 struct snd_ctl_elem_value *ucontrol)
2458{
2459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002460 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002461 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2462 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002463 idx = ucontrol->value.enumerated.item[0];
2464 if (idx >= imux->num_items)
2465 idx = imux->num_items - 1;
2466
Daniel Drakec4cfe662010-01-07 13:47:04 +01002467 spec->mic_boost = idx;
2468 if (!spec->dc_enable)
2469 cxt5066_set_mic_boost(codec);
2470 return 1;
2471}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002472
Daniel Drakec4cfe662010-01-07 13:47:04 +01002473static void cxt5066_enable_dc(struct hda_codec *codec)
2474{
2475 const struct hda_verb enable_dc_mode[] = {
2476 /* disable gain */
2477 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2478
2479 /* switch to DC input */
2480 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2481 {}
2482 };
2483
2484 /* configure as input source */
2485 snd_hda_sequence_write(codec, enable_dc_mode);
2486 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2487}
2488
2489static void cxt5066_disable_dc(struct hda_codec *codec)
2490{
2491 /* reconfigure input source */
2492 cxt5066_set_mic_boost(codec);
2493 /* automic also selects the right mic if we're recording */
2494 cxt5066_olpc_automic(codec);
2495}
2496
2497static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2498 struct snd_ctl_elem_value *ucontrol)
2499{
2500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2501 struct conexant_spec *spec = codec->spec;
2502 ucontrol->value.integer.value[0] = spec->dc_enable;
2503 return 0;
2504}
2505
2506static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2507 struct snd_ctl_elem_value *ucontrol)
2508{
2509 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2510 struct conexant_spec *spec = codec->spec;
2511 int dc_enable = !!ucontrol->value.integer.value[0];
2512
2513 if (dc_enable == spec->dc_enable)
2514 return 0;
2515
2516 spec->dc_enable = dc_enable;
2517 if (dc_enable)
2518 cxt5066_enable_dc(codec);
2519 else
2520 cxt5066_disable_dc(codec);
2521
2522 return 1;
2523}
2524
2525static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2526 struct snd_ctl_elem_info *uinfo)
2527{
2528 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2529}
2530
2531static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2532 struct snd_ctl_elem_value *ucontrol)
2533{
2534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2535 struct conexant_spec *spec = codec->spec;
2536 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2537 return 0;
2538}
2539
2540static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2541 struct snd_ctl_elem_value *ucontrol)
2542{
2543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2544 struct conexant_spec *spec = codec->spec;
2545 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2546 unsigned int idx;
2547
2548 idx = ucontrol->value.enumerated.item[0];
2549 if (idx >= imux->num_items)
2550 idx = imux->num_items - 1;
2551
2552 spec->dc_input_bias = idx;
2553 if (spec->dc_enable)
2554 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002555 return 1;
2556}
2557
Daniel Drake75f89912010-01-07 13:46:25 +01002558static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2559{
2560 struct conexant_spec *spec = codec->spec;
2561 /* mark as recording and configure the microphone widget so that the
2562 * recording LED comes on. */
2563 spec->recording = 1;
2564 cxt5066_olpc_select_mic(codec);
2565}
2566
2567static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2568{
2569 struct conexant_spec *spec = codec->spec;
2570 const struct hda_verb disable_mics[] = {
2571 /* disable external mic, port B */
2572 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2573
2574 /* disble internal mic, port C */
2575 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002576
2577 /* disable DC capture, port F */
2578 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002579 {},
2580 };
2581
2582 snd_hda_sequence_write(codec, disable_mics);
2583 spec->recording = 0;
2584}
2585
Andy Robinsonf6a24912011-01-24 10:12:37 -05002586static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002587 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002588 int num_pins)
2589{
2590 struct conexant_spec *spec = codec->spec;
2591 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2592 int i;
2593
2594 for (i = 0; i < num_pins; i++, dig_pins++) {
2595 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2596 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2597 continue;
2598 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2599 continue;
2600 if (spec->slave_dig_outs[0])
2601 nid_loc++;
2602 else
2603 nid_loc = spec->slave_dig_outs;
2604 }
2605}
2606
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002607static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002608 .num_items = 4,
2609 .items = {
2610 { "Mic B", 0 },
2611 { "Mic C", 1 },
2612 { "Mic E", 2 },
2613 { "Mic F", 3 },
2614 },
2615};
2616
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002617static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002618 .ops = &snd_hda_bind_vol,
2619 .values = {
2620 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2621 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2622 0
2623 },
2624};
2625
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002626static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002627 .ops = &snd_hda_bind_sw,
2628 .values = {
2629 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2630 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2631 0
2632 },
2633};
2634
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002635static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002636 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2637 {}
2638};
2639
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002640static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002641 {
2642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2643 .name = "Master Playback Volume",
2644 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2645 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2646 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002647 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002648 .info = snd_hda_mixer_amp_volume_info,
2649 .get = snd_hda_mixer_amp_volume_get,
2650 .put = snd_hda_mixer_amp_volume_put,
2651 .tlv = { .c = snd_hda_mixer_amp_tlv },
2652 /* offset by 28 volume steps to limit minimum gain to -46dB */
2653 .private_value =
2654 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2655 },
2656 {}
2657};
2658
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002659static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002660 {
2661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2662 .name = "DC Mode Enable Switch",
2663 .info = snd_ctl_boolean_mono_info,
2664 .get = cxt5066_olpc_dc_get,
2665 .put = cxt5066_olpc_dc_put,
2666 },
2667 {
2668 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2669 .name = "DC Input Bias Enum",
2670 .info = cxt5066_olpc_dc_bias_enum_info,
2671 .get = cxt5066_olpc_dc_bias_enum_get,
2672 .put = cxt5066_olpc_dc_bias_enum_put,
2673 },
2674 {}
2675};
2676
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002677static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002678 {
2679 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2680 .name = "Master Playback Switch",
2681 .info = cxt_eapd_info,
2682 .get = cxt_eapd_get,
2683 .put = cxt5066_hp_master_sw_put,
2684 .private_value = 0x1d,
2685 },
2686
2687 {
2688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002689 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002690 .info = cxt5066_mic_boost_mux_enum_info,
2691 .get = cxt5066_mic_boost_mux_enum_get,
2692 .put = cxt5066_mic_boost_mux_enum_put,
2693 },
2694
2695 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2696 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2697 {}
2698};
2699
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002700static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002701 {
2702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002703 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002704 .info = cxt5066_mic_boost_mux_enum_info,
2705 .get = cxt5066_mic_boost_mux_enum_get,
2706 .put = cxt5066_mic_boost_mux_enum_put,
2707 .private_value = 0x23 | 0x100,
2708 },
2709 {}
2710};
2711
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002712static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002713 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2714 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2715 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2716 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2717
2718 /* Speakers */
2719 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2720 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2721
2722 /* HP, Amp */
2723 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2724 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2725
2726 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2727 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2728
2729 /* DAC1 */
2730 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2731
2732 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2733 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2734 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2735 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2736 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2737 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2738
2739 /* no digital microphone support yet */
2740 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2741
2742 /* Audio input selector */
2743 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2744
2745 /* SPDIF route: PCM */
2746 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2747 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2748
2749 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2750 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2751
2752 /* EAPD */
2753 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2754
2755 /* not handling these yet */
2756 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2757 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2758 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2759 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2760 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2761 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2762 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2763 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2764 { } /* end */
2765};
2766
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002767static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002768 /* Port A: headphones */
2769 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2770 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2771
2772 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002773 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002774
2775 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002776 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002777
2778 /* Port D: unused */
2779 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2780
2781 /* Port E: unused, but has primary EAPD */
2782 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2783 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2784
Daniel Drakec4cfe662010-01-07 13:47:04 +01002785 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002786 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2787
2788 /* Port G: internal speakers */
2789 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2790 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2791
2792 /* DAC1 */
2793 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2794
2795 /* DAC2: unused */
2796 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2797
2798 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2799 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2801 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2802 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2803 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2804 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2805 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2806 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2807 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2808 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2809 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2810
2811 /* Disable digital microphone port */
2812 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2813
2814 /* Audio input selectors */
2815 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2816 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2817
2818 /* Disable SPDIF */
2819 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2820 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821
2822 /* enable unsolicited events for Port A and B */
2823 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2824 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2825 { } /* end */
2826};
2827
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002828static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002829 /* Port A: headphones */
2830 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2832
2833 /* Port B: external microphone */
2834 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2835
2836 /* Port C: unused */
2837 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2838
2839 /* Port D: unused */
2840 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2841
2842 /* Port E: unused, but has primary EAPD */
2843 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2844 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2845
2846 /* Port F: unused */
2847 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2848
2849 /* Port G: internal speakers */
2850 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2851 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2852
2853 /* DAC1 */
2854 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2855
2856 /* DAC2: unused */
2857 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2858
2859 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2860 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2861 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2862 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2863 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2864 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2865 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2866 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2867 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2868 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2869 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2870 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2871
2872 /* Digital microphone port */
2873 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2874
2875 /* Audio input selectors */
2876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2877 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2878
2879 /* Disable SPDIF */
2880 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2881 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2882
2883 /* enable unsolicited events for Port A and B */
2884 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2885 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2886 { } /* end */
2887};
2888
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002889static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002890 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2891 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2892 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2893 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2894
2895 /* Speakers */
2896 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2897 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2898
2899 /* HP, Amp */
2900 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2901 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2902
2903 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2904 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2905
2906 /* DAC1 */
2907 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2908
2909 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2910 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2911 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2912 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2914 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2915 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2916
2917 /* Audio input selector */
2918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2919 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2920
2921 /* SPDIF route: PCM */
2922 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2923 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2924
2925 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2926 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2927
2928 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002929 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002930
2931 /* EAPD */
2932 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2933
2934 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2935 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2936 { } /* end */
2937};
2938
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002939static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002940 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2941 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2942
2943 /* Port G: internal speakers */
2944 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2945 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2946
2947 /* Port A: HP, Amp */
2948 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2949 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2950
2951 /* Port B: Mic Dock */
2952 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2953
2954 /* Port C: Mic */
2955 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2956
2957 /* Port D: HP Dock, Amp */
2958 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2959 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2960
2961 /* DAC1 */
2962 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2963
2964 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2965 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2966 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2967 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2968 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2969 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2970 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2971
2972 /* Audio input selector */
2973 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2974 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2975
2976 /* SPDIF route: PCM */
2977 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2978 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2979
2980 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2981 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2982
2983 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002984 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002985
2986 /* EAPD */
2987 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2988
2989 /* enable unsolicited events for Port A, B, C and D */
2990 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2991 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2992 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2993 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2994 { } /* end */
2995};
2996
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002997static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002998 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2999 { } /* end */
3000};
3001
David Henningsson048e78a2010-09-02 08:35:47 +02003002
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003003static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02003004 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3005 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3006 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3007 { } /* end */
3008};
3009
Daniel Drake0fb67e92009-07-16 14:46:57 +01003010/* initialize jack-sensing, too */
3011static int cxt5066_init(struct hda_codec *codec)
3012{
3013 snd_printdd("CXT5066: init\n");
3014 conexant_init(codec);
3015 if (codec->patch_ops.unsol_event) {
3016 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003017 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003018 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003019 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003020 return 0;
3021}
3022
Daniel Drake75f89912010-01-07 13:46:25 +01003023static int cxt5066_olpc_init(struct hda_codec *codec)
3024{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003025 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003026 snd_printdd("CXT5066: init\n");
3027 conexant_init(codec);
3028 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003029 if (!spec->dc_enable) {
3030 cxt5066_set_mic_boost(codec);
3031 cxt5066_olpc_automic(codec);
3032 } else {
3033 cxt5066_enable_dc(codec);
3034 }
Daniel Drake75f89912010-01-07 13:46:25 +01003035 return 0;
3036}
3037
Daniel Drake0fb67e92009-07-16 14:46:57 +01003038enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003039 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003040 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3041 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003042 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003043 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003044 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003045 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003046 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003047 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003048 CXT5066_MODELS
3049};
3050
Takashi Iwaiea734962011-01-17 11:29:34 +01003051static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003052 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003053 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3054 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003055 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003056 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003057 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003058 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003059 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003060 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003061};
3062
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003063static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003064 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003065 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003066 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003067 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003068 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003069 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003070 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3071 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003072 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003073 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003074 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003075 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003076 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003077 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003078 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003079 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3080 CXT5066_LAPTOP),
3081 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003082 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003083 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003084 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003085 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003086 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003087 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003088 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003089 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003090 {}
3091};
3092
3093static int patch_cxt5066(struct hda_codec *codec)
3094{
3095 struct conexant_spec *spec;
3096 int board_config;
3097
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003098 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3099 cxt5066_models, cxt5066_cfg_tbl);
3100#if 0 /* use the old method just for safety */
3101 if (board_config < 0)
3102 board_config = CXT5066_AUTO;
3103#endif
3104 if (board_config == CXT5066_AUTO)
3105 return patch_conexant_auto(codec);
3106
Daniel Drake0fb67e92009-07-16 14:46:57 +01003107 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3108 if (!spec)
3109 return -ENOMEM;
3110 codec->spec = spec;
3111
3112 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003113 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003114
3115 spec->dell_automute = 0;
3116 spec->multiout.max_channels = 2;
3117 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3118 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003119 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3120 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003121 spec->num_adc_nids = 1;
3122 spec->adc_nids = cxt5066_adc_nids;
3123 spec->capsrc_nids = cxt5066_capsrc_nids;
3124 spec->input_mux = &cxt5066_capture_source;
3125
3126 spec->port_d_mode = PIN_HP;
3127
3128 spec->num_init_verbs = 1;
3129 spec->init_verbs[0] = cxt5066_init_verbs;
3130 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3131 spec->channel_mode = cxt5066_modes;
3132 spec->cur_adc = 0;
3133 spec->cur_adc_idx = 0;
3134
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003135 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3136
Daniel Drake0fb67e92009-07-16 14:46:57 +01003137 switch (board_config) {
3138 default:
3139 case CXT5066_LAPTOP:
3140 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3141 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3142 break;
3143 case CXT5066_DELL_LAPTOP:
3144 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3145 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3146
3147 spec->port_d_mode = PIN_OUT;
3148 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3149 spec->num_init_verbs++;
3150 spec->dell_automute = 1;
3151 break;
David Henningssona1d69062011-01-21 13:33:28 +01003152 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003153 case CXT5066_HP_LAPTOP:
3154 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003155 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003156 spec->init_verbs[spec->num_init_verbs] =
3157 cxt5066_init_verbs_hp_laptop;
3158 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003159 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3160 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003161 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3162 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3163 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003164 if (board_config == CXT5066_HP_LAPTOP)
3165 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003166 /* input source automatically selected */
3167 spec->input_mux = NULL;
3168 spec->port_d_mode = 0;
3169 spec->mic_boost = 3; /* default 30dB gain */
3170 break;
3171
Daniel Drake0fb67e92009-07-16 14:46:57 +01003172 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003173 codec->patch_ops.init = cxt5066_olpc_init;
3174 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003175 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3176 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003177 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003178 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3179 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003180 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003181
3182 /* no S/PDIF out */
3183 spec->multiout.dig_out_nid = 0;
3184
3185 /* input source automatically selected */
3186 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003187
3188 /* our capture hooks which allow us to turn on the microphone LED
3189 * at the right time */
3190 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3191 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003192 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003193 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003194 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003195 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003196 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3197 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3198 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003199 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003200 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003201 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003202 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003203
3204 /* no S/PDIF out */
3205 spec->multiout.dig_out_nid = 0;
3206
3207 /* input source automatically selected */
3208 spec->input_mux = NULL;
3209 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003210 case CXT5066_IDEAPAD:
3211 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003212 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003213 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3214 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3215 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3216 spec->port_d_mode = 0;
3217 spec->ideapad = 1;
3218 spec->mic_boost = 2; /* default 20dB gain */
3219
3220 /* no S/PDIF out */
3221 spec->multiout.dig_out_nid = 0;
3222
3223 /* input source automatically selected */
3224 spec->input_mux = NULL;
3225 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003226 case CXT5066_THINKPAD:
3227 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003228 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003229 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3230 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3231 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3232 spec->thinkpad = 1;
3233 spec->port_d_mode = PIN_OUT;
3234 spec->mic_boost = 2; /* default 20dB gain */
3235
3236 /* no S/PDIF out */
3237 spec->multiout.dig_out_nid = 0;
3238
3239 /* input source automatically selected */
3240 spec->input_mux = NULL;
3241 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003242 }
3243
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003244 if (spec->beep_amp)
3245 snd_hda_attach_beep_device(codec, spec->beep_amp);
3246
Daniel Drake0fb67e92009-07-16 14:46:57 +01003247 return 0;
3248}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003249
3250/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003251 * Automatic parser for CX20641 & co
3252 */
3253
Takashi Iwai6764bce2011-05-13 16:52:25 +02003254static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3255 struct hda_codec *codec,
3256 unsigned int stream_tag,
3257 unsigned int format,
3258 struct snd_pcm_substream *substream)
3259{
3260 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003261 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003262 if (spec->adc_switching) {
3263 spec->cur_adc = adc;
3264 spec->cur_adc_stream_tag = stream_tag;
3265 spec->cur_adc_format = format;
3266 }
3267 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3268 return 0;
3269}
3270
3271static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3272 struct hda_codec *codec,
3273 struct snd_pcm_substream *substream)
3274{
3275 struct conexant_spec *spec = codec->spec;
3276 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3277 spec->cur_adc = 0;
3278 return 0;
3279}
3280
3281static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3282 .substreams = 1,
3283 .channels_min = 2,
3284 .channels_max = 2,
3285 .nid = 0, /* fill later */
3286 .ops = {
3287 .prepare = cx_auto_capture_pcm_prepare,
3288 .cleanup = cx_auto_capture_pcm_cleanup
3289 },
3290};
3291
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003292static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003293
3294/* get the connection index of @nid in the widget @mux */
3295static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3296 hda_nid_t nid)
3297{
3298 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3299 int i, nums;
3300
3301 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3302 for (i = 0; i < nums; i++)
3303 if (conn[i] == nid)
3304 return i;
3305 return -1;
3306}
3307
3308/* get an unassigned DAC from the given list.
3309 * Return the nid if found and reduce the DAC list, or return zero if
3310 * not found
3311 */
3312static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3313 hda_nid_t *dacs, int *num_dacs)
3314{
3315 int i, nums = *num_dacs;
3316 hda_nid_t ret = 0;
3317
3318 for (i = 0; i < nums; i++) {
3319 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3320 ret = dacs[i];
3321 break;
3322 }
3323 }
3324 if (!ret)
3325 return 0;
3326 if (--nums > 0)
3327 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3328 *num_dacs = nums;
3329 return ret;
3330}
3331
3332#define MAX_AUTO_DACS 5
3333
3334/* fill analog DAC list from the widget tree */
3335static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3336{
3337 hda_nid_t nid, end_nid;
3338 int nums = 0;
3339
3340 end_nid = codec->start_nid + codec->num_nodes;
3341 for (nid = codec->start_nid; nid < end_nid; nid++) {
3342 unsigned int wcaps = get_wcaps(codec, nid);
3343 unsigned int type = get_wcaps_type(wcaps);
3344 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3345 dacs[nums++] = nid;
3346 if (nums >= MAX_AUTO_DACS)
3347 break;
3348 }
3349 }
3350 return nums;
3351}
3352
3353/* fill pin_dac_pair list from the pin and dac list */
3354static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3355 int num_pins, hda_nid_t *dacs, int *rest,
3356 struct pin_dac_pair *filled, int type)
3357{
3358 int i, nums;
3359
3360 nums = 0;
3361 for (i = 0; i < num_pins; i++) {
3362 filled[nums].pin = pins[i];
3363 filled[nums].type = type;
3364 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3365 nums++;
3366 }
3367 return nums;
3368}
3369
3370/* parse analog output paths */
3371static void cx_auto_parse_output(struct hda_codec *codec)
3372{
3373 struct conexant_spec *spec = codec->spec;
3374 struct auto_pin_cfg *cfg = &spec->autocfg;
3375 hda_nid_t dacs[MAX_AUTO_DACS];
3376 int i, j, nums, rest;
3377
3378 rest = fill_cx_auto_dacs(codec, dacs);
3379 /* parse all analog output pins */
3380 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3381 dacs, &rest, spec->dac_info,
3382 AUTO_PIN_LINE_OUT);
3383 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3384 dacs, &rest, spec->dac_info + nums,
3385 AUTO_PIN_HP_OUT);
3386 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3387 dacs, &rest, spec->dac_info + nums,
3388 AUTO_PIN_SPEAKER_OUT);
3389 spec->dac_info_filled = nums;
3390 /* fill multiout struct */
3391 for (i = 0; i < nums; i++) {
3392 hda_nid_t dac = spec->dac_info[i].dac;
3393 if (!dac)
3394 continue;
3395 switch (spec->dac_info[i].type) {
3396 case AUTO_PIN_LINE_OUT:
3397 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3398 spec->multiout.num_dacs++;
3399 break;
3400 case AUTO_PIN_HP_OUT:
3401 case AUTO_PIN_SPEAKER_OUT:
3402 if (!spec->multiout.hp_nid) {
3403 spec->multiout.hp_nid = dac;
3404 break;
3405 }
3406 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3407 if (!spec->multiout.extra_out_nid[j]) {
3408 spec->multiout.extra_out_nid[j] = dac;
3409 break;
3410 }
3411 break;
3412 }
3413 }
3414 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003415 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003416
3417 if (cfg->hp_outs > 0)
3418 spec->auto_mute = 1;
3419 spec->vmaster_nid = spec->private_dac_nids[0];
3420}
3421
Takashi Iwaida339862011-05-13 16:24:15 +02003422static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3423 hda_nid_t *pins, bool on);
3424
Takashi Iwaif2e57312010-09-15 10:07:08 +02003425/* auto-mute/unmute speaker and line outs according to headphone jack */
3426static void cx_auto_hp_automute(struct hda_codec *codec)
3427{
3428 struct conexant_spec *spec = codec->spec;
3429 struct auto_pin_cfg *cfg = &spec->autocfg;
3430 int i, present;
3431
3432 if (!spec->auto_mute)
3433 return;
3434 present = 0;
3435 for (i = 0; i < cfg->hp_outs; i++) {
3436 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3437 present = 1;
3438 break;
3439 }
3440 }
Takashi Iwaida339862011-05-13 16:24:15 +02003441 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003442 for (i = 0; i < cfg->line_outs; i++) {
3443 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3444 AC_VERB_SET_PIN_WIDGET_CONTROL,
3445 present ? 0 : PIN_OUT);
3446 }
Takashi Iwaida339862011-05-13 16:24:15 +02003447 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003448 for (i = 0; !present && i < cfg->line_outs; i++)
3449 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3450 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003451 for (i = 0; i < cfg->speaker_outs; i++) {
3452 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3453 AC_VERB_SET_PIN_WIDGET_CONTROL,
3454 present ? 0 : PIN_OUT);
3455 }
Takashi Iwaida339862011-05-13 16:24:15 +02003456 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003457}
3458
Takashi Iwai6764bce2011-05-13 16:52:25 +02003459static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3460 struct snd_ctl_elem_info *uinfo)
3461{
3462 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3463 struct conexant_spec *spec = codec->spec;
3464
3465 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3466}
3467
3468static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3469 struct snd_ctl_elem_value *ucontrol)
3470{
3471 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3472 struct conexant_spec *spec = codec->spec;
3473
3474 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3475 return 0;
3476}
3477
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003478/* look for the route the given pin from mux and return the index;
3479 * if do_select is set, actually select the route.
3480 */
3481static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003482 hda_nid_t pin, hda_nid_t *srcp,
3483 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003484{
3485 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3486 int i, nums;
3487
Takashi Iwaicf27f292011-05-16 11:33:02 +02003488 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3489 case AC_WID_AUD_IN:
3490 case AC_WID_AUD_SEL:
3491 case AC_WID_AUD_MIX:
3492 break;
3493 default:
3494 return -1;
3495 }
3496
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003497 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3498 for (i = 0; i < nums; i++)
3499 if (conn[i] == pin) {
3500 if (do_select)
3501 snd_hda_codec_write(codec, mux, 0,
3502 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003503 if (srcp)
3504 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003505 return i;
3506 }
3507 depth++;
3508 if (depth == 2)
3509 return -1;
3510 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003511 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003512 do_select, depth);
3513 if (ret >= 0) {
3514 if (do_select)
3515 snd_hda_codec_write(codec, mux, 0,
3516 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003517 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003518 }
3519 }
3520 return -1;
3521}
3522
3523static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3524 hda_nid_t pin)
3525{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003526 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003527}
3528
3529static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3530 hda_nid_t pin)
3531{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003532 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003533}
3534
Takashi Iwai6764bce2011-05-13 16:52:25 +02003535static int cx_auto_mux_enum_update(struct hda_codec *codec,
3536 const struct hda_input_mux *imux,
3537 unsigned int idx)
3538{
3539 struct conexant_spec *spec = codec->spec;
3540 hda_nid_t adc;
3541
3542 if (!imux->num_items)
3543 return 0;
3544 if (idx >= imux->num_items)
3545 idx = imux->num_items - 1;
3546 if (spec->cur_mux[0] == idx)
3547 return 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003548 adc = spec->imux_info[idx].adc;
3549 select_input_connection(codec, spec->imux_info[idx].adc,
3550 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003551 if (spec->cur_adc && spec->cur_adc != adc) {
3552 /* stream is running, let's swap the current ADC */
3553 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3554 spec->cur_adc = adc;
3555 snd_hda_codec_setup_stream(codec, adc,
3556 spec->cur_adc_stream_tag, 0,
3557 spec->cur_adc_format);
3558 }
3559 spec->cur_mux[0] = idx;
3560 return 1;
3561}
3562
3563static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3564 struct snd_ctl_elem_value *ucontrol)
3565{
3566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3567 struct conexant_spec *spec = codec->spec;
3568
3569 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3570 ucontrol->value.enumerated.item[0]);
3571}
3572
3573static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3574 {
3575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3576 .name = "Capture Source",
3577 .info = cx_auto_mux_enum_info,
3578 .get = cx_auto_mux_enum_get,
3579 .put = cx_auto_mux_enum_put
3580 },
3581 {}
3582};
3583
Takashi Iwaif2e57312010-09-15 10:07:08 +02003584/* automatic switch internal and external mic */
3585static void cx_auto_automic(struct hda_codec *codec)
3586{
3587 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003588 int ext_idx = spec->auto_mic_ext;
3589
3590 if (!spec->auto_mic)
3591 return;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003592 if (snd_hda_jack_detect(codec, spec->imux_info[ext_idx].pin))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003593 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3594 else
3595 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003596}
3597
3598static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3599{
3600 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3601 switch (res >> 26) {
3602 case CONEXANT_HP_EVENT:
3603 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003604 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003605 break;
3606 case CONEXANT_MIC_EVENT:
3607 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003608 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003609 break;
3610 }
3611}
3612
Takashi Iwaif2e57312010-09-15 10:07:08 +02003613/* return true if it's an internal-mic pin */
3614static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3615{
3616 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3617 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003618 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003619}
3620
3621/* return true if it's an external-mic pin */
3622static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3623{
3624 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3625 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003626 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3627 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003628}
3629
3630/* check whether the pin config is suitable for auto-mic switching;
3631 * auto-mic is enabled only when one int-mic and one-ext mic exist
3632 */
3633static void cx_auto_check_auto_mic(struct hda_codec *codec)
3634{
3635 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003636
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003637 if (is_ext_mic(codec, spec->imux_info[0].pin) &&
3638 is_int_mic(codec, spec->imux_info[1].pin)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003639 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003640 spec->auto_mic_ext = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003641 return;
3642 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003643 if (is_int_mic(codec, spec->imux_info[0].pin) &&
3644 is_ext_mic(codec, spec->imux_info[1].pin)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003645 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003646 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003647 return;
3648 }
3649}
3650
3651static void cx_auto_parse_input(struct hda_codec *codec)
3652{
3653 struct conexant_spec *spec = codec->spec;
3654 struct auto_pin_cfg *cfg = &spec->autocfg;
3655 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003656 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003657
3658 imux = &spec->private_imux;
3659 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003660 for (j = 0; j < spec->num_adc_nids; j++) {
3661 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003662 int idx = get_input_connection(codec, adc,
3663 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003664 if (idx >= 0) {
3665 const char *label;
3666 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003667 spec->imux_info[imux->num_items].index = i;
3668 spec->imux_info[imux->num_items].boost = 0;
3669 spec->imux_info[imux->num_items].adc = adc;
3670 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003671 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003672 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003673 break;
3674 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003675 }
3676 }
3677 if (imux->num_items == 2 && cfg->num_inputs == 2)
3678 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003679 if (imux->num_items > 1 && !spec->auto_mic) {
3680 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003681 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003682 spec->adc_switching = 1;
3683 break;
3684 }
3685 }
3686 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003687}
3688
3689/* get digital-input audio widget corresponding to the given pin */
3690static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3691{
3692 hda_nid_t nid, end_nid;
3693
3694 end_nid = codec->start_nid + codec->num_nodes;
3695 for (nid = codec->start_nid; nid < end_nid; nid++) {
3696 unsigned int wcaps = get_wcaps(codec, nid);
3697 unsigned int type = get_wcaps_type(wcaps);
3698 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3699 if (get_connection_index(codec, nid, pin) >= 0)
3700 return nid;
3701 }
3702 }
3703 return 0;
3704}
3705
3706static void cx_auto_parse_digital(struct hda_codec *codec)
3707{
3708 struct conexant_spec *spec = codec->spec;
3709 struct auto_pin_cfg *cfg = &spec->autocfg;
3710 hda_nid_t nid;
3711
3712 if (cfg->dig_outs &&
3713 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3714 spec->multiout.dig_out_nid = nid;
3715 if (cfg->dig_in_pin)
3716 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3717}
3718
3719#ifdef CONFIG_SND_HDA_INPUT_BEEP
3720static void cx_auto_parse_beep(struct hda_codec *codec)
3721{
3722 struct conexant_spec *spec = codec->spec;
3723 hda_nid_t nid, end_nid;
3724
3725 end_nid = codec->start_nid + codec->num_nodes;
3726 for (nid = codec->start_nid; nid < end_nid; nid++)
3727 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3728 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3729 break;
3730 }
3731}
3732#else
3733#define cx_auto_parse_beep(codec)
3734#endif
3735
3736static int cx_auto_parse_auto_config(struct hda_codec *codec)
3737{
3738 struct conexant_spec *spec = codec->spec;
3739 int err;
3740
3741 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3742 if (err < 0)
3743 return err;
3744
3745 cx_auto_parse_output(codec);
3746 cx_auto_parse_input(codec);
3747 cx_auto_parse_digital(codec);
3748 cx_auto_parse_beep(codec);
3749 return 0;
3750}
3751
Takashi Iwaida339862011-05-13 16:24:15 +02003752static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3753 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003754{
3755 int i;
3756 for (i = 0; i < num_pins; i++) {
3757 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3758 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003759 AC_VERB_SET_EAPD_BTLENABLE,
3760 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003761 }
3762}
3763
3764static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3765 hda_nid_t src)
3766{
3767 int idx = get_connection_index(codec, pin, src);
3768 if (idx >= 0)
3769 snd_hda_codec_write(codec, pin, 0,
3770 AC_VERB_SET_CONNECT_SEL, idx);
3771}
3772
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003773static void mute_outputs(struct hda_codec *codec, int num_nids,
3774 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003775{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003776 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003777
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003778 for (i = 0; i < num_nids; i++) {
3779 hda_nid_t nid = nids[i];
3780 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3781 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003782 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3783 val = AMP_OUT_MUTE;
3784 else
3785 val = AMP_OUT_ZERO;
3786 snd_hda_codec_write(codec, nid, 0,
3787 AC_VERB_SET_AMP_GAIN_MUTE, val);
3788 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003789}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003790
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003791static void cx_auto_init_output(struct hda_codec *codec)
3792{
3793 struct conexant_spec *spec = codec->spec;
3794 struct auto_pin_cfg *cfg = &spec->autocfg;
3795 hda_nid_t nid;
3796 int i;
3797
3798 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003799 for (i = 0; i < cfg->hp_outs; i++)
3800 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3801 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003802 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3803 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3804 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003805 if (spec->auto_mute) {
3806 for (i = 0; i < cfg->hp_outs; i++) {
3807 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3808 AC_VERB_SET_UNSOLICITED_ENABLE,
3809 AC_USRSP_EN | CONEXANT_HP_EVENT);
3810 }
3811 cx_auto_hp_automute(codec);
3812 } else {
3813 for (i = 0; i < cfg->line_outs; i++)
3814 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3815 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3816 for (i = 0; i < cfg->speaker_outs; i++)
3817 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3818 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003819 /* turn on EAPD */
3820 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3821 true);
3822 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3823 true);
3824 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3825 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003826 }
3827
3828 for (i = 0; i < spec->dac_info_filled; i++) {
3829 nid = spec->dac_info[i].dac;
3830 if (!nid)
3831 nid = spec->multiout.dac_nids[0];
3832 select_connection(codec, spec->dac_info[i].pin, nid);
3833 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003834}
3835
3836static void cx_auto_init_input(struct hda_codec *codec)
3837{
3838 struct conexant_spec *spec = codec->spec;
3839 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003840 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003841
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003842 for (i = 0; i < spec->num_adc_nids; i++) {
3843 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003844 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3845 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003846 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3847 val = AMP_IN_MUTE(0);
3848 else
3849 val = AMP_IN_UNMUTE(0);
3850 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3851 val);
3852 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003853
3854 for (i = 0; i < cfg->num_inputs; i++) {
3855 unsigned int type;
3856 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3857 type = PIN_VREF80;
3858 else
3859 type = PIN_IN;
3860 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3861 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3862 }
3863
3864 if (spec->auto_mic) {
3865 int ext_idx = spec->auto_mic_ext;
3866 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3867 AC_VERB_SET_UNSOLICITED_ENABLE,
3868 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3869 cx_auto_automic(codec);
3870 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003871 select_input_connection(codec, spec->imux_info[0].adc,
3872 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003873 }
3874}
3875
3876static void cx_auto_init_digital(struct hda_codec *codec)
3877{
3878 struct conexant_spec *spec = codec->spec;
3879 struct auto_pin_cfg *cfg = &spec->autocfg;
3880
3881 if (spec->multiout.dig_out_nid)
3882 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3883 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3884 if (spec->dig_in_nid)
3885 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3886 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3887}
3888
3889static int cx_auto_init(struct hda_codec *codec)
3890{
3891 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3892 cx_auto_init_output(codec);
3893 cx_auto_init_input(codec);
3894 cx_auto_init_digital(codec);
3895 return 0;
3896}
3897
David Henningsson983345e2011-02-15 19:57:09 +01003898static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003899 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003900 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003901{
3902 static char name[32];
3903 static struct snd_kcontrol_new knew[] = {
3904 HDA_CODEC_VOLUME(name, 0, 0, 0),
3905 HDA_CODEC_MUTE(name, 0, 0, 0),
3906 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003907 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003908 int i, err;
3909
3910 for (i = 0; i < 2; i++) {
3911 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003912 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3913 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003914 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3915 knew[i].index = cidx;
3916 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3917 kctl = snd_ctl_new1(&knew[i], codec);
3918 if (!kctl)
3919 return -ENOMEM;
3920 err = snd_hda_ctl_add(codec, nid, kctl);
3921 if (err < 0)
3922 return err;
3923 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3924 break;
3925 }
3926 return 0;
3927}
3928
David Henningsson983345e2011-02-15 19:57:09 +01003929#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3930 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3931
Takashi Iwaif2e57312010-09-15 10:07:08 +02003932#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3933 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3934
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003935static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3936 hda_nid_t pin, const char *name, int idx)
3937{
3938 unsigned int caps;
3939 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3940 if (caps & AC_AMPCAP_NUM_STEPS)
3941 return cx_auto_add_pb_volume(codec, dac, name, idx);
3942 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3943 if (caps & AC_AMPCAP_NUM_STEPS)
3944 return cx_auto_add_pb_volume(codec, pin, name, idx);
3945 return 0;
3946}
3947
Takashi Iwaif2e57312010-09-15 10:07:08 +02003948static int cx_auto_build_output_controls(struct hda_codec *codec)
3949{
3950 struct conexant_spec *spec = codec->spec;
3951 int i, err;
3952 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003953 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003954
3955 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003956 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3957 spec->dac_info[0].pin,
3958 "Master", 0);
3959
Takashi Iwaif2e57312010-09-15 10:07:08 +02003960 for (i = 0; i < spec->dac_info_filled; i++) {
3961 const char *label;
3962 int idx, type;
3963 if (!spec->dac_info[i].dac)
3964 continue;
3965 type = spec->dac_info[i].type;
3966 if (type == AUTO_PIN_LINE_OUT)
3967 type = spec->autocfg.line_out_type;
3968 switch (type) {
3969 case AUTO_PIN_LINE_OUT:
3970 default:
3971 label = texts[num_line++];
3972 idx = 0;
3973 break;
3974 case AUTO_PIN_HP_OUT:
3975 label = "Headphone";
3976 idx = num_hp++;
3977 break;
3978 case AUTO_PIN_SPEAKER_OUT:
3979 label = "Speaker";
3980 idx = num_spk++;
3981 break;
3982 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003983 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3984 spec->dac_info[i].pin,
3985 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003986 if (err < 0)
3987 return err;
3988 }
3989 return 0;
3990}
3991
Takashi Iwai6764bce2011-05-13 16:52:25 +02003992static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3993 const char *label, const char *pfx,
3994 int cidx)
3995{
3996 struct conexant_spec *spec = codec->spec;
3997 int i;
3998
3999 for (i = 0; i < spec->num_adc_nids; i++) {
4000 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004001 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004002 if (idx < 0)
4003 continue;
4004 return cx_auto_add_volume_idx(codec, label, pfx,
4005 cidx, adc_nid, HDA_INPUT, idx);
4006 }
4007 return 0;
4008}
4009
Takashi Iwaicf27f292011-05-16 11:33:02 +02004010static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4011 const char *label, int cidx)
4012{
4013 struct conexant_spec *spec = codec->spec;
4014 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004015 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004016
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004017 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004018 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4019 return cx_auto_add_volume(codec, label, " Boost", cidx,
4020 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004021 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4022 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004023 if (con < 0)
4024 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004025 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004026 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004027 return 0; /* already present */
4028 }
4029
4030 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004031 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004032 return cx_auto_add_volume(codec, label, " Boost", 0,
4033 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004034 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004035 return 0;
4036}
4037
Takashi Iwaif2e57312010-09-15 10:07:08 +02004038static int cx_auto_build_input_controls(struct hda_codec *codec)
4039{
4040 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004041 struct hda_input_mux *imux = &spec->private_imux;
4042 const char *prev_label;
4043 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004044 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004045 int multi_connection;
4046
4047 multi_connection = 0;
4048 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004049 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4050 spec->imux_info[i].pin);
4051 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004052 if (i > 0 && input_conn[i] != input_conn[0])
4053 multi_connection = 1;
4054 }
David Henningsson983345e2011-02-15 19:57:09 +01004055
Takashi Iwaif2e57312010-09-15 10:07:08 +02004056 prev_label = NULL;
4057 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004058 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004059 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004060 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004061
Takashi Iwaicf27f292011-05-16 11:33:02 +02004062 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004063 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004064 if (label == prev_label)
4065 cidx++;
4066 else
4067 cidx = 0;
4068 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004069
Takashi Iwaicf27f292011-05-16 11:33:02 +02004070 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4071 if (err < 0)
4072 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004073
Takashi Iwaicf27f292011-05-16 11:33:02 +02004074 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004075 if (i > 0)
4076 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004077 err = cx_auto_add_capture_volume(codec, nid,
4078 "Capture", "", cidx);
4079 } else {
4080 err = cx_auto_add_capture_volume(codec, nid,
4081 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004082 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004083 if (err < 0)
4084 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004085 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004086
4087 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4088 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4089 if (err < 0)
4090 return err;
4091 }
4092
Takashi Iwaif2e57312010-09-15 10:07:08 +02004093 return 0;
4094}
4095
4096static int cx_auto_build_controls(struct hda_codec *codec)
4097{
4098 int err;
4099
4100 err = cx_auto_build_output_controls(codec);
4101 if (err < 0)
4102 return err;
4103 err = cx_auto_build_input_controls(codec);
4104 if (err < 0)
4105 return err;
4106 return conexant_build_controls(codec);
4107}
4108
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004109static int cx_auto_search_adcs(struct hda_codec *codec)
4110{
4111 struct conexant_spec *spec = codec->spec;
4112 hda_nid_t nid, end_nid;
4113
4114 end_nid = codec->start_nid + codec->num_nodes;
4115 for (nid = codec->start_nid; nid < end_nid; nid++) {
4116 unsigned int caps = get_wcaps(codec, nid);
4117 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4118 continue;
4119 if (caps & AC_WCAP_DIGITAL)
4120 continue;
4121 if (snd_BUG_ON(spec->num_adc_nids >=
4122 ARRAY_SIZE(spec->private_adc_nids)))
4123 break;
4124 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4125 }
4126 spec->adc_nids = spec->private_adc_nids;
4127 return 0;
4128}
4129
4130
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004131static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004132 .build_controls = cx_auto_build_controls,
4133 .build_pcms = conexant_build_pcms,
4134 .init = cx_auto_init,
4135 .free = conexant_free,
4136 .unsol_event = cx_auto_unsol_event,
4137#ifdef CONFIG_SND_HDA_POWER_SAVE
4138 .suspend = conexant_suspend,
4139#endif
4140 .reboot_notify = snd_hda_shutup_pins,
4141};
4142
4143static int patch_conexant_auto(struct hda_codec *codec)
4144{
4145 struct conexant_spec *spec;
4146 int err;
4147
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004148 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4149 codec->chip_name);
4150
Takashi Iwaif2e57312010-09-15 10:07:08 +02004151 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4152 if (!spec)
4153 return -ENOMEM;
4154 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004155 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004156 err = cx_auto_search_adcs(codec);
4157 if (err < 0)
4158 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004159 err = cx_auto_parse_auto_config(codec);
4160 if (err < 0) {
4161 kfree(codec->spec);
4162 codec->spec = NULL;
4163 return err;
4164 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004165 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004166 codec->patch_ops = cx_auto_patch_ops;
4167 if (spec->beep_amp)
4168 snd_hda_attach_beep_device(codec, spec->beep_amp);
4169 return 0;
4170}
4171
4172/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004173 */
4174
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004175static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004176 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4177 .patch = patch_cxt5045 },
4178 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4179 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004180 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4181 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004182 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4183 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004184 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4185 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004186 { .id = 0x14f15068, .name = "CX20584",
4187 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004188 { .id = 0x14f15069, .name = "CX20585",
4189 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004190 { .id = 0x14f1506e, .name = "CX20590",
4191 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004192 { .id = 0x14f15097, .name = "CX20631",
4193 .patch = patch_conexant_auto },
4194 { .id = 0x14f15098, .name = "CX20632",
4195 .patch = patch_conexant_auto },
4196 { .id = 0x14f150a1, .name = "CX20641",
4197 .patch = patch_conexant_auto },
4198 { .id = 0x14f150a2, .name = "CX20642",
4199 .patch = patch_conexant_auto },
4200 { .id = 0x14f150ab, .name = "CX20651",
4201 .patch = patch_conexant_auto },
4202 { .id = 0x14f150ac, .name = "CX20652",
4203 .patch = patch_conexant_auto },
4204 { .id = 0x14f150b8, .name = "CX20664",
4205 .patch = patch_conexant_auto },
4206 { .id = 0x14f150b9, .name = "CX20665",
4207 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004208 {} /* terminator */
4209};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004210
4211MODULE_ALIAS("snd-hda-codec-id:14f15045");
4212MODULE_ALIAS("snd-hda-codec-id:14f15047");
4213MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004214MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004215MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004216MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004217MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004218MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004219MODULE_ALIAS("snd-hda-codec-id:14f15097");
4220MODULE_ALIAS("snd-hda-codec-id:14f15098");
4221MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4222MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4223MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4224MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4225MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4226MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004227
4228MODULE_LICENSE("GPL");
4229MODULE_DESCRIPTION("Conexant HD-audio codec");
4230
4231static struct hda_codec_preset_list conexant_list = {
4232 .preset = snd_hda_preset_conexant,
4233 .owner = THIS_MODULE,
4234};
4235
4236static int __init patch_conexant_init(void)
4237{
4238 return snd_hda_add_codec_preset(&conexant_list);
4239}
4240
4241static void __exit patch_conexant_exit(void)
4242{
4243 snd_hda_delete_codec_preset(&conexant_list);
4244}
4245
4246module_init(patch_conexant_init)
4247module_exit(patch_conexant_exit)