blob: 19f0daf6497d51ff06e5da4d2b35f8729d1d820d [file] [log] [blame]
Tobin Davisc9b443d2006-11-14 12:13:39 +01001/*
2 * HD audio interface patch for Conexant HDA audio codec
3 *
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Tobin Davisc9b443d2006-11-14 12:13:39 +010023#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <sound/core.h>
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010028#include <sound/jack.h>
29
Tobin Davisc9b443d2006-11-14 12:13:39 +010030#include "hda_codec.h"
31#include "hda_local.h"
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +020032#include "hda_beep.h"
Tobin Davisc9b443d2006-11-14 12:13:39 +010033
34#define CXT_PIN_DIR_IN 0x00
35#define CXT_PIN_DIR_OUT 0x01
36#define CXT_PIN_DIR_INOUT 0x02
37#define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39
40#define CONEXANT_HP_EVENT 0x37
41#define CONEXANT_MIC_EVENT 0x38
42
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010043/* Conexant 5051 specific */
Tobin Davisc9b443d2006-11-14 12:13:39 +010044
Takashi Iwaiecda0cf2010-01-24 11:14:36 +010045#define CXT5051_SPDIF_OUT 0x12
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010046#define CXT5051_PORTB_EVENT 0x38
47#define CXT5051_PORTC_EVENT 0x39
48
Takashi Iwaifaddaa52010-01-23 22:31:36 +010049#define AUTO_MIC_PORTB (1 << 1)
50#define AUTO_MIC_PORTC (1 << 2)
Ulrich Dangelbc7a1662009-01-02 19:30:13 +010051
52struct conexant_jack {
53
54 hda_nid_t nid;
55 int type;
56 struct snd_jack *jack;
57
58};
Tobin Davisc9b443d2006-11-14 12:13:39 +010059
Takashi Iwaif2e57312010-09-15 10:07:08 +020060struct pin_dac_pair {
61 hda_nid_t pin;
62 hda_nid_t dac;
63 int type;
64};
65
Tobin Davisc9b443d2006-11-14 12:13:39 +010066struct conexant_spec {
67
68 struct snd_kcontrol_new *mixers[5];
69 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010070 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010071
72 const struct hda_verb *init_verbs[5]; /* initialization verbs
73 * don't forget NULL
74 * termination!
75 */
76 unsigned int num_init_verbs;
77
78 /* playback */
79 struct hda_multi_out multiout; /* playback set-up
80 * max_channels, dacs must be set
81 * dig_out_nid and hp_nid are optional
82 */
83 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010084 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010085 unsigned int auto_mic;
Takashi Iwaif2e57312010-09-15 10:07:08 +020086 int auto_mic_ext; /* autocfg.inputs[] index for ext mic */
Tobin Davisc9b443d2006-11-14 12:13:39 +010087 unsigned int need_dac_fix;
88
89 /* capture */
90 unsigned int num_adc_nids;
91 hda_nid_t *adc_nids;
92 hda_nid_t dig_in_nid; /* digital-in NID; optional */
93
Takashi Iwai461e2c72008-01-25 11:35:17 +010094 unsigned int cur_adc_idx;
95 hda_nid_t cur_adc;
96 unsigned int cur_adc_stream_tag;
97 unsigned int cur_adc_format;
98
Tobin Davisc9b443d2006-11-14 12:13:39 +010099 /* capture source */
100 const struct hda_input_mux *input_mux;
101 hda_nid_t *capsrc_nids;
102 unsigned int cur_mux[3];
103
104 /* channel model */
105 const struct hda_channel_mode *channel_mode;
106 int num_channel_mode;
107
108 /* PCM information */
109 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
110
Tobin Davisc9b443d2006-11-14 12:13:39 +0100111 unsigned int spdif_route;
112
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100113 /* jack detection */
114 struct snd_array jacks;
115
Tobin Davisc9b443d2006-11-14 12:13:39 +0100116 /* dynamic controls, init_verbs and input_mux */
117 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100118 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200119 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaif2e57312010-09-15 10:07:08 +0200120 struct pin_dac_pair dac_info[8];
121 int dac_info_filled;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100122
Daniel Drake0fb67e92009-07-16 14:46:57 +0100123 unsigned int port_d_mode;
Takashi Iwaif2e57312010-09-15 10:07:08 +0200124 unsigned int auto_mute:1; /* used in auto-parser */
125 unsigned int dell_automute:1;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500126 unsigned int dell_vostro:1;
127 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200128 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200129 unsigned int hp_laptop:1;
David Henningssona1d69062011-01-21 13:33:28 +0100130 unsigned int asus:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100131
132 unsigned int ext_mic_present;
133 unsigned int recording;
134 void (*capture_prepare)(struct hda_codec *codec);
135 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100136
137 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
138 * through the microphone jack.
139 * When the user enables this through a mixer switch, both internal and
140 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
141 * we also allow the bias to be configured through a separate mixer
142 * control. */
143 unsigned int dc_enable;
144 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
145 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200146
147 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100148};
149
150static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
151 struct hda_codec *codec,
152 struct snd_pcm_substream *substream)
153{
154 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100155 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
156 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100157}
158
159static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
160 struct hda_codec *codec,
161 unsigned int stream_tag,
162 unsigned int format,
163 struct snd_pcm_substream *substream)
164{
165 struct conexant_spec *spec = codec->spec;
166 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
167 stream_tag,
168 format, substream);
169}
170
171static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
172 struct hda_codec *codec,
173 struct snd_pcm_substream *substream)
174{
175 struct conexant_spec *spec = codec->spec;
176 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
177}
178
179/*
180 * Digital out
181 */
182static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
183 struct hda_codec *codec,
184 struct snd_pcm_substream *substream)
185{
186 struct conexant_spec *spec = codec->spec;
187 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
188}
189
190static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
191 struct hda_codec *codec,
192 struct snd_pcm_substream *substream)
193{
194 struct conexant_spec *spec = codec->spec;
195 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
196}
197
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200198static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 unsigned int stream_tag,
201 unsigned int format,
202 struct snd_pcm_substream *substream)
203{
204 struct conexant_spec *spec = codec->spec;
205 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
206 stream_tag,
207 format, substream);
208}
209
Tobin Davisc9b443d2006-11-14 12:13:39 +0100210/*
211 * Analog capture
212 */
213static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
214 struct hda_codec *codec,
215 unsigned int stream_tag,
216 unsigned int format,
217 struct snd_pcm_substream *substream)
218{
219 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100220 if (spec->capture_prepare)
221 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100222 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
223 stream_tag, 0, format);
224 return 0;
225}
226
227static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
228 struct hda_codec *codec,
229 struct snd_pcm_substream *substream)
230{
231 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100232 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100233 if (spec->capture_cleanup)
234 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100235 return 0;
236}
237
238
239
240static struct hda_pcm_stream conexant_pcm_analog_playback = {
241 .substreams = 1,
242 .channels_min = 2,
243 .channels_max = 2,
244 .nid = 0, /* fill later */
245 .ops = {
246 .open = conexant_playback_pcm_open,
247 .prepare = conexant_playback_pcm_prepare,
248 .cleanup = conexant_playback_pcm_cleanup
249 },
250};
251
252static struct hda_pcm_stream conexant_pcm_analog_capture = {
253 .substreams = 1,
254 .channels_min = 2,
255 .channels_max = 2,
256 .nid = 0, /* fill later */
257 .ops = {
258 .prepare = conexant_capture_pcm_prepare,
259 .cleanup = conexant_capture_pcm_cleanup
260 },
261};
262
263
264static struct hda_pcm_stream conexant_pcm_digital_playback = {
265 .substreams = 1,
266 .channels_min = 2,
267 .channels_max = 2,
268 .nid = 0, /* fill later */
269 .ops = {
270 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200271 .close = conexant_dig_playback_pcm_close,
272 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100273 },
274};
275
276static struct hda_pcm_stream conexant_pcm_digital_capture = {
277 .substreams = 1,
278 .channels_min = 2,
279 .channels_max = 2,
280 /* NID is set in alc_build_pcms */
281};
282
Takashi Iwai461e2c72008-01-25 11:35:17 +0100283static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
284 struct hda_codec *codec,
285 unsigned int stream_tag,
286 unsigned int format,
287 struct snd_pcm_substream *substream)
288{
289 struct conexant_spec *spec = codec->spec;
290 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
291 spec->cur_adc_stream_tag = stream_tag;
292 spec->cur_adc_format = format;
293 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
294 return 0;
295}
296
297static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
298 struct hda_codec *codec,
299 struct snd_pcm_substream *substream)
300{
301 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100302 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100303 spec->cur_adc = 0;
304 return 0;
305}
306
307static struct hda_pcm_stream cx5051_pcm_analog_capture = {
308 .substreams = 1,
309 .channels_min = 2,
310 .channels_max = 2,
311 .nid = 0, /* fill later */
312 .ops = {
313 .prepare = cx5051_capture_pcm_prepare,
314 .cleanup = cx5051_capture_pcm_cleanup
315 },
316};
317
Tobin Davisc9b443d2006-11-14 12:13:39 +0100318static int conexant_build_pcms(struct hda_codec *codec)
319{
320 struct conexant_spec *spec = codec->spec;
321 struct hda_pcm *info = spec->pcm_rec;
322
323 codec->num_pcms = 1;
324 codec->pcm_info = info;
325
326 info->name = "CONEXANT Analog";
327 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
328 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
329 spec->multiout.max_channels;
330 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
331 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100332 if (codec->vendor_id == 0x14f15051)
333 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
334 cx5051_pcm_analog_capture;
335 else
336 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
337 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100338 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
339 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
340
341 if (spec->multiout.dig_out_nid) {
342 info++;
343 codec->num_pcms++;
344 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100345 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100346 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
347 conexant_pcm_digital_playback;
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
349 spec->multiout.dig_out_nid;
350 if (spec->dig_in_nid) {
351 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
352 conexant_pcm_digital_capture;
353 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
354 spec->dig_in_nid;
355 }
356 }
357
358 return 0;
359}
360
361static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
362 struct snd_ctl_elem_info *uinfo)
363{
364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
365 struct conexant_spec *spec = codec->spec;
366
367 return snd_hda_input_mux_info(spec->input_mux, uinfo);
368}
369
370static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_value *ucontrol)
372{
373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374 struct conexant_spec *spec = codec->spec;
375 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
376
377 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
378 return 0;
379}
380
381static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
382 struct snd_ctl_elem_value *ucontrol)
383{
384 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385 struct conexant_spec *spec = codec->spec;
386 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
387
388 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
389 spec->capsrc_nids[adc_idx],
390 &spec->cur_mux[adc_idx]);
391}
392
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200393#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200394static void conexant_free_jack_priv(struct snd_jack *jack)
395{
396 struct conexant_jack *jacks = jack->private_data;
397 jacks->nid = 0;
398 jacks->jack = NULL;
399}
400
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100401static int conexant_add_jack(struct hda_codec *codec,
402 hda_nid_t nid, int type)
403{
404 struct conexant_spec *spec;
405 struct conexant_jack *jack;
406 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200407 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100408
409 spec = codec->spec;
410 snd_array_init(&spec->jacks, sizeof(*jack), 32);
411 jack = snd_array_new(&spec->jacks);
412 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
413
414 if (!jack)
415 return -ENOMEM;
416
417 jack->nid = nid;
418 jack->type = type;
419
Takashi Iwai95c09092009-04-14 16:15:29 +0200420 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
421 if (err < 0)
422 return err;
423 jack->jack->private_data = jack;
424 jack->jack->private_free = conexant_free_jack_priv;
425 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100426}
427
428static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
429{
430 struct conexant_spec *spec = codec->spec;
431 struct conexant_jack *jacks = spec->jacks.list;
432
433 if (jacks) {
434 int i;
435 for (i = 0; i < spec->jacks.used; i++) {
436 if (jacks->nid == nid) {
437 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100438 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100439
440 present = (present) ? jacks->type : 0 ;
441
442 snd_jack_report(jacks->jack,
443 present);
444 }
445 jacks++;
446 }
447 }
448}
449
450static int conexant_init_jacks(struct hda_codec *codec)
451{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100452 struct conexant_spec *spec = codec->spec;
453 int i;
454
455 for (i = 0; i < spec->num_init_verbs; i++) {
456 const struct hda_verb *hv;
457
458 hv = spec->init_verbs[i];
459 while (hv->nid) {
460 int err = 0;
461 switch (hv->param ^ AC_USRSP_EN) {
462 case CONEXANT_HP_EVENT:
463 err = conexant_add_jack(codec, hv->nid,
464 SND_JACK_HEADPHONE);
465 conexant_report_jack(codec, hv->nid);
466 break;
467 case CXT5051_PORTC_EVENT:
468 case CONEXANT_MIC_EVENT:
469 err = conexant_add_jack(codec, hv->nid,
470 SND_JACK_MICROPHONE);
471 conexant_report_jack(codec, hv->nid);
472 break;
473 }
474 if (err < 0)
475 return err;
476 ++hv;
477 }
478 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100479 return 0;
480
481}
Takashi Iwai5801f992009-01-27 12:53:22 +0100482#else
483static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
484{
485}
486
487static inline int conexant_init_jacks(struct hda_codec *codec)
488{
489 return 0;
490}
491#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100492
Tobin Davisc9b443d2006-11-14 12:13:39 +0100493static int conexant_init(struct hda_codec *codec)
494{
495 struct conexant_spec *spec = codec->spec;
496 int i;
497
498 for (i = 0; i < spec->num_init_verbs; i++)
499 snd_hda_sequence_write(codec, spec->init_verbs[i]);
500 return 0;
501}
502
503static void conexant_free(struct hda_codec *codec)
504{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200505#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100506 struct conexant_spec *spec = codec->spec;
507 if (spec->jacks.list) {
508 struct conexant_jack *jacks = spec->jacks.list;
509 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200510 for (i = 0; i < spec->jacks.used; i++, jacks++) {
511 if (jacks->jack)
512 snd_device_free(codec->bus->card, jacks->jack);
513 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100514 snd_array_free(&spec->jacks);
515 }
516#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200517 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100518 kfree(codec->spec);
519}
520
Takashi Iwaib880c742009-03-10 14:41:05 +0100521static struct snd_kcontrol_new cxt_capture_mixers[] = {
522 {
523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
524 .name = "Capture Source",
525 .info = conexant_mux_enum_info,
526 .get = conexant_mux_enum_get,
527 .put = conexant_mux_enum_put
528 },
529 {}
530};
531
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200532#ifdef CONFIG_SND_HDA_INPUT_BEEP
533/* additional beep mixers; the actual parameters are overwritten at build */
534static struct snd_kcontrol_new cxt_beep_mixer[] = {
535 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
536 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
537 { } /* end */
538};
539#endif
540
Takashi Iwaiea734962011-01-17 11:29:34 +0100541static const char * const slave_vols[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100542 "Headphone Playback Volume",
543 "Speaker Playback Volume",
544 NULL
545};
546
Takashi Iwaiea734962011-01-17 11:29:34 +0100547static const char * const slave_sws[] = {
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100548 "Headphone Playback Switch",
549 "Speaker Playback Switch",
550 NULL
551};
552
Tobin Davisc9b443d2006-11-14 12:13:39 +0100553static int conexant_build_controls(struct hda_codec *codec)
554{
555 struct conexant_spec *spec = codec->spec;
556 unsigned int i;
557 int err;
558
559 for (i = 0; i < spec->num_mixers; i++) {
560 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
561 if (err < 0)
562 return err;
563 }
564 if (spec->multiout.dig_out_nid) {
565 err = snd_hda_create_spdif_out_ctls(codec,
566 spec->multiout.dig_out_nid);
567 if (err < 0)
568 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100569 err = snd_hda_create_spdif_share_sw(codec,
570 &spec->multiout);
571 if (err < 0)
572 return err;
573 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100574 }
575 if (spec->dig_in_nid) {
576 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
577 if (err < 0)
578 return err;
579 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100580
581 /* if we have no master control, let's create it */
582 if (spec->vmaster_nid &&
583 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
584 unsigned int vmaster_tlv[4];
585 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
586 HDA_OUTPUT, vmaster_tlv);
587 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
588 vmaster_tlv, slave_vols);
589 if (err < 0)
590 return err;
591 }
592 if (spec->vmaster_nid &&
593 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
594 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
595 NULL, slave_sws);
596 if (err < 0)
597 return err;
598 }
599
Takashi Iwaib880c742009-03-10 14:41:05 +0100600 if (spec->input_mux) {
601 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
602 if (err < 0)
603 return err;
604 }
605
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200606#ifdef CONFIG_SND_HDA_INPUT_BEEP
607 /* create beep controls if needed */
608 if (spec->beep_amp) {
609 struct snd_kcontrol_new *knew;
610 for (knew = cxt_beep_mixer; knew->name; knew++) {
611 struct snd_kcontrol *kctl;
612 kctl = snd_ctl_new1(knew, codec);
613 if (!kctl)
614 return -ENOMEM;
615 kctl->private_value = spec->beep_amp;
616 err = snd_hda_ctl_add(codec, 0, kctl);
617 if (err < 0)
618 return err;
619 }
620 }
621#endif
622
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623 return 0;
624}
625
Takashi Iwai697c3732010-07-30 11:28:02 +0200626#ifdef CONFIG_SND_HDA_POWER_SAVE
627static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
628{
629 snd_hda_shutup_pins(codec);
630 return 0;
631}
632#endif
633
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634static struct hda_codec_ops conexant_patch_ops = {
635 .build_controls = conexant_build_controls,
636 .build_pcms = conexant_build_pcms,
637 .init = conexant_init,
638 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200639#ifdef CONFIG_SND_HDA_POWER_SAVE
640 .suspend = conexant_suspend,
641#endif
642 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100643};
644
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200645#ifdef CONFIG_SND_HDA_INPUT_BEEP
646#define set_beep_amp(spec, nid, idx, dir) \
647 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
648#else
649#define set_beep_amp(spec, nid, idx, dir) /* NOP */
650#endif
651
Tobin Davisc9b443d2006-11-14 12:13:39 +0100652/*
653 * EAPD control
654 * the private value = nid | (invert << 8)
655 */
656
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200657#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100658
Tobin Davis82f30042007-02-13 12:45:44 +0100659static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100660 struct snd_ctl_elem_value *ucontrol)
661{
662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663 struct conexant_spec *spec = codec->spec;
664 int invert = (kcontrol->private_value >> 8) & 1;
665 if (invert)
666 ucontrol->value.integer.value[0] = !spec->cur_eapd;
667 else
668 ucontrol->value.integer.value[0] = spec->cur_eapd;
669 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100670
Tobin Davisc9b443d2006-11-14 12:13:39 +0100671}
672
Tobin Davis82f30042007-02-13 12:45:44 +0100673static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100674 struct snd_ctl_elem_value *ucontrol)
675{
676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677 struct conexant_spec *spec = codec->spec;
678 int invert = (kcontrol->private_value >> 8) & 1;
679 hda_nid_t nid = kcontrol->private_value & 0xff;
680 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100681
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100682 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100683 if (invert)
684 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200685 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100686 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100687
Tobin Davisc9b443d2006-11-14 12:13:39 +0100688 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200689 snd_hda_codec_write_cache(codec, nid,
690 0, AC_VERB_SET_EAPD_BTLENABLE,
691 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100692 return 1;
693}
694
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100695/* controls for test mode */
696#ifdef CONFIG_SND_DEBUG
697
Tobin Davis82f30042007-02-13 12:45:44 +0100698#define CXT_EAPD_SWITCH(xname, nid, mask) \
699 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
700 .info = cxt_eapd_info, \
701 .get = cxt_eapd_get, \
702 .put = cxt_eapd_put, \
703 .private_value = nid | (mask<<16) }
704
705
706
Tobin Davisc9b443d2006-11-14 12:13:39 +0100707static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
708 struct snd_ctl_elem_info *uinfo)
709{
710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711 struct conexant_spec *spec = codec->spec;
712 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
713 spec->num_channel_mode);
714}
715
716static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
717 struct snd_ctl_elem_value *ucontrol)
718{
719 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
720 struct conexant_spec *spec = codec->spec;
721 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
722 spec->num_channel_mode,
723 spec->multiout.max_channels);
724}
725
726static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
727 struct snd_ctl_elem_value *ucontrol)
728{
729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
730 struct conexant_spec *spec = codec->spec;
731 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
732 spec->num_channel_mode,
733 &spec->multiout.max_channels);
734 if (err >= 0 && spec->need_dac_fix)
735 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
736 return err;
737}
738
739#define CXT_PIN_MODE(xname, nid, dir) \
740 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
741 .info = conexant_ch_mode_info, \
742 .get = conexant_ch_mode_get, \
743 .put = conexant_ch_mode_put, \
744 .private_value = nid | (dir<<16) }
745
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100746#endif /* CONFIG_SND_DEBUG */
747
Tobin Davisc9b443d2006-11-14 12:13:39 +0100748/* Conexant 5045 specific */
749
750static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
751static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
752static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100753#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100754
Tobin Davis5cd57522006-11-20 17:42:09 +0100755static struct hda_channel_mode cxt5045_modes[1] = {
756 { 2, NULL },
757};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100758
759static struct hda_input_mux cxt5045_capture_source = {
760 .num_items = 2,
761 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100762 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100763 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100764 }
765};
766
Jiang Zhe5218c892008-01-17 11:18:41 +0100767static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200768 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100769 .items = {
770 { "IntMic", 0x1 },
771 { "ExtMic", 0x2 },
772 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200773 { "CD", 0x4 },
774 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100775 }
776};
777
Jiang zhe2de3c232008-03-06 11:09:09 +0100778static struct hda_input_mux cxt5045_capture_source_hp530 = {
779 .num_items = 2,
780 .items = {
781 { "ExtMic", 0x1 },
782 { "IntMic", 0x2 },
783 }
784};
785
Tobin Davisc9b443d2006-11-14 12:13:39 +0100786/* turn on/off EAPD (+ mute HP) as a master switch */
787static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
788 struct snd_ctl_elem_value *ucontrol)
789{
790 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
791 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100792 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100793
Tobin Davis82f30042007-02-13 12:45:44 +0100794 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795 return 0;
796
Tobin Davis82f30042007-02-13 12:45:44 +0100797 /* toggle internal speakers mute depending of presence of
798 * the headphone jack
799 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200800 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
801 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
802 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100803
Takashi Iwai47fd8302007-08-10 17:11:07 +0200804 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
805 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
806 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100807 return 1;
808}
809
810/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200811static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
812 .ops = &snd_hda_bind_vol,
813 .values = {
814 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
815 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
816 0
817 },
818};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100819
Tobin Davis7f296732007-03-12 11:39:01 +0100820/* toggle input of built-in and mic jack appropriately */
821static void cxt5045_hp_automic(struct hda_codec *codec)
822{
823 static struct hda_verb mic_jack_on[] = {
824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
825 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
826 {}
827 };
828 static struct hda_verb mic_jack_off[] = {
829 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
830 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
831 {}
832 };
833 unsigned int present;
834
Takashi Iwaid56757a2009-11-18 08:00:14 +0100835 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100836 if (present)
837 snd_hda_sequence_write(codec, mic_jack_on);
838 else
839 snd_hda_sequence_write(codec, mic_jack_off);
840}
841
Tobin Davisc9b443d2006-11-14 12:13:39 +0100842
843/* mute internal speaker if HP is plugged */
844static void cxt5045_hp_automute(struct hda_codec *codec)
845{
Tobin Davis82f30042007-02-13 12:45:44 +0100846 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100847 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100848
Takashi Iwaid56757a2009-11-18 08:00:14 +0100849 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100850
Takashi Iwai47fd8302007-08-10 17:11:07 +0200851 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
852 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
853 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100854}
855
856/* unsolicited event for HP jack sensing */
857static void cxt5045_hp_unsol_event(struct hda_codec *codec,
858 unsigned int res)
859{
860 res >>= 26;
861 switch (res) {
862 case CONEXANT_HP_EVENT:
863 cxt5045_hp_automute(codec);
864 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100865 case CONEXANT_MIC_EVENT:
866 cxt5045_hp_automic(codec);
867 break;
868
Tobin Davisc9b443d2006-11-14 12:13:39 +0100869 }
870}
871
872static struct snd_kcontrol_new cxt5045_mixers[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100873 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
874 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100875 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
876 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
Takashi Iwaic8229c32007-10-19 08:06:21 +0200877 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
878 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100879 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
880 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100881 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
882 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200883 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100884 {
885 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
886 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100887 .info = cxt_eapd_info,
888 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100889 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100890 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100891 },
892
893 {}
894};
895
Jiang Zhe5218c892008-01-17 11:18:41 +0100896static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200897 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
898 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
899 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
900 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
901
Jiang Zhe5218c892008-01-17 11:18:41 +0100902 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
903 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
904 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
905 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
906
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200907 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
908 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
909
Jiang Zhe5218c892008-01-17 11:18:41 +0100910 {}
911};
912
Jiang zhe2de3c232008-03-06 11:09:09 +0100913static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100914 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
915 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100916 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
917 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100918 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
919 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
David Henningsson28c4edb2010-12-20 14:24:29 +0100920 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
921 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +0100922 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
923 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
Jiang zhe2de3c232008-03-06 11:09:09 +0100924 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
925 {
926 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
927 .name = "Master Playback Switch",
928 .info = cxt_eapd_info,
929 .get = cxt_eapd_get,
930 .put = cxt5045_hp_master_sw_put,
931 .private_value = 0x10,
932 },
933
934 {}
935};
936
Tobin Davisc9b443d2006-11-14 12:13:39 +0100937static struct hda_verb cxt5045_init_verbs[] = {
938 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200939 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100940 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100941 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200942 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
943 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
944 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
945 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
946 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
947 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
948 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
950 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100951 /* Record selector: Internal mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100952 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100953 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100954 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
955 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100956 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100957 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100958 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100959 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 { } /* end */
961};
962
Jiang Zhe5218c892008-01-17 11:18:41 +0100963static struct hda_verb cxt5045_benq_init_verbs[] = {
David Henningsson28c4edb2010-12-20 14:24:29 +0100964 /* Internal Mic, Mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100965 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
966 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
967 /* Line In,HP, Amp */
968 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
969 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
970 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
971 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
972 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
973 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
974 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
976 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
David Henningsson28c4edb2010-12-20 14:24:29 +0100977 /* Record selector: Internal mic */
Jiang Zhe5218c892008-01-17 11:18:41 +0100978 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
979 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
980 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
981 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100982 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100983 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
984 /* EAPD */
985 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
986 { } /* end */
987};
Tobin Davis7f296732007-03-12 11:39:01 +0100988
989static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
990 /* pin sensing on HP jack */
991 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200992 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100993};
994
995static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
996 /* pin sensing on HP jack */
997 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200998 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100999};
1000
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001#ifdef CONFIG_SND_DEBUG
1002/* Test configuration for debugging, modelled after the ALC260 test
1003 * configuration.
1004 */
1005static struct hda_input_mux cxt5045_test_capture_source = {
1006 .num_items = 5,
1007 .items = {
1008 { "MIXER", 0x0 },
1009 { "MIC1 pin", 0x1 },
1010 { "LINE1 pin", 0x2 },
1011 { "HP-OUT pin", 0x3 },
1012 { "CD pin", 0x4 },
1013 },
1014};
1015
1016static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1017
1018 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001019 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1020 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001021 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1022 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1024 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001025
1026 /* Modes for retasking pin widgets */
1027 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1028 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1029
Tobin Davis82f30042007-02-13 12:45:44 +01001030 /* EAPD Switch Control */
1031 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1032
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001034
Tobin Davis7f296732007-03-12 11:39:01 +01001035 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1036 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1037 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1038 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1039 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1040 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1041 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1042 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1043 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1044 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001045 {
1046 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1047 .name = "Input Source",
1048 .info = conexant_mux_enum_info,
1049 .get = conexant_mux_enum_get,
1050 .put = conexant_mux_enum_put,
1051 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001052 /* Audio input controls */
1053 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1054 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1055 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1056 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1057 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1058 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1059 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1060 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1061 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1062 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001063 { } /* end */
1064};
1065
1066static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001067 /* Set connections */
1068 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1069 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1070 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071 /* Enable retasking pins as output, initially without power amp */
1072 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001073 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001074
1075 /* Disable digital (SPDIF) pins initially, but users can enable
1076 * them via a mixer switch. In the case of SPDIF-out, this initverb
1077 * payload also sets the generation to 0, output to be in "consumer"
1078 * PCM format, copyright asserted, no pre-emphasis and no validity
1079 * control.
1080 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001081 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1082 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001083
1084 /* Start with output sum widgets muted and their output gains at min */
1085 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1086 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1087
1088 /* Unmute retasking pin widget output buffers since the default
1089 * state appears to be output. As the pin mode is changed by the
1090 * user the pin mode control will take care of enabling the pin's
1091 * input/output buffers as needed.
1092 */
1093 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1094 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1095
1096 /* Mute capture amp left and right */
1097 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1098
1099 /* Set ADC connection select to match default mixer setting (mic1
1100 * pin)
1101 */
1102 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001103 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001104
1105 /* Mute all inputs to mixer widget (even unconnected ones) */
1106 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1107 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1108 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1109 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1110 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1111
1112 { }
1113};
1114#endif
1115
1116
1117/* initialize jack-sensing, too */
1118static int cxt5045_init(struct hda_codec *codec)
1119{
1120 conexant_init(codec);
1121 cxt5045_hp_automute(codec);
1122 return 0;
1123}
1124
1125
1126enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001127 CXT5045_LAPTOP_HPSENSE,
1128 CXT5045_LAPTOP_MICSENSE,
1129 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001130 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001131 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001132#ifdef CONFIG_SND_DEBUG
1133 CXT5045_TEST,
1134#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001135 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136};
1137
Takashi Iwaiea734962011-01-17 11:29:34 +01001138static const char * const cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001139 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1140 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1141 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1142 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001143 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001144#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001145 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001146#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001147};
1148
1149static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001150 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001151 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1152 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001153 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001154 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001155 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1156 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001157 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1158 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001159 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1160 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1161 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001162 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1163 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001164 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001165 {}
1166};
1167
1168static int patch_cxt5045(struct hda_codec *codec)
1169{
1170 struct conexant_spec *spec;
1171 int board_config;
1172
1173 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1174 if (!spec)
1175 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001176 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001177 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001178
1179 spec->multiout.max_channels = 2;
1180 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1181 spec->multiout.dac_nids = cxt5045_dac_nids;
1182 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1183 spec->num_adc_nids = 1;
1184 spec->adc_nids = cxt5045_adc_nids;
1185 spec->capsrc_nids = cxt5045_capsrc_nids;
1186 spec->input_mux = &cxt5045_capture_source;
1187 spec->num_mixers = 1;
1188 spec->mixers[0] = cxt5045_mixers;
1189 spec->num_init_verbs = 1;
1190 spec->init_verbs[0] = cxt5045_init_verbs;
1191 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001192 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1193 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001194
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001195 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001196
1197 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001198
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001199 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1200 cxt5045_models,
1201 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001202 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001203 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001204 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205 spec->input_mux = &cxt5045_capture_source;
1206 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001207 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1208 spec->mixers[0] = cxt5045_mixers;
1209 codec->patch_ops.init = cxt5045_init;
1210 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001211 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001212 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001213 spec->input_mux = &cxt5045_capture_source;
1214 spec->num_init_verbs = 2;
1215 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001216 spec->mixers[0] = cxt5045_mixers;
1217 codec->patch_ops.init = cxt5045_init;
1218 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001219 default:
1220 case CXT5045_LAPTOP_HPMICSENSE:
1221 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1222 spec->input_mux = &cxt5045_capture_source;
1223 spec->num_init_verbs = 3;
1224 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1225 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1226 spec->mixers[0] = cxt5045_mixers;
1227 codec->patch_ops.init = cxt5045_init;
1228 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001229 case CXT5045_BENQ:
1230 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1231 spec->input_mux = &cxt5045_capture_source_benq;
1232 spec->num_init_verbs = 1;
1233 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1234 spec->mixers[0] = cxt5045_mixers;
1235 spec->mixers[1] = cxt5045_benq_mixers;
1236 spec->num_mixers = 2;
1237 codec->patch_ops.init = cxt5045_init;
1238 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001239 case CXT5045_LAPTOP_HP530:
1240 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1241 spec->input_mux = &cxt5045_capture_source_hp530;
1242 spec->num_init_verbs = 2;
1243 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1244 spec->mixers[0] = cxt5045_mixers_hp530;
1245 codec->patch_ops.init = cxt5045_init;
1246 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001247#ifdef CONFIG_SND_DEBUG
1248 case CXT5045_TEST:
1249 spec->input_mux = &cxt5045_test_capture_source;
1250 spec->mixers[0] = cxt5045_test_mixer;
1251 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001252 break;
1253
Tobin Davisc9b443d2006-11-14 12:13:39 +01001254#endif
1255 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001256
Takashi Iwai031005f2008-06-26 14:49:58 +02001257 switch (codec->subsystem_id >> 16) {
1258 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001259 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001260 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001261 case 0x17aa:
1262 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1263 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1264 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001265 */
1266 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1267 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1268 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1269 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1270 (1 << AC_AMPCAP_MUTE_SHIFT));
1271 break;
1272 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001273
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001274 if (spec->beep_amp)
1275 snd_hda_attach_beep_device(codec, spec->beep_amp);
1276
Tobin Davisc9b443d2006-11-14 12:13:39 +01001277 return 0;
1278}
1279
1280
1281/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001282#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001284static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1286static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287
Tobin Davis5cd57522006-11-20 17:42:09 +01001288static struct hda_channel_mode cxt5047_modes[1] = {
1289 { 2, NULL },
1290};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001291
Tobin Davis82f30042007-02-13 12:45:44 +01001292static struct hda_input_mux cxt5047_toshiba_capture_source = {
1293 .num_items = 2,
1294 .items = {
1295 { "ExtMic", 0x2 },
1296 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 }
1298};
1299
1300/* turn on/off EAPD (+ mute HP) as a master switch */
1301static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1302 struct snd_ctl_elem_value *ucontrol)
1303{
1304 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1305 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001306 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001307
Tobin Davis82f30042007-02-13 12:45:44 +01001308 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001309 return 0;
1310
Tobin Davis82f30042007-02-13 12:45:44 +01001311 /* toggle internal speakers mute depending of presence of
1312 * the headphone jack
1313 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001314 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001315 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1316 * pin widgets unlike other codecs. In this case, we need to
1317 * set index 0x01 for the volume from the mixer amp 0x19.
1318 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001319 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001320 HDA_AMP_MUTE, bits);
1321 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1322 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1323 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001324 return 1;
1325}
1326
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327/* mute internal speaker if HP is plugged */
1328static void cxt5047_hp_automute(struct hda_codec *codec)
1329{
Tobin Davis82f30042007-02-13 12:45:44 +01001330 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001331 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001332
Takashi Iwaid56757a2009-11-18 08:00:14 +01001333 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001334
Takashi Iwai47fd8302007-08-10 17:11:07 +02001335 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001336 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001337 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001338 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001339}
1340
1341/* toggle input of built-in and mic jack appropriately */
1342static void cxt5047_hp_automic(struct hda_codec *codec)
1343{
1344 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001345 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1346 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001347 {}
1348 };
1349 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001350 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1351 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001352 {}
1353 };
1354 unsigned int present;
1355
Takashi Iwaid56757a2009-11-18 08:00:14 +01001356 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 if (present)
1358 snd_hda_sequence_write(codec, mic_jack_on);
1359 else
1360 snd_hda_sequence_write(codec, mic_jack_off);
1361}
1362
1363/* unsolicited event for HP jack sensing */
1364static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1365 unsigned int res)
1366{
Marc Boucher9f113e02008-01-22 15:18:08 +01001367 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001368 case CONEXANT_HP_EVENT:
1369 cxt5047_hp_automute(codec);
1370 break;
1371 case CONEXANT_MIC_EVENT:
1372 cxt5047_hp_automic(codec);
1373 break;
1374 }
1375}
1376
Takashi Iwaidf481e42009-03-10 15:35:35 +01001377static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1378 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1379 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001380 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1382 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1383 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1384 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001385 {
1386 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1387 .name = "Master Playback Switch",
1388 .info = cxt_eapd_info,
1389 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001390 .put = cxt5047_hp_master_sw_put,
1391 .private_value = 0x13,
1392 },
1393
1394 {}
1395};
1396
Takashi Iwaidf481e42009-03-10 15:35:35 +01001397static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001398 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001399 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001400 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1401 {}
1402};
1403
1404static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001406 { } /* end */
1407};
1408
1409static struct hda_verb cxt5047_init_verbs[] = {
1410 /* Line in, Mic, Built-in Mic */
1411 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1412 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1413 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001414 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001415 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001416 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1417 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001418 /* Record selector: Mic */
1419 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1420 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1421 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1422 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001423 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1424 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1425 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1426 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001427 /* SPDIF route: PCM */
1428 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001429 /* Enable unsolicited events */
1430 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1431 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001432 { } /* end */
1433};
1434
1435/* configuration for Toshiba Laptops */
1436static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001437 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001438 {}
1439};
1440
1441/* Test configuration for debugging, modelled after the ALC260 test
1442 * configuration.
1443 */
1444#ifdef CONFIG_SND_DEBUG
1445static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001446 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001447 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001448 { "LINE1 pin", 0x0 },
1449 { "MIC1 pin", 0x1 },
1450 { "MIC2 pin", 0x2 },
1451 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001452 },
1453};
1454
1455static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1456
1457 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001458 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1459 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1460 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1461 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001462 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1463 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1464 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1465 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001466 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1467 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1468 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1469 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001470
1471 /* Modes for retasking pin widgets */
1472 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1473 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1474
Tobin Davis82f30042007-02-13 12:45:44 +01001475 /* EAPD Switch Control */
1476 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1477
Tobin Davisc9b443d2006-11-14 12:13:39 +01001478 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001479 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1480 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1481 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1482 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1483 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1484 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1485 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1486 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001487
Tobin Davis82f30042007-02-13 12:45:44 +01001488 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1489 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1490 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1491 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1492 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1493 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1494 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1495 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001496 {
1497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1498 .name = "Input Source",
1499 .info = conexant_mux_enum_info,
1500 .get = conexant_mux_enum_get,
1501 .put = conexant_mux_enum_put,
1502 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001503 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001504
Tobin Davisc9b443d2006-11-14 12:13:39 +01001505 { } /* end */
1506};
1507
1508static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001509 /* Enable retasking pins as output, initially without power amp */
1510 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1511 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1512 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1513
1514 /* Disable digital (SPDIF) pins initially, but users can enable
1515 * them via a mixer switch. In the case of SPDIF-out, this initverb
1516 * payload also sets the generation to 0, output to be in "consumer"
1517 * PCM format, copyright asserted, no pre-emphasis and no validity
1518 * control.
1519 */
1520 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1521
1522 /* Ensure mic1, mic2, line1 pin widgets take input from the
1523 * OUT1 sum bus when acting as an output.
1524 */
1525 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1526 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1527
1528 /* Start with output sum widgets muted and their output gains at min */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1531
1532 /* Unmute retasking pin widget output buffers since the default
1533 * state appears to be output. As the pin mode is changed by the
1534 * user the pin mode control will take care of enabling the pin's
1535 * input/output buffers as needed.
1536 */
1537 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1538 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1539 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1540
1541 /* Mute capture amp left and right */
1542 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1543
1544 /* Set ADC connection select to match default mixer setting (mic1
1545 * pin)
1546 */
1547 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1548
1549 /* Mute all inputs to mixer widget (even unconnected ones) */
1550 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1551 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1552 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1553 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1554 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1555 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1556 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1557 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1558
1559 { }
1560};
1561#endif
1562
1563
1564/* initialize jack-sensing, too */
1565static int cxt5047_hp_init(struct hda_codec *codec)
1566{
1567 conexant_init(codec);
1568 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001569 return 0;
1570}
1571
1572
1573enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001574 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1575 CXT5047_LAPTOP_HP, /* Some HP laptops */
1576 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001577#ifdef CONFIG_SND_DEBUG
1578 CXT5047_TEST,
1579#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001580 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001581};
1582
Takashi Iwaiea734962011-01-17 11:29:34 +01001583static const char * const cxt5047_models[CXT5047_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001584 [CXT5047_LAPTOP] = "laptop",
1585 [CXT5047_LAPTOP_HP] = "laptop-hp",
1586 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001587#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001588 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001589#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001590};
1591
1592static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001593 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001594 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1595 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001596 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001597 {}
1598};
1599
1600static int patch_cxt5047(struct hda_codec *codec)
1601{
1602 struct conexant_spec *spec;
1603 int board_config;
1604
1605 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1606 if (!spec)
1607 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001608 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001609 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610
1611 spec->multiout.max_channels = 2;
1612 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1613 spec->multiout.dac_nids = cxt5047_dac_nids;
1614 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1615 spec->num_adc_nids = 1;
1616 spec->adc_nids = cxt5047_adc_nids;
1617 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001618 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001619 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001620 spec->num_init_verbs = 1;
1621 spec->init_verbs[0] = cxt5047_init_verbs;
1622 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001623 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1624 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001625
1626 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001627
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001628 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1629 cxt5047_models,
1630 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001631 switch (board_config) {
1632 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001633 spec->num_mixers = 2;
1634 spec->mixers[1] = cxt5047_hp_spk_mixers;
1635 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001636 break;
1637 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001638 spec->num_mixers = 2;
1639 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001640 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001641 codec->patch_ops.init = cxt5047_hp_init;
1642 break;
1643 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001644 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001645 spec->num_mixers = 2;
1646 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001647 spec->num_init_verbs = 2;
1648 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001649 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001650 break;
1651#ifdef CONFIG_SND_DEBUG
1652 case CXT5047_TEST:
1653 spec->input_mux = &cxt5047_test_capture_source;
1654 spec->mixers[0] = cxt5047_test_mixer;
1655 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001656 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001657#endif
1658 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001659 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001660
1661 switch (codec->subsystem_id >> 16) {
1662 case 0x103c:
1663 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1664 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1665 * with 0 dB offset 0x17)
1666 */
1667 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1668 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1669 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1670 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1671 (1 << AC_AMPCAP_MUTE_SHIFT));
1672 break;
1673 }
1674
Tobin Davisc9b443d2006-11-14 12:13:39 +01001675 return 0;
1676}
1677
Takashi Iwai461e2c72008-01-25 11:35:17 +01001678/* Conexant 5051 specific */
1679static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1680static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001681
1682static struct hda_channel_mode cxt5051_modes[1] = {
1683 { 2, NULL },
1684};
1685
1686static void cxt5051_update_speaker(struct hda_codec *codec)
1687{
1688 struct conexant_spec *spec = codec->spec;
1689 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001690 /* headphone pin */
1691 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1692 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1693 pinctl);
1694 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001695 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1696 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1697 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001698 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1699 if (spec->ideapad)
1700 snd_hda_codec_write(codec, 0x1b, 0,
1701 AC_VERB_SET_PIN_WIDGET_CONTROL,
1702 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001703}
1704
1705/* turn on/off EAPD (+ mute HP) as a master switch */
1706static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_value *ucontrol)
1708{
1709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1710
1711 if (!cxt_eapd_put(kcontrol, ucontrol))
1712 return 0;
1713 cxt5051_update_speaker(codec);
1714 return 1;
1715}
1716
1717/* toggle input of built-in and mic jack appropriately */
1718static void cxt5051_portb_automic(struct hda_codec *codec)
1719{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001720 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001721 unsigned int present;
1722
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001723 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001724 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001725 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001726 snd_hda_codec_write(codec, 0x14, 0,
1727 AC_VERB_SET_CONNECT_SEL,
1728 present ? 0x01 : 0x00);
1729}
1730
1731/* switch the current ADC according to the jack state */
1732static void cxt5051_portc_automic(struct hda_codec *codec)
1733{
1734 struct conexant_spec *spec = codec->spec;
1735 unsigned int present;
1736 hda_nid_t new_adc;
1737
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001738 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001739 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001740 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001741 if (present)
1742 spec->cur_adc_idx = 1;
1743 else
1744 spec->cur_adc_idx = 0;
1745 new_adc = spec->adc_nids[spec->cur_adc_idx];
1746 if (spec->cur_adc && spec->cur_adc != new_adc) {
1747 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001748 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001749 spec->cur_adc = new_adc;
1750 snd_hda_codec_setup_stream(codec, new_adc,
1751 spec->cur_adc_stream_tag, 0,
1752 spec->cur_adc_format);
1753 }
1754}
1755
1756/* mute internal speaker if HP is plugged */
1757static void cxt5051_hp_automute(struct hda_codec *codec)
1758{
1759 struct conexant_spec *spec = codec->spec;
1760
Takashi Iwaid56757a2009-11-18 08:00:14 +01001761 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001762 cxt5051_update_speaker(codec);
1763}
1764
1765/* unsolicited event for HP jack sensing */
1766static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1767 unsigned int res)
1768{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001769 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001770 switch (res >> 26) {
1771 case CONEXANT_HP_EVENT:
1772 cxt5051_hp_automute(codec);
1773 break;
1774 case CXT5051_PORTB_EVENT:
1775 cxt5051_portb_automic(codec);
1776 break;
1777 case CXT5051_PORTC_EVENT:
1778 cxt5051_portc_automic(codec);
1779 break;
1780 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001781 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001782}
1783
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001784static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001785 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1786 {
1787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1788 .name = "Master Playback Switch",
1789 .info = cxt_eapd_info,
1790 .get = cxt_eapd_get,
1791 .put = cxt5051_hp_master_sw_put,
1792 .private_value = 0x1a,
1793 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001794 {}
1795};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001796
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001797static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1798 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001800 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1801 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001802 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1803 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001804 {}
1805};
1806
1807static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1808 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1809 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001810 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1811 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001812 {}
1813};
1814
Takashi Iwai79d7d532009-03-04 09:03:50 +01001815static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001816 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1817 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001818 {}
1819};
1820
Ken Proxcd9d95a2010-01-08 09:01:47 +01001821static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001822 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1823 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001824 {}
1825};
1826
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001827static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1828 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1829 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
David Henningsson8607f7c2010-12-20 14:43:54 +01001830 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1831 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001832 {}
1833};
1834
Takashi Iwai461e2c72008-01-25 11:35:17 +01001835static struct hda_verb cxt5051_init_verbs[] = {
1836 /* Line in, Mic */
1837 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1838 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1839 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1840 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1841 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1842 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1843 /* SPK */
1844 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1845 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1846 /* HP, Amp */
1847 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1848 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1849 /* DAC1 */
1850 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001851 /* Record selector: Internal mic */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1853 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1854 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1855 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001856 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001857 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1858 /* EAPD */
1859 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1860 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001861 { } /* end */
1862};
1863
Takashi Iwai79d7d532009-03-04 09:03:50 +01001864static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1865 /* Line in, Mic */
1866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1867 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1868 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1869 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1870 /* SPK */
1871 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1872 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1873 /* HP, Amp */
1874 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1875 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1876 /* DAC1 */
1877 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001878 /* Record selector: Internal mic */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1880 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1881 /* SPDIF route: PCM */
1882 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1883 /* EAPD */
1884 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1885 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001886 { } /* end */
1887};
1888
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001889static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1890 /* Line in, Mic */
1891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1892 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1893 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1894 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1895 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1896 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1897 /* SPK */
1898 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1899 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1900 /* HP, Amp */
1901 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1902 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1903 /* Docking HP */
1904 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1905 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1906 /* DAC1 */
1907 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001908 /* Record selector: Internal mic */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1910 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1911 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1912 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001913 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001914 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1915 /* EAPD */
1916 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1917 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001918 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1919 { } /* end */
1920};
1921
Ken Proxcd9d95a2010-01-08 09:01:47 +01001922static struct hda_verb cxt5051_f700_init_verbs[] = {
1923 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001924 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001925 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1926 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1927 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1928 /* SPK */
1929 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1930 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1931 /* HP, Amp */
1932 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1933 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1934 /* DAC1 */
1935 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
David Henningsson28c4edb2010-12-20 14:24:29 +01001936 /* Record selector: Internal mic */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001937 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1938 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1939 /* SPDIF route: PCM */
1940 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1941 /* EAPD */
1942 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1943 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001944 { } /* end */
1945};
1946
Takashi Iwai6953e552010-01-24 11:00:27 +01001947static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1948 unsigned int event)
1949{
1950 snd_hda_codec_write(codec, nid, 0,
1951 AC_VERB_SET_UNSOLICITED_ENABLE,
1952 AC_USRSP_EN | event);
1953#ifdef CONFIG_SND_HDA_INPUT_JACK
1954 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1955 conexant_report_jack(codec, nid);
1956#endif
1957}
1958
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001959static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1960 /* Subwoofer */
1961 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1962 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1963 { } /* end */
1964};
1965
Takashi Iwai461e2c72008-01-25 11:35:17 +01001966/* initialize jack-sensing, too */
1967static int cxt5051_init(struct hda_codec *codec)
1968{
Takashi Iwai6953e552010-01-24 11:00:27 +01001969 struct conexant_spec *spec = codec->spec;
1970
Takashi Iwai461e2c72008-01-25 11:35:17 +01001971 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001972 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001973
1974 if (spec->auto_mic & AUTO_MIC_PORTB)
1975 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1976 if (spec->auto_mic & AUTO_MIC_PORTC)
1977 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1978
Takashi Iwai461e2c72008-01-25 11:35:17 +01001979 if (codec->patch_ops.unsol_event) {
1980 cxt5051_hp_automute(codec);
1981 cxt5051_portb_automic(codec);
1982 cxt5051_portc_automic(codec);
1983 }
1984 return 0;
1985}
1986
1987
1988enum {
1989 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1990 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001991 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001992 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001993 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001994 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001995 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001996 CXT5051_MODELS
1997};
1998
Takashi Iwaiea734962011-01-17 11:29:34 +01001999static const char *const cxt5051_models[CXT5051_MODELS] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01002000 [CXT5051_LAPTOP] = "laptop",
2001 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01002002 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002003 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002004 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002005 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002006 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai461e2c72008-01-25 11:35:17 +01002007};
2008
2009static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01002010 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01002011 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002012 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002013 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002014 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2015 CXT5051_LAPTOP),
2016 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002017 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002018 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002019 {}
2020};
2021
2022static int patch_cxt5051(struct hda_codec *codec)
2023{
2024 struct conexant_spec *spec;
2025 int board_config;
2026
2027 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2028 if (!spec)
2029 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002030 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002031 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002032
2033 codec->patch_ops = conexant_patch_ops;
2034 codec->patch_ops.init = cxt5051_init;
2035
2036 spec->multiout.max_channels = 2;
2037 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2038 spec->multiout.dac_nids = cxt5051_dac_nids;
2039 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2040 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2041 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002042 spec->num_mixers = 2;
2043 spec->mixers[0] = cxt5051_capture_mixers;
2044 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002045 spec->num_init_verbs = 1;
2046 spec->init_verbs[0] = cxt5051_init_verbs;
2047 spec->spdif_route = 0;
2048 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2049 spec->channel_mode = cxt5051_modes;
2050 spec->cur_adc = 0;
2051 spec->cur_adc_idx = 0;
2052
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002053 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2054
Takashi Iwai79d7d532009-03-04 09:03:50 +01002055 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2056
Takashi Iwai461e2c72008-01-25 11:35:17 +01002057 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2058 cxt5051_models,
2059 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002060 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002061 switch (board_config) {
2062 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002063 spec->mixers[0] = cxt5051_hp_mixers;
2064 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002065 case CXT5051_HP_DV6736:
2066 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2067 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002068 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002069 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002070 case CXT5051_LENOVO_X200:
2071 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002072 /* Thinkpad X301 does not have S/PDIF wired and no ability
2073 to use a docking station. */
2074 if (codec->subsystem_id == 0x17aa211f)
2075 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002076 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002077 case CXT5051_F700:
2078 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2079 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002080 spec->auto_mic = 0;
2081 break;
2082 case CXT5051_TOSHIBA:
2083 spec->mixers[0] = cxt5051_toshiba_mixers;
2084 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002085 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002086 case CXT5051_IDEAPAD:
2087 spec->init_verbs[spec->num_init_verbs++] =
2088 cxt5051_ideapad_init_verbs;
2089 spec->ideapad = 1;
2090 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002091 }
2092
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002093 if (spec->beep_amp)
2094 snd_hda_attach_beep_device(codec, spec->beep_amp);
2095
Takashi Iwai461e2c72008-01-25 11:35:17 +01002096 return 0;
2097}
2098
Daniel Drake0fb67e92009-07-16 14:46:57 +01002099/* Conexant 5066 specific */
2100
2101static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2102static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2103static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2104#define CXT5066_SPDIF_OUT 0x21
2105
Daniel Drakedbaccc02009-11-09 15:17:24 +00002106/* OLPC's microphone port is DC coupled for use with external sensors,
2107 * therefore we use a 50% mic bias in order to center the input signal with
2108 * the DC input range of the codec. */
2109#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2110
Daniel Drake0fb67e92009-07-16 14:46:57 +01002111static struct hda_channel_mode cxt5066_modes[1] = {
2112 { 2, NULL },
2113};
2114
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002115#define HP_PRESENT_PORT_A (1 << 0)
2116#define HP_PRESENT_PORT_D (1 << 1)
2117#define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2118#define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2119
Daniel Drake0fb67e92009-07-16 14:46:57 +01002120static void cxt5066_update_speaker(struct hda_codec *codec)
2121{
2122 struct conexant_spec *spec = codec->spec;
2123 unsigned int pinctl;
2124
John Baboval3a253442010-12-02 11:21:31 -05002125 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2126 spec->hp_present, spec->cur_eapd);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002127
2128 /* Port A (HP) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002129 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002130 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2131 pinctl);
2132
2133 /* Port D (HP/LO) */
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002134 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2135 if (spec->dell_automute || spec->thinkpad) {
2136 /* Mute if Port A is connected */
2137 if (hp_port_a_present(spec))
John Baboval3a253442010-12-02 11:21:31 -05002138 pinctl = 0;
2139 } else {
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002140 /* Thinkpad/Dell doesn't give pin-D status */
2141 if (!hp_port_d_present(spec))
2142 pinctl = 0;
John Baboval3a253442010-12-02 11:21:31 -05002143 }
Daniel Drake0fb67e92009-07-16 14:46:57 +01002144 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2145 pinctl);
2146
2147 /* CLASS_D AMP */
2148 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2149 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2150 pinctl);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002151}
2152
2153/* turn on/off EAPD (+ mute HP) as a master switch */
2154static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2155 struct snd_ctl_elem_value *ucontrol)
2156{
2157 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2158
2159 if (!cxt_eapd_put(kcontrol, ucontrol))
2160 return 0;
2161
2162 cxt5066_update_speaker(codec);
2163 return 1;
2164}
2165
Daniel Drakec4cfe662010-01-07 13:47:04 +01002166static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2167 .num_items = 3,
2168 .items = {
2169 { "Off", PIN_IN },
2170 { "50%", PIN_VREF50 },
2171 { "80%", PIN_VREF80 },
2172 },
2173};
2174
2175static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2176{
2177 struct conexant_spec *spec = codec->spec;
2178 /* Even though port F is the DC input, the bias is controlled on port B.
2179 * we also leave that port as an active input (but unselected) in DC mode
2180 * just in case that is necessary to make the bias setting take effect. */
2181 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2182 AC_VERB_SET_PIN_WIDGET_CONTROL,
2183 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2184}
2185
Daniel Drake75f89912010-01-07 13:46:25 +01002186/* OLPC defers mic widget control until when capture is started because the
2187 * microphone LED comes on as soon as these settings are put in place. if we
2188 * did this before recording, it would give the false indication that recording
2189 * is happening when it is not. */
2190static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002191{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002192 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002193 if (!spec->recording)
2194 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002195
Daniel Drakec4cfe662010-01-07 13:47:04 +01002196 if (spec->dc_enable) {
2197 /* in DC mode we ignore presence detection and just use the jack
2198 * through our special DC port */
2199 const struct hda_verb enable_dc_mode[] = {
2200 /* disble internal mic, port C */
2201 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2202
2203 /* enable DC capture, port F */
2204 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2205 {},
2206 };
2207
2208 snd_hda_sequence_write(codec, enable_dc_mode);
2209 /* port B input disabled (and bias set) through the following call */
2210 cxt5066_set_olpc_dc_bias(codec);
2211 return;
2212 }
2213
2214 /* disable DC (port F) */
2215 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2216
Daniel Drake75f89912010-01-07 13:46:25 +01002217 /* external mic, port B */
2218 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2219 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002220
Daniel Drake75f89912010-01-07 13:46:25 +01002221 /* internal mic, port C */
2222 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2223 spec->ext_mic_present ? 0 : PIN_VREF80);
2224}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002225
Daniel Drake75f89912010-01-07 13:46:25 +01002226/* toggle input of built-in and mic jack appropriately */
2227static void cxt5066_olpc_automic(struct hda_codec *codec)
2228{
2229 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002230 unsigned int present;
2231
Daniel Drakec4cfe662010-01-07 13:47:04 +01002232 if (spec->dc_enable) /* don't do presence detection in DC mode */
2233 return;
2234
Daniel Drake75f89912010-01-07 13:46:25 +01002235 present = snd_hda_codec_read(codec, 0x1a, 0,
2236 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2237 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002238 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002239 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002240 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002241
2242 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2243 present ? 0 : 1);
2244 spec->ext_mic_present = !!present;
2245
2246 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002247}
2248
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002249/* toggle input of built-in digital mic and mic jack appropriately */
2250static void cxt5066_vostro_automic(struct hda_codec *codec)
2251{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002252 unsigned int present;
2253
2254 struct hda_verb ext_mic_present[] = {
2255 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002256 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002257
2258 /* switch to external mic input */
2259 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2260 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2261
2262 /* disable internal digital mic */
2263 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2264 {}
2265 };
2266 static struct hda_verb ext_mic_absent[] = {
2267 /* enable internal mic, port C */
2268 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2269
2270 /* switch to internal mic input */
2271 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2272
2273 /* disable external mic, port B */
2274 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2275 {}
2276 };
2277
2278 present = snd_hda_jack_detect(codec, 0x1a);
2279 if (present) {
2280 snd_printdd("CXT5066: external microphone detected\n");
2281 snd_hda_sequence_write(codec, ext_mic_present);
2282 } else {
2283 snd_printdd("CXT5066: external microphone absent\n");
2284 snd_hda_sequence_write(codec, ext_mic_absent);
2285 }
2286}
2287
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002288/* toggle input of built-in digital mic and mic jack appropriately */
2289static void cxt5066_ideapad_automic(struct hda_codec *codec)
2290{
2291 unsigned int present;
2292
2293 struct hda_verb ext_mic_present[] = {
2294 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2295 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297 {}
2298 };
2299 static struct hda_verb ext_mic_absent[] = {
2300 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2301 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2302 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2303 {}
2304 };
2305
2306 present = snd_hda_jack_detect(codec, 0x1b);
2307 if (present) {
2308 snd_printdd("CXT5066: external microphone detected\n");
2309 snd_hda_sequence_write(codec, ext_mic_present);
2310 } else {
2311 snd_printdd("CXT5066: external microphone absent\n");
2312 snd_hda_sequence_write(codec, ext_mic_absent);
2313 }
2314}
2315
David Henningssona1d69062011-01-21 13:33:28 +01002316
2317/* toggle input of built-in digital mic and mic jack appropriately */
2318static void cxt5066_asus_automic(struct hda_codec *codec)
2319{
2320 unsigned int present;
2321
2322 present = snd_hda_jack_detect(codec, 0x1b);
2323 snd_printdd("CXT5066: external microphone present=%d\n", present);
2324 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2325 present ? 1 : 0);
2326}
2327
2328
David Henningsson048e78a2010-09-02 08:35:47 +02002329/* toggle input of built-in digital mic and mic jack appropriately */
2330static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2331{
2332 unsigned int present;
2333
2334 present = snd_hda_jack_detect(codec, 0x1b);
2335 snd_printdd("CXT5066: external microphone present=%d\n", present);
2336 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2337 present ? 1 : 3);
2338}
2339
2340
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002341/* toggle input of built-in digital mic and mic jack appropriately
2342 order is: external mic -> dock mic -> interal mic */
2343static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2344{
2345 unsigned int ext_present, dock_present;
2346
2347 static struct hda_verb ext_mic_present[] = {
2348 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2349 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2350 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2351 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2352 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2353 {}
2354 };
2355 static struct hda_verb dock_mic_present[] = {
2356 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2357 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2358 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2359 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2360 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2361 {}
2362 };
2363 static struct hda_verb ext_mic_absent[] = {
2364 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2365 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2366 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2367 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2368 {}
2369 };
2370
2371 ext_present = snd_hda_jack_detect(codec, 0x1b);
2372 dock_present = snd_hda_jack_detect(codec, 0x1a);
2373 if (ext_present) {
2374 snd_printdd("CXT5066: external microphone detected\n");
2375 snd_hda_sequence_write(codec, ext_mic_present);
2376 } else if (dock_present) {
2377 snd_printdd("CXT5066: dock microphone detected\n");
2378 snd_hda_sequence_write(codec, dock_mic_present);
2379 } else {
2380 snd_printdd("CXT5066: external microphone absent\n");
2381 snd_hda_sequence_write(codec, ext_mic_absent);
2382 }
2383}
2384
Daniel Drake0fb67e92009-07-16 14:46:57 +01002385/* mute internal speaker if HP is plugged */
2386static void cxt5066_hp_automute(struct hda_codec *codec)
2387{
2388 struct conexant_spec *spec = codec->spec;
2389 unsigned int portA, portD;
2390
2391 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002392 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002393
2394 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002395 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002396
Takashi Iwaia3de8ab2010-12-03 12:29:14 +01002397 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2398 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002399 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2400 portA, portD, spec->hp_present);
2401 cxt5066_update_speaker(codec);
2402}
2403
David Henningsson02b6b5b2011-01-21 13:27:39 +01002404/* Dispatch the right mic autoswitch function */
2405static void cxt5066_automic(struct hda_codec *codec)
2406{
2407 struct conexant_spec *spec = codec->spec;
2408
2409 if (spec->dell_vostro)
2410 cxt5066_vostro_automic(codec);
2411 else if (spec->ideapad)
2412 cxt5066_ideapad_automic(codec);
2413 else if (spec->thinkpad)
2414 cxt5066_thinkpad_automic(codec);
2415 else if (spec->hp_laptop)
2416 cxt5066_hp_laptop_automic(codec);
David Henningssona1d69062011-01-21 13:33:28 +01002417 else if (spec->asus)
2418 cxt5066_asus_automic(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01002419}
2420
Daniel Drake0fb67e92009-07-16 14:46:57 +01002421/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002422static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002423{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002424 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002425 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2426 switch (res >> 26) {
2427 case CONEXANT_HP_EVENT:
2428 cxt5066_hp_automute(codec);
2429 break;
2430 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002431 /* ignore mic events in DC mode; we're always using the jack */
2432 if (!spec->dc_enable)
2433 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002434 break;
2435 }
2436}
2437
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002438/* unsolicited event for jack sensing */
David Henningsson02b6b5b2011-01-21 13:27:39 +01002439static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002440{
David Henningsson02b6b5b2011-01-21 13:27:39 +01002441 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002442 switch (res >> 26) {
2443 case CONEXANT_HP_EVENT:
2444 cxt5066_hp_automute(codec);
2445 break;
2446 case CONEXANT_MIC_EVENT:
David Henningsson02b6b5b2011-01-21 13:27:39 +01002447 cxt5066_automic(codec);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002448 break;
2449 }
2450}
2451
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002452
Daniel Drake0fb67e92009-07-16 14:46:57 +01002453static const struct hda_input_mux cxt5066_analog_mic_boost = {
2454 .num_items = 5,
2455 .items = {
2456 { "0dB", 0 },
2457 { "10dB", 1 },
2458 { "20dB", 2 },
2459 { "30dB", 3 },
2460 { "40dB", 4 },
2461 },
2462};
2463
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002464static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002465{
2466 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002467 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002468 AC_VERB_SET_AMP_GAIN_MUTE,
2469 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2470 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002471 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002472 /* adjust the internal mic as well...it is not through 0x17 */
2473 snd_hda_codec_write_cache(codec, 0x23, 0,
2474 AC_VERB_SET_AMP_GAIN_MUTE,
2475 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2476 cxt5066_analog_mic_boost.
2477 items[spec->mic_boost].index);
2478 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002479}
2480
Daniel Drake0fb67e92009-07-16 14:46:57 +01002481static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2482 struct snd_ctl_elem_info *uinfo)
2483{
2484 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2485}
2486
2487static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2488 struct snd_ctl_elem_value *ucontrol)
2489{
2490 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002491 struct conexant_spec *spec = codec->spec;
2492 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002493 return 0;
2494}
2495
2496static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2497 struct snd_ctl_elem_value *ucontrol)
2498{
2499 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002500 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002501 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2502 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002503 idx = ucontrol->value.enumerated.item[0];
2504 if (idx >= imux->num_items)
2505 idx = imux->num_items - 1;
2506
Daniel Drakec4cfe662010-01-07 13:47:04 +01002507 spec->mic_boost = idx;
2508 if (!spec->dc_enable)
2509 cxt5066_set_mic_boost(codec);
2510 return 1;
2511}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002512
Daniel Drakec4cfe662010-01-07 13:47:04 +01002513static void cxt5066_enable_dc(struct hda_codec *codec)
2514{
2515 const struct hda_verb enable_dc_mode[] = {
2516 /* disable gain */
2517 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518
2519 /* switch to DC input */
2520 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2521 {}
2522 };
2523
2524 /* configure as input source */
2525 snd_hda_sequence_write(codec, enable_dc_mode);
2526 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2527}
2528
2529static void cxt5066_disable_dc(struct hda_codec *codec)
2530{
2531 /* reconfigure input source */
2532 cxt5066_set_mic_boost(codec);
2533 /* automic also selects the right mic if we're recording */
2534 cxt5066_olpc_automic(codec);
2535}
2536
2537static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2538 struct snd_ctl_elem_value *ucontrol)
2539{
2540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2541 struct conexant_spec *spec = codec->spec;
2542 ucontrol->value.integer.value[0] = spec->dc_enable;
2543 return 0;
2544}
2545
2546static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2548{
2549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550 struct conexant_spec *spec = codec->spec;
2551 int dc_enable = !!ucontrol->value.integer.value[0];
2552
2553 if (dc_enable == spec->dc_enable)
2554 return 0;
2555
2556 spec->dc_enable = dc_enable;
2557 if (dc_enable)
2558 cxt5066_enable_dc(codec);
2559 else
2560 cxt5066_disable_dc(codec);
2561
2562 return 1;
2563}
2564
2565static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2566 struct snd_ctl_elem_info *uinfo)
2567{
2568 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2569}
2570
2571static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2572 struct snd_ctl_elem_value *ucontrol)
2573{
2574 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2575 struct conexant_spec *spec = codec->spec;
2576 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2577 return 0;
2578}
2579
2580static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2581 struct snd_ctl_elem_value *ucontrol)
2582{
2583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2584 struct conexant_spec *spec = codec->spec;
2585 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2586 unsigned int idx;
2587
2588 idx = ucontrol->value.enumerated.item[0];
2589 if (idx >= imux->num_items)
2590 idx = imux->num_items - 1;
2591
2592 spec->dc_input_bias = idx;
2593 if (spec->dc_enable)
2594 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002595 return 1;
2596}
2597
Daniel Drake75f89912010-01-07 13:46:25 +01002598static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2599{
2600 struct conexant_spec *spec = codec->spec;
2601 /* mark as recording and configure the microphone widget so that the
2602 * recording LED comes on. */
2603 spec->recording = 1;
2604 cxt5066_olpc_select_mic(codec);
2605}
2606
2607static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2608{
2609 struct conexant_spec *spec = codec->spec;
2610 const struct hda_verb disable_mics[] = {
2611 /* disable external mic, port B */
2612 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2613
2614 /* disble internal mic, port C */
2615 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002616
2617 /* disable DC capture, port F */
2618 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002619 {},
2620 };
2621
2622 snd_hda_sequence_write(codec, disable_mics);
2623 spec->recording = 0;
2624}
2625
Daniel Drake0fb67e92009-07-16 14:46:57 +01002626static struct hda_input_mux cxt5066_capture_source = {
2627 .num_items = 4,
2628 .items = {
2629 { "Mic B", 0 },
2630 { "Mic C", 1 },
2631 { "Mic E", 2 },
2632 { "Mic F", 3 },
2633 },
2634};
2635
2636static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2637 .ops = &snd_hda_bind_vol,
2638 .values = {
2639 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2640 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2641 0
2642 },
2643};
2644
2645static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2646 .ops = &snd_hda_bind_sw,
2647 .values = {
2648 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2649 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2650 0
2651 },
2652};
2653
2654static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2655 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2656 {}
2657};
2658
2659static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2660 {
2661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2662 .name = "Master Playback Volume",
2663 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2664 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2665 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002666 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002667 .info = snd_hda_mixer_amp_volume_info,
2668 .get = snd_hda_mixer_amp_volume_get,
2669 .put = snd_hda_mixer_amp_volume_put,
2670 .tlv = { .c = snd_hda_mixer_amp_tlv },
2671 /* offset by 28 volume steps to limit minimum gain to -46dB */
2672 .private_value =
2673 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2674 },
2675 {}
2676};
2677
Daniel Drakec4cfe662010-01-07 13:47:04 +01002678static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2679 {
2680 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2681 .name = "DC Mode Enable Switch",
2682 .info = snd_ctl_boolean_mono_info,
2683 .get = cxt5066_olpc_dc_get,
2684 .put = cxt5066_olpc_dc_put,
2685 },
2686 {
2687 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2688 .name = "DC Input Bias Enum",
2689 .info = cxt5066_olpc_dc_bias_enum_info,
2690 .get = cxt5066_olpc_dc_bias_enum_get,
2691 .put = cxt5066_olpc_dc_bias_enum_put,
2692 },
2693 {}
2694};
2695
Daniel Drake0fb67e92009-07-16 14:46:57 +01002696static struct snd_kcontrol_new cxt5066_mixers[] = {
2697 {
2698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2699 .name = "Master Playback Switch",
2700 .info = cxt_eapd_info,
2701 .get = cxt_eapd_get,
2702 .put = cxt5066_hp_master_sw_put,
2703 .private_value = 0x1d,
2704 },
2705
2706 {
2707 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002708 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002709 .info = cxt5066_mic_boost_mux_enum_info,
2710 .get = cxt5066_mic_boost_mux_enum_get,
2711 .put = cxt5066_mic_boost_mux_enum_put,
2712 },
2713
2714 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2715 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2716 {}
2717};
2718
Einar Rünkaru254bba62009-12-16 22:16:13 +02002719static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2720 {
2721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
David Henningsson28c4edb2010-12-20 14:24:29 +01002722 .name = "Internal Mic Boost Capture Enum",
Einar Rünkaru254bba62009-12-16 22:16:13 +02002723 .info = cxt5066_mic_boost_mux_enum_info,
2724 .get = cxt5066_mic_boost_mux_enum_get,
2725 .put = cxt5066_mic_boost_mux_enum_put,
2726 .private_value = 0x23 | 0x100,
2727 },
2728 {}
2729};
2730
Daniel Drake0fb67e92009-07-16 14:46:57 +01002731static struct hda_verb cxt5066_init_verbs[] = {
2732 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2733 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2734 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2735 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2736
2737 /* Speakers */
2738 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2739 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2740
2741 /* HP, Amp */
2742 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2743 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2744
2745 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2746 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2747
2748 /* DAC1 */
2749 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2750
2751 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2752 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2753 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2757
2758 /* no digital microphone support yet */
2759 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2760
2761 /* Audio input selector */
2762 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2763
2764 /* SPDIF route: PCM */
2765 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2766 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2767
2768 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2769 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2770
2771 /* EAPD */
2772 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2773
2774 /* not handling these yet */
2775 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2776 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2777 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2778 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2779 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2780 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2781 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2782 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2783 { } /* end */
2784};
2785
2786static struct hda_verb cxt5066_init_verbs_olpc[] = {
2787 /* Port A: headphones */
2788 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2789 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2790
2791 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002792 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002793
2794 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002795 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002796
2797 /* Port D: unused */
2798 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2799
2800 /* Port E: unused, but has primary EAPD */
2801 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2802 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2803
Daniel Drakec4cfe662010-01-07 13:47:04 +01002804 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002805 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2806
2807 /* Port G: internal speakers */
2808 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2809 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2810
2811 /* DAC1 */
2812 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2813
2814 /* DAC2: unused */
2815 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2816
2817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2821 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2822 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2823 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2824 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2825 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2826 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2827 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2828 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2829
2830 /* Disable digital microphone port */
2831 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2832
2833 /* Audio input selectors */
2834 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2835 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2836
2837 /* Disable SPDIF */
2838 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2839 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2840
2841 /* enable unsolicited events for Port A and B */
2842 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2843 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2844 { } /* end */
2845};
2846
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002847static struct hda_verb cxt5066_init_verbs_vostro[] = {
2848 /* Port A: headphones */
2849 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2850 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2851
2852 /* Port B: external microphone */
2853 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2854
2855 /* Port C: unused */
2856 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2857
2858 /* Port D: unused */
2859 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2860
2861 /* Port E: unused, but has primary EAPD */
2862 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2864
2865 /* Port F: unused */
2866 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867
2868 /* Port G: internal speakers */
2869 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2870 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2871
2872 /* DAC1 */
2873 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2874
2875 /* DAC2: unused */
2876 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2877
2878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2880 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2881 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2882 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2883 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2884 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2885 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2887 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2888 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2889 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2890
2891 /* Digital microphone port */
2892 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2893
2894 /* Audio input selectors */
2895 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2896 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2897
2898 /* Disable SPDIF */
2899 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2900 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2901
2902 /* enable unsolicited events for Port A and B */
2903 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2904 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2905 { } /* end */
2906};
2907
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002908static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2909 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2910 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2911 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2912 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2913
2914 /* Speakers */
2915 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2916 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2917
2918 /* HP, Amp */
2919 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2920 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2921
2922 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2923 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2924
2925 /* DAC1 */
2926 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2927
2928 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2929 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2930 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2931 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2932 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2933 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2934 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2935
2936 /* Audio input selector */
2937 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2938 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2939
2940 /* SPDIF route: PCM */
2941 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2942 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2943
2944 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2945 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2946
2947 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01002948 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002949
2950 /* EAPD */
2951 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2952
2953 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2954 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2955 { } /* end */
2956};
2957
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002958static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2959 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2960 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2961
2962 /* Port G: internal speakers */
2963 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2964 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2965
2966 /* Port A: HP, Amp */
2967 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2968 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2969
2970 /* Port B: Mic Dock */
2971 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2972
2973 /* Port C: Mic */
2974 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2975
2976 /* Port D: HP Dock, Amp */
2977 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2978 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2979
2980 /* DAC1 */
2981 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2982
2983 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2984 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2985 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2986 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2987 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2988 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2989 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2990
2991 /* Audio input selector */
2992 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2993 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2994
2995 /* SPDIF route: PCM */
2996 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2997 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2998
2999 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3000 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3001
3002 /* internal microphone */
David Henningsson28c4edb2010-12-20 14:24:29 +01003003 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003004
3005 /* EAPD */
3006 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3007
3008 /* enable unsolicited events for Port A, B, C and D */
3009 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3010 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3011 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3012 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3013 { } /* end */
3014};
3015
Daniel Drake0fb67e92009-07-16 14:46:57 +01003016static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3017 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3018 { } /* end */
3019};
3020
David Henningsson048e78a2010-09-02 08:35:47 +02003021
3022static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3023 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3024 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3025 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3026 { } /* end */
3027};
3028
Daniel Drake0fb67e92009-07-16 14:46:57 +01003029/* initialize jack-sensing, too */
3030static int cxt5066_init(struct hda_codec *codec)
3031{
3032 snd_printdd("CXT5066: init\n");
3033 conexant_init(codec);
3034 if (codec->patch_ops.unsol_event) {
3035 cxt5066_hp_automute(codec);
David Henningsson02b6b5b2011-01-21 13:27:39 +01003036 cxt5066_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003037 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003038 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003039 return 0;
3040}
3041
Daniel Drake75f89912010-01-07 13:46:25 +01003042static int cxt5066_olpc_init(struct hda_codec *codec)
3043{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003044 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003045 snd_printdd("CXT5066: init\n");
3046 conexant_init(codec);
3047 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003048 if (!spec->dc_enable) {
3049 cxt5066_set_mic_boost(codec);
3050 cxt5066_olpc_automic(codec);
3051 } else {
3052 cxt5066_enable_dc(codec);
3053 }
Daniel Drake75f89912010-01-07 13:46:25 +01003054 return 0;
3055}
3056
Daniel Drake0fb67e92009-07-16 14:46:57 +01003057enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003058 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003059 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3060 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
David Henningsson1feba3b2010-09-17 10:52:50 +02003061 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003062 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003063 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningssona1d69062011-01-21 13:33:28 +01003064 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
David Henningsson048e78a2010-09-02 08:35:47 +02003065 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003066 CXT5066_MODELS
3067};
3068
Takashi Iwaiea734962011-01-17 11:29:34 +01003069static const char * const cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003070 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003071 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3072 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
David Henningsson1feba3b2010-09-17 10:52:50 +02003073 [CXT5066_DELL_VOSTRO] = "dell-vostro",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003074 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003075 [CXT5066_THINKPAD] = "thinkpad",
David Henningssona1d69062011-01-21 13:33:28 +01003076 [CXT5066_ASUS] = "asus",
David Henningsson048e78a2010-09-02 08:35:47 +02003077 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003078};
3079
3080static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
Takashi Iwai00cd0bb2010-10-21 09:57:40 +02003081 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
David Henningsson1feba3b2010-09-17 10:52:50 +02003082 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
David Henningsson8a96b1e2010-12-09 07:17:27 +01003083 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
Daniel T Chenca6cd852011-01-08 18:25:27 -05003084 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
David Henningsson1feba3b2010-09-17 10:52:50 +02003085 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003086 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003087 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Daniel T Chen673f7a82010-11-21 14:01:14 -05003088 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_HP_LAPTOP),
David Henningssona1d69062011-01-21 13:33:28 +01003089 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
Anisse Astier2ca9cac2010-09-10 15:47:55 +02003090 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003091 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003092 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
David Henningsson5637edb2010-09-17 10:58:03 +02003093 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3094 CXT5066_LAPTOP),
3095 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwai4d155642010-09-07 11:58:30 +02003096 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
Manoj Iyeref61d4e2010-12-03 18:43:55 -06003097 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003098 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
David Henningssona1d69062011-01-21 13:33:28 +01003099 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
David Henningsson22f21d52011-01-07 07:53:39 +01003100 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003101 {}
3102};
3103
3104static int patch_cxt5066(struct hda_codec *codec)
3105{
3106 struct conexant_spec *spec;
3107 int board_config;
3108
3109 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3110 if (!spec)
3111 return -ENOMEM;
3112 codec->spec = spec;
3113
3114 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003115 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003116
3117 spec->dell_automute = 0;
3118 spec->multiout.max_channels = 2;
3119 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3120 spec->multiout.dac_nids = cxt5066_dac_nids;
3121 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
3122 spec->num_adc_nids = 1;
3123 spec->adc_nids = cxt5066_adc_nids;
3124 spec->capsrc_nids = cxt5066_capsrc_nids;
3125 spec->input_mux = &cxt5066_capture_source;
3126
3127 spec->port_d_mode = PIN_HP;
3128
3129 spec->num_init_verbs = 1;
3130 spec->init_verbs[0] = cxt5066_init_verbs;
3131 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3132 spec->channel_mode = cxt5066_modes;
3133 spec->cur_adc = 0;
3134 spec->cur_adc_idx = 0;
3135
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003136 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3137
Daniel Drake0fb67e92009-07-16 14:46:57 +01003138 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3139 cxt5066_models, cxt5066_cfg_tbl);
3140 switch (board_config) {
3141 default:
3142 case CXT5066_LAPTOP:
3143 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3144 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3145 break;
3146 case CXT5066_DELL_LAPTOP:
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3148 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3149
3150 spec->port_d_mode = PIN_OUT;
3151 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3152 spec->num_init_verbs++;
3153 spec->dell_automute = 1;
3154 break;
David Henningssona1d69062011-01-21 13:33:28 +01003155 case CXT5066_ASUS:
David Henningsson048e78a2010-09-02 08:35:47 +02003156 case CXT5066_HP_LAPTOP:
3157 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003158 codec->patch_ops.unsol_event = cxt5066_unsol_event;
David Henningsson048e78a2010-09-02 08:35:47 +02003159 spec->init_verbs[spec->num_init_verbs] =
3160 cxt5066_init_verbs_hp_laptop;
3161 spec->num_init_verbs++;
David Henningssona1d69062011-01-21 13:33:28 +01003162 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3163 spec->asus = board_config == CXT5066_ASUS;
David Henningsson048e78a2010-09-02 08:35:47 +02003164 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3165 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3166 /* no S/PDIF out */
3167 spec->multiout.dig_out_nid = 0;
3168 /* input source automatically selected */
3169 spec->input_mux = NULL;
3170 spec->port_d_mode = 0;
3171 spec->mic_boost = 3; /* default 30dB gain */
3172 break;
3173
Daniel Drake0fb67e92009-07-16 14:46:57 +01003174 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003175 codec->patch_ops.init = cxt5066_olpc_init;
3176 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003177 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3178 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003179 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003180 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3181 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003182 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003183
3184 /* no S/PDIF out */
3185 spec->multiout.dig_out_nid = 0;
3186
3187 /* input source automatically selected */
3188 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003189
3190 /* our capture hooks which allow us to turn on the microphone LED
3191 * at the right time */
3192 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3193 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003194 break;
David Henningsson1feba3b2010-09-17 10:52:50 +02003195 case CXT5066_DELL_VOSTRO:
Daniel Drake75f89912010-01-07 13:46:25 +01003196 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003197 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003198 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3199 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3200 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003201 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003202 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003203 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003204 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003205
3206 /* no S/PDIF out */
3207 spec->multiout.dig_out_nid = 0;
3208
3209 /* input source automatically selected */
3210 spec->input_mux = NULL;
3211 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003212 case CXT5066_IDEAPAD:
3213 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003214 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003215 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3216 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3217 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3218 spec->port_d_mode = 0;
3219 spec->ideapad = 1;
3220 spec->mic_boost = 2; /* default 20dB gain */
3221
3222 /* no S/PDIF out */
3223 spec->multiout.dig_out_nid = 0;
3224
3225 /* input source automatically selected */
3226 spec->input_mux = NULL;
3227 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003228 case CXT5066_THINKPAD:
3229 codec->patch_ops.init = cxt5066_init;
David Henningsson02b6b5b2011-01-21 13:27:39 +01003230 codec->patch_ops.unsol_event = cxt5066_unsol_event;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003231 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3232 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3233 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3234 spec->thinkpad = 1;
3235 spec->port_d_mode = PIN_OUT;
3236 spec->mic_boost = 2; /* default 20dB gain */
3237
3238 /* no S/PDIF out */
3239 spec->multiout.dig_out_nid = 0;
3240
3241 /* input source automatically selected */
3242 spec->input_mux = NULL;
3243 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003244 }
3245
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003246 if (spec->beep_amp)
3247 snd_hda_attach_beep_device(codec, spec->beep_amp);
3248
Daniel Drake0fb67e92009-07-16 14:46:57 +01003249 return 0;
3250}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003251
3252/*
Takashi Iwaif2e57312010-09-15 10:07:08 +02003253 * Automatic parser for CX20641 & co
3254 */
3255
3256static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3257
3258/* get the connection index of @nid in the widget @mux */
3259static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3260 hda_nid_t nid)
3261{
3262 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3263 int i, nums;
3264
3265 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3266 for (i = 0; i < nums; i++)
3267 if (conn[i] == nid)
3268 return i;
3269 return -1;
3270}
3271
3272/* get an unassigned DAC from the given list.
3273 * Return the nid if found and reduce the DAC list, or return zero if
3274 * not found
3275 */
3276static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3277 hda_nid_t *dacs, int *num_dacs)
3278{
3279 int i, nums = *num_dacs;
3280 hda_nid_t ret = 0;
3281
3282 for (i = 0; i < nums; i++) {
3283 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3284 ret = dacs[i];
3285 break;
3286 }
3287 }
3288 if (!ret)
3289 return 0;
3290 if (--nums > 0)
3291 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3292 *num_dacs = nums;
3293 return ret;
3294}
3295
3296#define MAX_AUTO_DACS 5
3297
3298/* fill analog DAC list from the widget tree */
3299static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3300{
3301 hda_nid_t nid, end_nid;
3302 int nums = 0;
3303
3304 end_nid = codec->start_nid + codec->num_nodes;
3305 for (nid = codec->start_nid; nid < end_nid; nid++) {
3306 unsigned int wcaps = get_wcaps(codec, nid);
3307 unsigned int type = get_wcaps_type(wcaps);
3308 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3309 dacs[nums++] = nid;
3310 if (nums >= MAX_AUTO_DACS)
3311 break;
3312 }
3313 }
3314 return nums;
3315}
3316
3317/* fill pin_dac_pair list from the pin and dac list */
3318static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3319 int num_pins, hda_nid_t *dacs, int *rest,
3320 struct pin_dac_pair *filled, int type)
3321{
3322 int i, nums;
3323
3324 nums = 0;
3325 for (i = 0; i < num_pins; i++) {
3326 filled[nums].pin = pins[i];
3327 filled[nums].type = type;
3328 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3329 nums++;
3330 }
3331 return nums;
3332}
3333
3334/* parse analog output paths */
3335static void cx_auto_parse_output(struct hda_codec *codec)
3336{
3337 struct conexant_spec *spec = codec->spec;
3338 struct auto_pin_cfg *cfg = &spec->autocfg;
3339 hda_nid_t dacs[MAX_AUTO_DACS];
3340 int i, j, nums, rest;
3341
3342 rest = fill_cx_auto_dacs(codec, dacs);
3343 /* parse all analog output pins */
3344 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3345 dacs, &rest, spec->dac_info,
3346 AUTO_PIN_LINE_OUT);
3347 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3348 dacs, &rest, spec->dac_info + nums,
3349 AUTO_PIN_HP_OUT);
3350 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3351 dacs, &rest, spec->dac_info + nums,
3352 AUTO_PIN_SPEAKER_OUT);
3353 spec->dac_info_filled = nums;
3354 /* fill multiout struct */
3355 for (i = 0; i < nums; i++) {
3356 hda_nid_t dac = spec->dac_info[i].dac;
3357 if (!dac)
3358 continue;
3359 switch (spec->dac_info[i].type) {
3360 case AUTO_PIN_LINE_OUT:
3361 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3362 spec->multiout.num_dacs++;
3363 break;
3364 case AUTO_PIN_HP_OUT:
3365 case AUTO_PIN_SPEAKER_OUT:
3366 if (!spec->multiout.hp_nid) {
3367 spec->multiout.hp_nid = dac;
3368 break;
3369 }
3370 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3371 if (!spec->multiout.extra_out_nid[j]) {
3372 spec->multiout.extra_out_nid[j] = dac;
3373 break;
3374 }
3375 break;
3376 }
3377 }
3378 spec->multiout.dac_nids = spec->private_dac_nids;
3379 spec->multiout.max_channels = nums * 2;
3380
3381 if (cfg->hp_outs > 0)
3382 spec->auto_mute = 1;
3383 spec->vmaster_nid = spec->private_dac_nids[0];
3384}
3385
3386/* auto-mute/unmute speaker and line outs according to headphone jack */
3387static void cx_auto_hp_automute(struct hda_codec *codec)
3388{
3389 struct conexant_spec *spec = codec->spec;
3390 struct auto_pin_cfg *cfg = &spec->autocfg;
3391 int i, present;
3392
3393 if (!spec->auto_mute)
3394 return;
3395 present = 0;
3396 for (i = 0; i < cfg->hp_outs; i++) {
3397 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3398 present = 1;
3399 break;
3400 }
3401 }
3402 for (i = 0; i < cfg->line_outs; i++) {
3403 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3404 AC_VERB_SET_PIN_WIDGET_CONTROL,
3405 present ? 0 : PIN_OUT);
3406 }
Takashi Iwaifbb5bb52010-12-13 12:48:35 +01003407 for (i = 0; !present && i < cfg->line_outs; i++)
3408 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3409 present = 1;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003410 for (i = 0; i < cfg->speaker_outs; i++) {
3411 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3412 AC_VERB_SET_PIN_WIDGET_CONTROL,
3413 present ? 0 : PIN_OUT);
3414 }
3415}
3416
3417/* automatic switch internal and external mic */
3418static void cx_auto_automic(struct hda_codec *codec)
3419{
3420 struct conexant_spec *spec = codec->spec;
3421 struct auto_pin_cfg *cfg = &spec->autocfg;
3422 struct hda_input_mux *imux = &spec->private_imux;
3423 int ext_idx = spec->auto_mic_ext;
3424
3425 if (!spec->auto_mic)
3426 return;
3427 if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3428 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3429 AC_VERB_SET_CONNECT_SEL,
3430 imux->items[ext_idx].index);
3431 } else {
3432 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3433 AC_VERB_SET_CONNECT_SEL,
3434 imux->items[!ext_idx].index);
3435 }
3436}
3437
3438static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3439{
3440 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3441 switch (res >> 26) {
3442 case CONEXANT_HP_EVENT:
3443 cx_auto_hp_automute(codec);
3444 conexant_report_jack(codec, nid);
3445 break;
3446 case CONEXANT_MIC_EVENT:
3447 cx_auto_automic(codec);
3448 conexant_report_jack(codec, nid);
3449 break;
3450 }
3451}
3452
Takashi Iwaif2e57312010-09-15 10:07:08 +02003453/* return true if it's an internal-mic pin */
3454static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3455{
3456 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3457 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003458 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
Takashi Iwaif2e57312010-09-15 10:07:08 +02003459}
3460
3461/* return true if it's an external-mic pin */
3462static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3463{
3464 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3465 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
Takashi Iwaif68b3b22010-09-17 14:45:14 +02003466 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3467 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
Takashi Iwaif2e57312010-09-15 10:07:08 +02003468}
3469
3470/* check whether the pin config is suitable for auto-mic switching;
3471 * auto-mic is enabled only when one int-mic and one-ext mic exist
3472 */
3473static void cx_auto_check_auto_mic(struct hda_codec *codec)
3474{
3475 struct conexant_spec *spec = codec->spec;
3476 struct auto_pin_cfg *cfg = &spec->autocfg;
3477
3478 if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3479 is_int_mic(codec, cfg->inputs[1].pin)) {
3480 spec->auto_mic = 1;
3481 spec->auto_mic_ext = 1;
3482 return;
3483 }
3484 if (is_int_mic(codec, cfg->inputs[1].pin) &&
3485 is_ext_mic(codec, cfg->inputs[0].pin)) {
3486 spec->auto_mic = 1;
3487 spec->auto_mic_ext = 0;
3488 return;
3489 }
3490}
3491
3492static void cx_auto_parse_input(struct hda_codec *codec)
3493{
3494 struct conexant_spec *spec = codec->spec;
3495 struct auto_pin_cfg *cfg = &spec->autocfg;
3496 struct hda_input_mux *imux;
3497 int i;
3498
3499 imux = &spec->private_imux;
3500 for (i = 0; i < cfg->num_inputs; i++) {
3501 int idx = get_connection_index(codec, spec->adc_nids[0],
3502 cfg->inputs[i].pin);
3503 if (idx >= 0) {
3504 const char *label;
3505 label = hda_get_autocfg_input_label(codec, cfg, i);
3506 snd_hda_add_imux_item(imux, label, idx, NULL);
3507 }
3508 }
3509 if (imux->num_items == 2 && cfg->num_inputs == 2)
3510 cx_auto_check_auto_mic(codec);
3511 if (imux->num_items > 1 && !spec->auto_mic)
3512 spec->input_mux = imux;
3513}
3514
3515/* get digital-input audio widget corresponding to the given pin */
3516static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3517{
3518 hda_nid_t nid, end_nid;
3519
3520 end_nid = codec->start_nid + codec->num_nodes;
3521 for (nid = codec->start_nid; nid < end_nid; nid++) {
3522 unsigned int wcaps = get_wcaps(codec, nid);
3523 unsigned int type = get_wcaps_type(wcaps);
3524 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3525 if (get_connection_index(codec, nid, pin) >= 0)
3526 return nid;
3527 }
3528 }
3529 return 0;
3530}
3531
3532static void cx_auto_parse_digital(struct hda_codec *codec)
3533{
3534 struct conexant_spec *spec = codec->spec;
3535 struct auto_pin_cfg *cfg = &spec->autocfg;
3536 hda_nid_t nid;
3537
3538 if (cfg->dig_outs &&
3539 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3540 spec->multiout.dig_out_nid = nid;
3541 if (cfg->dig_in_pin)
3542 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3543}
3544
3545#ifdef CONFIG_SND_HDA_INPUT_BEEP
3546static void cx_auto_parse_beep(struct hda_codec *codec)
3547{
3548 struct conexant_spec *spec = codec->spec;
3549 hda_nid_t nid, end_nid;
3550
3551 end_nid = codec->start_nid + codec->num_nodes;
3552 for (nid = codec->start_nid; nid < end_nid; nid++)
3553 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3554 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3555 break;
3556 }
3557}
3558#else
3559#define cx_auto_parse_beep(codec)
3560#endif
3561
3562static int cx_auto_parse_auto_config(struct hda_codec *codec)
3563{
3564 struct conexant_spec *spec = codec->spec;
3565 int err;
3566
3567 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3568 if (err < 0)
3569 return err;
3570
3571 cx_auto_parse_output(codec);
3572 cx_auto_parse_input(codec);
3573 cx_auto_parse_digital(codec);
3574 cx_auto_parse_beep(codec);
3575 return 0;
3576}
3577
3578static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3579 hda_nid_t *pins)
3580{
3581 int i;
3582 for (i = 0; i < num_pins; i++) {
3583 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3584 snd_hda_codec_write(codec, pins[i], 0,
3585 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3586 }
3587}
3588
3589static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3590 hda_nid_t src)
3591{
3592 int idx = get_connection_index(codec, pin, src);
3593 if (idx >= 0)
3594 snd_hda_codec_write(codec, pin, 0,
3595 AC_VERB_SET_CONNECT_SEL, idx);
3596}
3597
3598static void cx_auto_init_output(struct hda_codec *codec)
3599{
3600 struct conexant_spec *spec = codec->spec;
3601 struct auto_pin_cfg *cfg = &spec->autocfg;
3602 hda_nid_t nid;
3603 int i;
3604
3605 for (i = 0; i < spec->multiout.num_dacs; i++)
3606 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3607 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3608
3609 for (i = 0; i < cfg->hp_outs; i++)
3610 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3611 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3612 if (spec->auto_mute) {
3613 for (i = 0; i < cfg->hp_outs; i++) {
3614 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3615 AC_VERB_SET_UNSOLICITED_ENABLE,
3616 AC_USRSP_EN | CONEXANT_HP_EVENT);
3617 }
3618 cx_auto_hp_automute(codec);
3619 } else {
3620 for (i = 0; i < cfg->line_outs; i++)
3621 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3622 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3623 for (i = 0; i < cfg->speaker_outs; i++)
3624 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3625 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3626 }
3627
3628 for (i = 0; i < spec->dac_info_filled; i++) {
3629 nid = spec->dac_info[i].dac;
3630 if (!nid)
3631 nid = spec->multiout.dac_nids[0];
3632 select_connection(codec, spec->dac_info[i].pin, nid);
3633 }
3634
3635 /* turn on EAPD */
3636 cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3637 cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3638 cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3639}
3640
3641static void cx_auto_init_input(struct hda_codec *codec)
3642{
3643 struct conexant_spec *spec = codec->spec;
3644 struct auto_pin_cfg *cfg = &spec->autocfg;
3645 int i;
3646
3647 for (i = 0; i < spec->num_adc_nids; i++)
3648 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3649 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3650
3651 for (i = 0; i < cfg->num_inputs; i++) {
3652 unsigned int type;
3653 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3654 type = PIN_VREF80;
3655 else
3656 type = PIN_IN;
3657 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3658 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3659 }
3660
3661 if (spec->auto_mic) {
3662 int ext_idx = spec->auto_mic_ext;
3663 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3664 AC_VERB_SET_UNSOLICITED_ENABLE,
3665 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3666 cx_auto_automic(codec);
3667 } else {
3668 for (i = 0; i < spec->num_adc_nids; i++) {
3669 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3670 AC_VERB_SET_CONNECT_SEL,
3671 spec->private_imux.items[0].index);
3672 }
3673 }
3674}
3675
3676static void cx_auto_init_digital(struct hda_codec *codec)
3677{
3678 struct conexant_spec *spec = codec->spec;
3679 struct auto_pin_cfg *cfg = &spec->autocfg;
3680
3681 if (spec->multiout.dig_out_nid)
3682 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3683 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3684 if (spec->dig_in_nid)
3685 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3686 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3687}
3688
3689static int cx_auto_init(struct hda_codec *codec)
3690{
3691 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3692 cx_auto_init_output(codec);
3693 cx_auto_init_input(codec);
3694 cx_auto_init_digital(codec);
3695 return 0;
3696}
3697
3698static int cx_auto_add_volume(struct hda_codec *codec, const char *basename,
3699 const char *dir, int cidx,
3700 hda_nid_t nid, int hda_dir)
3701{
3702 static char name[32];
3703 static struct snd_kcontrol_new knew[] = {
3704 HDA_CODEC_VOLUME(name, 0, 0, 0),
3705 HDA_CODEC_MUTE(name, 0, 0, 0),
3706 };
3707 static char *sfx[2] = { "Volume", "Switch" };
3708 int i, err;
3709
3710 for (i = 0; i < 2; i++) {
3711 struct snd_kcontrol *kctl;
3712 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir);
3713 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3714 knew[i].index = cidx;
3715 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3716 kctl = snd_ctl_new1(&knew[i], codec);
3717 if (!kctl)
3718 return -ENOMEM;
3719 err = snd_hda_ctl_add(codec, nid, kctl);
3720 if (err < 0)
3721 return err;
3722 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3723 break;
3724 }
3725 return 0;
3726}
3727
3728#define cx_auto_add_pb_volume(codec, nid, str, idx) \
3729 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3730
3731static int cx_auto_build_output_controls(struct hda_codec *codec)
3732{
3733 struct conexant_spec *spec = codec->spec;
3734 int i, err;
3735 int num_line = 0, num_hp = 0, num_spk = 0;
Takashi Iwaiea734962011-01-17 11:29:34 +01003736 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
Takashi Iwaif2e57312010-09-15 10:07:08 +02003737
3738 if (spec->dac_info_filled == 1)
3739 return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3740 "Master", 0);
3741 for (i = 0; i < spec->dac_info_filled; i++) {
3742 const char *label;
3743 int idx, type;
3744 if (!spec->dac_info[i].dac)
3745 continue;
3746 type = spec->dac_info[i].type;
3747 if (type == AUTO_PIN_LINE_OUT)
3748 type = spec->autocfg.line_out_type;
3749 switch (type) {
3750 case AUTO_PIN_LINE_OUT:
3751 default:
3752 label = texts[num_line++];
3753 idx = 0;
3754 break;
3755 case AUTO_PIN_HP_OUT:
3756 label = "Headphone";
3757 idx = num_hp++;
3758 break;
3759 case AUTO_PIN_SPEAKER_OUT:
3760 label = "Speaker";
3761 idx = num_spk++;
3762 break;
3763 }
3764 err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3765 label, idx);
3766 if (err < 0)
3767 return err;
3768 }
3769 return 0;
3770}
3771
3772static int cx_auto_build_input_controls(struct hda_codec *codec)
3773{
3774 struct conexant_spec *spec = codec->spec;
3775 struct auto_pin_cfg *cfg = &spec->autocfg;
3776 static const char *prev_label;
3777 int i, err, cidx;
3778
3779 err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0],
3780 HDA_INPUT);
3781 if (err < 0)
3782 return err;
3783 prev_label = NULL;
3784 cidx = 0;
3785 for (i = 0; i < cfg->num_inputs; i++) {
3786 hda_nid_t nid = cfg->inputs[i].pin;
3787 const char *label;
3788 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3789 continue;
3790 label = hda_get_autocfg_input_label(codec, cfg, i);
3791 if (label == prev_label)
3792 cidx++;
3793 else
3794 cidx = 0;
3795 prev_label = label;
3796 err = cx_auto_add_volume(codec, label, " Capture", cidx,
3797 nid, HDA_INPUT);
3798 if (err < 0)
3799 return err;
3800 }
3801 return 0;
3802}
3803
3804static int cx_auto_build_controls(struct hda_codec *codec)
3805{
3806 int err;
3807
3808 err = cx_auto_build_output_controls(codec);
3809 if (err < 0)
3810 return err;
3811 err = cx_auto_build_input_controls(codec);
3812 if (err < 0)
3813 return err;
3814 return conexant_build_controls(codec);
3815}
3816
3817static struct hda_codec_ops cx_auto_patch_ops = {
3818 .build_controls = cx_auto_build_controls,
3819 .build_pcms = conexant_build_pcms,
3820 .init = cx_auto_init,
3821 .free = conexant_free,
3822 .unsol_event = cx_auto_unsol_event,
3823#ifdef CONFIG_SND_HDA_POWER_SAVE
3824 .suspend = conexant_suspend,
3825#endif
3826 .reboot_notify = snd_hda_shutup_pins,
3827};
3828
3829static int patch_conexant_auto(struct hda_codec *codec)
3830{
3831 struct conexant_spec *spec;
3832 int err;
3833
3834 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3835 if (!spec)
3836 return -ENOMEM;
3837 codec->spec = spec;
3838 spec->adc_nids = cx_auto_adc_nids;
3839 spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3840 spec->capsrc_nids = spec->adc_nids;
3841 err = cx_auto_parse_auto_config(codec);
3842 if (err < 0) {
3843 kfree(codec->spec);
3844 codec->spec = NULL;
3845 return err;
3846 }
3847 codec->patch_ops = cx_auto_patch_ops;
3848 if (spec->beep_amp)
3849 snd_hda_attach_beep_device(codec, spec->beep_amp);
3850 return 0;
3851}
3852
3853/*
Takashi Iwai461e2c72008-01-25 11:35:17 +01003854 */
3855
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003856static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003857 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3858 .patch = patch_cxt5045 },
3859 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3860 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003861 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3862 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003863 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3864 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003865 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3866 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003867 { .id = 0x14f15068, .name = "CX20584",
3868 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003869 { .id = 0x14f15069, .name = "CX20585",
3870 .patch = patch_cxt5066 },
Takashi Iwaif2e57312010-09-15 10:07:08 +02003871 { .id = 0x14f15097, .name = "CX20631",
3872 .patch = patch_conexant_auto },
3873 { .id = 0x14f15098, .name = "CX20632",
3874 .patch = patch_conexant_auto },
3875 { .id = 0x14f150a1, .name = "CX20641",
3876 .patch = patch_conexant_auto },
3877 { .id = 0x14f150a2, .name = "CX20642",
3878 .patch = patch_conexant_auto },
3879 { .id = 0x14f150ab, .name = "CX20651",
3880 .patch = patch_conexant_auto },
3881 { .id = 0x14f150ac, .name = "CX20652",
3882 .patch = patch_conexant_auto },
3883 { .id = 0x14f150b8, .name = "CX20664",
3884 .patch = patch_conexant_auto },
3885 { .id = 0x14f150b9, .name = "CX20665",
3886 .patch = patch_conexant_auto },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003887 {} /* terminator */
3888};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003889
3890MODULE_ALIAS("snd-hda-codec-id:14f15045");
3891MODULE_ALIAS("snd-hda-codec-id:14f15047");
3892MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003893MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003894MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003895MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003896MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwaif2e57312010-09-15 10:07:08 +02003897MODULE_ALIAS("snd-hda-codec-id:14f15097");
3898MODULE_ALIAS("snd-hda-codec-id:14f15098");
3899MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3900MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3901MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3902MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3903MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3904MODULE_ALIAS("snd-hda-codec-id:14f150b9");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003905
3906MODULE_LICENSE("GPL");
3907MODULE_DESCRIPTION("Conexant HD-audio codec");
3908
3909static struct hda_codec_preset_list conexant_list = {
3910 .preset = snd_hda_preset_conexant,
3911 .owner = THIS_MODULE,
3912};
3913
3914static int __init patch_conexant_init(void)
3915{
3916 return snd_hda_add_codec_preset(&conexant_list);
3917}
3918
3919static void __exit patch_conexant_exit(void)
3920{
3921 snd_hda_delete_codec_preset(&conexant_list);
3922}
3923
3924module_init(patch_conexant_init)
3925module_exit(patch_conexant_exit)