blob: 4f0619908a30bd04acf72b0db91800a8ad6b007c [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
60struct conexant_spec {
61
62 struct snd_kcontrol_new *mixers[5];
63 int num_mixers;
Takashi Iwaidd5746a2009-03-10 14:30:40 +010064 hda_nid_t vmaster_nid;
Tobin Davisc9b443d2006-11-14 12:13:39 +010065
66 const struct hda_verb *init_verbs[5]; /* initialization verbs
67 * don't forget NULL
68 * termination!
69 */
70 unsigned int num_init_verbs;
71
72 /* playback */
73 struct hda_multi_out multiout; /* playback set-up
74 * max_channels, dacs must be set
75 * dig_out_nid and hp_nid are optional
76 */
77 unsigned int cur_eapd;
Tobin Davis82f30042007-02-13 12:45:44 +010078 unsigned int hp_present;
Takashi Iwaifaddaa52010-01-23 22:31:36 +010079 unsigned int auto_mic;
Tobin Davisc9b443d2006-11-14 12:13:39 +010080 unsigned int need_dac_fix;
81
82 /* capture */
83 unsigned int num_adc_nids;
84 hda_nid_t *adc_nids;
85 hda_nid_t dig_in_nid; /* digital-in NID; optional */
86
Takashi Iwai461e2c72008-01-25 11:35:17 +010087 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
91
Tobin Davisc9b443d2006-11-14 12:13:39 +010092 /* capture source */
93 const struct hda_input_mux *input_mux;
94 hda_nid_t *capsrc_nids;
95 unsigned int cur_mux[3];
96
97 /* channel model */
98 const struct hda_channel_mode *channel_mode;
99 int num_channel_mode;
100
101 /* PCM information */
102 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
103
Tobin Davisc9b443d2006-11-14 12:13:39 +0100104 unsigned int spdif_route;
105
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100106 /* jack detection */
107 struct snd_array jacks;
108
Tobin Davisc9b443d2006-11-14 12:13:39 +0100109 /* dynamic controls, init_verbs and input_mux */
110 struct auto_pin_cfg autocfg;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100111 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +0200112 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100113
Daniel Drake0fb67e92009-07-16 14:46:57 +0100114 unsigned int dell_automute;
115 unsigned int port_d_mode;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -0500116 unsigned int dell_vostro:1;
117 unsigned int ideapad:1;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +0200118 unsigned int thinkpad:1;
David Henningsson048e78a2010-09-02 08:35:47 +0200119 unsigned int hp_laptop:1;
Daniel Drake75f89912010-01-07 13:46:25 +0100120
121 unsigned int ext_mic_present;
122 unsigned int recording;
123 void (*capture_prepare)(struct hda_codec *codec);
124 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100125
126 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
127 * through the microphone jack.
128 * When the user enables this through a mixer switch, both internal and
129 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
130 * we also allow the bias to be configured through a separate mixer
131 * control. */
132 unsigned int dc_enable;
133 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
134 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200135
136 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100137};
138
139static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
140 struct hda_codec *codec,
141 struct snd_pcm_substream *substream)
142{
143 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100144 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
145 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100146}
147
148static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
149 struct hda_codec *codec,
150 unsigned int stream_tag,
151 unsigned int format,
152 struct snd_pcm_substream *substream)
153{
154 struct conexant_spec *spec = codec->spec;
155 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
156 stream_tag,
157 format, substream);
158}
159
160static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 struct snd_pcm_substream *substream)
163{
164 struct conexant_spec *spec = codec->spec;
165 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
166}
167
168/*
169 * Digital out
170 */
171static int conexant_dig_playback_pcm_open(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_dig_open(codec, &spec->multiout);
177}
178
179static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 struct snd_pcm_substream *substream)
182{
183 struct conexant_spec *spec = codec->spec;
184 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
185}
186
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200187static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 unsigned int stream_tag,
190 unsigned int format,
191 struct snd_pcm_substream *substream)
192{
193 struct conexant_spec *spec = codec->spec;
194 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
195 stream_tag,
196 format, substream);
197}
198
Tobin Davisc9b443d2006-11-14 12:13:39 +0100199/*
200 * Analog capture
201 */
202static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 unsigned int stream_tag,
205 unsigned int format,
206 struct snd_pcm_substream *substream)
207{
208 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100209 if (spec->capture_prepare)
210 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100211 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
212 stream_tag, 0, format);
213 return 0;
214}
215
216static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
217 struct hda_codec *codec,
218 struct snd_pcm_substream *substream)
219{
220 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100221 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100222 if (spec->capture_cleanup)
223 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100224 return 0;
225}
226
227
228
229static struct hda_pcm_stream conexant_pcm_analog_playback = {
230 .substreams = 1,
231 .channels_min = 2,
232 .channels_max = 2,
233 .nid = 0, /* fill later */
234 .ops = {
235 .open = conexant_playback_pcm_open,
236 .prepare = conexant_playback_pcm_prepare,
237 .cleanup = conexant_playback_pcm_cleanup
238 },
239};
240
241static struct hda_pcm_stream conexant_pcm_analog_capture = {
242 .substreams = 1,
243 .channels_min = 2,
244 .channels_max = 2,
245 .nid = 0, /* fill later */
246 .ops = {
247 .prepare = conexant_capture_pcm_prepare,
248 .cleanup = conexant_capture_pcm_cleanup
249 },
250};
251
252
253static struct hda_pcm_stream conexant_pcm_digital_playback = {
254 .substreams = 1,
255 .channels_min = 2,
256 .channels_max = 2,
257 .nid = 0, /* fill later */
258 .ops = {
259 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200260 .close = conexant_dig_playback_pcm_close,
261 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100262 },
263};
264
265static struct hda_pcm_stream conexant_pcm_digital_capture = {
266 .substreams = 1,
267 .channels_min = 2,
268 .channels_max = 2,
269 /* NID is set in alc_build_pcms */
270};
271
Takashi Iwai461e2c72008-01-25 11:35:17 +0100272static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
273 struct hda_codec *codec,
274 unsigned int stream_tag,
275 unsigned int format,
276 struct snd_pcm_substream *substream)
277{
278 struct conexant_spec *spec = codec->spec;
279 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
280 spec->cur_adc_stream_tag = stream_tag;
281 spec->cur_adc_format = format;
282 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
283 return 0;
284}
285
286static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
287 struct hda_codec *codec,
288 struct snd_pcm_substream *substream)
289{
290 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100291 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100292 spec->cur_adc = 0;
293 return 0;
294}
295
296static struct hda_pcm_stream cx5051_pcm_analog_capture = {
297 .substreams = 1,
298 .channels_min = 2,
299 .channels_max = 2,
300 .nid = 0, /* fill later */
301 .ops = {
302 .prepare = cx5051_capture_pcm_prepare,
303 .cleanup = cx5051_capture_pcm_cleanup
304 },
305};
306
Tobin Davisc9b443d2006-11-14 12:13:39 +0100307static int conexant_build_pcms(struct hda_codec *codec)
308{
309 struct conexant_spec *spec = codec->spec;
310 struct hda_pcm *info = spec->pcm_rec;
311
312 codec->num_pcms = 1;
313 codec->pcm_info = info;
314
315 info->name = "CONEXANT Analog";
316 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
318 spec->multiout.max_channels;
319 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
320 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100321 if (codec->vendor_id == 0x14f15051)
322 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
323 cx5051_pcm_analog_capture;
324 else
325 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
326 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100327 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
328 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
329
330 if (spec->multiout.dig_out_nid) {
331 info++;
332 codec->num_pcms++;
333 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100334 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100335 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
336 conexant_pcm_digital_playback;
337 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
338 spec->multiout.dig_out_nid;
339 if (spec->dig_in_nid) {
340 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
341 conexant_pcm_digital_capture;
342 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
343 spec->dig_in_nid;
344 }
345 }
346
347 return 0;
348}
349
350static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_info *uinfo)
352{
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 struct conexant_spec *spec = codec->spec;
355
356 return snd_hda_input_mux_info(spec->input_mux, uinfo);
357}
358
359static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
361{
362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363 struct conexant_spec *spec = codec->spec;
364 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
365
366 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
367 return 0;
368}
369
370static int conexant_mux_enum_put(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 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
378 spec->capsrc_nids[adc_idx],
379 &spec->cur_mux[adc_idx]);
380}
381
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200382#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200383static void conexant_free_jack_priv(struct snd_jack *jack)
384{
385 struct conexant_jack *jacks = jack->private_data;
386 jacks->nid = 0;
387 jacks->jack = NULL;
388}
389
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100390static int conexant_add_jack(struct hda_codec *codec,
391 hda_nid_t nid, int type)
392{
393 struct conexant_spec *spec;
394 struct conexant_jack *jack;
395 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200396 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100397
398 spec = codec->spec;
399 snd_array_init(&spec->jacks, sizeof(*jack), 32);
400 jack = snd_array_new(&spec->jacks);
401 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
402
403 if (!jack)
404 return -ENOMEM;
405
406 jack->nid = nid;
407 jack->type = type;
408
Takashi Iwai95c09092009-04-14 16:15:29 +0200409 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
410 if (err < 0)
411 return err;
412 jack->jack->private_data = jack;
413 jack->jack->private_free = conexant_free_jack_priv;
414 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100415}
416
417static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
418{
419 struct conexant_spec *spec = codec->spec;
420 struct conexant_jack *jacks = spec->jacks.list;
421
422 if (jacks) {
423 int i;
424 for (i = 0; i < spec->jacks.used; i++) {
425 if (jacks->nid == nid) {
426 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100427 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100428
429 present = (present) ? jacks->type : 0 ;
430
431 snd_jack_report(jacks->jack,
432 present);
433 }
434 jacks++;
435 }
436 }
437}
438
439static int conexant_init_jacks(struct hda_codec *codec)
440{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100441 struct conexant_spec *spec = codec->spec;
442 int i;
443
444 for (i = 0; i < spec->num_init_verbs; i++) {
445 const struct hda_verb *hv;
446
447 hv = spec->init_verbs[i];
448 while (hv->nid) {
449 int err = 0;
450 switch (hv->param ^ AC_USRSP_EN) {
451 case CONEXANT_HP_EVENT:
452 err = conexant_add_jack(codec, hv->nid,
453 SND_JACK_HEADPHONE);
454 conexant_report_jack(codec, hv->nid);
455 break;
456 case CXT5051_PORTC_EVENT:
457 case CONEXANT_MIC_EVENT:
458 err = conexant_add_jack(codec, hv->nid,
459 SND_JACK_MICROPHONE);
460 conexant_report_jack(codec, hv->nid);
461 break;
462 }
463 if (err < 0)
464 return err;
465 ++hv;
466 }
467 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100468 return 0;
469
470}
Takashi Iwai5801f992009-01-27 12:53:22 +0100471#else
472static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
473{
474}
475
476static inline int conexant_init_jacks(struct hda_codec *codec)
477{
478 return 0;
479}
480#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100481
Tobin Davisc9b443d2006-11-14 12:13:39 +0100482static int conexant_init(struct hda_codec *codec)
483{
484 struct conexant_spec *spec = codec->spec;
485 int i;
486
487 for (i = 0; i < spec->num_init_verbs; i++)
488 snd_hda_sequence_write(codec, spec->init_verbs[i]);
489 return 0;
490}
491
492static void conexant_free(struct hda_codec *codec)
493{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200494#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100495 struct conexant_spec *spec = codec->spec;
496 if (spec->jacks.list) {
497 struct conexant_jack *jacks = spec->jacks.list;
498 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200499 for (i = 0; i < spec->jacks.used; i++, jacks++) {
500 if (jacks->jack)
501 snd_device_free(codec->bus->card, jacks->jack);
502 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100503 snd_array_free(&spec->jacks);
504 }
505#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200506 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100507 kfree(codec->spec);
508}
509
Takashi Iwaib880c742009-03-10 14:41:05 +0100510static struct snd_kcontrol_new cxt_capture_mixers[] = {
511 {
512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
513 .name = "Capture Source",
514 .info = conexant_mux_enum_info,
515 .get = conexant_mux_enum_get,
516 .put = conexant_mux_enum_put
517 },
518 {}
519};
520
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200521#ifdef CONFIG_SND_HDA_INPUT_BEEP
522/* additional beep mixers; the actual parameters are overwritten at build */
523static struct snd_kcontrol_new cxt_beep_mixer[] = {
524 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
525 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
526 { } /* end */
527};
528#endif
529
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100530static const char *slave_vols[] = {
531 "Headphone Playback Volume",
532 "Speaker Playback Volume",
533 NULL
534};
535
536static const char *slave_sws[] = {
537 "Headphone Playback Switch",
538 "Speaker Playback Switch",
539 NULL
540};
541
Tobin Davisc9b443d2006-11-14 12:13:39 +0100542static int conexant_build_controls(struct hda_codec *codec)
543{
544 struct conexant_spec *spec = codec->spec;
545 unsigned int i;
546 int err;
547
548 for (i = 0; i < spec->num_mixers; i++) {
549 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
550 if (err < 0)
551 return err;
552 }
553 if (spec->multiout.dig_out_nid) {
554 err = snd_hda_create_spdif_out_ctls(codec,
555 spec->multiout.dig_out_nid);
556 if (err < 0)
557 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100558 err = snd_hda_create_spdif_share_sw(codec,
559 &spec->multiout);
560 if (err < 0)
561 return err;
562 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100563 }
564 if (spec->dig_in_nid) {
565 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
566 if (err < 0)
567 return err;
568 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100569
570 /* if we have no master control, let's create it */
571 if (spec->vmaster_nid &&
572 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
573 unsigned int vmaster_tlv[4];
574 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
575 HDA_OUTPUT, vmaster_tlv);
576 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
577 vmaster_tlv, slave_vols);
578 if (err < 0)
579 return err;
580 }
581 if (spec->vmaster_nid &&
582 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
583 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
584 NULL, slave_sws);
585 if (err < 0)
586 return err;
587 }
588
Takashi Iwaib880c742009-03-10 14:41:05 +0100589 if (spec->input_mux) {
590 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
591 if (err < 0)
592 return err;
593 }
594
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200595#ifdef CONFIG_SND_HDA_INPUT_BEEP
596 /* create beep controls if needed */
597 if (spec->beep_amp) {
598 struct snd_kcontrol_new *knew;
599 for (knew = cxt_beep_mixer; knew->name; knew++) {
600 struct snd_kcontrol *kctl;
601 kctl = snd_ctl_new1(knew, codec);
602 if (!kctl)
603 return -ENOMEM;
604 kctl->private_value = spec->beep_amp;
605 err = snd_hda_ctl_add(codec, 0, kctl);
606 if (err < 0)
607 return err;
608 }
609 }
610#endif
611
Tobin Davisc9b443d2006-11-14 12:13:39 +0100612 return 0;
613}
614
Takashi Iwai697c3732010-07-30 11:28:02 +0200615#ifdef CONFIG_SND_HDA_POWER_SAVE
616static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
617{
618 snd_hda_shutup_pins(codec);
619 return 0;
620}
621#endif
622
Tobin Davisc9b443d2006-11-14 12:13:39 +0100623static struct hda_codec_ops conexant_patch_ops = {
624 .build_controls = conexant_build_controls,
625 .build_pcms = conexant_build_pcms,
626 .init = conexant_init,
627 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200628#ifdef CONFIG_SND_HDA_POWER_SAVE
629 .suspend = conexant_suspend,
630#endif
631 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100632};
633
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200634#ifdef CONFIG_SND_HDA_INPUT_BEEP
635#define set_beep_amp(spec, nid, idx, dir) \
636 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
637#else
638#define set_beep_amp(spec, nid, idx, dir) /* NOP */
639#endif
640
Tobin Davisc9b443d2006-11-14 12:13:39 +0100641/*
642 * EAPD control
643 * the private value = nid | (invert << 8)
644 */
645
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200646#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100647
Tobin Davis82f30042007-02-13 12:45:44 +0100648static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 int invert = (kcontrol->private_value >> 8) & 1;
654 if (invert)
655 ucontrol->value.integer.value[0] = !spec->cur_eapd;
656 else
657 ucontrol->value.integer.value[0] = spec->cur_eapd;
658 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100659
Tobin Davisc9b443d2006-11-14 12:13:39 +0100660}
661
Tobin Davis82f30042007-02-13 12:45:44 +0100662static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100663 struct snd_ctl_elem_value *ucontrol)
664{
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct conexant_spec *spec = codec->spec;
667 int invert = (kcontrol->private_value >> 8) & 1;
668 hda_nid_t nid = kcontrol->private_value & 0xff;
669 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100670
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100671 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100672 if (invert)
673 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200674 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100675 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100676
Tobin Davisc9b443d2006-11-14 12:13:39 +0100677 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200678 snd_hda_codec_write_cache(codec, nid,
679 0, AC_VERB_SET_EAPD_BTLENABLE,
680 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100681 return 1;
682}
683
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100684/* controls for test mode */
685#ifdef CONFIG_SND_DEBUG
686
Tobin Davis82f30042007-02-13 12:45:44 +0100687#define CXT_EAPD_SWITCH(xname, nid, mask) \
688 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
689 .info = cxt_eapd_info, \
690 .get = cxt_eapd_get, \
691 .put = cxt_eapd_put, \
692 .private_value = nid | (mask<<16) }
693
694
695
Tobin Davisc9b443d2006-11-14 12:13:39 +0100696static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
697 struct snd_ctl_elem_info *uinfo)
698{
699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700 struct conexant_spec *spec = codec->spec;
701 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
702 spec->num_channel_mode);
703}
704
705static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_value *ucontrol)
707{
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 struct conexant_spec *spec = codec->spec;
710 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
711 spec->num_channel_mode,
712 spec->multiout.max_channels);
713}
714
715static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
716 struct snd_ctl_elem_value *ucontrol)
717{
718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
719 struct conexant_spec *spec = codec->spec;
720 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
721 spec->num_channel_mode,
722 &spec->multiout.max_channels);
723 if (err >= 0 && spec->need_dac_fix)
724 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
725 return err;
726}
727
728#define CXT_PIN_MODE(xname, nid, dir) \
729 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
730 .info = conexant_ch_mode_info, \
731 .get = conexant_ch_mode_get, \
732 .put = conexant_ch_mode_put, \
733 .private_value = nid | (dir<<16) }
734
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100735#endif /* CONFIG_SND_DEBUG */
736
Tobin Davisc9b443d2006-11-14 12:13:39 +0100737/* Conexant 5045 specific */
738
739static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
740static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
741static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100742#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100743
Tobin Davis5cd57522006-11-20 17:42:09 +0100744static struct hda_channel_mode cxt5045_modes[1] = {
745 { 2, NULL },
746};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100747
748static struct hda_input_mux cxt5045_capture_source = {
749 .num_items = 2,
750 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100751 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100752 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100753 }
754};
755
Jiang Zhe5218c892008-01-17 11:18:41 +0100756static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200757 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100758 .items = {
759 { "IntMic", 0x1 },
760 { "ExtMic", 0x2 },
761 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200762 { "CD", 0x4 },
763 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100764 }
765};
766
Jiang zhe2de3c232008-03-06 11:09:09 +0100767static struct hda_input_mux cxt5045_capture_source_hp530 = {
768 .num_items = 2,
769 .items = {
770 { "ExtMic", 0x1 },
771 { "IntMic", 0x2 },
772 }
773};
774
Tobin Davisc9b443d2006-11-14 12:13:39 +0100775/* turn on/off EAPD (+ mute HP) as a master switch */
776static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_value *ucontrol)
778{
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100781 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100782
Tobin Davis82f30042007-02-13 12:45:44 +0100783 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100784 return 0;
785
Tobin Davis82f30042007-02-13 12:45:44 +0100786 /* toggle internal speakers mute depending of presence of
787 * the headphone jack
788 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200789 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
790 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
791 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100792
Takashi Iwai47fd8302007-08-10 17:11:07 +0200793 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
794 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
795 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100796 return 1;
797}
798
799/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200800static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
801 .ops = &snd_hda_bind_vol,
802 .values = {
803 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
804 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
805 0
806 },
807};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100808
Tobin Davis7f296732007-03-12 11:39:01 +0100809/* toggle input of built-in and mic jack appropriately */
810static void cxt5045_hp_automic(struct hda_codec *codec)
811{
812 static struct hda_verb mic_jack_on[] = {
813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
814 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
815 {}
816 };
817 static struct hda_verb mic_jack_off[] = {
818 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
820 {}
821 };
822 unsigned int present;
823
Takashi Iwaid56757a2009-11-18 08:00:14 +0100824 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100825 if (present)
826 snd_hda_sequence_write(codec, mic_jack_on);
827 else
828 snd_hda_sequence_write(codec, mic_jack_off);
829}
830
Tobin Davisc9b443d2006-11-14 12:13:39 +0100831
832/* mute internal speaker if HP is plugged */
833static void cxt5045_hp_automute(struct hda_codec *codec)
834{
Tobin Davis82f30042007-02-13 12:45:44 +0100835 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100836 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100837
Takashi Iwaid56757a2009-11-18 08:00:14 +0100838 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100839
Takashi Iwai47fd8302007-08-10 17:11:07 +0200840 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
841 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
842 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100843}
844
845/* unsolicited event for HP jack sensing */
846static void cxt5045_hp_unsol_event(struct hda_codec *codec,
847 unsigned int res)
848{
849 res >>= 26;
850 switch (res) {
851 case CONEXANT_HP_EVENT:
852 cxt5045_hp_automute(codec);
853 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100854 case CONEXANT_MIC_EVENT:
855 cxt5045_hp_automic(codec);
856 break;
857
Tobin Davisc9b443d2006-11-14 12:13:39 +0100858 }
859}
860
861static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200862 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
863 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
864 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
865 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
866 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
867 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
868 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
869 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
870 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
871 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200872 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100873 {
874 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
875 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100876 .info = cxt_eapd_info,
877 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100878 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100879 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100880 },
881
882 {}
883};
884
Jiang Zhe5218c892008-01-17 11:18:41 +0100885static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200886 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
887 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
888 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
889 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
890
Jiang Zhe5218c892008-01-17 11:18:41 +0100891 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
892 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
893 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
894 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
895
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200896 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
897 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
898
Jiang Zhe5218c892008-01-17 11:18:41 +0100899 {}
900};
901
Jiang zhe2de3c232008-03-06 11:09:09 +0100902static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100903 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
904 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
905 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
906 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
907 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
908 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
909 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
910 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
911 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
912 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
913 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
914 {
915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
916 .name = "Master Playback Switch",
917 .info = cxt_eapd_info,
918 .get = cxt_eapd_get,
919 .put = cxt5045_hp_master_sw_put,
920 .private_value = 0x10,
921 },
922
923 {}
924};
925
Tobin Davisc9b443d2006-11-14 12:13:39 +0100926static struct hda_verb cxt5045_init_verbs[] = {
927 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200928 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100929 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200931 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
932 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
933 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
934 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
936 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
937 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
938 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
939 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100940 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100941 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100942 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100943 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
944 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100945 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100947 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100948 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100949 { } /* end */
950};
951
Jiang Zhe5218c892008-01-17 11:18:41 +0100952static struct hda_verb cxt5045_benq_init_verbs[] = {
953 /* Int Mic, Mic */
954 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
955 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
956 /* Line In,HP, Amp */
957 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
958 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
959 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
960 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
965 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
966 /* Record selector: Int mic */
967 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
968 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
969 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
970 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100971 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100972 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
973 /* EAPD */
974 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
975 { } /* end */
976};
Tobin Davis7f296732007-03-12 11:39:01 +0100977
978static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
979 /* pin sensing on HP jack */
980 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200981 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100982};
983
984static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
985 /* pin sensing on HP jack */
986 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200987 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100988};
989
Tobin Davisc9b443d2006-11-14 12:13:39 +0100990#ifdef CONFIG_SND_DEBUG
991/* Test configuration for debugging, modelled after the ALC260 test
992 * configuration.
993 */
994static struct hda_input_mux cxt5045_test_capture_source = {
995 .num_items = 5,
996 .items = {
997 { "MIXER", 0x0 },
998 { "MIC1 pin", 0x1 },
999 { "LINE1 pin", 0x2 },
1000 { "HP-OUT pin", 0x3 },
1001 { "CD pin", 0x4 },
1002 },
1003};
1004
1005static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1006
1007 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001008 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1009 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001010 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1011 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1012 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1013 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001014
1015 /* Modes for retasking pin widgets */
1016 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1017 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1018
Tobin Davis82f30042007-02-13 12:45:44 +01001019 /* EAPD Switch Control */
1020 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1021
Tobin Davisc9b443d2006-11-14 12:13:39 +01001022 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001023
Tobin Davis7f296732007-03-12 11:39:01 +01001024 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1025 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1026 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1027 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1028 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1029 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1030 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1031 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1032 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1033 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001034 {
1035 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1036 .name = "Input Source",
1037 .info = conexant_mux_enum_info,
1038 .get = conexant_mux_enum_get,
1039 .put = conexant_mux_enum_put,
1040 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001041 /* Audio input controls */
1042 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1043 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1044 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1045 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1046 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1047 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1048 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1049 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1050 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1051 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001052 { } /* end */
1053};
1054
1055static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001056 /* Set connections */
1057 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1058 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1059 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001060 /* Enable retasking pins as output, initially without power amp */
1061 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001062 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001063
1064 /* Disable digital (SPDIF) pins initially, but users can enable
1065 * them via a mixer switch. In the case of SPDIF-out, this initverb
1066 * payload also sets the generation to 0, output to be in "consumer"
1067 * PCM format, copyright asserted, no pre-emphasis and no validity
1068 * control.
1069 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001070 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1071 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001072
1073 /* Start with output sum widgets muted and their output gains at min */
1074 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1075 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1076
1077 /* Unmute retasking pin widget output buffers since the default
1078 * state appears to be output. As the pin mode is changed by the
1079 * user the pin mode control will take care of enabling the pin's
1080 * input/output buffers as needed.
1081 */
1082 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1083 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1084
1085 /* Mute capture amp left and right */
1086 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1087
1088 /* Set ADC connection select to match default mixer setting (mic1
1089 * pin)
1090 */
1091 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001092 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001093
1094 /* Mute all inputs to mixer widget (even unconnected ones) */
1095 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1096 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1097 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1098 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1099 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1100
1101 { }
1102};
1103#endif
1104
1105
1106/* initialize jack-sensing, too */
1107static int cxt5045_init(struct hda_codec *codec)
1108{
1109 conexant_init(codec);
1110 cxt5045_hp_automute(codec);
1111 return 0;
1112}
1113
1114
1115enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001116 CXT5045_LAPTOP_HPSENSE,
1117 CXT5045_LAPTOP_MICSENSE,
1118 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001119 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001120 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001121#ifdef CONFIG_SND_DEBUG
1122 CXT5045_TEST,
1123#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001124 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001125};
1126
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001127static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001128 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1129 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1130 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1131 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001132 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001133#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001134 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001135#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001136};
1137
1138static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001139 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001140 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1141 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001142 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001143 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001144 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1145 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001146 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1147 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001148 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1149 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1150 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001151 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1152 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001153 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001154 {}
1155};
1156
1157static int patch_cxt5045(struct hda_codec *codec)
1158{
1159 struct conexant_spec *spec;
1160 int board_config;
1161
1162 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1163 if (!spec)
1164 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001165 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001166 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001167
1168 spec->multiout.max_channels = 2;
1169 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1170 spec->multiout.dac_nids = cxt5045_dac_nids;
1171 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1172 spec->num_adc_nids = 1;
1173 spec->adc_nids = cxt5045_adc_nids;
1174 spec->capsrc_nids = cxt5045_capsrc_nids;
1175 spec->input_mux = &cxt5045_capture_source;
1176 spec->num_mixers = 1;
1177 spec->mixers[0] = cxt5045_mixers;
1178 spec->num_init_verbs = 1;
1179 spec->init_verbs[0] = cxt5045_init_verbs;
1180 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001181 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1182 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001183
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001184 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001185
1186 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001188 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1189 cxt5045_models,
1190 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001191 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001192 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001193 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001194 spec->input_mux = &cxt5045_capture_source;
1195 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001196 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1197 spec->mixers[0] = cxt5045_mixers;
1198 codec->patch_ops.init = cxt5045_init;
1199 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001200 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001201 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001202 spec->input_mux = &cxt5045_capture_source;
1203 spec->num_init_verbs = 2;
1204 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001205 spec->mixers[0] = cxt5045_mixers;
1206 codec->patch_ops.init = cxt5045_init;
1207 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001208 default:
1209 case CXT5045_LAPTOP_HPMICSENSE:
1210 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1211 spec->input_mux = &cxt5045_capture_source;
1212 spec->num_init_verbs = 3;
1213 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1214 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1215 spec->mixers[0] = cxt5045_mixers;
1216 codec->patch_ops.init = cxt5045_init;
1217 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001218 case CXT5045_BENQ:
1219 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1220 spec->input_mux = &cxt5045_capture_source_benq;
1221 spec->num_init_verbs = 1;
1222 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1223 spec->mixers[0] = cxt5045_mixers;
1224 spec->mixers[1] = cxt5045_benq_mixers;
1225 spec->num_mixers = 2;
1226 codec->patch_ops.init = cxt5045_init;
1227 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001228 case CXT5045_LAPTOP_HP530:
1229 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1230 spec->input_mux = &cxt5045_capture_source_hp530;
1231 spec->num_init_verbs = 2;
1232 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1233 spec->mixers[0] = cxt5045_mixers_hp530;
1234 codec->patch_ops.init = cxt5045_init;
1235 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001236#ifdef CONFIG_SND_DEBUG
1237 case CXT5045_TEST:
1238 spec->input_mux = &cxt5045_test_capture_source;
1239 spec->mixers[0] = cxt5045_test_mixer;
1240 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001241 break;
1242
Tobin Davisc9b443d2006-11-14 12:13:39 +01001243#endif
1244 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001245
Takashi Iwai031005f2008-06-26 14:49:58 +02001246 switch (codec->subsystem_id >> 16) {
1247 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001248 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001249 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001250 case 0x17aa:
1251 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1252 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1253 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001254 */
1255 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1256 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1257 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1258 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1259 (1 << AC_AMPCAP_MUTE_SHIFT));
1260 break;
1261 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001262
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001263 if (spec->beep_amp)
1264 snd_hda_attach_beep_device(codec, spec->beep_amp);
1265
Tobin Davisc9b443d2006-11-14 12:13:39 +01001266 return 0;
1267}
1268
1269
1270/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001271#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001272
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001273static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1275static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001276
Tobin Davis5cd57522006-11-20 17:42:09 +01001277static struct hda_channel_mode cxt5047_modes[1] = {
1278 { 2, NULL },
1279};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001280
Tobin Davis82f30042007-02-13 12:45:44 +01001281static struct hda_input_mux cxt5047_toshiba_capture_source = {
1282 .num_items = 2,
1283 .items = {
1284 { "ExtMic", 0x2 },
1285 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001286 }
1287};
1288
1289/* turn on/off EAPD (+ mute HP) as a master switch */
1290static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1291 struct snd_ctl_elem_value *ucontrol)
1292{
1293 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1294 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001295 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001296
Tobin Davis82f30042007-02-13 12:45:44 +01001297 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001298 return 0;
1299
Tobin Davis82f30042007-02-13 12:45:44 +01001300 /* toggle internal speakers mute depending of presence of
1301 * the headphone jack
1302 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001303 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001304 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1305 * pin widgets unlike other codecs. In this case, we need to
1306 * set index 0x01 for the volume from the mixer amp 0x19.
1307 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001308 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001309 HDA_AMP_MUTE, bits);
1310 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1311 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1312 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001313 return 1;
1314}
1315
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316/* mute internal speaker if HP is plugged */
1317static void cxt5047_hp_automute(struct hda_codec *codec)
1318{
Tobin Davis82f30042007-02-13 12:45:44 +01001319 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001320 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001321
Takashi Iwaid56757a2009-11-18 08:00:14 +01001322 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001323
Takashi Iwai47fd8302007-08-10 17:11:07 +02001324 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001325 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001326 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001327 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328}
1329
1330/* toggle input of built-in and mic jack appropriately */
1331static void cxt5047_hp_automic(struct hda_codec *codec)
1332{
1333 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001334 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1335 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001336 {}
1337 };
1338 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001339 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1340 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001341 {}
1342 };
1343 unsigned int present;
1344
Takashi Iwaid56757a2009-11-18 08:00:14 +01001345 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001346 if (present)
1347 snd_hda_sequence_write(codec, mic_jack_on);
1348 else
1349 snd_hda_sequence_write(codec, mic_jack_off);
1350}
1351
1352/* unsolicited event for HP jack sensing */
1353static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1354 unsigned int res)
1355{
Marc Boucher9f113e02008-01-22 15:18:08 +01001356 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 case CONEXANT_HP_EVENT:
1358 cxt5047_hp_automute(codec);
1359 break;
1360 case CONEXANT_MIC_EVENT:
1361 cxt5047_hp_automic(codec);
1362 break;
1363 }
1364}
1365
Takashi Iwaidf481e42009-03-10 15:35:35 +01001366static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1367 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1368 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1369 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001370 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1371 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1372 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001374 {
1375 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1376 .name = "Master Playback Switch",
1377 .info = cxt_eapd_info,
1378 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001379 .put = cxt5047_hp_master_sw_put,
1380 .private_value = 0x13,
1381 },
1382
1383 {}
1384};
1385
Takashi Iwaidf481e42009-03-10 15:35:35 +01001386static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001387 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001388 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001389 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1390 {}
1391};
1392
1393static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001394 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001395 { } /* end */
1396};
1397
1398static struct hda_verb cxt5047_init_verbs[] = {
1399 /* Line in, Mic, Built-in Mic */
1400 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1401 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1402 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001403 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001404 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001405 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1406 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001407 /* Record selector: Mic */
1408 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1409 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1410 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1411 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001412 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1413 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1414 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1415 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001416 /* SPDIF route: PCM */
1417 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001418 /* Enable unsolicited events */
1419 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1420 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001421 { } /* end */
1422};
1423
1424/* configuration for Toshiba Laptops */
1425static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001426 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001427 {}
1428};
1429
1430/* Test configuration for debugging, modelled after the ALC260 test
1431 * configuration.
1432 */
1433#ifdef CONFIG_SND_DEBUG
1434static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001435 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001436 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001437 { "LINE1 pin", 0x0 },
1438 { "MIC1 pin", 0x1 },
1439 { "MIC2 pin", 0x2 },
1440 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001441 },
1442};
1443
1444static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1445
1446 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001447 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1448 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1449 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1450 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001451 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1452 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1453 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1454 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001455 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1456 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1457 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1458 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001459
1460 /* Modes for retasking pin widgets */
1461 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1462 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1463
Tobin Davis82f30042007-02-13 12:45:44 +01001464 /* EAPD Switch Control */
1465 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1466
Tobin Davisc9b443d2006-11-14 12:13:39 +01001467 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001468 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1469 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1470 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1471 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1472 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1473 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1474 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1475 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001476
Tobin Davis82f30042007-02-13 12:45:44 +01001477 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1478 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1479 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1480 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1481 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1482 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1483 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1484 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001485 {
1486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1487 .name = "Input Source",
1488 .info = conexant_mux_enum_info,
1489 .get = conexant_mux_enum_get,
1490 .put = conexant_mux_enum_put,
1491 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001492 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001493
Tobin Davisc9b443d2006-11-14 12:13:39 +01001494 { } /* end */
1495};
1496
1497static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001498 /* Enable retasking pins as output, initially without power amp */
1499 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1500 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1502
1503 /* Disable digital (SPDIF) pins initially, but users can enable
1504 * them via a mixer switch. In the case of SPDIF-out, this initverb
1505 * payload also sets the generation to 0, output to be in "consumer"
1506 * PCM format, copyright asserted, no pre-emphasis and no validity
1507 * control.
1508 */
1509 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1510
1511 /* Ensure mic1, mic2, line1 pin widgets take input from the
1512 * OUT1 sum bus when acting as an output.
1513 */
1514 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1515 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1516
1517 /* Start with output sum widgets muted and their output gains at min */
1518 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1520
1521 /* Unmute retasking pin widget output buffers since the default
1522 * state appears to be output. As the pin mode is changed by the
1523 * user the pin mode control will take care of enabling the pin's
1524 * input/output buffers as needed.
1525 */
1526 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1527 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1528 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1529
1530 /* Mute capture amp left and right */
1531 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1532
1533 /* Set ADC connection select to match default mixer setting (mic1
1534 * pin)
1535 */
1536 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1537
1538 /* Mute all inputs to mixer widget (even unconnected ones) */
1539 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1540 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1541 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1543 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1544 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1545 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1546 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1547
1548 { }
1549};
1550#endif
1551
1552
1553/* initialize jack-sensing, too */
1554static int cxt5047_hp_init(struct hda_codec *codec)
1555{
1556 conexant_init(codec);
1557 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001558 return 0;
1559}
1560
1561
1562enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001563 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1564 CXT5047_LAPTOP_HP, /* Some HP laptops */
1565 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001566#ifdef CONFIG_SND_DEBUG
1567 CXT5047_TEST,
1568#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001569 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001570};
1571
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001572static const char *cxt5047_models[CXT5047_MODELS] = {
1573 [CXT5047_LAPTOP] = "laptop",
1574 [CXT5047_LAPTOP_HP] = "laptop-hp",
1575 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001577 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001578#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001579};
1580
1581static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001582 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001583 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1584 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001585 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001586 {}
1587};
1588
1589static int patch_cxt5047(struct hda_codec *codec)
1590{
1591 struct conexant_spec *spec;
1592 int board_config;
1593
1594 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1595 if (!spec)
1596 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001597 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001598 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001599
1600 spec->multiout.max_channels = 2;
1601 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1602 spec->multiout.dac_nids = cxt5047_dac_nids;
1603 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1604 spec->num_adc_nids = 1;
1605 spec->adc_nids = cxt5047_adc_nids;
1606 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001608 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001609 spec->num_init_verbs = 1;
1610 spec->init_verbs[0] = cxt5047_init_verbs;
1611 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001612 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1613 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001614
1615 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001616
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001617 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1618 cxt5047_models,
1619 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001620 switch (board_config) {
1621 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001622 spec->num_mixers = 2;
1623 spec->mixers[1] = cxt5047_hp_spk_mixers;
1624 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001625 break;
1626 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001627 spec->num_mixers = 2;
1628 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001629 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001630 codec->patch_ops.init = cxt5047_hp_init;
1631 break;
1632 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001633 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001634 spec->num_mixers = 2;
1635 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001636 spec->num_init_verbs = 2;
1637 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001639 break;
1640#ifdef CONFIG_SND_DEBUG
1641 case CXT5047_TEST:
1642 spec->input_mux = &cxt5047_test_capture_source;
1643 spec->mixers[0] = cxt5047_test_mixer;
1644 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001645 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001646#endif
1647 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001648 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001649
1650 switch (codec->subsystem_id >> 16) {
1651 case 0x103c:
1652 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1653 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1654 * with 0 dB offset 0x17)
1655 */
1656 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1657 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1658 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1659 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1660 (1 << AC_AMPCAP_MUTE_SHIFT));
1661 break;
1662 }
1663
Tobin Davisc9b443d2006-11-14 12:13:39 +01001664 return 0;
1665}
1666
Takashi Iwai461e2c72008-01-25 11:35:17 +01001667/* Conexant 5051 specific */
1668static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1669static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001670
1671static struct hda_channel_mode cxt5051_modes[1] = {
1672 { 2, NULL },
1673};
1674
1675static void cxt5051_update_speaker(struct hda_codec *codec)
1676{
1677 struct conexant_spec *spec = codec->spec;
1678 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001679 /* headphone pin */
1680 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1681 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1682 pinctl);
1683 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001684 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1685 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1686 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001687 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1688 if (spec->ideapad)
1689 snd_hda_codec_write(codec, 0x1b, 0,
1690 AC_VERB_SET_PIN_WIDGET_CONTROL,
1691 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001692}
1693
1694/* turn on/off EAPD (+ mute HP) as a master switch */
1695static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1696 struct snd_ctl_elem_value *ucontrol)
1697{
1698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1699
1700 if (!cxt_eapd_put(kcontrol, ucontrol))
1701 return 0;
1702 cxt5051_update_speaker(codec);
1703 return 1;
1704}
1705
1706/* toggle input of built-in and mic jack appropriately */
1707static void cxt5051_portb_automic(struct hda_codec *codec)
1708{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001709 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001710 unsigned int present;
1711
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001712 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001713 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001714 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 snd_hda_codec_write(codec, 0x14, 0,
1716 AC_VERB_SET_CONNECT_SEL,
1717 present ? 0x01 : 0x00);
1718}
1719
1720/* switch the current ADC according to the jack state */
1721static void cxt5051_portc_automic(struct hda_codec *codec)
1722{
1723 struct conexant_spec *spec = codec->spec;
1724 unsigned int present;
1725 hda_nid_t new_adc;
1726
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001727 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001728 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001729 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001730 if (present)
1731 spec->cur_adc_idx = 1;
1732 else
1733 spec->cur_adc_idx = 0;
1734 new_adc = spec->adc_nids[spec->cur_adc_idx];
1735 if (spec->cur_adc && spec->cur_adc != new_adc) {
1736 /* stream is running, let's swap the current ADC */
Takashi Iwaif0cea792010-08-13 11:56:53 +02001737 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001738 spec->cur_adc = new_adc;
1739 snd_hda_codec_setup_stream(codec, new_adc,
1740 spec->cur_adc_stream_tag, 0,
1741 spec->cur_adc_format);
1742 }
1743}
1744
1745/* mute internal speaker if HP is plugged */
1746static void cxt5051_hp_automute(struct hda_codec *codec)
1747{
1748 struct conexant_spec *spec = codec->spec;
1749
Takashi Iwaid56757a2009-11-18 08:00:14 +01001750 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001751 cxt5051_update_speaker(codec);
1752}
1753
1754/* unsolicited event for HP jack sensing */
1755static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1756 unsigned int res)
1757{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001758 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001759 switch (res >> 26) {
1760 case CONEXANT_HP_EVENT:
1761 cxt5051_hp_automute(codec);
1762 break;
1763 case CXT5051_PORTB_EVENT:
1764 cxt5051_portb_automic(codec);
1765 break;
1766 case CXT5051_PORTC_EVENT:
1767 cxt5051_portc_automic(codec);
1768 break;
1769 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001770 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001771}
1772
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001773static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001774 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1775 {
1776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1777 .name = "Master Playback Switch",
1778 .info = cxt_eapd_info,
1779 .get = cxt_eapd_get,
1780 .put = cxt5051_hp_master_sw_put,
1781 .private_value = 0x1a,
1782 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001783 {}
1784};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001785
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001786static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1787 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1789 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1790 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1791 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1792 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001793 {}
1794};
1795
1796static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1797 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1798 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1800 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001801 {}
1802};
1803
Takashi Iwai79d7d532009-03-04 09:03:50 +01001804static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001805 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1806 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001807 {}
1808};
1809
Ken Proxcd9d95a2010-01-08 09:01:47 +01001810static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001811 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1812 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001813 {}
1814};
1815
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001816static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1817 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1818 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1819 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1820 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001821 {}
1822};
1823
Takashi Iwai461e2c72008-01-25 11:35:17 +01001824static struct hda_verb cxt5051_init_verbs[] = {
1825 /* Line in, Mic */
1826 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1827 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1828 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1829 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1830 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1831 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1832 /* SPK */
1833 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1834 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* HP, Amp */
1836 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1837 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1838 /* DAC1 */
1839 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1840 /* Record selector: Int mic */
1841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1843 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1844 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001845 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001846 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1847 /* EAPD */
1848 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1849 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001850 { } /* end */
1851};
1852
Takashi Iwai79d7d532009-03-04 09:03:50 +01001853static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1854 /* Line in, Mic */
1855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1856 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1857 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1858 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1859 /* SPK */
1860 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1861 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1862 /* HP, Amp */
1863 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1864 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1865 /* DAC1 */
1866 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1867 /* Record selector: Int mic */
1868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1869 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1870 /* SPDIF route: PCM */
1871 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1872 /* EAPD */
1873 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1874 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001875 { } /* end */
1876};
1877
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001878static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1879 /* Line in, Mic */
1880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1881 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1882 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1883 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1884 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1885 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1886 /* SPK */
1887 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1888 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1889 /* HP, Amp */
1890 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1891 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1892 /* Docking HP */
1893 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1894 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1895 /* DAC1 */
1896 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1897 /* Record selector: Int mic */
1898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1899 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1900 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1901 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001902 {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 -05001903 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1904 /* EAPD */
1905 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1906 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001907 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1908 { } /* end */
1909};
1910
Ken Proxcd9d95a2010-01-08 09:01:47 +01001911static struct hda_verb cxt5051_f700_init_verbs[] = {
1912 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001914 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1915 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1916 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1917 /* SPK */
1918 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1919 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 /* HP, Amp */
1921 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1922 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1923 /* DAC1 */
1924 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1925 /* Record selector: Int mic */
1926 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1927 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1928 /* SPDIF route: PCM */
1929 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1930 /* EAPD */
1931 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1932 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001933 { } /* end */
1934};
1935
Takashi Iwai6953e552010-01-24 11:00:27 +01001936static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1937 unsigned int event)
1938{
1939 snd_hda_codec_write(codec, nid, 0,
1940 AC_VERB_SET_UNSOLICITED_ENABLE,
1941 AC_USRSP_EN | event);
1942#ifdef CONFIG_SND_HDA_INPUT_JACK
1943 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1944 conexant_report_jack(codec, nid);
1945#endif
1946}
1947
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001948static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1949 /* Subwoofer */
1950 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1951 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1952 { } /* end */
1953};
1954
Takashi Iwai461e2c72008-01-25 11:35:17 +01001955/* initialize jack-sensing, too */
1956static int cxt5051_init(struct hda_codec *codec)
1957{
Takashi Iwai6953e552010-01-24 11:00:27 +01001958 struct conexant_spec *spec = codec->spec;
1959
Takashi Iwai461e2c72008-01-25 11:35:17 +01001960 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001961 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001962
1963 if (spec->auto_mic & AUTO_MIC_PORTB)
1964 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1965 if (spec->auto_mic & AUTO_MIC_PORTC)
1966 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1967
Takashi Iwai461e2c72008-01-25 11:35:17 +01001968 if (codec->patch_ops.unsol_event) {
1969 cxt5051_hp_automute(codec);
1970 cxt5051_portb_automic(codec);
1971 cxt5051_portc_automic(codec);
1972 }
1973 return 0;
1974}
1975
1976
1977enum {
1978 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1979 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001980 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001981 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001982 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001983 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001984 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001985 CXT5051_MODELS
1986};
1987
1988static const char *cxt5051_models[CXT5051_MODELS] = {
1989 [CXT5051_LAPTOP] = "laptop",
1990 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001991 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001992 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001993 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001994 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001995 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001996};
1997
1998static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001999 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01002000 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002001 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002002 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002003 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2004 CXT5051_LAPTOP),
2005 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002006 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002007 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002008 {}
2009};
2010
2011static int patch_cxt5051(struct hda_codec *codec)
2012{
2013 struct conexant_spec *spec;
2014 int board_config;
2015
2016 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2017 if (!spec)
2018 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002019 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002020 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002021
2022 codec->patch_ops = conexant_patch_ops;
2023 codec->patch_ops.init = cxt5051_init;
2024
2025 spec->multiout.max_channels = 2;
2026 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2027 spec->multiout.dac_nids = cxt5051_dac_nids;
2028 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2029 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2030 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002031 spec->num_mixers = 2;
2032 spec->mixers[0] = cxt5051_capture_mixers;
2033 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002034 spec->num_init_verbs = 1;
2035 spec->init_verbs[0] = cxt5051_init_verbs;
2036 spec->spdif_route = 0;
2037 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2038 spec->channel_mode = cxt5051_modes;
2039 spec->cur_adc = 0;
2040 spec->cur_adc_idx = 0;
2041
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002042 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2043
Takashi Iwai79d7d532009-03-04 09:03:50 +01002044 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2045
Takashi Iwai461e2c72008-01-25 11:35:17 +01002046 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2047 cxt5051_models,
2048 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002049 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002050 switch (board_config) {
2051 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002052 spec->mixers[0] = cxt5051_hp_mixers;
2053 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002054 case CXT5051_HP_DV6736:
2055 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2056 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002057 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002058 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002059 case CXT5051_LENOVO_X200:
2060 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Jerone Young607bc3e2010-08-03 01:46:42 -05002061 /* Thinkpad X301 does not have S/PDIF wired and no ability
2062 to use a docking station. */
2063 if (codec->subsystem_id == 0x17aa211f)
2064 spec->multiout.dig_out_nid = 0;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002065 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002066 case CXT5051_F700:
2067 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2068 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002069 spec->auto_mic = 0;
2070 break;
2071 case CXT5051_TOSHIBA:
2072 spec->mixers[0] = cxt5051_toshiba_mixers;
2073 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002074 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002075 case CXT5051_IDEAPAD:
2076 spec->init_verbs[spec->num_init_verbs++] =
2077 cxt5051_ideapad_init_verbs;
2078 spec->ideapad = 1;
2079 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002080 }
2081
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002082 if (spec->beep_amp)
2083 snd_hda_attach_beep_device(codec, spec->beep_amp);
2084
Takashi Iwai461e2c72008-01-25 11:35:17 +01002085 return 0;
2086}
2087
Daniel Drake0fb67e92009-07-16 14:46:57 +01002088/* Conexant 5066 specific */
2089
2090static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2091static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2092static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2093#define CXT5066_SPDIF_OUT 0x21
2094
Daniel Drakedbaccc02009-11-09 15:17:24 +00002095/* OLPC's microphone port is DC coupled for use with external sensors,
2096 * therefore we use a 50% mic bias in order to center the input signal with
2097 * the DC input range of the codec. */
2098#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2099
Daniel Drake0fb67e92009-07-16 14:46:57 +01002100static struct hda_channel_mode cxt5066_modes[1] = {
2101 { 2, NULL },
2102};
2103
2104static void cxt5066_update_speaker(struct hda_codec *codec)
2105{
2106 struct conexant_spec *spec = codec->spec;
2107 unsigned int pinctl;
2108
2109 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2110 spec->hp_present);
2111
2112 /* Port A (HP) */
2113 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2114 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2115 pinctl);
2116
2117 /* Port D (HP/LO) */
2118 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2119 ? spec->port_d_mode : 0;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002120 /* Mute if Port A is connected on Thinkpad */
2121 if (spec->thinkpad && (spec->hp_present & 1))
2122 pinctl = 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002123 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2124 pinctl);
2125
2126 /* CLASS_D AMP */
2127 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2128 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2129 pinctl);
2130
2131 if (spec->dell_automute) {
2132 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2133 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2134 ? PIN_OUT : 0;
2135 snd_hda_codec_write(codec, 0x1c, 0,
2136 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2137 }
2138}
2139
2140/* turn on/off EAPD (+ mute HP) as a master switch */
2141static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2142 struct snd_ctl_elem_value *ucontrol)
2143{
2144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2145
2146 if (!cxt_eapd_put(kcontrol, ucontrol))
2147 return 0;
2148
2149 cxt5066_update_speaker(codec);
2150 return 1;
2151}
2152
Daniel Drakec4cfe662010-01-07 13:47:04 +01002153static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2154 .num_items = 3,
2155 .items = {
2156 { "Off", PIN_IN },
2157 { "50%", PIN_VREF50 },
2158 { "80%", PIN_VREF80 },
2159 },
2160};
2161
2162static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2163{
2164 struct conexant_spec *spec = codec->spec;
2165 /* Even though port F is the DC input, the bias is controlled on port B.
2166 * we also leave that port as an active input (but unselected) in DC mode
2167 * just in case that is necessary to make the bias setting take effect. */
2168 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2169 AC_VERB_SET_PIN_WIDGET_CONTROL,
2170 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2171}
2172
Daniel Drake75f89912010-01-07 13:46:25 +01002173/* OLPC defers mic widget control until when capture is started because the
2174 * microphone LED comes on as soon as these settings are put in place. if we
2175 * did this before recording, it would give the false indication that recording
2176 * is happening when it is not. */
2177static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002178{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002179 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002180 if (!spec->recording)
2181 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002182
Daniel Drakec4cfe662010-01-07 13:47:04 +01002183 if (spec->dc_enable) {
2184 /* in DC mode we ignore presence detection and just use the jack
2185 * through our special DC port */
2186 const struct hda_verb enable_dc_mode[] = {
2187 /* disble internal mic, port C */
2188 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2189
2190 /* enable DC capture, port F */
2191 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2192 {},
2193 };
2194
2195 snd_hda_sequence_write(codec, enable_dc_mode);
2196 /* port B input disabled (and bias set) through the following call */
2197 cxt5066_set_olpc_dc_bias(codec);
2198 return;
2199 }
2200
2201 /* disable DC (port F) */
2202 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2203
Daniel Drake75f89912010-01-07 13:46:25 +01002204 /* external mic, port B */
2205 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2206 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002207
Daniel Drake75f89912010-01-07 13:46:25 +01002208 /* internal mic, port C */
2209 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2210 spec->ext_mic_present ? 0 : PIN_VREF80);
2211}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002212
Daniel Drake75f89912010-01-07 13:46:25 +01002213/* toggle input of built-in and mic jack appropriately */
2214static void cxt5066_olpc_automic(struct hda_codec *codec)
2215{
2216 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002217 unsigned int present;
2218
Daniel Drakec4cfe662010-01-07 13:47:04 +01002219 if (spec->dc_enable) /* don't do presence detection in DC mode */
2220 return;
2221
Daniel Drake75f89912010-01-07 13:46:25 +01002222 present = snd_hda_codec_read(codec, 0x1a, 0,
2223 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2224 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002225 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002226 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002227 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002228
2229 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2230 present ? 0 : 1);
2231 spec->ext_mic_present = !!present;
2232
2233 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002234}
2235
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002236/* toggle input of built-in digital mic and mic jack appropriately */
2237static void cxt5066_vostro_automic(struct hda_codec *codec)
2238{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002239 unsigned int present;
2240
2241 struct hda_verb ext_mic_present[] = {
2242 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002243 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002244
2245 /* switch to external mic input */
2246 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2247 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2248
2249 /* disable internal digital mic */
2250 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2251 {}
2252 };
2253 static struct hda_verb ext_mic_absent[] = {
2254 /* enable internal mic, port C */
2255 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2256
2257 /* switch to internal mic input */
2258 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2259
2260 /* disable external mic, port B */
2261 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2262 {}
2263 };
2264
2265 present = snd_hda_jack_detect(codec, 0x1a);
2266 if (present) {
2267 snd_printdd("CXT5066: external microphone detected\n");
2268 snd_hda_sequence_write(codec, ext_mic_present);
2269 } else {
2270 snd_printdd("CXT5066: external microphone absent\n");
2271 snd_hda_sequence_write(codec, ext_mic_absent);
2272 }
2273}
2274
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002275/* toggle input of built-in digital mic and mic jack appropriately */
2276static void cxt5066_ideapad_automic(struct hda_codec *codec)
2277{
2278 unsigned int present;
2279
2280 struct hda_verb ext_mic_present[] = {
2281 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2282 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2283 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2284 {}
2285 };
2286 static struct hda_verb ext_mic_absent[] = {
2287 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2288 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2289 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2290 {}
2291 };
2292
2293 present = snd_hda_jack_detect(codec, 0x1b);
2294 if (present) {
2295 snd_printdd("CXT5066: external microphone detected\n");
2296 snd_hda_sequence_write(codec, ext_mic_present);
2297 } else {
2298 snd_printdd("CXT5066: external microphone absent\n");
2299 snd_hda_sequence_write(codec, ext_mic_absent);
2300 }
2301}
2302
David Henningsson048e78a2010-09-02 08:35:47 +02002303/* toggle input of built-in digital mic and mic jack appropriately */
2304static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2305{
2306 unsigned int present;
2307
2308 present = snd_hda_jack_detect(codec, 0x1b);
2309 snd_printdd("CXT5066: external microphone present=%d\n", present);
2310 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2311 present ? 1 : 3);
2312}
2313
2314
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002315/* toggle input of built-in digital mic and mic jack appropriately
2316 order is: external mic -> dock mic -> interal mic */
2317static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2318{
2319 unsigned int ext_present, dock_present;
2320
2321 static struct hda_verb ext_mic_present[] = {
2322 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2323 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2324 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2325 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2326 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2327 {}
2328 };
2329 static struct hda_verb dock_mic_present[] = {
2330 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2331 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2332 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2333 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2334 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2335 {}
2336 };
2337 static struct hda_verb ext_mic_absent[] = {
2338 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2339 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2341 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2342 {}
2343 };
2344
2345 ext_present = snd_hda_jack_detect(codec, 0x1b);
2346 dock_present = snd_hda_jack_detect(codec, 0x1a);
2347 if (ext_present) {
2348 snd_printdd("CXT5066: external microphone detected\n");
2349 snd_hda_sequence_write(codec, ext_mic_present);
2350 } else if (dock_present) {
2351 snd_printdd("CXT5066: dock microphone detected\n");
2352 snd_hda_sequence_write(codec, dock_mic_present);
2353 } else {
2354 snd_printdd("CXT5066: external microphone absent\n");
2355 snd_hda_sequence_write(codec, ext_mic_absent);
2356 }
2357}
2358
Daniel Drake0fb67e92009-07-16 14:46:57 +01002359/* mute internal speaker if HP is plugged */
2360static void cxt5066_hp_automute(struct hda_codec *codec)
2361{
2362 struct conexant_spec *spec = codec->spec;
2363 unsigned int portA, portD;
2364
2365 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002366 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002367
2368 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002369 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002370
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002371 spec->hp_present = !!(portA);
2372 spec->hp_present |= portD ? 2 : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002373 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2374 portA, portD, spec->hp_present);
2375 cxt5066_update_speaker(codec);
2376}
2377
2378/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002379static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002380{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002381 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002382 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2383 switch (res >> 26) {
2384 case CONEXANT_HP_EVENT:
2385 cxt5066_hp_automute(codec);
2386 break;
2387 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002388 /* ignore mic events in DC mode; we're always using the jack */
2389 if (!spec->dc_enable)
2390 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002391 break;
2392 }
2393}
2394
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002395/* unsolicited event for jack sensing */
2396static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2397{
2398 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2399 switch (res >> 26) {
2400 case CONEXANT_HP_EVENT:
2401 cxt5066_hp_automute(codec);
2402 break;
2403 case CONEXANT_MIC_EVENT:
2404 cxt5066_vostro_automic(codec);
2405 break;
2406 }
2407}
2408
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002409/* unsolicited event for jack sensing */
2410static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2411{
2412 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2413 switch (res >> 26) {
2414 case CONEXANT_HP_EVENT:
2415 cxt5066_hp_automute(codec);
2416 break;
2417 case CONEXANT_MIC_EVENT:
2418 cxt5066_ideapad_automic(codec);
2419 break;
2420 }
2421}
2422
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002423/* unsolicited event for jack sensing */
David Henningsson048e78a2010-09-02 08:35:47 +02002424static void cxt5066_hp_laptop_event(struct hda_codec *codec, unsigned int res)
2425{
2426 snd_printdd("CXT5066_hp_laptop: unsol event %x (%x)\n", res, res >> 26);
2427 switch (res >> 26) {
2428 case CONEXANT_HP_EVENT:
2429 cxt5066_hp_automute(codec);
2430 break;
2431 case CONEXANT_MIC_EVENT:
2432 cxt5066_hp_laptop_automic(codec);
2433 break;
2434 }
2435}
2436
2437/* unsolicited event for jack sensing */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002438static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
2439{
2440 snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
2441 switch (res >> 26) {
2442 case CONEXANT_HP_EVENT:
2443 cxt5066_hp_automute(codec);
2444 break;
2445 case CONEXANT_MIC_EVENT:
2446 cxt5066_thinkpad_automic(codec);
2447 break;
2448 }
2449}
2450
Daniel Drake0fb67e92009-07-16 14:46:57 +01002451static const struct hda_input_mux cxt5066_analog_mic_boost = {
2452 .num_items = 5,
2453 .items = {
2454 { "0dB", 0 },
2455 { "10dB", 1 },
2456 { "20dB", 2 },
2457 { "30dB", 3 },
2458 { "40dB", 4 },
2459 },
2460};
2461
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002462static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002463{
2464 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002465 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002466 AC_VERB_SET_AMP_GAIN_MUTE,
2467 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2468 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002469 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002470 /* adjust the internal mic as well...it is not through 0x17 */
2471 snd_hda_codec_write_cache(codec, 0x23, 0,
2472 AC_VERB_SET_AMP_GAIN_MUTE,
2473 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2474 cxt5066_analog_mic_boost.
2475 items[spec->mic_boost].index);
2476 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002477}
2478
Daniel Drake0fb67e92009-07-16 14:46:57 +01002479static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2480 struct snd_ctl_elem_info *uinfo)
2481{
2482 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2483}
2484
2485static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2487{
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002489 struct conexant_spec *spec = codec->spec;
2490 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002491 return 0;
2492}
2493
2494static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2495 struct snd_ctl_elem_value *ucontrol)
2496{
2497 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002498 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002499 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2500 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002501 idx = ucontrol->value.enumerated.item[0];
2502 if (idx >= imux->num_items)
2503 idx = imux->num_items - 1;
2504
Daniel Drakec4cfe662010-01-07 13:47:04 +01002505 spec->mic_boost = idx;
2506 if (!spec->dc_enable)
2507 cxt5066_set_mic_boost(codec);
2508 return 1;
2509}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002510
Daniel Drakec4cfe662010-01-07 13:47:04 +01002511static void cxt5066_enable_dc(struct hda_codec *codec)
2512{
2513 const struct hda_verb enable_dc_mode[] = {
2514 /* disable gain */
2515 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516
2517 /* switch to DC input */
2518 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2519 {}
2520 };
2521
2522 /* configure as input source */
2523 snd_hda_sequence_write(codec, enable_dc_mode);
2524 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2525}
2526
2527static void cxt5066_disable_dc(struct hda_codec *codec)
2528{
2529 /* reconfigure input source */
2530 cxt5066_set_mic_boost(codec);
2531 /* automic also selects the right mic if we're recording */
2532 cxt5066_olpc_automic(codec);
2533}
2534
2535static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2536 struct snd_ctl_elem_value *ucontrol)
2537{
2538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2539 struct conexant_spec *spec = codec->spec;
2540 ucontrol->value.integer.value[0] = spec->dc_enable;
2541 return 0;
2542}
2543
2544static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2545 struct snd_ctl_elem_value *ucontrol)
2546{
2547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2548 struct conexant_spec *spec = codec->spec;
2549 int dc_enable = !!ucontrol->value.integer.value[0];
2550
2551 if (dc_enable == spec->dc_enable)
2552 return 0;
2553
2554 spec->dc_enable = dc_enable;
2555 if (dc_enable)
2556 cxt5066_enable_dc(codec);
2557 else
2558 cxt5066_disable_dc(codec);
2559
2560 return 1;
2561}
2562
2563static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2564 struct snd_ctl_elem_info *uinfo)
2565{
2566 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2567}
2568
2569static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2570 struct snd_ctl_elem_value *ucontrol)
2571{
2572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2573 struct conexant_spec *spec = codec->spec;
2574 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2575 return 0;
2576}
2577
2578static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2579 struct snd_ctl_elem_value *ucontrol)
2580{
2581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2582 struct conexant_spec *spec = codec->spec;
2583 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2584 unsigned int idx;
2585
2586 idx = ucontrol->value.enumerated.item[0];
2587 if (idx >= imux->num_items)
2588 idx = imux->num_items - 1;
2589
2590 spec->dc_input_bias = idx;
2591 if (spec->dc_enable)
2592 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002593 return 1;
2594}
2595
Daniel Drake75f89912010-01-07 13:46:25 +01002596static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2597{
2598 struct conexant_spec *spec = codec->spec;
2599 /* mark as recording and configure the microphone widget so that the
2600 * recording LED comes on. */
2601 spec->recording = 1;
2602 cxt5066_olpc_select_mic(codec);
2603}
2604
2605static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2606{
2607 struct conexant_spec *spec = codec->spec;
2608 const struct hda_verb disable_mics[] = {
2609 /* disable external mic, port B */
2610 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2611
2612 /* disble internal mic, port C */
2613 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002614
2615 /* disable DC capture, port F */
2616 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002617 {},
2618 };
2619
2620 snd_hda_sequence_write(codec, disable_mics);
2621 spec->recording = 0;
2622}
2623
Daniel Drake0fb67e92009-07-16 14:46:57 +01002624static struct hda_input_mux cxt5066_capture_source = {
2625 .num_items = 4,
2626 .items = {
2627 { "Mic B", 0 },
2628 { "Mic C", 1 },
2629 { "Mic E", 2 },
2630 { "Mic F", 3 },
2631 },
2632};
2633
2634static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2635 .ops = &snd_hda_bind_vol,
2636 .values = {
2637 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2638 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2639 0
2640 },
2641};
2642
2643static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2644 .ops = &snd_hda_bind_sw,
2645 .values = {
2646 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2647 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2648 0
2649 },
2650};
2651
2652static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2653 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2654 {}
2655};
2656
2657static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2658 {
2659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2660 .name = "Master Playback Volume",
2661 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2662 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2663 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002664 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002665 .info = snd_hda_mixer_amp_volume_info,
2666 .get = snd_hda_mixer_amp_volume_get,
2667 .put = snd_hda_mixer_amp_volume_put,
2668 .tlv = { .c = snd_hda_mixer_amp_tlv },
2669 /* offset by 28 volume steps to limit minimum gain to -46dB */
2670 .private_value =
2671 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2672 },
2673 {}
2674};
2675
Daniel Drakec4cfe662010-01-07 13:47:04 +01002676static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2677 {
2678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2679 .name = "DC Mode Enable Switch",
2680 .info = snd_ctl_boolean_mono_info,
2681 .get = cxt5066_olpc_dc_get,
2682 .put = cxt5066_olpc_dc_put,
2683 },
2684 {
2685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686 .name = "DC Input Bias Enum",
2687 .info = cxt5066_olpc_dc_bias_enum_info,
2688 .get = cxt5066_olpc_dc_bias_enum_get,
2689 .put = cxt5066_olpc_dc_bias_enum_put,
2690 },
2691 {}
2692};
2693
Daniel Drake0fb67e92009-07-16 14:46:57 +01002694static struct snd_kcontrol_new cxt5066_mixers[] = {
2695 {
2696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2697 .name = "Master Playback Switch",
2698 .info = cxt_eapd_info,
2699 .get = cxt_eapd_get,
2700 .put = cxt5066_hp_master_sw_put,
2701 .private_value = 0x1d,
2702 },
2703
2704 {
2705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002706 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002707 .info = cxt5066_mic_boost_mux_enum_info,
2708 .get = cxt5066_mic_boost_mux_enum_get,
2709 .put = cxt5066_mic_boost_mux_enum_put,
2710 },
2711
2712 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2713 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2714 {}
2715};
2716
Einar Rünkaru254bba62009-12-16 22:16:13 +02002717static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2718 {
2719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2720 .name = "Int Mic Boost Capture Enum",
2721 .info = cxt5066_mic_boost_mux_enum_info,
2722 .get = cxt5066_mic_boost_mux_enum_get,
2723 .put = cxt5066_mic_boost_mux_enum_put,
2724 .private_value = 0x23 | 0x100,
2725 },
2726 {}
2727};
2728
Daniel Drake0fb67e92009-07-16 14:46:57 +01002729static struct hda_verb cxt5066_init_verbs[] = {
2730 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2731 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2732 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2733 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2734
2735 /* Speakers */
2736 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2737 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2738
2739 /* HP, Amp */
2740 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2741 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2742
2743 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2744 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2745
2746 /* DAC1 */
2747 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2748
2749 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2752 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2753 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2755
2756 /* no digital microphone support yet */
2757 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2758
2759 /* Audio input selector */
2760 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2761
2762 /* SPDIF route: PCM */
2763 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2764 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2765
2766 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2767 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2768
2769 /* EAPD */
2770 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2771
2772 /* not handling these yet */
2773 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2774 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2775 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2776 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2777 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2778 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2779 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2780 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2781 { } /* end */
2782};
2783
2784static struct hda_verb cxt5066_init_verbs_olpc[] = {
2785 /* Port A: headphones */
2786 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2787 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2788
2789 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002790 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002791
2792 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002793 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002794
2795 /* Port D: unused */
2796 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2797
2798 /* Port E: unused, but has primary EAPD */
2799 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2800 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2801
Daniel Drakec4cfe662010-01-07 13:47:04 +01002802 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002803 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2804
2805 /* Port G: internal speakers */
2806 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2807 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2808
2809 /* DAC1 */
2810 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2811
2812 /* DAC2: unused */
2813 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2814
2815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2819 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2820 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2821 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2822 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2823 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2824 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2825 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2826 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2827
2828 /* Disable digital microphone port */
2829 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2830
2831 /* Audio input selectors */
2832 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2833 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2834
2835 /* Disable SPDIF */
2836 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2837 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2838
2839 /* enable unsolicited events for Port A and B */
2840 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2841 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2842 { } /* end */
2843};
2844
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002845static struct hda_verb cxt5066_init_verbs_vostro[] = {
2846 /* Port A: headphones */
2847 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2848 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2849
2850 /* Port B: external microphone */
2851 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2852
2853 /* Port C: unused */
2854 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855
2856 /* Port D: unused */
2857 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2858
2859 /* Port E: unused, but has primary EAPD */
2860 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2861 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2862
2863 /* Port F: unused */
2864 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2865
2866 /* Port G: internal speakers */
2867 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2868 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2869
2870 /* DAC1 */
2871 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2872
2873 /* DAC2: unused */
2874 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2875
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2877 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2880 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2881 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2882 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2883 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2884 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2885 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2887 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2888
2889 /* Digital microphone port */
2890 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2891
2892 /* Audio input selectors */
2893 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2894 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2895
2896 /* Disable SPDIF */
2897 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2898 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2899
2900 /* enable unsolicited events for Port A and B */
2901 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2903 { } /* end */
2904};
2905
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002906static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2907 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2908 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2909 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2910 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2911
2912 /* Speakers */
2913 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2914 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2915
2916 /* HP, Amp */
2917 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2918 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2919
2920 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2921 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2922
2923 /* DAC1 */
2924 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2925
2926 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2927 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2928 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2929 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2930 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2931 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2932 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2933
2934 /* Audio input selector */
2935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2936 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2937
2938 /* SPDIF route: PCM */
2939 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2940 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2941
2942 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2943 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2944
2945 /* internal microphone */
2946 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2947
2948 /* EAPD */
2949 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2950
2951 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2952 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2953 { } /* end */
2954};
2955
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002956static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2957 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2958 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2959
2960 /* Port G: internal speakers */
2961 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2962 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2963
2964 /* Port A: HP, Amp */
2965 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2966 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2967
2968 /* Port B: Mic Dock */
2969 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2970
2971 /* Port C: Mic */
2972 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2973
2974 /* Port D: HP Dock, Amp */
2975 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2976 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2977
2978 /* DAC1 */
2979 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2980
2981 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2982 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2983 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2984 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2985 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2986 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2987 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2988
2989 /* Audio input selector */
2990 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2991 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2992
2993 /* SPDIF route: PCM */
2994 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2995 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2996
2997 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2998 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2999
3000 /* internal microphone */
3001 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
3002
3003 /* EAPD */
3004 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3005
3006 /* enable unsolicited events for Port A, B, C and D */
3007 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3008 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3009 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3010 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3011 { } /* end */
3012};
3013
Daniel Drake0fb67e92009-07-16 14:46:57 +01003014static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3015 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3016 { } /* end */
3017};
3018
David Henningsson048e78a2010-09-02 08:35:47 +02003019
3020static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3021 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3022 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3023 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3024 { } /* end */
3025};
3026
Daniel Drake0fb67e92009-07-16 14:46:57 +01003027/* initialize jack-sensing, too */
3028static int cxt5066_init(struct hda_codec *codec)
3029{
Einar Rünkaru254bba62009-12-16 22:16:13 +02003030 struct conexant_spec *spec = codec->spec;
3031
Daniel Drake0fb67e92009-07-16 14:46:57 +01003032 snd_printdd("CXT5066: init\n");
3033 conexant_init(codec);
3034 if (codec->patch_ops.unsol_event) {
3035 cxt5066_hp_automute(codec);
Einar Rünkaru254bba62009-12-16 22:16:13 +02003036 if (spec->dell_vostro)
3037 cxt5066_vostro_automic(codec);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003038 else if (spec->ideapad)
3039 cxt5066_ideapad_automic(codec);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003040 else if (spec->thinkpad)
3041 cxt5066_thinkpad_automic(codec);
David Henningsson048e78a2010-09-02 08:35:47 +02003042 else if (spec->hp_laptop)
3043 cxt5066_hp_laptop_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003044 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003045 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003046 return 0;
3047}
3048
Daniel Drake75f89912010-01-07 13:46:25 +01003049static int cxt5066_olpc_init(struct hda_codec *codec)
3050{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003051 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003052 snd_printdd("CXT5066: init\n");
3053 conexant_init(codec);
3054 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003055 if (!spec->dc_enable) {
3056 cxt5066_set_mic_boost(codec);
3057 cxt5066_olpc_automic(codec);
3058 } else {
3059 cxt5066_enable_dc(codec);
3060 }
Daniel Drake75f89912010-01-07 13:46:25 +01003061 return 0;
3062}
3063
Daniel Drake0fb67e92009-07-16 14:46:57 +01003064enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003065 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003066 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3067 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003068 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003069 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003070 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
David Henningsson048e78a2010-09-02 08:35:47 +02003071 CXT5066_HP_LAPTOP, /* HP Laptop */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003072 CXT5066_MODELS
3073};
3074
3075static const char *cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003076 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003077 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3078 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003079 [CXT5066_DELL_VOSTO] = "dell-vostro",
3080 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003081 [CXT5066_THINKPAD] = "thinkpad",
David Henningsson048e78a2010-09-02 08:35:47 +02003082 [CXT5066_HP_LAPTOP] = "hp-laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003083};
3084
3085static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3086 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3087 CXT5066_LAPTOP),
3088 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
3089 CXT5066_DELL_LAPTOP),
Daniel Drake798a8a12009-11-04 10:11:07 +00003090 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Takashi Iwaic3e68fa2010-08-16 10:15:57 +02003091 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTO),
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003092 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003093 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
David Henningsson048e78a2010-09-02 08:35:47 +02003094 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
Daniel T Chenc5366682010-05-04 22:07:58 -04003095 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003096 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
Andrej Gelenberg0217f142010-05-09 22:10:41 +02003097 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
Andreas Herrmannbadf18b2010-05-28 09:57:12 +02003098 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
Jerone Younga39e33e2010-05-26 10:06:01 -05003099 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003100 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3101 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD),
Jerone Young6f0ef6e2010-08-23 08:34:36 +02003102 SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003103 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD),
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003104 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003105 {}
3106};
3107
3108static int patch_cxt5066(struct hda_codec *codec)
3109{
3110 struct conexant_spec *spec;
3111 int board_config;
3112
3113 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3114 if (!spec)
3115 return -ENOMEM;
3116 codec->spec = spec;
3117
3118 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003119 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003120
3121 spec->dell_automute = 0;
3122 spec->multiout.max_channels = 2;
3123 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3124 spec->multiout.dac_nids = cxt5066_dac_nids;
3125 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
3126 spec->num_adc_nids = 1;
3127 spec->adc_nids = cxt5066_adc_nids;
3128 spec->capsrc_nids = cxt5066_capsrc_nids;
3129 spec->input_mux = &cxt5066_capture_source;
3130
3131 spec->port_d_mode = PIN_HP;
3132
3133 spec->num_init_verbs = 1;
3134 spec->init_verbs[0] = cxt5066_init_verbs;
3135 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3136 spec->channel_mode = cxt5066_modes;
3137 spec->cur_adc = 0;
3138 spec->cur_adc_idx = 0;
3139
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003140 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3141
Daniel Drake0fb67e92009-07-16 14:46:57 +01003142 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3143 cxt5066_models, cxt5066_cfg_tbl);
3144 switch (board_config) {
3145 default:
3146 case CXT5066_LAPTOP:
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3148 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3149 break;
3150 case CXT5066_DELL_LAPTOP:
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3152 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3153
3154 spec->port_d_mode = PIN_OUT;
3155 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3156 spec->num_init_verbs++;
3157 spec->dell_automute = 1;
3158 break;
David Henningsson048e78a2010-09-02 08:35:47 +02003159 case CXT5066_HP_LAPTOP:
3160 codec->patch_ops.init = cxt5066_init;
3161 codec->patch_ops.unsol_event = cxt5066_hp_laptop_event;
3162 spec->init_verbs[spec->num_init_verbs] =
3163 cxt5066_init_verbs_hp_laptop;
3164 spec->num_init_verbs++;
3165 spec->hp_laptop = 1;
3166 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3167 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3168 /* no S/PDIF out */
3169 spec->multiout.dig_out_nid = 0;
3170 /* input source automatically selected */
3171 spec->input_mux = NULL;
3172 spec->port_d_mode = 0;
3173 spec->mic_boost = 3; /* default 30dB gain */
3174 break;
3175
Daniel Drake0fb67e92009-07-16 14:46:57 +01003176 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003177 codec->patch_ops.init = cxt5066_olpc_init;
3178 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003179 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3180 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003181 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003182 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3183 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003184 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003185
3186 /* no S/PDIF out */
3187 spec->multiout.dig_out_nid = 0;
3188
3189 /* input source automatically selected */
3190 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003191
3192 /* our capture hooks which allow us to turn on the microphone LED
3193 * at the right time */
3194 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3195 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003196 break;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003197 case CXT5066_DELL_VOSTO:
Daniel Drake75f89912010-01-07 13:46:25 +01003198 codec->patch_ops.init = cxt5066_init;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003199 codec->patch_ops.unsol_event = cxt5066_vostro_event;
3200 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3201 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3202 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003203 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003204 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003205 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003206 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003207
3208 /* no S/PDIF out */
3209 spec->multiout.dig_out_nid = 0;
3210
3211 /* input source automatically selected */
3212 spec->input_mux = NULL;
3213 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003214 case CXT5066_IDEAPAD:
3215 codec->patch_ops.init = cxt5066_init;
3216 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3217 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3218 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3219 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3220 spec->port_d_mode = 0;
3221 spec->ideapad = 1;
3222 spec->mic_boost = 2; /* default 20dB gain */
3223
3224 /* no S/PDIF out */
3225 spec->multiout.dig_out_nid = 0;
3226
3227 /* input source automatically selected */
3228 spec->input_mux = NULL;
3229 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003230 case CXT5066_THINKPAD:
3231 codec->patch_ops.init = cxt5066_init;
3232 codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
3233 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3234 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3235 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3236 spec->thinkpad = 1;
3237 spec->port_d_mode = PIN_OUT;
3238 spec->mic_boost = 2; /* default 20dB gain */
3239
3240 /* no S/PDIF out */
3241 spec->multiout.dig_out_nid = 0;
3242
3243 /* input source automatically selected */
3244 spec->input_mux = NULL;
3245 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003246 }
3247
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003248 if (spec->beep_amp)
3249 snd_hda_attach_beep_device(codec, spec->beep_amp);
3250
Daniel Drake0fb67e92009-07-16 14:46:57 +01003251 return 0;
3252}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003253
3254/*
3255 */
3256
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003257static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003258 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3259 .patch = patch_cxt5045 },
3260 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3261 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003262 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3263 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003264 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3265 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003266 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3267 .patch = patch_cxt5066 },
Takashi Iwai850eab92010-08-09 13:44:27 +02003268 { .id = 0x14f15068, .name = "CX20584",
3269 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003270 { .id = 0x14f15069, .name = "CX20585",
3271 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003272 {} /* terminator */
3273};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003274
3275MODULE_ALIAS("snd-hda-codec-id:14f15045");
3276MODULE_ALIAS("snd-hda-codec-id:14f15047");
3277MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003278MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003279MODULE_ALIAS("snd-hda-codec-id:14f15067");
Takashi Iwai850eab92010-08-09 13:44:27 +02003280MODULE_ALIAS("snd-hda-codec-id:14f15068");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003281MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003282
3283MODULE_LICENSE("GPL");
3284MODULE_DESCRIPTION("Conexant HD-audio codec");
3285
3286static struct hda_codec_preset_list conexant_list = {
3287 .preset = snd_hda_preset_conexant,
3288 .owner = THIS_MODULE,
3289};
3290
3291static int __init patch_conexant_init(void)
3292{
3293 return snd_hda_add_codec_preset(&conexant_list);
3294}
3295
3296static void __exit patch_conexant_exit(void)
3297{
3298 snd_hda_delete_codec_preset(&conexant_list);
3299}
3300
3301module_init(patch_conexant_init)
3302module_exit(patch_conexant_exit)