blob: 703dda69ad7cd106b65189b0ab887ef2b87c5f05 [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",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200478 "Front Playback Volume",
479 "Surround Playback Volume",
480 "CLFE Playback Volume",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100481 NULL
482};
483
Takashi Iwaiea734962011-01-17 11:29:34 +0100484static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100485 "Headphone Playback Switch",
486 "Speaker Playback Switch",
Takashi Iwaia3a85d32011-05-17 09:17:52 +0200487 "Front Playback Switch",
488 "Surround Playback Switch",
489 "CLFE Playback Switch",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100490 NULL
491};
492
Tobin Davisc9b443d2006-11-14 12:13:39 +0100493static int conexant_build_controls(struct hda_codec *codec)
494{
495 struct conexant_spec *spec = codec->spec;
496 unsigned int i;
497 int err;
498
499 for (i = 0; i < spec->num_mixers; i++) {
500 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
501 if (err < 0)
502 return err;
503 }
504 if (spec->multiout.dig_out_nid) {
505 err = snd_hda_create_spdif_out_ctls(codec,
506 spec->multiout.dig_out_nid);
507 if (err < 0)
508 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100509 err = snd_hda_create_spdif_share_sw(codec,
510 &spec->multiout);
511 if (err < 0)
512 return err;
513 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100514 }
515 if (spec->dig_in_nid) {
516 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
517 if (err < 0)
518 return err;
519 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100520
521 /* if we have no master control, let's create it */
522 if (spec->vmaster_nid &&
523 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
524 unsigned int vmaster_tlv[4];
525 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
526 HDA_OUTPUT, vmaster_tlv);
527 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
528 vmaster_tlv, slave_vols);
529 if (err < 0)
530 return err;
531 }
532 if (spec->vmaster_nid &&
533 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
534 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
535 NULL, slave_sws);
536 if (err < 0)
537 return err;
538 }
539
Takashi Iwaib880c742009-03-10 14:41:05 +0100540 if (spec->input_mux) {
541 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
542 if (err < 0)
543 return err;
544 }
545
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200546#ifdef CONFIG_SND_HDA_INPUT_BEEP
547 /* create beep controls if needed */
548 if (spec->beep_amp) {
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200549 const struct snd_kcontrol_new *knew;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200550 for (knew = cxt_beep_mixer; knew->name; knew++) {
551 struct snd_kcontrol *kctl;
552 kctl = snd_ctl_new1(knew, codec);
553 if (!kctl)
554 return -ENOMEM;
555 kctl->private_value = spec->beep_amp;
556 err = snd_hda_ctl_add(codec, 0, kctl);
557 if (err < 0)
558 return err;
559 }
560 }
561#endif
562
Tobin Davisc9b443d2006-11-14 12:13:39 +0100563 return 0;
564}
565
Takashi Iwai697c3732010-07-30 11:28:02 +0200566#ifdef CONFIG_SND_HDA_POWER_SAVE
567static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
568{
569 snd_hda_shutup_pins(codec);
570 return 0;
571}
572#endif
573
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200574static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100575 .build_controls = conexant_build_controls,
576 .build_pcms = conexant_build_pcms,
577 .init = conexant_init,
578 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200579#ifdef CONFIG_SND_HDA_POWER_SAVE
580 .suspend = conexant_suspend,
581#endif
582 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583};
584
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200585#ifdef CONFIG_SND_HDA_INPUT_BEEP
586#define set_beep_amp(spec, nid, idx, dir) \
587 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
588#else
589#define set_beep_amp(spec, nid, idx, dir) /* NOP */
590#endif
591
Takashi Iwai6764bce2011-05-13 16:52:25 +0200592static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100593/*
594 * EAPD control
595 * the private value = nid | (invert << 8)
596 */
597
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200598#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599
Tobin Davis82f30042007-02-13 12:45:44 +0100600static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct conexant_spec *spec = codec->spec;
605 int invert = (kcontrol->private_value >> 8) & 1;
606 if (invert)
607 ucontrol->value.integer.value[0] = !spec->cur_eapd;
608 else
609 ucontrol->value.integer.value[0] = spec->cur_eapd;
610 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100611
Tobin Davisc9b443d2006-11-14 12:13:39 +0100612}
613
Tobin Davis82f30042007-02-13 12:45:44 +0100614static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100615 struct snd_ctl_elem_value *ucontrol)
616{
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct conexant_spec *spec = codec->spec;
619 int invert = (kcontrol->private_value >> 8) & 1;
620 hda_nid_t nid = kcontrol->private_value & 0xff;
621 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100622
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100623 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100624 if (invert)
625 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200626 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100627 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100628
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200630 snd_hda_codec_write_cache(codec, nid,
631 0, AC_VERB_SET_EAPD_BTLENABLE,
632 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633 return 1;
634}
635
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100636/* controls for test mode */
637#ifdef CONFIG_SND_DEBUG
638
Tobin Davis82f30042007-02-13 12:45:44 +0100639#define CXT_EAPD_SWITCH(xname, nid, mask) \
640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
641 .info = cxt_eapd_info, \
642 .get = cxt_eapd_get, \
643 .put = cxt_eapd_put, \
644 .private_value = nid | (mask<<16) }
645
646
647
Tobin Davisc9b443d2006-11-14 12:13:39 +0100648static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_info *uinfo)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
654 spec->num_channel_mode);
655}
656
657static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_value *ucontrol)
659{
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct conexant_spec *spec = codec->spec;
662 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
663 spec->num_channel_mode,
664 spec->multiout.max_channels);
665}
666
667static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671 struct conexant_spec *spec = codec->spec;
672 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
673 spec->num_channel_mode,
674 &spec->multiout.max_channels);
675 if (err >= 0 && spec->need_dac_fix)
676 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
677 return err;
678}
679
680#define CXT_PIN_MODE(xname, nid, dir) \
681 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
682 .info = conexant_ch_mode_info, \
683 .get = conexant_ch_mode_get, \
684 .put = conexant_ch_mode_put, \
685 .private_value = nid | (dir<<16) }
686
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100687#endif /* CONFIG_SND_DEBUG */
688
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689/* Conexant 5045 specific */
690
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200691static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
692static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
693static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100694#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200696static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100697 { 2, NULL },
698};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100699
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200700static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100701 .num_items = 2,
702 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100703 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100704 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100705 }
706};
707
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200708static const struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200709 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100710 .items = {
711 { "IntMic", 0x1 },
712 { "ExtMic", 0x2 },
713 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200714 { "CD", 0x4 },
715 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100716 }
717};
718
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200719static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100720 .num_items = 2,
721 .items = {
722 { "ExtMic", 0x1 },
723 { "IntMic", 0x2 },
724 }
725};
726
Tobin Davisc9b443d2006-11-14 12:13:39 +0100727/* turn on/off EAPD (+ mute HP) as a master switch */
728static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
730{
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100733 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734
Tobin Davis82f30042007-02-13 12:45:44 +0100735 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100736 return 0;
737
Tobin Davis82f30042007-02-13 12:45:44 +0100738 /* toggle internal speakers mute depending of presence of
739 * the headphone jack
740 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200741 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
742 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
743 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100744
Takashi Iwai47fd8302007-08-10 17:11:07 +0200745 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
746 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
747 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100748 return 1;
749}
750
751/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200752static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200753 .ops = &snd_hda_bind_vol,
754 .values = {
755 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
756 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
757 0
758 },
759};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100760
Tobin Davis7f296732007-03-12 11:39:01 +0100761/* toggle input of built-in and mic jack appropriately */
762static void cxt5045_hp_automic(struct hda_codec *codec)
763{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200764 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
766 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
767 {}
768 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200769 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100770 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
772 {}
773 };
774 unsigned int present;
775
Takashi Iwaid56757a2009-11-18 08:00:14 +0100776 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100777 if (present)
778 snd_hda_sequence_write(codec, mic_jack_on);
779 else
780 snd_hda_sequence_write(codec, mic_jack_off);
781}
782
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783
784/* mute internal speaker if HP is plugged */
785static void cxt5045_hp_automute(struct hda_codec *codec)
786{
Tobin Davis82f30042007-02-13 12:45:44 +0100787 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100788 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789
Takashi Iwaid56757a2009-11-18 08:00:14 +0100790 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100791
Takashi Iwai47fd8302007-08-10 17:11:07 +0200792 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
793 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
794 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795}
796
797/* unsolicited event for HP jack sensing */
798static void cxt5045_hp_unsol_event(struct hda_codec *codec,
799 unsigned int res)
800{
801 res >>= 26;
802 switch (res) {
803 case CONEXANT_HP_EVENT:
804 cxt5045_hp_automute(codec);
805 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100806 case CONEXANT_MIC_EVENT:
807 cxt5045_hp_automic(codec);
808 break;
809
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810 }
811}
812
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200813static const struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100814 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
815 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100816 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
817 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200818 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
819 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100820 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
821 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100822 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
823 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200824 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100825 {
826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
827 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100828 .info = cxt_eapd_info,
829 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100831 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100832 },
833
834 {}
835};
836
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200837static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200838 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
839 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
840 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
841 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
842
Jiang Zhe5218c892008-01-17 11:18:41 +0100843 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
844 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
845 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
846 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
847
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200848 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
849 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
850
Jiang Zhe5218c892008-01-17 11:18:41 +0100851 {}
852};
853
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200854static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100855 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
856 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100857 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
858 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100859 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
860 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100861 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
862 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100863 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
864 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100865 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
866 {
867 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
868 .name = "Master Playback Switch",
869 .info = cxt_eapd_info,
870 .get = cxt_eapd_get,
871 .put = cxt5045_hp_master_sw_put,
872 .private_value = 0x10,
873 },
874
875 {}
876};
877
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200878static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100879 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200880 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100881 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100882 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200883 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
885 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
886 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100892 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100893 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100894 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100895 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
896 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100897 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100898 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100899 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100900 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100901 { } /* end */
902};
903
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200904static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100905 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100906 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
907 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
908 /* Line In,HP, Amp */
909 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
910 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
911 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
912 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100918 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100919 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
920 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
921 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
922 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100923 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100924 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
925 /* EAPD */
926 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
927 { } /* end */
928};
Tobin Davis7f296732007-03-12 11:39:01 +0100929
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200930static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100931 /* pin sensing on HP jack */
932 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200933 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100934};
935
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200936static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100937 /* pin sensing on HP jack */
938 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200939 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100940};
941
Tobin Davisc9b443d2006-11-14 12:13:39 +0100942#ifdef CONFIG_SND_DEBUG
943/* Test configuration for debugging, modelled after the ALC260 test
944 * configuration.
945 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200946static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947 .num_items = 5,
948 .items = {
949 { "MIXER", 0x0 },
950 { "MIC1 pin", 0x1 },
951 { "LINE1 pin", 0x2 },
952 { "HP-OUT pin", 0x3 },
953 { "CD pin", 0x4 },
954 },
955};
956
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200957static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100958
959 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
961 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100962 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
963 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
964 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
965 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100966
967 /* Modes for retasking pin widgets */
968 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
969 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
970
Tobin Davis82f30042007-02-13 12:45:44 +0100971 /* EAPD Switch Control */
972 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
973
Tobin Davisc9b443d2006-11-14 12:13:39 +0100974 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100975
Tobin Davis7f296732007-03-12 11:39:01 +0100976 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
977 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
978 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
979 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
980 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
981 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
982 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
983 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
984 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
985 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100986 {
987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
988 .name = "Input Source",
989 .info = conexant_mux_enum_info,
990 .get = conexant_mux_enum_get,
991 .put = conexant_mux_enum_put,
992 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200993 /* Audio input controls */
994 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
995 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
996 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
997 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
998 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
999 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1000 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1001 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1002 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1003 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001004 { } /* end */
1005};
1006
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001007static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001008 /* Set connections */
1009 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1010 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1011 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012 /* Enable retasking pins as output, initially without power amp */
1013 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001014 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001015
1016 /* Disable digital (SPDIF) pins initially, but users can enable
1017 * them via a mixer switch. In the case of SPDIF-out, this initverb
1018 * payload also sets the generation to 0, output to be in "consumer"
1019 * PCM format, copyright asserted, no pre-emphasis and no validity
1020 * control.
1021 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001022 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1023 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001024
1025 /* Start with output sum widgets muted and their output gains at min */
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1027 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1028
1029 /* Unmute retasking pin widget output buffers since the default
1030 * state appears to be output. As the pin mode is changed by the
1031 * user the pin mode control will take care of enabling the pin's
1032 * input/output buffers as needed.
1033 */
1034 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1036
1037 /* Mute capture amp left and right */
1038 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1039
1040 /* Set ADC connection select to match default mixer setting (mic1
1041 * pin)
1042 */
1043 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001044 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001045
1046 /* Mute all inputs to mixer widget (even unconnected ones) */
1047 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1048 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1049 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1050 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1051 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1052
1053 { }
1054};
1055#endif
1056
1057
1058/* initialize jack-sensing, too */
1059static int cxt5045_init(struct hda_codec *codec)
1060{
1061 conexant_init(codec);
1062 cxt5045_hp_automute(codec);
1063 return 0;
1064}
1065
1066
1067enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001068 CXT5045_LAPTOP_HPSENSE,
1069 CXT5045_LAPTOP_MICSENSE,
1070 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001071 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001072 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073#ifdef CONFIG_SND_DEBUG
1074 CXT5045_TEST,
1075#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001076 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001077 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001078};
1079
Takashi Iwaiea734962011-01-17 11:29:34 +01001080static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001081 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1082 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1083 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1084 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001085 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001087 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001088#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001089 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001090};
1091
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001092static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001093 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001094 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1095 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001096 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001097 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001098 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1099 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001100 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1101 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001102 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1103 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1104 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001105 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1106 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001107 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001108 {}
1109};
1110
1111static int patch_cxt5045(struct hda_codec *codec)
1112{
1113 struct conexant_spec *spec;
1114 int board_config;
1115
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001116 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1117 cxt5045_models,
1118 cxt5045_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001119#if 0 /* use the old method just for safety */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001120 if (board_config < 0)
1121 board_config = CXT5045_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001122#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001123 if (board_config == CXT5045_AUTO)
1124 return patch_conexant_auto(codec);
1125
Tobin Davisc9b443d2006-11-14 12:13:39 +01001126 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1127 if (!spec)
1128 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001129 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001130 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001131
1132 spec->multiout.max_channels = 2;
1133 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1134 spec->multiout.dac_nids = cxt5045_dac_nids;
1135 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1136 spec->num_adc_nids = 1;
1137 spec->adc_nids = cxt5045_adc_nids;
1138 spec->capsrc_nids = cxt5045_capsrc_nids;
1139 spec->input_mux = &cxt5045_capture_source;
1140 spec->num_mixers = 1;
1141 spec->mixers[0] = cxt5045_mixers;
1142 spec->num_init_verbs = 1;
1143 spec->init_verbs[0] = cxt5045_init_verbs;
1144 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001145 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1146 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001147
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001148 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001149
1150 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001151
Tobin Davisc9b443d2006-11-14 12:13:39 +01001152 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001153 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001154 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001155 spec->input_mux = &cxt5045_capture_source;
1156 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001157 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1158 spec->mixers[0] = cxt5045_mixers;
1159 codec->patch_ops.init = cxt5045_init;
1160 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001161 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001162 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001163 spec->input_mux = &cxt5045_capture_source;
1164 spec->num_init_verbs = 2;
1165 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001166 spec->mixers[0] = cxt5045_mixers;
1167 codec->patch_ops.init = cxt5045_init;
1168 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001169 default:
1170 case CXT5045_LAPTOP_HPMICSENSE:
1171 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1172 spec->input_mux = &cxt5045_capture_source;
1173 spec->num_init_verbs = 3;
1174 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1175 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1176 spec->mixers[0] = cxt5045_mixers;
1177 codec->patch_ops.init = cxt5045_init;
1178 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001179 case CXT5045_BENQ:
1180 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1181 spec->input_mux = &cxt5045_capture_source_benq;
1182 spec->num_init_verbs = 1;
1183 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers;
1185 spec->mixers[1] = cxt5045_benq_mixers;
1186 spec->num_mixers = 2;
1187 codec->patch_ops.init = cxt5045_init;
1188 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001189 case CXT5045_LAPTOP_HP530:
1190 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1191 spec->input_mux = &cxt5045_capture_source_hp530;
1192 spec->num_init_verbs = 2;
1193 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1194 spec->mixers[0] = cxt5045_mixers_hp530;
1195 codec->patch_ops.init = cxt5045_init;
1196 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197#ifdef CONFIG_SND_DEBUG
1198 case CXT5045_TEST:
1199 spec->input_mux = &cxt5045_test_capture_source;
1200 spec->mixers[0] = cxt5045_test_mixer;
1201 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001202 break;
1203
Tobin Davisc9b443d2006-11-14 12:13:39 +01001204#endif
1205 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001206
Takashi Iwai031005f2008-06-26 14:49:58 +02001207 switch (codec->subsystem_id >> 16) {
1208 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001209 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001210 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001211 case 0x17aa:
1212 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1213 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1214 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001215 */
1216 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1217 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1218 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1219 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1220 (1 << AC_AMPCAP_MUTE_SHIFT));
1221 break;
1222 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001223
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001224 if (spec->beep_amp)
1225 snd_hda_attach_beep_device(codec, spec->beep_amp);
1226
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227 return 0;
1228}
1229
1230
1231/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001232#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001233
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001234static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1235static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1236static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001237
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001238static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001239 { 2, NULL },
1240};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001241
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001242static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001243 .num_items = 2,
1244 .items = {
1245 { "ExtMic", 0x2 },
1246 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247 }
1248};
1249
1250/* turn on/off EAPD (+ mute HP) as a master switch */
1251static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1252 struct snd_ctl_elem_value *ucontrol)
1253{
1254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1255 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001256 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001257
Tobin Davis82f30042007-02-13 12:45:44 +01001258 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259 return 0;
1260
Tobin Davis82f30042007-02-13 12:45:44 +01001261 /* toggle internal speakers mute depending of presence of
1262 * the headphone jack
1263 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001264 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001265 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1266 * pin widgets unlike other codecs. In this case, we need to
1267 * set index 0x01 for the volume from the mixer amp 0x19.
1268 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001269 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001270 HDA_AMP_MUTE, bits);
1271 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1272 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1273 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274 return 1;
1275}
1276
Tobin Davisc9b443d2006-11-14 12:13:39 +01001277/* mute internal speaker if HP is plugged */
1278static void cxt5047_hp_automute(struct hda_codec *codec)
1279{
Tobin Davis82f30042007-02-13 12:45:44 +01001280 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001281 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282
Takashi Iwaid56757a2009-11-18 08:00:14 +01001283 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001284
Takashi Iwai47fd8302007-08-10 17:11:07 +02001285 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001286 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001287 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001288 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001289}
1290
1291/* toggle input of built-in and mic jack appropriately */
1292static void cxt5047_hp_automic(struct hda_codec *codec)
1293{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001294 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001295 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1296 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 {}
1298 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001299 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001300 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1301 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001302 {}
1303 };
1304 unsigned int present;
1305
Takashi Iwaid56757a2009-11-18 08:00:14 +01001306 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001307 if (present)
1308 snd_hda_sequence_write(codec, mic_jack_on);
1309 else
1310 snd_hda_sequence_write(codec, mic_jack_off);
1311}
1312
1313/* unsolicited event for HP jack sensing */
1314static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1315 unsigned int res)
1316{
Marc Boucher9f113e02008-01-22 15:18:08 +01001317 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001318 case CONEXANT_HP_EVENT:
1319 cxt5047_hp_automute(codec);
1320 break;
1321 case CONEXANT_MIC_EVENT:
1322 cxt5047_hp_automic(codec);
1323 break;
1324 }
1325}
1326
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001327static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001328 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1329 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001330 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001331 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1332 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1333 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1334 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001335 {
1336 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1337 .name = "Master Playback Switch",
1338 .info = cxt_eapd_info,
1339 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 .put = cxt5047_hp_master_sw_put,
1341 .private_value = 0x13,
1342 },
1343
1344 {}
1345};
1346
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001347static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001348 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001349 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001350 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1351 {}
1352};
1353
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001354static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001355 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356 { } /* end */
1357};
1358
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001359static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001360 /* Line in, Mic, Built-in Mic */
1361 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1362 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1363 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001364 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001365 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001366 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1367 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001368 /* Record selector: Mic */
1369 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1370 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1371 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1372 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001373 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1374 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1375 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1376 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001377 /* SPDIF route: PCM */
1378 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001379 /* Enable unsolicited events */
1380 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1381 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 { } /* end */
1383};
1384
1385/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001386static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001387 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001388 {}
1389};
1390
1391/* Test configuration for debugging, modelled after the ALC260 test
1392 * configuration.
1393 */
1394#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001395static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001396 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001398 { "LINE1 pin", 0x0 },
1399 { "MIC1 pin", 0x1 },
1400 { "MIC2 pin", 0x2 },
1401 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001402 },
1403};
1404
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001405static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406
1407 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001408 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1410 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001412 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001416 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001420
1421 /* Modes for retasking pin widgets */
1422 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1423 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1424
Tobin Davis82f30042007-02-13 12:45:44 +01001425 /* EAPD Switch Control */
1426 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1427
Tobin Davisc9b443d2006-11-14 12:13:39 +01001428 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001429 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1430 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1431 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1432 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1433 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1434 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1435 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1436 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001437
Tobin Davis82f30042007-02-13 12:45:44 +01001438 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1439 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1440 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1441 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1442 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1443 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1444 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1445 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001446 {
1447 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1448 .name = "Input Source",
1449 .info = conexant_mux_enum_info,
1450 .get = conexant_mux_enum_get,
1451 .put = conexant_mux_enum_put,
1452 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001453 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001454
Tobin Davisc9b443d2006-11-14 12:13:39 +01001455 { } /* end */
1456};
1457
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001458static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459 /* Enable retasking pins as output, initially without power amp */
1460 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1461 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1462 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1463
1464 /* Disable digital (SPDIF) pins initially, but users can enable
1465 * them via a mixer switch. In the case of SPDIF-out, this initverb
1466 * payload also sets the generation to 0, output to be in "consumer"
1467 * PCM format, copyright asserted, no pre-emphasis and no validity
1468 * control.
1469 */
1470 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1471
1472 /* Ensure mic1, mic2, line1 pin widgets take input from the
1473 * OUT1 sum bus when acting as an output.
1474 */
1475 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1476 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1477
1478 /* Start with output sum widgets muted and their output gains at min */
1479 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1480 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1481
1482 /* Unmute retasking pin widget output buffers since the default
1483 * state appears to be output. As the pin mode is changed by the
1484 * user the pin mode control will take care of enabling the pin's
1485 * input/output buffers as needed.
1486 */
1487 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1488 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1489 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1490
1491 /* Mute capture amp left and right */
1492 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1493
1494 /* Set ADC connection select to match default mixer setting (mic1
1495 * pin)
1496 */
1497 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1498
1499 /* Mute all inputs to mixer widget (even unconnected ones) */
1500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1501 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1502 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1503 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1507 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1508
1509 { }
1510};
1511#endif
1512
1513
1514/* initialize jack-sensing, too */
1515static int cxt5047_hp_init(struct hda_codec *codec)
1516{
1517 conexant_init(codec);
1518 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001519 return 0;
1520}
1521
1522
1523enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001524 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1525 CXT5047_LAPTOP_HP, /* Some HP laptops */
1526 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001527#ifdef CONFIG_SND_DEBUG
1528 CXT5047_TEST,
1529#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001530 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001531 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532};
1533
Takashi Iwaiea734962011-01-17 11:29:34 +01001534static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001535 [CXT5047_LAPTOP] = "laptop",
1536 [CXT5047_LAPTOP_HP] = "laptop-hp",
1537 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001539 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001540#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001541 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001542};
1543
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001544static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001545 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001546 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1547 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001548 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001549 {}
1550};
1551
1552static int patch_cxt5047(struct hda_codec *codec)
1553{
1554 struct conexant_spec *spec;
1555 int board_config;
1556
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001557 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1558 cxt5047_models,
1559 cxt5047_cfg_tbl);
1560#if 0 /* not enabled as default, as BIOS often broken for this codec */
1561 if (board_config < 0)
1562 board_config = CXT5047_AUTO;
1563#endif
1564 if (board_config == CXT5047_AUTO)
1565 return patch_conexant_auto(codec);
1566
Tobin Davisc9b443d2006-11-14 12:13:39 +01001567 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1568 if (!spec)
1569 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001571 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001572
1573 spec->multiout.max_channels = 2;
1574 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1575 spec->multiout.dac_nids = cxt5047_dac_nids;
1576 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1577 spec->num_adc_nids = 1;
1578 spec->adc_nids = cxt5047_adc_nids;
1579 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001580 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001581 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001582 spec->num_init_verbs = 1;
1583 spec->init_verbs[0] = cxt5047_init_verbs;
1584 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001585 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1586 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001587
1588 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001589
Tobin Davisc9b443d2006-11-14 12:13:39 +01001590 switch (board_config) {
1591 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001592 spec->num_mixers = 2;
1593 spec->mixers[1] = cxt5047_hp_spk_mixers;
1594 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001595 break;
1596 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001597 spec->num_mixers = 2;
1598 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001599 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001600 codec->patch_ops.init = cxt5047_hp_init;
1601 break;
1602 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001603 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001604 spec->num_mixers = 2;
1605 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001606 spec->num_init_verbs = 2;
1607 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001608 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001609 break;
1610#ifdef CONFIG_SND_DEBUG
1611 case CXT5047_TEST:
1612 spec->input_mux = &cxt5047_test_capture_source;
1613 spec->mixers[0] = cxt5047_test_mixer;
1614 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001615 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001616#endif
1617 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001618 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001619
1620 switch (codec->subsystem_id >> 16) {
1621 case 0x103c:
1622 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1623 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1624 * with 0 dB offset 0x17)
1625 */
1626 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1627 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1628 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1629 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1630 (1 << AC_AMPCAP_MUTE_SHIFT));
1631 break;
1632 }
1633
Tobin Davisc9b443d2006-11-14 12:13:39 +01001634 return 0;
1635}
1636
Takashi Iwai461e2c72008-01-25 11:35:17 +01001637/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001638static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1639static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001640
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001641static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001642 { 2, NULL },
1643};
1644
1645static void cxt5051_update_speaker(struct hda_codec *codec)
1646{
1647 struct conexant_spec *spec = codec->spec;
1648 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001649 /* headphone pin */
1650 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1651 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1652 pinctl);
1653 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001654 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1655 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1656 pinctl);
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001657 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1658 if (spec->ideapad)
1659 snd_hda_codec_write(codec, 0x1b, 0,
1660 AC_VERB_SET_PIN_WIDGET_CONTROL,
1661 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001662}
1663
1664/* turn on/off EAPD (+ mute HP) as a master switch */
1665static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1666 struct snd_ctl_elem_value *ucontrol)
1667{
1668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1669
1670 if (!cxt_eapd_put(kcontrol, ucontrol))
1671 return 0;
1672 cxt5051_update_speaker(codec);
1673 return 1;
1674}
1675
1676/* toggle input of built-in and mic jack appropriately */
1677static void cxt5051_portb_automic(struct hda_codec *codec)
1678{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001679 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001680 unsigned int present;
1681
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001682 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001683 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001684 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001685 snd_hda_codec_write(codec, 0x14, 0,
1686 AC_VERB_SET_CONNECT_SEL,
1687 present ? 0x01 : 0x00);
1688}
1689
1690/* switch the current ADC according to the jack state */
1691static void cxt5051_portc_automic(struct hda_codec *codec)
1692{
1693 struct conexant_spec *spec = codec->spec;
1694 unsigned int present;
1695 hda_nid_t new_adc;
1696
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001697 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001698 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001699 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001700 if (present)
1701 spec->cur_adc_idx = 1;
1702 else
1703 spec->cur_adc_idx = 0;
1704 new_adc = spec->adc_nids[spec->cur_adc_idx];
1705 if (spec->cur_adc && spec->cur_adc != new_adc) {
1706 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001707 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001708 spec->cur_adc = new_adc;
1709 snd_hda_codec_setup_stream(codec, new_adc,
1710 spec->cur_adc_stream_tag, 0,
1711 spec->cur_adc_format);
1712 }
1713}
1714
1715/* mute internal speaker if HP is plugged */
1716static void cxt5051_hp_automute(struct hda_codec *codec)
1717{
1718 struct conexant_spec *spec = codec->spec;
1719
Takashi Iwaid56757a2009-11-18 08:00:14 +01001720 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001721 cxt5051_update_speaker(codec);
1722}
1723
1724/* unsolicited event for HP jack sensing */
1725static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1726 unsigned int res)
1727{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001728 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001729 switch (res >> 26) {
1730 case CONEXANT_HP_EVENT:
1731 cxt5051_hp_automute(codec);
1732 break;
1733 case CXT5051_PORTB_EVENT:
1734 cxt5051_portb_automic(codec);
1735 break;
1736 case CXT5051_PORTC_EVENT:
1737 cxt5051_portc_automic(codec);
1738 break;
1739 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001740 snd_hda_input_jack_report(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001741}
1742
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001743static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001744 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1745 {
1746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1747 .name = "Master Playback Switch",
1748 .info = cxt_eapd_info,
1749 .get = cxt_eapd_get,
1750 .put = cxt5051_hp_master_sw_put,
1751 .private_value = 0x1a,
1752 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001753 {}
1754};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001755
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001756static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001757 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1758 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001759 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1760 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001761 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1762 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001763 {}
1764};
1765
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001766static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001767 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1768 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001769 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1770 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001771 {}
1772};
1773
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001774static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001775 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1776 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001777 {}
1778};
1779
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001780static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001781 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1782 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001783 {}
1784};
1785
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001786static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001787 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001789 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1790 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001791 {}
1792};
1793
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001794static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001795 /* Line in, Mic */
1796 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1797 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1798 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1799 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1800 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1801 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1802 /* SPK */
1803 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1804 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1805 /* HP, Amp */
1806 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1807 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1808 /* DAC1 */
1809 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001810 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1814 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001815 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001816 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1817 /* EAPD */
1818 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1819 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001820 { } /* end */
1821};
1822
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001823static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001824 /* Line in, Mic */
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1828 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1829 /* SPK */
1830 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1831 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1832 /* HP, Amp */
1833 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1834 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* DAC1 */
1836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001837 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1840 /* SPDIF route: PCM */
1841 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1842 /* EAPD */
1843 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001845 { } /* end */
1846};
1847
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001848static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001849 /* Line in, Mic */
1850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1851 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1852 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1853 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1854 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1856 /* SPK */
1857 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1858 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1859 /* HP, Amp */
1860 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1861 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1862 /* Docking HP */
1863 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1864 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1865 /* DAC1 */
1866 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001867 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1870 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1871 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001872 {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 -05001873 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1874 /* EAPD */
1875 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1876 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001877 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1878 { } /* end */
1879};
1880
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001881static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001882 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001884 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1885 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1886 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1887 /* SPK */
1888 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1889 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1890 /* HP, Amp */
1891 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1892 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1893 /* DAC1 */
1894 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001895 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1897 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1898 /* SPDIF route: PCM */
1899 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1900 /* EAPD */
1901 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1902 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001903 { } /* end */
1904};
1905
Takashi Iwai6953e552010-01-24 11:00:27 +01001906static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1907 unsigned int event)
1908{
1909 snd_hda_codec_write(codec, nid, 0,
1910 AC_VERB_SET_UNSOLICITED_ENABLE,
1911 AC_USRSP_EN | event);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01001912 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1913 snd_hda_input_jack_report(codec, nid);
Takashi Iwai6953e552010-01-24 11:00:27 +01001914}
1915
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001916static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001917 /* Subwoofer */
1918 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1919 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 { } /* end */
1921};
1922
Takashi Iwai461e2c72008-01-25 11:35:17 +01001923/* initialize jack-sensing, too */
1924static int cxt5051_init(struct hda_codec *codec)
1925{
Takashi Iwai6953e552010-01-24 11:00:27 +01001926 struct conexant_spec *spec = codec->spec;
1927
Takashi Iwai461e2c72008-01-25 11:35:17 +01001928 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001929 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001930
1931 if (spec->auto_mic & AUTO_MIC_PORTB)
1932 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1933 if (spec->auto_mic & AUTO_MIC_PORTC)
1934 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1935
Takashi Iwai461e2c72008-01-25 11:35:17 +01001936 if (codec->patch_ops.unsol_event) {
1937 cxt5051_hp_automute(codec);
1938 cxt5051_portb_automic(codec);
1939 cxt5051_portc_automic(codec);
1940 }
1941 return 0;
1942}
1943
1944
1945enum {
1946 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1947 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001948 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001949 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001950 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001951 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001952 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001953 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001954 CXT5051_MODELS
1955};
1956
Takashi Iwaiea734962011-01-17 11:29:34 +01001957static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001958 [CXT5051_LAPTOP] = "laptop",
1959 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001960 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001961 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001962 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001963 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001964 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001965 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966};
1967
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001968static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001969 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001970 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001971 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001972 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001973 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1974 CXT5051_LAPTOP),
1975 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001976 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03001977 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001978 {}
1979};
1980
1981static int patch_cxt5051(struct hda_codec *codec)
1982{
1983 struct conexant_spec *spec;
1984 int board_config;
1985
Takashi Iwai6764bce2011-05-13 16:52:25 +02001986 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1987 cxt5051_models,
1988 cxt5051_cfg_tbl);
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001989#if 0 /* use the old method just for safety */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001990 if (board_config < 0)
1991 board_config = CXT5051_AUTO;
Takashi Iwai9b842cd2011-05-15 12:35:04 +02001992#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001993 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001994 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001995
Takashi Iwai461e2c72008-01-25 11:35:17 +01001996 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1997 if (!spec)
1998 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001999 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002000 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002001
2002 codec->patch_ops = conexant_patch_ops;
2003 codec->patch_ops.init = cxt5051_init;
2004
2005 spec->multiout.max_channels = 2;
2006 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2007 spec->multiout.dac_nids = cxt5051_dac_nids;
2008 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2009 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2010 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002011 spec->num_mixers = 2;
2012 spec->mixers[0] = cxt5051_capture_mixers;
2013 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002014 spec->num_init_verbs = 1;
2015 spec->init_verbs[0] = cxt5051_init_verbs;
2016 spec->spdif_route = 0;
2017 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2018 spec->channel_mode = cxt5051_modes;
2019 spec->cur_adc = 0;
2020 spec->cur_adc_idx = 0;
2021
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002022 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2023
Takashi Iwai79d7d532009-03-04 09:03:50 +01002024 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2025
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002026 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002027 switch (board_config) {
2028 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002029 spec->mixers[0] = cxt5051_hp_mixers;
2030 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002031 case CXT5051_HP_DV6736:
2032 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2033 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002034 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002035 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002036 case CXT5051_LENOVO_X200:
2037 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002038 /* Thinkpad X301 does not have S/PDIF wired and no ability
2039 to use a docking station. */
2040 if (codec->subsystem_id == 0x17aa211f)
2041 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002042 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002043 case CXT5051_F700:
2044 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2045 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002046 spec->auto_mic = 0;
2047 break;
2048 case CXT5051_TOSHIBA:
2049 spec->mixers[0] = cxt5051_toshiba_mixers;
2050 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002051 break;
Herton Ronaldo Krzesinskif7154de2010-06-17 14:15:06 -03002052 case CXT5051_IDEAPAD:
2053 spec->init_verbs[spec->num_init_verbs++] =
2054 cxt5051_ideapad_init_verbs;
2055 spec->ideapad = 1;
2056 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002057 }
2058
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002059 if (spec->beep_amp)
2060 snd_hda_attach_beep_device(codec, spec->beep_amp);
2061
Takashi Iwai461e2c72008-01-25 11:35:17 +01002062 return 0;
2063}
2064
Daniel Drake0fb67e92009-07-16 14:46:57 +01002065/* Conexant 5066 specific */
2066
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002067static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2068static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2069static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2070static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01002071
Daniel Drakedbaccc02009-11-09 15:17:24 +00002072/* OLPC's microphone port is DC coupled for use with external sensors,
2073 * therefore we use a 50% mic bias in order to center the input signal with
2074 * the DC input range of the codec. */
2075#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2076
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002077static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002078 { 2, NULL },
2079};
2080
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002081#define HP_PRESENT_PORT_A (1 << 0)
2082#define HP_PRESENT_PORT_D (1 << 1)
2083#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2084#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2085
Daniel Drake0fb67e92009-07-16 14:46:57 +01002086static void cxt5066_update_speaker(struct hda_codec *codec)
2087{
2088 struct conexant_spec *spec = codec->spec;
2089 unsigned int pinctl;
2090
John Baboval3a253442010-12-02 11:21:31 -05002091 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2092 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002093
2094 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002095 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002096 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2097 pinctl);
2098
2099 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002100 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2101 if (spec->dell_automute || spec->thinkpad) {
2102 /* Mute if Port A is connected */
2103 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002104 pinctl = 0;
2105 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002106 /* Thinkpad/Dell doesn't give pin-D status */
2107 if (!hp_port_d_present(spec))
2108 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002109 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002110 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2111 pinctl);
2112
2113 /* CLASS_D AMP */
2114 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2115 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2116 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002117}
2118
2119/* turn on/off EAPD (+ mute HP) as a master switch */
2120static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2121 struct snd_ctl_elem_value *ucontrol)
2122{
2123 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2124
2125 if (!cxt_eapd_put(kcontrol, ucontrol))
2126 return 0;
2127
2128 cxt5066_update_speaker(codec);
2129 return 1;
2130}
2131
Daniel Drakec4cfe662010-01-07 13:47:04 +01002132static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2133 .num_items = 3,
2134 .items = {
2135 { "Off", PIN_IN },
2136 { "50%", PIN_VREF50 },
2137 { "80%", PIN_VREF80 },
2138 },
2139};
2140
2141static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2142{
2143 struct conexant_spec *spec = codec->spec;
2144 /* Even though port F is the DC input, the bias is controlled on port B.
2145 * we also leave that port as an active input (but unselected) in DC mode
2146 * just in case that is necessary to make the bias setting take effect. */
2147 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2148 AC_VERB_SET_PIN_WIDGET_CONTROL,
2149 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2150}
2151
Daniel Drake75f89912010-01-07 13:46:25 +01002152/* OLPC defers mic widget control until when capture is started because the
2153 * microphone LED comes on as soon as these settings are put in place. if we
2154 * did this before recording, it would give the false indication that recording
2155 * is happening when it is not. */
2156static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002157{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002158 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002159 if (!spec->recording)
2160 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002161
Daniel Drakec4cfe662010-01-07 13:47:04 +01002162 if (spec->dc_enable) {
2163 /* in DC mode we ignore presence detection and just use the jack
2164 * through our special DC port */
2165 const struct hda_verb enable_dc_mode[] = {
2166 /* disble internal mic, port C */
2167 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2168
2169 /* enable DC capture, port F */
2170 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2171 {},
2172 };
2173
2174 snd_hda_sequence_write(codec, enable_dc_mode);
2175 /* port B input disabled (and bias set) through the following call */
2176 cxt5066_set_olpc_dc_bias(codec);
2177 return;
2178 }
2179
2180 /* disable DC (port F) */
2181 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2182
Daniel Drake75f89912010-01-07 13:46:25 +01002183 /* external mic, port B */
2184 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2185 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002186
Daniel Drake75f89912010-01-07 13:46:25 +01002187 /* internal mic, port C */
2188 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2189 spec->ext_mic_present ? 0 : PIN_VREF80);
2190}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002191
Daniel Drake75f89912010-01-07 13:46:25 +01002192/* toggle input of built-in and mic jack appropriately */
2193static void cxt5066_olpc_automic(struct hda_codec *codec)
2194{
2195 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002196 unsigned int present;
2197
Daniel Drakec4cfe662010-01-07 13:47:04 +01002198 if (spec->dc_enable) /* don't do presence detection in DC mode */
2199 return;
2200
Daniel Drake75f89912010-01-07 13:46:25 +01002201 present = snd_hda_codec_read(codec, 0x1a, 0,
2202 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2203 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002204 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002205 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002206 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002207
2208 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2209 present ? 0 : 1);
2210 spec->ext_mic_present = !!present;
2211
2212 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002213}
2214
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002215/* toggle input of built-in digital mic and mic jack appropriately */
2216static void cxt5066_vostro_automic(struct hda_codec *codec)
2217{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002218 unsigned int present;
2219
2220 struct hda_verb ext_mic_present[] = {
2221 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002222 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002223
2224 /* switch to external mic input */
2225 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2226 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2227
2228 /* disable internal digital mic */
2229 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2230 {}
2231 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002232 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002233 /* enable internal mic, port C */
2234 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2235
2236 /* switch to internal mic input */
2237 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2238
2239 /* disable external mic, port B */
2240 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2241 {}
2242 };
2243
2244 present = snd_hda_jack_detect(codec, 0x1a);
2245 if (present) {
2246 snd_printdd("CXT5066: external microphone detected\n");
2247 snd_hda_sequence_write(codec, ext_mic_present);
2248 } else {
2249 snd_printdd("CXT5066: external microphone absent\n");
2250 snd_hda_sequence_write(codec, ext_mic_absent);
2251 }
2252}
2253
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002254/* toggle input of built-in digital mic and mic jack appropriately */
2255static void cxt5066_ideapad_automic(struct hda_codec *codec)
2256{
2257 unsigned int present;
2258
2259 struct hda_verb ext_mic_present[] = {
2260 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2261 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2262 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2263 {}
2264 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002265 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002266 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2267 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2268 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2269 {}
2270 };
2271
2272 present = snd_hda_jack_detect(codec, 0x1b);
2273 if (present) {
2274 snd_printdd("CXT5066: external microphone detected\n");
2275 snd_hda_sequence_write(codec, ext_mic_present);
2276 } else {
2277 snd_printdd("CXT5066: external microphone absent\n");
2278 snd_hda_sequence_write(codec, ext_mic_absent);
2279 }
2280}
2281
David Henningssona1d69062011-01-21 13:33:28 +01002282
2283/* toggle input of built-in digital mic and mic jack appropriately */
2284static void cxt5066_asus_automic(struct hda_codec *codec)
2285{
2286 unsigned int present;
2287
2288 present = snd_hda_jack_detect(codec, 0x1b);
2289 snd_printdd("CXT5066: external microphone present=%d\n", present);
2290 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2291 present ? 1 : 0);
2292}
2293
2294
David Henningsson048e78a2010-09-02 08:35:47 +02002295/* toggle input of built-in digital mic and mic jack appropriately */
2296static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2297{
2298 unsigned int present;
2299
2300 present = snd_hda_jack_detect(codec, 0x1b);
2301 snd_printdd("CXT5066: external microphone present=%d\n", present);
2302 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2303 present ? 1 : 3);
2304}
2305
2306
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002307/* toggle input of built-in digital mic and mic jack appropriately
2308 order is: external mic -> dock mic -> interal mic */
2309static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2310{
2311 unsigned int ext_present, dock_present;
2312
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002313 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002314 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2315 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2316 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2317 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2318 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2319 {}
2320 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002321 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002322 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2323 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2324 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2325 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2326 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2327 {}
2328 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002329 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002330 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2331 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2332 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2333 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2334 {}
2335 };
2336
2337 ext_present = snd_hda_jack_detect(codec, 0x1b);
2338 dock_present = snd_hda_jack_detect(codec, 0x1a);
2339 if (ext_present) {
2340 snd_printdd("CXT5066: external microphone detected\n");
2341 snd_hda_sequence_write(codec, ext_mic_present);
2342 } else if (dock_present) {
2343 snd_printdd("CXT5066: dock microphone detected\n");
2344 snd_hda_sequence_write(codec, dock_mic_present);
2345 } else {
2346 snd_printdd("CXT5066: external microphone absent\n");
2347 snd_hda_sequence_write(codec, ext_mic_absent);
2348 }
2349}
2350
Daniel Drake0fb67e92009-07-16 14:46:57 +01002351/* mute internal speaker if HP is plugged */
2352static void cxt5066_hp_automute(struct hda_codec *codec)
2353{
2354 struct conexant_spec *spec = codec->spec;
2355 unsigned int portA, portD;
2356
2357 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002358 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359
2360 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002361 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002362
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002363 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2364 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002365 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2366 portA, portD, spec->hp_present);
2367 cxt5066_update_speaker(codec);
2368}
2369
David Henningsson02b6b5b2011-01-21 13:27:39 +01002370/* Dispatch the right mic autoswitch function */
2371static void cxt5066_automic(struct hda_codec *codec)
2372{
2373 struct conexant_spec *spec = codec->spec;
2374
2375 if (spec->dell_vostro)
2376 cxt5066_vostro_automic(codec);
2377 else if (spec->ideapad)
2378 cxt5066_ideapad_automic(codec);
2379 else if (spec->thinkpad)
2380 cxt5066_thinkpad_automic(codec);
2381 else if (spec->hp_laptop)
2382 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002383 else if (spec->asus)
2384 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002385}
2386
Daniel Drake0fb67e92009-07-16 14:46:57 +01002387/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002388static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002389{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002390 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002391 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2392 switch (res >> 26) {
2393 case CONEXANT_HP_EVENT:
2394 cxt5066_hp_automute(codec);
2395 break;
2396 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002397 /* ignore mic events in DC mode; we're always using the jack */
2398 if (!spec->dc_enable)
2399 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002400 break;
2401 }
2402}
2403
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002404/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002405static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002406{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002407 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002408 switch (res >> 26) {
2409 case CONEXANT_HP_EVENT:
2410 cxt5066_hp_automute(codec);
2411 break;
2412 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002413 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002414 break;
2415 }
2416}
2417
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002418
Daniel Drake0fb67e92009-07-16 14:46:57 +01002419static const struct hda_input_mux cxt5066_analog_mic_boost = {
2420 .num_items = 5,
2421 .items = {
2422 { "0dB", 0 },
2423 { "10dB", 1 },
2424 { "20dB", 2 },
2425 { "30dB", 3 },
2426 { "40dB", 4 },
2427 },
2428};
2429
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002430static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002431{
2432 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002433 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002434 AC_VERB_SET_AMP_GAIN_MUTE,
2435 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2436 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002437 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002438 /* adjust the internal mic as well...it is not through 0x17 */
2439 snd_hda_codec_write_cache(codec, 0x23, 0,
2440 AC_VERB_SET_AMP_GAIN_MUTE,
2441 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2442 cxt5066_analog_mic_boost.
2443 items[spec->mic_boost].index);
2444 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002445}
2446
Daniel Drake0fb67e92009-07-16 14:46:57 +01002447static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2448 struct snd_ctl_elem_info *uinfo)
2449{
2450 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2451}
2452
2453static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2454 struct snd_ctl_elem_value *ucontrol)
2455{
2456 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002457 struct conexant_spec *spec = codec->spec;
2458 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002459 return 0;
2460}
2461
2462static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2463 struct snd_ctl_elem_value *ucontrol)
2464{
2465 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002466 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002467 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2468 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002469 idx = ucontrol->value.enumerated.item[0];
2470 if (idx >= imux->num_items)
2471 idx = imux->num_items - 1;
2472
Daniel Drakec4cfe662010-01-07 13:47:04 +01002473 spec->mic_boost = idx;
2474 if (!spec->dc_enable)
2475 cxt5066_set_mic_boost(codec);
2476 return 1;
2477}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002478
Daniel Drakec4cfe662010-01-07 13:47:04 +01002479static void cxt5066_enable_dc(struct hda_codec *codec)
2480{
2481 const struct hda_verb enable_dc_mode[] = {
2482 /* disable gain */
2483 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2484
2485 /* switch to DC input */
2486 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2487 {}
2488 };
2489
2490 /* configure as input source */
2491 snd_hda_sequence_write(codec, enable_dc_mode);
2492 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2493}
2494
2495static void cxt5066_disable_dc(struct hda_codec *codec)
2496{
2497 /* reconfigure input source */
2498 cxt5066_set_mic_boost(codec);
2499 /* automic also selects the right mic if we're recording */
2500 cxt5066_olpc_automic(codec);
2501}
2502
2503static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2504 struct snd_ctl_elem_value *ucontrol)
2505{
2506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2507 struct conexant_spec *spec = codec->spec;
2508 ucontrol->value.integer.value[0] = spec->dc_enable;
2509 return 0;
2510}
2511
2512static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2513 struct snd_ctl_elem_value *ucontrol)
2514{
2515 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2516 struct conexant_spec *spec = codec->spec;
2517 int dc_enable = !!ucontrol->value.integer.value[0];
2518
2519 if (dc_enable == spec->dc_enable)
2520 return 0;
2521
2522 spec->dc_enable = dc_enable;
2523 if (dc_enable)
2524 cxt5066_enable_dc(codec);
2525 else
2526 cxt5066_disable_dc(codec);
2527
2528 return 1;
2529}
2530
2531static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2532 struct snd_ctl_elem_info *uinfo)
2533{
2534 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2535}
2536
2537static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2538 struct snd_ctl_elem_value *ucontrol)
2539{
2540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2541 struct conexant_spec *spec = codec->spec;
2542 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2543 return 0;
2544}
2545
2546static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2548{
2549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550 struct conexant_spec *spec = codec->spec;
2551 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2552 unsigned int idx;
2553
2554 idx = ucontrol->value.enumerated.item[0];
2555 if (idx >= imux->num_items)
2556 idx = imux->num_items - 1;
2557
2558 spec->dc_input_bias = idx;
2559 if (spec->dc_enable)
2560 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002561 return 1;
2562}
2563
Daniel Drake75f89912010-01-07 13:46:25 +01002564static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2565{
2566 struct conexant_spec *spec = codec->spec;
2567 /* mark as recording and configure the microphone widget so that the
2568 * recording LED comes on. */
2569 spec->recording = 1;
2570 cxt5066_olpc_select_mic(codec);
2571}
2572
2573static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2574{
2575 struct conexant_spec *spec = codec->spec;
2576 const struct hda_verb disable_mics[] = {
2577 /* disable external mic, port B */
2578 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2579
2580 /* disble internal mic, port C */
2581 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002582
2583 /* disable DC capture, port F */
2584 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002585 {},
2586 };
2587
2588 snd_hda_sequence_write(codec, disable_mics);
2589 spec->recording = 0;
2590}
2591
Andy Robinsonf6a24912011-01-24 10:12:37 -05002592static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002593 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002594 int num_pins)
2595{
2596 struct conexant_spec *spec = codec->spec;
2597 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2598 int i;
2599
2600 for (i = 0; i < num_pins; i++, dig_pins++) {
2601 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2602 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2603 continue;
2604 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2605 continue;
2606 if (spec->slave_dig_outs[0])
2607 nid_loc++;
2608 else
2609 nid_loc = spec->slave_dig_outs;
2610 }
2611}
2612
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002613static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002614 .num_items = 4,
2615 .items = {
2616 { "Mic B", 0 },
2617 { "Mic C", 1 },
2618 { "Mic E", 2 },
2619 { "Mic F", 3 },
2620 },
2621};
2622
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002623static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002624 .ops = &snd_hda_bind_vol,
2625 .values = {
2626 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2627 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2628 0
2629 },
2630};
2631
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002632static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002633 .ops = &snd_hda_bind_sw,
2634 .values = {
2635 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2636 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2637 0
2638 },
2639};
2640
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002641static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002642 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2643 {}
2644};
2645
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002646static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002647 {
2648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2649 .name = "Master Playback Volume",
2650 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2651 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2652 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002653 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002654 .info = snd_hda_mixer_amp_volume_info,
2655 .get = snd_hda_mixer_amp_volume_get,
2656 .put = snd_hda_mixer_amp_volume_put,
2657 .tlv = { .c = snd_hda_mixer_amp_tlv },
2658 /* offset by 28 volume steps to limit minimum gain to -46dB */
2659 .private_value =
2660 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2661 },
2662 {}
2663};
2664
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002665static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002666 {
2667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2668 .name = "DC Mode Enable Switch",
2669 .info = snd_ctl_boolean_mono_info,
2670 .get = cxt5066_olpc_dc_get,
2671 .put = cxt5066_olpc_dc_put,
2672 },
2673 {
2674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2675 .name = "DC Input Bias Enum",
2676 .info = cxt5066_olpc_dc_bias_enum_info,
2677 .get = cxt5066_olpc_dc_bias_enum_get,
2678 .put = cxt5066_olpc_dc_bias_enum_put,
2679 },
2680 {}
2681};
2682
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002683static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002684 {
2685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686 .name = "Master Playback Switch",
2687 .info = cxt_eapd_info,
2688 .get = cxt_eapd_get,
2689 .put = cxt5066_hp_master_sw_put,
2690 .private_value = 0x1d,
2691 },
2692
2693 {
2694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002695 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002696 .info = cxt5066_mic_boost_mux_enum_info,
2697 .get = cxt5066_mic_boost_mux_enum_get,
2698 .put = cxt5066_mic_boost_mux_enum_put,
2699 },
2700
2701 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2702 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2703 {}
2704};
2705
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002706static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002707 {
2708 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002709 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002710 .info = cxt5066_mic_boost_mux_enum_info,
2711 .get = cxt5066_mic_boost_mux_enum_get,
2712 .put = cxt5066_mic_boost_mux_enum_put,
2713 .private_value = 0x23 | 0x100,
2714 },
2715 {}
2716};
2717
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002718static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002719 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2720 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2721 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2722 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2723
2724 /* Speakers */
2725 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2726 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2727
2728 /* HP, Amp */
2729 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2730 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2731
2732 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2733 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2734
2735 /* DAC1 */
2736 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2737
2738 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2739 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2741 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2742 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2744
2745 /* no digital microphone support yet */
2746 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2747
2748 /* Audio input selector */
2749 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2750
2751 /* SPDIF route: PCM */
2752 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2753 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2754
2755 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2756 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2757
2758 /* EAPD */
2759 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2760
2761 /* not handling these yet */
2762 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2763 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2764 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2765 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2766 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2767 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2768 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2769 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2770 { } /* end */
2771};
2772
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002773static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002774 /* Port A: headphones */
2775 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2776 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2777
2778 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002779 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002780
2781 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002782 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002783
2784 /* Port D: unused */
2785 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2786
2787 /* Port E: unused, but has primary EAPD */
2788 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2789 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2790
Daniel Drakec4cfe662010-01-07 13:47:04 +01002791 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002792 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2793
2794 /* Port G: internal speakers */
2795 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2796 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2797
2798 /* DAC1 */
2799 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2800
2801 /* DAC2: unused */
2802 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2803
2804 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2808 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2809 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2810 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2811 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2812 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2813 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2815 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2816
2817 /* Disable digital microphone port */
2818 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2819
2820 /* Audio input selectors */
2821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2822 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2823
2824 /* Disable SPDIF */
2825 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2827
2828 /* enable unsolicited events for Port A and B */
2829 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2830 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2831 { } /* end */
2832};
2833
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002834static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002835 /* Port A: headphones */
2836 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2837 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2838
2839 /* Port B: external microphone */
2840 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2841
2842 /* Port C: unused */
2843 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2844
2845 /* Port D: unused */
2846 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2847
2848 /* Port E: unused, but has primary EAPD */
2849 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2850 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2851
2852 /* Port F: unused */
2853 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2854
2855 /* Port G: internal speakers */
2856 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2857 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2858
2859 /* DAC1 */
2860 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2861
2862 /* DAC2: unused */
2863 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2864
2865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2866 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2869 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2870 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2871 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2872 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2873 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2874 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2875 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2876 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2877
2878 /* Digital microphone port */
2879 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2880
2881 /* Audio input selectors */
2882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2883 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2884
2885 /* Disable SPDIF */
2886 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2887 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2888
2889 /* enable unsolicited events for Port A and B */
2890 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2891 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2892 { } /* end */
2893};
2894
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002895static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002896 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2897 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2898 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2899 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2900
2901 /* Speakers */
2902 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2903 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2904
2905 /* HP, Amp */
2906 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2907 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2908
2909 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2910 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2911
2912 /* DAC1 */
2913 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2914
2915 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2916 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2917 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2918 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2919 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2920 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2921 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2922
2923 /* Audio input selector */
2924 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2925 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2926
2927 /* SPDIF route: PCM */
2928 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2929 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2930
2931 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2932 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2933
2934 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002935 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002936
2937 /* EAPD */
2938 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2939
2940 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2941 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2942 { } /* end */
2943};
2944
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002945static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002946 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2947 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2948
2949 /* Port G: internal speakers */
2950 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2951 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2952
2953 /* Port A: HP, Amp */
2954 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2955 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2956
2957 /* Port B: Mic Dock */
2958 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2959
2960 /* Port C: Mic */
2961 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2962
2963 /* Port D: HP Dock, Amp */
2964 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2965 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2966
2967 /* DAC1 */
2968 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2969
2970 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2971 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2972 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2973 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2974 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2975 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2976 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2977
2978 /* Audio input selector */
2979 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2980 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2981
2982 /* SPDIF route: PCM */
2983 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2984 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2985
2986 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2987 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2988
2989 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002990 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002991
2992 /* EAPD */
2993 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2994
2995 /* enable unsolicited events for Port A, B, C and D */
2996 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2997 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2998 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2999 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3000 { } /* end */
3001};
3002
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003003static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01003004 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3005 { } /* end */
3006};
3007
David Henningsson048e78a2010-09-02 08:35:47 +02003008
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003009static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02003010 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3011 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3012 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3013 { } /* end */
3014};
3015
Daniel Drake0fb67e92009-07-16 14:46:57 +01003016/* initialize jack-sensing, too */
3017static int cxt5066_init(struct hda_codec *codec)
3018{
3019 snd_printdd("CXT5066: init\n");
3020 conexant_init(codec);
3021 if (codec->patch_ops.unsol_event) {
3022 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003023 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003024 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003025 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003026 return 0;
3027}
3028
Daniel Drake75f89912010-01-07 13:46:25 +01003029static int cxt5066_olpc_init(struct hda_codec *codec)
3030{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003031 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003032 snd_printdd("CXT5066: init\n");
3033 conexant_init(codec);
3034 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003035 if (!spec->dc_enable) {
3036 cxt5066_set_mic_boost(codec);
3037 cxt5066_olpc_automic(codec);
3038 } else {
3039 cxt5066_enable_dc(codec);
3040 }
Daniel Drake75f89912010-01-07 13:46:25 +01003041 return 0;
3042}
3043
Daniel Drake0fb67e92009-07-16 14:46:57 +01003044enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003045 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003046 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3047 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003048 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003049 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003050 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003051 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003052 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003053 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003054 CXT5066_MODELS
3055};
3056
Takashi Iwaiea734962011-01-17 11:29:34 +01003057static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003058 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003059 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3060 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003061 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003062 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003063 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003064 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003065 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003066 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003067};
3068
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003069static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003070 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003071 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003072 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003073 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003074 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003075 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01003076 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3077 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003078 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003079 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01003080 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05003081 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003082 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003083 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003084 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003085 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3086 CXT5066_LAPTOP),
3087 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003088 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003089 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01003090 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
Jerone Youngab854572010-07-19 08:30:58 -05003091 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningsson84012652011-03-31 09:36:19 +02003092 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02003093 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003094 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003095 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003096 {}
3097};
3098
3099static int patch_cxt5066(struct hda_codec *codec)
3100{
3101 struct conexant_spec *spec;
3102 int board_config;
3103
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02003104 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3105 cxt5066_models, cxt5066_cfg_tbl);
3106#if 0 /* use the old method just for safety */
3107 if (board_config < 0)
3108 board_config = CXT5066_AUTO;
3109#endif
3110 if (board_config == CXT5066_AUTO)
3111 return patch_conexant_auto(codec);
3112
Daniel Drake0fb67e92009-07-16 14:46:57 +01003113 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3114 if (!spec)
3115 return -ENOMEM;
3116 codec->spec = spec;
3117
3118 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003119 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003120
3121 spec->dell_automute = 0;
3122 spec->multiout.max_channels = 2;
3123 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3124 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05003125 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3126 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01003127 spec->num_adc_nids = 1;
3128 spec->adc_nids = cxt5066_adc_nids;
3129 spec->capsrc_nids = cxt5066_capsrc_nids;
3130 spec->input_mux = &cxt5066_capture_source;
3131
3132 spec->port_d_mode = PIN_HP;
3133
3134 spec->num_init_verbs = 1;
3135 spec->init_verbs[0] = cxt5066_init_verbs;
3136 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3137 spec->channel_mode = cxt5066_modes;
3138 spec->cur_adc = 0;
3139 spec->cur_adc_idx = 0;
3140
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003141 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3142
Daniel Drake0fb67e92009-07-16 14:46:57 +01003143 switch (board_config) {
3144 default:
3145 case CXT5066_LAPTOP:
3146 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3148 break;
3149 case CXT5066_DELL_LAPTOP:
3150 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3152
3153 spec->port_d_mode = PIN_OUT;
3154 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3155 spec->num_init_verbs++;
3156 spec->dell_automute = 1;
3157 break;
David Henningssona1d69062011-01-21 13:33:28 +01003158 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003159 case CXT5066_HP_LAPTOP:
3160 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003161 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003162 spec->init_verbs[spec->num_init_verbs] =
3163 cxt5066_init_verbs_hp_laptop;
3164 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003165 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3166 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003167 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3168 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3169 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003170 if (board_config == CXT5066_HP_LAPTOP)
3171 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003172 /* input source automatically selected */
3173 spec->input_mux = NULL;
3174 spec->port_d_mode = 0;
3175 spec->mic_boost = 3; /* default 30dB gain */
3176 break;
3177
Daniel Drake0fb67e92009-07-16 14:46:57 +01003178 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003179 codec->patch_ops.init = cxt5066_olpc_init;
3180 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003181 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3182 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003183 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003184 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3185 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003186 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003187
3188 /* no S/PDIF out */
3189 spec->multiout.dig_out_nid = 0;
3190
3191 /* input source automatically selected */
3192 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003193
3194 /* our capture hooks which allow us to turn on the microphone LED
3195 * at the right time */
3196 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3197 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003198 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003199 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003200 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003201 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003202 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3203 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3204 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003205 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003206 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003207 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003208 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003209
3210 /* no S/PDIF out */
3211 spec->multiout.dig_out_nid = 0;
3212
3213 /* input source automatically selected */
3214 spec->input_mux = NULL;
3215 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003216 case CXT5066_IDEAPAD:
3217 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003218 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003219 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3220 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3221 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3222 spec->port_d_mode = 0;
3223 spec->ideapad = 1;
3224 spec->mic_boost = 2; /* default 20dB gain */
3225
3226 /* no S/PDIF out */
3227 spec->multiout.dig_out_nid = 0;
3228
3229 /* input source automatically selected */
3230 spec->input_mux = NULL;
3231 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003232 case CXT5066_THINKPAD:
3233 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003234 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003235 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3236 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3237 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3238 spec->thinkpad = 1;
3239 spec->port_d_mode = PIN_OUT;
3240 spec->mic_boost = 2; /* default 20dB gain */
3241
3242 /* no S/PDIF out */
3243 spec->multiout.dig_out_nid = 0;
3244
3245 /* input source automatically selected */
3246 spec->input_mux = NULL;
3247 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003248 }
3249
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003250 if (spec->beep_amp)
3251 snd_hda_attach_beep_device(codec, spec->beep_amp);
3252
Daniel Drake0fb67e92009-07-16 14:46:57 +01003253 return 0;
3254}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003255
3256/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003257 * Automatic parser for CX20641 & co
3258 */
3259
Takashi Iwai6764bce2011-05-13 16:52:25 +02003260static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3261 struct hda_codec *codec,
3262 unsigned int stream_tag,
3263 unsigned int format,
3264 struct snd_pcm_substream *substream)
3265{
3266 struct conexant_spec *spec = codec->spec;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003267 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003268 if (spec->adc_switching) {
3269 spec->cur_adc = adc;
3270 spec->cur_adc_stream_tag = stream_tag;
3271 spec->cur_adc_format = format;
3272 }
3273 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3274 return 0;
3275}
3276
3277static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3278 struct hda_codec *codec,
3279 struct snd_pcm_substream *substream)
3280{
3281 struct conexant_spec *spec = codec->spec;
3282 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3283 spec->cur_adc = 0;
3284 return 0;
3285}
3286
3287static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3288 .substreams = 1,
3289 .channels_min = 2,
3290 .channels_max = 2,
3291 .nid = 0, /* fill later */
3292 .ops = {
3293 .prepare = cx_auto_capture_pcm_prepare,
3294 .cleanup = cx_auto_capture_pcm_cleanup
3295 },
3296};
3297
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003298static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003299
3300/* get the connection index of @nid in the widget @mux */
3301static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3302 hda_nid_t nid)
3303{
3304 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3305 int i, nums;
3306
3307 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3308 for (i = 0; i < nums; i++)
3309 if (conn[i] == nid)
3310 return i;
3311 return -1;
3312}
3313
3314/* get an unassigned DAC from the given list.
3315 * Return the nid if found and reduce the DAC list, or return zero if
3316 * not found
3317 */
3318static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3319 hda_nid_t *dacs, int *num_dacs)
3320{
3321 int i, nums = *num_dacs;
3322 hda_nid_t ret = 0;
3323
3324 for (i = 0; i < nums; i++) {
3325 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3326 ret = dacs[i];
3327 break;
3328 }
3329 }
3330 if (!ret)
3331 return 0;
3332 if (--nums > 0)
3333 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3334 *num_dacs = nums;
3335 return ret;
3336}
3337
3338#define MAX_AUTO_DACS 5
3339
3340/* fill analog DAC list from the widget tree */
3341static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3342{
3343 hda_nid_t nid, end_nid;
3344 int nums = 0;
3345
3346 end_nid = codec->start_nid + codec->num_nodes;
3347 for (nid = codec->start_nid; nid < end_nid; nid++) {
3348 unsigned int wcaps = get_wcaps(codec, nid);
3349 unsigned int type = get_wcaps_type(wcaps);
3350 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3351 dacs[nums++] = nid;
3352 if (nums >= MAX_AUTO_DACS)
3353 break;
3354 }
3355 }
3356 return nums;
3357}
3358
3359/* fill pin_dac_pair list from the pin and dac list */
3360static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3361 int num_pins, hda_nid_t *dacs, int *rest,
3362 struct pin_dac_pair *filled, int type)
3363{
3364 int i, nums;
3365
3366 nums = 0;
3367 for (i = 0; i < num_pins; i++) {
3368 filled[nums].pin = pins[i];
3369 filled[nums].type = type;
3370 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3371 nums++;
3372 }
3373 return nums;
3374}
3375
3376/* parse analog output paths */
3377static void cx_auto_parse_output(struct hda_codec *codec)
3378{
3379 struct conexant_spec *spec = codec->spec;
3380 struct auto_pin_cfg *cfg = &spec->autocfg;
3381 hda_nid_t dacs[MAX_AUTO_DACS];
3382 int i, j, nums, rest;
3383
3384 rest = fill_cx_auto_dacs(codec, dacs);
3385 /* parse all analog output pins */
3386 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3387 dacs, &rest, spec->dac_info,
3388 AUTO_PIN_LINE_OUT);
3389 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3390 dacs, &rest, spec->dac_info + nums,
3391 AUTO_PIN_HP_OUT);
3392 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3393 dacs, &rest, spec->dac_info + nums,
3394 AUTO_PIN_SPEAKER_OUT);
3395 spec->dac_info_filled = nums;
3396 /* fill multiout struct */
3397 for (i = 0; i < nums; i++) {
3398 hda_nid_t dac = spec->dac_info[i].dac;
3399 if (!dac)
3400 continue;
3401 switch (spec->dac_info[i].type) {
3402 case AUTO_PIN_LINE_OUT:
3403 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3404 spec->multiout.num_dacs++;
3405 break;
3406 case AUTO_PIN_HP_OUT:
3407 case AUTO_PIN_SPEAKER_OUT:
3408 if (!spec->multiout.hp_nid) {
3409 spec->multiout.hp_nid = dac;
3410 break;
3411 }
3412 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3413 if (!spec->multiout.extra_out_nid[j]) {
3414 spec->multiout.extra_out_nid[j] = dac;
3415 break;
3416 }
3417 break;
3418 }
3419 }
3420 spec->multiout.dac_nids = spec->private_dac_nids;
David Henningsson89724952011-02-16 21:34:04 +01003421 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003422
3423 if (cfg->hp_outs > 0)
3424 spec->auto_mute = 1;
3425 spec->vmaster_nid = spec->private_dac_nids[0];
3426}
3427
Takashi Iwaida339862011-05-13 16:24:15 +02003428static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3429 hda_nid_t *pins, bool on);
3430
Takashi Iwaif2e57312010-09-15 10:07:08 +02003431/* auto-mute/unmute speaker and line outs according to headphone jack */
3432static void cx_auto_hp_automute(struct hda_codec *codec)
3433{
3434 struct conexant_spec *spec = codec->spec;
3435 struct auto_pin_cfg *cfg = &spec->autocfg;
3436 int i, present;
3437
3438 if (!spec->auto_mute)
3439 return;
3440 present = 0;
3441 for (i = 0; i < cfg->hp_outs; i++) {
3442 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3443 present = 1;
3444 break;
3445 }
3446 }
Takashi Iwaida339862011-05-13 16:24:15 +02003447 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003448 for (i = 0; i < cfg->line_outs; i++) {
3449 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3450 AC_VERB_SET_PIN_WIDGET_CONTROL,
3451 present ? 0 : PIN_OUT);
3452 }
Takashi Iwaida339862011-05-13 16:24:15 +02003453 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003454 for (i = 0; !present && i < cfg->line_outs; i++)
3455 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3456 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003457 for (i = 0; i < cfg->speaker_outs; i++) {
3458 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3459 AC_VERB_SET_PIN_WIDGET_CONTROL,
3460 present ? 0 : PIN_OUT);
3461 }
Takashi Iwaida339862011-05-13 16:24:15 +02003462 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003463}
3464
Takashi Iwai6764bce2011-05-13 16:52:25 +02003465static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3466 struct snd_ctl_elem_info *uinfo)
3467{
3468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3469 struct conexant_spec *spec = codec->spec;
3470
3471 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3472}
3473
3474static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3475 struct snd_ctl_elem_value *ucontrol)
3476{
3477 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3478 struct conexant_spec *spec = codec->spec;
3479
3480 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3481 return 0;
3482}
3483
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003484/* look for the route the given pin from mux and return the index;
3485 * if do_select is set, actually select the route.
3486 */
3487static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
Takashi Iwaicf27f292011-05-16 11:33:02 +02003488 hda_nid_t pin, hda_nid_t *srcp,
3489 bool do_select, int depth)
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003490{
3491 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3492 int i, nums;
3493
Takashi Iwaicf27f292011-05-16 11:33:02 +02003494 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3495 case AC_WID_AUD_IN:
3496 case AC_WID_AUD_SEL:
3497 case AC_WID_AUD_MIX:
3498 break;
3499 default:
3500 return -1;
3501 }
3502
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003503 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3504 for (i = 0; i < nums; i++)
3505 if (conn[i] == pin) {
3506 if (do_select)
3507 snd_hda_codec_write(codec, mux, 0,
3508 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003509 if (srcp)
3510 *srcp = mux;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003511 return i;
3512 }
3513 depth++;
3514 if (depth == 2)
3515 return -1;
3516 for (i = 0; i < nums; i++) {
Takashi Iwaicf27f292011-05-16 11:33:02 +02003517 int ret = __select_input_connection(codec, conn[i], pin, srcp,
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003518 do_select, depth);
3519 if (ret >= 0) {
3520 if (do_select)
3521 snd_hda_codec_write(codec, mux, 0,
3522 AC_VERB_SET_CONNECT_SEL, i);
Takashi Iwaicf27f292011-05-16 11:33:02 +02003523 return i;
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003524 }
3525 }
3526 return -1;
3527}
3528
3529static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3530 hda_nid_t pin)
3531{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003532 __select_input_connection(codec, mux, pin, NULL, true, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003533}
3534
3535static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3536 hda_nid_t pin)
3537{
Takashi Iwaicf27f292011-05-16 11:33:02 +02003538 return __select_input_connection(codec, mux, pin, NULL, false, 0);
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003539}
3540
Takashi Iwai6764bce2011-05-13 16:52:25 +02003541static int cx_auto_mux_enum_update(struct hda_codec *codec,
3542 const struct hda_input_mux *imux,
3543 unsigned int idx)
3544{
3545 struct conexant_spec *spec = codec->spec;
3546 hda_nid_t adc;
3547
3548 if (!imux->num_items)
3549 return 0;
3550 if (idx >= imux->num_items)
3551 idx = imux->num_items - 1;
3552 if (spec->cur_mux[0] == idx)
3553 return 0;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003554 adc = spec->imux_info[idx].adc;
3555 select_input_connection(codec, spec->imux_info[idx].adc,
3556 spec->imux_info[idx].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003557 if (spec->cur_adc && spec->cur_adc != adc) {
3558 /* stream is running, let's swap the current ADC */
3559 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3560 spec->cur_adc = adc;
3561 snd_hda_codec_setup_stream(codec, adc,
3562 spec->cur_adc_stream_tag, 0,
3563 spec->cur_adc_format);
3564 }
3565 spec->cur_mux[0] = idx;
3566 return 1;
3567}
3568
3569static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3570 struct snd_ctl_elem_value *ucontrol)
3571{
3572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3573 struct conexant_spec *spec = codec->spec;
3574
3575 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3576 ucontrol->value.enumerated.item[0]);
3577}
3578
3579static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3580 {
3581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3582 .name = "Capture Source",
3583 .info = cx_auto_mux_enum_info,
3584 .get = cx_auto_mux_enum_get,
3585 .put = cx_auto_mux_enum_put
3586 },
3587 {}
3588};
3589
Takashi Iwaif2e57312010-09-15 10:07:08 +02003590/* automatic switch internal and external mic */
3591static void cx_auto_automic(struct hda_codec *codec)
3592{
3593 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003594 int ext_idx = spec->auto_mic_ext;
3595
3596 if (!spec->auto_mic)
3597 return;
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003598 if (snd_hda_jack_detect(codec, spec->imux_info[ext_idx].pin))
Takashi Iwai6764bce2011-05-13 16:52:25 +02003599 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3600 else
3601 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003602}
3603
3604static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3605{
3606 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3607 switch (res >> 26) {
3608 case CONEXANT_HP_EVENT:
3609 cx_auto_hp_automute(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003610 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003611 break;
3612 case CONEXANT_MIC_EVENT:
3613 cx_auto_automic(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01003614 snd_hda_input_jack_report(codec, nid);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003615 break;
3616 }
3617}
3618
Takashi Iwaif2e57312010-09-15 10:07:08 +02003619/* return true if it's an internal-mic pin */
3620static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3621{
3622 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3623 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003624 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003625}
3626
3627/* return true if it's an external-mic pin */
3628static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3629{
3630 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3631 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003632 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3633 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003634}
3635
3636/* check whether the pin config is suitable for auto-mic switching;
3637 * auto-mic is enabled only when one int-mic and one-ext mic exist
3638 */
3639static void cx_auto_check_auto_mic(struct hda_codec *codec)
3640{
3641 struct conexant_spec *spec = codec->spec;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003642
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003643 if (is_ext_mic(codec, spec->imux_info[0].pin) &&
3644 is_int_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 = 0;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003647 return;
3648 }
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003649 if (is_int_mic(codec, spec->imux_info[0].pin) &&
3650 is_ext_mic(codec, spec->imux_info[1].pin)) {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003651 spec->auto_mic = 1;
Takashi Iwai2557f742011-05-13 16:18:37 +02003652 spec->auto_mic_ext = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003653 return;
3654 }
3655}
3656
3657static void cx_auto_parse_input(struct hda_codec *codec)
3658{
3659 struct conexant_spec *spec = codec->spec;
3660 struct auto_pin_cfg *cfg = &spec->autocfg;
3661 struct hda_input_mux *imux;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003662 int i, j;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003663
3664 imux = &spec->private_imux;
3665 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003666 for (j = 0; j < spec->num_adc_nids; j++) {
3667 hda_nid_t adc = spec->adc_nids[j];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02003668 int idx = get_input_connection(codec, adc,
3669 cfg->inputs[i].pin);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003670 if (idx >= 0) {
3671 const char *label;
3672 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003673 spec->imux_info[imux->num_items].index = i;
3674 spec->imux_info[imux->num_items].boost = 0;
3675 spec->imux_info[imux->num_items].adc = adc;
3676 spec->imux_info[imux->num_items].pin =
Takashi Iwaif6100bb2011-05-13 18:26:39 +02003677 cfg->inputs[i].pin;
Takashi Iwai6764bce2011-05-13 16:52:25 +02003678 snd_hda_add_imux_item(imux, label, idx, NULL);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003679 break;
3680 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003681 }
3682 }
3683 if (imux->num_items == 2 && cfg->num_inputs == 2)
3684 cx_auto_check_auto_mic(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02003685 if (imux->num_items > 1 && !spec->auto_mic) {
3686 for (i = 1; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003687 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
Takashi Iwai6764bce2011-05-13 16:52:25 +02003688 spec->adc_switching = 1;
3689 break;
3690 }
3691 }
3692 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003693}
3694
3695/* get digital-input audio widget corresponding to the given pin */
3696static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3697{
3698 hda_nid_t nid, end_nid;
3699
3700 end_nid = codec->start_nid + codec->num_nodes;
3701 for (nid = codec->start_nid; nid < end_nid; nid++) {
3702 unsigned int wcaps = get_wcaps(codec, nid);
3703 unsigned int type = get_wcaps_type(wcaps);
3704 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3705 if (get_connection_index(codec, nid, pin) >= 0)
3706 return nid;
3707 }
3708 }
3709 return 0;
3710}
3711
3712static void cx_auto_parse_digital(struct hda_codec *codec)
3713{
3714 struct conexant_spec *spec = codec->spec;
3715 struct auto_pin_cfg *cfg = &spec->autocfg;
3716 hda_nid_t nid;
3717
3718 if (cfg->dig_outs &&
3719 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3720 spec->multiout.dig_out_nid = nid;
3721 if (cfg->dig_in_pin)
3722 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3723}
3724
3725#ifdef CONFIG_SND_HDA_INPUT_BEEP
3726static void cx_auto_parse_beep(struct hda_codec *codec)
3727{
3728 struct conexant_spec *spec = codec->spec;
3729 hda_nid_t nid, end_nid;
3730
3731 end_nid = codec->start_nid + codec->num_nodes;
3732 for (nid = codec->start_nid; nid < end_nid; nid++)
3733 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3734 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3735 break;
3736 }
3737}
3738#else
3739#define cx_auto_parse_beep(codec)
3740#endif
3741
3742static int cx_auto_parse_auto_config(struct hda_codec *codec)
3743{
3744 struct conexant_spec *spec = codec->spec;
3745 int err;
3746
3747 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3748 if (err < 0)
3749 return err;
3750
3751 cx_auto_parse_output(codec);
3752 cx_auto_parse_input(codec);
3753 cx_auto_parse_digital(codec);
3754 cx_auto_parse_beep(codec);
3755 return 0;
3756}
3757
Takashi Iwaida339862011-05-13 16:24:15 +02003758static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3759 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003760{
3761 int i;
3762 for (i = 0; i < num_pins; i++) {
3763 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3764 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003765 AC_VERB_SET_EAPD_BTLENABLE,
3766 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003767 }
3768}
3769
3770static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3771 hda_nid_t src)
3772{
3773 int idx = get_connection_index(codec, pin, src);
3774 if (idx >= 0)
3775 snd_hda_codec_write(codec, pin, 0,
3776 AC_VERB_SET_CONNECT_SEL, idx);
3777}
3778
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003779static void mute_outputs(struct hda_codec *codec, int num_nids,
3780 const hda_nid_t *nids)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003781{
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003782 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003783
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003784 for (i = 0; i < num_nids; i++) {
3785 hda_nid_t nid = nids[i];
3786 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3787 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003788 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3789 val = AMP_OUT_MUTE;
3790 else
3791 val = AMP_OUT_ZERO;
3792 snd_hda_codec_write(codec, nid, 0,
3793 AC_VERB_SET_AMP_GAIN_MUTE, val);
3794 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003795}
Takashi Iwaif2e57312010-09-15 10:07:08 +02003796
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003797static void cx_auto_init_output(struct hda_codec *codec)
3798{
3799 struct conexant_spec *spec = codec->spec;
3800 struct auto_pin_cfg *cfg = &spec->autocfg;
3801 hda_nid_t nid;
3802 int i;
3803
3804 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003805 for (i = 0; i < cfg->hp_outs; i++)
3806 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3807 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003808 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3809 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3810 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003811 if (spec->auto_mute) {
3812 for (i = 0; i < cfg->hp_outs; i++) {
3813 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3814 AC_VERB_SET_UNSOLICITED_ENABLE,
3815 AC_USRSP_EN | CONEXANT_HP_EVENT);
3816 }
3817 cx_auto_hp_automute(codec);
3818 } else {
3819 for (i = 0; i < cfg->line_outs; i++)
3820 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3821 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3822 for (i = 0; i < cfg->speaker_outs; i++)
3823 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3824 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
Takashi Iwaida339862011-05-13 16:24:15 +02003825 /* turn on EAPD */
3826 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3827 true);
3828 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3829 true);
3830 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3831 true);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003832 }
3833
3834 for (i = 0; i < spec->dac_info_filled; i++) {
3835 nid = spec->dac_info[i].dac;
3836 if (!nid)
3837 nid = spec->multiout.dac_nids[0];
3838 select_connection(codec, spec->dac_info[i].pin, nid);
3839 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003840}
3841
3842static void cx_auto_init_input(struct hda_codec *codec)
3843{
3844 struct conexant_spec *spec = codec->spec;
3845 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003846 int i, val;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003847
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003848 for (i = 0; i < spec->num_adc_nids; i++) {
3849 hda_nid_t nid = spec->adc_nids[i];
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003850 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3851 continue;
Takashi Iwai0ad1b5b2011-05-13 16:43:12 +02003852 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3853 val = AMP_IN_MUTE(0);
3854 else
3855 val = AMP_IN_UNMUTE(0);
3856 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3857 val);
3858 }
Takashi Iwaif2e57312010-09-15 10:07:08 +02003859
3860 for (i = 0; i < cfg->num_inputs; i++) {
3861 unsigned int type;
3862 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3863 type = PIN_VREF80;
3864 else
3865 type = PIN_IN;
3866 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3867 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3868 }
3869
3870 if (spec->auto_mic) {
3871 int ext_idx = spec->auto_mic_ext;
3872 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3873 AC_VERB_SET_UNSOLICITED_ENABLE,
3874 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3875 cx_auto_automic(codec);
3876 } else {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02003877 select_input_connection(codec, spec->imux_info[0].adc,
3878 spec->imux_info[0].pin);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003879 }
3880}
3881
3882static void cx_auto_init_digital(struct hda_codec *codec)
3883{
3884 struct conexant_spec *spec = codec->spec;
3885 struct auto_pin_cfg *cfg = &spec->autocfg;
3886
3887 if (spec->multiout.dig_out_nid)
3888 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3889 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3890 if (spec->dig_in_nid)
3891 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3892 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3893}
3894
3895static int cx_auto_init(struct hda_codec *codec)
3896{
3897 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3898 cx_auto_init_output(codec);
3899 cx_auto_init_input(codec);
3900 cx_auto_init_digital(codec);
3901 return 0;
3902}
3903
David Henningsson983345e2011-02-15 19:57:09 +01003904static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003905 const char *dir, int cidx,
David Henningsson983345e2011-02-15 19:57:09 +01003906 hda_nid_t nid, int hda_dir, int amp_idx)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003907{
3908 static char name[32];
3909 static struct snd_kcontrol_new knew[] = {
3910 HDA_CODEC_VOLUME(name, 0, 0, 0),
3911 HDA_CODEC_MUTE(name, 0, 0, 0),
3912 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003913 static const char * const sfx[2] = { "Volume", "Switch" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003914 int i, err;
3915
3916 for (i = 0; i < 2; i++) {
3917 struct snd_kcontrol *kctl;
David Henningsson983345e2011-02-15 19:57:09 +01003918 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3919 hda_dir);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003920 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3921 knew[i].index = cidx;
3922 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3923 kctl = snd_ctl_new1(&knew[i], codec);
3924 if (!kctl)
3925 return -ENOMEM;
3926 err = snd_hda_ctl_add(codec, nid, kctl);
3927 if (err < 0)
3928 return err;
3929 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3930 break;
3931 }
3932 return 0;
3933}
3934
David Henningsson983345e2011-02-15 19:57:09 +01003935#define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3936 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3937
Takashi Iwaif2e57312010-09-15 10:07:08 +02003938#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3939 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3940
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003941static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3942 hda_nid_t pin, const char *name, int idx)
3943{
3944 unsigned int caps;
3945 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3946 if (caps & AC_AMPCAP_NUM_STEPS)
3947 return cx_auto_add_pb_volume(codec, dac, name, idx);
3948 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3949 if (caps & AC_AMPCAP_NUM_STEPS)
3950 return cx_auto_add_pb_volume(codec, pin, name, idx);
3951 return 0;
3952}
3953
Takashi Iwaif2e57312010-09-15 10:07:08 +02003954static int cx_auto_build_output_controls(struct hda_codec *codec)
3955{
3956 struct conexant_spec *spec = codec->spec;
3957 int i, err;
3958 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003959 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003960
3961 if (spec->dac_info_filled == 1)
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003962 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3963 spec->dac_info[0].pin,
3964 "Master", 0);
3965
Takashi Iwaif2e57312010-09-15 10:07:08 +02003966 for (i = 0; i < spec->dac_info_filled; i++) {
3967 const char *label;
3968 int idx, type;
3969 if (!spec->dac_info[i].dac)
3970 continue;
3971 type = spec->dac_info[i].type;
3972 if (type == AUTO_PIN_LINE_OUT)
3973 type = spec->autocfg.line_out_type;
3974 switch (type) {
3975 case AUTO_PIN_LINE_OUT:
3976 default:
3977 label = texts[num_line++];
3978 idx = 0;
3979 break;
3980 case AUTO_PIN_HP_OUT:
3981 label = "Headphone";
3982 idx = num_hp++;
3983 break;
3984 case AUTO_PIN_SPEAKER_OUT:
3985 label = "Speaker";
3986 idx = num_spk++;
3987 break;
3988 }
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003989 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3990 spec->dac_info[i].pin,
3991 label, idx);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003992 if (err < 0)
3993 return err;
3994 }
3995 return 0;
3996}
3997
Takashi Iwai6764bce2011-05-13 16:52:25 +02003998static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3999 const char *label, const char *pfx,
4000 int cidx)
4001{
4002 struct conexant_spec *spec = codec->spec;
4003 int i;
4004
4005 for (i = 0; i < spec->num_adc_nids; i++) {
4006 hda_nid_t adc_nid = spec->adc_nids[i];
Takashi Iwai5c9887e2011-05-13 18:36:37 +02004007 int idx = get_input_connection(codec, adc_nid, nid);
Takashi Iwai6764bce2011-05-13 16:52:25 +02004008 if (idx < 0)
4009 continue;
4010 return cx_auto_add_volume_idx(codec, label, pfx,
4011 cidx, adc_nid, HDA_INPUT, idx);
4012 }
4013 return 0;
4014}
4015
Takashi Iwaicf27f292011-05-16 11:33:02 +02004016static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4017 const char *label, int cidx)
4018{
4019 struct conexant_spec *spec = codec->spec;
4020 hda_nid_t mux, nid;
Takashi Iwaif9759302011-05-16 11:45:15 +02004021 int i, con;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004022
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004023 nid = spec->imux_info[idx].pin;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004024 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4025 return cx_auto_add_volume(codec, label, " Boost", cidx,
4026 nid, HDA_INPUT);
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004027 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4028 &mux, false, 0);
Takashi Iwaicf27f292011-05-16 11:33:02 +02004029 if (con < 0)
4030 return 0;
Takashi Iwaif9759302011-05-16 11:45:15 +02004031 for (i = 0; i < idx; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004032 if (spec->imux_info[i].boost == mux)
Takashi Iwaif9759302011-05-16 11:45:15 +02004033 return 0; /* already present */
4034 }
4035
4036 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004037 spec->imux_info[idx].boost = mux;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004038 return cx_auto_add_volume(codec, label, " Boost", 0,
4039 mux, HDA_OUTPUT);
Takashi Iwaif9759302011-05-16 11:45:15 +02004040 }
Takashi Iwaicf27f292011-05-16 11:33:02 +02004041 return 0;
4042}
4043
Takashi Iwaif2e57312010-09-15 10:07:08 +02004044static int cx_auto_build_input_controls(struct hda_codec *codec)
4045{
4046 struct conexant_spec *spec = codec->spec;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004047 struct hda_input_mux *imux = &spec->private_imux;
4048 const char *prev_label;
4049 int input_conn[HDA_MAX_NUM_INPUTS];
Takashi Iwai6764bce2011-05-13 16:52:25 +02004050 int i, err, cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004051 int multi_connection;
4052
4053 multi_connection = 0;
4054 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004055 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4056 spec->imux_info[i].pin);
4057 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004058 if (i > 0 && input_conn[i] != input_conn[0])
4059 multi_connection = 1;
4060 }
David Henningsson983345e2011-02-15 19:57:09 +01004061
Takashi Iwaif2e57312010-09-15 10:07:08 +02004062 prev_label = NULL;
4063 cidx = 0;
Takashi Iwaicf27f292011-05-16 11:33:02 +02004064 for (i = 0; i < imux->num_items; i++) {
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004065 hda_nid_t nid = spec->imux_info[i].pin;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004066 const char *label;
David Henningsson983345e2011-02-15 19:57:09 +01004067
Takashi Iwaicf27f292011-05-16 11:33:02 +02004068 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
Takashi Iwai47ad1f42011-05-17 09:15:55 +02004069 spec->imux_info[i].index);
Takashi Iwaif2e57312010-09-15 10:07:08 +02004070 if (label == prev_label)
4071 cidx++;
4072 else
4073 cidx = 0;
4074 prev_label = label;
David Henningsson983345e2011-02-15 19:57:09 +01004075
Takashi Iwaicf27f292011-05-16 11:33:02 +02004076 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4077 if (err < 0)
4078 return err;
David Henningsson983345e2011-02-15 19:57:09 +01004079
Takashi Iwaicf27f292011-05-16 11:33:02 +02004080 if (!multi_connection) {
Takashi Iwaif9759302011-05-16 11:45:15 +02004081 if (i > 0)
4082 continue;
Takashi Iwai6764bce2011-05-13 16:52:25 +02004083 err = cx_auto_add_capture_volume(codec, nid,
4084 "Capture", "", cidx);
4085 } else {
4086 err = cx_auto_add_capture_volume(codec, nid,
4087 label, " Capture", cidx);
David Henningsson983345e2011-02-15 19:57:09 +01004088 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004089 if (err < 0)
4090 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004091 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004092
4093 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4094 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4095 if (err < 0)
4096 return err;
4097 }
4098
Takashi Iwaif2e57312010-09-15 10:07:08 +02004099 return 0;
4100}
4101
4102static int cx_auto_build_controls(struct hda_codec *codec)
4103{
4104 int err;
4105
4106 err = cx_auto_build_output_controls(codec);
4107 if (err < 0)
4108 return err;
4109 err = cx_auto_build_input_controls(codec);
4110 if (err < 0)
4111 return err;
4112 return conexant_build_controls(codec);
4113}
4114
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004115static int cx_auto_search_adcs(struct hda_codec *codec)
4116{
4117 struct conexant_spec *spec = codec->spec;
4118 hda_nid_t nid, end_nid;
4119
4120 end_nid = codec->start_nid + codec->num_nodes;
4121 for (nid = codec->start_nid; nid < end_nid; nid++) {
4122 unsigned int caps = get_wcaps(codec, nid);
4123 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4124 continue;
4125 if (caps & AC_WCAP_DIGITAL)
4126 continue;
4127 if (snd_BUG_ON(spec->num_adc_nids >=
4128 ARRAY_SIZE(spec->private_adc_nids)))
4129 break;
4130 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4131 }
4132 spec->adc_nids = spec->private_adc_nids;
4133 return 0;
4134}
4135
4136
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004137static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02004138 .build_controls = cx_auto_build_controls,
4139 .build_pcms = conexant_build_pcms,
4140 .init = cx_auto_init,
4141 .free = conexant_free,
4142 .unsol_event = cx_auto_unsol_event,
4143#ifdef CONFIG_SND_HDA_POWER_SAVE
4144 .suspend = conexant_suspend,
4145#endif
4146 .reboot_notify = snd_hda_shutup_pins,
4147};
4148
4149static int patch_conexant_auto(struct hda_codec *codec)
4150{
4151 struct conexant_spec *spec;
4152 int err;
4153
Takashi Iwai1f8458a2011-05-13 17:22:05 +02004154 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4155 codec->chip_name);
4156
Takashi Iwaif2e57312010-09-15 10:07:08 +02004157 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4158 if (!spec)
4159 return -ENOMEM;
4160 codec->spec = spec;
Takashi Iwai1387cde2011-05-15 12:21:20 +02004161 codec->pin_amp_workaround = 1;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02004162 err = cx_auto_search_adcs(codec);
4163 if (err < 0)
4164 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004165 err = cx_auto_parse_auto_config(codec);
4166 if (err < 0) {
4167 kfree(codec->spec);
4168 codec->spec = NULL;
4169 return err;
4170 }
Takashi Iwai6764bce2011-05-13 16:52:25 +02004171 spec->capture_stream = &cx_auto_pcm_analog_capture;
Takashi Iwaif2e57312010-09-15 10:07:08 +02004172 codec->patch_ops = cx_auto_patch_ops;
4173 if (spec->beep_amp)
4174 snd_hda_attach_beep_device(codec, spec->beep_amp);
4175 return 0;
4176}
4177
4178/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01004179 */
4180
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02004181static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01004182 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4183 .patch = patch_cxt5045 },
4184 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4185 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01004186 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4187 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01004188 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4189 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004190 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4191 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02004192 { .id = 0x14f15068, .name = "CX20584",
4193 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004194 { .id = 0x14f15069, .name = "CX20585",
4195 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01004196 { .id = 0x14f1506e, .name = "CX20590",
4197 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02004198 { .id = 0x14f15097, .name = "CX20631",
4199 .patch = patch_conexant_auto },
4200 { .id = 0x14f15098, .name = "CX20632",
4201 .patch = patch_conexant_auto },
4202 { .id = 0x14f150a1, .name = "CX20641",
4203 .patch = patch_conexant_auto },
4204 { .id = 0x14f150a2, .name = "CX20642",
4205 .patch = patch_conexant_auto },
4206 { .id = 0x14f150ab, .name = "CX20651",
4207 .patch = patch_conexant_auto },
4208 { .id = 0x14f150ac, .name = "CX20652",
4209 .patch = patch_conexant_auto },
4210 { .id = 0x14f150b8, .name = "CX20664",
4211 .patch = patch_conexant_auto },
4212 { .id = 0x14f150b9, .name = "CX20665",
4213 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01004214 {} /* terminator */
4215};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004216
4217MODULE_ALIAS("snd-hda-codec-id:14f15045");
4218MODULE_ALIAS("snd-hda-codec-id:14f15047");
4219MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01004220MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02004221MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02004222MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02004223MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningsson6da8b512011-02-08 07:16:06 +01004224MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02004225MODULE_ALIAS("snd-hda-codec-id:14f15097");
4226MODULE_ALIAS("snd-hda-codec-id:14f15098");
4227MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4228MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4229MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4230MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4231MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4232MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004233
4234MODULE_LICENSE("GPL");
4235MODULE_DESCRIPTION("Conexant HD-audio codec");
4236
4237static struct hda_codec_preset_list conexant_list = {
4238 .preset = snd_hda_preset_conexant,
4239 .owner = THIS_MODULE,
4240};
4241
4242static int __init patch_conexant_init(void)
4243{
4244 return snd_hda_add_codec_preset(&conexant_list);
4245}
4246
4247static void __exit patch_conexant_exit(void)
4248{
4249 snd_hda_delete_codec_preset(&conexant_list);
4250}
4251
4252module_init(patch_conexant_init)
4253module_exit(patch_conexant_exit)