blob: 3b789ee548b4924ecda48758be47ab5ccbc32cf9 [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
614static struct hda_codec_ops conexant_patch_ops = {
615 .build_controls = conexant_build_controls,
616 .build_pcms = conexant_build_pcms,
617 .init = conexant_init,
618 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100619};
620
Takashi Iwai3507e2a2010-07-08 18:39:00 +0200621#ifdef CONFIG_SND_HDA_INPUT_BEEP
622#define set_beep_amp(spec, nid, idx, dir) \
623 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
624#else
625#define set_beep_amp(spec, nid, idx, dir) /* NOP */
626#endif
627
Tobin Davisc9b443d2006-11-14 12:13:39 +0100628/*
629 * EAPD control
630 * the private value = nid | (invert << 8)
631 */
632
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200633#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100634
Tobin Davis82f30042007-02-13 12:45:44 +0100635static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100636 struct snd_ctl_elem_value *ucontrol)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct conexant_spec *spec = codec->spec;
640 int invert = (kcontrol->private_value >> 8) & 1;
641 if (invert)
642 ucontrol->value.integer.value[0] = !spec->cur_eapd;
643 else
644 ucontrol->value.integer.value[0] = spec->cur_eapd;
645 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100646
Tobin Davisc9b443d2006-11-14 12:13:39 +0100647}
648
Tobin Davis82f30042007-02-13 12:45:44 +0100649static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100650 struct snd_ctl_elem_value *ucontrol)
651{
652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
653 struct conexant_spec *spec = codec->spec;
654 int invert = (kcontrol->private_value >> 8) & 1;
655 hda_nid_t nid = kcontrol->private_value & 0xff;
656 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100657
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100658 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100659 if (invert)
660 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200661 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100662 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100663
Tobin Davisc9b443d2006-11-14 12:13:39 +0100664 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200665 snd_hda_codec_write_cache(codec, nid,
666 0, AC_VERB_SET_EAPD_BTLENABLE,
667 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100668 return 1;
669}
670
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100671/* controls for test mode */
672#ifdef CONFIG_SND_DEBUG
673
Tobin Davis82f30042007-02-13 12:45:44 +0100674#define CXT_EAPD_SWITCH(xname, nid, mask) \
675 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
676 .info = cxt_eapd_info, \
677 .get = cxt_eapd_get, \
678 .put = cxt_eapd_put, \
679 .private_value = nid | (mask<<16) }
680
681
682
Tobin Davisc9b443d2006-11-14 12:13:39 +0100683static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
684 struct snd_ctl_elem_info *uinfo)
685{
686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
687 struct conexant_spec *spec = codec->spec;
688 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
689 spec->num_channel_mode);
690}
691
692static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
693 struct snd_ctl_elem_value *ucontrol)
694{
695 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
696 struct conexant_spec *spec = codec->spec;
697 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
698 spec->num_channel_mode,
699 spec->multiout.max_channels);
700}
701
702static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
704{
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706 struct conexant_spec *spec = codec->spec;
707 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
708 spec->num_channel_mode,
709 &spec->multiout.max_channels);
710 if (err >= 0 && spec->need_dac_fix)
711 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
712 return err;
713}
714
715#define CXT_PIN_MODE(xname, nid, dir) \
716 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
717 .info = conexant_ch_mode_info, \
718 .get = conexant_ch_mode_get, \
719 .put = conexant_ch_mode_put, \
720 .private_value = nid | (dir<<16) }
721
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100722#endif /* CONFIG_SND_DEBUG */
723
Tobin Davisc9b443d2006-11-14 12:13:39 +0100724/* Conexant 5045 specific */
725
726static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
727static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
728static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100729#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100730
Tobin Davis5cd57522006-11-20 17:42:09 +0100731static struct hda_channel_mode cxt5045_modes[1] = {
732 { 2, NULL },
733};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734
735static struct hda_input_mux cxt5045_capture_source = {
736 .num_items = 2,
737 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100738 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100739 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100740 }
741};
742
Jiang Zhe5218c892008-01-17 11:18:41 +0100743static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200744 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100745 .items = {
746 { "IntMic", 0x1 },
747 { "ExtMic", 0x2 },
748 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200749 { "CD", 0x4 },
750 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100751 }
752};
753
Jiang zhe2de3c232008-03-06 11:09:09 +0100754static struct hda_input_mux cxt5045_capture_source_hp530 = {
755 .num_items = 2,
756 .items = {
757 { "ExtMic", 0x1 },
758 { "IntMic", 0x2 },
759 }
760};
761
Tobin Davisc9b443d2006-11-14 12:13:39 +0100762/* turn on/off EAPD (+ mute HP) as a master switch */
763static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
764 struct snd_ctl_elem_value *ucontrol)
765{
766 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
767 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100768 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100769
Tobin Davis82f30042007-02-13 12:45:44 +0100770 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100771 return 0;
772
Tobin Davis82f30042007-02-13 12:45:44 +0100773 /* toggle internal speakers mute depending of presence of
774 * the headphone jack
775 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200776 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
777 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
778 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100779
Takashi Iwai47fd8302007-08-10 17:11:07 +0200780 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
781 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
782 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783 return 1;
784}
785
786/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200787static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
788 .ops = &snd_hda_bind_vol,
789 .values = {
790 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
791 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
792 0
793 },
794};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795
Tobin Davis7f296732007-03-12 11:39:01 +0100796/* toggle input of built-in and mic jack appropriately */
797static void cxt5045_hp_automic(struct hda_codec *codec)
798{
799 static struct hda_verb mic_jack_on[] = {
800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
801 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
802 {}
803 };
804 static struct hda_verb mic_jack_off[] = {
805 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
807 {}
808 };
809 unsigned int present;
810
Takashi Iwaid56757a2009-11-18 08:00:14 +0100811 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100812 if (present)
813 snd_hda_sequence_write(codec, mic_jack_on);
814 else
815 snd_hda_sequence_write(codec, mic_jack_off);
816}
817
Tobin Davisc9b443d2006-11-14 12:13:39 +0100818
819/* mute internal speaker if HP is plugged */
820static void cxt5045_hp_automute(struct hda_codec *codec)
821{
Tobin Davis82f30042007-02-13 12:45:44 +0100822 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100823 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100824
Takashi Iwaid56757a2009-11-18 08:00:14 +0100825 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100826
Takashi Iwai47fd8302007-08-10 17:11:07 +0200827 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
828 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
829 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830}
831
832/* unsolicited event for HP jack sensing */
833static void cxt5045_hp_unsol_event(struct hda_codec *codec,
834 unsigned int res)
835{
836 res >>= 26;
837 switch (res) {
838 case CONEXANT_HP_EVENT:
839 cxt5045_hp_automute(codec);
840 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100841 case CONEXANT_MIC_EVENT:
842 cxt5045_hp_automic(codec);
843 break;
844
Tobin Davisc9b443d2006-11-14 12:13:39 +0100845 }
846}
847
848static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200849 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
850 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
851 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
852 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
853 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
854 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
855 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
856 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
857 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
858 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200859 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100860 {
861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
862 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100863 .info = cxt_eapd_info,
864 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100865 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100866 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100867 },
868
869 {}
870};
871
Jiang Zhe5218c892008-01-17 11:18:41 +0100872static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200873 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
874 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
875 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
876 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
877
Jiang Zhe5218c892008-01-17 11:18:41 +0100878 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
879 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
880 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
881 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
882
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200883 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
884 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
885
Jiang Zhe5218c892008-01-17 11:18:41 +0100886 {}
887};
888
Jiang zhe2de3c232008-03-06 11:09:09 +0100889static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100890 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
891 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
892 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
893 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
894 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
895 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
896 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
897 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
898 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
899 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
900 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
901 {
902 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
903 .name = "Master Playback Switch",
904 .info = cxt_eapd_info,
905 .get = cxt_eapd_get,
906 .put = cxt5045_hp_master_sw_put,
907 .private_value = 0x10,
908 },
909
910 {}
911};
912
Tobin Davisc9b443d2006-11-14 12:13:39 +0100913static struct hda_verb cxt5045_init_verbs[] = {
914 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200915 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100916 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100917 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200918 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
919 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
920 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
921 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
922 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
923 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
924 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
925 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
926 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100927 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100928 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100929 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100930 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
931 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100932 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100933 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100934 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100935 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100936 { } /* end */
937};
938
Jiang Zhe5218c892008-01-17 11:18:41 +0100939static struct hda_verb cxt5045_benq_init_verbs[] = {
940 /* Int Mic, Mic */
941 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
942 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
943 /* Line In,HP, Amp */
944 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
945 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
946 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
947 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
948 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
950 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
951 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
952 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
953 /* Record selector: Int mic */
954 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
955 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
956 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
957 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100958 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100959 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
960 /* EAPD */
961 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
962 { } /* end */
963};
Tobin Davis7f296732007-03-12 11:39:01 +0100964
965static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
966 /* pin sensing on HP jack */
967 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200968 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100969};
970
971static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
972 /* pin sensing on HP jack */
973 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200974 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100975};
976
Tobin Davisc9b443d2006-11-14 12:13:39 +0100977#ifdef CONFIG_SND_DEBUG
978/* Test configuration for debugging, modelled after the ALC260 test
979 * configuration.
980 */
981static struct hda_input_mux cxt5045_test_capture_source = {
982 .num_items = 5,
983 .items = {
984 { "MIXER", 0x0 },
985 { "MIC1 pin", 0x1 },
986 { "LINE1 pin", 0x2 },
987 { "HP-OUT pin", 0x3 },
988 { "CD pin", 0x4 },
989 },
990};
991
992static struct snd_kcontrol_new cxt5045_test_mixer[] = {
993
994 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100995 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
996 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100997 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
998 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
999 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1000 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001001
1002 /* Modes for retasking pin widgets */
1003 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1004 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1005
Tobin Davis82f30042007-02-13 12:45:44 +01001006 /* EAPD Switch Control */
1007 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1008
Tobin Davisc9b443d2006-11-14 12:13:39 +01001009 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001010
Tobin Davis7f296732007-03-12 11:39:01 +01001011 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1012 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1013 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1014 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1015 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1016 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1017 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1018 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1019 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1020 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001021 {
1022 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1023 .name = "Input Source",
1024 .info = conexant_mux_enum_info,
1025 .get = conexant_mux_enum_get,
1026 .put = conexant_mux_enum_put,
1027 },
Tobin Davisfb3409e2007-05-17 09:40:47 +02001028 /* Audio input controls */
1029 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1030 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1031 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1032 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1033 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1034 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1035 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1036 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1037 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1038 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001039 { } /* end */
1040};
1041
1042static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001043 /* Set connections */
1044 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1045 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1046 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001047 /* Enable retasking pins as output, initially without power amp */
1048 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001049 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001050
1051 /* Disable digital (SPDIF) pins initially, but users can enable
1052 * them via a mixer switch. In the case of SPDIF-out, this initverb
1053 * payload also sets the generation to 0, output to be in "consumer"
1054 * PCM format, copyright asserted, no pre-emphasis and no validity
1055 * control.
1056 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001057 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1058 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001059
1060 /* Start with output sum widgets muted and their output gains at min */
1061 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1062 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1063
1064 /* Unmute retasking pin widget output buffers since the default
1065 * state appears to be output. As the pin mode is changed by the
1066 * user the pin mode control will take care of enabling the pin's
1067 * input/output buffers as needed.
1068 */
1069 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1070 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1071
1072 /* Mute capture amp left and right */
1073 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1074
1075 /* Set ADC connection select to match default mixer setting (mic1
1076 * pin)
1077 */
1078 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001079 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001080
1081 /* Mute all inputs to mixer widget (even unconnected ones) */
1082 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1083 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1084 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1085 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1086 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1087
1088 { }
1089};
1090#endif
1091
1092
1093/* initialize jack-sensing, too */
1094static int cxt5045_init(struct hda_codec *codec)
1095{
1096 conexant_init(codec);
1097 cxt5045_hp_automute(codec);
1098 return 0;
1099}
1100
1101
1102enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001103 CXT5045_LAPTOP_HPSENSE,
1104 CXT5045_LAPTOP_MICSENSE,
1105 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001106 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001107 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001108#ifdef CONFIG_SND_DEBUG
1109 CXT5045_TEST,
1110#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001111 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001112};
1113
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001114static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001115 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1116 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1117 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1118 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001119 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001120#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001121 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001122#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001123};
1124
1125static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001126 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001127 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1128 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001129 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001130 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001131 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1132 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001133 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1134 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001135 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1136 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1137 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001138 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1139 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001140 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001141 {}
1142};
1143
1144static int patch_cxt5045(struct hda_codec *codec)
1145{
1146 struct conexant_spec *spec;
1147 int board_config;
1148
1149 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1150 if (!spec)
1151 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001152 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001153 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001154
1155 spec->multiout.max_channels = 2;
1156 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1157 spec->multiout.dac_nids = cxt5045_dac_nids;
1158 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1159 spec->num_adc_nids = 1;
1160 spec->adc_nids = cxt5045_adc_nids;
1161 spec->capsrc_nids = cxt5045_capsrc_nids;
1162 spec->input_mux = &cxt5045_capture_source;
1163 spec->num_mixers = 1;
1164 spec->mixers[0] = cxt5045_mixers;
1165 spec->num_init_verbs = 1;
1166 spec->init_verbs[0] = cxt5045_init_verbs;
1167 spec->spdif_route = 0;
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001168 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1169 spec->channel_mode = cxt5045_modes;
Tobin Davis5cd57522006-11-20 17:42:09 +01001170
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001171 set_beep_amp(spec, 0x16, 0, 1);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001172
1173 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001174
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001175 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1176 cxt5045_models,
1177 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001178 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001179 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001180 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001181 spec->input_mux = &cxt5045_capture_source;
1182 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001183 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers;
1185 codec->patch_ops.init = cxt5045_init;
1186 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001187 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001188 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001189 spec->input_mux = &cxt5045_capture_source;
1190 spec->num_init_verbs = 2;
1191 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001192 spec->mixers[0] = cxt5045_mixers;
1193 codec->patch_ops.init = cxt5045_init;
1194 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001195 default:
1196 case CXT5045_LAPTOP_HPMICSENSE:
1197 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1198 spec->input_mux = &cxt5045_capture_source;
1199 spec->num_init_verbs = 3;
1200 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1201 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1202 spec->mixers[0] = cxt5045_mixers;
1203 codec->patch_ops.init = cxt5045_init;
1204 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001205 case CXT5045_BENQ:
1206 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1207 spec->input_mux = &cxt5045_capture_source_benq;
1208 spec->num_init_verbs = 1;
1209 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1210 spec->mixers[0] = cxt5045_mixers;
1211 spec->mixers[1] = cxt5045_benq_mixers;
1212 spec->num_mixers = 2;
1213 codec->patch_ops.init = cxt5045_init;
1214 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001215 case CXT5045_LAPTOP_HP530:
1216 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1217 spec->input_mux = &cxt5045_capture_source_hp530;
1218 spec->num_init_verbs = 2;
1219 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1220 spec->mixers[0] = cxt5045_mixers_hp530;
1221 codec->patch_ops.init = cxt5045_init;
1222 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001223#ifdef CONFIG_SND_DEBUG
1224 case CXT5045_TEST:
1225 spec->input_mux = &cxt5045_test_capture_source;
1226 spec->mixers[0] = cxt5045_test_mixer;
1227 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001228 break;
1229
Tobin Davisc9b443d2006-11-14 12:13:39 +01001230#endif
1231 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001232
Takashi Iwai031005f2008-06-26 14:49:58 +02001233 switch (codec->subsystem_id >> 16) {
1234 case 0x103c:
Daniel T Chen8f0f5ff2010-04-28 18:00:11 -04001235 case 0x1631:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001236 case 0x1734:
Daniel T Chen0ebf9e32010-05-10 21:50:04 +02001237 case 0x17aa:
1238 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1239 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1240 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001241 */
1242 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1243 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1244 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1245 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1246 (1 << AC_AMPCAP_MUTE_SHIFT));
1247 break;
1248 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001249
Takashi Iwai3507e2a2010-07-08 18:39:00 +02001250 if (spec->beep_amp)
1251 snd_hda_attach_beep_device(codec, spec->beep_amp);
1252
Tobin Davisc9b443d2006-11-14 12:13:39 +01001253 return 0;
1254}
1255
1256
1257/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001258#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001260static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001261static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1262static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001263
Tobin Davis5cd57522006-11-20 17:42:09 +01001264static struct hda_channel_mode cxt5047_modes[1] = {
1265 { 2, NULL },
1266};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267
Tobin Davis82f30042007-02-13 12:45:44 +01001268static struct hda_input_mux cxt5047_toshiba_capture_source = {
1269 .num_items = 2,
1270 .items = {
1271 { "ExtMic", 0x2 },
1272 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001273 }
1274};
1275
1276/* turn on/off EAPD (+ mute HP) as a master switch */
1277static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1278 struct snd_ctl_elem_value *ucontrol)
1279{
1280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1281 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001282 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001283
Tobin Davis82f30042007-02-13 12:45:44 +01001284 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001285 return 0;
1286
Tobin Davis82f30042007-02-13 12:45:44 +01001287 /* toggle internal speakers mute depending of presence of
1288 * the headphone jack
1289 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001290 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001291 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1292 * pin widgets unlike other codecs. In this case, we need to
1293 * set index 0x01 for the volume from the mixer amp 0x19.
1294 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001295 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001296 HDA_AMP_MUTE, bits);
1297 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1298 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1299 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001300 return 1;
1301}
1302
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303/* mute internal speaker if HP is plugged */
1304static void cxt5047_hp_automute(struct hda_codec *codec)
1305{
Tobin Davis82f30042007-02-13 12:45:44 +01001306 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001307 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001308
Takashi Iwaid56757a2009-11-18 08:00:14 +01001309 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001310
Takashi Iwai47fd8302007-08-10 17:11:07 +02001311 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001312 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001313 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001314 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001315}
1316
1317/* toggle input of built-in and mic jack appropriately */
1318static void cxt5047_hp_automic(struct hda_codec *codec)
1319{
1320 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001321 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1322 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001323 {}
1324 };
1325 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001326 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1327 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001328 {}
1329 };
1330 unsigned int present;
1331
Takashi Iwaid56757a2009-11-18 08:00:14 +01001332 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001333 if (present)
1334 snd_hda_sequence_write(codec, mic_jack_on);
1335 else
1336 snd_hda_sequence_write(codec, mic_jack_off);
1337}
1338
1339/* unsolicited event for HP jack sensing */
1340static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1341 unsigned int res)
1342{
Marc Boucher9f113e02008-01-22 15:18:08 +01001343 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001344 case CONEXANT_HP_EVENT:
1345 cxt5047_hp_automute(codec);
1346 break;
1347 case CONEXANT_MIC_EVENT:
1348 cxt5047_hp_automic(codec);
1349 break;
1350 }
1351}
1352
Takashi Iwaidf481e42009-03-10 15:35:35 +01001353static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1354 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1355 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1356 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001357 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1358 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1359 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001361 {
1362 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1363 .name = "Master Playback Switch",
1364 .info = cxt_eapd_info,
1365 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001366 .put = cxt5047_hp_master_sw_put,
1367 .private_value = 0x13,
1368 },
1369
1370 {}
1371};
1372
Takashi Iwaidf481e42009-03-10 15:35:35 +01001373static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001374 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001375 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001376 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1377 {}
1378};
1379
1380static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001381 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 { } /* end */
1383};
1384
1385static struct hda_verb cxt5047_init_verbs[] = {
1386 /* Line in, Mic, Built-in Mic */
1387 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1388 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1389 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001390 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001391 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001392 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1393 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001394 /* Record selector: Mic */
1395 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1396 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1397 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1398 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001399 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1400 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1401 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1402 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001403 /* SPDIF route: PCM */
1404 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001405 /* Enable unsolicited events */
1406 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1407 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001408 { } /* end */
1409};
1410
1411/* configuration for Toshiba Laptops */
1412static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001413 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001414 {}
1415};
1416
1417/* Test configuration for debugging, modelled after the ALC260 test
1418 * configuration.
1419 */
1420#ifdef CONFIG_SND_DEBUG
1421static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001422 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001423 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001424 { "LINE1 pin", 0x0 },
1425 { "MIC1 pin", 0x1 },
1426 { "MIC2 pin", 0x2 },
1427 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001428 },
1429};
1430
1431static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1432
1433 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001434 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1436 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1437 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001438 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1439 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001442 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1443 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1444 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1445 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001446
1447 /* Modes for retasking pin widgets */
1448 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1449 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1450
Tobin Davis82f30042007-02-13 12:45:44 +01001451 /* EAPD Switch Control */
1452 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1453
Tobin Davisc9b443d2006-11-14 12:13:39 +01001454 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001455 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1456 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1457 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1458 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1459 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1460 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1461 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1462 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001463
Tobin Davis82f30042007-02-13 12:45:44 +01001464 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1465 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1466 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1467 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1468 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1469 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1470 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1471 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001472 {
1473 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1474 .name = "Input Source",
1475 .info = conexant_mux_enum_info,
1476 .get = conexant_mux_enum_get,
1477 .put = conexant_mux_enum_put,
1478 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001479 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001480
Tobin Davisc9b443d2006-11-14 12:13:39 +01001481 { } /* end */
1482};
1483
1484static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001485 /* Enable retasking pins as output, initially without power amp */
1486 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489
1490 /* Disable digital (SPDIF) pins initially, but users can enable
1491 * them via a mixer switch. In the case of SPDIF-out, this initverb
1492 * payload also sets the generation to 0, output to be in "consumer"
1493 * PCM format, copyright asserted, no pre-emphasis and no validity
1494 * control.
1495 */
1496 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497
1498 /* Ensure mic1, mic2, line1 pin widgets take input from the
1499 * OUT1 sum bus when acting as an output.
1500 */
1501 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1502 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503
1504 /* Start with output sum widgets muted and their output gains at min */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507
1508 /* Unmute retasking pin widget output buffers since the default
1509 * state appears to be output. As the pin mode is changed by the
1510 * user the pin mode control will take care of enabling the pin's
1511 * input/output buffers as needed.
1512 */
1513 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516
1517 /* Mute capture amp left and right */
1518 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519
1520 /* Set ADC connection select to match default mixer setting (mic1
1521 * pin)
1522 */
1523 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524
1525 /* Mute all inputs to mixer widget (even unconnected ones) */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1534
1535 { }
1536};
1537#endif
1538
1539
1540/* initialize jack-sensing, too */
1541static int cxt5047_hp_init(struct hda_codec *codec)
1542{
1543 conexant_init(codec);
1544 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545 return 0;
1546}
1547
1548
1549enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001550 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1551 CXT5047_LAPTOP_HP, /* Some HP laptops */
1552 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553#ifdef CONFIG_SND_DEBUG
1554 CXT5047_TEST,
1555#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001556 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001557};
1558
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001559static const char *cxt5047_models[CXT5047_MODELS] = {
1560 [CXT5047_LAPTOP] = "laptop",
1561 [CXT5047_LAPTOP_HP] = "laptop-hp",
1562 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001563#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001564 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001565#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001566};
1567
1568static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001569 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001570 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1571 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001572 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001573 {}
1574};
1575
1576static int patch_cxt5047(struct hda_codec *codec)
1577{
1578 struct conexant_spec *spec;
1579 int board_config;
1580
1581 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1582 if (!spec)
1583 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001584 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001585 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001586
1587 spec->multiout.max_channels = 2;
1588 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1589 spec->multiout.dac_nids = cxt5047_dac_nids;
1590 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1591 spec->num_adc_nids = 1;
1592 spec->adc_nids = cxt5047_adc_nids;
1593 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001594 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001595 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001596 spec->num_init_verbs = 1;
1597 spec->init_verbs[0] = cxt5047_init_verbs;
1598 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001599 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1600 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001601
1602 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001603
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001604 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1605 cxt5047_models,
1606 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001607 switch (board_config) {
1608 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001609 spec->num_mixers = 2;
1610 spec->mixers[1] = cxt5047_hp_spk_mixers;
1611 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001612 break;
1613 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001614 spec->num_mixers = 2;
1615 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001616 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001617 codec->patch_ops.init = cxt5047_hp_init;
1618 break;
1619 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001620 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001621 spec->num_mixers = 2;
1622 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001623 spec->num_init_verbs = 2;
1624 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001625 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001626 break;
1627#ifdef CONFIG_SND_DEBUG
1628 case CXT5047_TEST:
1629 spec->input_mux = &cxt5047_test_capture_source;
1630 spec->mixers[0] = cxt5047_test_mixer;
1631 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001632 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001633#endif
1634 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001635 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001636
1637 switch (codec->subsystem_id >> 16) {
1638 case 0x103c:
1639 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1640 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1641 * with 0 dB offset 0x17)
1642 */
1643 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1644 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1645 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1646 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1647 (1 << AC_AMPCAP_MUTE_SHIFT));
1648 break;
1649 }
1650
Tobin Davisc9b443d2006-11-14 12:13:39 +01001651 return 0;
1652}
1653
Takashi Iwai461e2c72008-01-25 11:35:17 +01001654/* Conexant 5051 specific */
1655static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1656static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001657
1658static struct hda_channel_mode cxt5051_modes[1] = {
1659 { 2, NULL },
1660};
1661
1662static void cxt5051_update_speaker(struct hda_codec *codec)
1663{
1664 struct conexant_spec *spec = codec->spec;
1665 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001666 /* headphone pin */
1667 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1668 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1669 pinctl);
1670 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001671 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1672 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1673 pinctl);
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001674 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1675 if (spec->ideapad)
1676 snd_hda_codec_write(codec, 0x1b, 0,
1677 AC_VERB_SET_PIN_WIDGET_CONTROL,
1678 pinctl);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679}
1680
1681/* turn on/off EAPD (+ mute HP) as a master switch */
1682static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1683 struct snd_ctl_elem_value *ucontrol)
1684{
1685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1686
1687 if (!cxt_eapd_put(kcontrol, ucontrol))
1688 return 0;
1689 cxt5051_update_speaker(codec);
1690 return 1;
1691}
1692
1693/* toggle input of built-in and mic jack appropriately */
1694static void cxt5051_portb_automic(struct hda_codec *codec)
1695{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001696 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001697 unsigned int present;
1698
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001699 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001700 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001701 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001702 snd_hda_codec_write(codec, 0x14, 0,
1703 AC_VERB_SET_CONNECT_SEL,
1704 present ? 0x01 : 0x00);
1705}
1706
1707/* switch the current ADC according to the jack state */
1708static void cxt5051_portc_automic(struct hda_codec *codec)
1709{
1710 struct conexant_spec *spec = codec->spec;
1711 unsigned int present;
1712 hda_nid_t new_adc;
1713
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001714 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001715 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001716 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001717 if (present)
1718 spec->cur_adc_idx = 1;
1719 else
1720 spec->cur_adc_idx = 0;
1721 new_adc = spec->adc_nids[spec->cur_adc_idx];
1722 if (spec->cur_adc && spec->cur_adc != new_adc) {
1723 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001724 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001725 spec->cur_adc = new_adc;
1726 snd_hda_codec_setup_stream(codec, new_adc,
1727 spec->cur_adc_stream_tag, 0,
1728 spec->cur_adc_format);
1729 }
1730}
1731
1732/* mute internal speaker if HP is plugged */
1733static void cxt5051_hp_automute(struct hda_codec *codec)
1734{
1735 struct conexant_spec *spec = codec->spec;
1736
Takashi Iwaid56757a2009-11-18 08:00:14 +01001737 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001738 cxt5051_update_speaker(codec);
1739}
1740
1741/* unsolicited event for HP jack sensing */
1742static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1743 unsigned int res)
1744{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001745 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001746 switch (res >> 26) {
1747 case CONEXANT_HP_EVENT:
1748 cxt5051_hp_automute(codec);
1749 break;
1750 case CXT5051_PORTB_EVENT:
1751 cxt5051_portb_automic(codec);
1752 break;
1753 case CXT5051_PORTC_EVENT:
1754 cxt5051_portc_automic(codec);
1755 break;
1756 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001757 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001758}
1759
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001760static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001761 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1762 {
1763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1764 .name = "Master Playback Switch",
1765 .info = cxt_eapd_info,
1766 .get = cxt_eapd_get,
1767 .put = cxt5051_hp_master_sw_put,
1768 .private_value = 0x1a,
1769 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001770 {}
1771};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001772
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001773static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1774 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1775 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1776 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1777 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1778 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1779 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001780 {}
1781};
1782
1783static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1784 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1785 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1786 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1787 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001788 {}
1789};
1790
Takashi Iwai79d7d532009-03-04 09:03:50 +01001791static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001792 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1793 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001794 {}
1795};
1796
Ken Proxcd9d95a2010-01-08 09:01:47 +01001797static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001798 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1799 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001800 {}
1801};
1802
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001803static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1804 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1805 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1806 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1807 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001808 {}
1809};
1810
Takashi Iwai461e2c72008-01-25 11:35:17 +01001811static struct hda_verb cxt5051_init_verbs[] = {
1812 /* Line in, Mic */
1813 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1814 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1815 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1816 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1817 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1818 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1819 /* SPK */
1820 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1821 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1822 /* HP, Amp */
1823 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1824 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1825 /* DAC1 */
1826 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1827 /* Record selector: Int mic */
1828 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1829 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1830 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1831 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001832 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001833 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1834 /* EAPD */
1835 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1836 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001837 { } /* end */
1838};
1839
Takashi Iwai79d7d532009-03-04 09:03:50 +01001840static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1841 /* Line in, Mic */
1842 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1843 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1844 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1845 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1846 /* SPK */
1847 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1849 /* HP, Amp */
1850 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1851 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1852 /* DAC1 */
1853 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1854 /* Record selector: Int mic */
1855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1856 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1857 /* SPDIF route: PCM */
1858 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1859 /* EAPD */
1860 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1861 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001862 { } /* end */
1863};
1864
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001865static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1866 /* Line in, Mic */
1867 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1868 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1869 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1870 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1871 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1872 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1873 /* SPK */
1874 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1876 /* HP, Amp */
1877 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1878 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1879 /* Docking HP */
1880 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1881 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1882 /* DAC1 */
1883 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1884 /* Record selector: Int mic */
1885 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1887 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1888 /* SPDIF route: PCM */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001889 {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 -05001890 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1891 /* EAPD */
1892 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1893 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001894 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1895 { } /* end */
1896};
1897
Ken Proxcd9d95a2010-01-08 09:01:47 +01001898static struct hda_verb cxt5051_f700_init_verbs[] = {
1899 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001901 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1902 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1903 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1904 /* SPK */
1905 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1906 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1907 /* HP, Amp */
1908 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1909 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1910 /* DAC1 */
1911 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1912 /* Record selector: Int mic */
1913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1914 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1915 /* SPDIF route: PCM */
1916 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1917 /* EAPD */
1918 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1919 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001920 { } /* end */
1921};
1922
Takashi Iwai6953e552010-01-24 11:00:27 +01001923static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1924 unsigned int event)
1925{
1926 snd_hda_codec_write(codec, nid, 0,
1927 AC_VERB_SET_UNSOLICITED_ENABLE,
1928 AC_USRSP_EN | event);
1929#ifdef CONFIG_SND_HDA_INPUT_JACK
1930 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1931 conexant_report_jack(codec, nid);
1932#endif
1933}
1934
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001935static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1936 /* Subwoofer */
1937 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1938 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1939 { } /* end */
1940};
1941
Takashi Iwai461e2c72008-01-25 11:35:17 +01001942/* initialize jack-sensing, too */
1943static int cxt5051_init(struct hda_codec *codec)
1944{
Takashi Iwai6953e552010-01-24 11:00:27 +01001945 struct conexant_spec *spec = codec->spec;
1946
Takashi Iwai461e2c72008-01-25 11:35:17 +01001947 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001948 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001949
1950 if (spec->auto_mic & AUTO_MIC_PORTB)
1951 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1952 if (spec->auto_mic & AUTO_MIC_PORTC)
1953 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1954
Takashi Iwai461e2c72008-01-25 11:35:17 +01001955 if (codec->patch_ops.unsol_event) {
1956 cxt5051_hp_automute(codec);
1957 cxt5051_portb_automic(codec);
1958 cxt5051_portc_automic(codec);
1959 }
1960 return 0;
1961}
1962
1963
1964enum {
1965 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1966 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001967 CXT5051_HP_DV6736, /* HP without mic switch */
Pierre-Louis Bossart1965c442010-05-06 16:37:03 -05001968 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001969 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001970 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001971 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001972 CXT5051_MODELS
1973};
1974
1975static const char *cxt5051_models[CXT5051_MODELS] = {
1976 [CXT5051_LAPTOP] = "laptop",
1977 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001978 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001979 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001980 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001981 [CXT5051_TOSHIBA] = "toshiba",
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001982 [CXT5051_IDEAPAD] = "ideapad",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001983};
1984
1985static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001986 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001987 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001988 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001989 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001990 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1991 CXT5051_LAPTOP),
1992 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001993 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03001994 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001995 {}
1996};
1997
1998static int patch_cxt5051(struct hda_codec *codec)
1999{
2000 struct conexant_spec *spec;
2001 int board_config;
2002
2003 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2004 if (!spec)
2005 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002006 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01002007 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002008
2009 codec->patch_ops = conexant_patch_ops;
2010 codec->patch_ops.init = cxt5051_init;
2011
2012 spec->multiout.max_channels = 2;
2013 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2014 spec->multiout.dac_nids = cxt5051_dac_nids;
2015 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2016 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2017 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01002018 spec->num_mixers = 2;
2019 spec->mixers[0] = cxt5051_capture_mixers;
2020 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002021 spec->num_init_verbs = 1;
2022 spec->init_verbs[0] = cxt5051_init_verbs;
2023 spec->spdif_route = 0;
2024 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2025 spec->channel_mode = cxt5051_modes;
2026 spec->cur_adc = 0;
2027 spec->cur_adc_idx = 0;
2028
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002029 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2030
Takashi Iwai79d7d532009-03-04 09:03:50 +01002031 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2032
Takashi Iwai461e2c72008-01-25 11:35:17 +01002033 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2034 cxt5051_models,
2035 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002036 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002037 switch (board_config) {
2038 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01002039 spec->mixers[0] = cxt5051_hp_mixers;
2040 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002041 case CXT5051_HP_DV6736:
2042 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2043 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002044 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01002045 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05002046 case CXT5051_LENOVO_X200:
2047 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002048 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002049 case CXT5051_F700:
2050 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2051 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01002052 spec->auto_mic = 0;
2053 break;
2054 case CXT5051_TOSHIBA:
2055 spec->mixers[0] = cxt5051_toshiba_mixers;
2056 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01002057 break;
Herton Ronaldo Krzesinskif7154de22010-06-17 14:15:06 -03002058 case CXT5051_IDEAPAD:
2059 spec->init_verbs[spec->num_init_verbs++] =
2060 cxt5051_ideapad_init_verbs;
2061 spec->ideapad = 1;
2062 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01002063 }
2064
Takashi Iwai3507e2a2010-07-08 18:39:00 +02002065 if (spec->beep_amp)
2066 snd_hda_attach_beep_device(codec, spec->beep_amp);
2067
Takashi Iwai461e2c72008-01-25 11:35:17 +01002068 return 0;
2069}
2070
Daniel Drake0fb67e92009-07-16 14:46:57 +01002071/* Conexant 5066 specific */
2072
2073static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2074static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2075static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2076#define CXT5066_SPDIF_OUT 0x21
2077
Daniel Drakedbaccc02009-11-09 15:17:24 +00002078/* OLPC's microphone port is DC coupled for use with external sensors,
2079 * therefore we use a 50% mic bias in order to center the input signal with
2080 * the DC input range of the codec. */
2081#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2082
Daniel Drake0fb67e92009-07-16 14:46:57 +01002083static struct hda_channel_mode cxt5066_modes[1] = {
2084 { 2, NULL },
2085};
2086
2087static void cxt5066_update_speaker(struct hda_codec *codec)
2088{
2089 struct conexant_spec *spec = codec->spec;
2090 unsigned int pinctl;
2091
2092 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2093 spec->hp_present);
2094
2095 /* Port A (HP) */
2096 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2097 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2098 pinctl);
2099
2100 /* Port D (HP/LO) */
2101 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2102 ? spec->port_d_mode : 0;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002103 /* Mute if Port A is connected on Thinkpad */
2104 if (spec->thinkpad && (spec->hp_present & 1))
2105 pinctl = 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002106 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2107 pinctl);
2108
2109 /* CLASS_D AMP */
2110 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2111 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2112 pinctl);
2113
2114 if (spec->dell_automute) {
2115 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2116 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2117 ? PIN_OUT : 0;
2118 snd_hda_codec_write(codec, 0x1c, 0,
2119 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2120 }
2121}
2122
2123/* turn on/off EAPD (+ mute HP) as a master switch */
2124static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2125 struct snd_ctl_elem_value *ucontrol)
2126{
2127 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2128
2129 if (!cxt_eapd_put(kcontrol, ucontrol))
2130 return 0;
2131
2132 cxt5066_update_speaker(codec);
2133 return 1;
2134}
2135
Daniel Drakec4cfe662010-01-07 13:47:04 +01002136static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2137 .num_items = 3,
2138 .items = {
2139 { "Off", PIN_IN },
2140 { "50%", PIN_VREF50 },
2141 { "80%", PIN_VREF80 },
2142 },
2143};
2144
2145static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2146{
2147 struct conexant_spec *spec = codec->spec;
2148 /* Even though port F is the DC input, the bias is controlled on port B.
2149 * we also leave that port as an active input (but unselected) in DC mode
2150 * just in case that is necessary to make the bias setting take effect. */
2151 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2152 AC_VERB_SET_PIN_WIDGET_CONTROL,
2153 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2154}
2155
Daniel Drake75f89912010-01-07 13:46:25 +01002156/* OLPC defers mic widget control until when capture is started because the
2157 * microphone LED comes on as soon as these settings are put in place. if we
2158 * did this before recording, it would give the false indication that recording
2159 * is happening when it is not. */
2160static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002161{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002162 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002163 if (!spec->recording)
2164 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002165
Daniel Drakec4cfe662010-01-07 13:47:04 +01002166 if (spec->dc_enable) {
2167 /* in DC mode we ignore presence detection and just use the jack
2168 * through our special DC port */
2169 const struct hda_verb enable_dc_mode[] = {
2170 /* disble internal mic, port C */
2171 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2172
2173 /* enable DC capture, port F */
2174 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2175 {},
2176 };
2177
2178 snd_hda_sequence_write(codec, enable_dc_mode);
2179 /* port B input disabled (and bias set) through the following call */
2180 cxt5066_set_olpc_dc_bias(codec);
2181 return;
2182 }
2183
2184 /* disable DC (port F) */
2185 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2186
Daniel Drake75f89912010-01-07 13:46:25 +01002187 /* external mic, port B */
2188 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2189 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002190
Daniel Drake75f89912010-01-07 13:46:25 +01002191 /* internal mic, port C */
2192 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2193 spec->ext_mic_present ? 0 : PIN_VREF80);
2194}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002195
Daniel Drake75f89912010-01-07 13:46:25 +01002196/* toggle input of built-in and mic jack appropriately */
2197static void cxt5066_olpc_automic(struct hda_codec *codec)
2198{
2199 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002200 unsigned int present;
2201
Daniel Drakec4cfe662010-01-07 13:47:04 +01002202 if (spec->dc_enable) /* don't do presence detection in DC mode */
2203 return;
2204
Daniel Drake75f89912010-01-07 13:46:25 +01002205 present = snd_hda_codec_read(codec, 0x1a, 0,
2206 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2207 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002208 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002209 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002210 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002211
2212 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2213 present ? 0 : 1);
2214 spec->ext_mic_present = !!present;
2215
2216 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002217}
2218
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002219/* toggle input of built-in digital mic and mic jack appropriately */
2220static void cxt5066_vostro_automic(struct hda_codec *codec)
2221{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002222 unsigned int present;
2223
2224 struct hda_verb ext_mic_present[] = {
2225 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002226 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002227
2228 /* switch to external mic input */
2229 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2230 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2231
2232 /* disable internal digital mic */
2233 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2234 {}
2235 };
2236 static struct hda_verb ext_mic_absent[] = {
2237 /* enable internal mic, port C */
2238 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2239
2240 /* switch to internal mic input */
2241 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2242
2243 /* disable external mic, port B */
2244 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2245 {}
2246 };
2247
2248 present = snd_hda_jack_detect(codec, 0x1a);
2249 if (present) {
2250 snd_printdd("CXT5066: external microphone detected\n");
2251 snd_hda_sequence_write(codec, ext_mic_present);
2252 } else {
2253 snd_printdd("CXT5066: external microphone absent\n");
2254 snd_hda_sequence_write(codec, ext_mic_absent);
2255 }
2256}
2257
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002258/* toggle input of built-in digital mic and mic jack appropriately */
2259static void cxt5066_ideapad_automic(struct hda_codec *codec)
2260{
2261 unsigned int present;
2262
2263 struct hda_verb ext_mic_present[] = {
2264 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2265 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2266 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2267 {}
2268 };
2269 static struct hda_verb ext_mic_absent[] = {
2270 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2271 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2273 {}
2274 };
2275
2276 present = snd_hda_jack_detect(codec, 0x1b);
2277 if (present) {
2278 snd_printdd("CXT5066: external microphone detected\n");
2279 snd_hda_sequence_write(codec, ext_mic_present);
2280 } else {
2281 snd_printdd("CXT5066: external microphone absent\n");
2282 snd_hda_sequence_write(codec, ext_mic_absent);
2283 }
2284}
2285
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002286/* toggle input of built-in digital mic and mic jack appropriately
2287 order is: external mic -> dock mic -> interal mic */
2288static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2289{
2290 unsigned int ext_present, dock_present;
2291
2292 static struct hda_verb ext_mic_present[] = {
2293 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2294 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2295 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2298 {}
2299 };
2300 static struct hda_verb dock_mic_present[] = {
2301 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2302 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2303 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2304 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2305 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 {}
2307 };
2308 static struct hda_verb ext_mic_absent[] = {
2309 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2310 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2311 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2312 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 {}
2314 };
2315
2316 ext_present = snd_hda_jack_detect(codec, 0x1b);
2317 dock_present = snd_hda_jack_detect(codec, 0x1a);
2318 if (ext_present) {
2319 snd_printdd("CXT5066: external microphone detected\n");
2320 snd_hda_sequence_write(codec, ext_mic_present);
2321 } else if (dock_present) {
2322 snd_printdd("CXT5066: dock microphone detected\n");
2323 snd_hda_sequence_write(codec, dock_mic_present);
2324 } else {
2325 snd_printdd("CXT5066: external microphone absent\n");
2326 snd_hda_sequence_write(codec, ext_mic_absent);
2327 }
2328}
2329
Daniel Drake0fb67e92009-07-16 14:46:57 +01002330/* mute internal speaker if HP is plugged */
2331static void cxt5066_hp_automute(struct hda_codec *codec)
2332{
2333 struct conexant_spec *spec = codec->spec;
2334 unsigned int portA, portD;
2335
2336 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002337 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002338
2339 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002340 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002341
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002342 spec->hp_present = !!(portA);
2343 spec->hp_present |= portD ? 2 : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002344 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2345 portA, portD, spec->hp_present);
2346 cxt5066_update_speaker(codec);
2347}
2348
2349/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002350static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002351{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002352 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002353 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2354 switch (res >> 26) {
2355 case CONEXANT_HP_EVENT:
2356 cxt5066_hp_automute(codec);
2357 break;
2358 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002359 /* ignore mic events in DC mode; we're always using the jack */
2360 if (!spec->dc_enable)
2361 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002362 break;
2363 }
2364}
2365
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002366/* unsolicited event for jack sensing */
2367static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2368{
2369 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2370 switch (res >> 26) {
2371 case CONEXANT_HP_EVENT:
2372 cxt5066_hp_automute(codec);
2373 break;
2374 case CONEXANT_MIC_EVENT:
2375 cxt5066_vostro_automic(codec);
2376 break;
2377 }
2378}
2379
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002380/* unsolicited event for jack sensing */
2381static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2382{
2383 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2384 switch (res >> 26) {
2385 case CONEXANT_HP_EVENT:
2386 cxt5066_hp_automute(codec);
2387 break;
2388 case CONEXANT_MIC_EVENT:
2389 cxt5066_ideapad_automic(codec);
2390 break;
2391 }
2392}
2393
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002394/* unsolicited event for jack sensing */
2395static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
2396{
2397 snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
2398 switch (res >> 26) {
2399 case CONEXANT_HP_EVENT:
2400 cxt5066_hp_automute(codec);
2401 break;
2402 case CONEXANT_MIC_EVENT:
2403 cxt5066_thinkpad_automic(codec);
2404 break;
2405 }
2406}
2407
Daniel Drake0fb67e92009-07-16 14:46:57 +01002408static const struct hda_input_mux cxt5066_analog_mic_boost = {
2409 .num_items = 5,
2410 .items = {
2411 { "0dB", 0 },
2412 { "10dB", 1 },
2413 { "20dB", 2 },
2414 { "30dB", 3 },
2415 { "40dB", 4 },
2416 },
2417};
2418
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002419static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002420{
2421 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002422 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002423 AC_VERB_SET_AMP_GAIN_MUTE,
2424 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2425 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002426 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002427 /* adjust the internal mic as well...it is not through 0x17 */
2428 snd_hda_codec_write_cache(codec, 0x23, 0,
2429 AC_VERB_SET_AMP_GAIN_MUTE,
2430 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2431 cxt5066_analog_mic_boost.
2432 items[spec->mic_boost].index);
2433 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002434}
2435
Daniel Drake0fb67e92009-07-16 14:46:57 +01002436static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_info *uinfo)
2438{
2439 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2440}
2441
2442static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2444{
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002446 struct conexant_spec *spec = codec->spec;
2447 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002448 return 0;
2449}
2450
2451static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2452 struct snd_ctl_elem_value *ucontrol)
2453{
2454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002455 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002456 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2457 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002458 idx = ucontrol->value.enumerated.item[0];
2459 if (idx >= imux->num_items)
2460 idx = imux->num_items - 1;
2461
Daniel Drakec4cfe662010-01-07 13:47:04 +01002462 spec->mic_boost = idx;
2463 if (!spec->dc_enable)
2464 cxt5066_set_mic_boost(codec);
2465 return 1;
2466}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002467
Daniel Drakec4cfe662010-01-07 13:47:04 +01002468static void cxt5066_enable_dc(struct hda_codec *codec)
2469{
2470 const struct hda_verb enable_dc_mode[] = {
2471 /* disable gain */
2472 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2473
2474 /* switch to DC input */
2475 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2476 {}
2477 };
2478
2479 /* configure as input source */
2480 snd_hda_sequence_write(codec, enable_dc_mode);
2481 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2482}
2483
2484static void cxt5066_disable_dc(struct hda_codec *codec)
2485{
2486 /* reconfigure input source */
2487 cxt5066_set_mic_boost(codec);
2488 /* automic also selects the right mic if we're recording */
2489 cxt5066_olpc_automic(codec);
2490}
2491
2492static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2493 struct snd_ctl_elem_value *ucontrol)
2494{
2495 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2496 struct conexant_spec *spec = codec->spec;
2497 ucontrol->value.integer.value[0] = spec->dc_enable;
2498 return 0;
2499}
2500
2501static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2502 struct snd_ctl_elem_value *ucontrol)
2503{
2504 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2505 struct conexant_spec *spec = codec->spec;
2506 int dc_enable = !!ucontrol->value.integer.value[0];
2507
2508 if (dc_enable == spec->dc_enable)
2509 return 0;
2510
2511 spec->dc_enable = dc_enable;
2512 if (dc_enable)
2513 cxt5066_enable_dc(codec);
2514 else
2515 cxt5066_disable_dc(codec);
2516
2517 return 1;
2518}
2519
2520static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2521 struct snd_ctl_elem_info *uinfo)
2522{
2523 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2524}
2525
2526static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2527 struct snd_ctl_elem_value *ucontrol)
2528{
2529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2530 struct conexant_spec *spec = codec->spec;
2531 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2532 return 0;
2533}
2534
2535static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2536 struct snd_ctl_elem_value *ucontrol)
2537{
2538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2539 struct conexant_spec *spec = codec->spec;
2540 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2541 unsigned int idx;
2542
2543 idx = ucontrol->value.enumerated.item[0];
2544 if (idx >= imux->num_items)
2545 idx = imux->num_items - 1;
2546
2547 spec->dc_input_bias = idx;
2548 if (spec->dc_enable)
2549 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002550 return 1;
2551}
2552
Daniel Drake75f89912010-01-07 13:46:25 +01002553static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2554{
2555 struct conexant_spec *spec = codec->spec;
2556 /* mark as recording and configure the microphone widget so that the
2557 * recording LED comes on. */
2558 spec->recording = 1;
2559 cxt5066_olpc_select_mic(codec);
2560}
2561
2562static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2563{
2564 struct conexant_spec *spec = codec->spec;
2565 const struct hda_verb disable_mics[] = {
2566 /* disable external mic, port B */
2567 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2568
2569 /* disble internal mic, port C */
2570 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002571
2572 /* disable DC capture, port F */
2573 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002574 {},
2575 };
2576
2577 snd_hda_sequence_write(codec, disable_mics);
2578 spec->recording = 0;
2579}
2580
Daniel Drake0fb67e92009-07-16 14:46:57 +01002581static struct hda_input_mux cxt5066_capture_source = {
2582 .num_items = 4,
2583 .items = {
2584 { "Mic B", 0 },
2585 { "Mic C", 1 },
2586 { "Mic E", 2 },
2587 { "Mic F", 3 },
2588 },
2589};
2590
2591static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2592 .ops = &snd_hda_bind_vol,
2593 .values = {
2594 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2595 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2596 0
2597 },
2598};
2599
2600static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2601 .ops = &snd_hda_bind_sw,
2602 .values = {
2603 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2604 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2605 0
2606 },
2607};
2608
2609static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2610 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2611 {}
2612};
2613
2614static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2615 {
2616 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2617 .name = "Master Playback Volume",
2618 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2619 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2620 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002621 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002622 .info = snd_hda_mixer_amp_volume_info,
2623 .get = snd_hda_mixer_amp_volume_get,
2624 .put = snd_hda_mixer_amp_volume_put,
2625 .tlv = { .c = snd_hda_mixer_amp_tlv },
2626 /* offset by 28 volume steps to limit minimum gain to -46dB */
2627 .private_value =
2628 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2629 },
2630 {}
2631};
2632
Daniel Drakec4cfe662010-01-07 13:47:04 +01002633static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2634 {
2635 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2636 .name = "DC Mode Enable Switch",
2637 .info = snd_ctl_boolean_mono_info,
2638 .get = cxt5066_olpc_dc_get,
2639 .put = cxt5066_olpc_dc_put,
2640 },
2641 {
2642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2643 .name = "DC Input Bias Enum",
2644 .info = cxt5066_olpc_dc_bias_enum_info,
2645 .get = cxt5066_olpc_dc_bias_enum_get,
2646 .put = cxt5066_olpc_dc_bias_enum_put,
2647 },
2648 {}
2649};
2650
Daniel Drake0fb67e92009-07-16 14:46:57 +01002651static struct snd_kcontrol_new cxt5066_mixers[] = {
2652 {
2653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2654 .name = "Master Playback Switch",
2655 .info = cxt_eapd_info,
2656 .get = cxt_eapd_get,
2657 .put = cxt5066_hp_master_sw_put,
2658 .private_value = 0x1d,
2659 },
2660
2661 {
2662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002663 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002664 .info = cxt5066_mic_boost_mux_enum_info,
2665 .get = cxt5066_mic_boost_mux_enum_get,
2666 .put = cxt5066_mic_boost_mux_enum_put,
2667 },
2668
2669 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2670 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2671 {}
2672};
2673
Einar Rünkaru254bba62009-12-16 22:16:13 +02002674static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2675 {
2676 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2677 .name = "Int Mic Boost Capture Enum",
2678 .info = cxt5066_mic_boost_mux_enum_info,
2679 .get = cxt5066_mic_boost_mux_enum_get,
2680 .put = cxt5066_mic_boost_mux_enum_put,
2681 .private_value = 0x23 | 0x100,
2682 },
2683 {}
2684};
2685
Daniel Drake0fb67e92009-07-16 14:46:57 +01002686static struct hda_verb cxt5066_init_verbs[] = {
2687 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2688 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2689 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2690 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2691
2692 /* Speakers */
2693 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2694 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2695
2696 /* HP, Amp */
2697 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2698 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2699
2700 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2701 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2702
2703 /* DAC1 */
2704 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2705
2706 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2707 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2708 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2709 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2710 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2711 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2712
2713 /* no digital microphone support yet */
2714 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2715
2716 /* Audio input selector */
2717 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2718
2719 /* SPDIF route: PCM */
2720 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2721 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2722
2723 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2724 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2725
2726 /* EAPD */
2727 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2728
2729 /* not handling these yet */
2730 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2731 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2732 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2733 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2734 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2735 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2736 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2737 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2738 { } /* end */
2739};
2740
2741static struct hda_verb cxt5066_init_verbs_olpc[] = {
2742 /* Port A: headphones */
2743 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2744 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2745
2746 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002747 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002748
2749 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002750 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002751
2752 /* Port D: unused */
2753 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2754
2755 /* Port E: unused, but has primary EAPD */
2756 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2757 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2758
Daniel Drakec4cfe662010-01-07 13:47:04 +01002759 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002760 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2761
2762 /* Port G: internal speakers */
2763 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2764 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2765
2766 /* DAC1 */
2767 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2768
2769 /* DAC2: unused */
2770 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2771
2772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2773 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2774 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2776 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2777 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2778 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2779 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2782 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2784
2785 /* Disable digital microphone port */
2786 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2787
2788 /* Audio input selectors */
2789 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2790 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2791
2792 /* Disable SPDIF */
2793 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2794 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2795
2796 /* enable unsolicited events for Port A and B */
2797 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2798 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2799 { } /* end */
2800};
2801
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002802static struct hda_verb cxt5066_init_verbs_vostro[] = {
2803 /* Port A: headphones */
2804 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2805 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2806
2807 /* Port B: external microphone */
2808 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2809
2810 /* Port C: unused */
2811 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2812
2813 /* Port D: unused */
2814 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815
2816 /* Port E: unused, but has primary EAPD */
2817 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2819
2820 /* Port F: unused */
2821 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2822
2823 /* Port G: internal speakers */
2824 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2825 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2826
2827 /* DAC1 */
2828 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2829
2830 /* DAC2: unused */
2831 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2832
2833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2834 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2836 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2837 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2838 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2839 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2840 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2841 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2842 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2843 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2844 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2845
2846 /* Digital microphone port */
2847 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2848
2849 /* Audio input selectors */
2850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2851 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2852
2853 /* Disable SPDIF */
2854 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2856
2857 /* enable unsolicited events for Port A and B */
2858 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2859 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2860 { } /* end */
2861};
2862
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002863static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2864 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2865 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2866 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2867 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2868
2869 /* Speakers */
2870 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2871 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2872
2873 /* HP, Amp */
2874 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2875 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2876
2877 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2878 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2879
2880 /* DAC1 */
2881 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2882
2883 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2884 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2885 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2887 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2888 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2889 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2890
2891 /* Audio input selector */
2892 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2893 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2894
2895 /* SPDIF route: PCM */
2896 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2897 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2898
2899 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2900 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2901
2902 /* internal microphone */
2903 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2904
2905 /* EAPD */
2906 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2907
2908 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2909 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2910 { } /* end */
2911};
2912
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002913static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2914 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2915 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2916
2917 /* Port G: internal speakers */
2918 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2919 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2920
2921 /* Port A: HP, Amp */
2922 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2923 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2924
2925 /* Port B: Mic Dock */
2926 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2927
2928 /* Port C: Mic */
2929 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2930
2931 /* Port D: HP Dock, Amp */
2932 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2933 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2934
2935 /* DAC1 */
2936 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2937
2938 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2939 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2940 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2941 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2942 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2943 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2944 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2945
2946 /* Audio input selector */
2947 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2948 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2949
2950 /* SPDIF route: PCM */
2951 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2952 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2953
2954 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2955 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2956
2957 /* internal microphone */
2958 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2959
2960 /* EAPD */
2961 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2962
2963 /* enable unsolicited events for Port A, B, C and D */
2964 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2965 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2966 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2967 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2968 { } /* end */
2969};
2970
Daniel Drake0fb67e92009-07-16 14:46:57 +01002971static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2972 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2973 { } /* end */
2974};
2975
2976/* initialize jack-sensing, too */
2977static int cxt5066_init(struct hda_codec *codec)
2978{
Einar Rünkaru254bba62009-12-16 22:16:13 +02002979 struct conexant_spec *spec = codec->spec;
2980
Daniel Drake0fb67e92009-07-16 14:46:57 +01002981 snd_printdd("CXT5066: init\n");
2982 conexant_init(codec);
2983 if (codec->patch_ops.unsol_event) {
2984 cxt5066_hp_automute(codec);
Einar Rünkaru254bba62009-12-16 22:16:13 +02002985 if (spec->dell_vostro)
2986 cxt5066_vostro_automic(codec);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002987 else if (spec->ideapad)
2988 cxt5066_ideapad_automic(codec);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002989 else if (spec->thinkpad)
2990 cxt5066_thinkpad_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002991 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002992 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002993 return 0;
2994}
2995
Daniel Drake75f89912010-01-07 13:46:25 +01002996static int cxt5066_olpc_init(struct hda_codec *codec)
2997{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002998 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002999 snd_printdd("CXT5066: init\n");
3000 conexant_init(codec);
3001 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01003002 if (!spec->dc_enable) {
3003 cxt5066_set_mic_boost(codec);
3004 cxt5066_olpc_automic(codec);
3005 } else {
3006 cxt5066_enable_dc(codec);
3007 }
Daniel Drake75f89912010-01-07 13:46:25 +01003008 return 0;
3009}
3010
Daniel Drake0fb67e92009-07-16 14:46:57 +01003011enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003012 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003013 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3014 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003015 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003016 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003017 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003018 CXT5066_MODELS
3019};
3020
3021static const char *cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003022 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003023 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3024 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003025 [CXT5066_DELL_VOSTO] = "dell-vostro",
3026 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003027 [CXT5066_THINKPAD] = "thinkpad",
Daniel Drake0fb67e92009-07-16 14:46:57 +01003028};
3029
3030static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3031 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3032 CXT5066_LAPTOP),
3033 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
3034 CXT5066_DELL_LAPTOP),
Daniel Drake798a8a12009-11-04 10:11:07 +00003035 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003036 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
Anisse Astier231f50b2010-04-28 18:05:06 +02003037 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
Daniel T Chenc5366682010-05-04 22:07:58 -04003038 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
Daniel T Chen4442dd42010-05-03 20:39:31 -04003039 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
Andrej Gelenberg0217f142010-05-09 22:10:41 +02003040 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
Andreas Herrmannbadf18b2010-05-28 09:57:12 +02003041 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
Jerone Younga39e33e2010-05-26 10:06:01 -05003042 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003043 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003044 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
Daniel Drake0fb67e92009-07-16 14:46:57 +01003045 {}
3046};
3047
3048static int patch_cxt5066(struct hda_codec *codec)
3049{
3050 struct conexant_spec *spec;
3051 int board_config;
3052
3053 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3054 if (!spec)
3055 return -ENOMEM;
3056 codec->spec = spec;
3057
3058 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01003059 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003060
3061 spec->dell_automute = 0;
3062 spec->multiout.max_channels = 2;
3063 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3064 spec->multiout.dac_nids = cxt5066_dac_nids;
3065 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
3066 spec->num_adc_nids = 1;
3067 spec->adc_nids = cxt5066_adc_nids;
3068 spec->capsrc_nids = cxt5066_capsrc_nids;
3069 spec->input_mux = &cxt5066_capture_source;
3070
3071 spec->port_d_mode = PIN_HP;
3072
3073 spec->num_init_verbs = 1;
3074 spec->init_verbs[0] = cxt5066_init_verbs;
3075 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3076 spec->channel_mode = cxt5066_modes;
3077 spec->cur_adc = 0;
3078 spec->cur_adc_idx = 0;
3079
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003080 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3081
Daniel Drake0fb67e92009-07-16 14:46:57 +01003082 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3083 cxt5066_models, cxt5066_cfg_tbl);
3084 switch (board_config) {
3085 default:
3086 case CXT5066_LAPTOP:
3087 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3088 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3089 break;
3090 case CXT5066_DELL_LAPTOP:
3091 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3092 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3093
3094 spec->port_d_mode = PIN_OUT;
3095 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3096 spec->num_init_verbs++;
3097 spec->dell_automute = 1;
3098 break;
3099 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003100 codec->patch_ops.init = cxt5066_olpc_init;
3101 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003102 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3103 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003104 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003105 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3106 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003107 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003108
3109 /* no S/PDIF out */
3110 spec->multiout.dig_out_nid = 0;
3111
3112 /* input source automatically selected */
3113 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003114
3115 /* our capture hooks which allow us to turn on the microphone LED
3116 * at the right time */
3117 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3118 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003119 break;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003120 case CXT5066_DELL_VOSTO:
Daniel Drake75f89912010-01-07 13:46:25 +01003121 codec->patch_ops.init = cxt5066_init;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003122 codec->patch_ops.unsol_event = cxt5066_vostro_event;
3123 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3124 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3125 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003126 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003127 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003128 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003129 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003130
3131 /* no S/PDIF out */
3132 spec->multiout.dig_out_nid = 0;
3133
3134 /* input source automatically selected */
3135 spec->input_mux = NULL;
3136 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003137 case CXT5066_IDEAPAD:
3138 codec->patch_ops.init = cxt5066_init;
3139 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3140 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3141 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3142 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3143 spec->port_d_mode = 0;
3144 spec->ideapad = 1;
3145 spec->mic_boost = 2; /* default 20dB gain */
3146
3147 /* no S/PDIF out */
3148 spec->multiout.dig_out_nid = 0;
3149
3150 /* input source automatically selected */
3151 spec->input_mux = NULL;
3152 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003153 case CXT5066_THINKPAD:
3154 codec->patch_ops.init = cxt5066_init;
3155 codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
3156 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3157 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3158 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3159 spec->thinkpad = 1;
3160 spec->port_d_mode = PIN_OUT;
3161 spec->mic_boost = 2; /* default 20dB gain */
3162
3163 /* no S/PDIF out */
3164 spec->multiout.dig_out_nid = 0;
3165
3166 /* input source automatically selected */
3167 spec->input_mux = NULL;
3168 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003169 }
3170
Takashi Iwai3507e2a2010-07-08 18:39:00 +02003171 if (spec->beep_amp)
3172 snd_hda_attach_beep_device(codec, spec->beep_amp);
3173
Daniel Drake0fb67e92009-07-16 14:46:57 +01003174 return 0;
3175}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003176
3177/*
3178 */
3179
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003180static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003181 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3182 .patch = patch_cxt5045 },
3183 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3184 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003185 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3186 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003187 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3188 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003189 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3190 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003191 { .id = 0x14f15069, .name = "CX20585",
3192 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003193 {} /* terminator */
3194};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003195
3196MODULE_ALIAS("snd-hda-codec-id:14f15045");
3197MODULE_ALIAS("snd-hda-codec-id:14f15047");
3198MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003199MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003200MODULE_ALIAS("snd-hda-codec-id:14f15067");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003201MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003202
3203MODULE_LICENSE("GPL");
3204MODULE_DESCRIPTION("Conexant HD-audio codec");
3205
3206static struct hda_codec_preset_list conexant_list = {
3207 .preset = snd_hda_preset_conexant,
3208 .owner = THIS_MODULE,
3209};
3210
3211static int __init patch_conexant_init(void)
3212{
3213 return snd_hda_add_codec_preset(&conexant_list);
3214}
3215
3216static void __exit patch_conexant_exit(void)
3217{
3218 snd_hda_delete_codec_preset(&conexant_list);
3219}
3220
3221module_init(patch_conexant_init)
3222module_exit(patch_conexant_exit)