blob: 549964395770ef9a517948bfc046e01a8cc5b8f9 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Tobin Davisc9b443d2006-11-14 12:13:39 +010028#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010029#include <sound/jack.h>
30
Tobin Davisc9b443d2006-11-14 12:13:39 +010031#include "hda_codec.h"
32#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020033#include "hda_auto_parser.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020034#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020035#include "hda_jack.h"
Takashi Iwaiaed523f2012-12-20 16:34:12 +010036#include "hda_generic.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010037
Takashi Iwaibf92d1d2012-12-20 16:38:19 +010038#define ENABLE_CXT_STATIC_QUIRKS
Tobin Davisc9b443d2006-11-14 12:13:39 +010039
40#define CXT_PIN_DIR_IN 0x00
41#define CXT_PIN_DIR_OUT 0x01
42#define CXT_PIN_DIR_INOUT 0x02
43#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
44#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
45
46#define CONEXANT_HP_EVENT 0x37
47#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020048#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010049
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010050/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010051
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010052#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010053#define CXT5051_PORTB_EVENT 0x38
54#define CXT5051_PORTC_EVENT 0x39
55
Takashi Iwaifaddaa52010-01-23 22:31:36 +010056#define AUTO_MIC_PORTB (1 << 1)
57#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010058
Tobin Davisc9b443d2006-11-14 12:13:39 +010059struct conexant_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +020060 struct hda_gen_spec gen;
Tobin Davisc9b443d2006-11-14 12:13:39 +010061
Takashi Iwaibf92d1d2012-12-20 16:38:19 +010062 unsigned int beep_amp;
63
64 /* extra EAPD pins */
65 unsigned int num_eapds;
66 hda_nid_t eapds[4];
67
68#ifdef ENABLE_CXT_STATIC_QUIRKS
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020069 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010070 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010071 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010072
73 const struct hda_verb *init_verbs[5]; /* initialization verbs
74 * don't forget NULL
75 * termination!
76 */
77 unsigned int num_init_verbs;
78
79 /* playback */
80 struct hda_multi_out multiout; /* playback set-up
81 * max_channels, dacs must be set
82 * dig_out_nid and hp_nid are optional
83 */
84 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010085 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020086 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010087 unsigned int auto_mic;
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
Daniel Drake0fb67e92009-07-16 14:46:57 +0100115 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200116 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500117 unsigned int dell_vostro:1;
118 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200119 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200120 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100121 unsigned int asus:1;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200122
Daniel Drake75f89912010-01-07 13:46:25 +0100123 unsigned int ext_mic_present;
124 unsigned int recording;
125 void (*capture_prepare)(struct hda_codec *codec);
126 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100127
128 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
129 * through the microphone jack.
130 * When the user enables this through a mixer switch, both internal and
131 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
132 * we also allow the bias to be configured through a separate mixer
133 * control. */
134 unsigned int dc_enable;
135 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
136 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwaibf92d1d2012-12-20 16:38:19 +0100137#endif /* ENABLE_CXT_STATIC_QUIRKS */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100138};
139
Takashi Iwaibf92d1d2012-12-20 16:38:19 +0100140
141#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100142static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
143 int idx, int dir)
144{
145 spec->gen.beep_nid = nid;
146 spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
147}
Takashi Iwaibf92d1d2012-12-20 16:38:19 +0100148/* additional beep mixers; the actual parameters are overwritten at build */
149static const struct snd_kcontrol_new cxt_beep_mixer[] = {
150 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
151 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
152 { } /* end */
153};
154
155/* create beep controls if needed */
156static int add_beep_ctls(struct hda_codec *codec)
157{
158 struct conexant_spec *spec = codec->spec;
159 int err;
160
161 if (spec->beep_amp) {
162 const struct snd_kcontrol_new *knew;
163 for (knew = cxt_beep_mixer; knew->name; knew++) {
164 struct snd_kcontrol *kctl;
165 kctl = snd_ctl_new1(knew, codec);
166 if (!kctl)
167 return -ENOMEM;
168 kctl->private_value = spec->beep_amp;
169 err = snd_hda_ctl_add(codec, 0, kctl);
170 if (err < 0)
171 return err;
172 }
173 }
174 return 0;
175}
176#else
177#define set_beep_amp(spec, nid, idx, dir) /* NOP */
178#define add_beep_ctls(codec) 0
179#endif
180
181
182#ifdef ENABLE_CXT_STATIC_QUIRKS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100183static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 struct snd_pcm_substream *substream)
186{
187 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100188 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
189 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100190}
191
192static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
193 struct hda_codec *codec,
194 unsigned int stream_tag,
195 unsigned int format,
196 struct snd_pcm_substream *substream)
197{
198 struct conexant_spec *spec = codec->spec;
199 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
200 stream_tag,
201 format, substream);
202}
203
204static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
205 struct hda_codec *codec,
206 struct snd_pcm_substream *substream)
207{
208 struct conexant_spec *spec = codec->spec;
209 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
210}
211
212/*
213 * Digital out
214 */
215static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
216 struct hda_codec *codec,
217 struct snd_pcm_substream *substream)
218{
219 struct conexant_spec *spec = codec->spec;
220 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
221}
222
223static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
224 struct hda_codec *codec,
225 struct snd_pcm_substream *substream)
226{
227 struct conexant_spec *spec = codec->spec;
228 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
229}
230
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200231static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
232 struct hda_codec *codec,
233 unsigned int stream_tag,
234 unsigned int format,
235 struct snd_pcm_substream *substream)
236{
237 struct conexant_spec *spec = codec->spec;
238 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
239 stream_tag,
240 format, substream);
241}
242
Tobin Davisc9b443d2006-11-14 12:13:39 +0100243/*
244 * Analog capture
245 */
246static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
247 struct hda_codec *codec,
248 unsigned int stream_tag,
249 unsigned int format,
250 struct snd_pcm_substream *substream)
251{
252 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100253 if (spec->capture_prepare)
254 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100255 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
256 stream_tag, 0, format);
257 return 0;
258}
259
260static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
261 struct hda_codec *codec,
262 struct snd_pcm_substream *substream)
263{
264 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100265 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100266 if (spec->capture_cleanup)
267 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100268 return 0;
269}
270
271
272
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200273static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100274 .substreams = 1,
275 .channels_min = 2,
276 .channels_max = 2,
277 .nid = 0, /* fill later */
278 .ops = {
279 .open = conexant_playback_pcm_open,
280 .prepare = conexant_playback_pcm_prepare,
281 .cleanup = conexant_playback_pcm_cleanup
282 },
283};
284
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200285static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100286 .substreams = 1,
287 .channels_min = 2,
288 .channels_max = 2,
289 .nid = 0, /* fill later */
290 .ops = {
291 .prepare = conexant_capture_pcm_prepare,
292 .cleanup = conexant_capture_pcm_cleanup
293 },
294};
295
296
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200297static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100298 .substreams = 1,
299 .channels_min = 2,
300 .channels_max = 2,
301 .nid = 0, /* fill later */
302 .ops = {
303 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200304 .close = conexant_dig_playback_pcm_close,
305 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100306 },
307};
308
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200309static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100310 .substreams = 1,
311 .channels_min = 2,
312 .channels_max = 2,
313 /* NID is set in alc_build_pcms */
314};
315
Takashi Iwai461e2c72008-01-25 11:35:17 +0100316static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
317 struct hda_codec *codec,
318 unsigned int stream_tag,
319 unsigned int format,
320 struct snd_pcm_substream *substream)
321{
322 struct conexant_spec *spec = codec->spec;
323 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
324 spec->cur_adc_stream_tag = stream_tag;
325 spec->cur_adc_format = format;
326 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
327 return 0;
328}
329
330static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
331 struct hda_codec *codec,
332 struct snd_pcm_substream *substream)
333{
334 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100335 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100336 spec->cur_adc = 0;
337 return 0;
338}
339
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200340static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100341 .substreams = 1,
342 .channels_min = 2,
343 .channels_max = 2,
344 .nid = 0, /* fill later */
345 .ops = {
346 .prepare = cx5051_capture_pcm_prepare,
347 .cleanup = cx5051_capture_pcm_cleanup
348 },
349};
350
Tobin Davisc9b443d2006-11-14 12:13:39 +0100351static int conexant_build_pcms(struct hda_codec *codec)
352{
353 struct conexant_spec *spec = codec->spec;
354 struct hda_pcm *info = spec->pcm_rec;
355
356 codec->num_pcms = 1;
357 codec->pcm_info = info;
358
359 info->name = "CONEXANT Analog";
360 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
361 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
362 spec->multiout.max_channels;
363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
364 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200365 if (spec->capture_stream)
366 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
367 else {
368 if (codec->vendor_id == 0x14f15051)
369 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
370 cx5051_pcm_analog_capture;
371 else {
372 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
373 conexant_pcm_analog_capture;
374 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
375 spec->num_adc_nids;
376 }
377 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100378 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
379
380 if (spec->multiout.dig_out_nid) {
381 info++;
382 codec->num_pcms++;
383 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100384 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100385 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
386 conexant_pcm_digital_playback;
387 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
388 spec->multiout.dig_out_nid;
389 if (spec->dig_in_nid) {
390 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
391 conexant_pcm_digital_capture;
392 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
393 spec->dig_in_nid;
394 }
395 }
396
397 return 0;
398}
399
400static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_info *uinfo)
402{
403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404 struct conexant_spec *spec = codec->spec;
405
406 return snd_hda_input_mux_info(spec->input_mux, uinfo);
407}
408
409static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
410 struct snd_ctl_elem_value *ucontrol)
411{
412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413 struct conexant_spec *spec = codec->spec;
414 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
415
416 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
417 return 0;
418}
419
420static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_value *ucontrol)
422{
423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424 struct conexant_spec *spec = codec->spec;
425 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
426
427 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
428 spec->capsrc_nids[adc_idx],
429 &spec->cur_mux[adc_idx]);
430}
431
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200432static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
433 unsigned int power_state)
434{
435 if (power_state == AC_PWRST_D3)
436 msleep(100);
437 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
438 power_state);
439 /* partial workaround for "azx_get_response timeout" */
440 if (power_state == AC_PWRST_D0)
441 msleep(10);
Takashi Iwai9419ab62013-01-24 17:23:35 +0100442 snd_hda_codec_set_power_to_all(codec, fg, power_state);
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200443}
444
Tobin Davisc9b443d2006-11-14 12:13:39 +0100445static int conexant_init(struct hda_codec *codec)
446{
447 struct conexant_spec *spec = codec->spec;
448 int i;
449
450 for (i = 0; i < spec->num_init_verbs; i++)
451 snd_hda_sequence_write(codec, spec->init_verbs[i]);
452 return 0;
453}
454
455static void conexant_free(struct hda_codec *codec)
456{
Takashi Iwaiee48df52012-06-26 14:54:32 +0200457 struct conexant_spec *spec = codec->spec;
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200458 snd_hda_detach_beep_device(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +0200459 kfree(spec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100460}
461
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200462static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100463 {
464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
465 .name = "Capture Source",
466 .info = conexant_mux_enum_info,
467 .get = conexant_mux_enum_get,
468 .put = conexant_mux_enum_put
469 },
470 {}
471};
472
Takashi Iwai9322ca52012-02-03 14:28:01 +0100473static const char * const slave_pfxs[] = {
Takashi Iwaif37bc7a2012-11-08 15:59:23 +0100474 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100475 NULL
476};
477
Tobin Davisc9b443d2006-11-14 12:13:39 +0100478static int conexant_build_controls(struct hda_codec *codec)
479{
480 struct conexant_spec *spec = codec->spec;
481 unsigned int i;
482 int err;
483
484 for (i = 0; i < spec->num_mixers; i++) {
485 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
486 if (err < 0)
487 return err;
488 }
489 if (spec->multiout.dig_out_nid) {
490 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600491 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100492 spec->multiout.dig_out_nid);
493 if (err < 0)
494 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100495 err = snd_hda_create_spdif_share_sw(codec,
496 &spec->multiout);
497 if (err < 0)
498 return err;
499 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100500 }
501 if (spec->dig_in_nid) {
502 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
503 if (err < 0)
504 return err;
505 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100506
507 /* if we have no master control, let's create it */
508 if (spec->vmaster_nid &&
509 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
510 unsigned int vmaster_tlv[4];
511 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
512 HDA_OUTPUT, vmaster_tlv);
513 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100514 vmaster_tlv, slave_pfxs,
515 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100516 if (err < 0)
517 return err;
518 }
519 if (spec->vmaster_nid &&
520 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100521 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
522 NULL, slave_pfxs,
523 "Playback Switch");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100524 if (err < 0)
525 return err;
526 }
527
Takashi Iwaib880c742009-03-10 14:41:05 +0100528 if (spec->input_mux) {
529 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
530 if (err < 0)
531 return err;
532 }
533
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100534 err = add_beep_ctls(codec);
535 if (err < 0)
536 return err;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200537
Tobin Davisc9b443d2006-11-14 12:13:39 +0100538 return 0;
539}
540
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200541static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542 .build_controls = conexant_build_controls,
543 .build_pcms = conexant_build_pcms,
544 .init = conexant_init,
545 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200546 .set_power_state = conexant_set_power,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100547};
548
Takashi Iwai6764bce2011-05-13 16:52:25 +0200549static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100550/*
551 * EAPD control
552 * the private value = nid | (invert << 8)
553 */
554
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200555#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100556
Tobin Davis82f30042007-02-13 12:45:44 +0100557static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100558 struct snd_ctl_elem_value *ucontrol)
559{
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct conexant_spec *spec = codec->spec;
562 int invert = (kcontrol->private_value >> 8) & 1;
563 if (invert)
564 ucontrol->value.integer.value[0] = !spec->cur_eapd;
565 else
566 ucontrol->value.integer.value[0] = spec->cur_eapd;
567 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100568
Tobin Davisc9b443d2006-11-14 12:13:39 +0100569}
570
Tobin Davis82f30042007-02-13 12:45:44 +0100571static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100572 struct snd_ctl_elem_value *ucontrol)
573{
574 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
575 struct conexant_spec *spec = codec->spec;
576 int invert = (kcontrol->private_value >> 8) & 1;
577 hda_nid_t nid = kcontrol->private_value & 0xff;
578 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100579
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100580 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100581 if (invert)
582 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200583 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100584 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100585
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200587 snd_hda_codec_write_cache(codec, nid,
588 0, AC_VERB_SET_EAPD_BTLENABLE,
589 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100590 return 1;
591}
592
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100593/* controls for test mode */
594#ifdef CONFIG_SND_DEBUG
595
Tobin Davis82f30042007-02-13 12:45:44 +0100596#define CXT_EAPD_SWITCH(xname, nid, mask) \
597 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
598 .info = cxt_eapd_info, \
599 .get = cxt_eapd_get, \
600 .put = cxt_eapd_put, \
601 .private_value = nid | (mask<<16) }
602
603
604
Tobin Davisc9b443d2006-11-14 12:13:39 +0100605static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
606 struct snd_ctl_elem_info *uinfo)
607{
608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609 struct conexant_spec *spec = codec->spec;
610 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
611 spec->num_channel_mode);
612}
613
614static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
616{
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct conexant_spec *spec = codec->spec;
619 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
620 spec->num_channel_mode,
621 spec->multiout.max_channels);
622}
623
624static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_value *ucontrol)
626{
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct conexant_spec *spec = codec->spec;
629 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
630 spec->num_channel_mode,
631 &spec->multiout.max_channels);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100632 return err;
633}
634
635#define CXT_PIN_MODE(xname, nid, dir) \
636 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
637 .info = conexant_ch_mode_info, \
638 .get = conexant_ch_mode_get, \
639 .put = conexant_ch_mode_put, \
640 .private_value = nid | (dir<<16) }
641
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100642#endif /* CONFIG_SND_DEBUG */
643
Tobin Davisc9b443d2006-11-14 12:13:39 +0100644/* Conexant 5045 specific */
645
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200646static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
647static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
648static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100649#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100650
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200651static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100652 { 2, NULL },
653};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100654
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200655static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100656 .num_items = 2,
657 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200658 { "Internal Mic", 0x1 },
659 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100660 }
661};
662
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200663static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200664 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100665 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200666 { "Internal Mic", 0x1 },
667 { "Mic", 0x2 },
668 { "Line", 0x3 },
669 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100670 }
671};
672
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200673static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100674 .num_items = 2,
675 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200676 { "Mic", 0x1 },
677 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100678 }
679};
680
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681/* turn on/off EAPD (+ mute HP) as a master switch */
682static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
684{
685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100687 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100688
Tobin Davis82f30042007-02-13 12:45:44 +0100689 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100690 return 0;
691
Tobin Davis82f30042007-02-13 12:45:44 +0100692 /* toggle internal speakers mute depending of presence of
693 * the headphone jack
694 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200695 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
696 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
697 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100698
Takashi Iwai47fd8302007-08-10 17:11:07 +0200699 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
700 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
701 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100702 return 1;
703}
704
705/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200706static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200707 .ops = &snd_hda_bind_vol,
708 .values = {
709 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
710 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
711 0
712 },
713};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100714
Tobin Davis7f296732007-03-12 11:39:01 +0100715/* toggle input of built-in and mic jack appropriately */
716static void cxt5045_hp_automic(struct hda_codec *codec)
717{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200718 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
720 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
721 {}
722 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200723 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100724 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
725 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
726 {}
727 };
728 unsigned int present;
729
Takashi Iwaid56757a2009-11-18 08:00:14 +0100730 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100731 if (present)
732 snd_hda_sequence_write(codec, mic_jack_on);
733 else
734 snd_hda_sequence_write(codec, mic_jack_off);
735}
736
Tobin Davisc9b443d2006-11-14 12:13:39 +0100737
738/* mute internal speaker if HP is plugged */
739static void cxt5045_hp_automute(struct hda_codec *codec)
740{
Tobin Davis82f30042007-02-13 12:45:44 +0100741 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100742 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100743
Takashi Iwaid56757a2009-11-18 08:00:14 +0100744 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100745
Takashi Iwai47fd8302007-08-10 17:11:07 +0200746 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
747 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
748 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100749}
750
751/* unsolicited event for HP jack sensing */
752static void cxt5045_hp_unsol_event(struct hda_codec *codec,
753 unsigned int res)
754{
755 res >>= 26;
756 switch (res) {
757 case CONEXANT_HP_EVENT:
758 cxt5045_hp_automute(codec);
759 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100760 case CONEXANT_MIC_EVENT:
761 cxt5045_hp_automic(codec);
762 break;
763
Tobin Davisc9b443d2006-11-14 12:13:39 +0100764 }
765}
766
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200767static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200768 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
769 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200770 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
771 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100772 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
773 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100774 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
775 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200776 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100777 {
778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
779 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100780 .info = cxt_eapd_info,
781 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100782 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100783 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784 },
785
786 {}
787};
788
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200789static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200790 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
791 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200792
Jiang Zhe5218c892008-01-17 11:18:41 +0100793 {}
794};
795
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200796static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200797 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
798 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100799 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
800 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100801 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
802 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100803 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
804 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100805 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
806 {
807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
808 .name = "Master Playback Switch",
809 .info = cxt_eapd_info,
810 .get = cxt_eapd_get,
811 .put = cxt5045_hp_master_sw_put,
812 .private_value = 0x10,
813 },
814
815 {}
816};
817
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200818static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100819 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200820 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100821 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100822 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200823 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
824 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
825 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
826 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
827 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
830 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
831 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100832 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100833 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100834 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100835 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
836 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100837 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100838 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100839 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100840 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100841 { } /* end */
842};
843
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200844static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100845 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100846 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
847 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
848 /* Line In,HP, Amp */
849 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
850 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
851 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
852 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100858 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100859 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
860 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
861 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
862 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100863 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100864 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
865 /* EAPD */
866 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
867 { } /* end */
868};
Tobin Davis7f296732007-03-12 11:39:01 +0100869
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200870static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100871 /* pin sensing on HP jack */
872 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200873 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100874};
875
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200876static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100877 /* pin sensing on HP jack */
878 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200879 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100880};
881
Tobin Davisc9b443d2006-11-14 12:13:39 +0100882#ifdef CONFIG_SND_DEBUG
883/* Test configuration for debugging, modelled after the ALC260 test
884 * configuration.
885 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200886static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100887 .num_items = 5,
888 .items = {
889 { "MIXER", 0x0 },
890 { "MIC1 pin", 0x1 },
891 { "LINE1 pin", 0x2 },
892 { "HP-OUT pin", 0x3 },
893 { "CD pin", 0x4 },
894 },
895};
896
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200897static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100898
899 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100900 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
901 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200902 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
903 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
904 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
905 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100906
907 /* Modes for retasking pin widgets */
908 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
909 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
910
Tobin Davis82f30042007-02-13 12:45:44 +0100911 /* EAPD Switch Control */
912 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
913
Tobin Davisc9b443d2006-11-14 12:13:39 +0100914 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100915
Michael Karcher250f3272012-04-06 15:34:20 +0200916 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
917 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
918 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
919 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
920 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
921 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
922 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
923 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
924 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
925 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926 {
927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
928 .name = "Input Source",
929 .info = conexant_mux_enum_info,
930 .get = conexant_mux_enum_get,
931 .put = conexant_mux_enum_put,
932 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200933 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200934 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
935 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100936 { } /* end */
937};
938
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200939static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100940 /* Set connections */
941 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
942 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
943 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100944 /* Enable retasking pins as output, initially without power amp */
945 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100946 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947
948 /* Disable digital (SPDIF) pins initially, but users can enable
949 * them via a mixer switch. In the case of SPDIF-out, this initverb
950 * payload also sets the generation to 0, output to be in "consumer"
951 * PCM format, copyright asserted, no pre-emphasis and no validity
952 * control.
953 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100954 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
955 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100956
Tobin Davisc9b443d2006-11-14 12:13:39 +0100957 /* Unmute retasking pin widget output buffers since the default
958 * state appears to be output. As the pin mode is changed by the
959 * user the pin mode control will take care of enabling the pin's
960 * input/output buffers as needed.
961 */
962 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
963 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
964
965 /* Mute capture amp left and right */
966 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
967
968 /* Set ADC connection select to match default mixer setting (mic1
969 * pin)
970 */
Michael Karcher250f3272012-04-06 15:34:20 +0200971 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
972 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100973
974 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +0200975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100976 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
978 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
979 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
980
981 { }
982};
983#endif
984
985
986/* initialize jack-sensing, too */
987static int cxt5045_init(struct hda_codec *codec)
988{
989 conexant_init(codec);
990 cxt5045_hp_automute(codec);
991 return 0;
992}
993
994
995enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100996 CXT5045_LAPTOP_HPSENSE,
997 CXT5045_LAPTOP_MICSENSE,
998 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100999 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001000 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001#ifdef CONFIG_SND_DEBUG
1002 CXT5045_TEST,
1003#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001004 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001005 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001006};
1007
Takashi Iwaiea734962011-01-17 11:29:34 +01001008static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001009 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1010 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1011 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1012 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001013 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001014#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001015 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001016#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001017 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001018};
1019
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001020static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001021 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001022 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001023 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001024 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1025 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001026 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1027 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001028 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1029 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1030 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001031 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1032 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001033 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001034 {}
1035};
1036
1037static int patch_cxt5045(struct hda_codec *codec)
1038{
1039 struct conexant_spec *spec;
1040 int board_config;
1041
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001042 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1043 cxt5045_models,
1044 cxt5045_cfg_tbl);
1045 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001046 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001047 if (board_config == CXT5045_AUTO)
1048 return patch_conexant_auto(codec);
1049
Tobin Davisc9b443d2006-11-14 12:13:39 +01001050 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1051 if (!spec)
1052 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001053 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001054 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001055
1056 spec->multiout.max_channels = 2;
1057 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1058 spec->multiout.dac_nids = cxt5045_dac_nids;
1059 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1060 spec->num_adc_nids = 1;
1061 spec->adc_nids = cxt5045_adc_nids;
1062 spec->capsrc_nids = cxt5045_capsrc_nids;
1063 spec->input_mux = &cxt5045_capture_source;
1064 spec->num_mixers = 1;
1065 spec->mixers[0] = cxt5045_mixers;
1066 spec->num_init_verbs = 1;
1067 spec->init_verbs[0] = cxt5045_init_verbs;
1068 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001069 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1070 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001071
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001072 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073
1074 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075
Tobin Davisc9b443d2006-11-14 12:13:39 +01001076 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001077 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001078 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001079 spec->input_mux = &cxt5045_capture_source;
1080 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001081 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1082 spec->mixers[0] = cxt5045_mixers;
1083 codec->patch_ops.init = cxt5045_init;
1084 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001085 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001086 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001087 spec->input_mux = &cxt5045_capture_source;
1088 spec->num_init_verbs = 2;
1089 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001090 spec->mixers[0] = cxt5045_mixers;
1091 codec->patch_ops.init = cxt5045_init;
1092 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001093 default:
1094 case CXT5045_LAPTOP_HPMICSENSE:
1095 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1096 spec->input_mux = &cxt5045_capture_source;
1097 spec->num_init_verbs = 3;
1098 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1099 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1100 spec->mixers[0] = cxt5045_mixers;
1101 codec->patch_ops.init = cxt5045_init;
1102 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001103 case CXT5045_BENQ:
1104 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1105 spec->input_mux = &cxt5045_capture_source_benq;
1106 spec->num_init_verbs = 1;
1107 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1108 spec->mixers[0] = cxt5045_mixers;
1109 spec->mixers[1] = cxt5045_benq_mixers;
1110 spec->num_mixers = 2;
1111 codec->patch_ops.init = cxt5045_init;
1112 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001113 case CXT5045_LAPTOP_HP530:
1114 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1115 spec->input_mux = &cxt5045_capture_source_hp530;
1116 spec->num_init_verbs = 2;
1117 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1118 spec->mixers[0] = cxt5045_mixers_hp530;
1119 codec->patch_ops.init = cxt5045_init;
1120 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001121#ifdef CONFIG_SND_DEBUG
1122 case CXT5045_TEST:
1123 spec->input_mux = &cxt5045_test_capture_source;
1124 spec->mixers[0] = cxt5045_test_mixer;
1125 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001126 break;
1127
Tobin Davisc9b443d2006-11-14 12:13:39 +01001128#endif
1129 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001130
Takashi Iwai031005f2008-06-26 14:49:58 +02001131 switch (codec->subsystem_id >> 16) {
1132 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001133 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001134 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001135 case 0x17aa:
1136 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1137 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1138 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001139 */
1140 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1141 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1142 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1143 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1144 (1 << AC_AMPCAP_MUTE_SHIFT));
1145 break;
1146 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001147
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001148 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01001149 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001150
Tobin Davisc9b443d2006-11-14 12:13:39 +01001151 return 0;
1152}
1153
1154
1155/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001156#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001158static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1159static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1160static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001161
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001162static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001163 { 2, NULL },
1164};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001165
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001166static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001167 .num_items = 2,
1168 .items = {
1169 { "ExtMic", 0x2 },
1170 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001171 }
1172};
1173
1174/* turn on/off EAPD (+ mute HP) as a master switch */
1175static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1176 struct snd_ctl_elem_value *ucontrol)
1177{
1178 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1179 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001180 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181
Tobin Davis82f30042007-02-13 12:45:44 +01001182 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001183 return 0;
1184
Tobin Davis82f30042007-02-13 12:45:44 +01001185 /* toggle internal speakers mute depending of presence of
1186 * the headphone jack
1187 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001188 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001189 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1190 * pin widgets unlike other codecs. In this case, we need to
1191 * set index 0x01 for the volume from the mixer amp 0x19.
1192 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001193 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001194 HDA_AMP_MUTE, bits);
1195 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1196 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1197 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001198 return 1;
1199}
1200
Tobin Davisc9b443d2006-11-14 12:13:39 +01001201/* mute internal speaker if HP is plugged */
1202static void cxt5047_hp_automute(struct hda_codec *codec)
1203{
Tobin Davis82f30042007-02-13 12:45:44 +01001204 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001205 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001206
Takashi Iwaid56757a2009-11-18 08:00:14 +01001207 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001208
Takashi Iwai47fd8302007-08-10 17:11:07 +02001209 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001210 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001211 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001212 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001213}
1214
1215/* toggle input of built-in and mic jack appropriately */
1216static void cxt5047_hp_automic(struct hda_codec *codec)
1217{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001218 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001219 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1220 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001221 {}
1222 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001223 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001224 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1225 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001226 {}
1227 };
1228 unsigned int present;
1229
Takashi Iwaid56757a2009-11-18 08:00:14 +01001230 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001231 if (present)
1232 snd_hda_sequence_write(codec, mic_jack_on);
1233 else
1234 snd_hda_sequence_write(codec, mic_jack_off);
1235}
1236
1237/* unsolicited event for HP jack sensing */
1238static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1239 unsigned int res)
1240{
Marc Boucher9f113e02008-01-22 15:18:08 +01001241 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242 case CONEXANT_HP_EVENT:
1243 cxt5047_hp_automute(codec);
1244 break;
1245 case CONEXANT_MIC_EVENT:
1246 cxt5047_hp_automic(codec);
1247 break;
1248 }
1249}
1250
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001251static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001252 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1253 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001254 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001255 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1256 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1257 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1258 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001259 {
1260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1261 .name = "Master Playback Switch",
1262 .info = cxt_eapd_info,
1263 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001264 .put = cxt5047_hp_master_sw_put,
1265 .private_value = 0x13,
1266 },
1267
1268 {}
1269};
1270
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001271static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001272 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001273 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001274 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1275 {}
1276};
1277
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001278static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001279 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280 { } /* end */
1281};
1282
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001283static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001284 /* Line in, Mic, Built-in Mic */
1285 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1286 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1287 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001288 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001289 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001290 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1291 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001292 /* Record selector: Mic */
1293 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1294 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1295 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1296 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1298 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1299 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1300 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001301 /* SPDIF route: PCM */
1302 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001303 /* Enable unsolicited events */
1304 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1305 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001306 { } /* end */
1307};
1308
1309/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001310static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001311 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 {}
1313};
1314
1315/* Test configuration for debugging, modelled after the ALC260 test
1316 * configuration.
1317 */
1318#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001319static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001320 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001322 { "LINE1 pin", 0x0 },
1323 { "MIC1 pin", 0x1 },
1324 { "MIC2 pin", 0x2 },
1325 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326 },
1327};
1328
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001329static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001330
1331 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001332 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1333 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1334 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1335 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001336 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1337 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1338 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001340 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1341 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1342 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1343 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344
1345 /* Modes for retasking pin widgets */
1346 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1347 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1348
Tobin Davis82f30042007-02-13 12:45:44 +01001349 /* EAPD Switch Control */
1350 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1351
Tobin Davisc9b443d2006-11-14 12:13:39 +01001352 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001353 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1354 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1355 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1356 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1357 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1358 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1359 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1360 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001361
Tobin Davis82f30042007-02-13 12:45:44 +01001362 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1363 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1364 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1365 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1366 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1367 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1368 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1369 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370 {
1371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1372 .name = "Input Source",
1373 .info = conexant_mux_enum_info,
1374 .get = conexant_mux_enum_get,
1375 .put = conexant_mux_enum_put,
1376 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001377 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001378
Tobin Davisc9b443d2006-11-14 12:13:39 +01001379 { } /* end */
1380};
1381
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001382static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001383 /* Enable retasking pins as output, initially without power amp */
1384 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1385 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1386 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1387
1388 /* Disable digital (SPDIF) pins initially, but users can enable
1389 * them via a mixer switch. In the case of SPDIF-out, this initverb
1390 * payload also sets the generation to 0, output to be in "consumer"
1391 * PCM format, copyright asserted, no pre-emphasis and no validity
1392 * control.
1393 */
1394 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1395
1396 /* Ensure mic1, mic2, line1 pin widgets take input from the
1397 * OUT1 sum bus when acting as an output.
1398 */
1399 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1400 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1401
1402 /* Start with output sum widgets muted and their output gains at min */
1403 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1404 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1405
1406 /* Unmute retasking pin widget output buffers since the default
1407 * state appears to be output. As the pin mode is changed by the
1408 * user the pin mode control will take care of enabling the pin's
1409 * input/output buffers as needed.
1410 */
1411 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1412 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1413 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1414
1415 /* Mute capture amp left and right */
1416 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1417
1418 /* Set ADC connection select to match default mixer setting (mic1
1419 * pin)
1420 */
1421 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1422
1423 /* Mute all inputs to mixer widget (even unconnected ones) */
1424 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1425 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1426 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1427 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1428 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1429 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1430 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1431 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1432
1433 { }
1434};
1435#endif
1436
1437
1438/* initialize jack-sensing, too */
1439static int cxt5047_hp_init(struct hda_codec *codec)
1440{
1441 conexant_init(codec);
1442 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443 return 0;
1444}
1445
1446
1447enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001448 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1449 CXT5047_LAPTOP_HP, /* Some HP laptops */
1450 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001451#ifdef CONFIG_SND_DEBUG
1452 CXT5047_TEST,
1453#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001454 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001455 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001456};
1457
Takashi Iwaiea734962011-01-17 11:29:34 +01001458static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001459 [CXT5047_LAPTOP] = "laptop",
1460 [CXT5047_LAPTOP_HP] = "laptop-hp",
1461 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001462#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001463 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001464#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001465 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001466};
1467
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001468static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001469 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001470 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1471 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001472 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001473 {}
1474};
1475
1476static int patch_cxt5047(struct hda_codec *codec)
1477{
1478 struct conexant_spec *spec;
1479 int board_config;
1480
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001481 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1482 cxt5047_models,
1483 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001484 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001485 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001486 if (board_config == CXT5047_AUTO)
1487 return patch_conexant_auto(codec);
1488
Tobin Davisc9b443d2006-11-14 12:13:39 +01001489 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1490 if (!spec)
1491 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001492 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001493 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001494
1495 spec->multiout.max_channels = 2;
1496 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1497 spec->multiout.dac_nids = cxt5047_dac_nids;
1498 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1499 spec->num_adc_nids = 1;
1500 spec->adc_nids = cxt5047_adc_nids;
1501 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001502 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001503 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504 spec->num_init_verbs = 1;
1505 spec->init_verbs[0] = cxt5047_init_verbs;
1506 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001507 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1508 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509
1510 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001511
Tobin Davisc9b443d2006-11-14 12:13:39 +01001512 switch (board_config) {
1513 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001514 spec->num_mixers = 2;
1515 spec->mixers[1] = cxt5047_hp_spk_mixers;
1516 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001517 break;
1518 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001519 spec->num_mixers = 2;
1520 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001521 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522 codec->patch_ops.init = cxt5047_hp_init;
1523 break;
1524 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001525 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001526 spec->num_mixers = 2;
1527 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001528 spec->num_init_verbs = 2;
1529 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001530 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001531 break;
1532#ifdef CONFIG_SND_DEBUG
1533 case CXT5047_TEST:
1534 spec->input_mux = &cxt5047_test_capture_source;
1535 spec->mixers[0] = cxt5047_test_mixer;
1536 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001537 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001538#endif
1539 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001540 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001541
1542 switch (codec->subsystem_id >> 16) {
1543 case 0x103c:
1544 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1545 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1546 * with 0 dB offset 0x17)
1547 */
1548 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1549 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1550 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1551 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1552 (1 << AC_AMPCAP_MUTE_SHIFT));
1553 break;
1554 }
1555
Tobin Davisc9b443d2006-11-14 12:13:39 +01001556 return 0;
1557}
1558
Takashi Iwai461e2c72008-01-25 11:35:17 +01001559/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001560static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1561static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001562
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001563static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001564 { 2, NULL },
1565};
1566
1567static void cxt5051_update_speaker(struct hda_codec *codec)
1568{
1569 struct conexant_spec *spec = codec->spec;
1570 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001571 /* headphone pin */
1572 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001573 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001574 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001575 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001576 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001577 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001578 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001579 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001580}
1581
1582/* turn on/off EAPD (+ mute HP) as a master switch */
1583static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1584 struct snd_ctl_elem_value *ucontrol)
1585{
1586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1587
1588 if (!cxt_eapd_put(kcontrol, ucontrol))
1589 return 0;
1590 cxt5051_update_speaker(codec);
1591 return 1;
1592}
1593
1594/* toggle input of built-in and mic jack appropriately */
1595static void cxt5051_portb_automic(struct hda_codec *codec)
1596{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001597 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001598 unsigned int present;
1599
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001600 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001601 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001602 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001603 snd_hda_codec_write(codec, 0x14, 0,
1604 AC_VERB_SET_CONNECT_SEL,
1605 present ? 0x01 : 0x00);
1606}
1607
1608/* switch the current ADC according to the jack state */
1609static void cxt5051_portc_automic(struct hda_codec *codec)
1610{
1611 struct conexant_spec *spec = codec->spec;
1612 unsigned int present;
1613 hda_nid_t new_adc;
1614
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001615 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001616 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001617 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001618 if (present)
1619 spec->cur_adc_idx = 1;
1620 else
1621 spec->cur_adc_idx = 0;
1622 new_adc = spec->adc_nids[spec->cur_adc_idx];
1623 if (spec->cur_adc && spec->cur_adc != new_adc) {
1624 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001625 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001626 spec->cur_adc = new_adc;
1627 snd_hda_codec_setup_stream(codec, new_adc,
1628 spec->cur_adc_stream_tag, 0,
1629 spec->cur_adc_format);
1630 }
1631}
1632
1633/* mute internal speaker if HP is plugged */
1634static void cxt5051_hp_automute(struct hda_codec *codec)
1635{
1636 struct conexant_spec *spec = codec->spec;
1637
Takashi Iwaid56757a2009-11-18 08:00:14 +01001638 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001639 cxt5051_update_speaker(codec);
1640}
1641
1642/* unsolicited event for HP jack sensing */
1643static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1644 unsigned int res)
1645{
1646 switch (res >> 26) {
1647 case CONEXANT_HP_EVENT:
1648 cxt5051_hp_automute(codec);
1649 break;
1650 case CXT5051_PORTB_EVENT:
1651 cxt5051_portb_automic(codec);
1652 break;
1653 case CXT5051_PORTC_EVENT:
1654 cxt5051_portc_automic(codec);
1655 break;
1656 }
1657}
1658
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001659static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001660 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1661 {
1662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1663 .name = "Master Playback Switch",
1664 .info = cxt_eapd_info,
1665 .get = cxt_eapd_get,
1666 .put = cxt5051_hp_master_sw_put,
1667 .private_value = 0x1a,
1668 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001669 {}
1670};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001671
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001672static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001673 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1674 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001675 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1676 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
David Henningssonc40bd912012-09-19 12:19:47 +02001677 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1678 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 {}
1680};
1681
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001682static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001683 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1684 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001685 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1686 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001687 {}
1688};
1689
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001690static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001691 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1692 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001693 {}
1694};
1695
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001696static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001697 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1698 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001699 {}
1700};
1701
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001702static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001703 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1704 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001705 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1706 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001707 {}
1708};
1709
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001710static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001711 /* Line in, Mic */
1712 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1713 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1714 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1715 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1716 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1717 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1718 /* SPK */
1719 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1720 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1721 /* HP, Amp */
1722 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1723 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1724 /* DAC1 */
1725 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001726 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001727 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1729 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1730 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001731 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1733 /* EAPD */
1734 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1735 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001736 { } /* end */
1737};
1738
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001739static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001740 /* Line in, Mic */
1741 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1742 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1743 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1744 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1745 /* SPK */
1746 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1747 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1748 /* HP, Amp */
1749 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1750 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1751 /* DAC1 */
1752 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001753 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1755 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1756 /* SPDIF route: PCM */
1757 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1758 /* EAPD */
1759 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1760 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001761 { } /* end */
1762};
1763
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001764static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001765 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001766 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001767 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1768 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1769 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1770 /* SPK */
1771 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1773 /* HP, Amp */
1774 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1775 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1776 /* DAC1 */
1777 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001778 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1780 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1781 /* SPDIF route: PCM */
1782 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1783 /* EAPD */
1784 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1785 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001786 { } /* end */
1787};
1788
Takashi Iwai6953e552010-01-24 11:00:27 +01001789static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1790 unsigned int event)
1791{
1792 snd_hda_codec_write(codec, nid, 0,
1793 AC_VERB_SET_UNSOLICITED_ENABLE,
1794 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001795}
1796
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001797static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001798 /* Subwoofer */
1799 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1800 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1801 { } /* end */
1802};
1803
Takashi Iwai461e2c72008-01-25 11:35:17 +01001804/* initialize jack-sensing, too */
1805static int cxt5051_init(struct hda_codec *codec)
1806{
Takashi Iwai6953e552010-01-24 11:00:27 +01001807 struct conexant_spec *spec = codec->spec;
1808
Takashi Iwai461e2c72008-01-25 11:35:17 +01001809 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001810
1811 if (spec->auto_mic & AUTO_MIC_PORTB)
1812 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1813 if (spec->auto_mic & AUTO_MIC_PORTC)
1814 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1815
Takashi Iwai461e2c72008-01-25 11:35:17 +01001816 if (codec->patch_ops.unsol_event) {
1817 cxt5051_hp_automute(codec);
1818 cxt5051_portb_automic(codec);
1819 cxt5051_portc_automic(codec);
1820 }
1821 return 0;
1822}
1823
1824
1825enum {
1826 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1827 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001828 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001829 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001830 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001831 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001832 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001833 CXT5051_MODELS
1834};
1835
Takashi Iwaiea734962011-01-17 11:29:34 +01001836static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001837 [CXT5051_LAPTOP] = "laptop",
1838 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001839 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001840 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001841 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001842 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001843 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001844};
1845
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001846static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001847 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001848 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001849 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001850 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001851 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1852 CXT5051_LAPTOP),
1853 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001854 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001855 {}
1856};
1857
1858static int patch_cxt5051(struct hda_codec *codec)
1859{
1860 struct conexant_spec *spec;
1861 int board_config;
1862
Takashi Iwai6764bce2011-05-13 16:52:25 +02001863 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1864 cxt5051_models,
1865 cxt5051_cfg_tbl);
1866 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001867 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001868 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001869 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001870
Takashi Iwai461e2c72008-01-25 11:35:17 +01001871 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1872 if (!spec)
1873 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001874 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001875 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001876
1877 codec->patch_ops = conexant_patch_ops;
1878 codec->patch_ops.init = cxt5051_init;
1879
1880 spec->multiout.max_channels = 2;
1881 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1882 spec->multiout.dac_nids = cxt5051_dac_nids;
1883 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1884 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1885 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001886 spec->num_mixers = 2;
1887 spec->mixers[0] = cxt5051_capture_mixers;
1888 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001889 spec->num_init_verbs = 1;
1890 spec->init_verbs[0] = cxt5051_init_verbs;
1891 spec->spdif_route = 0;
1892 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1893 spec->channel_mode = cxt5051_modes;
1894 spec->cur_adc = 0;
1895 spec->cur_adc_idx = 0;
1896
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001897 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1898
Takashi Iwai79d7d532009-03-04 09:03:50 +01001899 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1900
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001901 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001902 switch (board_config) {
1903 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001904 spec->mixers[0] = cxt5051_hp_mixers;
1905 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001906 case CXT5051_HP_DV6736:
1907 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1908 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001909 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001910 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001911 case CXT5051_F700:
1912 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1913 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001914 spec->auto_mic = 0;
1915 break;
1916 case CXT5051_TOSHIBA:
1917 spec->mixers[0] = cxt5051_toshiba_mixers;
1918 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001919 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001920 case CXT5051_IDEAPAD:
1921 spec->init_verbs[spec->num_init_verbs++] =
1922 cxt5051_ideapad_init_verbs;
1923 spec->ideapad = 1;
1924 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001925 }
1926
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001927 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01001928 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001929
Takashi Iwai461e2c72008-01-25 11:35:17 +01001930 return 0;
1931}
1932
Daniel Drake0fb67e92009-07-16 14:46:57 +01001933/* Conexant 5066 specific */
1934
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001935static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1936static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1937static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1938static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001939
Daniel Drakedbaccc02009-11-09 15:17:24 +00001940/* OLPC's microphone port is DC coupled for use with external sensors,
1941 * therefore we use a 50% mic bias in order to center the input signal with
1942 * the DC input range of the codec. */
1943#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1944
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001945static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001946 { 2, NULL },
1947};
1948
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001949#define HP_PRESENT_PORT_A (1 << 0)
1950#define HP_PRESENT_PORT_D (1 << 1)
1951#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1952#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1953
Daniel Drake0fb67e92009-07-16 14:46:57 +01001954static void cxt5066_update_speaker(struct hda_codec *codec)
1955{
1956 struct conexant_spec *spec = codec->spec;
1957 unsigned int pinctl;
1958
John Baboval3a253442010-12-02 11:21:31 -05001959 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1960 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001961
1962 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001963 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001964 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001965
1966 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001967 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1968 if (spec->dell_automute || spec->thinkpad) {
1969 /* Mute if Port A is connected */
1970 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05001971 pinctl = 0;
1972 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001973 /* Thinkpad/Dell doesn't give pin-D status */
1974 if (!hp_port_d_present(spec))
1975 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05001976 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001977 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001978
1979 /* CLASS_D AMP */
1980 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001981 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001982}
1983
1984/* turn on/off EAPD (+ mute HP) as a master switch */
1985static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1986 struct snd_ctl_elem_value *ucontrol)
1987{
1988 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1989
1990 if (!cxt_eapd_put(kcontrol, ucontrol))
1991 return 0;
1992
1993 cxt5066_update_speaker(codec);
1994 return 1;
1995}
1996
Daniel Drakec4cfe662010-01-07 13:47:04 +01001997static const struct hda_input_mux cxt5066_olpc_dc_bias = {
1998 .num_items = 3,
1999 .items = {
2000 { "Off", PIN_IN },
2001 { "50%", PIN_VREF50 },
2002 { "80%", PIN_VREF80 },
2003 },
2004};
2005
2006static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2007{
2008 struct conexant_spec *spec = codec->spec;
2009 /* Even though port F is the DC input, the bias is controlled on port B.
2010 * we also leave that port as an active input (but unselected) in DC mode
2011 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002012 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002013 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2014}
2015
Daniel Drake75f89912010-01-07 13:46:25 +01002016/* OLPC defers mic widget control until when capture is started because the
2017 * microphone LED comes on as soon as these settings are put in place. if we
2018 * did this before recording, it would give the false indication that recording
2019 * is happening when it is not. */
2020static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002021{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002022 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002023 if (!spec->recording)
2024 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002025
Daniel Drakec4cfe662010-01-07 13:47:04 +01002026 if (spec->dc_enable) {
2027 /* in DC mode we ignore presence detection and just use the jack
2028 * through our special DC port */
2029 const struct hda_verb enable_dc_mode[] = {
2030 /* disble internal mic, port C */
2031 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2032
2033 /* enable DC capture, port F */
2034 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2035 {},
2036 };
2037
2038 snd_hda_sequence_write(codec, enable_dc_mode);
2039 /* port B input disabled (and bias set) through the following call */
2040 cxt5066_set_olpc_dc_bias(codec);
2041 return;
2042 }
2043
2044 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002045 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002046
Daniel Drake75f89912010-01-07 13:46:25 +01002047 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002048 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002049 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002050
Daniel Drake75f89912010-01-07 13:46:25 +01002051 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002052 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002053 spec->ext_mic_present ? 0 : PIN_VREF80);
2054}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002055
Daniel Drake75f89912010-01-07 13:46:25 +01002056/* toggle input of built-in and mic jack appropriately */
2057static void cxt5066_olpc_automic(struct hda_codec *codec)
2058{
2059 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002060 unsigned int present;
2061
Daniel Drakec4cfe662010-01-07 13:47:04 +01002062 if (spec->dc_enable) /* don't do presence detection in DC mode */
2063 return;
2064
Daniel Drake75f89912010-01-07 13:46:25 +01002065 present = snd_hda_codec_read(codec, 0x1a, 0,
2066 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2067 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002068 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002069 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002070 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002071
2072 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2073 present ? 0 : 1);
2074 spec->ext_mic_present = !!present;
2075
2076 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002077}
2078
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002079/* toggle input of built-in digital mic and mic jack appropriately */
2080static void cxt5066_vostro_automic(struct hda_codec *codec)
2081{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002082 unsigned int present;
2083
2084 struct hda_verb ext_mic_present[] = {
2085 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002086 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002087
2088 /* switch to external mic input */
2089 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2090 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2091
2092 /* disable internal digital mic */
2093 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2094 {}
2095 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002096 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002097 /* enable internal mic, port C */
2098 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2099
2100 /* switch to internal mic input */
2101 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2102
2103 /* disable external mic, port B */
2104 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2105 {}
2106 };
2107
2108 present = snd_hda_jack_detect(codec, 0x1a);
2109 if (present) {
2110 snd_printdd("CXT5066: external microphone detected\n");
2111 snd_hda_sequence_write(codec, ext_mic_present);
2112 } else {
2113 snd_printdd("CXT5066: external microphone absent\n");
2114 snd_hda_sequence_write(codec, ext_mic_absent);
2115 }
2116}
2117
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002118/* toggle input of built-in digital mic and mic jack appropriately */
2119static void cxt5066_ideapad_automic(struct hda_codec *codec)
2120{
2121 unsigned int present;
2122
2123 struct hda_verb ext_mic_present[] = {
2124 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2125 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2126 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2127 {}
2128 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002129 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002130 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2131 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2132 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2133 {}
2134 };
2135
2136 present = snd_hda_jack_detect(codec, 0x1b);
2137 if (present) {
2138 snd_printdd("CXT5066: external microphone detected\n");
2139 snd_hda_sequence_write(codec, ext_mic_present);
2140 } else {
2141 snd_printdd("CXT5066: external microphone absent\n");
2142 snd_hda_sequence_write(codec, ext_mic_absent);
2143 }
2144}
2145
David Henningssona1d69062011-01-21 13:33:28 +01002146
2147/* toggle input of built-in digital mic and mic jack appropriately */
2148static void cxt5066_asus_automic(struct hda_codec *codec)
2149{
2150 unsigned int present;
2151
2152 present = snd_hda_jack_detect(codec, 0x1b);
2153 snd_printdd("CXT5066: external microphone present=%d\n", present);
2154 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2155 present ? 1 : 0);
2156}
2157
2158
David Henningsson048e78a2010-09-02 08:35:47 +02002159/* toggle input of built-in digital mic and mic jack appropriately */
2160static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2161{
2162 unsigned int present;
2163
2164 present = snd_hda_jack_detect(codec, 0x1b);
2165 snd_printdd("CXT5066: external microphone present=%d\n", present);
2166 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2167 present ? 1 : 3);
2168}
2169
2170
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002171/* toggle input of built-in digital mic and mic jack appropriately
2172 order is: external mic -> dock mic -> interal mic */
2173static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2174{
2175 unsigned int ext_present, dock_present;
2176
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002177 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002178 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2179 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2180 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2181 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2182 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2183 {}
2184 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002185 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002186 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2187 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2188 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2189 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2190 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2191 {}
2192 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002193 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002194 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2195 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2196 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2197 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2198 {}
2199 };
2200
2201 ext_present = snd_hda_jack_detect(codec, 0x1b);
2202 dock_present = snd_hda_jack_detect(codec, 0x1a);
2203 if (ext_present) {
2204 snd_printdd("CXT5066: external microphone detected\n");
2205 snd_hda_sequence_write(codec, ext_mic_present);
2206 } else if (dock_present) {
2207 snd_printdd("CXT5066: dock microphone detected\n");
2208 snd_hda_sequence_write(codec, dock_mic_present);
2209 } else {
2210 snd_printdd("CXT5066: external microphone absent\n");
2211 snd_hda_sequence_write(codec, ext_mic_absent);
2212 }
2213}
2214
Daniel Drake0fb67e92009-07-16 14:46:57 +01002215/* mute internal speaker if HP is plugged */
2216static void cxt5066_hp_automute(struct hda_codec *codec)
2217{
2218 struct conexant_spec *spec = codec->spec;
2219 unsigned int portA, portD;
2220
2221 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002222 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002223
2224 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002225 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002226
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002227 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2228 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002229 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2230 portA, portD, spec->hp_present);
2231 cxt5066_update_speaker(codec);
2232}
2233
David Henningsson02b6b5b2011-01-21 13:27:39 +01002234/* Dispatch the right mic autoswitch function */
2235static void cxt5066_automic(struct hda_codec *codec)
2236{
2237 struct conexant_spec *spec = codec->spec;
2238
2239 if (spec->dell_vostro)
2240 cxt5066_vostro_automic(codec);
2241 else if (spec->ideapad)
2242 cxt5066_ideapad_automic(codec);
2243 else if (spec->thinkpad)
2244 cxt5066_thinkpad_automic(codec);
2245 else if (spec->hp_laptop)
2246 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002247 else if (spec->asus)
2248 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002249}
2250
Daniel Drake0fb67e92009-07-16 14:46:57 +01002251/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002252static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002253{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002254 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002255 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2256 switch (res >> 26) {
2257 case CONEXANT_HP_EVENT:
2258 cxt5066_hp_automute(codec);
2259 break;
2260 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002261 /* ignore mic events in DC mode; we're always using the jack */
2262 if (!spec->dc_enable)
2263 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002264 break;
2265 }
2266}
2267
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002268/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002269static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002270{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002271 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002272 switch (res >> 26) {
2273 case CONEXANT_HP_EVENT:
2274 cxt5066_hp_automute(codec);
2275 break;
2276 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002277 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002278 break;
2279 }
2280}
2281
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002282
Daniel Drake0fb67e92009-07-16 14:46:57 +01002283static const struct hda_input_mux cxt5066_analog_mic_boost = {
2284 .num_items = 5,
2285 .items = {
2286 { "0dB", 0 },
2287 { "10dB", 1 },
2288 { "20dB", 2 },
2289 { "30dB", 3 },
2290 { "40dB", 4 },
2291 },
2292};
2293
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002294static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002295{
2296 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002297 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002298 AC_VERB_SET_AMP_GAIN_MUTE,
2299 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2300 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002301 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002302 /* adjust the internal mic as well...it is not through 0x17 */
2303 snd_hda_codec_write_cache(codec, 0x23, 0,
2304 AC_VERB_SET_AMP_GAIN_MUTE,
2305 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2306 cxt5066_analog_mic_boost.
2307 items[spec->mic_boost].index);
2308 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002309}
2310
Daniel Drake0fb67e92009-07-16 14:46:57 +01002311static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2312 struct snd_ctl_elem_info *uinfo)
2313{
2314 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2315}
2316
2317static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2318 struct snd_ctl_elem_value *ucontrol)
2319{
2320 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002321 struct conexant_spec *spec = codec->spec;
2322 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002323 return 0;
2324}
2325
2326static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2327 struct snd_ctl_elem_value *ucontrol)
2328{
2329 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002330 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002331 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2332 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002333 idx = ucontrol->value.enumerated.item[0];
2334 if (idx >= imux->num_items)
2335 idx = imux->num_items - 1;
2336
Daniel Drakec4cfe662010-01-07 13:47:04 +01002337 spec->mic_boost = idx;
2338 if (!spec->dc_enable)
2339 cxt5066_set_mic_boost(codec);
2340 return 1;
2341}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002342
Daniel Drakec4cfe662010-01-07 13:47:04 +01002343static void cxt5066_enable_dc(struct hda_codec *codec)
2344{
2345 const struct hda_verb enable_dc_mode[] = {
2346 /* disable gain */
2347 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2348
2349 /* switch to DC input */
2350 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2351 {}
2352 };
2353
2354 /* configure as input source */
2355 snd_hda_sequence_write(codec, enable_dc_mode);
2356 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2357}
2358
2359static void cxt5066_disable_dc(struct hda_codec *codec)
2360{
2361 /* reconfigure input source */
2362 cxt5066_set_mic_boost(codec);
2363 /* automic also selects the right mic if we're recording */
2364 cxt5066_olpc_automic(codec);
2365}
2366
2367static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2368 struct snd_ctl_elem_value *ucontrol)
2369{
2370 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2371 struct conexant_spec *spec = codec->spec;
2372 ucontrol->value.integer.value[0] = spec->dc_enable;
2373 return 0;
2374}
2375
2376static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2377 struct snd_ctl_elem_value *ucontrol)
2378{
2379 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2380 struct conexant_spec *spec = codec->spec;
2381 int dc_enable = !!ucontrol->value.integer.value[0];
2382
2383 if (dc_enable == spec->dc_enable)
2384 return 0;
2385
2386 spec->dc_enable = dc_enable;
2387 if (dc_enable)
2388 cxt5066_enable_dc(codec);
2389 else
2390 cxt5066_disable_dc(codec);
2391
2392 return 1;
2393}
2394
2395static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2396 struct snd_ctl_elem_info *uinfo)
2397{
2398 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2399}
2400
2401static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2402 struct snd_ctl_elem_value *ucontrol)
2403{
2404 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2405 struct conexant_spec *spec = codec->spec;
2406 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2407 return 0;
2408}
2409
2410static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2411 struct snd_ctl_elem_value *ucontrol)
2412{
2413 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2414 struct conexant_spec *spec = codec->spec;
2415 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2416 unsigned int idx;
2417
2418 idx = ucontrol->value.enumerated.item[0];
2419 if (idx >= imux->num_items)
2420 idx = imux->num_items - 1;
2421
2422 spec->dc_input_bias = idx;
2423 if (spec->dc_enable)
2424 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002425 return 1;
2426}
2427
Daniel Drake75f89912010-01-07 13:46:25 +01002428static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2429{
2430 struct conexant_spec *spec = codec->spec;
2431 /* mark as recording and configure the microphone widget so that the
2432 * recording LED comes on. */
2433 spec->recording = 1;
2434 cxt5066_olpc_select_mic(codec);
2435}
2436
2437static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2438{
2439 struct conexant_spec *spec = codec->spec;
2440 const struct hda_verb disable_mics[] = {
2441 /* disable external mic, port B */
2442 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2443
2444 /* disble internal mic, port C */
2445 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002446
2447 /* disable DC capture, port F */
2448 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002449 {},
2450 };
2451
2452 snd_hda_sequence_write(codec, disable_mics);
2453 spec->recording = 0;
2454}
2455
Andy Robinsonf6a24912011-01-24 10:12:37 -05002456static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002457 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002458 int num_pins)
2459{
2460 struct conexant_spec *spec = codec->spec;
2461 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2462 int i;
2463
2464 for (i = 0; i < num_pins; i++, dig_pins++) {
2465 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2466 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2467 continue;
2468 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2469 continue;
Andy Robinsonf6a24912011-01-24 10:12:37 -05002470 }
2471}
2472
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002473static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002474 .num_items = 4,
2475 .items = {
2476 { "Mic B", 0 },
2477 { "Mic C", 1 },
2478 { "Mic E", 2 },
2479 { "Mic F", 3 },
2480 },
2481};
2482
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002483static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002484 .ops = &snd_hda_bind_vol,
2485 .values = {
2486 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2487 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2488 0
2489 },
2490};
2491
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002492static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002493 .ops = &snd_hda_bind_sw,
2494 .values = {
2495 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2496 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2497 0
2498 },
2499};
2500
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002501static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002502 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2503 {}
2504};
2505
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002506static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002507 {
2508 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2509 .name = "Master Playback Volume",
2510 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2511 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2512 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002513 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002514 .info = snd_hda_mixer_amp_volume_info,
2515 .get = snd_hda_mixer_amp_volume_get,
2516 .put = snd_hda_mixer_amp_volume_put,
2517 .tlv = { .c = snd_hda_mixer_amp_tlv },
2518 /* offset by 28 volume steps to limit minimum gain to -46dB */
2519 .private_value =
2520 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2521 },
2522 {}
2523};
2524
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002525static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002526 {
2527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2528 .name = "DC Mode Enable Switch",
2529 .info = snd_ctl_boolean_mono_info,
2530 .get = cxt5066_olpc_dc_get,
2531 .put = cxt5066_olpc_dc_put,
2532 },
2533 {
2534 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2535 .name = "DC Input Bias Enum",
2536 .info = cxt5066_olpc_dc_bias_enum_info,
2537 .get = cxt5066_olpc_dc_bias_enum_get,
2538 .put = cxt5066_olpc_dc_bias_enum_put,
2539 },
2540 {}
2541};
2542
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002543static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002544 {
2545 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2546 .name = "Master Playback Switch",
2547 .info = cxt_eapd_info,
2548 .get = cxt_eapd_get,
2549 .put = cxt5066_hp_master_sw_put,
2550 .private_value = 0x1d,
2551 },
2552
2553 {
2554 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002555 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002556 .info = cxt5066_mic_boost_mux_enum_info,
2557 .get = cxt5066_mic_boost_mux_enum_get,
2558 .put = cxt5066_mic_boost_mux_enum_put,
2559 },
2560
2561 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2562 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2563 {}
2564};
2565
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002566static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002567 {
2568 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002569 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002570 .info = cxt5066_mic_boost_mux_enum_info,
2571 .get = cxt5066_mic_boost_mux_enum_get,
2572 .put = cxt5066_mic_boost_mux_enum_put,
2573 .private_value = 0x23 | 0x100,
2574 },
2575 {}
2576};
2577
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002578static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002579 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2580 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2581 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2582 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2583
2584 /* Speakers */
2585 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2586 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2587
2588 /* HP, Amp */
2589 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2590 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2591
2592 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2593 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2594
2595 /* DAC1 */
2596 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2597
2598 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2599 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2600 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2601 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2602 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2603 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2604
2605 /* no digital microphone support yet */
2606 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2607
2608 /* Audio input selector */
2609 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2610
2611 /* SPDIF route: PCM */
2612 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2613 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2614
2615 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2616 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2617
2618 /* EAPD */
2619 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2620
2621 /* not handling these yet */
2622 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2623 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2624 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2625 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2626 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2627 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2628 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2629 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2630 { } /* end */
2631};
2632
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002633static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002634 /* Port A: headphones */
2635 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2636 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2637
2638 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002639 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002640
2641 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002642 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002643
2644 /* Port D: unused */
2645 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2646
2647 /* Port E: unused, but has primary EAPD */
2648 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2649 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2650
Daniel Drakec4cfe662010-01-07 13:47:04 +01002651 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002652 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2653
2654 /* Port G: internal speakers */
2655 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2656 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2657
2658 /* DAC1 */
2659 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2660
2661 /* DAC2: unused */
2662 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2663
2664 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2665 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2666 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2667 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2668 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2669 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2670 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2671 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2672 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2673 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2674 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2675 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2676
2677 /* Disable digital microphone port */
2678 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2679
2680 /* Audio input selectors */
2681 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2682 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2683
2684 /* Disable SPDIF */
2685 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2686 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2687
2688 /* enable unsolicited events for Port A and B */
2689 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2690 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2691 { } /* end */
2692};
2693
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002694static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002695 /* Port A: headphones */
2696 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2697 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2698
2699 /* Port B: external microphone */
2700 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2701
2702 /* Port C: unused */
2703 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2704
2705 /* Port D: unused */
2706 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2707
2708 /* Port E: unused, but has primary EAPD */
2709 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2710 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2711
2712 /* Port F: unused */
2713 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2714
2715 /* Port G: internal speakers */
2716 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2717 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2718
2719 /* DAC1 */
2720 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2721
2722 /* DAC2: unused */
2723 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2724
2725 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2726 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2727 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2729 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2730 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2731 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2732 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2733 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2734 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2735 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2736 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2737
2738 /* Digital microphone port */
2739 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2740
2741 /* Audio input selectors */
2742 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2744
2745 /* Disable SPDIF */
2746 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2747 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2748
2749 /* enable unsolicited events for Port A and B */
2750 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2751 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2752 { } /* end */
2753};
2754
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002755static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002756 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2757 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2758 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2759 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2760
2761 /* Speakers */
2762 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2763 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2764
2765 /* HP, Amp */
2766 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2767 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2768
2769 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2770 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2771
2772 /* DAC1 */
2773 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2774
2775 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2781 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2782
2783 /* Audio input selector */
2784 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2785 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2786
2787 /* SPDIF route: PCM */
2788 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2789 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2790
2791 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2792 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2793
2794 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002795 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002796
2797 /* EAPD */
2798 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2799
2800 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2801 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2802 { } /* end */
2803};
2804
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002805static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002806 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2807 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2808
2809 /* Port G: internal speakers */
2810 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2811 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2812
2813 /* Port A: HP, Amp */
2814 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2816
2817 /* Port B: Mic Dock */
2818 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2819
2820 /* Port C: Mic */
2821 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2822
2823 /* Port D: HP Dock, Amp */
2824 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2825 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2826
2827 /* DAC1 */
2828 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2829
2830 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2831 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2832 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2834 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2836 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2837
2838 /* Audio input selector */
2839 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2840 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2841
2842 /* SPDIF route: PCM */
2843 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2844 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2845
2846 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2847 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2848
2849 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002850 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002851
2852 /* EAPD */
2853 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2854
2855 /* enable unsolicited events for Port A, B, C and D */
2856 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2857 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2858 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2859 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2860 { } /* end */
2861};
2862
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002863static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002864 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2865 { } /* end */
2866};
2867
David Henningsson048e78a2010-09-02 08:35:47 +02002868
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002869static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002870 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2871 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2872 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2873 { } /* end */
2874};
2875
Daniel Drake0fb67e92009-07-16 14:46:57 +01002876/* initialize jack-sensing, too */
2877static int cxt5066_init(struct hda_codec *codec)
2878{
2879 snd_printdd("CXT5066: init\n");
2880 conexant_init(codec);
2881 if (codec->patch_ops.unsol_event) {
2882 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002883 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002884 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002885 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002886 return 0;
2887}
2888
Daniel Drake75f89912010-01-07 13:46:25 +01002889static int cxt5066_olpc_init(struct hda_codec *codec)
2890{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002891 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002892 snd_printdd("CXT5066: init\n");
2893 conexant_init(codec);
2894 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002895 if (!spec->dc_enable) {
2896 cxt5066_set_mic_boost(codec);
2897 cxt5066_olpc_automic(codec);
2898 } else {
2899 cxt5066_enable_dc(codec);
2900 }
Daniel Drake75f89912010-01-07 13:46:25 +01002901 return 0;
2902}
2903
Daniel Drake0fb67e92009-07-16 14:46:57 +01002904enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002905 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002906 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2907 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002908 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002909 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002910 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002911 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002912 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002913 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002914 CXT5066_MODELS
2915};
2916
Takashi Iwaiea734962011-01-17 11:29:34 +01002917static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002918 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002919 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2920 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002921 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002922 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002923 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002924 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002925 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002926 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002927};
2928
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002929static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002930 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002931 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002932 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002933 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50bc2010-04-28 18:05:06 +02002934 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002935 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2936 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002937 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002938 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002939 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002940 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002941 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002942 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002943 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2944 CXT5066_LAPTOP),
2945 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002946 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002947 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002948 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson84012652011-03-31 09:36:19 +02002949 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002950 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002951 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002952 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002953 {}
2954};
2955
2956static int patch_cxt5066(struct hda_codec *codec)
2957{
2958 struct conexant_spec *spec;
2959 int board_config;
2960
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002961 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2962 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002963 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02002964 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002965 if (board_config == CXT5066_AUTO)
2966 return patch_conexant_auto(codec);
2967
Daniel Drake0fb67e92009-07-16 14:46:57 +01002968 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2969 if (!spec)
2970 return -ENOMEM;
2971 codec->spec = spec;
2972
2973 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01002974 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002975
2976 spec->dell_automute = 0;
2977 spec->multiout.max_channels = 2;
2978 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2979 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05002980 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2981 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01002982 spec->num_adc_nids = 1;
2983 spec->adc_nids = cxt5066_adc_nids;
2984 spec->capsrc_nids = cxt5066_capsrc_nids;
2985 spec->input_mux = &cxt5066_capture_source;
2986
2987 spec->port_d_mode = PIN_HP;
2988
2989 spec->num_init_verbs = 1;
2990 spec->init_verbs[0] = cxt5066_init_verbs;
2991 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2992 spec->channel_mode = cxt5066_modes;
2993 spec->cur_adc = 0;
2994 spec->cur_adc_idx = 0;
2995
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002996 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2997
Daniel Drake0fb67e92009-07-16 14:46:57 +01002998 switch (board_config) {
2999 default:
3000 case CXT5066_LAPTOP:
3001 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3002 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3003 break;
3004 case CXT5066_DELL_LAPTOP:
3005 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3006 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3007
3008 spec->port_d_mode = PIN_OUT;
3009 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3010 spec->num_init_verbs++;
3011 spec->dell_automute = 1;
3012 break;
David Henningssona1d69062011-01-21 13:33:28 +01003013 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003014 case CXT5066_HP_LAPTOP:
3015 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003016 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003017 spec->init_verbs[spec->num_init_verbs] =
3018 cxt5066_init_verbs_hp_laptop;
3019 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003020 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3021 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003022 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3023 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3024 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003025 if (board_config == CXT5066_HP_LAPTOP)
3026 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003027 /* input source automatically selected */
3028 spec->input_mux = NULL;
3029 spec->port_d_mode = 0;
3030 spec->mic_boost = 3; /* default 30dB gain */
3031 break;
3032
Daniel Drake0fb67e92009-07-16 14:46:57 +01003033 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003034 codec->patch_ops.init = cxt5066_olpc_init;
3035 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003036 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3037 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003038 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003039 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3040 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003041 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003042
3043 /* no S/PDIF out */
3044 spec->multiout.dig_out_nid = 0;
3045
3046 /* input source automatically selected */
3047 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003048
3049 /* our capture hooks which allow us to turn on the microphone LED
3050 * at the right time */
3051 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3052 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003053 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003054 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003055 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003056 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003057 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3058 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3059 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003060 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003061 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003062 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003063 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003064
3065 /* no S/PDIF out */
3066 spec->multiout.dig_out_nid = 0;
3067
3068 /* input source automatically selected */
3069 spec->input_mux = NULL;
3070 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003071 case CXT5066_IDEAPAD:
3072 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003073 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003074 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3075 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3076 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3077 spec->port_d_mode = 0;
3078 spec->ideapad = 1;
3079 spec->mic_boost = 2; /* default 20dB gain */
3080
3081 /* no S/PDIF out */
3082 spec->multiout.dig_out_nid = 0;
3083
3084 /* input source automatically selected */
3085 spec->input_mux = NULL;
3086 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003087 case CXT5066_THINKPAD:
3088 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003089 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003090 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3091 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3092 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3093 spec->thinkpad = 1;
3094 spec->port_d_mode = PIN_OUT;
3095 spec->mic_boost = 2; /* default 20dB gain */
3096
3097 /* no S/PDIF out */
3098 spec->multiout.dig_out_nid = 0;
3099
3100 /* input source automatically selected */
3101 spec->input_mux = NULL;
3102 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003103 }
3104
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003105 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01003106 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003107
Daniel Drake0fb67e92009-07-16 14:46:57 +01003108 return 0;
3109}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003110
Takashi Iwaibf92d1d2012-12-20 16:38:19 +01003111#endif /* ENABLE_CXT_STATIC_QUIRKS */
3112
3113
Takashi Iwai461e2c72008-01-25 11:35:17 +01003114/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003115 * Automatic parser for CX20641 & co
3116 */
3117
Takashi Iwaif2e57312010-09-15 10:07:08 +02003118#ifdef CONFIG_SND_HDA_INPUT_BEEP
3119static void cx_auto_parse_beep(struct hda_codec *codec)
3120{
3121 struct conexant_spec *spec = codec->spec;
3122 hda_nid_t nid, end_nid;
3123
3124 end_nid = codec->start_nid + codec->num_nodes;
3125 for (nid = codec->start_nid; nid < end_nid; nid++)
3126 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3127 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3128 break;
3129 }
3130}
3131#else
3132#define cx_auto_parse_beep(codec)
3133#endif
3134
Takashi Iwai254f2962011-10-14 15:22:34 +02003135/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003136static void cx_auto_parse_eapd(struct hda_codec *codec)
3137{
3138 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003139 hda_nid_t nid, end_nid;
3140
3141 end_nid = codec->start_nid + codec->num_nodes;
3142 for (nid = codec->start_nid; nid < end_nid; nid++) {
3143 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3144 continue;
3145 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3146 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003147 spec->eapds[spec->num_eapds++] = nid;
3148 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3149 break;
3150 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003151
3152 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3153 * it's a new chip, where EAPDs are supposed to be associated to
3154 * pins, and we can control EAPD per pin.
3155 * OTOH, if only one or two EAPDs are found, it's an old chip,
3156 * thus it might control over all pins.
3157 */
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003158 if (spec->num_eapds > 2)
3159 spec->gen.own_eapd_ctl = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003160}
3161
Takashi Iwaida339862011-05-13 16:24:15 +02003162static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3163 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003164{
3165 int i;
3166 for (i = 0; i < num_pins; i++) {
3167 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3168 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003169 AC_VERB_SET_EAPD_BTLENABLE,
3170 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003171 }
3172}
3173
Takashi Iwai527c73b2012-03-12 12:38:51 +01003174/* turn on/off EAPD according to Master switch */
3175static void cx_auto_vmaster_hook(void *private_data, int enabled)
3176{
3177 struct hda_codec *codec = private_data;
3178 struct conexant_spec *spec = codec->spec;
3179
Takashi Iwai527c73b2012-03-12 12:38:51 +01003180 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3181}
3182
Takashi Iwaif2e57312010-09-15 10:07:08 +02003183static int cx_auto_build_controls(struct hda_codec *codec)
3184{
3185 int err;
3186
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003187 err = snd_hda_gen_build_controls(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003188 if (err < 0)
3189 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003190
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003191 err = add_beep_ctls(codec);
3192 if (err < 0)
3193 return err;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003194
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003195 return 0;
3196}
3197
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003198static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003199 .build_controls = cx_auto_build_controls,
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003200 .build_pcms = snd_hda_gen_build_pcms,
3201 .init = snd_hda_gen_init,
Takashi Iwai7504b6c2013-03-18 11:25:51 +01003202 .free = snd_hda_gen_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02003203 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai164a7ad2013-01-18 18:25:45 +01003204#ifdef CONFIG_PM
3205 .check_power_status = snd_hda_gen_check_power_status,
3206#endif
Takashi Iwaif2e57312010-09-15 10:07:08 +02003207};
3208
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003209/*
3210 * pin fix-up
3211 */
David Henningsson18dcd302012-04-02 15:40:27 +02003212enum {
3213 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02003214 CXT_PINCFG_LENOVO_TP410,
Huacai Chen239fb862012-10-05 21:25:09 +08003215 CXT_PINCFG_LEMOTE_A1004,
3216 CXT_PINCFG_LEMOTE_A1205,
David Henningsson18dcd302012-04-02 15:40:27 +02003217 CXT_FIXUP_STEREO_DMIC,
Huacai Chen239fb862012-10-05 21:25:09 +08003218 CXT_FIXUP_INC_MIC_BOOST,
David Henningsson18dcd302012-04-02 15:40:27 +02003219};
3220
Takashi Iwai23d30f22012-05-07 17:17:32 +02003221static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
3222 const struct hda_fixup *fix, int action)
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003223{
David Henningsson18dcd302012-04-02 15:40:27 +02003224 struct conexant_spec *spec = codec->spec;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003225 spec->gen.inv_dmic_split = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003226}
3227
Huacai Chen239fb862012-10-05 21:25:09 +08003228static void cxt5066_increase_mic_boost(struct hda_codec *codec,
3229 const struct hda_fixup *fix, int action)
3230{
3231 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3232 return;
3233
3234 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
3235 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
3236 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3237 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3238 (0 << AC_AMPCAP_MUTE_SHIFT));
3239}
3240
Takashi Iwaid70f36322012-04-19 15:18:08 +02003241/* ThinkPad X200 & co with cxt5051 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02003242static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003243 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
3244 { 0x17, 0x21a11000 }, /* dock-mic */
3245 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01003246 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003247 {}
3248};
3249
Takashi Iwaid70f36322012-04-19 15:18:08 +02003250/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02003251static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
Takashi Iwaid70f36322012-04-19 15:18:08 +02003252 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
3253 { 0x1a, 0x21a190f0 }, /* dock-mic */
3254 { 0x1c, 0x212140ff }, /* dock-HP */
3255 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003256};
3257
Huacai Chen239fb862012-10-05 21:25:09 +08003258/* Lemote A1004/A1205 with cxt5066 */
3259static const struct hda_pintbl cxt_pincfg_lemote[] = {
3260 { 0x1a, 0x90a10020 }, /* Internal mic */
3261 { 0x1b, 0x03a11020 }, /* External mic */
3262 { 0x1d, 0x400101f0 }, /* Not used */
3263 { 0x1e, 0x40a701f0 }, /* Not used */
3264 { 0x20, 0x404501f0 }, /* Not used */
3265 { 0x22, 0x404401f0 }, /* Not used */
3266 { 0x23, 0x40a701f0 }, /* Not used */
3267 {}
3268};
3269
Takashi Iwai23d30f22012-05-07 17:17:32 +02003270static const struct hda_fixup cxt_fixups[] = {
3271 [CXT_PINCFG_LENOVO_X200] = {
3272 .type = HDA_FIXUP_PINS,
3273 .v.pins = cxt_pincfg_lenovo_x200,
3274 },
3275 [CXT_PINCFG_LENOVO_TP410] = {
3276 .type = HDA_FIXUP_PINS,
3277 .v.pins = cxt_pincfg_lenovo_tp410,
3278 },
Huacai Chen239fb862012-10-05 21:25:09 +08003279 [CXT_PINCFG_LEMOTE_A1004] = {
3280 .type = HDA_FIXUP_PINS,
3281 .chained = true,
3282 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
3283 .v.pins = cxt_pincfg_lemote,
3284 },
3285 [CXT_PINCFG_LEMOTE_A1205] = {
3286 .type = HDA_FIXUP_PINS,
3287 .v.pins = cxt_pincfg_lemote,
3288 },
Takashi Iwai23d30f22012-05-07 17:17:32 +02003289 [CXT_FIXUP_STEREO_DMIC] = {
3290 .type = HDA_FIXUP_FUNC,
3291 .v.func = cxt_fixup_stereo_dmic,
3292 },
Huacai Chen239fb862012-10-05 21:25:09 +08003293 [CXT_FIXUP_INC_MIC_BOOST] = {
3294 .type = HDA_FIXUP_FUNC,
3295 .v.func = cxt5066_increase_mic_boost,
3296 },
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003297};
3298
Takashi Iwaid70f36322012-04-19 15:18:08 +02003299static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003300 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3301 {}
3302};
3303
Takashi Iwaid70f36322012-04-19 15:18:08 +02003304static const struct snd_pci_quirk cxt5066_fixups[] = {
Takashi Iwai63a077e2012-12-12 12:10:01 +01003305 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaid70f36322012-04-19 15:18:08 +02003306 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3307 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3308 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3309 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3310 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02003311 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechelee4db0952012-09-26 01:20:44 +02003312 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningssonb3c5dce2012-06-21 16:03:01 +02003313 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Huacai Chen239fb862012-10-05 21:25:09 +08003314 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3315 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
Takashi Iwaif2e57312010-09-15 10:07:08 +02003316 {}
3317};
3318
Takashi Iwai38681372012-02-27 15:00:58 +01003319/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
3320 * can be created (bko#42825)
3321 */
3322static void add_cx5051_fake_mutes(struct hda_codec *codec)
3323{
3324 static hda_nid_t out_nids[] = {
3325 0x10, 0x11, 0
3326 };
3327 hda_nid_t *p;
3328
3329 for (p = out_nids; *p; p++)
3330 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
3331 AC_AMPCAP_MIN_MUTE |
3332 query_amp_caps(codec, *p, HDA_OUTPUT));
3333}
3334
Takashi Iwaif2e57312010-09-15 10:07:08 +02003335static int patch_conexant_auto(struct hda_codec *codec)
3336{
3337 struct conexant_spec *spec;
3338 int err;
3339
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003340 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3341 codec->chip_name);
3342
Takashi Iwaif2e57312010-09-15 10:07:08 +02003343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3344 if (!spec)
3345 return -ENOMEM;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003346 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003347 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003348
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003349 cx_auto_parse_beep(codec);
3350 cx_auto_parse_eapd(codec);
3351 if (spec->gen.own_eapd_ctl)
3352 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003353
Takashi Iwai6b452142011-10-14 15:26:20 +02003354 switch (codec->vendor_id) {
3355 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02003356 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02003357 break;
Takashi Iwai164a7ad2013-01-18 18:25:45 +01003358 case 0x14f15047:
3359 codec->pin_amp_workaround = 1;
3360 spec->gen.mixer_nid = 0x19;
3361 break;
Takashi Iwai38681372012-02-27 15:00:58 +01003362 case 0x14f15051:
3363 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02003364 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02003365 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
Takashi Iwai38681372012-02-27 15:00:58 +01003366 break;
Michael Karcher51969d62012-04-06 15:34:19 +02003367 default:
3368 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02003369 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
3370 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02003371 }
3372
Takashi Iwaif29735c2012-03-13 07:55:10 +01003373 /* Show mute-led control only on HP laptops
3374 * This is a sort of white-list: on HP laptops, EAPD corresponds
3375 * only to the mute-LED without actualy amp function. Meanwhile,
3376 * others may use EAPD really as an amp switch, so it might be
3377 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01003378 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01003379 switch (codec->subsystem_id >> 16) {
3380 case 0x103c:
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003381 spec->gen.vmaster_mute_enum = 1;
Takashi Iwaif29735c2012-03-13 07:55:10 +01003382 break;
3383 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01003384
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003385 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3386
3387 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003388 if (err < 0)
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003389 goto error;
3390
3391 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3392 if (err < 0)
3393 goto error;
3394
Takashi Iwaif2e57312010-09-15 10:07:08 +02003395 codec->patch_ops = cx_auto_patch_ops;
Takashi Iwai4f2864a2012-01-25 11:54:19 +01003396
3397 /* Some laptops with Conexant chips show stalls in S3 resume,
3398 * which falls into the single-cmd mode.
3399 * Better to make reset, then.
3400 */
3401 if (!codec->bus->sync_write) {
3402 snd_printd("hda_codec: "
3403 "Enable sync_write for stable communication\n");
3404 codec->bus->sync_write = 1;
3405 codec->bus->allow_bus_reset = 1;
3406 }
3407
Takashi Iwaif2e57312010-09-15 10:07:08 +02003408 return 0;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003409
3410 error:
3411 snd_hda_gen_free(codec);
3412 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003413}
3414
Takashi Iwaibf92d1d2012-12-20 16:38:19 +01003415#ifndef ENABLE_CXT_STATIC_QUIRKS
3416#define patch_cxt5045 patch_conexant_auto
3417#define patch_cxt5047 patch_conexant_auto
3418#define patch_cxt5051 patch_conexant_auto
3419#define patch_cxt5066 patch_conexant_auto
3420#endif
3421
Takashi Iwaif2e57312010-09-15 10:07:08 +02003422/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01003423 */
3424
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003425static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003426 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3427 .patch = patch_cxt5045 },
3428 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3429 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003430 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3431 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003432 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3433 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003434 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3435 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003436 { .id = 0x14f15068, .name = "CX20584",
3437 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003438 { .id = 0x14f15069, .name = "CX20585",
3439 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02003440 { .id = 0x14f1506c, .name = "CX20588",
3441 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01003442 { .id = 0x14f1506e, .name = "CX20590",
3443 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02003444 { .id = 0x14f15097, .name = "CX20631",
3445 .patch = patch_conexant_auto },
3446 { .id = 0x14f15098, .name = "CX20632",
3447 .patch = patch_conexant_auto },
3448 { .id = 0x14f150a1, .name = "CX20641",
3449 .patch = patch_conexant_auto },
3450 { .id = 0x14f150a2, .name = "CX20642",
3451 .patch = patch_conexant_auto },
3452 { .id = 0x14f150ab, .name = "CX20651",
3453 .patch = patch_conexant_auto },
3454 { .id = 0x14f150ac, .name = "CX20652",
3455 .patch = patch_conexant_auto },
3456 { .id = 0x14f150b8, .name = "CX20664",
3457 .patch = patch_conexant_auto },
3458 { .id = 0x14f150b9, .name = "CX20665",
3459 .patch = patch_conexant_auto },
Takashi Iwai2d825fd2012-05-11 08:39:24 +02003460 { .id = 0x14f1510f, .name = "CX20751/2",
3461 .patch = patch_conexant_auto },
3462 { .id = 0x14f15110, .name = "CX20751/2",
3463 .patch = patch_conexant_auto },
3464 { .id = 0x14f15111, .name = "CX20753/4",
3465 .patch = patch_conexant_auto },
Takashi Iwai42c364a2013-01-21 16:53:37 +01003466 { .id = 0x14f15113, .name = "CX20755",
3467 .patch = patch_conexant_auto },
3468 { .id = 0x14f15114, .name = "CX20756",
3469 .patch = patch_conexant_auto },
3470 { .id = 0x14f15115, .name = "CX20757",
3471 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003472 {} /* terminator */
3473};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003474
3475MODULE_ALIAS("snd-hda-codec-id:14f15045");
3476MODULE_ALIAS("snd-hda-codec-id:14f15047");
3477MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003478MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003479MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003480MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003481MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02003482MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01003483MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02003484MODULE_ALIAS("snd-hda-codec-id:14f15097");
3485MODULE_ALIAS("snd-hda-codec-id:14f15098");
3486MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3487MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3488MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3489MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3490MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3491MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai2d825fd2012-05-11 08:39:24 +02003492MODULE_ALIAS("snd-hda-codec-id:14f1510f");
3493MODULE_ALIAS("snd-hda-codec-id:14f15110");
3494MODULE_ALIAS("snd-hda-codec-id:14f15111");
Takashi Iwai42c364a2013-01-21 16:53:37 +01003495MODULE_ALIAS("snd-hda-codec-id:14f15113");
3496MODULE_ALIAS("snd-hda-codec-id:14f15114");
3497MODULE_ALIAS("snd-hda-codec-id:14f15115");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003498
3499MODULE_LICENSE("GPL");
3500MODULE_DESCRIPTION("Conexant HD-audio codec");
3501
3502static struct hda_codec_preset_list conexant_list = {
3503 .preset = snd_hda_preset_conexant,
3504 .owner = THIS_MODULE,
3505};
3506
3507static int __init patch_conexant_init(void)
3508{
3509 return snd_hda_add_codec_preset(&conexant_list);
3510}
3511
3512static void __exit patch_conexant_exit(void)
3513{
3514 snd_hda_delete_codec_preset(&conexant_list);
3515}
3516
3517module_init(patch_conexant_init)
3518module_exit(patch_conexant_exit)