blob: d6341f3fef01bfa0da87979b6c1accc44a04b4a6 [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;
Daniel Drake75f89912010-01-07 13:46:25 +0100119
120 unsigned int ext_mic_present;
121 unsigned int recording;
122 void (*capture_prepare)(struct hda_codec *codec);
123 void (*capture_cleanup)(struct hda_codec *codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +0100124
125 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
126 * through the microphone jack.
127 * When the user enables this through a mixer switch, both internal and
128 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
129 * we also allow the bias to be configured through a separate mixer
130 * control. */
131 unsigned int dc_enable;
132 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
133 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200134
135 unsigned int beep_amp;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100136};
137
138static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
139 struct hda_codec *codec,
140 struct snd_pcm_substream *substream)
141{
142 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100143 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
144 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100145}
146
147static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
148 struct hda_codec *codec,
149 unsigned int stream_tag,
150 unsigned int format,
151 struct snd_pcm_substream *substream)
152{
153 struct conexant_spec *spec = codec->spec;
154 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
155 stream_tag,
156 format, substream);
157}
158
159static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
160 struct hda_codec *codec,
161 struct snd_pcm_substream *substream)
162{
163 struct conexant_spec *spec = codec->spec;
164 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
165}
166
167/*
168 * Digital out
169 */
170static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
173{
174 struct conexant_spec *spec = codec->spec;
175 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
176}
177
178static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
179 struct hda_codec *codec,
180 struct snd_pcm_substream *substream)
181{
182 struct conexant_spec *spec = codec->spec;
183 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
184}
185
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200186static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
187 struct hda_codec *codec,
188 unsigned int stream_tag,
189 unsigned int format,
190 struct snd_pcm_substream *substream)
191{
192 struct conexant_spec *spec = codec->spec;
193 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
194 stream_tag,
195 format, substream);
196}
197
Tobin Davisc9b443d2006-11-14 12:13:39 +0100198/*
199 * Analog capture
200 */
201static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
202 struct hda_codec *codec,
203 unsigned int stream_tag,
204 unsigned int format,
205 struct snd_pcm_substream *substream)
206{
207 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100208 if (spec->capture_prepare)
209 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100210 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
211 stream_tag, 0, format);
212 return 0;
213}
214
215static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
216 struct hda_codec *codec,
217 struct snd_pcm_substream *substream)
218{
219 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100220 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100221 if (spec->capture_cleanup)
222 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100223 return 0;
224}
225
226
227
228static struct hda_pcm_stream conexant_pcm_analog_playback = {
229 .substreams = 1,
230 .channels_min = 2,
231 .channels_max = 2,
232 .nid = 0, /* fill later */
233 .ops = {
234 .open = conexant_playback_pcm_open,
235 .prepare = conexant_playback_pcm_prepare,
236 .cleanup = conexant_playback_pcm_cleanup
237 },
238};
239
240static struct hda_pcm_stream conexant_pcm_analog_capture = {
241 .substreams = 1,
242 .channels_min = 2,
243 .channels_max = 2,
244 .nid = 0, /* fill later */
245 .ops = {
246 .prepare = conexant_capture_pcm_prepare,
247 .cleanup = conexant_capture_pcm_cleanup
248 },
249};
250
251
252static struct hda_pcm_stream conexant_pcm_digital_playback = {
253 .substreams = 1,
254 .channels_min = 2,
255 .channels_max = 2,
256 .nid = 0, /* fill later */
257 .ops = {
258 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200259 .close = conexant_dig_playback_pcm_close,
260 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100261 },
262};
263
264static struct hda_pcm_stream conexant_pcm_digital_capture = {
265 .substreams = 1,
266 .channels_min = 2,
267 .channels_max = 2,
268 /* NID is set in alc_build_pcms */
269};
270
Takashi Iwai461e2c72008-01-25 11:35:17 +0100271static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
272 struct hda_codec *codec,
273 unsigned int stream_tag,
274 unsigned int format,
275 struct snd_pcm_substream *substream)
276{
277 struct conexant_spec *spec = codec->spec;
278 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
279 spec->cur_adc_stream_tag = stream_tag;
280 spec->cur_adc_format = format;
281 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
282 return 0;
283}
284
285static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
286 struct hda_codec *codec,
287 struct snd_pcm_substream *substream)
288{
289 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100290 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100291 spec->cur_adc = 0;
292 return 0;
293}
294
295static struct hda_pcm_stream cx5051_pcm_analog_capture = {
296 .substreams = 1,
297 .channels_min = 2,
298 .channels_max = 2,
299 .nid = 0, /* fill later */
300 .ops = {
301 .prepare = cx5051_capture_pcm_prepare,
302 .cleanup = cx5051_capture_pcm_cleanup
303 },
304};
305
Tobin Davisc9b443d2006-11-14 12:13:39 +0100306static int conexant_build_pcms(struct hda_codec *codec)
307{
308 struct conexant_spec *spec = codec->spec;
309 struct hda_pcm *info = spec->pcm_rec;
310
311 codec->num_pcms = 1;
312 codec->pcm_info = info;
313
314 info->name = "CONEXANT Analog";
315 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
316 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
317 spec->multiout.max_channels;
318 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
319 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100320 if (codec->vendor_id == 0x14f15051)
321 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
322 cx5051_pcm_analog_capture;
323 else
324 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
325 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100326 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
327 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
328
329 if (spec->multiout.dig_out_nid) {
330 info++;
331 codec->num_pcms++;
332 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100333 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100334 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
335 conexant_pcm_digital_playback;
336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
337 spec->multiout.dig_out_nid;
338 if (spec->dig_in_nid) {
339 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
340 conexant_pcm_digital_capture;
341 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
342 spec->dig_in_nid;
343 }
344 }
345
346 return 0;
347}
348
349static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
350 struct snd_ctl_elem_info *uinfo)
351{
352 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353 struct conexant_spec *spec = codec->spec;
354
355 return snd_hda_input_mux_info(spec->input_mux, uinfo);
356}
357
358static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol)
360{
361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
362 struct conexant_spec *spec = codec->spec;
363 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
364
365 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
366 return 0;
367}
368
369static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
370 struct snd_ctl_elem_value *ucontrol)
371{
372 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
373 struct conexant_spec *spec = codec->spec;
374 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
375
376 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
377 spec->capsrc_nids[adc_idx],
378 &spec->cur_mux[adc_idx]);
379}
380
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200381#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200382static void conexant_free_jack_priv(struct snd_jack *jack)
383{
384 struct conexant_jack *jacks = jack->private_data;
385 jacks->nid = 0;
386 jacks->jack = NULL;
387}
388
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100389static int conexant_add_jack(struct hda_codec *codec,
390 hda_nid_t nid, int type)
391{
392 struct conexant_spec *spec;
393 struct conexant_jack *jack;
394 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200395 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100396
397 spec = codec->spec;
398 snd_array_init(&spec->jacks, sizeof(*jack), 32);
399 jack = snd_array_new(&spec->jacks);
400 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
401
402 if (!jack)
403 return -ENOMEM;
404
405 jack->nid = nid;
406 jack->type = type;
407
Takashi Iwai95c09092009-04-14 16:15:29 +0200408 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
409 if (err < 0)
410 return err;
411 jack->jack->private_data = jack;
412 jack->jack->private_free = conexant_free_jack_priv;
413 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100414}
415
416static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
417{
418 struct conexant_spec *spec = codec->spec;
419 struct conexant_jack *jacks = spec->jacks.list;
420
421 if (jacks) {
422 int i;
423 for (i = 0; i < spec->jacks.used; i++) {
424 if (jacks->nid == nid) {
425 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100426 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100427
428 present = (present) ? jacks->type : 0 ;
429
430 snd_jack_report(jacks->jack,
431 present);
432 }
433 jacks++;
434 }
435 }
436}
437
438static int conexant_init_jacks(struct hda_codec *codec)
439{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100440 struct conexant_spec *spec = codec->spec;
441 int i;
442
443 for (i = 0; i < spec->num_init_verbs; i++) {
444 const struct hda_verb *hv;
445
446 hv = spec->init_verbs[i];
447 while (hv->nid) {
448 int err = 0;
449 switch (hv->param ^ AC_USRSP_EN) {
450 case CONEXANT_HP_EVENT:
451 err = conexant_add_jack(codec, hv->nid,
452 SND_JACK_HEADPHONE);
453 conexant_report_jack(codec, hv->nid);
454 break;
455 case CXT5051_PORTC_EVENT:
456 case CONEXANT_MIC_EVENT:
457 err = conexant_add_jack(codec, hv->nid,
458 SND_JACK_MICROPHONE);
459 conexant_report_jack(codec, hv->nid);
460 break;
461 }
462 if (err < 0)
463 return err;
464 ++hv;
465 }
466 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100467 return 0;
468
469}
Takashi Iwai5801f992009-01-27 12:53:22 +0100470#else
471static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
472{
473}
474
475static inline int conexant_init_jacks(struct hda_codec *codec)
476{
477 return 0;
478}
479#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100480
Tobin Davisc9b443d2006-11-14 12:13:39 +0100481static int conexant_init(struct hda_codec *codec)
482{
483 struct conexant_spec *spec = codec->spec;
484 int i;
485
486 for (i = 0; i < spec->num_init_verbs; i++)
487 snd_hda_sequence_write(codec, spec->init_verbs[i]);
488 return 0;
489}
490
491static void conexant_free(struct hda_codec *codec)
492{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200493#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100494 struct conexant_spec *spec = codec->spec;
495 if (spec->jacks.list) {
496 struct conexant_jack *jacks = spec->jacks.list;
497 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200498 for (i = 0; i < spec->jacks.used; i++, jacks++) {
499 if (jacks->jack)
500 snd_device_free(codec->bus->card, jacks->jack);
501 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100502 snd_array_free(&spec->jacks);
503 }
504#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200505 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100506 kfree(codec->spec);
507}
508
Takashi Iwaib880c742009-03-10 14:41:05 +0100509static struct snd_kcontrol_new cxt_capture_mixers[] = {
510 {
511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
512 .name = "Capture Source",
513 .info = conexant_mux_enum_info,
514 .get = conexant_mux_enum_get,
515 .put = conexant_mux_enum_put
516 },
517 {}
518};
519
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200520#ifdef CONFIG_SND_HDA_INPUT_BEEP
521/* additional beep mixers; the actual parameters are overwritten at build */
522static struct snd_kcontrol_new cxt_beep_mixer[] = {
523 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
524 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
525 { } /* end */
526};
527#endif
528
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100529static const char *slave_vols[] = {
530 "Headphone Playback Volume",
531 "Speaker Playback Volume",
532 NULL
533};
534
535static const char *slave_sws[] = {
536 "Headphone Playback Switch",
537 "Speaker Playback Switch",
538 NULL
539};
540
Tobin Davisc9b443d2006-11-14 12:13:39 +0100541static int conexant_build_controls(struct hda_codec *codec)
542{
543 struct conexant_spec *spec = codec->spec;
544 unsigned int i;
545 int err;
546
547 for (i = 0; i < spec->num_mixers; i++) {
548 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
549 if (err < 0)
550 return err;
551 }
552 if (spec->multiout.dig_out_nid) {
553 err = snd_hda_create_spdif_out_ctls(codec,
554 spec->multiout.dig_out_nid);
555 if (err < 0)
556 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100557 err = snd_hda_create_spdif_share_sw(codec,
558 &spec->multiout);
559 if (err < 0)
560 return err;
561 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100562 }
563 if (spec->dig_in_nid) {
564 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
565 if (err < 0)
566 return err;
567 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100568
569 /* if we have no master control, let's create it */
570 if (spec->vmaster_nid &&
571 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
572 unsigned int vmaster_tlv[4];
573 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
574 HDA_OUTPUT, vmaster_tlv);
575 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
576 vmaster_tlv, slave_vols);
577 if (err < 0)
578 return err;
579 }
580 if (spec->vmaster_nid &&
581 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
582 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
583 NULL, slave_sws);
584 if (err < 0)
585 return err;
586 }
587
Takashi Iwaib880c742009-03-10 14:41:05 +0100588 if (spec->input_mux) {
589 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
590 if (err < 0)
591 return err;
592 }
593
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200594#ifdef CONFIG_SND_HDA_INPUT_BEEP
595 /* create beep controls if needed */
596 if (spec->beep_amp) {
597 struct snd_kcontrol_new *knew;
598 for (knew = cxt_beep_mixer; knew->name; knew++) {
599 struct snd_kcontrol *kctl;
600 kctl = snd_ctl_new1(knew, codec);
601 if (!kctl)
602 return -ENOMEM;
603 kctl->private_value = spec->beep_amp;
604 err = snd_hda_ctl_add(codec, 0, kctl);
605 if (err < 0)
606 return err;
607 }
608 }
609#endif
610
Tobin Davisc9b443d2006-11-14 12:13:39 +0100611 return 0;
612}
613
Takashi Iwai697c3732010-07-30 11:28:02 +0200614#ifdef CONFIG_SND_HDA_POWER_SAVE
615static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
616{
617 snd_hda_shutup_pins(codec);
618 return 0;
619}
620#endif
621
Tobin Davisc9b443d2006-11-14 12:13:39 +0100622static struct hda_codec_ops conexant_patch_ops = {
623 .build_controls = conexant_build_controls,
624 .build_pcms = conexant_build_pcms,
625 .init = conexant_init,
626 .free = conexant_free,
Takashi Iwai697c3732010-07-30 11:28:02 +0200627#ifdef CONFIG_SND_HDA_POWER_SAVE
628 .suspend = conexant_suspend,
629#endif
630 .reboot_notify = snd_hda_shutup_pins,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100631};
632
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200633#ifdef CONFIG_SND_HDA_INPUT_BEEP
634#define set_beep_amp(spec, nid, idx, dir) \
635 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
636#else
637#define set_beep_amp(spec, nid, idx, dir) /* NOP */
638#endif
639
Tobin Davisc9b443d2006-11-14 12:13:39 +0100640/*
641 * EAPD control
642 * the private value = nid | (invert << 8)
643 */
644
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200645#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100646
Tobin Davis82f30042007-02-13 12:45:44 +0100647static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100648 struct snd_ctl_elem_value *ucontrol)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct conexant_spec *spec = codec->spec;
652 int invert = (kcontrol->private_value >> 8) & 1;
653 if (invert)
654 ucontrol->value.integer.value[0] = !spec->cur_eapd;
655 else
656 ucontrol->value.integer.value[0] = spec->cur_eapd;
657 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100658
Tobin Davisc9b443d2006-11-14 12:13:39 +0100659}
660
Tobin Davis82f30042007-02-13 12:45:44 +0100661static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100662 struct snd_ctl_elem_value *ucontrol)
663{
664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
665 struct conexant_spec *spec = codec->spec;
666 int invert = (kcontrol->private_value >> 8) & 1;
667 hda_nid_t nid = kcontrol->private_value & 0xff;
668 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100669
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100670 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100671 if (invert)
672 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200673 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100674 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100675
Tobin Davisc9b443d2006-11-14 12:13:39 +0100676 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200677 snd_hda_codec_write_cache(codec, nid,
678 0, AC_VERB_SET_EAPD_BTLENABLE,
679 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100680 return 1;
681}
682
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100683/* controls for test mode */
684#ifdef CONFIG_SND_DEBUG
685
Tobin Davis82f30042007-02-13 12:45:44 +0100686#define CXT_EAPD_SWITCH(xname, nid, mask) \
687 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
688 .info = cxt_eapd_info, \
689 .get = cxt_eapd_get, \
690 .put = cxt_eapd_put, \
691 .private_value = nid | (mask<<16) }
692
693
694
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_info *uinfo)
697{
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699 struct conexant_spec *spec = codec->spec;
700 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
701 spec->num_channel_mode);
702}
703
704static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
705 struct snd_ctl_elem_value *ucontrol)
706{
707 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
708 struct conexant_spec *spec = codec->spec;
709 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
710 spec->num_channel_mode,
711 spec->multiout.max_channels);
712}
713
714static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct conexant_spec *spec = codec->spec;
719 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
720 spec->num_channel_mode,
721 &spec->multiout.max_channels);
722 if (err >= 0 && spec->need_dac_fix)
723 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
724 return err;
725}
726
727#define CXT_PIN_MODE(xname, nid, dir) \
728 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
729 .info = conexant_ch_mode_info, \
730 .get = conexant_ch_mode_get, \
731 .put = conexant_ch_mode_put, \
732 .private_value = nid | (dir<<16) }
733
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100734#endif /* CONFIG_SND_DEBUG */
735
Tobin Davisc9b443d2006-11-14 12:13:39 +0100736/* Conexant 5045 specific */
737
738static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
739static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
740static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100741#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100742
Tobin Davis5cd57522006-11-20 17:42:09 +0100743static struct hda_channel_mode cxt5045_modes[1] = {
744 { 2, NULL },
745};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100746
747static struct hda_input_mux cxt5045_capture_source = {
748 .num_items = 2,
749 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100750 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100751 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100752 }
753};
754
Jiang Zhe5218c892008-01-17 11:18:41 +0100755static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200756 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100757 .items = {
758 { "IntMic", 0x1 },
759 { "ExtMic", 0x2 },
760 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200761 { "CD", 0x4 },
762 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100763 }
764};
765
Jiang zhe2de3c232008-03-06 11:09:09 +0100766static struct hda_input_mux cxt5045_capture_source_hp530 = {
767 .num_items = 2,
768 .items = {
769 { "ExtMic", 0x1 },
770 { "IntMic", 0x2 },
771 }
772};
773
Tobin Davisc9b443d2006-11-14 12:13:39 +0100774/* turn on/off EAPD (+ mute HP) as a master switch */
775static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
776 struct snd_ctl_elem_value *ucontrol)
777{
778 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
779 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100780 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100781
Tobin Davis82f30042007-02-13 12:45:44 +0100782 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783 return 0;
784
Tobin Davis82f30042007-02-13 12:45:44 +0100785 /* toggle internal speakers mute depending of presence of
786 * the headphone jack
787 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200788 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
789 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
790 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100791
Takashi Iwai47fd8302007-08-10 17:11:07 +0200792 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
793 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
794 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795 return 1;
796}
797
798/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200799static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
800 .ops = &snd_hda_bind_vol,
801 .values = {
802 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
803 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
804 0
805 },
806};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100807
Tobin Davis7f296732007-03-12 11:39:01 +0100808/* toggle input of built-in and mic jack appropriately */
809static void cxt5045_hp_automic(struct hda_codec *codec)
810{
811 static struct hda_verb mic_jack_on[] = {
812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
813 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
814 {}
815 };
816 static struct hda_verb mic_jack_off[] = {
817 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
819 {}
820 };
821 unsigned int present;
822
Takashi Iwaid56757a2009-11-18 08:00:14 +0100823 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100824 if (present)
825 snd_hda_sequence_write(codec, mic_jack_on);
826 else
827 snd_hda_sequence_write(codec, mic_jack_off);
828}
829
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830
831/* mute internal speaker if HP is plugged */
832static void cxt5045_hp_automute(struct hda_codec *codec)
833{
Tobin Davis82f30042007-02-13 12:45:44 +0100834 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100835 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100836
Takashi Iwaid56757a2009-11-18 08:00:14 +0100837 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100838
Takashi Iwai47fd8302007-08-10 17:11:07 +0200839 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
840 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
841 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100842}
843
844/* unsolicited event for HP jack sensing */
845static void cxt5045_hp_unsol_event(struct hda_codec *codec,
846 unsigned int res)
847{
848 res >>= 26;
849 switch (res) {
850 case CONEXANT_HP_EVENT:
851 cxt5045_hp_automute(codec);
852 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100853 case CONEXANT_MIC_EVENT:
854 cxt5045_hp_automic(codec);
855 break;
856
Tobin Davisc9b443d2006-11-14 12:13:39 +0100857 }
858}
859
860static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200861 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
862 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
863 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
864 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
865 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
866 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
867 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
868 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
869 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
870 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200871 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100872 {
873 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
874 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100875 .info = cxt_eapd_info,
876 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100877 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100878 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100879 },
880
881 {}
882};
883
Jiang Zhe5218c892008-01-17 11:18:41 +0100884static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200885 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
886 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
887 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
888 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
889
Jiang Zhe5218c892008-01-17 11:18:41 +0100890 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
891 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
892 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
893 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
894
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200895 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
896 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
897
Jiang Zhe5218c892008-01-17 11:18:41 +0100898 {}
899};
900
Jiang zhe2de3c232008-03-06 11:09:09 +0100901static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100902 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
903 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
904 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
905 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
906 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
907 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
908 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
909 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
910 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
911 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
912 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
913 {
914 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
915 .name = "Master Playback Switch",
916 .info = cxt_eapd_info,
917 .get = cxt_eapd_get,
918 .put = cxt5045_hp_master_sw_put,
919 .private_value = 0x10,
920 },
921
922 {}
923};
924
Tobin Davisc9b443d2006-11-14 12:13:39 +0100925static struct hda_verb cxt5045_init_verbs[] = {
926 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200927 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100928 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100929 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200930 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
931 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
932 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
933 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
934 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
936 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
937 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
938 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100939 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100940 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100941 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100942 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
943 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100944 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100945 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100946 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100947 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100948 { } /* end */
949};
950
Jiang Zhe5218c892008-01-17 11:18:41 +0100951static struct hda_verb cxt5045_benq_init_verbs[] = {
952 /* Int Mic, Mic */
953 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
954 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
955 /* Line In,HP, Amp */
956 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
957 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
958 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
959 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
960 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
965 /* Record selector: Int mic */
966 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
967 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
968 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
969 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100970 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100971 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
972 /* EAPD */
973 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
974 { } /* end */
975};
Tobin Davis7f296732007-03-12 11:39:01 +0100976
977static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
978 /* pin sensing on HP jack */
979 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200980 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100981};
982
983static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
984 /* pin sensing on HP jack */
985 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200986 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100987};
988
Tobin Davisc9b443d2006-11-14 12:13:39 +0100989#ifdef CONFIG_SND_DEBUG
990/* Test configuration for debugging, modelled after the ALC260 test
991 * configuration.
992 */
993static struct hda_input_mux cxt5045_test_capture_source = {
994 .num_items = 5,
995 .items = {
996 { "MIXER", 0x0 },
997 { "MIC1 pin", 0x1 },
998 { "LINE1 pin", 0x2 },
999 { "HP-OUT pin", 0x3 },
1000 { "CD pin", 0x4 },
1001 },
1002};
1003
1004static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1005
1006 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001007 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1008 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +01001009 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1010 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1011 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1012 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001013
1014 /* Modes for retasking pin widgets */
1015 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1016 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1017
Tobin Davis82f30042007-02-13 12:45:44 +01001018 /* EAPD Switch Control */
1019 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1020
Tobin Davisc9b443d2006-11-14 12:13:39 +01001021 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001022
Tobin Davis7f296732007-03-12 11:39:01 +01001023 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1024 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1025 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1026 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1027 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1028 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1029 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1030 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1031 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1032 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001033 {
1034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1035 .name = "Input Source",
1036 .info = conexant_mux_enum_info,
1037 .get = conexant_mux_enum_get,
1038 .put = conexant_mux_enum_put,
1039 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001040 /* Audio input controls */
1041 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1042 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1043 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1044 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1045 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1046 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1047 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1048 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1049 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1050 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001051 { } /* end */
1052};
1053
1054static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001055 /* Set connections */
1056 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1057 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1058 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001059 /* Enable retasking pins as output, initially without power amp */
1060 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001061 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001062
1063 /* Disable digital (SPDIF) pins initially, but users can enable
1064 * them via a mixer switch. In the case of SPDIF-out, this initverb
1065 * payload also sets the generation to 0, output to be in "consumer"
1066 * PCM format, copyright asserted, no pre-emphasis and no validity
1067 * control.
1068 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001069 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1070 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001071
1072 /* Start with output sum widgets muted and their output gains at min */
1073 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1074 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1075
1076 /* Unmute retasking pin widget output buffers since the default
1077 * state appears to be output. As the pin mode is changed by the
1078 * user the pin mode control will take care of enabling the pin's
1079 * input/output buffers as needed.
1080 */
1081 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1082 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1083
1084 /* Mute capture amp left and right */
1085 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1086
1087 /* Set ADC connection select to match default mixer setting (mic1
1088 * pin)
1089 */
1090 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001091 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001092
1093 /* Mute all inputs to mixer widget (even unconnected ones) */
1094 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1095 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1096 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1097 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1098 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1099
1100 { }
1101};
1102#endif
1103
1104
1105/* initialize jack-sensing, too */
1106static int cxt5045_init(struct hda_codec *codec)
1107{
1108 conexant_init(codec);
1109 cxt5045_hp_automute(codec);
1110 return 0;
1111}
1112
1113
1114enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001115 CXT5045_LAPTOP_HPSENSE,
1116 CXT5045_LAPTOP_MICSENSE,
1117 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001118 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001119 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001120#ifdef CONFIG_SND_DEBUG
1121 CXT5045_TEST,
1122#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001123 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001124};
1125
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001126static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001127 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1128 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1129 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1130 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001131 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001132#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001133 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001134#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001135};
1136
1137static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001138 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001139 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1140 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001141 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001142 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001143 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1144 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001145 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1146 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001147 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1148 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1149 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001150 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1151 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001152 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001153 {}
1154};
1155
1156static int patch_cxt5045(struct hda_codec *codec)
1157{
1158 struct conexant_spec *spec;
1159 int board_config;
1160
1161 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1162 if (!spec)
1163 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001164 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001165 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001166
1167 spec->multiout.max_channels = 2;
1168 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1169 spec->multiout.dac_nids = cxt5045_dac_nids;
1170 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1171 spec->num_adc_nids = 1;
1172 spec->adc_nids = cxt5045_adc_nids;
1173 spec->capsrc_nids = cxt5045_capsrc_nids;
1174 spec->input_mux = &cxt5045_capture_source;
1175 spec->num_mixers = 1;
1176 spec->mixers[0] = cxt5045_mixers;
1177 spec->num_init_verbs = 1;
1178 spec->init_verbs[0] = cxt5045_init_verbs;
1179 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001180 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1181 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001182
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001183 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001184
1185 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001186
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001187 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1188 cxt5045_models,
1189 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001190 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001191 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001192 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001193 spec->input_mux = &cxt5045_capture_source;
1194 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001195 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1196 spec->mixers[0] = cxt5045_mixers;
1197 codec->patch_ops.init = cxt5045_init;
1198 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001199 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001200 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001201 spec->input_mux = &cxt5045_capture_source;
1202 spec->num_init_verbs = 2;
1203 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001204 spec->mixers[0] = cxt5045_mixers;
1205 codec->patch_ops.init = cxt5045_init;
1206 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001207 default:
1208 case CXT5045_LAPTOP_HPMICSENSE:
1209 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1210 spec->input_mux = &cxt5045_capture_source;
1211 spec->num_init_verbs = 3;
1212 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1213 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1214 spec->mixers[0] = cxt5045_mixers;
1215 codec->patch_ops.init = cxt5045_init;
1216 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001217 case CXT5045_BENQ:
1218 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1219 spec->input_mux = &cxt5045_capture_source_benq;
1220 spec->num_init_verbs = 1;
1221 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1222 spec->mixers[0] = cxt5045_mixers;
1223 spec->mixers[1] = cxt5045_benq_mixers;
1224 spec->num_mixers = 2;
1225 codec->patch_ops.init = cxt5045_init;
1226 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001227 case CXT5045_LAPTOP_HP530:
1228 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1229 spec->input_mux = &cxt5045_capture_source_hp530;
1230 spec->num_init_verbs = 2;
1231 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1232 spec->mixers[0] = cxt5045_mixers_hp530;
1233 codec->patch_ops.init = cxt5045_init;
1234 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001235#ifdef CONFIG_SND_DEBUG
1236 case CXT5045_TEST:
1237 spec->input_mux = &cxt5045_test_capture_source;
1238 spec->mixers[0] = cxt5045_test_mixer;
1239 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001240 break;
1241
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242#endif
1243 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001244
Takashi Iwai031005f2008-06-26 14:49:58 +02001245 switch (codec->subsystem_id >> 16) {
1246 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001247 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001248 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001249 case 0x17aa:
1250 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1251 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1252 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001253 */
1254 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1255 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1256 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1257 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1258 (1 << AC_AMPCAP_MUTE_SHIFT));
1259 break;
1260 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001261
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001262 if (spec->beep_amp)
1263 snd_hda_attach_beep_device(codec, spec->beep_amp);
1264
Tobin Davisc9b443d2006-11-14 12:13:39 +01001265 return 0;
1266}
1267
1268
1269/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001270#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001271
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001272static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001273static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1274static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001275
Tobin Davis5cd57522006-11-20 17:42:09 +01001276static struct hda_channel_mode cxt5047_modes[1] = {
1277 { 2, NULL },
1278};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001279
Tobin Davis82f30042007-02-13 12:45:44 +01001280static struct hda_input_mux cxt5047_toshiba_capture_source = {
1281 .num_items = 2,
1282 .items = {
1283 { "ExtMic", 0x2 },
1284 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 }
1286};
1287
1288/* turn on/off EAPD (+ mute HP) as a master switch */
1289static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1290 struct snd_ctl_elem_value *ucontrol)
1291{
1292 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1293 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001294 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001295
Tobin Davis82f30042007-02-13 12:45:44 +01001296 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001297 return 0;
1298
Tobin Davis82f30042007-02-13 12:45:44 +01001299 /* toggle internal speakers mute depending of presence of
1300 * the headphone jack
1301 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001302 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001303 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1304 * pin widgets unlike other codecs. In this case, we need to
1305 * set index 0x01 for the volume from the mixer amp 0x19.
1306 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001307 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001308 HDA_AMP_MUTE, bits);
1309 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1310 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1311 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001312 return 1;
1313}
1314
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315/* mute internal speaker if HP is plugged */
1316static void cxt5047_hp_automute(struct hda_codec *codec)
1317{
Tobin Davis82f30042007-02-13 12:45:44 +01001318 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001319 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001320
Takashi Iwaid56757a2009-11-18 08:00:14 +01001321 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001322
Takashi Iwai47fd8302007-08-10 17:11:07 +02001323 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001324 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001325 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001326 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001327}
1328
1329/* toggle input of built-in and mic jack appropriately */
1330static void cxt5047_hp_automic(struct hda_codec *codec)
1331{
1332 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001333 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1334 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001335 {}
1336 };
1337 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001338 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1339 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 {}
1341 };
1342 unsigned int present;
1343
Takashi Iwaid56757a2009-11-18 08:00:14 +01001344 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001345 if (present)
1346 snd_hda_sequence_write(codec, mic_jack_on);
1347 else
1348 snd_hda_sequence_write(codec, mic_jack_off);
1349}
1350
1351/* unsolicited event for HP jack sensing */
1352static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1353 unsigned int res)
1354{
Marc Boucher9f113e02008-01-22 15:18:08 +01001355 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001356 case CONEXANT_HP_EVENT:
1357 cxt5047_hp_automute(codec);
1358 break;
1359 case CONEXANT_MIC_EVENT:
1360 cxt5047_hp_automic(codec);
1361 break;
1362 }
1363}
1364
Takashi Iwaidf481e42009-03-10 15:35:35 +01001365static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1366 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1367 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1368 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001369 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1370 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1371 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1372 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001373 {
1374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1375 .name = "Master Playback Switch",
1376 .info = cxt_eapd_info,
1377 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001378 .put = cxt5047_hp_master_sw_put,
1379 .private_value = 0x13,
1380 },
1381
1382 {}
1383};
1384
Takashi Iwaidf481e42009-03-10 15:35:35 +01001385static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001386 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001387 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001388 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1389 {}
1390};
1391
1392static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001393 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001394 { } /* end */
1395};
1396
1397static struct hda_verb cxt5047_init_verbs[] = {
1398 /* Line in, Mic, Built-in Mic */
1399 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1400 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1401 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001402 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001403 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001404 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1405 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001406 /* Record selector: Mic */
1407 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1408 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1409 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1410 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001411 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1412 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1413 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1414 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001415 /* SPDIF route: PCM */
1416 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001417 /* Enable unsolicited events */
1418 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1419 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001420 { } /* end */
1421};
1422
1423/* configuration for Toshiba Laptops */
1424static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001425 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001426 {}
1427};
1428
1429/* Test configuration for debugging, modelled after the ALC260 test
1430 * configuration.
1431 */
1432#ifdef CONFIG_SND_DEBUG
1433static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001434 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001435 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001436 { "LINE1 pin", 0x0 },
1437 { "MIC1 pin", 0x1 },
1438 { "MIC2 pin", 0x2 },
1439 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001440 },
1441};
1442
1443static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1444
1445 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001446 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1447 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1448 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1449 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001450 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1451 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1452 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1453 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001454 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1455 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1456 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1457 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001458
1459 /* Modes for retasking pin widgets */
1460 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1461 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1462
Tobin Davis82f30042007-02-13 12:45:44 +01001463 /* EAPD Switch Control */
1464 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1465
Tobin Davisc9b443d2006-11-14 12:13:39 +01001466 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001467 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1468 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1469 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1470 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1471 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1472 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1473 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1474 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001475
Tobin Davis82f30042007-02-13 12:45:44 +01001476 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1477 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1478 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1479 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1480 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1481 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1482 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1483 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001484 {
1485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1486 .name = "Input Source",
1487 .info = conexant_mux_enum_info,
1488 .get = conexant_mux_enum_get,
1489 .put = conexant_mux_enum_put,
1490 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001491 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001492
Tobin Davisc9b443d2006-11-14 12:13:39 +01001493 { } /* end */
1494};
1495
1496static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001497 /* Enable retasking pins as output, initially without power amp */
1498 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1499 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1500 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501
1502 /* Disable digital (SPDIF) pins initially, but users can enable
1503 * them via a mixer switch. In the case of SPDIF-out, this initverb
1504 * payload also sets the generation to 0, output to be in "consumer"
1505 * PCM format, copyright asserted, no pre-emphasis and no validity
1506 * control.
1507 */
1508 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1509
1510 /* Ensure mic1, mic2, line1 pin widgets take input from the
1511 * OUT1 sum bus when acting as an output.
1512 */
1513 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1514 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1515
1516 /* Start with output sum widgets muted and their output gains at min */
1517 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1518 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1519
1520 /* Unmute retasking pin widget output buffers since the default
1521 * state appears to be output. As the pin mode is changed by the
1522 * user the pin mode control will take care of enabling the pin's
1523 * input/output buffers as needed.
1524 */
1525 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1526 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1527 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1528
1529 /* Mute capture amp left and right */
1530 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1531
1532 /* Set ADC connection select to match default mixer setting (mic1
1533 * pin)
1534 */
1535 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1536
1537 /* Mute all inputs to mixer widget (even unconnected ones) */
1538 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1539 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1540 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1541 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1543 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1544 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1545 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1546
1547 { }
1548};
1549#endif
1550
1551
1552/* initialize jack-sensing, too */
1553static int cxt5047_hp_init(struct hda_codec *codec)
1554{
1555 conexant_init(codec);
1556 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557 return 0;
1558}
1559
1560
1561enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001562 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1563 CXT5047_LAPTOP_HP, /* Some HP laptops */
1564 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565#ifdef CONFIG_SND_DEBUG
1566 CXT5047_TEST,
1567#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001568 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001569};
1570
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001571static const char *cxt5047_models[CXT5047_MODELS] = {
1572 [CXT5047_LAPTOP] = "laptop",
1573 [CXT5047_LAPTOP_HP] = "laptop-hp",
1574 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001575#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001576 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001577#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001578};
1579
1580static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001581 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001582 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1583 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001584 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001585 {}
1586};
1587
1588static int patch_cxt5047(struct hda_codec *codec)
1589{
1590 struct conexant_spec *spec;
1591 int board_config;
1592
1593 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1594 if (!spec)
1595 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001597 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001598
1599 spec->multiout.max_channels = 2;
1600 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1601 spec->multiout.dac_nids = cxt5047_dac_nids;
1602 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1603 spec->num_adc_nids = 1;
1604 spec->adc_nids = cxt5047_adc_nids;
1605 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001606 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001607 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001608 spec->num_init_verbs = 1;
1609 spec->init_verbs[0] = cxt5047_init_verbs;
1610 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001611 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1612 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001613
1614 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001615
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001616 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1617 cxt5047_models,
1618 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001619 switch (board_config) {
1620 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001621 spec->num_mixers = 2;
1622 spec->mixers[1] = cxt5047_hp_spk_mixers;
1623 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001624 break;
1625 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001626 spec->num_mixers = 2;
1627 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001628 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001629 codec->patch_ops.init = cxt5047_hp_init;
1630 break;
1631 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001632 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001633 spec->num_mixers = 2;
1634 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001635 spec->num_init_verbs = 2;
1636 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001637 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001638 break;
1639#ifdef CONFIG_SND_DEBUG
1640 case CXT5047_TEST:
1641 spec->input_mux = &cxt5047_test_capture_source;
1642 spec->mixers[0] = cxt5047_test_mixer;
1643 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001644 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001645#endif
1646 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001647 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001648
1649 switch (codec->subsystem_id >> 16) {
1650 case 0x103c:
1651 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1652 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1653 * with 0 dB offset 0x17)
1654 */
1655 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1656 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1657 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1658 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1659 (1 << AC_AMPCAP_MUTE_SHIFT));
1660 break;
1661 }
1662
Tobin Davisc9b443d2006-11-14 12:13:39 +01001663 return 0;
1664}
1665
Takashi Iwai461e2c72008-01-25 11:35:17 +01001666/* Conexant 5051 specific */
1667static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1668static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001669
1670static struct hda_channel_mode cxt5051_modes[1] = {
1671 { 2, NULL },
1672};
1673
1674static void cxt5051_update_speaker(struct hda_codec *codec)
1675{
1676 struct conexant_spec *spec = codec->spec;
1677 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001678 /* headphone pin */
1679 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1680 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1681 pinctl);
1682 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001683 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1684 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1685 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001686 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1687 if (spec->ideapad)
1688 snd_hda_codec_write(codec, 0x1b, 0,
1689 AC_VERB_SET_PIN_WIDGET_CONTROL,
1690 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001691}
1692
1693/* turn on/off EAPD (+ mute HP) as a master switch */
1694static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1695 struct snd_ctl_elem_value *ucontrol)
1696{
1697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1698
1699 if (!cxt_eapd_put(kcontrol, ucontrol))
1700 return 0;
1701 cxt5051_update_speaker(codec);
1702 return 1;
1703}
1704
1705/* toggle input of built-in and mic jack appropriately */
1706static void cxt5051_portb_automic(struct hda_codec *codec)
1707{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001708 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001709 unsigned int present;
1710
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001711 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001712 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001713 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001714 snd_hda_codec_write(codec, 0x14, 0,
1715 AC_VERB_SET_CONNECT_SEL,
1716 present ? 0x01 : 0x00);
1717}
1718
1719/* switch the current ADC according to the jack state */
1720static void cxt5051_portc_automic(struct hda_codec *codec)
1721{
1722 struct conexant_spec *spec = codec->spec;
1723 unsigned int present;
1724 hda_nid_t new_adc;
1725
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001726 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001727 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001728 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001729 if (present)
1730 spec->cur_adc_idx = 1;
1731 else
1732 spec->cur_adc_idx = 0;
1733 new_adc = spec->adc_nids[spec->cur_adc_idx];
1734 if (spec->cur_adc && spec->cur_adc != new_adc) {
1735 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001736 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001737 spec->cur_adc = new_adc;
1738 snd_hda_codec_setup_stream(codec, new_adc,
1739 spec->cur_adc_stream_tag, 0,
1740 spec->cur_adc_format);
1741 }
1742}
1743
1744/* mute internal speaker if HP is plugged */
1745static void cxt5051_hp_automute(struct hda_codec *codec)
1746{
1747 struct conexant_spec *spec = codec->spec;
1748
Takashi Iwaid56757a2009-11-18 08:00:14 +01001749 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001750 cxt5051_update_speaker(codec);
1751}
1752
1753/* unsolicited event for HP jack sensing */
1754static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1755 unsigned int res)
1756{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001757 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001758 switch (res >> 26) {
1759 case CONEXANT_HP_EVENT:
1760 cxt5051_hp_automute(codec);
1761 break;
1762 case CXT5051_PORTB_EVENT:
1763 cxt5051_portb_automic(codec);
1764 break;
1765 case CXT5051_PORTC_EVENT:
1766 cxt5051_portc_automic(codec);
1767 break;
1768 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001769 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001770}
1771
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001772static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001773 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1774 {
1775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1776 .name = "Master Playback Switch",
1777 .info = cxt_eapd_info,
1778 .get = cxt_eapd_get,
1779 .put = cxt5051_hp_master_sw_put,
1780 .private_value = 0x1a,
1781 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001782 {}
1783};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001784
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001785static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1786 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1787 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1789 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1790 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1791 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001792 {}
1793};
1794
1795static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1796 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1797 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1798 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1799 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001800 {}
1801};
1802
Takashi Iwai79d7d532009-03-04 09:03:50 +01001803static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001804 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1805 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001806 {}
1807};
1808
Ken Proxcd9d95a2010-01-08 09:01:47 +01001809static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001810 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1811 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001812 {}
1813};
1814
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001815static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1816 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1817 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1818 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1819 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001820 {}
1821};
1822
Takashi Iwai461e2c72008-01-25 11:35:17 +01001823static struct hda_verb cxt5051_init_verbs[] = {
1824 /* Line in, Mic */
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1828 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1830 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1831 /* SPK */
1832 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1833 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1834 /* HP, Amp */
1835 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1836 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1837 /* DAC1 */
1838 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1839 /* Record selector: Int mic */
1840 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1842 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1843 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001844 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001845 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1846 /* EAPD */
1847 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1848 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001849 { } /* end */
1850};
1851
Takashi Iwai79d7d532009-03-04 09:03:50 +01001852static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1853 /* Line in, Mic */
1854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1855 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1856 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1857 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1858 /* SPK */
1859 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1860 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1861 /* HP, Amp */
1862 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1863 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1864 /* DAC1 */
1865 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1866 /* Record selector: Int mic */
1867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1868 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1869 /* SPDIF route: PCM */
1870 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1871 /* EAPD */
1872 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1873 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001874 { } /* end */
1875};
1876
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001877static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1878 /* Line in, Mic */
1879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1880 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1881 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1882 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1883 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1884 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1885 /* SPK */
1886 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1887 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1888 /* HP, Amp */
1889 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1890 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1891 /* Docking HP */
1892 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1893 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1894 /* DAC1 */
1895 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1896 /* Record selector: Int mic */
1897 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1899 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1900 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001901 {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 -05001902 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1903 /* EAPD */
1904 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1905 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001906 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1907 { } /* end */
1908};
1909
Ken Proxcd9d95a2010-01-08 09:01:47 +01001910static struct hda_verb cxt5051_f700_init_verbs[] = {
1911 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001912 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001913 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1914 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1915 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1916 /* SPK */
1917 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1918 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1919 /* HP, Amp */
1920 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1921 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1922 /* DAC1 */
1923 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1924 /* Record selector: Int mic */
1925 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1926 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1927 /* SPDIF route: PCM */
1928 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1929 /* EAPD */
1930 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1931 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001932 { } /* end */
1933};
1934
Takashi Iwai6953e552010-01-24 11:00:27 +01001935static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1936 unsigned int event)
1937{
1938 snd_hda_codec_write(codec, nid, 0,
1939 AC_VERB_SET_UNSOLICITED_ENABLE,
1940 AC_USRSP_EN | event);
1941#ifdef CONFIG_SND_HDA_INPUT_JACK
1942 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1943 conexant_report_jack(codec, nid);
1944#endif
1945}
1946
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001947static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1948 /* Subwoofer */
1949 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1950 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1951 { } /* end */
1952};
1953
Takashi Iwai461e2c72008-01-25 11:35:17 +01001954/* initialize jack-sensing, too */
1955static int cxt5051_init(struct hda_codec *codec)
1956{
Takashi Iwai6953e552010-01-24 11:00:27 +01001957 struct conexant_spec *spec = codec->spec;
1958
Takashi Iwai461e2c72008-01-25 11:35:17 +01001959 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001960 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001961
1962 if (spec->auto_mic & AUTO_MIC_PORTB)
1963 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1964 if (spec->auto_mic & AUTO_MIC_PORTC)
1965 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1966
Takashi Iwai461e2c72008-01-25 11:35:17 +01001967 if (codec->patch_ops.unsol_event) {
1968 cxt5051_hp_automute(codec);
1969 cxt5051_portb_automic(codec);
1970 cxt5051_portc_automic(codec);
1971 }
1972 return 0;
1973}
1974
1975
1976enum {
1977 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1978 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001979 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001980 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001981 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001982 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001983 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001984 CXT5051_MODELS
1985};
1986
1987static const char *cxt5051_models[CXT5051_MODELS] = {
1988 [CXT5051_LAPTOP] = "laptop",
1989 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001990 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001991 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001992 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001993 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001994 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001995};
1996
1997static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001998 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001999 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01002000 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002001 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002002 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2003 CXT5051_LAPTOP),
2004 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002005 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002006 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01002007 {}
2008};
2009
2010static int patch_cxt5051(struct hda_codec *codec)
2011{
2012 struct conexant_spec *spec;
2013 int board_config;
2014
2015 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2016 if (!spec)
2017 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002018 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002019 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002020
2021 codec->patch_ops = conexant_patch_ops;
2022 codec->patch_ops.init = cxt5051_init;
2023
2024 spec->multiout.max_channels = 2;
2025 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2026 spec->multiout.dac_nids = cxt5051_dac_nids;
2027 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2028 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2029 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002030 spec->num_mixers = 2;
2031 spec->mixers[0] = cxt5051_capture_mixers;
2032 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002033 spec->num_init_verbs = 1;
2034 spec->init_verbs[0] = cxt5051_init_verbs;
2035 spec->spdif_route = 0;
2036 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2037 spec->channel_mode = cxt5051_modes;
2038 spec->cur_adc = 0;
2039 spec->cur_adc_idx = 0;
2040
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002041 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2042
Takashi Iwai79d7d532009-03-04 09:03:50 +01002043 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2044
Takashi Iwai461e2c72008-01-25 11:35:17 +01002045 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2046 cxt5051_models,
2047 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002048 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002049 switch (board_config) {
2050 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002051 spec->mixers[0] = cxt5051_hp_mixers;
2052 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002053 case CXT5051_HP_DV6736:
2054 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2055 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002056 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002057 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002058 case CXT5051_LENOVO_X200:
2059 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002060 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002061 case CXT5051_F700:
2062 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2063 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002064 spec->auto_mic = 0;
2065 break;
2066 case CXT5051_TOSHIBA:
2067 spec->mixers[0] = cxt5051_toshiba_mixers;
2068 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002069 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002070 case CXT5051_IDEAPAD:
2071 spec->init_verbs[spec->num_init_verbs++] =
2072 cxt5051_ideapad_init_verbs;
2073 spec->ideapad = 1;
2074 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002075 }
2076
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002077 if (spec->beep_amp)
2078 snd_hda_attach_beep_device(codec, spec->beep_amp);
2079
Takashi Iwai461e2c72008-01-25 11:35:17 +01002080 return 0;
2081}
2082
Daniel Drake0fb67e92009-07-16 14:46:57 +01002083/* Conexant 5066 specific */
2084
2085static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2086static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2087static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2088#define CXT5066_SPDIF_OUT 0x21
2089
Daniel Drakedbaccc02009-11-09 15:17:24 +00002090/* OLPC's microphone port is DC coupled for use with external sensors,
2091 * therefore we use a 50% mic bias in order to center the input signal with
2092 * the DC input range of the codec. */
2093#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2094
Daniel Drake0fb67e92009-07-16 14:46:57 +01002095static struct hda_channel_mode cxt5066_modes[1] = {
2096 { 2, NULL },
2097};
2098
2099static void cxt5066_update_speaker(struct hda_codec *codec)
2100{
2101 struct conexant_spec *spec = codec->spec;
2102 unsigned int pinctl;
2103
2104 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2105 spec->hp_present);
2106
2107 /* Port A (HP) */
2108 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2109 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2110 pinctl);
2111
2112 /* Port D (HP/LO) */
2113 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2114 ? spec->port_d_mode : 0;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002115 /* Mute if Port A is connected on Thinkpad */
2116 if (spec->thinkpad && (spec->hp_present & 1))
2117 pinctl = 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002118 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2119 pinctl);
2120
2121 /* CLASS_D AMP */
2122 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2123 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2124 pinctl);
2125
2126 if (spec->dell_automute) {
2127 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2128 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2129 ? PIN_OUT : 0;
2130 snd_hda_codec_write(codec, 0x1c, 0,
2131 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2132 }
2133}
2134
2135/* turn on/off EAPD (+ mute HP) as a master switch */
2136static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2137 struct snd_ctl_elem_value *ucontrol)
2138{
2139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2140
2141 if (!cxt_eapd_put(kcontrol, ucontrol))
2142 return 0;
2143
2144 cxt5066_update_speaker(codec);
2145 return 1;
2146}
2147
Daniel Drakec4cfe662010-01-07 13:47:04 +01002148static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2149 .num_items = 3,
2150 .items = {
2151 { "Off", PIN_IN },
2152 { "50%", PIN_VREF50 },
2153 { "80%", PIN_VREF80 },
2154 },
2155};
2156
2157static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2158{
2159 struct conexant_spec *spec = codec->spec;
2160 /* Even though port F is the DC input, the bias is controlled on port B.
2161 * we also leave that port as an active input (but unselected) in DC mode
2162 * just in case that is necessary to make the bias setting take effect. */
2163 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2164 AC_VERB_SET_PIN_WIDGET_CONTROL,
2165 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2166}
2167
Daniel Drake75f89912010-01-07 13:46:25 +01002168/* OLPC defers mic widget control until when capture is started because the
2169 * microphone LED comes on as soon as these settings are put in place. if we
2170 * did this before recording, it would give the false indication that recording
2171 * is happening when it is not. */
2172static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002173{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002174 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002175 if (!spec->recording)
2176 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002177
Daniel Drakec4cfe662010-01-07 13:47:04 +01002178 if (spec->dc_enable) {
2179 /* in DC mode we ignore presence detection and just use the jack
2180 * through our special DC port */
2181 const struct hda_verb enable_dc_mode[] = {
2182 /* disble internal mic, port C */
2183 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2184
2185 /* enable DC capture, port F */
2186 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2187 {},
2188 };
2189
2190 snd_hda_sequence_write(codec, enable_dc_mode);
2191 /* port B input disabled (and bias set) through the following call */
2192 cxt5066_set_olpc_dc_bias(codec);
2193 return;
2194 }
2195
2196 /* disable DC (port F) */
2197 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2198
Daniel Drake75f89912010-01-07 13:46:25 +01002199 /* external mic, port B */
2200 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2201 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002202
Daniel Drake75f89912010-01-07 13:46:25 +01002203 /* internal mic, port C */
2204 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2205 spec->ext_mic_present ? 0 : PIN_VREF80);
2206}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002207
Daniel Drake75f89912010-01-07 13:46:25 +01002208/* toggle input of built-in and mic jack appropriately */
2209static void cxt5066_olpc_automic(struct hda_codec *codec)
2210{
2211 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002212 unsigned int present;
2213
Daniel Drakec4cfe662010-01-07 13:47:04 +01002214 if (spec->dc_enable) /* don't do presence detection in DC mode */
2215 return;
2216
Daniel Drake75f89912010-01-07 13:46:25 +01002217 present = snd_hda_codec_read(codec, 0x1a, 0,
2218 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2219 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002220 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002221 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002222 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002223
2224 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2225 present ? 0 : 1);
2226 spec->ext_mic_present = !!present;
2227
2228 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002229}
2230
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002231/* toggle input of built-in digital mic and mic jack appropriately */
2232static void cxt5066_vostro_automic(struct hda_codec *codec)
2233{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002234 unsigned int present;
2235
2236 struct hda_verb ext_mic_present[] = {
2237 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002238 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002239
2240 /* switch to external mic input */
2241 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2242 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2243
2244 /* disable internal digital mic */
2245 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2246 {}
2247 };
2248 static struct hda_verb ext_mic_absent[] = {
2249 /* enable internal mic, port C */
2250 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2251
2252 /* switch to internal mic input */
2253 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2254
2255 /* disable external mic, port B */
2256 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2257 {}
2258 };
2259
2260 present = snd_hda_jack_detect(codec, 0x1a);
2261 if (present) {
2262 snd_printdd("CXT5066: external microphone detected\n");
2263 snd_hda_sequence_write(codec, ext_mic_present);
2264 } else {
2265 snd_printdd("CXT5066: external microphone absent\n");
2266 snd_hda_sequence_write(codec, ext_mic_absent);
2267 }
2268}
2269
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002270/* toggle input of built-in digital mic and mic jack appropriately */
2271static void cxt5066_ideapad_automic(struct hda_codec *codec)
2272{
2273 unsigned int present;
2274
2275 struct hda_verb ext_mic_present[] = {
2276 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2277 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2278 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2279 {}
2280 };
2281 static struct hda_verb ext_mic_absent[] = {
2282 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2283 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2284 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2285 {}
2286 };
2287
2288 present = snd_hda_jack_detect(codec, 0x1b);
2289 if (present) {
2290 snd_printdd("CXT5066: external microphone detected\n");
2291 snd_hda_sequence_write(codec, ext_mic_present);
2292 } else {
2293 snd_printdd("CXT5066: external microphone absent\n");
2294 snd_hda_sequence_write(codec, ext_mic_absent);
2295 }
2296}
2297
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002298/* toggle input of built-in digital mic and mic jack appropriately
2299 order is: external mic -> dock mic -> interal mic */
2300static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2301{
2302 unsigned int ext_present, dock_present;
2303
2304 static struct hda_verb ext_mic_present[] = {
2305 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2306 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2307 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2308 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2309 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2310 {}
2311 };
2312 static struct hda_verb dock_mic_present[] = {
2313 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2314 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2315 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2316 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2317 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2318 {}
2319 };
2320 static struct hda_verb ext_mic_absent[] = {
2321 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2322 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2323 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2324 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2325 {}
2326 };
2327
2328 ext_present = snd_hda_jack_detect(codec, 0x1b);
2329 dock_present = snd_hda_jack_detect(codec, 0x1a);
2330 if (ext_present) {
2331 snd_printdd("CXT5066: external microphone detected\n");
2332 snd_hda_sequence_write(codec, ext_mic_present);
2333 } else if (dock_present) {
2334 snd_printdd("CXT5066: dock microphone detected\n");
2335 snd_hda_sequence_write(codec, dock_mic_present);
2336 } else {
2337 snd_printdd("CXT5066: external microphone absent\n");
2338 snd_hda_sequence_write(codec, ext_mic_absent);
2339 }
2340}
2341
Daniel Drake0fb67e92009-07-16 14:46:57 +01002342/* mute internal speaker if HP is plugged */
2343static void cxt5066_hp_automute(struct hda_codec *codec)
2344{
2345 struct conexant_spec *spec = codec->spec;
2346 unsigned int portA, portD;
2347
2348 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002349 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002350
2351 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002352 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002353
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002354 spec->hp_present = !!(portA);
2355 spec->hp_present |= portD ? 2 : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002356 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2357 portA, portD, spec->hp_present);
2358 cxt5066_update_speaker(codec);
2359}
2360
2361/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002362static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002363{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002364 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002365 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2366 switch (res >> 26) {
2367 case CONEXANT_HP_EVENT:
2368 cxt5066_hp_automute(codec);
2369 break;
2370 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002371 /* ignore mic events in DC mode; we're always using the jack */
2372 if (!spec->dc_enable)
2373 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002374 break;
2375 }
2376}
2377
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002378/* unsolicited event for jack sensing */
2379static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2380{
2381 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2382 switch (res >> 26) {
2383 case CONEXANT_HP_EVENT:
2384 cxt5066_hp_automute(codec);
2385 break;
2386 case CONEXANT_MIC_EVENT:
2387 cxt5066_vostro_automic(codec);
2388 break;
2389 }
2390}
2391
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002392/* unsolicited event for jack sensing */
2393static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2394{
2395 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2396 switch (res >> 26) {
2397 case CONEXANT_HP_EVENT:
2398 cxt5066_hp_automute(codec);
2399 break;
2400 case CONEXANT_MIC_EVENT:
2401 cxt5066_ideapad_automic(codec);
2402 break;
2403 }
2404}
2405
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002406/* unsolicited event for jack sensing */
2407static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
2408{
2409 snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
2410 switch (res >> 26) {
2411 case CONEXANT_HP_EVENT:
2412 cxt5066_hp_automute(codec);
2413 break;
2414 case CONEXANT_MIC_EVENT:
2415 cxt5066_thinkpad_automic(codec);
2416 break;
2417 }
2418}
2419
Daniel Drake0fb67e92009-07-16 14:46:57 +01002420static const struct hda_input_mux cxt5066_analog_mic_boost = {
2421 .num_items = 5,
2422 .items = {
2423 { "0dB", 0 },
2424 { "10dB", 1 },
2425 { "20dB", 2 },
2426 { "30dB", 3 },
2427 { "40dB", 4 },
2428 },
2429};
2430
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002431static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002432{
2433 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002434 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002435 AC_VERB_SET_AMP_GAIN_MUTE,
2436 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2437 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002438 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002439 /* adjust the internal mic as well...it is not through 0x17 */
2440 snd_hda_codec_write_cache(codec, 0x23, 0,
2441 AC_VERB_SET_AMP_GAIN_MUTE,
2442 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2443 cxt5066_analog_mic_boost.
2444 items[spec->mic_boost].index);
2445 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002446}
2447
Daniel Drake0fb67e92009-07-16 14:46:57 +01002448static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2449 struct snd_ctl_elem_info *uinfo)
2450{
2451 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2452}
2453
2454static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2455 struct snd_ctl_elem_value *ucontrol)
2456{
2457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002458 struct conexant_spec *spec = codec->spec;
2459 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002460 return 0;
2461}
2462
2463static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2464 struct snd_ctl_elem_value *ucontrol)
2465{
2466 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002467 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002468 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2469 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002470 idx = ucontrol->value.enumerated.item[0];
2471 if (idx >= imux->num_items)
2472 idx = imux->num_items - 1;
2473
Daniel Drakec4cfe662010-01-07 13:47:04 +01002474 spec->mic_boost = idx;
2475 if (!spec->dc_enable)
2476 cxt5066_set_mic_boost(codec);
2477 return 1;
2478}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002479
Daniel Drakec4cfe662010-01-07 13:47:04 +01002480static void cxt5066_enable_dc(struct hda_codec *codec)
2481{
2482 const struct hda_verb enable_dc_mode[] = {
2483 /* disable gain */
2484 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485
2486 /* switch to DC input */
2487 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2488 {}
2489 };
2490
2491 /* configure as input source */
2492 snd_hda_sequence_write(codec, enable_dc_mode);
2493 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2494}
2495
2496static void cxt5066_disable_dc(struct hda_codec *codec)
2497{
2498 /* reconfigure input source */
2499 cxt5066_set_mic_boost(codec);
2500 /* automic also selects the right mic if we're recording */
2501 cxt5066_olpc_automic(codec);
2502}
2503
2504static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2505 struct snd_ctl_elem_value *ucontrol)
2506{
2507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2508 struct conexant_spec *spec = codec->spec;
2509 ucontrol->value.integer.value[0] = spec->dc_enable;
2510 return 0;
2511}
2512
2513static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2514 struct snd_ctl_elem_value *ucontrol)
2515{
2516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2517 struct conexant_spec *spec = codec->spec;
2518 int dc_enable = !!ucontrol->value.integer.value[0];
2519
2520 if (dc_enable == spec->dc_enable)
2521 return 0;
2522
2523 spec->dc_enable = dc_enable;
2524 if (dc_enable)
2525 cxt5066_enable_dc(codec);
2526 else
2527 cxt5066_disable_dc(codec);
2528
2529 return 1;
2530}
2531
2532static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2533 struct snd_ctl_elem_info *uinfo)
2534{
2535 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2536}
2537
2538static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2539 struct snd_ctl_elem_value *ucontrol)
2540{
2541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2542 struct conexant_spec *spec = codec->spec;
2543 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2544 return 0;
2545}
2546
2547static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2548 struct snd_ctl_elem_value *ucontrol)
2549{
2550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2551 struct conexant_spec *spec = codec->spec;
2552 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2553 unsigned int idx;
2554
2555 idx = ucontrol->value.enumerated.item[0];
2556 if (idx >= imux->num_items)
2557 idx = imux->num_items - 1;
2558
2559 spec->dc_input_bias = idx;
2560 if (spec->dc_enable)
2561 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002562 return 1;
2563}
2564
Daniel Drake75f89912010-01-07 13:46:25 +01002565static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2566{
2567 struct conexant_spec *spec = codec->spec;
2568 /* mark as recording and configure the microphone widget so that the
2569 * recording LED comes on. */
2570 spec->recording = 1;
2571 cxt5066_olpc_select_mic(codec);
2572}
2573
2574static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2575{
2576 struct conexant_spec *spec = codec->spec;
2577 const struct hda_verb disable_mics[] = {
2578 /* disable external mic, port B */
2579 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2580
2581 /* disble internal mic, port C */
2582 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002583
2584 /* disable DC capture, port F */
2585 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002586 {},
2587 };
2588
2589 snd_hda_sequence_write(codec, disable_mics);
2590 spec->recording = 0;
2591}
2592
Daniel Drake0fb67e92009-07-16 14:46:57 +01002593static struct hda_input_mux cxt5066_capture_source = {
2594 .num_items = 4,
2595 .items = {
2596 { "Mic B", 0 },
2597 { "Mic C", 1 },
2598 { "Mic E", 2 },
2599 { "Mic F", 3 },
2600 },
2601};
2602
2603static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2604 .ops = &snd_hda_bind_vol,
2605 .values = {
2606 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2607 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2608 0
2609 },
2610};
2611
2612static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2613 .ops = &snd_hda_bind_sw,
2614 .values = {
2615 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2616 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2617 0
2618 },
2619};
2620
2621static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2622 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2623 {}
2624};
2625
2626static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2627 {
2628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2629 .name = "Master Playback Volume",
2630 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2631 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2632 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002633 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002634 .info = snd_hda_mixer_amp_volume_info,
2635 .get = snd_hda_mixer_amp_volume_get,
2636 .put = snd_hda_mixer_amp_volume_put,
2637 .tlv = { .c = snd_hda_mixer_amp_tlv },
2638 /* offset by 28 volume steps to limit minimum gain to -46dB */
2639 .private_value =
2640 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2641 },
2642 {}
2643};
2644
Daniel Drakec4cfe662010-01-07 13:47:04 +01002645static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2646 {
2647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2648 .name = "DC Mode Enable Switch",
2649 .info = snd_ctl_boolean_mono_info,
2650 .get = cxt5066_olpc_dc_get,
2651 .put = cxt5066_olpc_dc_put,
2652 },
2653 {
2654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2655 .name = "DC Input Bias Enum",
2656 .info = cxt5066_olpc_dc_bias_enum_info,
2657 .get = cxt5066_olpc_dc_bias_enum_get,
2658 .put = cxt5066_olpc_dc_bias_enum_put,
2659 },
2660 {}
2661};
2662
Daniel Drake0fb67e92009-07-16 14:46:57 +01002663static struct snd_kcontrol_new cxt5066_mixers[] = {
2664 {
2665 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2666 .name = "Master Playback Switch",
2667 .info = cxt_eapd_info,
2668 .get = cxt_eapd_get,
2669 .put = cxt5066_hp_master_sw_put,
2670 .private_value = 0x1d,
2671 },
2672
2673 {
2674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002675 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002676 .info = cxt5066_mic_boost_mux_enum_info,
2677 .get = cxt5066_mic_boost_mux_enum_get,
2678 .put = cxt5066_mic_boost_mux_enum_put,
2679 },
2680
2681 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2682 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2683 {}
2684};
2685
Einar Rünkaru254bba62009-12-16 22:16:13 +02002686static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2687 {
2688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2689 .name = "Int Mic Boost Capture Enum",
2690 .info = cxt5066_mic_boost_mux_enum_info,
2691 .get = cxt5066_mic_boost_mux_enum_get,
2692 .put = cxt5066_mic_boost_mux_enum_put,
2693 .private_value = 0x23 | 0x100,
2694 },
2695 {}
2696};
2697
Daniel Drake0fb67e92009-07-16 14:46:57 +01002698static struct hda_verb cxt5066_init_verbs[] = {
2699 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2700 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2701 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2702 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2703
2704 /* Speakers */
2705 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2706 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2707
2708 /* HP, Amp */
2709 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2710 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2711
2712 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2713 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2714
2715 /* DAC1 */
2716 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2717
2718 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2723 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2724
2725 /* no digital microphone support yet */
2726 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727
2728 /* Audio input selector */
2729 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2730
2731 /* SPDIF route: PCM */
2732 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2733 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2734
2735 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2736 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2737
2738 /* EAPD */
2739 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2740
2741 /* not handling these yet */
2742 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2745 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2746 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2747 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2748 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2749 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2750 { } /* end */
2751};
2752
2753static struct hda_verb cxt5066_init_verbs_olpc[] = {
2754 /* Port A: headphones */
2755 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2756 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2757
2758 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002759 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002760
2761 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002762 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002763
2764 /* Port D: unused */
2765 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2766
2767 /* Port E: unused, but has primary EAPD */
2768 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2769 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2770
Daniel Drakec4cfe662010-01-07 13:47:04 +01002771 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002772 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2773
2774 /* Port G: internal speakers */
2775 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2776 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2777
2778 /* DAC1 */
2779 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2780
2781 /* DAC2: unused */
2782 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2783
2784 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2785 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2789 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2791 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2792 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2793 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2794 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2795 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2796
2797 /* Disable digital microphone port */
2798 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2799
2800 /* Audio input selectors */
2801 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2802 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2803
2804 /* Disable SPDIF */
2805 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2806 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2807
2808 /* enable unsolicited events for Port A and B */
2809 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2810 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2811 { } /* end */
2812};
2813
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002814static struct hda_verb cxt5066_init_verbs_vostro[] = {
2815 /* Port A: headphones */
2816 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2817 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2818
2819 /* Port B: external microphone */
2820 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821
2822 /* Port C: unused */
2823 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824
2825 /* Port D: unused */
2826 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2827
2828 /* Port E: unused, but has primary EAPD */
2829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2830 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2831
2832 /* Port F: unused */
2833 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2834
2835 /* Port G: internal speakers */
2836 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2837 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2838
2839 /* DAC1 */
2840 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2841
2842 /* DAC2: unused */
2843 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2844
2845 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2847 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2848 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2849 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2853 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2854 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2855 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2856 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2857
2858 /* Digital microphone port */
2859 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2860
2861 /* Audio input selectors */
2862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2863 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2864
2865 /* Disable SPDIF */
2866 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2867 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2868
2869 /* enable unsolicited events for Port A and B */
2870 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2871 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2872 { } /* end */
2873};
2874
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002875static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2876 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2877 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2878 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2879 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2880
2881 /* Speakers */
2882 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2883 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2884
2885 /* HP, Amp */
2886 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2887 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2888
2889 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2890 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2891
2892 /* DAC1 */
2893 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2894
2895 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2897 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2899 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2900 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2901 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2902
2903 /* Audio input selector */
2904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2905 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2906
2907 /* SPDIF route: PCM */
2908 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2909 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2910
2911 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2912 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2913
2914 /* internal microphone */
2915 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2916
2917 /* EAPD */
2918 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2919
2920 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2921 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2922 { } /* end */
2923};
2924
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002925static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2926 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2927 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2928
2929 /* Port G: internal speakers */
2930 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2931 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2932
2933 /* Port A: HP, Amp */
2934 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2935 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2936
2937 /* Port B: Mic Dock */
2938 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2939
2940 /* Port C: Mic */
2941 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2942
2943 /* Port D: HP Dock, Amp */
2944 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2945 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2946
2947 /* DAC1 */
2948 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2949
2950 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2952 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2953 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2954 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2955 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2956 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2957
2958 /* Audio input selector */
2959 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2960 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2961
2962 /* SPDIF route: PCM */
2963 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2964 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2965
2966 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2967 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2968
2969 /* internal microphone */
2970 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2971
2972 /* EAPD */
2973 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2974
2975 /* enable unsolicited events for Port A, B, C and D */
2976 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2977 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2978 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2979 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2980 { } /* end */
2981};
2982
Daniel Drake0fb67e92009-07-16 14:46:57 +01002983static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2984 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2985 { } /* end */
2986};
2987
2988/* initialize jack-sensing, too */
2989static int cxt5066_init(struct hda_codec *codec)
2990{
Einar Rünkaru254bba62009-12-16 22:16:13 +02002991 struct conexant_spec *spec = codec->spec;
2992
Daniel Drake0fb67e92009-07-16 14:46:57 +01002993 snd_printdd("CXT5066: init\n");
2994 conexant_init(codec);
2995 if (codec->patch_ops.unsol_event) {
2996 cxt5066_hp_automute(codec);
Einar Rünkaru254bba62009-12-16 22:16:13 +02002997 if (spec->dell_vostro)
2998 cxt5066_vostro_automic(codec);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002999 else if (spec->ideapad)
3000 cxt5066_ideapad_automic(codec);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003001 else if (spec->thinkpad)
3002 cxt5066_thinkpad_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003003 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01003004 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01003005 return 0;
3006}
3007
Daniel Drake75f89912010-01-07 13:46:25 +01003008static int cxt5066_olpc_init(struct hda_codec *codec)
3009{
Daniel Drakec4cfe662010-01-07 13:47:04 +01003010 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01003011 snd_printdd("CXT5066: init\n");
3012 conexant_init(codec);
3013 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003014 if (!spec->dc_enable) {
3015 cxt5066_set_mic_boost(codec);
3016 cxt5066_olpc_automic(codec);
3017 } else {
3018 cxt5066_enable_dc(codec);
3019 }
Daniel Drake75f89912010-01-07 13:46:25 +01003020 return 0;
3021}
3022
Daniel Drake0fb67e92009-07-16 14:46:57 +01003023enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003024 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003025 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3026 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003027 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003028 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003029 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003030 CXT5066_MODELS
3031};
3032
3033static const char *cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003034 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003035 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3036 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003037 [CXT5066_DELL_VOSTO] = "dell-vostro",
3038 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003039 [CXT5066_THINKPAD] = "thinkpad",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003040};
3041
3042static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3043 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3044 CXT5066_LAPTOP),
3045 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
3046 CXT5066_DELL_LAPTOP),
Daniel Drake798a8a12009-11-04 10:11:07 +00003047 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003048 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003049 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003050 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003051 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
Andrej Gelenberg0217f142010-05-09 22:10:41 +02003052 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
Andreas Herrmannbadf18b2010-05-28 09:57:12 +02003053 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
Jerone Younga39e33e2010-05-26 10:06:01 -05003054 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
Jerone Youngab854572010-07-19 08:30:58 -05003055 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3056 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD),
3057 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD),
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003058 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003059 {}
3060};
3061
3062static int patch_cxt5066(struct hda_codec *codec)
3063{
3064 struct conexant_spec *spec;
3065 int board_config;
3066
3067 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3068 if (!spec)
3069 return -ENOMEM;
3070 codec->spec = spec;
3071
3072 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003073 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003074
3075 spec->dell_automute = 0;
3076 spec->multiout.max_channels = 2;
3077 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3078 spec->multiout.dac_nids = cxt5066_dac_nids;
3079 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
3080 spec->num_adc_nids = 1;
3081 spec->adc_nids = cxt5066_adc_nids;
3082 spec->capsrc_nids = cxt5066_capsrc_nids;
3083 spec->input_mux = &cxt5066_capture_source;
3084
3085 spec->port_d_mode = PIN_HP;
3086
3087 spec->num_init_verbs = 1;
3088 spec->init_verbs[0] = cxt5066_init_verbs;
3089 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3090 spec->channel_mode = cxt5066_modes;
3091 spec->cur_adc = 0;
3092 spec->cur_adc_idx = 0;
3093
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003094 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3095
Daniel Drake0fb67e92009-07-16 14:46:57 +01003096 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3097 cxt5066_models, cxt5066_cfg_tbl);
3098 switch (board_config) {
3099 default:
3100 case CXT5066_LAPTOP:
3101 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3102 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3103 break;
3104 case CXT5066_DELL_LAPTOP:
3105 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3106 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3107
3108 spec->port_d_mode = PIN_OUT;
3109 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3110 spec->num_init_verbs++;
3111 spec->dell_automute = 1;
3112 break;
3113 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003114 codec->patch_ops.init = cxt5066_olpc_init;
3115 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003116 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3117 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003118 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003119 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3120 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003121 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003122
3123 /* no S/PDIF out */
3124 spec->multiout.dig_out_nid = 0;
3125
3126 /* input source automatically selected */
3127 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003128
3129 /* our capture hooks which allow us to turn on the microphone LED
3130 * at the right time */
3131 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3132 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003133 break;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003134 case CXT5066_DELL_VOSTO:
Daniel Drake75f89912010-01-07 13:46:25 +01003135 codec->patch_ops.init = cxt5066_init;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003136 codec->patch_ops.unsol_event = cxt5066_vostro_event;
3137 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3138 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3139 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003140 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003141 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003142 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003143 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003144
3145 /* no S/PDIF out */
3146 spec->multiout.dig_out_nid = 0;
3147
3148 /* input source automatically selected */
3149 spec->input_mux = NULL;
3150 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003151 case CXT5066_IDEAPAD:
3152 codec->patch_ops.init = cxt5066_init;
3153 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3154 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3155 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3156 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3157 spec->port_d_mode = 0;
3158 spec->ideapad = 1;
3159 spec->mic_boost = 2; /* default 20dB gain */
3160
3161 /* no S/PDIF out */
3162 spec->multiout.dig_out_nid = 0;
3163
3164 /* input source automatically selected */
3165 spec->input_mux = NULL;
3166 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003167 case CXT5066_THINKPAD:
3168 codec->patch_ops.init = cxt5066_init;
3169 codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
3170 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3171 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3172 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3173 spec->thinkpad = 1;
3174 spec->port_d_mode = PIN_OUT;
3175 spec->mic_boost = 2; /* default 20dB gain */
3176
3177 /* no S/PDIF out */
3178 spec->multiout.dig_out_nid = 0;
3179
3180 /* input source automatically selected */
3181 spec->input_mux = NULL;
3182 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003183 }
3184
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003185 if (spec->beep_amp)
3186 snd_hda_attach_beep_device(codec, spec->beep_amp);
3187
Daniel Drake0fb67e92009-07-16 14:46:57 +01003188 return 0;
3189}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003190
3191/*
3192 */
3193
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003194static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003195 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3196 .patch = patch_cxt5045 },
3197 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3198 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003199 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3200 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003201 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3202 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003203 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3204 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003205 { .id = 0x14f15069, .name = "CX20585",
3206 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003207 {} /* terminator */
3208};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003209
3210MODULE_ALIAS("snd-hda-codec-id:14f15045");
3211MODULE_ALIAS("snd-hda-codec-id:14f15047");
3212MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003213MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003214MODULE_ALIAS("snd-hda-codec-id:14f15067");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003215MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003216
3217MODULE_LICENSE("GPL");
3218MODULE_DESCRIPTION("Conexant HD-audio codec");
3219
3220static struct hda_codec_preset_list conexant_list = {
3221 .preset = snd_hda_preset_conexant,
3222 .owner = THIS_MODULE,
3223};
3224
3225static int __init patch_conexant_init(void)
3226{
3227 return snd_hda_add_codec_preset(&conexant_list);
3228}
3229
3230static void __exit patch_conexant_exit(void)
3231{
3232 snd_hda_delete_codec_preset(&conexant_list);
3233}
3234
3235module_init(patch_conexant_init)
3236module_exit(patch_conexant_exit)