blob: 1ff5f3cc96b1b083a2a3c82c7663152322105aa2 [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
38#define CXT_PIN_DIR_IN 0x00
39#define CXT_PIN_DIR_OUT 0x01
40#define CXT_PIN_DIR_INOUT 0x02
41#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
42#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
43
44#define CONEXANT_HP_EVENT 0x37
45#define CONEXANT_MIC_EVENT 0x38
Takashi Iwai03697e22011-05-17 09:53:31 +020046#define CONEXANT_LINE_EVENT 0x39
Tobin Davisc9b443d2006-11-14 12:13:39 +010047
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010048/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010049
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010050#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051#define CXT5051_PORTB_EVENT 0x38
52#define CXT5051_PORTC_EVENT 0x39
53
Takashi Iwaifaddaa52010-01-23 22:31:36 +010054#define AUTO_MIC_PORTB (1 << 1)
55#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010056
Tobin Davisc9b443d2006-11-14 12:13:39 +010057struct conexant_spec {
Takashi Iwaiaed523f2012-12-20 16:34:12 +010058 struct hda_gen_spec gen;
59
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020060 const struct snd_kcontrol_new *mixers[5];
Tobin Davisc9b443d2006-11-14 12:13:39 +010061 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010062 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010063
64 const struct hda_verb *init_verbs[5]; /* initialization verbs
65 * don't forget NULL
66 * termination!
67 */
68 unsigned int num_init_verbs;
69
70 /* playback */
71 struct hda_multi_out multiout; /* playback set-up
72 * max_channels, dacs must be set
73 * dig_out_nid and hp_nid are optional
74 */
75 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010076 unsigned int hp_present;
Takashi Iwai03697e22011-05-17 09:53:31 +020077 unsigned int line_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010078 unsigned int auto_mic;
Tobin Davisc9b443d2006-11-14 12:13:39 +010079
80 /* capture */
81 unsigned int num_adc_nids;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020082 const hda_nid_t *adc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010083 hda_nid_t dig_in_nid; /* digital-in NID; optional */
84
Takashi Iwai461e2c72008-01-25 11:35:17 +010085 unsigned int cur_adc_idx;
86 hda_nid_t cur_adc;
87 unsigned int cur_adc_stream_tag;
88 unsigned int cur_adc_format;
89
Takashi Iwai6764bce2011-05-13 16:52:25 +020090 const struct hda_pcm_stream *capture_stream;
91
Tobin Davisc9b443d2006-11-14 12:13:39 +010092 /* capture source */
93 const struct hda_input_mux *input_mux;
Takashi Iwai34cbe3a2011-05-02 11:38:21 +020094 const hda_nid_t *capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +010095 unsigned int cur_mux[3];
96
97 /* channel model */
98 const struct hda_channel_mode *channel_mode;
99 int num_channel_mode;
100
101 /* PCM information */
102 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
103
Tobin Davisc9b443d2006-11-14 12:13:39 +0100104 unsigned int spdif_route;
105
Daniel Drake0fb67e92009-07-16 14:46:57 +0100106 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200107 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500108 unsigned int dell_vostro:1;
109 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200110 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200111 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100112 unsigned int asus:1;
Takashi Iwai6764bce2011-05-13 16:52:25 +0200113
Daniel Drake75f89912010-01-07 13:46:25 +0100114 unsigned int ext_mic_present;
115 unsigned int recording;
116 void (*capture_prepare)(struct hda_codec *codec);
117 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100118
119 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
120 * through the microphone jack.
121 * When the user enables this through a mixer switch, both internal and
122 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
123 * we also allow the bias to be configured through a separate mixer
124 * control. */
125 unsigned int dc_enable;
126 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
127 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200128
129 unsigned int beep_amp;
Takashi Iwai19110592011-07-11 14:46:44 +0200130
131 /* extra EAPD pins */
132 unsigned int num_eapds;
133 hda_nid_t eapds[4];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100134};
135
136static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
137 struct hda_codec *codec,
138 struct snd_pcm_substream *substream)
139{
140 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100141 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
142 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100143}
144
145static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 unsigned int stream_tag,
148 unsigned int format,
149 struct snd_pcm_substream *substream)
150{
151 struct conexant_spec *spec = codec->spec;
152 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
153 stream_tag,
154 format, substream);
155}
156
157static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 struct snd_pcm_substream *substream)
160{
161 struct conexant_spec *spec = codec->spec;
162 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
163}
164
165/*
166 * Digital out
167 */
168static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
170 struct snd_pcm_substream *substream)
171{
172 struct conexant_spec *spec = codec->spec;
173 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
174}
175
176static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 struct snd_pcm_substream *substream)
179{
180 struct conexant_spec *spec = codec->spec;
181 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
182}
183
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200184static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
185 struct hda_codec *codec,
186 unsigned int stream_tag,
187 unsigned int format,
188 struct snd_pcm_substream *substream)
189{
190 struct conexant_spec *spec = codec->spec;
191 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
192 stream_tag,
193 format, substream);
194}
195
Tobin Davisc9b443d2006-11-14 12:13:39 +0100196/*
197 * Analog capture
198 */
199static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
200 struct hda_codec *codec,
201 unsigned int stream_tag,
202 unsigned int format,
203 struct snd_pcm_substream *substream)
204{
205 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100206 if (spec->capture_prepare)
207 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100208 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
209 stream_tag, 0, format);
210 return 0;
211}
212
213static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
214 struct hda_codec *codec,
215 struct snd_pcm_substream *substream)
216{
217 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100218 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100219 if (spec->capture_cleanup)
220 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100221 return 0;
222}
223
224
225
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200226static const struct hda_pcm_stream conexant_pcm_analog_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100227 .substreams = 1,
228 .channels_min = 2,
229 .channels_max = 2,
230 .nid = 0, /* fill later */
231 .ops = {
232 .open = conexant_playback_pcm_open,
233 .prepare = conexant_playback_pcm_prepare,
234 .cleanup = conexant_playback_pcm_cleanup
235 },
236};
237
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200238static const struct hda_pcm_stream conexant_pcm_analog_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100239 .substreams = 1,
240 .channels_min = 2,
241 .channels_max = 2,
242 .nid = 0, /* fill later */
243 .ops = {
244 .prepare = conexant_capture_pcm_prepare,
245 .cleanup = conexant_capture_pcm_cleanup
246 },
247};
248
249
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200250static const struct hda_pcm_stream conexant_pcm_digital_playback = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100251 .substreams = 1,
252 .channels_min = 2,
253 .channels_max = 2,
254 .nid = 0, /* fill later */
255 .ops = {
256 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200257 .close = conexant_dig_playback_pcm_close,
258 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100259 },
260};
261
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200262static const struct hda_pcm_stream conexant_pcm_digital_capture = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100263 .substreams = 1,
264 .channels_min = 2,
265 .channels_max = 2,
266 /* NID is set in alc_build_pcms */
267};
268
Takashi Iwai461e2c72008-01-25 11:35:17 +0100269static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
270 struct hda_codec *codec,
271 unsigned int stream_tag,
272 unsigned int format,
273 struct snd_pcm_substream *substream)
274{
275 struct conexant_spec *spec = codec->spec;
276 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
277 spec->cur_adc_stream_tag = stream_tag;
278 spec->cur_adc_format = format;
279 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
280 return 0;
281}
282
283static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
284 struct hda_codec *codec,
285 struct snd_pcm_substream *substream)
286{
287 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100288 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100289 spec->cur_adc = 0;
290 return 0;
291}
292
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200293static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
Takashi Iwai461e2c72008-01-25 11:35:17 +0100294 .substreams = 1,
295 .channels_min = 2,
296 .channels_max = 2,
297 .nid = 0, /* fill later */
298 .ops = {
299 .prepare = cx5051_capture_pcm_prepare,
300 .cleanup = cx5051_capture_pcm_cleanup
301 },
302};
303
Tobin Davisc9b443d2006-11-14 12:13:39 +0100304static int conexant_build_pcms(struct hda_codec *codec)
305{
306 struct conexant_spec *spec = codec->spec;
307 struct hda_pcm *info = spec->pcm_rec;
308
309 codec->num_pcms = 1;
310 codec->pcm_info = info;
311
312 info->name = "CONEXANT Analog";
313 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
314 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
315 spec->multiout.max_channels;
316 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
317 spec->multiout.dac_nids[0];
Takashi Iwai6764bce2011-05-13 16:52:25 +0200318 if (spec->capture_stream)
319 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
320 else {
321 if (codec->vendor_id == 0x14f15051)
322 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
323 cx5051_pcm_analog_capture;
324 else {
325 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
326 conexant_pcm_analog_capture;
327 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
328 spec->num_adc_nids;
329 }
330 }
Tobin Davisc9b443d2006-11-14 12:13:39 +0100331 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
332
333 if (spec->multiout.dig_out_nid) {
334 info++;
335 codec->num_pcms++;
336 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100337 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100338 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
339 conexant_pcm_digital_playback;
340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
341 spec->multiout.dig_out_nid;
342 if (spec->dig_in_nid) {
343 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
344 conexant_pcm_digital_capture;
345 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
346 spec->dig_in_nid;
347 }
348 }
349
350 return 0;
351}
352
353static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
354 struct snd_ctl_elem_info *uinfo)
355{
356 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357 struct conexant_spec *spec = codec->spec;
358
359 return snd_hda_input_mux_info(spec->input_mux, uinfo);
360}
361
362static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_value *ucontrol)
364{
365 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366 struct conexant_spec *spec = codec->spec;
367 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
368
369 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
370 return 0;
371}
372
373static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
375{
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct conexant_spec *spec = codec->spec;
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379
380 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
381 spec->capsrc_nids[adc_idx],
382 &spec->cur_mux[adc_idx]);
383}
384
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200385static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
386 unsigned int power_state)
387{
388 if (power_state == AC_PWRST_D3)
389 msleep(100);
390 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
391 power_state);
392 /* partial workaround for "azx_get_response timeout" */
393 if (power_state == AC_PWRST_D0)
394 msleep(10);
395 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
396}
397
Tobin Davisc9b443d2006-11-14 12:13:39 +0100398static int conexant_init(struct hda_codec *codec)
399{
400 struct conexant_spec *spec = codec->spec;
401 int i;
402
403 for (i = 0; i < spec->num_init_verbs; i++)
404 snd_hda_sequence_write(codec, spec->init_verbs[i]);
405 return 0;
406}
407
408static void conexant_free(struct hda_codec *codec)
409{
Takashi Iwaiee48df52012-06-26 14:54:32 +0200410 struct conexant_spec *spec = codec->spec;
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200411 snd_hda_detach_beep_device(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +0200412 kfree(spec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100413}
414
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200415static const struct snd_kcontrol_new cxt_capture_mixers[] = {
Takashi Iwaib880c742009-03-10 14:41:05 +0100416 {
417 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
418 .name = "Capture Source",
419 .info = conexant_mux_enum_info,
420 .get = conexant_mux_enum_get,
421 .put = conexant_mux_enum_put
422 },
423 {}
424};
425
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200426#ifdef CONFIG_SND_HDA_INPUT_BEEP
427/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200428static const struct snd_kcontrol_new cxt_beep_mixer[] = {
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200429 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
430 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
431 { } /* end */
432};
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100433/* create beep controls if needed */
434static int add_beep_ctls(struct hda_codec *codec)
435{
436 struct conexant_spec *spec = codec->spec;
437 int err;
438
439 if (spec->beep_amp) {
440 const struct snd_kcontrol_new *knew;
441 for (knew = cxt_beep_mixer; knew->name; knew++) {
442 struct snd_kcontrol *kctl;
443 kctl = snd_ctl_new1(knew, codec);
444 if (!kctl)
445 return -ENOMEM;
446 kctl->private_value = spec->beep_amp;
447 err = snd_hda_ctl_add(codec, 0, kctl);
448 if (err < 0)
449 return err;
450 }
451 }
452 return 0;
453}
454#else
455#define add_beep_ctls(codec) 0
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200456#endif
457
Takashi Iwai9322ca52012-02-03 14:28:01 +0100458static const char * const slave_pfxs[] = {
Takashi Iwaif37bc7a2012-11-08 15:59:23 +0100459 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100460 NULL
461};
462
Tobin Davisc9b443d2006-11-14 12:13:39 +0100463static int conexant_build_controls(struct hda_codec *codec)
464{
465 struct conexant_spec *spec = codec->spec;
466 unsigned int i;
467 int err;
468
469 for (i = 0; i < spec->num_mixers; i++) {
470 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
471 if (err < 0)
472 return err;
473 }
474 if (spec->multiout.dig_out_nid) {
475 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -0600476 spec->multiout.dig_out_nid,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100477 spec->multiout.dig_out_nid);
478 if (err < 0)
479 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100480 err = snd_hda_create_spdif_share_sw(codec,
481 &spec->multiout);
482 if (err < 0)
483 return err;
484 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100485 }
486 if (spec->dig_in_nid) {
487 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
488 if (err < 0)
489 return err;
490 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100491
492 /* if we have no master control, let's create it */
493 if (spec->vmaster_nid &&
494 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
495 unsigned int vmaster_tlv[4];
496 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
497 HDA_OUTPUT, vmaster_tlv);
498 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +0100499 vmaster_tlv, slave_pfxs,
500 "Playback Volume");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100501 if (err < 0)
502 return err;
503 }
504 if (spec->vmaster_nid &&
505 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100506 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
507 NULL, slave_pfxs,
508 "Playback Switch");
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100509 if (err < 0)
510 return err;
511 }
512
Takashi Iwaib880c742009-03-10 14:41:05 +0100513 if (spec->input_mux) {
514 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
515 if (err < 0)
516 return err;
517 }
518
Takashi Iwaiaed523f2012-12-20 16:34:12 +0100519 err = add_beep_ctls(codec);
520 if (err < 0)
521 return err;
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200522
Tobin Davisc9b443d2006-11-14 12:13:39 +0100523 return 0;
524}
525
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200526static const struct hda_codec_ops conexant_patch_ops = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100527 .build_controls = conexant_build_controls,
528 .build_pcms = conexant_build_pcms,
529 .init = conexant_init,
530 .free = conexant_free,
Takashi Iwai4d7fbdb2011-07-26 10:33:10 +0200531 .set_power_state = conexant_set_power,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100532};
533
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200534#ifdef CONFIG_SND_HDA_INPUT_BEEP
535#define set_beep_amp(spec, nid, idx, dir) \
536 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
537#else
538#define set_beep_amp(spec, nid, idx, dir) /* NOP */
539#endif
540
Takashi Iwai6764bce2011-05-13 16:52:25 +0200541static int patch_conexant_auto(struct hda_codec *codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542/*
543 * EAPD control
544 * the private value = nid | (invert << 8)
545 */
546
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200547#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100548
Tobin Davis82f30042007-02-13 12:45:44 +0100549static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100550 struct snd_ctl_elem_value *ucontrol)
551{
552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
553 struct conexant_spec *spec = codec->spec;
554 int invert = (kcontrol->private_value >> 8) & 1;
555 if (invert)
556 ucontrol->value.integer.value[0] = !spec->cur_eapd;
557 else
558 ucontrol->value.integer.value[0] = spec->cur_eapd;
559 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100560
Tobin Davisc9b443d2006-11-14 12:13:39 +0100561}
562
Tobin Davis82f30042007-02-13 12:45:44 +0100563static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100564 struct snd_ctl_elem_value *ucontrol)
565{
566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
567 struct conexant_spec *spec = codec->spec;
568 int invert = (kcontrol->private_value >> 8) & 1;
569 hda_nid_t nid = kcontrol->private_value & 0xff;
570 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100571
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100572 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100573 if (invert)
574 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200575 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100576 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100577
Tobin Davisc9b443d2006-11-14 12:13:39 +0100578 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200579 snd_hda_codec_write_cache(codec, nid,
580 0, AC_VERB_SET_EAPD_BTLENABLE,
581 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100582 return 1;
583}
584
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100585/* controls for test mode */
586#ifdef CONFIG_SND_DEBUG
587
Tobin Davis82f30042007-02-13 12:45:44 +0100588#define CXT_EAPD_SWITCH(xname, nid, mask) \
589 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
590 .info = cxt_eapd_info, \
591 .get = cxt_eapd_get, \
592 .put = cxt_eapd_put, \
593 .private_value = nid | (mask<<16) }
594
595
596
Tobin Davisc9b443d2006-11-14 12:13:39 +0100597static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
598 struct snd_ctl_elem_info *uinfo)
599{
600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
601 struct conexant_spec *spec = codec->spec;
602 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
603 spec->num_channel_mode);
604}
605
606static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
608{
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 struct conexant_spec *spec = codec->spec;
611 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
612 spec->num_channel_mode,
613 spec->multiout.max_channels);
614}
615
616static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
618{
619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620 struct conexant_spec *spec = codec->spec;
621 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
622 spec->num_channel_mode,
623 &spec->multiout.max_channels);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100624 return err;
625}
626
627#define CXT_PIN_MODE(xname, nid, dir) \
628 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
629 .info = conexant_ch_mode_info, \
630 .get = conexant_ch_mode_get, \
631 .put = conexant_ch_mode_put, \
632 .private_value = nid | (dir<<16) }
633
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100634#endif /* CONFIG_SND_DEBUG */
635
Tobin Davisc9b443d2006-11-14 12:13:39 +0100636/* Conexant 5045 specific */
637
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200638static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
639static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
640static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100641#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100642
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200643static const struct hda_channel_mode cxt5045_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +0100644 { 2, NULL },
645};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100646
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200647static const struct hda_input_mux cxt5045_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100648 .num_items = 2,
649 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200650 { "Internal Mic", 0x1 },
651 { "Mic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100652 }
653};
654
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200655static const struct hda_input_mux cxt5045_capture_source_benq = {
Michael Karchere6e03da2012-04-06 15:34:18 +0200656 .num_items = 4,
Jiang Zhe5218c892008-01-17 11:18:41 +0100657 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200658 { "Internal Mic", 0x1 },
659 { "Mic", 0x2 },
660 { "Line", 0x3 },
661 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100662 }
663};
664
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200665static const struct hda_input_mux cxt5045_capture_source_hp530 = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100666 .num_items = 2,
667 .items = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200668 { "Mic", 0x1 },
669 { "Internal Mic", 0x2 },
Jiang zhe2de3c232008-03-06 11:09:09 +0100670 }
671};
672
Tobin Davisc9b443d2006-11-14 12:13:39 +0100673/* turn on/off EAPD (+ mute HP) as a master switch */
674static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_value *ucontrol)
676{
677 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
678 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100679 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680
Tobin Davis82f30042007-02-13 12:45:44 +0100681 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100682 return 0;
683
Tobin Davis82f30042007-02-13 12:45:44 +0100684 /* toggle internal speakers mute depending of presence of
685 * the headphone jack
686 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200687 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
688 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
689 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100690
Takashi Iwai47fd8302007-08-10 17:11:07 +0200691 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
692 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
693 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100694 return 1;
695}
696
697/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200698static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +0200699 .ops = &snd_hda_bind_vol,
700 .values = {
701 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
702 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
703 0
704 },
705};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100706
Tobin Davis7f296732007-03-12 11:39:01 +0100707/* toggle input of built-in and mic jack appropriately */
708static void cxt5045_hp_automic(struct hda_codec *codec)
709{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200710 static const struct hda_verb mic_jack_on[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100711 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
712 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
713 {}
714 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200715 static const struct hda_verb mic_jack_off[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100716 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
718 {}
719 };
720 unsigned int present;
721
Takashi Iwaid56757a2009-11-18 08:00:14 +0100722 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100723 if (present)
724 snd_hda_sequence_write(codec, mic_jack_on);
725 else
726 snd_hda_sequence_write(codec, mic_jack_off);
727}
728
Tobin Davisc9b443d2006-11-14 12:13:39 +0100729
730/* mute internal speaker if HP is plugged */
731static void cxt5045_hp_automute(struct hda_codec *codec)
732{
Tobin Davis82f30042007-02-13 12:45:44 +0100733 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100734 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100735
Takashi Iwaid56757a2009-11-18 08:00:14 +0100736 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100737
Takashi Iwai47fd8302007-08-10 17:11:07 +0200738 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
739 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
740 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100741}
742
743/* unsolicited event for HP jack sensing */
744static void cxt5045_hp_unsol_event(struct hda_codec *codec,
745 unsigned int res)
746{
747 res >>= 26;
748 switch (res) {
749 case CONEXANT_HP_EVENT:
750 cxt5045_hp_automute(codec);
751 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100752 case CONEXANT_MIC_EVENT:
753 cxt5045_hp_automic(codec);
754 break;
755
Tobin Davisc9b443d2006-11-14 12:13:39 +0100756 }
757}
758
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200759static const struct snd_kcontrol_new cxt5045_mixers[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200760 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
761 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200762 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
763 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100764 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
765 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100766 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
767 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200768 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769 {
770 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
771 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100772 .info = cxt_eapd_info,
773 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100774 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100775 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100776 },
777
778 {}
779};
780
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200781static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Michael Karcher3edbbb92012-04-06 15:34:16 +0200782 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
783 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200784
Jiang Zhe5218c892008-01-17 11:18:41 +0100785 {}
786};
787
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200788static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Michael Karchercbf2d282012-04-06 15:34:17 +0200789 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
790 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100791 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
792 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100793 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
794 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100795 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
796 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100797 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
798 {
799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
800 .name = "Master Playback Switch",
801 .info = cxt_eapd_info,
802 .get = cxt_eapd_get,
803 .put = cxt5045_hp_master_sw_put,
804 .private_value = 0x10,
805 },
806
807 {}
808};
809
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200810static const struct hda_verb cxt5045_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100811 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200812 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100813 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100814 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200815 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
816 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
817 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
818 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
822 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
823 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100824 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100825 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100826 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100827 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
828 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100829 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100831 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100832 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100833 { } /* end */
834};
835
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200836static const struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100837 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100838 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
839 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
840 /* Line In,HP, Amp */
841 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
842 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
843 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
844 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
845 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
846 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
847 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
848 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
849 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100850 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100851 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
852 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
853 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
854 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100855 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100856 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
857 /* EAPD */
858 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
859 { } /* end */
860};
Tobin Davis7f296732007-03-12 11:39:01 +0100861
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200862static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100863 /* pin sensing on HP jack */
864 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200865 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100866};
867
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200868static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100869 /* pin sensing on HP jack */
870 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200871 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100872};
873
Tobin Davisc9b443d2006-11-14 12:13:39 +0100874#ifdef CONFIG_SND_DEBUG
875/* Test configuration for debugging, modelled after the ALC260 test
876 * configuration.
877 */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200878static const struct hda_input_mux cxt5045_test_capture_source = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100879 .num_items = 5,
880 .items = {
881 { "MIXER", 0x0 },
882 { "MIC1 pin", 0x1 },
883 { "LINE1 pin", 0x2 },
884 { "HP-OUT pin", 0x3 },
885 { "CD pin", 0x4 },
886 },
887};
888
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200889static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +0100890
891 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100892 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
893 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Michael Karcher250f3272012-04-06 15:34:20 +0200894 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
895 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
896 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
897 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100898
899 /* Modes for retasking pin widgets */
900 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
901 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
902
Tobin Davis82f30042007-02-13 12:45:44 +0100903 /* EAPD Switch Control */
904 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
905
Tobin Davisc9b443d2006-11-14 12:13:39 +0100906 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100907
Michael Karcher250f3272012-04-06 15:34:20 +0200908 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
909 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
910 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
911 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
912 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
913 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
914 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
915 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
916 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
917 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100918 {
919 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
920 .name = "Input Source",
921 .info = conexant_mux_enum_info,
922 .get = conexant_mux_enum_get,
923 .put = conexant_mux_enum_put,
924 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200925 /* Audio input controls */
Michael Karchercbf2d282012-04-06 15:34:17 +0200926 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
927 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100928 { } /* end */
929};
930
Takashi Iwai34cbe3a2011-05-02 11:38:21 +0200931static const struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +0100932 /* Set connections */
933 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
934 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
935 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100936 /* Enable retasking pins as output, initially without power amp */
937 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +0100938 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100939
940 /* Disable digital (SPDIF) pins initially, but users can enable
941 * them via a mixer switch. In the case of SPDIF-out, this initverb
942 * payload also sets the generation to 0, output to be in "consumer"
943 * PCM format, copyright asserted, no pre-emphasis and no validity
944 * control.
945 */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100946 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
947 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100948
Tobin Davisc9b443d2006-11-14 12:13:39 +0100949 /* Unmute retasking pin widget output buffers since the default
950 * state appears to be output. As the pin mode is changed by the
951 * user the pin mode control will take care of enabling the pin's
952 * input/output buffers as needed.
953 */
954 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
955 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
956
957 /* Mute capture amp left and right */
958 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
959
960 /* Set ADC connection select to match default mixer setting (mic1
961 * pin)
962 */
Michael Karcher250f3272012-04-06 15:34:20 +0200963 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
964 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100965
966 /* Mute all inputs to mixer widget (even unconnected ones) */
Michael Karcher250f3272012-04-06 15:34:20 +0200967 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100968 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
969 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
970 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
971 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
972
973 { }
974};
975#endif
976
977
978/* initialize jack-sensing, too */
979static int cxt5045_init(struct hda_codec *codec)
980{
981 conexant_init(codec);
982 cxt5045_hp_automute(codec);
983 return 0;
984}
985
986
987enum {
Marc Boucher15908c32008-01-22 15:15:59 +0100988 CXT5045_LAPTOP_HPSENSE,
989 CXT5045_LAPTOP_MICSENSE,
990 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +0100991 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +0100992 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100993#ifdef CONFIG_SND_DEBUG
994 CXT5045_TEST,
995#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +0200996 CXT5045_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100997 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +0100998};
999
Takashi Iwaiea734962011-01-17 11:29:34 +01001000static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001001 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1002 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1003 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1004 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001005 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001006#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001007 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001008#endif
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001009 [CXT5045_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001010};
1011
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001012static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001013 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001014 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001015 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001016 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1017 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001018 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1019 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001020 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1021 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1022 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001023 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1024 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001025 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001026 {}
1027};
1028
1029static int patch_cxt5045(struct hda_codec *codec)
1030{
1031 struct conexant_spec *spec;
1032 int board_config;
1033
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001034 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1035 cxt5045_models,
1036 cxt5045_cfg_tbl);
1037 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001038 board_config = CXT5045_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001039 if (board_config == CXT5045_AUTO)
1040 return patch_conexant_auto(codec);
1041
Tobin Davisc9b443d2006-11-14 12:13:39 +01001042 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1043 if (!spec)
1044 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001045 codec->spec = spec;
Michael Karcher4f324562012-04-06 15:34:15 +02001046 codec->single_adc_amp = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001047
1048 spec->multiout.max_channels = 2;
1049 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1050 spec->multiout.dac_nids = cxt5045_dac_nids;
1051 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1052 spec->num_adc_nids = 1;
1053 spec->adc_nids = cxt5045_adc_nids;
1054 spec->capsrc_nids = cxt5045_capsrc_nids;
1055 spec->input_mux = &cxt5045_capture_source;
1056 spec->num_mixers = 1;
1057 spec->mixers[0] = cxt5045_mixers;
1058 spec->num_init_verbs = 1;
1059 spec->init_verbs[0] = cxt5045_init_verbs;
1060 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001061 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1062 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001063
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001064 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001065
1066 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001067
Tobin Davisc9b443d2006-11-14 12:13:39 +01001068 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001069 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001070 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071 spec->input_mux = &cxt5045_capture_source;
1072 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001073 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1074 spec->mixers[0] = cxt5045_mixers;
1075 codec->patch_ops.init = cxt5045_init;
1076 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001077 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001078 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001079 spec->input_mux = &cxt5045_capture_source;
1080 spec->num_init_verbs = 2;
1081 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001082 spec->mixers[0] = cxt5045_mixers;
1083 codec->patch_ops.init = cxt5045_init;
1084 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001085 default:
1086 case CXT5045_LAPTOP_HPMICSENSE:
1087 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1088 spec->input_mux = &cxt5045_capture_source;
1089 spec->num_init_verbs = 3;
1090 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1091 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1092 spec->mixers[0] = cxt5045_mixers;
1093 codec->patch_ops.init = cxt5045_init;
1094 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001095 case CXT5045_BENQ:
1096 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1097 spec->input_mux = &cxt5045_capture_source_benq;
1098 spec->num_init_verbs = 1;
1099 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1100 spec->mixers[0] = cxt5045_mixers;
1101 spec->mixers[1] = cxt5045_benq_mixers;
1102 spec->num_mixers = 2;
1103 codec->patch_ops.init = cxt5045_init;
1104 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001105 case CXT5045_LAPTOP_HP530:
1106 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1107 spec->input_mux = &cxt5045_capture_source_hp530;
1108 spec->num_init_verbs = 2;
1109 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1110 spec->mixers[0] = cxt5045_mixers_hp530;
1111 codec->patch_ops.init = cxt5045_init;
1112 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001113#ifdef CONFIG_SND_DEBUG
1114 case CXT5045_TEST:
1115 spec->input_mux = &cxt5045_test_capture_source;
1116 spec->mixers[0] = cxt5045_test_mixer;
1117 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001118 break;
1119
Tobin Davisc9b443d2006-11-14 12:13:39 +01001120#endif
1121 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001122
Takashi Iwai031005f2008-06-26 14:49:58 +02001123 switch (codec->subsystem_id >> 16) {
1124 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001125 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001126 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001127 case 0x17aa:
1128 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1129 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1130 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001131 */
1132 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1133 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1134 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1135 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1136 (1 << AC_AMPCAP_MUTE_SHIFT));
1137 break;
1138 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001139
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001140 if (spec->beep_amp)
1141 snd_hda_attach_beep_device(codec, spec->beep_amp);
1142
Tobin Davisc9b443d2006-11-14 12:13:39 +01001143 return 0;
1144}
1145
1146
1147/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001148#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001149
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001150static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1151static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1152static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001154static const struct hda_channel_mode cxt5047_modes[1] = {
Tobin Davis5cd57522006-11-20 17:42:09 +01001155 { 2, NULL },
1156};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001157
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001158static const struct hda_input_mux cxt5047_toshiba_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001159 .num_items = 2,
1160 .items = {
1161 { "ExtMic", 0x2 },
1162 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001163 }
1164};
1165
1166/* turn on/off EAPD (+ mute HP) as a master switch */
1167static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1168 struct snd_ctl_elem_value *ucontrol)
1169{
1170 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1171 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001172 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001173
Tobin Davis82f30042007-02-13 12:45:44 +01001174 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001175 return 0;
1176
Tobin Davis82f30042007-02-13 12:45:44 +01001177 /* toggle internal speakers mute depending of presence of
1178 * the headphone jack
1179 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001180 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001181 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1182 * pin widgets unlike other codecs. In this case, we need to
1183 * set index 0x01 for the volume from the mixer amp 0x19.
1184 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001185 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001186 HDA_AMP_MUTE, bits);
1187 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1188 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1189 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001190 return 1;
1191}
1192
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193/* mute internal speaker if HP is plugged */
1194static void cxt5047_hp_automute(struct hda_codec *codec)
1195{
Tobin Davis82f30042007-02-13 12:45:44 +01001196 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001197 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001198
Takashi Iwaid56757a2009-11-18 08:00:14 +01001199 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001200
Takashi Iwai47fd8302007-08-10 17:11:07 +02001201 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001202 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001203 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001204 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205}
1206
1207/* toggle input of built-in and mic jack appropriately */
1208static void cxt5047_hp_automic(struct hda_codec *codec)
1209{
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001210 static const struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001211 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1212 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001213 {}
1214 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001215 static const struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001216 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1217 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001218 {}
1219 };
1220 unsigned int present;
1221
Takashi Iwaid56757a2009-11-18 08:00:14 +01001222 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223 if (present)
1224 snd_hda_sequence_write(codec, mic_jack_on);
1225 else
1226 snd_hda_sequence_write(codec, mic_jack_off);
1227}
1228
1229/* unsolicited event for HP jack sensing */
1230static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1231 unsigned int res)
1232{
Marc Boucher9f113e02008-01-22 15:18:08 +01001233 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001234 case CONEXANT_HP_EVENT:
1235 cxt5047_hp_automute(codec);
1236 break;
1237 case CONEXANT_MIC_EVENT:
1238 cxt5047_hp_automic(codec);
1239 break;
1240 }
1241}
1242
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001243static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
Takashi Iwaidf481e42009-03-10 15:35:35 +01001244 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1245 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001246 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1248 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1249 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1250 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001251 {
1252 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1253 .name = "Master Playback Switch",
1254 .info = cxt_eapd_info,
1255 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001256 .put = cxt5047_hp_master_sw_put,
1257 .private_value = 0x13,
1258 },
1259
1260 {}
1261};
1262
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001263static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001264 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001265 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001266 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1267 {}
1268};
1269
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001270static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001271 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001272 { } /* end */
1273};
1274
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001275static const struct hda_verb cxt5047_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276 /* Line in, Mic, Built-in Mic */
1277 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1278 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1279 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001280 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001281 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001282 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1283 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001284 /* Record selector: Mic */
1285 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1286 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1287 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1288 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001289 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1290 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1291 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1292 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001293 /* SPDIF route: PCM */
1294 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001295 /* Enable unsolicited events */
1296 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1297 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001298 { } /* end */
1299};
1300
1301/* configuration for Toshiba Laptops */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001302static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001303 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001304 {}
1305};
1306
1307/* Test configuration for debugging, modelled after the ALC260 test
1308 * configuration.
1309 */
1310#ifdef CONFIG_SND_DEBUG
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001311static const struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001312 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001313 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001314 { "LINE1 pin", 0x0 },
1315 { "MIC1 pin", 0x1 },
1316 { "MIC2 pin", 0x2 },
1317 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001318 },
1319};
1320
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001321static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001322
1323 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001324 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1325 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1326 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1327 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1329 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1330 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1331 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001332 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1333 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1334 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1335 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001336
1337 /* Modes for retasking pin widgets */
1338 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1339 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1340
Tobin Davis82f30042007-02-13 12:45:44 +01001341 /* EAPD Switch Control */
1342 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1343
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001345 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1346 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1347 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1348 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1349 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1350 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1351 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1352 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001353
Tobin Davis82f30042007-02-13 12:45:44 +01001354 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1355 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1356 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1357 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1358 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1359 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1360 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1361 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 {
1363 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1364 .name = "Input Source",
1365 .info = conexant_mux_enum_info,
1366 .get = conexant_mux_enum_get,
1367 .put = conexant_mux_enum_put,
1368 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001369 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001370
Tobin Davisc9b443d2006-11-14 12:13:39 +01001371 { } /* end */
1372};
1373
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001374static const struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001375 /* Enable retasking pins as output, initially without power amp */
1376 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1378 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1379
1380 /* Disable digital (SPDIF) pins initially, but users can enable
1381 * them via a mixer switch. In the case of SPDIF-out, this initverb
1382 * payload also sets the generation to 0, output to be in "consumer"
1383 * PCM format, copyright asserted, no pre-emphasis and no validity
1384 * control.
1385 */
1386 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1387
1388 /* Ensure mic1, mic2, line1 pin widgets take input from the
1389 * OUT1 sum bus when acting as an output.
1390 */
1391 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1392 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1393
1394 /* Start with output sum widgets muted and their output gains at min */
1395 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1396 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1397
1398 /* Unmute retasking pin widget output buffers since the default
1399 * state appears to be output. As the pin mode is changed by the
1400 * user the pin mode control will take care of enabling the pin's
1401 * input/output buffers as needed.
1402 */
1403 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1404 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1405 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1406
1407 /* Mute capture amp left and right */
1408 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1409
1410 /* Set ADC connection select to match default mixer setting (mic1
1411 * pin)
1412 */
1413 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1414
1415 /* Mute all inputs to mixer widget (even unconnected ones) */
1416 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1417 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1418 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1419 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1420 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1421 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1422 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1423 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1424
1425 { }
1426};
1427#endif
1428
1429
1430/* initialize jack-sensing, too */
1431static int cxt5047_hp_init(struct hda_codec *codec)
1432{
1433 conexant_init(codec);
1434 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001435 return 0;
1436}
1437
1438
1439enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001440 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1441 CXT5047_LAPTOP_HP, /* Some HP laptops */
1442 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001443#ifdef CONFIG_SND_DEBUG
1444 CXT5047_TEST,
1445#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001446 CXT5047_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001447 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001448};
1449
Takashi Iwaiea734962011-01-17 11:29:34 +01001450static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001451 [CXT5047_LAPTOP] = "laptop",
1452 [CXT5047_LAPTOP_HP] = "laptop-hp",
1453 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001454#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001455 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001456#endif
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001457 [CXT5047_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001458};
1459
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001460static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001461 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001462 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1463 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001464 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001465 {}
1466};
1467
1468static int patch_cxt5047(struct hda_codec *codec)
1469{
1470 struct conexant_spec *spec;
1471 int board_config;
1472
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001473 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1474 cxt5047_models,
1475 cxt5047_cfg_tbl);
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001476 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001477 board_config = CXT5047_AUTO; /* model=auto as default */
Takashi Iwaifa5dadc2011-05-13 19:33:18 +02001478 if (board_config == CXT5047_AUTO)
1479 return patch_conexant_auto(codec);
1480
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1482 if (!spec)
1483 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001484 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001485 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001486
1487 spec->multiout.max_channels = 2;
1488 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1489 spec->multiout.dac_nids = cxt5047_dac_nids;
1490 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1491 spec->num_adc_nids = 1;
1492 spec->adc_nids = cxt5047_adc_nids;
1493 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001494 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001495 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001496 spec->num_init_verbs = 1;
1497 spec->init_verbs[0] = cxt5047_init_verbs;
1498 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001499 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1500 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001501
1502 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001503
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504 switch (board_config) {
1505 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001506 spec->num_mixers = 2;
1507 spec->mixers[1] = cxt5047_hp_spk_mixers;
1508 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509 break;
1510 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001511 spec->num_mixers = 2;
1512 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001513 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001514 codec->patch_ops.init = cxt5047_hp_init;
1515 break;
1516 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001517 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001518 spec->num_mixers = 2;
1519 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001520 spec->num_init_verbs = 2;
1521 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001522 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001523 break;
1524#ifdef CONFIG_SND_DEBUG
1525 case CXT5047_TEST:
1526 spec->input_mux = &cxt5047_test_capture_source;
1527 spec->mixers[0] = cxt5047_test_mixer;
1528 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001529 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001530#endif
1531 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001532 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001533
1534 switch (codec->subsystem_id >> 16) {
1535 case 0x103c:
1536 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1537 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1538 * with 0 dB offset 0x17)
1539 */
1540 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1541 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1542 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1543 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1544 (1 << AC_AMPCAP_MUTE_SHIFT));
1545 break;
1546 }
1547
Tobin Davisc9b443d2006-11-14 12:13:39 +01001548 return 0;
1549}
1550
Takashi Iwai461e2c72008-01-25 11:35:17 +01001551/* Conexant 5051 specific */
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001552static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1553static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001554
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001555static const struct hda_channel_mode cxt5051_modes[1] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001556 { 2, NULL },
1557};
1558
1559static void cxt5051_update_speaker(struct hda_codec *codec)
1560{
1561 struct conexant_spec *spec = codec->spec;
1562 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001563 /* headphone pin */
1564 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001565 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
Takashi Iwai23d2df52010-01-24 11:19:27 +01001566 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001567 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001568 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
Justin P. Mattocka80581d2012-02-11 05:55:58 -08001569 /* on ideapad there is an additional speaker (subwoofer) to mute */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001570 if (spec->ideapad)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001571 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001572}
1573
1574/* turn on/off EAPD (+ mute HP) as a master switch */
1575static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1576 struct snd_ctl_elem_value *ucontrol)
1577{
1578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1579
1580 if (!cxt_eapd_put(kcontrol, ucontrol))
1581 return 0;
1582 cxt5051_update_speaker(codec);
1583 return 1;
1584}
1585
1586/* toggle input of built-in and mic jack appropriately */
1587static void cxt5051_portb_automic(struct hda_codec *codec)
1588{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001589 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001590 unsigned int present;
1591
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001592 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001593 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001594 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001595 snd_hda_codec_write(codec, 0x14, 0,
1596 AC_VERB_SET_CONNECT_SEL,
1597 present ? 0x01 : 0x00);
1598}
1599
1600/* switch the current ADC according to the jack state */
1601static void cxt5051_portc_automic(struct hda_codec *codec)
1602{
1603 struct conexant_spec *spec = codec->spec;
1604 unsigned int present;
1605 hda_nid_t new_adc;
1606
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001607 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001608 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001609 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001610 if (present)
1611 spec->cur_adc_idx = 1;
1612 else
1613 spec->cur_adc_idx = 0;
1614 new_adc = spec->adc_nids[spec->cur_adc_idx];
1615 if (spec->cur_adc && spec->cur_adc != new_adc) {
1616 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001617 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001618 spec->cur_adc = new_adc;
1619 snd_hda_codec_setup_stream(codec, new_adc,
1620 spec->cur_adc_stream_tag, 0,
1621 spec->cur_adc_format);
1622 }
1623}
1624
1625/* mute internal speaker if HP is plugged */
1626static void cxt5051_hp_automute(struct hda_codec *codec)
1627{
1628 struct conexant_spec *spec = codec->spec;
1629
Takashi Iwaid56757a2009-11-18 08:00:14 +01001630 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001631 cxt5051_update_speaker(codec);
1632}
1633
1634/* unsolicited event for HP jack sensing */
1635static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1636 unsigned int res)
1637{
1638 switch (res >> 26) {
1639 case CONEXANT_HP_EVENT:
1640 cxt5051_hp_automute(codec);
1641 break;
1642 case CXT5051_PORTB_EVENT:
1643 cxt5051_portb_automic(codec);
1644 break;
1645 case CXT5051_PORTC_EVENT:
1646 cxt5051_portc_automic(codec);
1647 break;
1648 }
1649}
1650
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001651static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001652 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1653 {
1654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1655 .name = "Master Playback Switch",
1656 .info = cxt_eapd_info,
1657 .get = cxt_eapd_get,
1658 .put = cxt5051_hp_master_sw_put,
1659 .private_value = 0x1a,
1660 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001661 {}
1662};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001663
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001664static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001665 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1666 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001667 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1668 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
David Henningssonc40bd912012-09-19 12:19:47 +02001669 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1670 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001671 {}
1672};
1673
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001674static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001675 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1676 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001677 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1678 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 {}
1680};
1681
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001682static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001683 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1684 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001685 {}
1686};
1687
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001688static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001689 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1690 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001691 {}
1692};
1693
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001694static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001695 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1696 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001697 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1698 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001699 {}
1700};
1701
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001702static const struct hda_verb cxt5051_init_verbs[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001703 /* Line in, Mic */
1704 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1705 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1706 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1707 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1708 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1709 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1710 /* SPK */
1711 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1712 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1713 /* HP, Amp */
1714 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1715 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1716 /* DAC1 */
1717 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001718 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1721 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1722 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001723 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001724 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1725 /* EAPD */
1726 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1727 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001728 { } /* end */
1729};
1730
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001731static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001732 /* Line in, Mic */
1733 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1734 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1735 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1736 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1737 /* SPK */
1738 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1739 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1740 /* HP, Amp */
1741 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1742 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1743 /* DAC1 */
1744 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001745 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001746 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1747 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1748 /* SPDIF route: PCM */
1749 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1750 /* EAPD */
1751 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1752 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001753 { } /* end */
1754};
1755
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001756static const struct hda_verb cxt5051_f700_init_verbs[] = {
Ken Proxcd9d95a2010-01-08 09:01:47 +01001757 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001758 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001759 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1761 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1762 /* SPK */
1763 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1764 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1765 /* HP, Amp */
1766 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1767 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1768 /* DAC1 */
1769 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001770 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1772 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1773 /* SPDIF route: PCM */
1774 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1775 /* EAPD */
1776 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1777 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001778 { } /* end */
1779};
1780
Takashi Iwai6953e552010-01-24 11:00:27 +01001781static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1782 unsigned int event)
1783{
1784 snd_hda_codec_write(codec, nid, 0,
1785 AC_VERB_SET_UNSOLICITED_ENABLE,
1786 AC_USRSP_EN | event);
Takashi Iwai6953e552010-01-24 11:00:27 +01001787}
1788
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001789static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001790 /* Subwoofer */
1791 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1792 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1793 { } /* end */
1794};
1795
Takashi Iwai461e2c72008-01-25 11:35:17 +01001796/* initialize jack-sensing, too */
1797static int cxt5051_init(struct hda_codec *codec)
1798{
Takashi Iwai6953e552010-01-24 11:00:27 +01001799 struct conexant_spec *spec = codec->spec;
1800
Takashi Iwai461e2c72008-01-25 11:35:17 +01001801 conexant_init(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001802
1803 if (spec->auto_mic & AUTO_MIC_PORTB)
1804 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1805 if (spec->auto_mic & AUTO_MIC_PORTC)
1806 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1807
Takashi Iwai461e2c72008-01-25 11:35:17 +01001808 if (codec->patch_ops.unsol_event) {
1809 cxt5051_hp_automute(codec);
1810 cxt5051_portb_automic(codec);
1811 cxt5051_portc_automic(codec);
1812 }
1813 return 0;
1814}
1815
1816
1817enum {
1818 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1819 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001820 CXT5051_HP_DV6736, /* HP without mic switch */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001821 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001822 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001823 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai6764bce2011-05-13 16:52:25 +02001824 CXT5051_AUTO, /* auto-parser */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001825 CXT5051_MODELS
1826};
1827
Takashi Iwaiea734962011-01-17 11:29:34 +01001828static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001829 [CXT5051_LAPTOP] = "laptop",
1830 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001831 [CXT5051_HP_DV6736] = "hp-dv6736",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001832 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001833 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001834 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai6764bce2011-05-13 16:52:25 +02001835 [CXT5051_AUTO] = "auto",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001836};
1837
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001838static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001839 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001840 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001841 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001842 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001843 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1844 CXT5051_LAPTOP),
1845 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001846 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001847 {}
1848};
1849
1850static int patch_cxt5051(struct hda_codec *codec)
1851{
1852 struct conexant_spec *spec;
1853 int board_config;
1854
Takashi Iwai6764bce2011-05-13 16:52:25 +02001855 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1856 cxt5051_models,
1857 cxt5051_cfg_tbl);
1858 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02001859 board_config = CXT5051_AUTO; /* model=auto as default */
Takashi Iwai1f8458a2011-05-13 17:22:05 +02001860 if (board_config == CXT5051_AUTO)
Takashi Iwai6764bce2011-05-13 16:52:25 +02001861 return patch_conexant_auto(codec);
Takashi Iwai6764bce2011-05-13 16:52:25 +02001862
Takashi Iwai461e2c72008-01-25 11:35:17 +01001863 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1864 if (!spec)
1865 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001866 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001867 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001868
1869 codec->patch_ops = conexant_patch_ops;
1870 codec->patch_ops.init = cxt5051_init;
1871
1872 spec->multiout.max_channels = 2;
1873 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1874 spec->multiout.dac_nids = cxt5051_dac_nids;
1875 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1876 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1877 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001878 spec->num_mixers = 2;
1879 spec->mixers[0] = cxt5051_capture_mixers;
1880 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001881 spec->num_init_verbs = 1;
1882 spec->init_verbs[0] = cxt5051_init_verbs;
1883 spec->spdif_route = 0;
1884 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1885 spec->channel_mode = cxt5051_modes;
1886 spec->cur_adc = 0;
1887 spec->cur_adc_idx = 0;
1888
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001889 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1890
Takashi Iwai79d7d532009-03-04 09:03:50 +01001891 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1892
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001893 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001894 switch (board_config) {
1895 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001896 spec->mixers[0] = cxt5051_hp_mixers;
1897 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001898 case CXT5051_HP_DV6736:
1899 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1900 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001901 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001902 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001903 case CXT5051_F700:
1904 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1905 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001906 spec->auto_mic = 0;
1907 break;
1908 case CXT5051_TOSHIBA:
1909 spec->mixers[0] = cxt5051_toshiba_mixers;
1910 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001911 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001912 case CXT5051_IDEAPAD:
1913 spec->init_verbs[spec->num_init_verbs++] =
1914 cxt5051_ideapad_init_verbs;
1915 spec->ideapad = 1;
1916 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001917 }
1918
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001919 if (spec->beep_amp)
1920 snd_hda_attach_beep_device(codec, spec->beep_amp);
1921
Takashi Iwai461e2c72008-01-25 11:35:17 +01001922 return 0;
1923}
1924
Daniel Drake0fb67e92009-07-16 14:46:57 +01001925/* Conexant 5066 specific */
1926
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001927static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1928static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1929static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1930static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
Daniel Drake0fb67e92009-07-16 14:46:57 +01001931
Daniel Drakedbaccc02009-11-09 15:17:24 +00001932/* OLPC's microphone port is DC coupled for use with external sensors,
1933 * therefore we use a 50% mic bias in order to center the input signal with
1934 * the DC input range of the codec. */
1935#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1936
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02001937static const struct hda_channel_mode cxt5066_modes[1] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01001938 { 2, NULL },
1939};
1940
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001941#define HP_PRESENT_PORT_A (1 << 0)
1942#define HP_PRESENT_PORT_D (1 << 1)
1943#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1944#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1945
Daniel Drake0fb67e92009-07-16 14:46:57 +01001946static void cxt5066_update_speaker(struct hda_codec *codec)
1947{
1948 struct conexant_spec *spec = codec->spec;
1949 unsigned int pinctl;
1950
John Baboval3a253442010-12-02 11:21:31 -05001951 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1952 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001953
1954 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001955 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001956 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001957
1958 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001959 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1960 if (spec->dell_automute || spec->thinkpad) {
1961 /* Mute if Port A is connected */
1962 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05001963 pinctl = 0;
1964 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01001965 /* Thinkpad/Dell doesn't give pin-D status */
1966 if (!hp_port_d_present(spec))
1967 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05001968 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001969 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001970
1971 /* CLASS_D AMP */
1972 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001973 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01001974}
1975
1976/* turn on/off EAPD (+ mute HP) as a master switch */
1977static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1978 struct snd_ctl_elem_value *ucontrol)
1979{
1980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1981
1982 if (!cxt_eapd_put(kcontrol, ucontrol))
1983 return 0;
1984
1985 cxt5066_update_speaker(codec);
1986 return 1;
1987}
1988
Daniel Drakec4cfe662010-01-07 13:47:04 +01001989static const struct hda_input_mux cxt5066_olpc_dc_bias = {
1990 .num_items = 3,
1991 .items = {
1992 { "Off", PIN_IN },
1993 { "50%", PIN_VREF50 },
1994 { "80%", PIN_VREF80 },
1995 },
1996};
1997
1998static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
1999{
2000 struct conexant_spec *spec = codec->spec;
2001 /* Even though port F is the DC input, the bias is controlled on port B.
2002 * we also leave that port as an active input (but unselected) in DC mode
2003 * just in case that is necessary to make the bias setting take effect. */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002004 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002005 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2006}
2007
Daniel Drake75f89912010-01-07 13:46:25 +01002008/* OLPC defers mic widget control until when capture is started because the
2009 * microphone LED comes on as soon as these settings are put in place. if we
2010 * did this before recording, it would give the false indication that recording
2011 * is happening when it is not. */
2012static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002013{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002014 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002015 if (!spec->recording)
2016 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002017
Daniel Drakec4cfe662010-01-07 13:47:04 +01002018 if (spec->dc_enable) {
2019 /* in DC mode we ignore presence detection and just use the jack
2020 * through our special DC port */
2021 const struct hda_verb enable_dc_mode[] = {
2022 /* disble internal mic, port C */
2023 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2024
2025 /* enable DC capture, port F */
2026 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2027 {},
2028 };
2029
2030 snd_hda_sequence_write(codec, enable_dc_mode);
2031 /* port B input disabled (and bias set) through the following call */
2032 cxt5066_set_olpc_dc_bias(codec);
2033 return;
2034 }
2035
2036 /* disable DC (port F) */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002037 snd_hda_set_pin_ctl(codec, 0x1e, 0);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002038
Daniel Drake75f89912010-01-07 13:46:25 +01002039 /* external mic, port B */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002040 snd_hda_set_pin_ctl(codec, 0x1a,
Daniel Drake75f89912010-01-07 13:46:25 +01002041 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002042
Daniel Drake75f89912010-01-07 13:46:25 +01002043 /* internal mic, port C */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002044 snd_hda_set_pin_ctl(codec, 0x1b,
Daniel Drake75f89912010-01-07 13:46:25 +01002045 spec->ext_mic_present ? 0 : PIN_VREF80);
2046}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002047
Daniel Drake75f89912010-01-07 13:46:25 +01002048/* toggle input of built-in and mic jack appropriately */
2049static void cxt5066_olpc_automic(struct hda_codec *codec)
2050{
2051 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002052 unsigned int present;
2053
Daniel Drakec4cfe662010-01-07 13:47:04 +01002054 if (spec->dc_enable) /* don't do presence detection in DC mode */
2055 return;
2056
Daniel Drake75f89912010-01-07 13:46:25 +01002057 present = snd_hda_codec_read(codec, 0x1a, 0,
2058 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2059 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002060 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002061 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002062 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002063
2064 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2065 present ? 0 : 1);
2066 spec->ext_mic_present = !!present;
2067
2068 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002069}
2070
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002071/* toggle input of built-in digital mic and mic jack appropriately */
2072static void cxt5066_vostro_automic(struct hda_codec *codec)
2073{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002074 unsigned int present;
2075
2076 struct hda_verb ext_mic_present[] = {
2077 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002078 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002079
2080 /* switch to external mic input */
2081 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2082 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2083
2084 /* disable internal digital mic */
2085 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2086 {}
2087 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002088 static const struct hda_verb ext_mic_absent[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002089 /* enable internal mic, port C */
2090 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2091
2092 /* switch to internal mic input */
2093 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2094
2095 /* disable external mic, port B */
2096 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2097 {}
2098 };
2099
2100 present = snd_hda_jack_detect(codec, 0x1a);
2101 if (present) {
2102 snd_printdd("CXT5066: external microphone detected\n");
2103 snd_hda_sequence_write(codec, ext_mic_present);
2104 } else {
2105 snd_printdd("CXT5066: external microphone absent\n");
2106 snd_hda_sequence_write(codec, ext_mic_absent);
2107 }
2108}
2109
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002110/* toggle input of built-in digital mic and mic jack appropriately */
2111static void cxt5066_ideapad_automic(struct hda_codec *codec)
2112{
2113 unsigned int present;
2114
2115 struct hda_verb ext_mic_present[] = {
2116 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2117 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2118 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2119 {}
2120 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002121 static const struct hda_verb ext_mic_absent[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002122 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2123 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2124 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2125 {}
2126 };
2127
2128 present = snd_hda_jack_detect(codec, 0x1b);
2129 if (present) {
2130 snd_printdd("CXT5066: external microphone detected\n");
2131 snd_hda_sequence_write(codec, ext_mic_present);
2132 } else {
2133 snd_printdd("CXT5066: external microphone absent\n");
2134 snd_hda_sequence_write(codec, ext_mic_absent);
2135 }
2136}
2137
David Henningssona1d69062011-01-21 13:33:28 +01002138
2139/* toggle input of built-in digital mic and mic jack appropriately */
2140static void cxt5066_asus_automic(struct hda_codec *codec)
2141{
2142 unsigned int present;
2143
2144 present = snd_hda_jack_detect(codec, 0x1b);
2145 snd_printdd("CXT5066: external microphone present=%d\n", present);
2146 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2147 present ? 1 : 0);
2148}
2149
2150
David Henningsson048e78a2010-09-02 08:35:47 +02002151/* toggle input of built-in digital mic and mic jack appropriately */
2152static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2153{
2154 unsigned int present;
2155
2156 present = snd_hda_jack_detect(codec, 0x1b);
2157 snd_printdd("CXT5066: external microphone present=%d\n", present);
2158 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2159 present ? 1 : 3);
2160}
2161
2162
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002163/* toggle input of built-in digital mic and mic jack appropriately
2164 order is: external mic -> dock mic -> interal mic */
2165static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2166{
2167 unsigned int ext_present, dock_present;
2168
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002169 static const struct hda_verb ext_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002170 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2171 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2172 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2173 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2174 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2175 {}
2176 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002177 static const struct hda_verb dock_mic_present[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002178 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2179 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2180 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2181 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2182 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2183 {}
2184 };
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002185 static const struct hda_verb ext_mic_absent[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002186 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2187 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2188 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2189 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2190 {}
2191 };
2192
2193 ext_present = snd_hda_jack_detect(codec, 0x1b);
2194 dock_present = snd_hda_jack_detect(codec, 0x1a);
2195 if (ext_present) {
2196 snd_printdd("CXT5066: external microphone detected\n");
2197 snd_hda_sequence_write(codec, ext_mic_present);
2198 } else if (dock_present) {
2199 snd_printdd("CXT5066: dock microphone detected\n");
2200 snd_hda_sequence_write(codec, dock_mic_present);
2201 } else {
2202 snd_printdd("CXT5066: external microphone absent\n");
2203 snd_hda_sequence_write(codec, ext_mic_absent);
2204 }
2205}
2206
Daniel Drake0fb67e92009-07-16 14:46:57 +01002207/* mute internal speaker if HP is plugged */
2208static void cxt5066_hp_automute(struct hda_codec *codec)
2209{
2210 struct conexant_spec *spec = codec->spec;
2211 unsigned int portA, portD;
2212
2213 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002214 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002215
2216 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002217 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002218
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002219 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2220 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002221 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2222 portA, portD, spec->hp_present);
2223 cxt5066_update_speaker(codec);
2224}
2225
David Henningsson02b6b5b2011-01-21 13:27:39 +01002226/* Dispatch the right mic autoswitch function */
2227static void cxt5066_automic(struct hda_codec *codec)
2228{
2229 struct conexant_spec *spec = codec->spec;
2230
2231 if (spec->dell_vostro)
2232 cxt5066_vostro_automic(codec);
2233 else if (spec->ideapad)
2234 cxt5066_ideapad_automic(codec);
2235 else if (spec->thinkpad)
2236 cxt5066_thinkpad_automic(codec);
2237 else if (spec->hp_laptop)
2238 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002239 else if (spec->asus)
2240 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002241}
2242
Daniel Drake0fb67e92009-07-16 14:46:57 +01002243/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002244static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002245{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002246 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002247 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2248 switch (res >> 26) {
2249 case CONEXANT_HP_EVENT:
2250 cxt5066_hp_automute(codec);
2251 break;
2252 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002253 /* ignore mic events in DC mode; we're always using the jack */
2254 if (!spec->dc_enable)
2255 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002256 break;
2257 }
2258}
2259
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002260/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002261static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002262{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002263 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002264 switch (res >> 26) {
2265 case CONEXANT_HP_EVENT:
2266 cxt5066_hp_automute(codec);
2267 break;
2268 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002269 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002270 break;
2271 }
2272}
2273
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002274
Daniel Drake0fb67e92009-07-16 14:46:57 +01002275static const struct hda_input_mux cxt5066_analog_mic_boost = {
2276 .num_items = 5,
2277 .items = {
2278 { "0dB", 0 },
2279 { "10dB", 1 },
2280 { "20dB", 2 },
2281 { "30dB", 3 },
2282 { "40dB", 4 },
2283 },
2284};
2285
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002286static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002287{
2288 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002289 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002290 AC_VERB_SET_AMP_GAIN_MUTE,
2291 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2292 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002293 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002294 /* adjust the internal mic as well...it is not through 0x17 */
2295 snd_hda_codec_write_cache(codec, 0x23, 0,
2296 AC_VERB_SET_AMP_GAIN_MUTE,
2297 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2298 cxt5066_analog_mic_boost.
2299 items[spec->mic_boost].index);
2300 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002301}
2302
Daniel Drake0fb67e92009-07-16 14:46:57 +01002303static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2304 struct snd_ctl_elem_info *uinfo)
2305{
2306 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2307}
2308
2309static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2310 struct snd_ctl_elem_value *ucontrol)
2311{
2312 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002313 struct conexant_spec *spec = codec->spec;
2314 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002315 return 0;
2316}
2317
2318static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2319 struct snd_ctl_elem_value *ucontrol)
2320{
2321 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002322 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002323 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2324 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002325 idx = ucontrol->value.enumerated.item[0];
2326 if (idx >= imux->num_items)
2327 idx = imux->num_items - 1;
2328
Daniel Drakec4cfe662010-01-07 13:47:04 +01002329 spec->mic_boost = idx;
2330 if (!spec->dc_enable)
2331 cxt5066_set_mic_boost(codec);
2332 return 1;
2333}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002334
Daniel Drakec4cfe662010-01-07 13:47:04 +01002335static void cxt5066_enable_dc(struct hda_codec *codec)
2336{
2337 const struct hda_verb enable_dc_mode[] = {
2338 /* disable gain */
2339 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2340
2341 /* switch to DC input */
2342 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2343 {}
2344 };
2345
2346 /* configure as input source */
2347 snd_hda_sequence_write(codec, enable_dc_mode);
2348 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2349}
2350
2351static void cxt5066_disable_dc(struct hda_codec *codec)
2352{
2353 /* reconfigure input source */
2354 cxt5066_set_mic_boost(codec);
2355 /* automic also selects the right mic if we're recording */
2356 cxt5066_olpc_automic(codec);
2357}
2358
2359static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2360 struct snd_ctl_elem_value *ucontrol)
2361{
2362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2363 struct conexant_spec *spec = codec->spec;
2364 ucontrol->value.integer.value[0] = spec->dc_enable;
2365 return 0;
2366}
2367
2368static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2369 struct snd_ctl_elem_value *ucontrol)
2370{
2371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2372 struct conexant_spec *spec = codec->spec;
2373 int dc_enable = !!ucontrol->value.integer.value[0];
2374
2375 if (dc_enable == spec->dc_enable)
2376 return 0;
2377
2378 spec->dc_enable = dc_enable;
2379 if (dc_enable)
2380 cxt5066_enable_dc(codec);
2381 else
2382 cxt5066_disable_dc(codec);
2383
2384 return 1;
2385}
2386
2387static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2388 struct snd_ctl_elem_info *uinfo)
2389{
2390 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2391}
2392
2393static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2394 struct snd_ctl_elem_value *ucontrol)
2395{
2396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397 struct conexant_spec *spec = codec->spec;
2398 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2399 return 0;
2400}
2401
2402static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2404{
2405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2406 struct conexant_spec *spec = codec->spec;
2407 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2408 unsigned int idx;
2409
2410 idx = ucontrol->value.enumerated.item[0];
2411 if (idx >= imux->num_items)
2412 idx = imux->num_items - 1;
2413
2414 spec->dc_input_bias = idx;
2415 if (spec->dc_enable)
2416 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002417 return 1;
2418}
2419
Daniel Drake75f89912010-01-07 13:46:25 +01002420static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2421{
2422 struct conexant_spec *spec = codec->spec;
2423 /* mark as recording and configure the microphone widget so that the
2424 * recording LED comes on. */
2425 spec->recording = 1;
2426 cxt5066_olpc_select_mic(codec);
2427}
2428
2429static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2430{
2431 struct conexant_spec *spec = codec->spec;
2432 const struct hda_verb disable_mics[] = {
2433 /* disable external mic, port B */
2434 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2435
2436 /* disble internal mic, port C */
2437 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002438
2439 /* disable DC capture, port F */
2440 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002441 {},
2442 };
2443
2444 snd_hda_sequence_write(codec, disable_mics);
2445 spec->recording = 0;
2446}
2447
Andy Robinsonf6a24912011-01-24 10:12:37 -05002448static void conexant_check_dig_outs(struct hda_codec *codec,
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002449 const hda_nid_t *dig_pins,
Andy Robinsonf6a24912011-01-24 10:12:37 -05002450 int num_pins)
2451{
2452 struct conexant_spec *spec = codec->spec;
2453 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2454 int i;
2455
2456 for (i = 0; i < num_pins; i++, dig_pins++) {
2457 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2458 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2459 continue;
2460 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2461 continue;
Andy Robinsonf6a24912011-01-24 10:12:37 -05002462 }
2463}
2464
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002465static const struct hda_input_mux cxt5066_capture_source = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002466 .num_items = 4,
2467 .items = {
2468 { "Mic B", 0 },
2469 { "Mic C", 1 },
2470 { "Mic E", 2 },
2471 { "Mic F", 3 },
2472 },
2473};
2474
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002475static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002476 .ops = &snd_hda_bind_vol,
2477 .values = {
2478 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2479 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2480 0
2481 },
2482};
2483
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002484static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002485 .ops = &snd_hda_bind_sw,
2486 .values = {
2487 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2488 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2489 0
2490 },
2491};
2492
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002493static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002494 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2495 {}
2496};
2497
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002498static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002499 {
2500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2501 .name = "Master Playback Volume",
2502 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2503 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2504 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002505 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002506 .info = snd_hda_mixer_amp_volume_info,
2507 .get = snd_hda_mixer_amp_volume_get,
2508 .put = snd_hda_mixer_amp_volume_put,
2509 .tlv = { .c = snd_hda_mixer_amp_tlv },
2510 /* offset by 28 volume steps to limit minimum gain to -46dB */
2511 .private_value =
2512 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2513 },
2514 {}
2515};
2516
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002517static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
Daniel Drakec4cfe662010-01-07 13:47:04 +01002518 {
2519 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2520 .name = "DC Mode Enable Switch",
2521 .info = snd_ctl_boolean_mono_info,
2522 .get = cxt5066_olpc_dc_get,
2523 .put = cxt5066_olpc_dc_put,
2524 },
2525 {
2526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2527 .name = "DC Input Bias Enum",
2528 .info = cxt5066_olpc_dc_bias_enum_info,
2529 .get = cxt5066_olpc_dc_bias_enum_get,
2530 .put = cxt5066_olpc_dc_bias_enum_put,
2531 },
2532 {}
2533};
2534
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002535static const struct snd_kcontrol_new cxt5066_mixers[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002536 {
2537 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2538 .name = "Master Playback Switch",
2539 .info = cxt_eapd_info,
2540 .get = cxt_eapd_get,
2541 .put = cxt5066_hp_master_sw_put,
2542 .private_value = 0x1d,
2543 },
2544
2545 {
2546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002547 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002548 .info = cxt5066_mic_boost_mux_enum_info,
2549 .get = cxt5066_mic_boost_mux_enum_get,
2550 .put = cxt5066_mic_boost_mux_enum_put,
2551 },
2552
2553 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2554 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2555 {}
2556};
2557
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002558static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
Einar Rünkaru254bba62009-12-16 22:16:13 +02002559 {
2560 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002561 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002562 .info = cxt5066_mic_boost_mux_enum_info,
2563 .get = cxt5066_mic_boost_mux_enum_get,
2564 .put = cxt5066_mic_boost_mux_enum_put,
2565 .private_value = 0x23 | 0x100,
2566 },
2567 {}
2568};
2569
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002570static const struct hda_verb cxt5066_init_verbs[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002571 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2572 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2573 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2574 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2575
2576 /* Speakers */
2577 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2578 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2579
2580 /* HP, Amp */
2581 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2582 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2583
2584 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2585 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2586
2587 /* DAC1 */
2588 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2589
2590 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2591 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2592 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2593 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2594 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2595 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2596
2597 /* no digital microphone support yet */
2598 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2599
2600 /* Audio input selector */
2601 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2602
2603 /* SPDIF route: PCM */
2604 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2605 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2606
2607 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2608 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2609
2610 /* EAPD */
2611 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2612
2613 /* not handling these yet */
2614 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2615 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2616 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2617 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2618 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2619 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2620 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2621 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2622 { } /* end */
2623};
2624
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002625static const struct hda_verb cxt5066_init_verbs_olpc[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002626 /* Port A: headphones */
2627 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2628 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2629
2630 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002631 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002632
2633 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002634 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002635
2636 /* Port D: unused */
2637 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2638
2639 /* Port E: unused, but has primary EAPD */
2640 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2641 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2642
Daniel Drakec4cfe662010-01-07 13:47:04 +01002643 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002644 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2645
2646 /* Port G: internal speakers */
2647 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2648 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2649
2650 /* DAC1 */
2651 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2652
2653 /* DAC2: unused */
2654 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2655
2656 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2657 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2658 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2659 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2660 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2661 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2662 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2663 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2664 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2665 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2666 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2667 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2668
2669 /* Disable digital microphone port */
2670 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2671
2672 /* Audio input selectors */
2673 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2674 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2675
2676 /* Disable SPDIF */
2677 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2678 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2679
2680 /* enable unsolicited events for Port A and B */
2681 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2682 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2683 { } /* end */
2684};
2685
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002686static const struct hda_verb cxt5066_init_verbs_vostro[] = {
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002687 /* Port A: headphones */
2688 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2689 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2690
2691 /* Port B: external microphone */
2692 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2693
2694 /* Port C: unused */
2695 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2696
2697 /* Port D: unused */
2698 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2699
2700 /* Port E: unused, but has primary EAPD */
2701 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2702 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2703
2704 /* Port F: unused */
2705 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2706
2707 /* Port G: internal speakers */
2708 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2709 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2710
2711 /* DAC1 */
2712 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2713
2714 /* DAC2: unused */
2715 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2716
2717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2721 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2722 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2723 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2724 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2725 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2726 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2727 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2728 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2729
2730 /* Digital microphone port */
2731 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2732
2733 /* Audio input selectors */
2734 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2735 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2736
2737 /* Disable SPDIF */
2738 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2739 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2740
2741 /* enable unsolicited events for Port A and B */
2742 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2743 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2744 { } /* end */
2745};
2746
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002747static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002748 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2749 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2750 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2751 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2752
2753 /* Speakers */
2754 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2755 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2756
2757 /* HP, Amp */
2758 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2759 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2760
2761 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2762 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2763
2764 /* DAC1 */
2765 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2766
2767 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2769 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2773 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2774
2775 /* Audio input selector */
2776 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2777 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2778
2779 /* SPDIF route: PCM */
2780 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2781 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2782
2783 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2784 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2785
2786 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002787 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002788
2789 /* EAPD */
2790 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2791
2792 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2793 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2794 { } /* end */
2795};
2796
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002797static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002798 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2799 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2800
2801 /* Port G: internal speakers */
2802 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2803 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2804
2805 /* Port A: HP, Amp */
2806 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2807 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2808
2809 /* Port B: Mic Dock */
2810 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2811
2812 /* Port C: Mic */
2813 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2814
2815 /* Port D: HP Dock, Amp */
2816 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2817 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2818
2819 /* DAC1 */
2820 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2821
2822 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2826 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2828 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2829
2830 /* Audio input selector */
2831 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2832 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2833
2834 /* SPDIF route: PCM */
2835 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2836 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2837
2838 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2839 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2840
2841 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002842 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002843
2844 /* EAPD */
2845 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2846
2847 /* enable unsolicited events for Port A, B, C and D */
2848 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2849 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2850 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2851 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2852 { } /* end */
2853};
2854
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002855static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
Daniel Drake0fb67e92009-07-16 14:46:57 +01002856 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2857 { } /* end */
2858};
2859
David Henningsson048e78a2010-09-02 08:35:47 +02002860
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002861static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
David Henningsson048e78a2010-09-02 08:35:47 +02002862 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2863 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2864 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2865 { } /* end */
2866};
2867
Daniel Drake0fb67e92009-07-16 14:46:57 +01002868/* initialize jack-sensing, too */
2869static int cxt5066_init(struct hda_codec *codec)
2870{
2871 snd_printdd("CXT5066: init\n");
2872 conexant_init(codec);
2873 if (codec->patch_ops.unsol_event) {
2874 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002875 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002876 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002877 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002878 return 0;
2879}
2880
Daniel Drake75f89912010-01-07 13:46:25 +01002881static int cxt5066_olpc_init(struct hda_codec *codec)
2882{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002883 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002884 snd_printdd("CXT5066: init\n");
2885 conexant_init(codec);
2886 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002887 if (!spec->dc_enable) {
2888 cxt5066_set_mic_boost(codec);
2889 cxt5066_olpc_automic(codec);
2890 } else {
2891 cxt5066_enable_dc(codec);
2892 }
Daniel Drake75f89912010-01-07 13:46:25 +01002893 return 0;
2894}
2895
Daniel Drake0fb67e92009-07-16 14:46:57 +01002896enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002897 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002898 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2899 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02002900 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002901 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002902 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01002903 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02002904 CXT5066_HP_LAPTOP, /* HP Laptop */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002905 CXT5066_AUTO, /* BIOS auto-parser */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002906 CXT5066_MODELS
2907};
2908
Takashi Iwaiea734962011-01-17 11:29:34 +01002909static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002910 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002911 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2912 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02002913 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002914 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002915 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01002916 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02002917 [CXT5066_HP_LAPTOP] = "hp-laptop",
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002918 [CXT5066_AUTO] = "auto",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002919};
2920
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02002921static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02002922 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02002923 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01002924 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05002925 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
Anisse Astier231f50bc2010-04-28 18:05:06 +02002926 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningssonebbd2242011-02-23 13:15:56 +01002927 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2928 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02002929 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002930 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002931 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Andy Robinsonf6a24912011-01-24 10:12:37 -05002932 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02002933 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04002934 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02002935 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2936 CXT5066_LAPTOP),
2937 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02002938 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06002939 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
David Henningsson19593872011-01-27 10:28:46 +01002940 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
David Henningsson84012652011-03-31 09:36:19 +02002941 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
David Henningssonb2cb1292011-04-05 07:55:24 +02002942 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
David Henningssond2859fd2011-05-23 08:26:16 +02002943 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
David Henningssona1d69062011-01-21 13:33:28 +01002944 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002945 {}
2946};
2947
2948static int patch_cxt5066(struct hda_codec *codec)
2949{
2950 struct conexant_spec *spec;
2951 int board_config;
2952
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002953 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2954 cxt5066_models, cxt5066_cfg_tbl);
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002955 if (board_config < 0)
Takashi Iwaic82693d2011-06-28 14:17:17 +02002956 board_config = CXT5066_AUTO; /* model=auto as default */
Takashi Iwaifea4a4f2011-05-16 11:49:12 +02002957 if (board_config == CXT5066_AUTO)
2958 return patch_conexant_auto(codec);
2959
Daniel Drake0fb67e92009-07-16 14:46:57 +01002960 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2961 if (!spec)
2962 return -ENOMEM;
2963 codec->spec = spec;
2964
2965 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01002966 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002967
2968 spec->dell_automute = 0;
2969 spec->multiout.max_channels = 2;
2970 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2971 spec->multiout.dac_nids = cxt5066_dac_nids;
Andy Robinsonf6a24912011-01-24 10:12:37 -05002972 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2973 ARRAY_SIZE(cxt5066_digout_pin_nids));
Daniel Drake0fb67e92009-07-16 14:46:57 +01002974 spec->num_adc_nids = 1;
2975 spec->adc_nids = cxt5066_adc_nids;
2976 spec->capsrc_nids = cxt5066_capsrc_nids;
2977 spec->input_mux = &cxt5066_capture_source;
2978
2979 spec->port_d_mode = PIN_HP;
2980
2981 spec->num_init_verbs = 1;
2982 spec->init_verbs[0] = cxt5066_init_verbs;
2983 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2984 spec->channel_mode = cxt5066_modes;
2985 spec->cur_adc = 0;
2986 spec->cur_adc_idx = 0;
2987
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002988 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2989
Daniel Drake0fb67e92009-07-16 14:46:57 +01002990 switch (board_config) {
2991 default:
2992 case CXT5066_LAPTOP:
2993 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2994 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2995 break;
2996 case CXT5066_DELL_LAPTOP:
2997 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2998 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2999
3000 spec->port_d_mode = PIN_OUT;
3001 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3002 spec->num_init_verbs++;
3003 spec->dell_automute = 1;
3004 break;
David Henningssona1d69062011-01-21 13:33:28 +01003005 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003006 case CXT5066_HP_LAPTOP:
3007 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003008 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003009 spec->init_verbs[spec->num_init_verbs] =
3010 cxt5066_init_verbs_hp_laptop;
3011 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003012 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3013 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003014 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3015 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3016 /* no S/PDIF out */
Andy Robinsonf6a24912011-01-24 10:12:37 -05003017 if (board_config == CXT5066_HP_LAPTOP)
3018 spec->multiout.dig_out_nid = 0;
David Henningsson048e78a2010-09-02 08:35:47 +02003019 /* input source automatically selected */
3020 spec->input_mux = NULL;
3021 spec->port_d_mode = 0;
3022 spec->mic_boost = 3; /* default 30dB gain */
3023 break;
3024
Daniel Drake0fb67e92009-07-16 14:46:57 +01003025 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003026 codec->patch_ops.init = cxt5066_olpc_init;
3027 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003028 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3029 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003030 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003031 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3032 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003033 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003034
3035 /* no S/PDIF out */
3036 spec->multiout.dig_out_nid = 0;
3037
3038 /* input source automatically selected */
3039 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003040
3041 /* our capture hooks which allow us to turn on the microphone LED
3042 * at the right time */
3043 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3044 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003045 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003046 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003047 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003048 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003049 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3050 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3051 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003052 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003053 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003054 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003055 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003056
3057 /* no S/PDIF out */
3058 spec->multiout.dig_out_nid = 0;
3059
3060 /* input source automatically selected */
3061 spec->input_mux = NULL;
3062 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003063 case CXT5066_IDEAPAD:
3064 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003065 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003066 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3067 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3068 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3069 spec->port_d_mode = 0;
3070 spec->ideapad = 1;
3071 spec->mic_boost = 2; /* default 20dB gain */
3072
3073 /* no S/PDIF out */
3074 spec->multiout.dig_out_nid = 0;
3075
3076 /* input source automatically selected */
3077 spec->input_mux = NULL;
3078 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003079 case CXT5066_THINKPAD:
3080 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003081 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003082 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3083 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3084 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3085 spec->thinkpad = 1;
3086 spec->port_d_mode = PIN_OUT;
3087 spec->mic_boost = 2; /* default 20dB gain */
3088
3089 /* no S/PDIF out */
3090 spec->multiout.dig_out_nid = 0;
3091
3092 /* input source automatically selected */
3093 spec->input_mux = NULL;
3094 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003095 }
3096
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003097 if (spec->beep_amp)
3098 snd_hda_attach_beep_device(codec, spec->beep_amp);
3099
Daniel Drake0fb67e92009-07-16 14:46:57 +01003100 return 0;
3101}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003102
3103/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003104 * Automatic parser for CX20641 & co
3105 */
3106
Takashi Iwaif2e57312010-09-15 10:07:08 +02003107#ifdef CONFIG_SND_HDA_INPUT_BEEP
3108static void cx_auto_parse_beep(struct hda_codec *codec)
3109{
3110 struct conexant_spec *spec = codec->spec;
3111 hda_nid_t nid, end_nid;
3112
3113 end_nid = codec->start_nid + codec->num_nodes;
3114 for (nid = codec->start_nid; nid < end_nid; nid++)
3115 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3116 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3117 break;
3118 }
3119}
3120#else
3121#define cx_auto_parse_beep(codec)
3122#endif
3123
Takashi Iwai254f2962011-10-14 15:22:34 +02003124/* parse EAPDs */
Takashi Iwai19110592011-07-11 14:46:44 +02003125static void cx_auto_parse_eapd(struct hda_codec *codec)
3126{
3127 struct conexant_spec *spec = codec->spec;
Takashi Iwai19110592011-07-11 14:46:44 +02003128 hda_nid_t nid, end_nid;
3129
3130 end_nid = codec->start_nid + codec->num_nodes;
3131 for (nid = codec->start_nid; nid < end_nid; nid++) {
3132 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3133 continue;
3134 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3135 continue;
Takashi Iwai19110592011-07-11 14:46:44 +02003136 spec->eapds[spec->num_eapds++] = nid;
3137 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3138 break;
3139 }
Takashi Iwai254f2962011-10-14 15:22:34 +02003140
3141 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3142 * it's a new chip, where EAPDs are supposed to be associated to
3143 * pins, and we can control EAPD per pin.
3144 * OTOH, if only one or two EAPDs are found, it's an old chip,
3145 * thus it might control over all pins.
3146 */
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003147 if (spec->num_eapds > 2)
3148 spec->gen.own_eapd_ctl = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003149}
3150
Takashi Iwaida339862011-05-13 16:24:15 +02003151static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3152 hda_nid_t *pins, bool on)
Takashi Iwaif2e57312010-09-15 10:07:08 +02003153{
3154 int i;
3155 for (i = 0; i < num_pins; i++) {
3156 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3157 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwaida339862011-05-13 16:24:15 +02003158 AC_VERB_SET_EAPD_BTLENABLE,
3159 on ? 0x02 : 0);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003160 }
3161}
3162
Takashi Iwai527c73b2012-03-12 12:38:51 +01003163/* turn on/off EAPD according to Master switch */
3164static void cx_auto_vmaster_hook(void *private_data, int enabled)
3165{
3166 struct hda_codec *codec = private_data;
3167 struct conexant_spec *spec = codec->spec;
3168
Takashi Iwai527c73b2012-03-12 12:38:51 +01003169 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3170}
3171
Takashi Iwaif2e57312010-09-15 10:07:08 +02003172static int cx_auto_build_controls(struct hda_codec *codec)
3173{
3174 int err;
3175
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003176 err = snd_hda_gen_build_controls(codec);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003177 if (err < 0)
3178 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003179
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003180 err = add_beep_ctls(codec);
3181 if (err < 0)
3182 return err;
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003183
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003184 return 0;
3185}
3186
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003187static const struct hda_codec_ops cx_auto_patch_ops = {
Takashi Iwaif2e57312010-09-15 10:07:08 +02003188 .build_controls = cx_auto_build_controls,
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003189 .build_pcms = snd_hda_gen_build_pcms,
3190 .init = snd_hda_gen_init,
3191 .free = snd_hda_gen_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02003192 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwaif2e57312010-09-15 10:07:08 +02003193};
3194
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003195/*
3196 * pin fix-up
3197 */
David Henningsson18dcd302012-04-02 15:40:27 +02003198enum {
3199 CXT_PINCFG_LENOVO_X200,
Takashi Iwaid3980112012-04-19 17:17:59 +02003200 CXT_PINCFG_LENOVO_TP410,
Huacai Chen239fb862012-10-05 21:25:09 +08003201 CXT_PINCFG_LEMOTE_A1004,
3202 CXT_PINCFG_LEMOTE_A1205,
David Henningsson18dcd302012-04-02 15:40:27 +02003203 CXT_FIXUP_STEREO_DMIC,
Huacai Chen239fb862012-10-05 21:25:09 +08003204 CXT_FIXUP_INC_MIC_BOOST,
David Henningsson18dcd302012-04-02 15:40:27 +02003205};
3206
Takashi Iwai23d30f22012-05-07 17:17:32 +02003207static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
3208 const struct hda_fixup *fix, int action)
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003209{
David Henningsson18dcd302012-04-02 15:40:27 +02003210 struct conexant_spec *spec = codec->spec;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003211 spec->gen.inv_dmic_split = 1;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003212}
3213
Huacai Chen239fb862012-10-05 21:25:09 +08003214static void cxt5066_increase_mic_boost(struct hda_codec *codec,
3215 const struct hda_fixup *fix, int action)
3216{
3217 if (action != HDA_FIXUP_ACT_PRE_PROBE)
3218 return;
3219
3220 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
3221 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
3222 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3223 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3224 (0 << AC_AMPCAP_MUTE_SHIFT));
3225}
3226
Takashi Iwaid70f36322012-04-19 15:18:08 +02003227/* ThinkPad X200 & co with cxt5051 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02003228static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003229 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
3230 { 0x17, 0x21a11000 }, /* dock-mic */
3231 { 0x19, 0x2121103f }, /* dock-HP */
Takashi Iwai3e93f5e2012-02-28 21:49:55 +01003232 { 0x1c, 0x21440100 }, /* dock SPDIF out */
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003233 {}
3234};
3235
Takashi Iwaid70f36322012-04-19 15:18:08 +02003236/* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
Takashi Iwai23d30f22012-05-07 17:17:32 +02003237static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
Takashi Iwaid70f36322012-04-19 15:18:08 +02003238 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
3239 { 0x1a, 0x21a190f0 }, /* dock-mic */
3240 { 0x1c, 0x212140ff }, /* dock-HP */
3241 {}
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003242};
3243
Huacai Chen239fb862012-10-05 21:25:09 +08003244/* Lemote A1004/A1205 with cxt5066 */
3245static const struct hda_pintbl cxt_pincfg_lemote[] = {
3246 { 0x1a, 0x90a10020 }, /* Internal mic */
3247 { 0x1b, 0x03a11020 }, /* External mic */
3248 { 0x1d, 0x400101f0 }, /* Not used */
3249 { 0x1e, 0x40a701f0 }, /* Not used */
3250 { 0x20, 0x404501f0 }, /* Not used */
3251 { 0x22, 0x404401f0 }, /* Not used */
3252 { 0x23, 0x40a701f0 }, /* Not used */
3253 {}
3254};
3255
Takashi Iwai23d30f22012-05-07 17:17:32 +02003256static const struct hda_fixup cxt_fixups[] = {
3257 [CXT_PINCFG_LENOVO_X200] = {
3258 .type = HDA_FIXUP_PINS,
3259 .v.pins = cxt_pincfg_lenovo_x200,
3260 },
3261 [CXT_PINCFG_LENOVO_TP410] = {
3262 .type = HDA_FIXUP_PINS,
3263 .v.pins = cxt_pincfg_lenovo_tp410,
3264 },
Huacai Chen239fb862012-10-05 21:25:09 +08003265 [CXT_PINCFG_LEMOTE_A1004] = {
3266 .type = HDA_FIXUP_PINS,
3267 .chained = true,
3268 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
3269 .v.pins = cxt_pincfg_lemote,
3270 },
3271 [CXT_PINCFG_LEMOTE_A1205] = {
3272 .type = HDA_FIXUP_PINS,
3273 .v.pins = cxt_pincfg_lemote,
3274 },
Takashi Iwai23d30f22012-05-07 17:17:32 +02003275 [CXT_FIXUP_STEREO_DMIC] = {
3276 .type = HDA_FIXUP_FUNC,
3277 .v.func = cxt_fixup_stereo_dmic,
3278 },
Huacai Chen239fb862012-10-05 21:25:09 +08003279 [CXT_FIXUP_INC_MIC_BOOST] = {
3280 .type = HDA_FIXUP_FUNC,
3281 .v.func = cxt5066_increase_mic_boost,
3282 },
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003283};
3284
Takashi Iwaid70f36322012-04-19 15:18:08 +02003285static const struct snd_pci_quirk cxt5051_fixups[] = {
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003286 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3287 {}
3288};
3289
Takashi Iwaid70f36322012-04-19 15:18:08 +02003290static const struct snd_pci_quirk cxt5066_fixups[] = {
Takashi Iwai63a077e2012-12-12 12:10:01 +01003291 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
Takashi Iwaid70f36322012-04-19 15:18:08 +02003292 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3293 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3294 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3295 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3296 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
David Henningsson18dcd302012-04-02 15:40:27 +02003297 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
Felix Kaechelee4db0952012-09-26 01:20:44 +02003298 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
David Henningssonb3c5dce2012-06-21 16:03:01 +02003299 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
Huacai Chen239fb862012-10-05 21:25:09 +08003300 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3301 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
Takashi Iwaif2e57312010-09-15 10:07:08 +02003302 {}
3303};
3304
Takashi Iwai38681372012-02-27 15:00:58 +01003305/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
3306 * can be created (bko#42825)
3307 */
3308static void add_cx5051_fake_mutes(struct hda_codec *codec)
3309{
3310 static hda_nid_t out_nids[] = {
3311 0x10, 0x11, 0
3312 };
3313 hda_nid_t *p;
3314
3315 for (p = out_nids; *p; p++)
3316 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
3317 AC_AMPCAP_MIN_MUTE |
3318 query_amp_caps(codec, *p, HDA_OUTPUT));
3319}
3320
Takashi Iwaif2e57312010-09-15 10:07:08 +02003321static int patch_conexant_auto(struct hda_codec *codec)
3322{
3323 struct conexant_spec *spec;
3324 int err;
3325
Takashi Iwai1f8458a2011-05-13 17:22:05 +02003326 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3327 codec->chip_name);
3328
Takashi Iwaif2e57312010-09-15 10:07:08 +02003329 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3330 if (!spec)
3331 return -ENOMEM;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003332 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003333 codec->spec = spec;
Takashi Iwaie92d4b02011-08-24 16:22:21 +02003334
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003335 cx_auto_parse_beep(codec);
3336 cx_auto_parse_eapd(codec);
3337 if (spec->gen.own_eapd_ctl)
3338 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
3339
Takashi Iwai6b452142011-10-14 15:26:20 +02003340 switch (codec->vendor_id) {
3341 case 0x14f15045:
Michael Karcher4f324562012-04-06 15:34:15 +02003342 codec->single_adc_amp = 1;
Takashi Iwai6b452142011-10-14 15:26:20 +02003343 break;
Takashi Iwai38681372012-02-27 15:00:58 +01003344 case 0x14f15051:
3345 add_cx5051_fake_mutes(codec);
Michael Karcher51969d62012-04-06 15:34:19 +02003346 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02003347 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
Takashi Iwai38681372012-02-27 15:00:58 +01003348 break;
Michael Karcher51969d62012-04-06 15:34:19 +02003349 default:
3350 codec->pin_amp_workaround = 1;
Takashi Iwai23d30f22012-05-07 17:17:32 +02003351 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
3352 break;
Takashi Iwai6b452142011-10-14 15:26:20 +02003353 }
3354
Takashi Iwaif29735c2012-03-13 07:55:10 +01003355 /* Show mute-led control only on HP laptops
3356 * This is a sort of white-list: on HP laptops, EAPD corresponds
3357 * only to the mute-LED without actualy amp function. Meanwhile,
3358 * others may use EAPD really as an amp switch, so it might be
3359 * not good to expose it blindly.
Takashi Iwai527c73b2012-03-12 12:38:51 +01003360 */
Takashi Iwaif29735c2012-03-13 07:55:10 +01003361 switch (codec->subsystem_id >> 16) {
3362 case 0x103c:
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003363 spec->gen.vmaster_mute_enum = 1;
Takashi Iwaif29735c2012-03-13 07:55:10 +01003364 break;
3365 }
Takashi Iwai527c73b2012-03-12 12:38:51 +01003366
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003367 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3368
3369 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
Takashi Iwai22ce5f72011-05-15 12:19:29 +02003370 if (err < 0)
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003371 goto error;
3372
3373 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3374 if (err < 0)
3375 goto error;
3376
Takashi Iwaif2e57312010-09-15 10:07:08 +02003377 codec->patch_ops = cx_auto_patch_ops;
3378 if (spec->beep_amp)
3379 snd_hda_attach_beep_device(codec, spec->beep_amp);
Takashi Iwai4f2864a2012-01-25 11:54:19 +01003380
3381 /* Some laptops with Conexant chips show stalls in S3 resume,
3382 * which falls into the single-cmd mode.
3383 * Better to make reset, then.
3384 */
3385 if (!codec->bus->sync_write) {
3386 snd_printd("hda_codec: "
3387 "Enable sync_write for stable communication\n");
3388 codec->bus->sync_write = 1;
3389 codec->bus->allow_bus_reset = 1;
3390 }
3391
Takashi Iwaif2e57312010-09-15 10:07:08 +02003392 return 0;
Takashi Iwaiaed523f2012-12-20 16:34:12 +01003393
3394 error:
3395 snd_hda_gen_free(codec);
3396 return err;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003397}
3398
3399/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01003400 */
3401
Takashi Iwai34cbe3a2011-05-02 11:38:21 +02003402static const struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003403 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3404 .patch = patch_cxt5045 },
3405 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3406 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003407 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3408 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003409 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3410 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003411 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3412 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003413 { .id = 0x14f15068, .name = "CX20584",
3414 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003415 { .id = 0x14f15069, .name = "CX20585",
3416 .patch = patch_cxt5066 },
David Henningssonf0ca89b2011-06-21 20:51:34 +02003417 { .id = 0x14f1506c, .name = "CX20588",
3418 .patch = patch_cxt5066 },
David Henningsson6da8b512011-02-08 07:16:06 +01003419 { .id = 0x14f1506e, .name = "CX20590",
3420 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02003421 { .id = 0x14f15097, .name = "CX20631",
3422 .patch = patch_conexant_auto },
3423 { .id = 0x14f15098, .name = "CX20632",
3424 .patch = patch_conexant_auto },
3425 { .id = 0x14f150a1, .name = "CX20641",
3426 .patch = patch_conexant_auto },
3427 { .id = 0x14f150a2, .name = "CX20642",
3428 .patch = patch_conexant_auto },
3429 { .id = 0x14f150ab, .name = "CX20651",
3430 .patch = patch_conexant_auto },
3431 { .id = 0x14f150ac, .name = "CX20652",
3432 .patch = patch_conexant_auto },
3433 { .id = 0x14f150b8, .name = "CX20664",
3434 .patch = patch_conexant_auto },
3435 { .id = 0x14f150b9, .name = "CX20665",
3436 .patch = patch_conexant_auto },
Takashi Iwai2d825fd2012-05-11 08:39:24 +02003437 { .id = 0x14f1510f, .name = "CX20751/2",
3438 .patch = patch_conexant_auto },
3439 { .id = 0x14f15110, .name = "CX20751/2",
3440 .patch = patch_conexant_auto },
3441 { .id = 0x14f15111, .name = "CX20753/4",
3442 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003443 {} /* terminator */
3444};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003445
3446MODULE_ALIAS("snd-hda-codec-id:14f15045");
3447MODULE_ALIAS("snd-hda-codec-id:14f15047");
3448MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003449MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003450MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003451MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003452MODULE_ALIAS("snd-hda-codec-id:14f15069");
David Henningssonf0ca89b2011-06-21 20:51:34 +02003453MODULE_ALIAS("snd-hda-codec-id:14f1506c");
David Henningsson6da8b512011-02-08 07:16:06 +01003454MODULE_ALIAS("snd-hda-codec-id:14f1506e");
Takashi Iwaif2e57312010-09-15 10:07:08 +02003455MODULE_ALIAS("snd-hda-codec-id:14f15097");
3456MODULE_ALIAS("snd-hda-codec-id:14f15098");
3457MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3458MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3459MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3460MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3461MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3462MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai2d825fd2012-05-11 08:39:24 +02003463MODULE_ALIAS("snd-hda-codec-id:14f1510f");
3464MODULE_ALIAS("snd-hda-codec-id:14f15110");
3465MODULE_ALIAS("snd-hda-codec-id:14f15111");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003466
3467MODULE_LICENSE("GPL");
3468MODULE_DESCRIPTION("Conexant HD-audio codec");
3469
3470static struct hda_codec_preset_list conexant_list = {
3471 .preset = snd_hda_preset_conexant,
3472 .owner = THIS_MODULE,
3473};
3474
3475static int __init patch_conexant_init(void)
3476{
3477 return snd_hda_add_codec_preset(&conexant_list);
3478}
3479
3480static void __exit patch_conexant_exit(void)
3481{
3482 snd_hda_delete_codec_preset(&conexant_list);
3483}
3484
3485module_init(patch_conexant_init)
3486module_exit(patch_conexant_exit)