blob: 2a89d1eefeb6059623a985fea7cdb464dc4c7390 [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
142#define set_beep_amp(spec, nid, idx, dir) \
143 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
144/* additional beep mixers; the actual parameters are overwritten at build */
145static const struct snd_kcontrol_new cxt_beep_mixer[] = {
146 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
147 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
148 { } /* end */
149};
150
151/* create beep controls if needed */
152static int add_beep_ctls(struct hda_codec *codec)
153{
154 struct conexant_spec *spec = codec->spec;
155 int err;
156
157 if (spec->beep_amp) {
158 const struct snd_kcontrol_new *knew;
159 for (knew = cxt_beep_mixer; knew->name; knew++) {
160 struct snd_kcontrol *kctl;
161 kctl = snd_ctl_new1(knew, codec);
162 if (!kctl)
163 return -ENOMEM;
164 kctl->private_value = spec->beep_amp;
165 err = snd_hda_ctl_add(codec, 0, kctl);
166 if (err < 0)
167 return err;
168 }
169 }
170 return 0;
171}
172#else
173#define set_beep_amp(spec, nid, idx, dir) /* NOP */
174#define add_beep_ctls(codec) 0
175#endif
176
177
178#ifdef ENABLE_CXT_STATIC_QUIRKS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100179static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 struct snd_pcm_substream *substream)
182{
183 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100184 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
185 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100186}
187
188static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
190 unsigned int stream_tag,
191 unsigned int format,
192 struct snd_pcm_substream *substream)
193{
194 struct conexant_spec *spec = codec->spec;
195 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
196 stream_tag,
197 format, substream);
198}
199
200static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
201 struct hda_codec *codec,
202 struct snd_pcm_substream *substream)
203{
204 struct conexant_spec *spec = codec->spec;
205 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
206}
207
208/*
209 * Digital out
210 */
211static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
212 struct hda_codec *codec,
213 struct snd_pcm_substream *substream)
214{
215 struct conexant_spec *spec = codec->spec;
216 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
217}
218
219static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
220 struct hda_codec *codec,
221 struct snd_pcm_substream *substream)
222{
223 struct conexant_spec *spec = codec->spec;
224 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
225}
226
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200227static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
228 struct hda_codec *codec,
229 unsigned int stream_tag,
230 unsigned int format,
231 struct snd_pcm_substream *substream)
232{
233 struct conexant_spec *spec = codec->spec;
234 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
235 stream_tag,
236 format, substream);
237}
238
Tobin Davisc9b443d2006-11-14 12:13:39 +0100239/*
240 * Analog capture
241 */
242static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
243 struct hda_codec *codec,
244 unsigned int stream_tag,
245 unsigned int format,
246 struct snd_pcm_substream *substream)
247{
248 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100249 if (spec->capture_prepare)
250 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100251 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
252 stream_tag, 0, format);
253 return 0;
254}
255
256static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 struct snd_pcm_substream *substream)
259{
260 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100261 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100262 if (spec->capture_cleanup)
263 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100264 return 0;
265}
266
267
268
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200269static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100270 .substreams = 1,
271 .channels_min = 2,
272 .channels_max = 2,
273 .nid = 0, /* fill later */
274 .ops = {
275 .open = conexant_playback_pcm_open,
276 .prepare = conexant_playback_pcm_prepare,
277 .cleanup = conexant_playback_pcm_cleanup
278 },
279};
280
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200281static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100282 .substreams = 1,
283 .channels_min = 2,
284 .channels_max = 2,
285 .nid = 0, /* fill later */
286 .ops = {
287 .prepare = conexant_capture_pcm_prepare,
288 .cleanup = conexant_capture_pcm_cleanup
289 },
290};
291
292
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200293static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100294 .substreams = 1,
295 .channels_min = 2,
296 .channels_max = 2,
297 .nid = 0, /* fill later */
298 .ops = {
299 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200300 .close = conexant_dig_playback_pcm_close,
301 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100302 },
303};
304
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200305static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100306 .substreams = 1,
307 .channels_min = 2,
308 .channels_max = 2,
309 /* NID is set in alc_build_pcms */
310};
311
Takashi Iwai461e2c72008-01-25 11:35:17 +0100312static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
313 struct hda_codec *codec,
314 unsigned int stream_tag,
315 unsigned int format,
316 struct snd_pcm_substream *substream)
317{
318 struct conexant_spec *spec = codec->spec;
319 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
320 spec->cur_adc_stream_tag = stream_tag;
321 spec->cur_adc_format = format;
322 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
323 return 0;
324}
325
326static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
327 struct hda_codec *codec,
328 struct snd_pcm_substream *substream)
329{
330 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100331 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100332 spec->cur_adc = 0;
333 return 0;
334}
335
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200336static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100337 .substreams = 1,
338 .channels_min = 2,
339 .channels_max = 2,
340 .nid = 0, /* fill later */
341 .ops = {
342 .prepare = cx5051_capture_pcm_prepare,
343 .cleanup = cx5051_capture_pcm_cleanup
344 },
345};
346
Tobin Davisc9b443d2006-11-14 12:13:39 +0100347static int conexant_build_pcms(struct hda_codec *codec)
348{
349 struct conexant_spec *spec = codec->spec;
350 struct hda_pcm *info = spec->pcm_rec;
351
352 codec->num_pcms = 1;
353 codec->pcm_info = info;
354
355 info->name = "CONEXANT Analog";
356 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
358 spec->multiout.max_channels;
359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
360 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200361 if (spec->capture_stream)
362 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
363 else {
364 if (codec->vendor_id == 0x14f15051)
365 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
366 cx5051_pcm_analog_capture;
367 else {
368 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
369 conexant_pcm_analog_capture;
370 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
371 spec->num_adc_nids;
372 }
373 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100374 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
375
376 if (spec->multiout.dig_out_nid) {
377 info++;
378 codec->num_pcms++;
379 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100380 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100381 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
382 conexant_pcm_digital_playback;
383 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
384 spec->multiout.dig_out_nid;
385 if (spec->dig_in_nid) {
386 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
387 conexant_pcm_digital_capture;
388 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
389 spec->dig_in_nid;
390 }
391 }
392
393 return 0;
394}
395
396static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_info *uinfo)
398{
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 struct conexant_spec *spec = codec->spec;
401
402 return snd_hda_input_mux_info(spec->input_mux, uinfo);
403}
404
405static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_value *ucontrol)
407{
408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409 struct conexant_spec *spec = codec->spec;
410 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
411
412 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
413 return 0;
414}
415
416static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_value *ucontrol)
418{
419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 struct conexant_spec *spec = codec->spec;
421 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
422
423 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
424 spec->capsrc_nids[adc_idx],
425 &spec->cur_mux[adc_idx]);
426}
427
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200428static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
429 unsigned int power_state)
430{
431 if (power_state == AC_PWRST_D3)
432 msleep(100);
433 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
434 power_state);
435 /* partial workaround for "azx_get_response timeout" */
436 if (power_state == AC_PWRST_D0)
437 msleep(10);
Takashi Iwai9419ab62013-01-24 17:23:35 +0100438 snd_hda_codec_set_power_to_all(codec, fg, power_state);
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200439}
440
Tobin Davisc9b443d2006-11-14 12:13:39 +0100441static int conexant_init(struct hda_codec *codec)
442{
443 struct conexant_spec *spec = codec->spec;
444 int i;
445
446 for (i = 0; i < spec->num_init_verbs; i++)
447 snd_hda_sequence_write(codec, spec->init_verbs[i]);
448 return 0;
449}
450
451static void conexant_free(struct hda_codec *codec)
452{
Takashi Iwaiee48df52012-06-26 14:54:32 +0200453 struct conexant_spec *spec = codec->spec;
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200454 snd_hda_detach_beep_device(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +0200455 kfree(spec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100456}
457
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200458static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100459 {
460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
461 .name = "Capture Source",
462 .info = conexant_mux_enum_info,
463 .get = conexant_mux_enum_get,
464 .put = conexant_mux_enum_put
465 },
466 {}
467};
468
Takashi Iwai9322ca52012-02-03 14:28:01 +0100469static const char * const slave_pfxs[] = {
Takashi Iwaif37bc7a2012-11-08 15:59:23 +0100470 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100471 NULL
472};
473
Tobin Davisc9b443d2006-11-14 12:13:39 +0100474static int conexant_build_controls(struct hda_codec *codec)
475{
476 struct conexant_spec *spec = codec->spec;
477 unsigned int i;
478 int err;
479
480 for (i = 0; i < spec->num_mixers; i++) {
481 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
482 if (err < 0)
483 return err;
484 }
485 if (spec->multiout.dig_out_nid) {
486 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600487 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100488 spec->multiout.dig_out_nid);
489 if (err < 0)
490 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100491 err = snd_hda_create_spdif_share_sw(codec,
492 &spec->multiout);
493 if (err < 0)
494 return err;
495 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100496 }
497 if (spec->dig_in_nid) {
498 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
499 if (err < 0)
500 return err;
501 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100502
503 /* if we have no master control, let's create it */
504 if (spec->vmaster_nid &&
505 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
506 unsigned int vmaster_tlv[4];
507 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
508 HDA_OUTPUT, vmaster_tlv);
509 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100510 vmaster_tlv, slave_pfxs,
511 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100512 if (err < 0)
513 return err;
514 }
515 if (spec->vmaster_nid &&
516 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100517 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
518 NULL, slave_pfxs,
519 "Playback Switch");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100520 if (err < 0)
521 return err;
522 }
523
Takashi Iwaib880c742009-03-10 14:41:05 +0100524 if (spec->input_mux) {
525 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
526 if (err < 0)
527 return err;
528 }
529
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100530 err = add_beep_ctls(codec);
531 if (err < 0)
532 return err;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200533
Tobin Davisc9b443d2006-11-14 12:13:39 +0100534 return 0;
535}
536
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200537static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100538 .build_controls = conexant_build_controls,
539 .build_pcms = conexant_build_pcms,
540 .init = conexant_init,
541 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200542 .set_power_state = conexant_set_power,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100543};
544
Takashi Iwai6764bce2011-05-13 16:52:25 +0200545static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100546/*
547 * EAPD control
548 * the private value = nid | (invert << 8)
549 */
550
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200551#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100552
Tobin Davis82f30042007-02-13 12:45:44 +0100553static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100554 struct snd_ctl_elem_value *ucontrol)
555{
556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
557 struct conexant_spec *spec = codec->spec;
558 int invert = (kcontrol->private_value >> 8) & 1;
559 if (invert)
560 ucontrol->value.integer.value[0] = !spec->cur_eapd;
561 else
562 ucontrol->value.integer.value[0] = spec->cur_eapd;
563 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100564
Tobin Davisc9b443d2006-11-14 12:13:39 +0100565}
566
Tobin Davis82f30042007-02-13 12:45:44 +0100567static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100568 struct snd_ctl_elem_value *ucontrol)
569{
570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
571 struct conexant_spec *spec = codec->spec;
572 int invert = (kcontrol->private_value >> 8) & 1;
573 hda_nid_t nid = kcontrol->private_value & 0xff;
574 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100575
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100576 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100577 if (invert)
578 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200579 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100580 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100581
Tobin Davisc9b443d2006-11-14 12:13:39 +0100582 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200583 snd_hda_codec_write_cache(codec, nid,
584 0, AC_VERB_SET_EAPD_BTLENABLE,
585 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100586 return 1;
587}
588
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100589/* controls for test mode */
590#ifdef CONFIG_SND_DEBUG
591
Tobin Davis82f30042007-02-13 12:45:44 +0100592#define CXT_EAPD_SWITCH(xname, nid, mask) \
593 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
594 .info = cxt_eapd_info, \
595 .get = cxt_eapd_get, \
596 .put = cxt_eapd_put, \
597 .private_value = nid | (mask<<16) }
598
599
600
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
602 struct snd_ctl_elem_info *uinfo)
603{
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 struct conexant_spec *spec = codec->spec;
606 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
607 spec->num_channel_mode);
608}
609
610static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct conexant_spec *spec = codec->spec;
615 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
616 spec->num_channel_mode,
617 spec->multiout.max_channels);
618}
619
620static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
621 struct snd_ctl_elem_value *ucontrol)
622{
623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
624 struct conexant_spec *spec = codec->spec;
625 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
626 spec->num_channel_mode,
627 &spec->multiout.max_channels);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628 return err;
629}
630
631#define CXT_PIN_MODE(xname, nid, dir) \
632 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
633 .info = conexant_ch_mode_info, \
634 .get = conexant_ch_mode_get, \
635 .put = conexant_ch_mode_put, \
636 .private_value = nid | (dir<<16) }
637
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100638#endif /* CONFIG_SND_DEBUG */
639
Tobin Davisc9b443d2006-11-14 12:13:39 +0100640/* Conexant 5045 specific */
641
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200642static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
643static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
644static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100645#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100646
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200647static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100648 { 2, NULL },
649};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100650
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200651static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100652 .num_items = 2,
653 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200654 { "Internal Mic", 0x1 },
655 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100656 }
657};
658
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200659static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200660 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100661 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200662 { "Internal Mic", 0x1 },
663 { "Mic", 0x2 },
664 { "Line", 0x3 },
665 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100666 }
667};
668
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200669static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100670 .num_items = 2,
671 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200672 { "Mic", 0x1 },
673 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100674 }
675};
676
Tobin Davisc9b443d2006-11-14 12:13:39 +0100677/* turn on/off EAPD (+ mute HP) as a master switch */
678static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
679 struct snd_ctl_elem_value *ucontrol)
680{
681 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
682 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100683 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100684
Tobin Davis82f30042007-02-13 12:45:44 +0100685 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686 return 0;
687
Tobin Davis82f30042007-02-13 12:45:44 +0100688 /* toggle internal speakers mute depending of presence of
689 * the headphone jack
690 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200691 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
692 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
693 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100694
Takashi Iwai47fd8302007-08-10 17:11:07 +0200695 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
696 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
697 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100698 return 1;
699}
700
701/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200702static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200703 .ops = &snd_hda_bind_vol,
704 .values = {
705 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
706 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
707 0
708 },
709};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100710
Tobin Davis7f296732007-03-12 11:39:01 +0100711/* toggle input of built-in and mic jack appropriately */
712static void cxt5045_hp_automic(struct hda_codec *codec)
713{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200714 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100715 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
716 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
717 {}
718 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200719 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100720 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
722 {}
723 };
724 unsigned int present;
725
Takashi Iwaid56757a2009-11-18 08:00:14 +0100726 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100727 if (present)
728 snd_hda_sequence_write(codec, mic_jack_on);
729 else
730 snd_hda_sequence_write(codec, mic_jack_off);
731}
732
Tobin Davisc9b443d2006-11-14 12:13:39 +0100733
734/* mute internal speaker if HP is plugged */
735static void cxt5045_hp_automute(struct hda_codec *codec)
736{
Tobin Davis82f30042007-02-13 12:45:44 +0100737 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100738 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100739
Takashi Iwaid56757a2009-11-18 08:00:14 +0100740 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100741
Takashi Iwai47fd8302007-08-10 17:11:07 +0200742 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
743 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
744 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100745}
746
747/* unsolicited event for HP jack sensing */
748static void cxt5045_hp_unsol_event(struct hda_codec *codec,
749 unsigned int res)
750{
751 res >>= 26;
752 switch (res) {
753 case CONEXANT_HP_EVENT:
754 cxt5045_hp_automute(codec);
755 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100756 case CONEXANT_MIC_EVENT:
757 cxt5045_hp_automic(codec);
758 break;
759
Tobin Davisc9b443d2006-11-14 12:13:39 +0100760 }
761}
762
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200763static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200764 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
765 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200766 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
767 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100768 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
769 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100770 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
771 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200772 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100773 {
774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
775 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100776 .info = cxt_eapd_info,
777 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100778 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100779 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100780 },
781
782 {}
783};
784
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200785static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200786 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
787 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200788
Jiang Zhe5218c892008-01-17 11:18:41 +0100789 {}
790};
791
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200792static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200793 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
794 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100795 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
796 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100797 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
798 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100799 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
800 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100801 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
802 {
803 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
804 .name = "Master Playback Switch",
805 .info = cxt_eapd_info,
806 .get = cxt_eapd_get,
807 .put = cxt5045_hp_master_sw_put,
808 .private_value = 0x10,
809 },
810
811 {}
812};
813
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200814static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100815 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200816 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100817 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200819 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
820 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
821 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
822 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
823 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
824 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
826 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
827 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100828 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100829 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100830 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100831 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
832 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100833 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100834 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100835 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100836 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100837 { } /* end */
838};
839
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200840static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100841 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100842 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
843 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
844 /* Line In,HP, Amp */
845 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
846 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
847 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
848 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
849 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
851 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
852 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100854 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100855 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
856 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
857 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
858 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100859 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100860 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
861 /* EAPD */
862 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
863 { } /* end */
864};
Tobin Davis7f296732007-03-12 11:39:01 +0100865
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200866static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100867 /* pin sensing on HP jack */
868 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200869 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100870};
871
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200872static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100873 /* pin sensing on HP jack */
874 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200875 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100876};
877
Tobin Davisc9b443d2006-11-14 12:13:39 +0100878#ifdef CONFIG_SND_DEBUG
879/* Test configuration for debugging, modelled after the ALC260 test
880 * configuration.
881 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200882static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100883 .num_items = 5,
884 .items = {
885 { "MIXER", 0x0 },
886 { "MIC1 pin", 0x1 },
887 { "LINE1 pin", 0x2 },
888 { "HP-OUT pin", 0x3 },
889 { "CD pin", 0x4 },
890 },
891};
892
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200893static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100894
895 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100896 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
897 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200898 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
899 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
900 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
901 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100902
903 /* Modes for retasking pin widgets */
904 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
905 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
906
Tobin Davis82f30042007-02-13 12:45:44 +0100907 /* EAPD Switch Control */
908 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
909
Tobin Davisc9b443d2006-11-14 12:13:39 +0100910 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100911
Michael Karcher250f3272012-04-06 15:34:20 +0200912 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
913 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
914 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
915 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
916 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
917 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
918 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
919 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
920 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
921 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100922 {
923 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
924 .name = "Input Source",
925 .info = conexant_mux_enum_info,
926 .get = conexant_mux_enum_get,
927 .put = conexant_mux_enum_put,
928 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200929 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200930 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
931 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100932 { } /* end */
933};
934
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200935static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100936 /* Set connections */
937 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
938 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
939 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100940 /* Enable retasking pins as output, initially without power amp */
941 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100942 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100943
944 /* Disable digital (SPDIF) pins initially, but users can enable
945 * them via a mixer switch. In the case of SPDIF-out, this initverb
946 * payload also sets the generation to 0, output to be in "consumer"
947 * PCM format, copyright asserted, no pre-emphasis and no validity
948 * control.
949 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100950 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
951 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100952
Tobin Davisc9b443d2006-11-14 12:13:39 +0100953 /* Unmute retasking pin widget output buffers since the default
954 * state appears to be output. As the pin mode is changed by the
955 * user the pin mode control will take care of enabling the pin's
956 * input/output buffers as needed.
957 */
958 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
959 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
960
961 /* Mute capture amp left and right */
962 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
963
964 /* Set ADC connection select to match default mixer setting (mic1
965 * pin)
966 */
Michael Karcher250f3272012-04-06 15:34:20 +0200967 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
968 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100969
970 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +0200971 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100972 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
973 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
974 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
976
977 { }
978};
979#endif
980
981
982/* initialize jack-sensing, too */
983static int cxt5045_init(struct hda_codec *codec)
984{
985 conexant_init(codec);
986 cxt5045_hp_automute(codec);
987 return 0;
988}
989
990
991enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100992 CXT5045_LAPTOP_HPSENSE,
993 CXT5045_LAPTOP_MICSENSE,
994 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100995 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +0100996 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100997#ifdef CONFIG_SND_DEBUG
998 CXT5045_TEST,
999#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001000 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001001 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001002};
1003
Takashi Iwaiea734962011-01-17 11:29:34 +01001004static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001005 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1006 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1007 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1008 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001009 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001010#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001011 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001013 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001014};
1015
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001016static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001017 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001018 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001019 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001020 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1021 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001022 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1023 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001024 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1025 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1026 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001027 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1028 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001029 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001030 {}
1031};
1032
1033static int patch_cxt5045(struct hda_codec *codec)
1034{
1035 struct conexant_spec *spec;
1036 int board_config;
1037
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001038 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1039 cxt5045_models,
1040 cxt5045_cfg_tbl);
1041 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001042 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001043 if (board_config == CXT5045_AUTO)
1044 return patch_conexant_auto(codec);
1045
Tobin Davisc9b443d2006-11-14 12:13:39 +01001046 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1047 if (!spec)
1048 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001049 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001050 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051
1052 spec->multiout.max_channels = 2;
1053 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1054 spec->multiout.dac_nids = cxt5045_dac_nids;
1055 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1056 spec->num_adc_nids = 1;
1057 spec->adc_nids = cxt5045_adc_nids;
1058 spec->capsrc_nids = cxt5045_capsrc_nids;
1059 spec->input_mux = &cxt5045_capture_source;
1060 spec->num_mixers = 1;
1061 spec->mixers[0] = cxt5045_mixers;
1062 spec->num_init_verbs = 1;
1063 spec->init_verbs[0] = cxt5045_init_verbs;
1064 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001065 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1066 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001067
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001068 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001069
1070 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001073 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001074 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001075 spec->input_mux = &cxt5045_capture_source;
1076 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001077 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1078 spec->mixers[0] = cxt5045_mixers;
1079 codec->patch_ops.init = cxt5045_init;
1080 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001081 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001082 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001083 spec->input_mux = &cxt5045_capture_source;
1084 spec->num_init_verbs = 2;
1085 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001086 spec->mixers[0] = cxt5045_mixers;
1087 codec->patch_ops.init = cxt5045_init;
1088 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001089 default:
1090 case CXT5045_LAPTOP_HPMICSENSE:
1091 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1092 spec->input_mux = &cxt5045_capture_source;
1093 spec->num_init_verbs = 3;
1094 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1095 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1096 spec->mixers[0] = cxt5045_mixers;
1097 codec->patch_ops.init = cxt5045_init;
1098 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001099 case CXT5045_BENQ:
1100 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1101 spec->input_mux = &cxt5045_capture_source_benq;
1102 spec->num_init_verbs = 1;
1103 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1104 spec->mixers[0] = cxt5045_mixers;
1105 spec->mixers[1] = cxt5045_benq_mixers;
1106 spec->num_mixers = 2;
1107 codec->patch_ops.init = cxt5045_init;
1108 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001109 case CXT5045_LAPTOP_HP530:
1110 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1111 spec->input_mux = &cxt5045_capture_source_hp530;
1112 spec->num_init_verbs = 2;
1113 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1114 spec->mixers[0] = cxt5045_mixers_hp530;
1115 codec->patch_ops.init = cxt5045_init;
1116 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117#ifdef CONFIG_SND_DEBUG
1118 case CXT5045_TEST:
1119 spec->input_mux = &cxt5045_test_capture_source;
1120 spec->mixers[0] = cxt5045_test_mixer;
1121 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001122 break;
1123
Tobin Davisc9b443d2006-11-14 12:13:39 +01001124#endif
1125 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001126
Takashi Iwai031005f2008-06-26 14:49:58 +02001127 switch (codec->subsystem_id >> 16) {
1128 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001129 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001130 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001131 case 0x17aa:
1132 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1133 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1134 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001135 */
1136 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1137 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1138 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1139 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1140 (1 << AC_AMPCAP_MUTE_SHIFT));
1141 break;
1142 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001143
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001144 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01001145 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001146
Tobin Davisc9b443d2006-11-14 12:13:39 +01001147 return 0;
1148}
1149
1150
1151/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001152#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001154static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1155static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1156static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001158static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001159 { 2, NULL },
1160};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001161
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001162static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001163 .num_items = 2,
1164 .items = {
1165 { "ExtMic", 0x2 },
1166 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001167 }
1168};
1169
1170/* turn on/off EAPD (+ mute HP) as a master switch */
1171static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1172 struct snd_ctl_elem_value *ucontrol)
1173{
1174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1175 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001176 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001177
Tobin Davis82f30042007-02-13 12:45:44 +01001178 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001179 return 0;
1180
Tobin Davis82f30042007-02-13 12:45:44 +01001181 /* toggle internal speakers mute depending of presence of
1182 * the headphone jack
1183 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001184 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001185 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1186 * pin widgets unlike other codecs. In this case, we need to
1187 * set index 0x01 for the volume from the mixer amp 0x19.
1188 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001189 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001190 HDA_AMP_MUTE, bits);
1191 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1192 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1193 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001194 return 1;
1195}
1196
Tobin Davisc9b443d2006-11-14 12:13:39 +01001197/* mute internal speaker if HP is plugged */
1198static void cxt5047_hp_automute(struct hda_codec *codec)
1199{
Tobin Davis82f30042007-02-13 12:45:44 +01001200 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001201 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001202
Takashi Iwaid56757a2009-11-18 08:00:14 +01001203 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001204
Takashi Iwai47fd8302007-08-10 17:11:07 +02001205 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001206 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001207 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001208 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001209}
1210
1211/* toggle input of built-in and mic jack appropriately */
1212static void cxt5047_hp_automic(struct hda_codec *codec)
1213{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001214 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001215 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1216 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001217 {}
1218 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001219 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001220 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1221 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222 {}
1223 };
1224 unsigned int present;
1225
Takashi Iwaid56757a2009-11-18 08:00:14 +01001226 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001227 if (present)
1228 snd_hda_sequence_write(codec, mic_jack_on);
1229 else
1230 snd_hda_sequence_write(codec, mic_jack_off);
1231}
1232
1233/* unsolicited event for HP jack sensing */
1234static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1235 unsigned int res)
1236{
Marc Boucher9f113e02008-01-22 15:18:08 +01001237 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001238 case CONEXANT_HP_EVENT:
1239 cxt5047_hp_automute(codec);
1240 break;
1241 case CONEXANT_MIC_EVENT:
1242 cxt5047_hp_automic(codec);
1243 break;
1244 }
1245}
1246
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001247static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001248 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1249 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001250 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001251 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1252 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1253 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1254 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001255 {
1256 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1257 .name = "Master Playback Switch",
1258 .info = cxt_eapd_info,
1259 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001260 .put = cxt5047_hp_master_sw_put,
1261 .private_value = 0x13,
1262 },
1263
1264 {}
1265};
1266
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001267static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001268 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001269 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001270 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1271 {}
1272};
1273
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001274static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001275 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276 { } /* end */
1277};
1278
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001279static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280 /* Line in, Mic, Built-in Mic */
1281 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1282 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1283 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001284 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001285 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001286 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1287 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001288 /* Record selector: Mic */
1289 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1290 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1291 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1292 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001293 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1294 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1295 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1296 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 /* SPDIF route: PCM */
1298 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001299 /* Enable unsolicited events */
1300 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1301 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001302 { } /* end */
1303};
1304
1305/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001306static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001307 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308 {}
1309};
1310
1311/* Test configuration for debugging, modelled after the ALC260 test
1312 * configuration.
1313 */
1314#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001315static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001316 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001317 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001318 { "LINE1 pin", 0x0 },
1319 { "MIC1 pin", 0x1 },
1320 { "MIC2 pin", 0x2 },
1321 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001322 },
1323};
1324
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001325static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001326
1327 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001328 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1329 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1330 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1331 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1333 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1334 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1335 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001336 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1337 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1338 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340
1341 /* Modes for retasking pin widgets */
1342 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1343 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1344
Tobin Davis82f30042007-02-13 12:45:44 +01001345 /* EAPD Switch Control */
1346 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1347
Tobin Davisc9b443d2006-11-14 12:13:39 +01001348 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001349 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1350 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1351 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1352 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1353 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1354 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1355 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1356 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357
Tobin Davis82f30042007-02-13 12:45:44 +01001358 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1359 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1360 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1361 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1362 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1363 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1364 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1365 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 {
1367 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1368 .name = "Input Source",
1369 .info = conexant_mux_enum_info,
1370 .get = conexant_mux_enum_get,
1371 .put = conexant_mux_enum_put,
1372 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001373 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001374
Tobin Davisc9b443d2006-11-14 12:13:39 +01001375 { } /* end */
1376};
1377
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001378static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001379 /* Enable retasking pins as output, initially without power amp */
1380 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1381 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1382 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1383
1384 /* Disable digital (SPDIF) pins initially, but users can enable
1385 * them via a mixer switch. In the case of SPDIF-out, this initverb
1386 * payload also sets the generation to 0, output to be in "consumer"
1387 * PCM format, copyright asserted, no pre-emphasis and no validity
1388 * control.
1389 */
1390 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1391
1392 /* Ensure mic1, mic2, line1 pin widgets take input from the
1393 * OUT1 sum bus when acting as an output.
1394 */
1395 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1396 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1397
1398 /* Start with output sum widgets muted and their output gains at min */
1399 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1400 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1401
1402 /* Unmute retasking pin widget output buffers since the default
1403 * state appears to be output. As the pin mode is changed by the
1404 * user the pin mode control will take care of enabling the pin's
1405 * input/output buffers as needed.
1406 */
1407 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1408 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1409 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1410
1411 /* Mute capture amp left and right */
1412 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1413
1414 /* Set ADC connection select to match default mixer setting (mic1
1415 * pin)
1416 */
1417 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1418
1419 /* Mute all inputs to mixer widget (even unconnected ones) */
1420 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1421 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1422 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1423 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1424 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1425 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1426 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1427 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1428
1429 { }
1430};
1431#endif
1432
1433
1434/* initialize jack-sensing, too */
1435static int cxt5047_hp_init(struct hda_codec *codec)
1436{
1437 conexant_init(codec);
1438 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001439 return 0;
1440}
1441
1442
1443enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001444 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1445 CXT5047_LAPTOP_HP, /* Some HP laptops */
1446 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001447#ifdef CONFIG_SND_DEBUG
1448 CXT5047_TEST,
1449#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001450 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001451 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001452};
1453
Takashi Iwaiea734962011-01-17 11:29:34 +01001454static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001455 [CXT5047_LAPTOP] = "laptop",
1456 [CXT5047_LAPTOP_HP] = "laptop-hp",
1457 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001458#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001459 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001460#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001461 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001462};
1463
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001464static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001465 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001466 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1467 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001468 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001469 {}
1470};
1471
1472static int patch_cxt5047(struct hda_codec *codec)
1473{
1474 struct conexant_spec *spec;
1475 int board_config;
1476
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001477 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1478 cxt5047_models,
1479 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001480 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001481 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001482 if (board_config == CXT5047_AUTO)
1483 return patch_conexant_auto(codec);
1484
Tobin Davisc9b443d2006-11-14 12:13:39 +01001485 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1486 if (!spec)
1487 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001488 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001489 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001490
1491 spec->multiout.max_channels = 2;
1492 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1493 spec->multiout.dac_nids = cxt5047_dac_nids;
1494 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1495 spec->num_adc_nids = 1;
1496 spec->adc_nids = cxt5047_adc_nids;
1497 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001498 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001499 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001500 spec->num_init_verbs = 1;
1501 spec->init_verbs[0] = cxt5047_init_verbs;
1502 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001503 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1504 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001505
1506 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001507
Tobin Davisc9b443d2006-11-14 12:13:39 +01001508 switch (board_config) {
1509 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001510 spec->num_mixers = 2;
1511 spec->mixers[1] = cxt5047_hp_spk_mixers;
1512 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001513 break;
1514 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001515 spec->num_mixers = 2;
1516 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001517 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001518 codec->patch_ops.init = cxt5047_hp_init;
1519 break;
1520 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001521 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001522 spec->num_mixers = 2;
1523 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524 spec->num_init_verbs = 2;
1525 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001526 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001527 break;
1528#ifdef CONFIG_SND_DEBUG
1529 case CXT5047_TEST:
1530 spec->input_mux = &cxt5047_test_capture_source;
1531 spec->mixers[0] = cxt5047_test_mixer;
1532 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001533 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001534#endif
1535 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001536 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001537
1538 switch (codec->subsystem_id >> 16) {
1539 case 0x103c:
1540 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1541 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1542 * with 0 dB offset 0x17)
1543 */
1544 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1545 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1546 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1547 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1548 (1 << AC_AMPCAP_MUTE_SHIFT));
1549 break;
1550 }
1551
Tobin Davisc9b443d2006-11-14 12:13:39 +01001552 return 0;
1553}
1554
Takashi Iwai461e2c72008-01-25 11:35:17 +01001555/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001556static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1557static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001558
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001559static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001560 { 2, NULL },
1561};
1562
1563static void cxt5051_update_speaker(struct hda_codec *codec)
1564{
1565 struct conexant_spec *spec = codec->spec;
1566 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001567 /* headphone pin */
1568 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001569 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001570 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001571 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001572 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001573 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001574 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001575 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001576}
1577
1578/* turn on/off EAPD (+ mute HP) as a master switch */
1579static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1580 struct snd_ctl_elem_value *ucontrol)
1581{
1582 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1583
1584 if (!cxt_eapd_put(kcontrol, ucontrol))
1585 return 0;
1586 cxt5051_update_speaker(codec);
1587 return 1;
1588}
1589
1590/* toggle input of built-in and mic jack appropriately */
1591static void cxt5051_portb_automic(struct hda_codec *codec)
1592{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001593 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001594 unsigned int present;
1595
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001596 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001597 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001598 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001599 snd_hda_codec_write(codec, 0x14, 0,
1600 AC_VERB_SET_CONNECT_SEL,
1601 present ? 0x01 : 0x00);
1602}
1603
1604/* switch the current ADC according to the jack state */
1605static void cxt5051_portc_automic(struct hda_codec *codec)
1606{
1607 struct conexant_spec *spec = codec->spec;
1608 unsigned int present;
1609 hda_nid_t new_adc;
1610
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001611 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001612 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001613 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001614 if (present)
1615 spec->cur_adc_idx = 1;
1616 else
1617 spec->cur_adc_idx = 0;
1618 new_adc = spec->adc_nids[spec->cur_adc_idx];
1619 if (spec->cur_adc && spec->cur_adc != new_adc) {
1620 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001621 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001622 spec->cur_adc = new_adc;
1623 snd_hda_codec_setup_stream(codec, new_adc,
1624 spec->cur_adc_stream_tag, 0,
1625 spec->cur_adc_format);
1626 }
1627}
1628
1629/* mute internal speaker if HP is plugged */
1630static void cxt5051_hp_automute(struct hda_codec *codec)
1631{
1632 struct conexant_spec *spec = codec->spec;
1633
Takashi Iwaid56757a2009-11-18 08:00:14 +01001634 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001635 cxt5051_update_speaker(codec);
1636}
1637
1638/* unsolicited event for HP jack sensing */
1639static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1640 unsigned int res)
1641{
1642 switch (res >> 26) {
1643 case CONEXANT_HP_EVENT:
1644 cxt5051_hp_automute(codec);
1645 break;
1646 case CXT5051_PORTB_EVENT:
1647 cxt5051_portb_automic(codec);
1648 break;
1649 case CXT5051_PORTC_EVENT:
1650 cxt5051_portc_automic(codec);
1651 break;
1652 }
1653}
1654
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001655static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001656 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1657 {
1658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1659 .name = "Master Playback Switch",
1660 .info = cxt_eapd_info,
1661 .get = cxt_eapd_get,
1662 .put = cxt5051_hp_master_sw_put,
1663 .private_value = 0x1a,
1664 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001665 {}
1666};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001667
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001668static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001669 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1670 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001671 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1672 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
David Henningssonc40bd912012-09-19 12:19:47 +02001673 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1674 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001675 {}
1676};
1677
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001678static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1680 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001681 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1682 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001683 {}
1684};
1685
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001686static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001687 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1688 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001689 {}
1690};
1691
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001692static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001693 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1694 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001695 {}
1696};
1697
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001698static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001699 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1700 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001701 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1702 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001703 {}
1704};
1705
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001706static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001707 /* Line in, Mic */
1708 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1709 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1710 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1711 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1712 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1713 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1714 /* SPK */
1715 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1716 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1717 /* HP, Amp */
1718 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1719 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1720 /* DAC1 */
1721 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001722 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001723 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1724 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1725 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1726 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001727 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001728 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1729 /* EAPD */
1730 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1731 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001732 { } /* end */
1733};
1734
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001735static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001736 /* Line in, Mic */
1737 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1738 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1739 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1740 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1741 /* SPK */
1742 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1743 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1744 /* HP, Amp */
1745 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1746 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1747 /* DAC1 */
1748 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001749 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1751 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1752 /* SPDIF route: PCM */
1753 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1754 /* EAPD */
1755 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1756 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001757 { } /* end */
1758};
1759
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001760static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001761 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001762 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001763 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1764 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1765 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1766 /* SPK */
1767 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1768 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1769 /* HP, Amp */
1770 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1771 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1772 /* DAC1 */
1773 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001774 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1776 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1777 /* SPDIF route: PCM */
1778 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1779 /* EAPD */
1780 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1781 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001782 { } /* end */
1783};
1784
Takashi Iwai6953e552010-01-24 11:00:27 +01001785static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1786 unsigned int event)
1787{
1788 snd_hda_codec_write(codec, nid, 0,
1789 AC_VERB_SET_UNSOLICITED_ENABLE,
1790 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001791}
1792
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001793static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001794 /* Subwoofer */
1795 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1796 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1797 { } /* end */
1798};
1799
Takashi Iwai461e2c72008-01-25 11:35:17 +01001800/* initialize jack-sensing, too */
1801static int cxt5051_init(struct hda_codec *codec)
1802{
Takashi Iwai6953e552010-01-24 11:00:27 +01001803 struct conexant_spec *spec = codec->spec;
1804
Takashi Iwai461e2c72008-01-25 11:35:17 +01001805 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001806
1807 if (spec->auto_mic & AUTO_MIC_PORTB)
1808 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1809 if (spec->auto_mic & AUTO_MIC_PORTC)
1810 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1811
Takashi Iwai461e2c72008-01-25 11:35:17 +01001812 if (codec->patch_ops.unsol_event) {
1813 cxt5051_hp_automute(codec);
1814 cxt5051_portb_automic(codec);
1815 cxt5051_portc_automic(codec);
1816 }
1817 return 0;
1818}
1819
1820
1821enum {
1822 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1823 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001824 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001825 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001826 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001827 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001828 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001829 CXT5051_MODELS
1830};
1831
Takashi Iwaiea734962011-01-17 11:29:34 +01001832static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001833 [CXT5051_LAPTOP] = "laptop",
1834 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001835 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001836 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001837 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001838 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001839 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001840};
1841
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001842static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001843 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001844 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001845 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001846 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001847 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1848 CXT5051_LAPTOP),
1849 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001850 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001851 {}
1852};
1853
1854static int patch_cxt5051(struct hda_codec *codec)
1855{
1856 struct conexant_spec *spec;
1857 int board_config;
1858
Takashi Iwai6764bce2011-05-13 16:52:25 +02001859 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1860 cxt5051_models,
1861 cxt5051_cfg_tbl);
1862 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001863 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001864 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001865 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001866
Takashi Iwai461e2c72008-01-25 11:35:17 +01001867 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1868 if (!spec)
1869 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001870 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001871 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001872
1873 codec->patch_ops = conexant_patch_ops;
1874 codec->patch_ops.init = cxt5051_init;
1875
1876 spec->multiout.max_channels = 2;
1877 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1878 spec->multiout.dac_nids = cxt5051_dac_nids;
1879 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1880 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1881 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001882 spec->num_mixers = 2;
1883 spec->mixers[0] = cxt5051_capture_mixers;
1884 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001885 spec->num_init_verbs = 1;
1886 spec->init_verbs[0] = cxt5051_init_verbs;
1887 spec->spdif_route = 0;
1888 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1889 spec->channel_mode = cxt5051_modes;
1890 spec->cur_adc = 0;
1891 spec->cur_adc_idx = 0;
1892
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001893 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1894
Takashi Iwai79d7d532009-03-04 09:03:50 +01001895 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1896
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001897 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001898 switch (board_config) {
1899 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001900 spec->mixers[0] = cxt5051_hp_mixers;
1901 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001902 case CXT5051_HP_DV6736:
1903 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1904 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001905 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001906 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001907 case CXT5051_F700:
1908 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1909 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001910 spec->auto_mic = 0;
1911 break;
1912 case CXT5051_TOSHIBA:
1913 spec->mixers[0] = cxt5051_toshiba_mixers;
1914 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001915 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001916 case CXT5051_IDEAPAD:
1917 spec->init_verbs[spec->num_init_verbs++] =
1918 cxt5051_ideapad_init_verbs;
1919 spec->ideapad = 1;
1920 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001921 }
1922
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001923 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01001924 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001925
Takashi Iwai461e2c72008-01-25 11:35:17 +01001926 return 0;
1927}
1928
Daniel Drake0fb67e92009-07-16 14:46:57 +01001929/* Conexant 5066 specific */
1930
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001931static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1932static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1933static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1934static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001935
Daniel Drakedbaccc02009-11-09 15:17:24 +00001936/* OLPC's microphone port is DC coupled for use with external sensors,
1937 * therefore we use a 50% mic bias in order to center the input signal with
1938 * the DC input range of the codec. */
1939#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1940
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001941static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001942 { 2, NULL },
1943};
1944
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001945#define HP_PRESENT_PORT_A (1 << 0)
1946#define HP_PRESENT_PORT_D (1 << 1)
1947#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1948#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1949
Daniel Drake0fb67e92009-07-16 14:46:57 +01001950static void cxt5066_update_speaker(struct hda_codec *codec)
1951{
1952 struct conexant_spec *spec = codec->spec;
1953 unsigned int pinctl;
1954
John Baboval3a253442010-12-02 11:21:31 -05001955 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1956 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001957
1958 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001959 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001960 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001961
1962 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001963 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1964 if (spec->dell_automute || spec->thinkpad) {
1965 /* Mute if Port A is connected */
1966 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05001967 pinctl = 0;
1968 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001969 /* Thinkpad/Dell doesn't give pin-D status */
1970 if (!hp_port_d_present(spec))
1971 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05001972 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001973 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001974
1975 /* CLASS_D AMP */
1976 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001977 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001978}
1979
1980/* turn on/off EAPD (+ mute HP) as a master switch */
1981static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1982 struct snd_ctl_elem_value *ucontrol)
1983{
1984 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1985
1986 if (!cxt_eapd_put(kcontrol, ucontrol))
1987 return 0;
1988
1989 cxt5066_update_speaker(codec);
1990 return 1;
1991}
1992
Daniel Drakec4cfe662010-01-07 13:47:04 +01001993static const struct hda_input_mux cxt5066_olpc_dc_bias = {
1994 .num_items = 3,
1995 .items = {
1996 { "Off", PIN_IN },
1997 { "50%", PIN_VREF50 },
1998 { "80%", PIN_VREF80 },
1999 },
2000};
2001
2002static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2003{
2004 struct conexant_spec *spec = codec->spec;
2005 /* Even though port F is the DC input, the bias is controlled on port B.
2006 * we also leave that port as an active input (but unselected) in DC mode
2007 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002008 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002009 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2010}
2011
Daniel Drake75f89912010-01-07 13:46:25 +01002012/* OLPC defers mic widget control until when capture is started because the
2013 * microphone LED comes on as soon as these settings are put in place. if we
2014 * did this before recording, it would give the false indication that recording
2015 * is happening when it is not. */
2016static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002017{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002018 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002019 if (!spec->recording)
2020 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002021
Daniel Drakec4cfe662010-01-07 13:47:04 +01002022 if (spec->dc_enable) {
2023 /* in DC mode we ignore presence detection and just use the jack
2024 * through our special DC port */
2025 const struct hda_verb enable_dc_mode[] = {
2026 /* disble internal mic, port C */
2027 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2028
2029 /* enable DC capture, port F */
2030 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2031 {},
2032 };
2033
2034 snd_hda_sequence_write(codec, enable_dc_mode);
2035 /* port B input disabled (and bias set) through the following call */
2036 cxt5066_set_olpc_dc_bias(codec);
2037 return;
2038 }
2039
2040 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002041 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002042
Daniel Drake75f89912010-01-07 13:46:25 +01002043 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002044 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002045 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002046
Daniel Drake75f89912010-01-07 13:46:25 +01002047 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002048 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002049 spec->ext_mic_present ? 0 : PIN_VREF80);
2050}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002051
Daniel Drake75f89912010-01-07 13:46:25 +01002052/* toggle input of built-in and mic jack appropriately */
2053static void cxt5066_olpc_automic(struct hda_codec *codec)
2054{
2055 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002056 unsigned int present;
2057
Daniel Drakec4cfe662010-01-07 13:47:04 +01002058 if (spec->dc_enable) /* don't do presence detection in DC mode */
2059 return;
2060
Daniel Drake75f89912010-01-07 13:46:25 +01002061 present = snd_hda_codec_read(codec, 0x1a, 0,
2062 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2063 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002064 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002065 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002066 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002067
2068 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2069 present ? 0 : 1);
2070 spec->ext_mic_present = !!present;
2071
2072 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002073}
2074
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002075/* toggle input of built-in digital mic and mic jack appropriately */
2076static void cxt5066_vostro_automic(struct hda_codec *codec)
2077{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002078 unsigned int present;
2079
2080 struct hda_verb ext_mic_present[] = {
2081 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002082 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002083
2084 /* switch to external mic input */
2085 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2086 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2087
2088 /* disable internal digital mic */
2089 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2090 {}
2091 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002092 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002093 /* enable internal mic, port C */
2094 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2095
2096 /* switch to internal mic input */
2097 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2098
2099 /* disable external mic, port B */
2100 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2101 {}
2102 };
2103
2104 present = snd_hda_jack_detect(codec, 0x1a);
2105 if (present) {
2106 snd_printdd("CXT5066: external microphone detected\n");
2107 snd_hda_sequence_write(codec, ext_mic_present);
2108 } else {
2109 snd_printdd("CXT5066: external microphone absent\n");
2110 snd_hda_sequence_write(codec, ext_mic_absent);
2111 }
2112}
2113
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002114/* toggle input of built-in digital mic and mic jack appropriately */
2115static void cxt5066_ideapad_automic(struct hda_codec *codec)
2116{
2117 unsigned int present;
2118
2119 struct hda_verb ext_mic_present[] = {
2120 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2121 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2122 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2123 {}
2124 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002125 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002126 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2127 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2128 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2129 {}
2130 };
2131
2132 present = snd_hda_jack_detect(codec, 0x1b);
2133 if (present) {
2134 snd_printdd("CXT5066: external microphone detected\n");
2135 snd_hda_sequence_write(codec, ext_mic_present);
2136 } else {
2137 snd_printdd("CXT5066: external microphone absent\n");
2138 snd_hda_sequence_write(codec, ext_mic_absent);
2139 }
2140}
2141
David Henningssona1d69062011-01-21 13:33:28 +01002142
2143/* toggle input of built-in digital mic and mic jack appropriately */
2144static void cxt5066_asus_automic(struct hda_codec *codec)
2145{
2146 unsigned int present;
2147
2148 present = snd_hda_jack_detect(codec, 0x1b);
2149 snd_printdd("CXT5066: external microphone present=%d\n", present);
2150 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2151 present ? 1 : 0);
2152}
2153
2154
David Henningsson048e78a2010-09-02 08:35:47 +02002155/* toggle input of built-in digital mic and mic jack appropriately */
2156static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2157{
2158 unsigned int present;
2159
2160 present = snd_hda_jack_detect(codec, 0x1b);
2161 snd_printdd("CXT5066: external microphone present=%d\n", present);
2162 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2163 present ? 1 : 3);
2164}
2165
2166
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002167/* toggle input of built-in digital mic and mic jack appropriately
2168 order is: external mic -> dock mic -> interal mic */
2169static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2170{
2171 unsigned int ext_present, dock_present;
2172
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002173 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002174 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2175 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2176 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2177 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2178 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2179 {}
2180 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002181 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002182 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2183 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2184 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2185 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2186 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2187 {}
2188 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002189 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002190 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2191 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2192 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2193 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2194 {}
2195 };
2196
2197 ext_present = snd_hda_jack_detect(codec, 0x1b);
2198 dock_present = snd_hda_jack_detect(codec, 0x1a);
2199 if (ext_present) {
2200 snd_printdd("CXT5066: external microphone detected\n");
2201 snd_hda_sequence_write(codec, ext_mic_present);
2202 } else if (dock_present) {
2203 snd_printdd("CXT5066: dock microphone detected\n");
2204 snd_hda_sequence_write(codec, dock_mic_present);
2205 } else {
2206 snd_printdd("CXT5066: external microphone absent\n");
2207 snd_hda_sequence_write(codec, ext_mic_absent);
2208 }
2209}
2210
Daniel Drake0fb67e92009-07-16 14:46:57 +01002211/* mute internal speaker if HP is plugged */
2212static void cxt5066_hp_automute(struct hda_codec *codec)
2213{
2214 struct conexant_spec *spec = codec->spec;
2215 unsigned int portA, portD;
2216
2217 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002218 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002219
2220 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002221 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002222
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002223 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2224 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002225 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2226 portA, portD, spec->hp_present);
2227 cxt5066_update_speaker(codec);
2228}
2229
David Henningsson02b6b5b2011-01-21 13:27:39 +01002230/* Dispatch the right mic autoswitch function */
2231static void cxt5066_automic(struct hda_codec *codec)
2232{
2233 struct conexant_spec *spec = codec->spec;
2234
2235 if (spec->dell_vostro)
2236 cxt5066_vostro_automic(codec);
2237 else if (spec->ideapad)
2238 cxt5066_ideapad_automic(codec);
2239 else if (spec->thinkpad)
2240 cxt5066_thinkpad_automic(codec);
2241 else if (spec->hp_laptop)
2242 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002243 else if (spec->asus)
2244 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002245}
2246
Daniel Drake0fb67e92009-07-16 14:46:57 +01002247/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002248static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002249{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002250 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002251 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2252 switch (res >> 26) {
2253 case CONEXANT_HP_EVENT:
2254 cxt5066_hp_automute(codec);
2255 break;
2256 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002257 /* ignore mic events in DC mode; we're always using the jack */
2258 if (!spec->dc_enable)
2259 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002260 break;
2261 }
2262}
2263
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002264/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002265static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002266{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002267 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002268 switch (res >> 26) {
2269 case CONEXANT_HP_EVENT:
2270 cxt5066_hp_automute(codec);
2271 break;
2272 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002273 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002274 break;
2275 }
2276}
2277
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002278
Daniel Drake0fb67e92009-07-16 14:46:57 +01002279static const struct hda_input_mux cxt5066_analog_mic_boost = {
2280 .num_items = 5,
2281 .items = {
2282 { "0dB", 0 },
2283 { "10dB", 1 },
2284 { "20dB", 2 },
2285 { "30dB", 3 },
2286 { "40dB", 4 },
2287 },
2288};
2289
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002290static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002291{
2292 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002293 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002294 AC_VERB_SET_AMP_GAIN_MUTE,
2295 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2296 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002297 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002298 /* adjust the internal mic as well...it is not through 0x17 */
2299 snd_hda_codec_write_cache(codec, 0x23, 0,
2300 AC_VERB_SET_AMP_GAIN_MUTE,
2301 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2302 cxt5066_analog_mic_boost.
2303 items[spec->mic_boost].index);
2304 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002305}
2306
Daniel Drake0fb67e92009-07-16 14:46:57 +01002307static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2308 struct snd_ctl_elem_info *uinfo)
2309{
2310 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2311}
2312
2313static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2314 struct snd_ctl_elem_value *ucontrol)
2315{
2316 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002317 struct conexant_spec *spec = codec->spec;
2318 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002319 return 0;
2320}
2321
2322static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2323 struct snd_ctl_elem_value *ucontrol)
2324{
2325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002326 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002327 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2328 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002329 idx = ucontrol->value.enumerated.item[0];
2330 if (idx >= imux->num_items)
2331 idx = imux->num_items - 1;
2332
Daniel Drakec4cfe662010-01-07 13:47:04 +01002333 spec->mic_boost = idx;
2334 if (!spec->dc_enable)
2335 cxt5066_set_mic_boost(codec);
2336 return 1;
2337}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002338
Daniel Drakec4cfe662010-01-07 13:47:04 +01002339static void cxt5066_enable_dc(struct hda_codec *codec)
2340{
2341 const struct hda_verb enable_dc_mode[] = {
2342 /* disable gain */
2343 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2344
2345 /* switch to DC input */
2346 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2347 {}
2348 };
2349
2350 /* configure as input source */
2351 snd_hda_sequence_write(codec, enable_dc_mode);
2352 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2353}
2354
2355static void cxt5066_disable_dc(struct hda_codec *codec)
2356{
2357 /* reconfigure input source */
2358 cxt5066_set_mic_boost(codec);
2359 /* automic also selects the right mic if we're recording */
2360 cxt5066_olpc_automic(codec);
2361}
2362
2363static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2364 struct snd_ctl_elem_value *ucontrol)
2365{
2366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2367 struct conexant_spec *spec = codec->spec;
2368 ucontrol->value.integer.value[0] = spec->dc_enable;
2369 return 0;
2370}
2371
2372static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2373 struct snd_ctl_elem_value *ucontrol)
2374{
2375 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2376 struct conexant_spec *spec = codec->spec;
2377 int dc_enable = !!ucontrol->value.integer.value[0];
2378
2379 if (dc_enable == spec->dc_enable)
2380 return 0;
2381
2382 spec->dc_enable = dc_enable;
2383 if (dc_enable)
2384 cxt5066_enable_dc(codec);
2385 else
2386 cxt5066_disable_dc(codec);
2387
2388 return 1;
2389}
2390
2391static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_info *uinfo)
2393{
2394 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2395}
2396
2397static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2398 struct snd_ctl_elem_value *ucontrol)
2399{
2400 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2401 struct conexant_spec *spec = codec->spec;
2402 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2403 return 0;
2404}
2405
2406static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2407 struct snd_ctl_elem_value *ucontrol)
2408{
2409 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2410 struct conexant_spec *spec = codec->spec;
2411 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2412 unsigned int idx;
2413
2414 idx = ucontrol->value.enumerated.item[0];
2415 if (idx >= imux->num_items)
2416 idx = imux->num_items - 1;
2417
2418 spec->dc_input_bias = idx;
2419 if (spec->dc_enable)
2420 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002421 return 1;
2422}
2423
Daniel Drake75f89912010-01-07 13:46:25 +01002424static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2425{
2426 struct conexant_spec *spec = codec->spec;
2427 /* mark as recording and configure the microphone widget so that the
2428 * recording LED comes on. */
2429 spec->recording = 1;
2430 cxt5066_olpc_select_mic(codec);
2431}
2432
2433static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2434{
2435 struct conexant_spec *spec = codec->spec;
2436 const struct hda_verb disable_mics[] = {
2437 /* disable external mic, port B */
2438 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2439
2440 /* disble internal mic, port C */
2441 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002442
2443 /* disable DC capture, port F */
2444 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002445 {},
2446 };
2447
2448 snd_hda_sequence_write(codec, disable_mics);
2449 spec->recording = 0;
2450}
2451
Andy Robinsonf6a24912011-01-24 10:12:37 -05002452static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002453 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002454 int num_pins)
2455{
2456 struct conexant_spec *spec = codec->spec;
2457 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2458 int i;
2459
2460 for (i = 0; i < num_pins; i++, dig_pins++) {
2461 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2462 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2463 continue;
2464 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2465 continue;
Andy Robinsonf6a24912011-01-24 10:12:37 -05002466 }
2467}
2468
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002469static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002470 .num_items = 4,
2471 .items = {
2472 { "Mic B", 0 },
2473 { "Mic C", 1 },
2474 { "Mic E", 2 },
2475 { "Mic F", 3 },
2476 },
2477};
2478
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002479static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002480 .ops = &snd_hda_bind_vol,
2481 .values = {
2482 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2483 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2484 0
2485 },
2486};
2487
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002488static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002489 .ops = &snd_hda_bind_sw,
2490 .values = {
2491 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2492 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2493 0
2494 },
2495};
2496
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002497static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002498 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2499 {}
2500};
2501
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002502static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002503 {
2504 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2505 .name = "Master Playback Volume",
2506 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2507 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2508 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002509 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002510 .info = snd_hda_mixer_amp_volume_info,
2511 .get = snd_hda_mixer_amp_volume_get,
2512 .put = snd_hda_mixer_amp_volume_put,
2513 .tlv = { .c = snd_hda_mixer_amp_tlv },
2514 /* offset by 28 volume steps to limit minimum gain to -46dB */
2515 .private_value =
2516 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2517 },
2518 {}
2519};
2520
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002521static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002522 {
2523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2524 .name = "DC Mode Enable Switch",
2525 .info = snd_ctl_boolean_mono_info,
2526 .get = cxt5066_olpc_dc_get,
2527 .put = cxt5066_olpc_dc_put,
2528 },
2529 {
2530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2531 .name = "DC Input Bias Enum",
2532 .info = cxt5066_olpc_dc_bias_enum_info,
2533 .get = cxt5066_olpc_dc_bias_enum_get,
2534 .put = cxt5066_olpc_dc_bias_enum_put,
2535 },
2536 {}
2537};
2538
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002539static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002540 {
2541 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2542 .name = "Master Playback Switch",
2543 .info = cxt_eapd_info,
2544 .get = cxt_eapd_get,
2545 .put = cxt5066_hp_master_sw_put,
2546 .private_value = 0x1d,
2547 },
2548
2549 {
2550 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002551 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002552 .info = cxt5066_mic_boost_mux_enum_info,
2553 .get = cxt5066_mic_boost_mux_enum_get,
2554 .put = cxt5066_mic_boost_mux_enum_put,
2555 },
2556
2557 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2558 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2559 {}
2560};
2561
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002562static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002563 {
2564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002565 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002566 .info = cxt5066_mic_boost_mux_enum_info,
2567 .get = cxt5066_mic_boost_mux_enum_get,
2568 .put = cxt5066_mic_boost_mux_enum_put,
2569 .private_value = 0x23 | 0x100,
2570 },
2571 {}
2572};
2573
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002574static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002575 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2576 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2577 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2578 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2579
2580 /* Speakers */
2581 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2582 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2583
2584 /* HP, Amp */
2585 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2586 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2587
2588 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2589 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2590
2591 /* DAC1 */
2592 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2593
2594 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2595 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2596 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2597 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2598 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2599 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2600
2601 /* no digital microphone support yet */
2602 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2603
2604 /* Audio input selector */
2605 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2606
2607 /* SPDIF route: PCM */
2608 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2609 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2610
2611 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2612 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2613
2614 /* EAPD */
2615 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2616
2617 /* not handling these yet */
2618 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2619 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2620 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2621 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2622 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2623 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2624 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2625 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2626 { } /* end */
2627};
2628
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002629static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002630 /* Port A: headphones */
2631 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2632 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2633
2634 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002635 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002636
2637 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002638 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002639
2640 /* Port D: unused */
2641 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2642
2643 /* Port E: unused, but has primary EAPD */
2644 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2645 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2646
Daniel Drakec4cfe662010-01-07 13:47:04 +01002647 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002648 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2649
2650 /* Port G: internal speakers */
2651 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2652 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2653
2654 /* DAC1 */
2655 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2656
2657 /* DAC2: unused */
2658 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2659
2660 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2661 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2662 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2663 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2664 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2665 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2666 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2667 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2668 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2669 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2670 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2671 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2672
2673 /* Disable digital microphone port */
2674 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2675
2676 /* Audio input selectors */
2677 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2678 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2679
2680 /* Disable SPDIF */
2681 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2682 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2683
2684 /* enable unsolicited events for Port A and B */
2685 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2686 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2687 { } /* end */
2688};
2689
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002690static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002691 /* Port A: headphones */
2692 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2693 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2694
2695 /* Port B: external microphone */
2696 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2697
2698 /* Port C: unused */
2699 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2700
2701 /* Port D: unused */
2702 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2703
2704 /* Port E: unused, but has primary EAPD */
2705 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2706 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2707
2708 /* Port F: unused */
2709 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2710
2711 /* Port G: internal speakers */
2712 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2713 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2714
2715 /* DAC1 */
2716 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2717
2718 /* DAC2: unused */
2719 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2720
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2723 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2724 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2725 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2726 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2727 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2728 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2729 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2730 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2731 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2732 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2733
2734 /* Digital microphone port */
2735 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2736
2737 /* Audio input selectors */
2738 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2739 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2740
2741 /* Disable SPDIF */
2742 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2743 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2744
2745 /* enable unsolicited events for Port A and B */
2746 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2747 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2748 { } /* end */
2749};
2750
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002751static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002752 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2753 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2754 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2755 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2756
2757 /* Speakers */
2758 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2759 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2760
2761 /* HP, Amp */
2762 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2763 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2764
2765 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2766 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2767
2768 /* DAC1 */
2769 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2770
2771 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2773 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2774 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2777 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2778
2779 /* Audio input selector */
2780 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2781 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2782
2783 /* SPDIF route: PCM */
2784 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2785 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2786
2787 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2788 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2789
2790 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002791 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002792
2793 /* EAPD */
2794 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2795
2796 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2797 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2798 { } /* end */
2799};
2800
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002801static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002802 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2803 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2804
2805 /* Port G: internal speakers */
2806 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2807 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2808
2809 /* Port A: HP, Amp */
2810 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2811 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2812
2813 /* Port B: Mic Dock */
2814 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815
2816 /* Port C: Mic */
2817 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818
2819 /* Port D: HP Dock, Amp */
2820 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2822
2823 /* DAC1 */
2824 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2825
2826 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2828 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2829 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2830 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2831 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2832 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2833
2834 /* Audio input selector */
2835 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2836 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2837
2838 /* SPDIF route: PCM */
2839 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2840 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2841
2842 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2843 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2844
2845 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002846 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002847
2848 /* EAPD */
2849 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2850
2851 /* enable unsolicited events for Port A, B, C and D */
2852 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2853 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2854 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2855 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2856 { } /* end */
2857};
2858
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002859static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002860 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2861 { } /* end */
2862};
2863
David Henningsson048e78a2010-09-02 08:35:47 +02002864
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002865static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002866 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2867 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2868 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2869 { } /* end */
2870};
2871
Daniel Drake0fb67e92009-07-16 14:46:57 +01002872/* initialize jack-sensing, too */
2873static int cxt5066_init(struct hda_codec *codec)
2874{
2875 snd_printdd("CXT5066: init\n");
2876 conexant_init(codec);
2877 if (codec->patch_ops.unsol_event) {
2878 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002879 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002880 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002881 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002882 return 0;
2883}
2884
Daniel Drake75f89912010-01-07 13:46:25 +01002885static int cxt5066_olpc_init(struct hda_codec *codec)
2886{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002887 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002888 snd_printdd("CXT5066: init\n");
2889 conexant_init(codec);
2890 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002891 if (!spec->dc_enable) {
2892 cxt5066_set_mic_boost(codec);
2893 cxt5066_olpc_automic(codec);
2894 } else {
2895 cxt5066_enable_dc(codec);
2896 }
Daniel Drake75f89912010-01-07 13:46:25 +01002897 return 0;
2898}
2899
Daniel Drake0fb67e92009-07-16 14:46:57 +01002900enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002901 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002902 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2903 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002904 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002905 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002906 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002907 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002908 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002909 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002910 CXT5066_MODELS
2911};
2912
Takashi Iwaiea734962011-01-17 11:29:34 +01002913static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002914 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002915 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2916 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002917 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002918 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002919 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002920 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002921 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002922 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002923};
2924
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002925static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002926 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002927 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002928 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002929 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02002930 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002931 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2932 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002933 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002934 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002935 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002936 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002937 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002938 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002939 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2940 CXT5066_LAPTOP),
2941 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002942 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002943 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002944 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson84012652011-03-31 09:36:19 +02002945 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002946 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002947 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002948 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002949 {}
2950};
2951
2952static int patch_cxt5066(struct hda_codec *codec)
2953{
2954 struct conexant_spec *spec;
2955 int board_config;
2956
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002957 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2958 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002959 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02002960 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002961 if (board_config == CXT5066_AUTO)
2962 return patch_conexant_auto(codec);
2963
Daniel Drake0fb67e92009-07-16 14:46:57 +01002964 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2965 if (!spec)
2966 return -ENOMEM;
2967 codec->spec = spec;
2968
2969 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01002970 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002971
2972 spec->dell_automute = 0;
2973 spec->multiout.max_channels = 2;
2974 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2975 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05002976 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2977 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01002978 spec->num_adc_nids = 1;
2979 spec->adc_nids = cxt5066_adc_nids;
2980 spec->capsrc_nids = cxt5066_capsrc_nids;
2981 spec->input_mux = &cxt5066_capture_source;
2982
2983 spec->port_d_mode = PIN_HP;
2984
2985 spec->num_init_verbs = 1;
2986 spec->init_verbs[0] = cxt5066_init_verbs;
2987 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2988 spec->channel_mode = cxt5066_modes;
2989 spec->cur_adc = 0;
2990 spec->cur_adc_idx = 0;
2991
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002992 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2993
Daniel Drake0fb67e92009-07-16 14:46:57 +01002994 switch (board_config) {
2995 default:
2996 case CXT5066_LAPTOP:
2997 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2998 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2999 break;
3000 case CXT5066_DELL_LAPTOP:
3001 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3002 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3003
3004 spec->port_d_mode = PIN_OUT;
3005 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3006 spec->num_init_verbs++;
3007 spec->dell_automute = 1;
3008 break;
David Henningssona1d69062011-01-21 13:33:28 +01003009 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003010 case CXT5066_HP_LAPTOP:
3011 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003012 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003013 spec->init_verbs[spec->num_init_verbs] =
3014 cxt5066_init_verbs_hp_laptop;
3015 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003016 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3017 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003018 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3019 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3020 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003021 if (board_config == CXT5066_HP_LAPTOP)
3022 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003023 /* input source automatically selected */
3024 spec->input_mux = NULL;
3025 spec->port_d_mode = 0;
3026 spec->mic_boost = 3; /* default 30dB gain */
3027 break;
3028
Daniel Drake0fb67e92009-07-16 14:46:57 +01003029 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003030 codec->patch_ops.init = cxt5066_olpc_init;
3031 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3033 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003034 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003035 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3036 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003037 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003038
3039 /* no S/PDIF out */
3040 spec->multiout.dig_out_nid = 0;
3041
3042 /* input source automatically selected */
3043 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003044
3045 /* our capture hooks which allow us to turn on the microphone LED
3046 * at the right time */
3047 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3048 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003049 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003050 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003051 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003052 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003053 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3054 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3055 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003056 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003057 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003058 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003059 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003060
3061 /* no S/PDIF out */
3062 spec->multiout.dig_out_nid = 0;
3063
3064 /* input source automatically selected */
3065 spec->input_mux = NULL;
3066 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003067 case CXT5066_IDEAPAD:
3068 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003069 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003070 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3071 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3072 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3073 spec->port_d_mode = 0;
3074 spec->ideapad = 1;
3075 spec->mic_boost = 2; /* default 20dB gain */
3076
3077 /* no S/PDIF out */
3078 spec->multiout.dig_out_nid = 0;
3079
3080 /* input source automatically selected */
3081 spec->input_mux = NULL;
3082 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003083 case CXT5066_THINKPAD:
3084 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003085 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003086 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3087 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3088 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3089 spec->thinkpad = 1;
3090 spec->port_d_mode = PIN_OUT;
3091 spec->mic_boost = 2; /* default 20dB gain */
3092
3093 /* no S/PDIF out */
3094 spec->multiout.dig_out_nid = 0;
3095
3096 /* input source automatically selected */
3097 spec->input_mux = NULL;
3098 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003099 }
3100
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003101 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01003102 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003103
Daniel Drake0fb67e92009-07-16 14:46:57 +01003104 return 0;
3105}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003106
Takashi Iwaibf92d1d2012-12-20 16:38:19 +01003107#endif /* ENABLE_CXT_STATIC_QUIRKS */
3108
3109
Takashi Iwai461e2c72008-01-25 11:35:17 +01003110/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003111 * Automatic parser for CX20641 & co
3112 */
3113
Takashi Iwaif2e57312010-09-15 10:07:08 +02003114#ifdef CONFIG_SND_HDA_INPUT_BEEP
3115static void cx_auto_parse_beep(struct hda_codec *codec)
3116{
3117 struct conexant_spec *spec = codec->spec;
3118 hda_nid_t nid, end_nid;
3119
3120 end_nid = codec->start_nid + codec->num_nodes;
3121 for (nid = codec->start_nid; nid < end_nid; nid++)
3122 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3123 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3124 break;
3125 }
3126}
3127#else
3128#define cx_auto_parse_beep(codec)
3129#endif
3130
Takashi Iwai254f2962011-10-14 15:22:34 +02003131/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003132static void cx_auto_parse_eapd(struct hda_codec *codec)
3133{
3134 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003135 hda_nid_t nid, end_nid;
3136
3137 end_nid = codec->start_nid + codec->num_nodes;
3138 for (nid = codec->start_nid; nid < end_nid; nid++) {
3139 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3140 continue;
3141 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3142 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003143 spec->eapds[spec->num_eapds++] = nid;
3144 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3145 break;
3146 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003147
3148 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3149 * it's a new chip, where EAPDs are supposed to be associated to
3150 * pins, and we can control EAPD per pin.
3151 * OTOH, if only one or two EAPDs are found, it's an old chip,
3152 * thus it might control over all pins.
3153 */
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003154 if (spec->num_eapds > 2)
3155 spec->gen.own_eapd_ctl = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003156}
3157
Takashi Iwaida339862011-05-13 16:24:15 +02003158static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3159 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003160{
3161 int i;
3162 for (i = 0; i < num_pins; i++) {
3163 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3164 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003165 AC_VERB_SET_EAPD_BTLENABLE,
3166 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003167 }
3168}
3169
Takashi Iwai527c73b2012-03-12 12:38:51 +01003170/* turn on/off EAPD according to Master switch */
3171static void cx_auto_vmaster_hook(void *private_data, int enabled)
3172{
3173 struct hda_codec *codec = private_data;
3174 struct conexant_spec *spec = codec->spec;
3175
Takashi Iwai527c73b2012-03-12 12:38:51 +01003176 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3177}
3178
Takashi Iwaif2e57312010-09-15 10:07:08 +02003179static int cx_auto_build_controls(struct hda_codec *codec)
3180{
3181 int err;
3182
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003183 err = snd_hda_gen_build_controls(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003184 if (err < 0)
3185 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003186
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003187 err = add_beep_ctls(codec);
3188 if (err < 0)
3189 return err;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003190
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003191 return 0;
3192}
3193
Takashi Iwai31b69452013-03-17 10:23:40 +01003194static void cx_auto_free(struct hda_codec *codec)
3195{
3196 snd_hda_detach_beep_device(codec);
3197 snd_hda_gen_free(codec);
3198}
3199
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003200static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003201 .build_controls = cx_auto_build_controls,
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003202 .build_pcms = snd_hda_gen_build_pcms,
3203 .init = snd_hda_gen_init,
Takashi Iwai31b69452013-03-17 10:23:40 +01003204 .free = cx_auto_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02003205 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai164a7ad2013-01-18 18:25:45 +01003206#ifdef CONFIG_PM
3207 .check_power_status = snd_hda_gen_check_power_status,
3208#endif
Takashi Iwaif2e57312010-09-15 10:07:08 +02003209};
3210
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003211/*
3212 * pin fix-up
3213 */
David Henningsson18dcd302012-04-02 15:40:27 +02003214enum {
3215 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02003216 CXT_PINCFG_LENOVO_TP410,
Huacai Chen239fb862012-10-05 21:25:09 +08003217 CXT_PINCFG_LEMOTE_A1004,
3218 CXT_PINCFG_LEMOTE_A1205,
David Henningsson18dcd302012-04-02 15:40:27 +02003219 CXT_FIXUP_STEREO_DMIC,
Huacai Chen239fb862012-10-05 21:25:09 +08003220 CXT_FIXUP_INC_MIC_BOOST,
David Henningsson18dcd302012-04-02 15:40:27 +02003221};
3222
Takashi Iwai23d30f22012-05-07 17:17:32 +02003223static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
3224 const struct hda_fixup *fix, int action)
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003225{
David Henningsson18dcd302012-04-02 15:40:27 +02003226 struct conexant_spec *spec = codec->spec;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003227 spec->gen.inv_dmic_split = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003228}
3229
Huacai Chen239fb862012-10-05 21:25:09 +08003230static void cxt5066_increase_mic_boost(struct hda_codec *codec,
3231 const struct hda_fixup *fix, int action)
3232{
3233 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3234 return;
3235
3236 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
3237 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
3238 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3239 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3240 (0 << AC_AMPCAP_MUTE_SHIFT));
3241}
3242
Takashi Iwaid70f3632012-04-19 15:18:08 +02003243/* ThinkPad X200 & co with cxt5051 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02003244static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003245 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
3246 { 0x17, 0x21a11000 }, /* dock-mic */
3247 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01003248 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003249 {}
3250};
3251
Takashi Iwaid70f3632012-04-19 15:18:08 +02003252/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02003253static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
Takashi Iwaid70f3632012-04-19 15:18:08 +02003254 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
3255 { 0x1a, 0x21a190f0 }, /* dock-mic */
3256 { 0x1c, 0x212140ff }, /* dock-HP */
3257 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003258};
3259
Huacai Chen239fb862012-10-05 21:25:09 +08003260/* Lemote A1004/A1205 with cxt5066 */
3261static const struct hda_pintbl cxt_pincfg_lemote[] = {
3262 { 0x1a, 0x90a10020 }, /* Internal mic */
3263 { 0x1b, 0x03a11020 }, /* External mic */
3264 { 0x1d, 0x400101f0 }, /* Not used */
3265 { 0x1e, 0x40a701f0 }, /* Not used */
3266 { 0x20, 0x404501f0 }, /* Not used */
3267 { 0x22, 0x404401f0 }, /* Not used */
3268 { 0x23, 0x40a701f0 }, /* Not used */
3269 {}
3270};
3271
Takashi Iwai23d30f22012-05-07 17:17:32 +02003272static const struct hda_fixup cxt_fixups[] = {
3273 [CXT_PINCFG_LENOVO_X200] = {
3274 .type = HDA_FIXUP_PINS,
3275 .v.pins = cxt_pincfg_lenovo_x200,
3276 },
3277 [CXT_PINCFG_LENOVO_TP410] = {
3278 .type = HDA_FIXUP_PINS,
3279 .v.pins = cxt_pincfg_lenovo_tp410,
3280 },
Huacai Chen239fb862012-10-05 21:25:09 +08003281 [CXT_PINCFG_LEMOTE_A1004] = {
3282 .type = HDA_FIXUP_PINS,
3283 .chained = true,
3284 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
3285 .v.pins = cxt_pincfg_lemote,
3286 },
3287 [CXT_PINCFG_LEMOTE_A1205] = {
3288 .type = HDA_FIXUP_PINS,
3289 .v.pins = cxt_pincfg_lemote,
3290 },
Takashi Iwai23d30f22012-05-07 17:17:32 +02003291 [CXT_FIXUP_STEREO_DMIC] = {
3292 .type = HDA_FIXUP_FUNC,
3293 .v.func = cxt_fixup_stereo_dmic,
3294 },
Huacai Chen239fb862012-10-05 21:25:09 +08003295 [CXT_FIXUP_INC_MIC_BOOST] = {
3296 .type = HDA_FIXUP_FUNC,
3297 .v.func = cxt5066_increase_mic_boost,
3298 },
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003299};
3300
Takashi Iwaid70f3632012-04-19 15:18:08 +02003301static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003302 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3303 {}
3304};
3305
Takashi Iwaid70f3632012-04-19 15:18:08 +02003306static const struct snd_pci_quirk cxt5066_fixups[] = {
Takashi Iwai63a077e2012-12-12 12:10:01 +01003307 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaid70f3632012-04-19 15:18:08 +02003308 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3309 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3310 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3311 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3312 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02003313 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechelee4db0952012-09-26 01:20:44 +02003314 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningssonb3c5dce2012-06-21 16:03:01 +02003315 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Huacai Chen239fb862012-10-05 21:25:09 +08003316 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3317 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
Takashi Iwaif2e57312010-09-15 10:07:08 +02003318 {}
3319};
3320
Takashi Iwai38681372012-02-27 15:00:58 +01003321/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
3322 * can be created (bko#42825)
3323 */
3324static void add_cx5051_fake_mutes(struct hda_codec *codec)
3325{
3326 static hda_nid_t out_nids[] = {
3327 0x10, 0x11, 0
3328 };
3329 hda_nid_t *p;
3330
3331 for (p = out_nids; *p; p++)
3332 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
3333 AC_AMPCAP_MIN_MUTE |
3334 query_amp_caps(codec, *p, HDA_OUTPUT));
3335}
3336
Takashi Iwaif2e57312010-09-15 10:07:08 +02003337static int patch_conexant_auto(struct hda_codec *codec)
3338{
3339 struct conexant_spec *spec;
3340 int err;
3341
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003342 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3343 codec->chip_name);
3344
Takashi Iwaif2e57312010-09-15 10:07:08 +02003345 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3346 if (!spec)
3347 return -ENOMEM;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003348 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003349 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003350
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003351 cx_auto_parse_beep(codec);
3352 cx_auto_parse_eapd(codec);
3353 if (spec->gen.own_eapd_ctl)
3354 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003355
Takashi Iwai6b452142011-10-14 15:26:20 +02003356 switch (codec->vendor_id) {
3357 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02003358 codec->single_adc_amp = 1;
David Henningsson8be69ef2013-02-14 11:36:39 +01003359 codec->power_filter = NULL; /* Needs speaker amp to D3 to avoid click */
Takashi Iwai6b452142011-10-14 15:26:20 +02003360 break;
Takashi Iwai164a7ad2013-01-18 18:25:45 +01003361 case 0x14f15047:
3362 codec->pin_amp_workaround = 1;
3363 spec->gen.mixer_nid = 0x19;
3364 break;
Takashi Iwai38681372012-02-27 15:00:58 +01003365 case 0x14f15051:
3366 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02003367 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02003368 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
Takashi Iwai38681372012-02-27 15:00:58 +01003369 break;
Michael Karcher51969d62012-04-06 15:34:19 +02003370 default:
3371 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02003372 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
3373 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02003374 }
3375
Takashi Iwaif29735c2012-03-13 07:55:10 +01003376 /* Show mute-led control only on HP laptops
3377 * This is a sort of white-list: on HP laptops, EAPD corresponds
3378 * only to the mute-LED without actualy amp function. Meanwhile,
3379 * others may use EAPD really as an amp switch, so it might be
3380 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01003381 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01003382 switch (codec->subsystem_id >> 16) {
3383 case 0x103c:
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003384 spec->gen.vmaster_mute_enum = 1;
Takashi Iwaif29735c2012-03-13 07:55:10 +01003385 break;
3386 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01003387
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003388 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3389
3390 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003391 if (err < 0)
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003392 goto error;
3393
3394 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3395 if (err < 0)
3396 goto error;
3397
Takashi Iwaif2e57312010-09-15 10:07:08 +02003398 codec->patch_ops = cx_auto_patch_ops;
3399 if (spec->beep_amp)
Takashi Iwaia86b1a2c2013-03-18 11:00:44 +01003400 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
Takashi Iwai4f2864a2012-01-25 11:54:19 +01003401
3402 /* Some laptops with Conexant chips show stalls in S3 resume,
3403 * which falls into the single-cmd mode.
3404 * Better to make reset, then.
3405 */
3406 if (!codec->bus->sync_write) {
3407 snd_printd("hda_codec: "
3408 "Enable sync_write for stable communication\n");
3409 codec->bus->sync_write = 1;
3410 codec->bus->allow_bus_reset = 1;
3411 }
3412
Takashi Iwaif2e57312010-09-15 10:07:08 +02003413 return 0;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003414
3415 error:
3416 snd_hda_gen_free(codec);
3417 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003418}
3419
Takashi Iwaibf92d1d2012-12-20 16:38:19 +01003420#ifndef ENABLE_CXT_STATIC_QUIRKS
3421#define patch_cxt5045 patch_conexant_auto
3422#define patch_cxt5047 patch_conexant_auto
3423#define patch_cxt5051 patch_conexant_auto
3424#define patch_cxt5066 patch_conexant_auto
3425#endif
3426
Takashi Iwaif2e57312010-09-15 10:07:08 +02003427/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01003428 */
3429
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003430static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003431 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3432 .patch = patch_cxt5045 },
3433 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3434 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003435 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3436 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003437 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3438 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003439 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3440 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003441 { .id = 0x14f15068, .name = "CX20584",
3442 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003443 { .id = 0x14f15069, .name = "CX20585",
3444 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02003445 { .id = 0x14f1506c, .name = "CX20588",
3446 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01003447 { .id = 0x14f1506e, .name = "CX20590",
3448 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02003449 { .id = 0x14f15097, .name = "CX20631",
3450 .patch = patch_conexant_auto },
3451 { .id = 0x14f15098, .name = "CX20632",
3452 .patch = patch_conexant_auto },
3453 { .id = 0x14f150a1, .name = "CX20641",
3454 .patch = patch_conexant_auto },
3455 { .id = 0x14f150a2, .name = "CX20642",
3456 .patch = patch_conexant_auto },
3457 { .id = 0x14f150ab, .name = "CX20651",
3458 .patch = patch_conexant_auto },
3459 { .id = 0x14f150ac, .name = "CX20652",
3460 .patch = patch_conexant_auto },
3461 { .id = 0x14f150b8, .name = "CX20664",
3462 .patch = patch_conexant_auto },
3463 { .id = 0x14f150b9, .name = "CX20665",
3464 .patch = patch_conexant_auto },
Takashi Iwai2d825fd2012-05-11 08:39:24 +02003465 { .id = 0x14f1510f, .name = "CX20751/2",
3466 .patch = patch_conexant_auto },
3467 { .id = 0x14f15110, .name = "CX20751/2",
3468 .patch = patch_conexant_auto },
3469 { .id = 0x14f15111, .name = "CX20753/4",
3470 .patch = patch_conexant_auto },
Takashi Iwai42c364a2013-01-21 16:53:37 +01003471 { .id = 0x14f15113, .name = "CX20755",
3472 .patch = patch_conexant_auto },
3473 { .id = 0x14f15114, .name = "CX20756",
3474 .patch = patch_conexant_auto },
3475 { .id = 0x14f15115, .name = "CX20757",
3476 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003477 {} /* terminator */
3478};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003479
3480MODULE_ALIAS("snd-hda-codec-id:14f15045");
3481MODULE_ALIAS("snd-hda-codec-id:14f15047");
3482MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003483MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003484MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003485MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003486MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02003487MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01003488MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02003489MODULE_ALIAS("snd-hda-codec-id:14f15097");
3490MODULE_ALIAS("snd-hda-codec-id:14f15098");
3491MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3492MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3493MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3494MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3495MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3496MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai2d825fd2012-05-11 08:39:24 +02003497MODULE_ALIAS("snd-hda-codec-id:14f1510f");
3498MODULE_ALIAS("snd-hda-codec-id:14f15110");
3499MODULE_ALIAS("snd-hda-codec-id:14f15111");
Takashi Iwai42c364a2013-01-21 16:53:37 +01003500MODULE_ALIAS("snd-hda-codec-id:14f15113");
3501MODULE_ALIAS("snd-hda-codec-id:14f15114");
3502MODULE_ALIAS("snd-hda-codec-id:14f15115");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003503
3504MODULE_LICENSE("GPL");
3505MODULE_DESCRIPTION("Conexant HD-audio codec");
3506
3507static struct hda_codec_preset_list conexant_list = {
3508 .preset = snd_hda_preset_conexant,
3509 .owner = THIS_MODULE,
3510};
3511
3512static int __init patch_conexant_init(void)
3513{
3514 return snd_hda_add_codec_preset(&conexant_list);
3515}
3516
3517static void __exit patch_conexant_exit(void)
3518{
3519 snd_hda_delete_codec_preset(&conexant_list);
3520}
3521
3522module_init(patch_conexant_init)
3523module_exit(patch_conexant_exit)