blob: 509a1049ff40d1a6ecc344ef83dc174c48509a49 [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 */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100134};
135
136static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
137 struct hda_codec *codec,
138 struct snd_pcm_substream *substream)
139{
140 struct conexant_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100141 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
142 hinfo);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100143}
144
145static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 unsigned int stream_tag,
148 unsigned int format,
149 struct snd_pcm_substream *substream)
150{
151 struct conexant_spec *spec = codec->spec;
152 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
153 stream_tag,
154 format, substream);
155}
156
157static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 struct snd_pcm_substream *substream)
160{
161 struct conexant_spec *spec = codec->spec;
162 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
163}
164
165/*
166 * Digital out
167 */
168static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
170 struct snd_pcm_substream *substream)
171{
172 struct conexant_spec *spec = codec->spec;
173 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
174}
175
176static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 struct snd_pcm_substream *substream)
179{
180 struct conexant_spec *spec = codec->spec;
181 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
182}
183
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200184static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
185 struct hda_codec *codec,
186 unsigned int stream_tag,
187 unsigned int format,
188 struct snd_pcm_substream *substream)
189{
190 struct conexant_spec *spec = codec->spec;
191 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
192 stream_tag,
193 format, substream);
194}
195
Tobin Davisc9b443d2006-11-14 12:13:39 +0100196/*
197 * Analog capture
198 */
199static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
200 struct hda_codec *codec,
201 unsigned int stream_tag,
202 unsigned int format,
203 struct snd_pcm_substream *substream)
204{
205 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +0100206 if (spec->capture_prepare)
207 spec->capture_prepare(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100208 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
209 stream_tag, 0, format);
210 return 0;
211}
212
213static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
214 struct hda_codec *codec,
215 struct snd_pcm_substream *substream)
216{
217 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100218 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Daniel Drake75f89912010-01-07 13:46:25 +0100219 if (spec->capture_cleanup)
220 spec->capture_cleanup(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100221 return 0;
222}
223
224
225
226static struct hda_pcm_stream conexant_pcm_analog_playback = {
227 .substreams = 1,
228 .channels_min = 2,
229 .channels_max = 2,
230 .nid = 0, /* fill later */
231 .ops = {
232 .open = conexant_playback_pcm_open,
233 .prepare = conexant_playback_pcm_prepare,
234 .cleanup = conexant_playback_pcm_cleanup
235 },
236};
237
238static struct hda_pcm_stream conexant_pcm_analog_capture = {
239 .substreams = 1,
240 .channels_min = 2,
241 .channels_max = 2,
242 .nid = 0, /* fill later */
243 .ops = {
244 .prepare = conexant_capture_pcm_prepare,
245 .cleanup = conexant_capture_pcm_cleanup
246 },
247};
248
249
250static struct hda_pcm_stream conexant_pcm_digital_playback = {
251 .substreams = 1,
252 .channels_min = 2,
253 .channels_max = 2,
254 .nid = 0, /* fill later */
255 .ops = {
256 .open = conexant_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200257 .close = conexant_dig_playback_pcm_close,
258 .prepare = conexant_dig_playback_pcm_prepare
Tobin Davisc9b443d2006-11-14 12:13:39 +0100259 },
260};
261
262static struct hda_pcm_stream conexant_pcm_digital_capture = {
263 .substreams = 1,
264 .channels_min = 2,
265 .channels_max = 2,
266 /* NID is set in alc_build_pcms */
267};
268
Takashi Iwai461e2c72008-01-25 11:35:17 +0100269static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
270 struct hda_codec *codec,
271 unsigned int stream_tag,
272 unsigned int format,
273 struct snd_pcm_substream *substream)
274{
275 struct conexant_spec *spec = codec->spec;
276 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
277 spec->cur_adc_stream_tag = stream_tag;
278 spec->cur_adc_format = format;
279 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
280 return 0;
281}
282
283static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
284 struct hda_codec *codec,
285 struct snd_pcm_substream *substream)
286{
287 struct conexant_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100288 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +0100289 spec->cur_adc = 0;
290 return 0;
291}
292
293static struct hda_pcm_stream cx5051_pcm_analog_capture = {
294 .substreams = 1,
295 .channels_min = 2,
296 .channels_max = 2,
297 .nid = 0, /* fill later */
298 .ops = {
299 .prepare = cx5051_capture_pcm_prepare,
300 .cleanup = cx5051_capture_pcm_cleanup
301 },
302};
303
Tobin Davisc9b443d2006-11-14 12:13:39 +0100304static int conexant_build_pcms(struct hda_codec *codec)
305{
306 struct conexant_spec *spec = codec->spec;
307 struct hda_pcm *info = spec->pcm_rec;
308
309 codec->num_pcms = 1;
310 codec->pcm_info = info;
311
312 info->name = "CONEXANT Analog";
313 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
314 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
315 spec->multiout.max_channels;
316 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
317 spec->multiout.dac_nids[0];
Takashi Iwai461e2c72008-01-25 11:35:17 +0100318 if (codec->vendor_id == 0x14f15051)
319 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
320 cx5051_pcm_analog_capture;
321 else
322 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
323 conexant_pcm_analog_capture;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100324 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
325 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
326
327 if (spec->multiout.dig_out_nid) {
328 info++;
329 codec->num_pcms++;
330 info->name = "Conexant Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100331 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100332 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
333 conexant_pcm_digital_playback;
334 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
335 spec->multiout.dig_out_nid;
336 if (spec->dig_in_nid) {
337 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
338 conexant_pcm_digital_capture;
339 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
340 spec->dig_in_nid;
341 }
342 }
343
344 return 0;
345}
346
347static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
348 struct snd_ctl_elem_info *uinfo)
349{
350 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
351 struct conexant_spec *spec = codec->spec;
352
353 return snd_hda_input_mux_info(spec->input_mux, uinfo);
354}
355
356static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
357 struct snd_ctl_elem_value *ucontrol)
358{
359 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360 struct conexant_spec *spec = codec->spec;
361 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
362
363 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
364 return 0;
365}
366
367static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
368 struct snd_ctl_elem_value *ucontrol)
369{
370 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
371 struct conexant_spec *spec = codec->spec;
372 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
373
374 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
375 spec->capsrc_nids[adc_idx],
376 &spec->cur_mux[adc_idx]);
377}
378
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200379#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +0200380static void conexant_free_jack_priv(struct snd_jack *jack)
381{
382 struct conexant_jack *jacks = jack->private_data;
383 jacks->nid = 0;
384 jacks->jack = NULL;
385}
386
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100387static int conexant_add_jack(struct hda_codec *codec,
388 hda_nid_t nid, int type)
389{
390 struct conexant_spec *spec;
391 struct conexant_jack *jack;
392 const char *name;
Takashi Iwai95c09092009-04-14 16:15:29 +0200393 int err;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100394
395 spec = codec->spec;
396 snd_array_init(&spec->jacks, sizeof(*jack), 32);
397 jack = snd_array_new(&spec->jacks);
398 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
399
400 if (!jack)
401 return -ENOMEM;
402
403 jack->nid = nid;
404 jack->type = type;
405
Takashi Iwai95c09092009-04-14 16:15:29 +0200406 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
407 if (err < 0)
408 return err;
409 jack->jack->private_data = jack;
410 jack->jack->private_free = conexant_free_jack_priv;
411 return 0;
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100412}
413
414static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
415{
416 struct conexant_spec *spec = codec->spec;
417 struct conexant_jack *jacks = spec->jacks.list;
418
419 if (jacks) {
420 int i;
421 for (i = 0; i < spec->jacks.used; i++) {
422 if (jacks->nid == nid) {
423 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100424 present = snd_hda_jack_detect(codec, nid);
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100425
426 present = (present) ? jacks->type : 0 ;
427
428 snd_jack_report(jacks->jack,
429 present);
430 }
431 jacks++;
432 }
433 }
434}
435
436static int conexant_init_jacks(struct hda_codec *codec)
437{
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100438 struct conexant_spec *spec = codec->spec;
439 int i;
440
441 for (i = 0; i < spec->num_init_verbs; i++) {
442 const struct hda_verb *hv;
443
444 hv = spec->init_verbs[i];
445 while (hv->nid) {
446 int err = 0;
447 switch (hv->param ^ AC_USRSP_EN) {
448 case CONEXANT_HP_EVENT:
449 err = conexant_add_jack(codec, hv->nid,
450 SND_JACK_HEADPHONE);
451 conexant_report_jack(codec, hv->nid);
452 break;
453 case CXT5051_PORTC_EVENT:
454 case CONEXANT_MIC_EVENT:
455 err = conexant_add_jack(codec, hv->nid,
456 SND_JACK_MICROPHONE);
457 conexant_report_jack(codec, hv->nid);
458 break;
459 }
460 if (err < 0)
461 return err;
462 ++hv;
463 }
464 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100465 return 0;
466
467}
Takashi Iwai5801f992009-01-27 12:53:22 +0100468#else
469static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
470{
471}
472
473static inline int conexant_init_jacks(struct hda_codec *codec)
474{
475 return 0;
476}
477#endif
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100478
Tobin Davisc9b443d2006-11-14 12:13:39 +0100479static int conexant_init(struct hda_codec *codec)
480{
481 struct conexant_spec *spec = codec->spec;
482 int i;
483
484 for (i = 0; i < spec->num_init_verbs; i++)
485 snd_hda_sequence_write(codec, spec->init_verbs[i]);
486 return 0;
487}
488
489static void conexant_free(struct hda_codec *codec)
490{
Takashi Iwai8c8145b2009-06-22 17:00:38 +0200491#ifdef CONFIG_SND_HDA_INPUT_JACK
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100492 struct conexant_spec *spec = codec->spec;
493 if (spec->jacks.list) {
494 struct conexant_jack *jacks = spec->jacks.list;
495 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +0200496 for (i = 0; i < spec->jacks.used; i++, jacks++) {
497 if (jacks->jack)
498 snd_device_free(codec->bus->card, jacks->jack);
499 }
Ulrich Dangelbc7a1662009-01-02 19:30:13 +0100500 snd_array_free(&spec->jacks);
501 }
502#endif
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +0200503 snd_hda_detach_beep_device(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100504 kfree(codec->spec);
505}
506
Takashi Iwaib880c742009-03-10 14:41:05 +0100507static struct snd_kcontrol_new cxt_capture_mixers[] = {
508 {
509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
510 .name = "Capture Source",
511 .info = conexant_mux_enum_info,
512 .get = conexant_mux_enum_get,
513 .put = conexant_mux_enum_put
514 },
515 {}
516};
517
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100518static const char *slave_vols[] = {
519 "Headphone Playback Volume",
520 "Speaker Playback Volume",
521 NULL
522};
523
524static const char *slave_sws[] = {
525 "Headphone Playback Switch",
526 "Speaker Playback Switch",
527 NULL
528};
529
Tobin Davisc9b443d2006-11-14 12:13:39 +0100530static int conexant_build_controls(struct hda_codec *codec)
531{
532 struct conexant_spec *spec = codec->spec;
533 unsigned int i;
534 int err;
535
536 for (i = 0; i < spec->num_mixers; i++) {
537 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
538 if (err < 0)
539 return err;
540 }
541 if (spec->multiout.dig_out_nid) {
542 err = snd_hda_create_spdif_out_ctls(codec,
543 spec->multiout.dig_out_nid);
544 if (err < 0)
545 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100546 err = snd_hda_create_spdif_share_sw(codec,
547 &spec->multiout);
548 if (err < 0)
549 return err;
550 spec->multiout.share_spdif = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100551 }
552 if (spec->dig_in_nid) {
553 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
554 if (err < 0)
555 return err;
556 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +0100557
558 /* if we have no master control, let's create it */
559 if (spec->vmaster_nid &&
560 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
561 unsigned int vmaster_tlv[4];
562 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
563 HDA_OUTPUT, vmaster_tlv);
564 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
565 vmaster_tlv, slave_vols);
566 if (err < 0)
567 return err;
568 }
569 if (spec->vmaster_nid &&
570 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
571 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
572 NULL, slave_sws);
573 if (err < 0)
574 return err;
575 }
576
Takashi Iwaib880c742009-03-10 14:41:05 +0100577 if (spec->input_mux) {
578 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
579 if (err < 0)
580 return err;
581 }
582
Tobin Davisc9b443d2006-11-14 12:13:39 +0100583 return 0;
584}
585
586static struct hda_codec_ops conexant_patch_ops = {
587 .build_controls = conexant_build_controls,
588 .build_pcms = conexant_build_pcms,
589 .init = conexant_init,
590 .free = conexant_free,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100591};
592
593/*
594 * EAPD control
595 * the private value = nid | (invert << 8)
596 */
597
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200598#define cxt_eapd_info snd_ctl_boolean_mono_info
Tobin Davisc9b443d2006-11-14 12:13:39 +0100599
Tobin Davis82f30042007-02-13 12:45:44 +0100600static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct conexant_spec *spec = codec->spec;
605 int invert = (kcontrol->private_value >> 8) & 1;
606 if (invert)
607 ucontrol->value.integer.value[0] = !spec->cur_eapd;
608 else
609 ucontrol->value.integer.value[0] = spec->cur_eapd;
610 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100611
Tobin Davisc9b443d2006-11-14 12:13:39 +0100612}
613
Tobin Davis82f30042007-02-13 12:45:44 +0100614static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100615 struct snd_ctl_elem_value *ucontrol)
616{
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct conexant_spec *spec = codec->spec;
619 int invert = (kcontrol->private_value >> 8) & 1;
620 hda_nid_t nid = kcontrol->private_value & 0xff;
621 unsigned int eapd;
Tobin Davis82f30042007-02-13 12:45:44 +0100622
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100623 eapd = !!ucontrol->value.integer.value[0];
Tobin Davisc9b443d2006-11-14 12:13:39 +0100624 if (invert)
625 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200626 if (eapd == spec->cur_eapd)
Tobin Davisc9b443d2006-11-14 12:13:39 +0100627 return 0;
Tobin Davis82f30042007-02-13 12:45:44 +0100628
Tobin Davisc9b443d2006-11-14 12:13:39 +0100629 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200630 snd_hda_codec_write_cache(codec, nid,
631 0, AC_VERB_SET_EAPD_BTLENABLE,
632 eapd ? 0x02 : 0x00);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100633 return 1;
634}
635
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100636/* controls for test mode */
637#ifdef CONFIG_SND_DEBUG
638
Tobin Davis82f30042007-02-13 12:45:44 +0100639#define CXT_EAPD_SWITCH(xname, nid, mask) \
640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
641 .info = cxt_eapd_info, \
642 .get = cxt_eapd_get, \
643 .put = cxt_eapd_put, \
644 .private_value = nid | (mask<<16) }
645
646
647
Tobin Davisc9b443d2006-11-14 12:13:39 +0100648static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_info *uinfo)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
654 spec->num_channel_mode);
655}
656
657static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_value *ucontrol)
659{
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct conexant_spec *spec = codec->spec;
662 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
663 spec->num_channel_mode,
664 spec->multiout.max_channels);
665}
666
667static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671 struct conexant_spec *spec = codec->spec;
672 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
673 spec->num_channel_mode,
674 &spec->multiout.max_channels);
675 if (err >= 0 && spec->need_dac_fix)
676 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
677 return err;
678}
679
680#define CXT_PIN_MODE(xname, nid, dir) \
681 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
682 .info = conexant_ch_mode_info, \
683 .get = conexant_ch_mode_get, \
684 .put = conexant_ch_mode_put, \
685 .private_value = nid | (dir<<16) }
686
Takashi Iwai86d72bd2006-11-28 11:33:10 +0100687#endif /* CONFIG_SND_DEBUG */
688
Tobin Davisc9b443d2006-11-14 12:13:39 +0100689/* Conexant 5045 specific */
690
691static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
692static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
693static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
Takashi Iwaicbef9782008-02-22 18:36:46 +0100694#define CXT5045_SPDIF_OUT 0x18
Tobin Davisc9b443d2006-11-14 12:13:39 +0100695
Tobin Davis5cd57522006-11-20 17:42:09 +0100696static struct hda_channel_mode cxt5045_modes[1] = {
697 { 2, NULL },
698};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100699
700static struct hda_input_mux cxt5045_capture_source = {
701 .num_items = 2,
702 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +0100703 { "IntMic", 0x1 },
Jiang zhef4beee92008-01-17 11:19:26 +0100704 { "ExtMic", 0x2 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100705 }
706};
707
Jiang Zhe5218c892008-01-17 11:18:41 +0100708static struct hda_input_mux cxt5045_capture_source_benq = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200709 .num_items = 5,
Jiang Zhe5218c892008-01-17 11:18:41 +0100710 .items = {
711 { "IntMic", 0x1 },
712 { "ExtMic", 0x2 },
713 { "LineIn", 0x3 },
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200714 { "CD", 0x4 },
715 { "Mixer", 0x0 },
Jiang Zhe5218c892008-01-17 11:18:41 +0100716 }
717};
718
Jiang zhe2de3c232008-03-06 11:09:09 +0100719static struct hda_input_mux cxt5045_capture_source_hp530 = {
720 .num_items = 2,
721 .items = {
722 { "ExtMic", 0x1 },
723 { "IntMic", 0x2 },
724 }
725};
726
Tobin Davisc9b443d2006-11-14 12:13:39 +0100727/* turn on/off EAPD (+ mute HP) as a master switch */
728static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
730{
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +0100733 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100734
Tobin Davis82f30042007-02-13 12:45:44 +0100735 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +0100736 return 0;
737
Tobin Davis82f30042007-02-13 12:45:44 +0100738 /* toggle internal speakers mute depending of presence of
739 * the headphone jack
740 */
Takashi Iwai47fd8302007-08-10 17:11:07 +0200741 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
742 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
743 HDA_AMP_MUTE, bits);
Tobin Davis7f296732007-03-12 11:39:01 +0100744
Takashi Iwai47fd8302007-08-10 17:11:07 +0200745 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
746 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
747 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100748 return 1;
749}
750
751/* bind volumes of both NID 0x10 and 0x11 */
Takashi Iwaicca3b372007-08-10 17:12:15 +0200752static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
753 .ops = &snd_hda_bind_vol,
754 .values = {
755 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
756 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
757 0
758 },
759};
Tobin Davisc9b443d2006-11-14 12:13:39 +0100760
Tobin Davis7f296732007-03-12 11:39:01 +0100761/* toggle input of built-in and mic jack appropriately */
762static void cxt5045_hp_automic(struct hda_codec *codec)
763{
764 static struct hda_verb mic_jack_on[] = {
765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
766 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
767 {}
768 };
769 static struct hda_verb mic_jack_off[] = {
770 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
772 {}
773 };
774 unsigned int present;
775
Takashi Iwaid56757a2009-11-18 08:00:14 +0100776 present = snd_hda_jack_detect(codec, 0x12);
Tobin Davis7f296732007-03-12 11:39:01 +0100777 if (present)
778 snd_hda_sequence_write(codec, mic_jack_on);
779 else
780 snd_hda_sequence_write(codec, mic_jack_off);
781}
782
Tobin Davisc9b443d2006-11-14 12:13:39 +0100783
784/* mute internal speaker if HP is plugged */
785static void cxt5045_hp_automute(struct hda_codec *codec)
786{
Tobin Davis82f30042007-02-13 12:45:44 +0100787 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +0100788 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +0100789
Takashi Iwaid56757a2009-11-18 08:00:14 +0100790 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
Tobin Davisdd87da12007-02-26 16:07:42 +0100791
Takashi Iwai47fd8302007-08-10 17:11:07 +0200792 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
793 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
794 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +0100795}
796
797/* unsolicited event for HP jack sensing */
798static void cxt5045_hp_unsol_event(struct hda_codec *codec,
799 unsigned int res)
800{
801 res >>= 26;
802 switch (res) {
803 case CONEXANT_HP_EVENT:
804 cxt5045_hp_automute(codec);
805 break;
Tobin Davis7f296732007-03-12 11:39:01 +0100806 case CONEXANT_MIC_EVENT:
807 cxt5045_hp_automic(codec);
808 break;
809
Tobin Davisc9b443d2006-11-14 12:13:39 +0100810 }
811}
812
813static struct snd_kcontrol_new cxt5045_mixers[] = {
Takashi Iwaic8229c32007-10-19 08:06:21 +0200814 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
815 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
816 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
817 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
818 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
819 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
820 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
821 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
822 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
823 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
Takashi Iwaicca3b372007-08-10 17:12:15 +0200824 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100825 {
826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
827 .name = "Master Playback Switch",
Tobin Davis82f30042007-02-13 12:45:44 +0100828 .info = cxt_eapd_info,
829 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100830 .put = cxt5045_hp_master_sw_put,
Tobin Davis82f30042007-02-13 12:45:44 +0100831 .private_value = 0x10,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100832 },
833
834 {}
835};
836
Jiang Zhe5218c892008-01-17 11:18:41 +0100837static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200838 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
839 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
840 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
841 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
842
Jiang Zhe5218c892008-01-17 11:18:41 +0100843 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
844 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
845 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
846 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
847
Lukasz Marcinowski22e14132009-09-22 21:42:40 +0200848 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
849 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
850
Jiang Zhe5218c892008-01-17 11:18:41 +0100851 {}
852};
853
Jiang zhe2de3c232008-03-06 11:09:09 +0100854static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +0100855 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
856 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
857 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
858 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
859 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
860 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
861 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
862 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
863 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
864 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
865 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
866 {
867 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
868 .name = "Master Playback Switch",
869 .info = cxt_eapd_info,
870 .get = cxt_eapd_get,
871 .put = cxt5045_hp_master_sw_put,
872 .private_value = 0x10,
873 },
874
875 {}
876};
877
Tobin Davisc9b443d2006-11-14 12:13:39 +0100878static struct hda_verb cxt5045_init_verbs[] = {
879 /* Line in, Mic */
Takashi Iwai4090dff2008-07-12 12:02:45 +0200880 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davis7f296732007-03-12 11:39:01 +0100881 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100882 /* HP, Amp */
Takashi Iwaic8229c32007-10-19 08:06:21 +0200883 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
885 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
886 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Tobin Davis82f30042007-02-13 12:45:44 +0100892 /* Record selector: Int mic */
Tobin Davis7f296732007-03-12 11:39:01 +0100893 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
Tobin Davis82f30042007-02-13 12:45:44 +0100894 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
Tobin Davisc9b443d2006-11-14 12:13:39 +0100895 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
896 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100897 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +0100898 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +0100899 /* EAPD */
Tobin Davis82f30042007-02-13 12:45:44 +0100900 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100901 { } /* end */
902};
903
Jiang Zhe5218c892008-01-17 11:18:41 +0100904static struct hda_verb cxt5045_benq_init_verbs[] = {
905 /* Int Mic, Mic */
906 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
907 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
908 /* Line In,HP, Amp */
909 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
910 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
911 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
912 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
918 /* Record selector: Int mic */
919 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
920 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
921 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
922 /* SPDIF route: PCM */
Takashi Iwaicbef9782008-02-22 18:36:46 +0100923 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Jiang Zhe5218c892008-01-17 11:18:41 +0100924 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
925 /* EAPD */
926 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
927 { } /* end */
928};
Tobin Davis7f296732007-03-12 11:39:01 +0100929
930static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
931 /* pin sensing on HP jack */
932 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200933 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100934};
935
936static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
937 /* pin sensing on HP jack */
938 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Takashi Iwaid3091fa2007-03-28 15:11:53 +0200939 { } /* end */
Tobin Davis7f296732007-03-12 11:39:01 +0100940};
941
Tobin Davisc9b443d2006-11-14 12:13:39 +0100942#ifdef CONFIG_SND_DEBUG
943/* Test configuration for debugging, modelled after the ALC260 test
944 * configuration.
945 */
946static struct hda_input_mux cxt5045_test_capture_source = {
947 .num_items = 5,
948 .items = {
949 { "MIXER", 0x0 },
950 { "MIC1 pin", 0x1 },
951 { "LINE1 pin", 0x2 },
952 { "HP-OUT pin", 0x3 },
953 { "CD pin", 0x4 },
954 },
955};
956
957static struct snd_kcontrol_new cxt5045_test_mixer[] = {
958
959 /* Output controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100960 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
961 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
Tobin Davis7f296732007-03-12 11:39:01 +0100962 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
963 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
964 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
965 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100966
967 /* Modes for retasking pin widgets */
968 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
969 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
970
Tobin Davis82f30042007-02-13 12:45:44 +0100971 /* EAPD Switch Control */
972 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
973
Tobin Davisc9b443d2006-11-14 12:13:39 +0100974 /* Loopback mixer controls */
Tobin Davisc9b443d2006-11-14 12:13:39 +0100975
Tobin Davis7f296732007-03-12 11:39:01 +0100976 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
977 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
978 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
979 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
980 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
981 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
982 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
983 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
984 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
985 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +0100986 {
987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
988 .name = "Input Source",
989 .info = conexant_mux_enum_info,
990 .get = conexant_mux_enum_get,
991 .put = conexant_mux_enum_put,
992 },
Tobin Davisfb3409e2007-05-17 09:40:47 +0200993 /* Audio input controls */
994 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
995 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
996 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
997 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
998 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
999 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1000 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1001 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1002 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1003 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001004 { } /* end */
1005};
1006
1007static struct hda_verb cxt5045_test_init_verbs[] = {
Tobin Davis7f296732007-03-12 11:39:01 +01001008 /* Set connections */
1009 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1010 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1011 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001012 /* Enable retasking pins as output, initially without power amp */
1013 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davis7f296732007-03-12 11:39:01 +01001014 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001015
1016 /* Disable digital (SPDIF) pins initially, but users can enable
1017 * them via a mixer switch. In the case of SPDIF-out, this initverb
1018 * payload also sets the generation to 0, output to be in "consumer"
1019 * PCM format, copyright asserted, no pre-emphasis and no validity
1020 * control.
1021 */
Takashi Iwaicbef9782008-02-22 18:36:46 +01001022 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1023 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001024
1025 /* Start with output sum widgets muted and their output gains at min */
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1027 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1028
1029 /* Unmute retasking pin widget output buffers since the default
1030 * state appears to be output. As the pin mode is changed by the
1031 * user the pin mode control will take care of enabling the pin's
1032 * input/output buffers as needed.
1033 */
1034 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1036
1037 /* Mute capture amp left and right */
1038 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1039
1040 /* Set ADC connection select to match default mixer setting (mic1
1041 * pin)
1042 */
1043 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davis7f296732007-03-12 11:39:01 +01001044 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001045
1046 /* Mute all inputs to mixer widget (even unconnected ones) */
1047 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1048 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1049 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1050 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1051 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1052
1053 { }
1054};
1055#endif
1056
1057
1058/* initialize jack-sensing, too */
1059static int cxt5045_init(struct hda_codec *codec)
1060{
1061 conexant_init(codec);
1062 cxt5045_hp_automute(codec);
1063 return 0;
1064}
1065
1066
1067enum {
Marc Boucher15908c32008-01-22 15:15:59 +01001068 CXT5045_LAPTOP_HPSENSE,
1069 CXT5045_LAPTOP_MICSENSE,
1070 CXT5045_LAPTOP_HPMICSENSE,
Jiang Zhe5218c892008-01-17 11:18:41 +01001071 CXT5045_BENQ,
Jiang zhe2de3c232008-03-06 11:09:09 +01001072 CXT5045_LAPTOP_HP530,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001073#ifdef CONFIG_SND_DEBUG
1074 CXT5045_TEST,
1075#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001076 CXT5045_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001077};
1078
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001079static const char *cxt5045_models[CXT5045_MODELS] = {
Marc Boucher15908c32008-01-22 15:15:59 +01001080 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1081 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1082 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1083 [CXT5045_BENQ] = "benq",
Jiang zhe2de3c232008-03-06 11:09:09 +01001084 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001085#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001086 [CXT5045_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001087#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001088};
1089
1090static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
Jiang zhe2de3c232008-03-06 11:09:09 +01001091 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001092 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1093 CXT5045_LAPTOP_HPSENSE),
Takashi Iwai6a9dccd2008-07-01 14:52:05 +02001094 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
Jiang Zhe5218c892008-01-17 11:18:41 +01001095 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
Marc Boucher15908c32008-01-22 15:15:59 +01001096 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1097 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwai9e464152008-07-12 12:05:25 +02001098 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1099 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001100 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1101 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1102 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001103 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1104 CXT5045_LAPTOP_HPMICSENSE),
Marc Boucher15908c32008-01-22 15:15:59 +01001105 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001106 {}
1107};
1108
1109static int patch_cxt5045(struct hda_codec *codec)
1110{
1111 struct conexant_spec *spec;
1112 int board_config;
1113
1114 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1115 if (!spec)
1116 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001117 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001118 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001119
1120 spec->multiout.max_channels = 2;
1121 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1122 spec->multiout.dac_nids = cxt5045_dac_nids;
1123 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1124 spec->num_adc_nids = 1;
1125 spec->adc_nids = cxt5045_adc_nids;
1126 spec->capsrc_nids = cxt5045_capsrc_nids;
1127 spec->input_mux = &cxt5045_capture_source;
1128 spec->num_mixers = 1;
1129 spec->mixers[0] = cxt5045_mixers;
1130 spec->num_init_verbs = 1;
1131 spec->init_verbs[0] = cxt5045_init_verbs;
1132 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001133 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1134 spec->channel_mode = cxt5045_modes,
1135
Tobin Davisc9b443d2006-11-14 12:13:39 +01001136
1137 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001138
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001139 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1140 cxt5045_models,
1141 cxt5045_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001142 switch (board_config) {
Marc Boucher15908c32008-01-22 15:15:59 +01001143 case CXT5045_LAPTOP_HPSENSE:
Tobin Davis7f296732007-03-12 11:39:01 +01001144 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001145 spec->input_mux = &cxt5045_capture_source;
1146 spec->num_init_verbs = 2;
Tobin Davis7f296732007-03-12 11:39:01 +01001147 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1148 spec->mixers[0] = cxt5045_mixers;
1149 codec->patch_ops.init = cxt5045_init;
1150 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001151 case CXT5045_LAPTOP_MICSENSE:
Takashi Iwai86376df2008-07-12 12:04:05 +02001152 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
Tobin Davis7f296732007-03-12 11:39:01 +01001153 spec->input_mux = &cxt5045_capture_source;
1154 spec->num_init_verbs = 2;
1155 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001156 spec->mixers[0] = cxt5045_mixers;
1157 codec->patch_ops.init = cxt5045_init;
1158 break;
Marc Boucher15908c32008-01-22 15:15:59 +01001159 default:
1160 case CXT5045_LAPTOP_HPMICSENSE:
1161 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1162 spec->input_mux = &cxt5045_capture_source;
1163 spec->num_init_verbs = 3;
1164 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1165 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1166 spec->mixers[0] = cxt5045_mixers;
1167 codec->patch_ops.init = cxt5045_init;
1168 break;
Jiang Zhe5218c892008-01-17 11:18:41 +01001169 case CXT5045_BENQ:
1170 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1171 spec->input_mux = &cxt5045_capture_source_benq;
1172 spec->num_init_verbs = 1;
1173 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1174 spec->mixers[0] = cxt5045_mixers;
1175 spec->mixers[1] = cxt5045_benq_mixers;
1176 spec->num_mixers = 2;
1177 codec->patch_ops.init = cxt5045_init;
1178 break;
Jiang zhe2de3c232008-03-06 11:09:09 +01001179 case CXT5045_LAPTOP_HP530:
1180 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1181 spec->input_mux = &cxt5045_capture_source_hp530;
1182 spec->num_init_verbs = 2;
1183 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers_hp530;
1185 codec->patch_ops.init = cxt5045_init;
1186 break;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001187#ifdef CONFIG_SND_DEBUG
1188 case CXT5045_TEST:
1189 spec->input_mux = &cxt5045_test_capture_source;
1190 spec->mixers[0] = cxt5045_test_mixer;
1191 spec->init_verbs[0] = cxt5045_test_init_verbs;
Marc Boucher15908c32008-01-22 15:15:59 +01001192 break;
1193
Tobin Davisc9b443d2006-11-14 12:13:39 +01001194#endif
1195 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001196
Takashi Iwai031005f2008-06-26 14:49:58 +02001197 switch (codec->subsystem_id >> 16) {
1198 case 0x103c:
Daniel T Chen0b587fc2009-11-25 18:27:20 -05001199 case 0x1734:
1200 /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1201 * on NID 0x17. Fix max PCM level to 0 dB
1202 * (originally it has 0x2b steps with 0dB offset 0x14)
Takashi Iwai031005f2008-06-26 14:49:58 +02001203 */
1204 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1205 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1206 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1207 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1208 (1 << AC_AMPCAP_MUTE_SHIFT));
1209 break;
1210 }
Takashi Iwai48ecb7e2007-12-17 14:32:49 +01001211
Tobin Davisc9b443d2006-11-14 12:13:39 +01001212 return 0;
1213}
1214
1215
1216/* Conexant 5047 specific */
Tobin Davis82f30042007-02-13 12:45:44 +01001217#define CXT5047_SPDIF_OUT 0x11
Tobin Davisc9b443d2006-11-14 12:13:39 +01001218
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001219static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001220static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1221static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
Tobin Davisc9b443d2006-11-14 12:13:39 +01001222
Tobin Davis5cd57522006-11-20 17:42:09 +01001223static struct hda_channel_mode cxt5047_modes[1] = {
1224 { 2, NULL },
1225};
Tobin Davisc9b443d2006-11-14 12:13:39 +01001226
Tobin Davis82f30042007-02-13 12:45:44 +01001227static struct hda_input_mux cxt5047_toshiba_capture_source = {
1228 .num_items = 2,
1229 .items = {
1230 { "ExtMic", 0x2 },
1231 { "Line-In", 0x1 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001232 }
1233};
1234
1235/* turn on/off EAPD (+ mute HP) as a master switch */
1236static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1237 struct snd_ctl_elem_value *ucontrol)
1238{
1239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1240 struct conexant_spec *spec = codec->spec;
Tobin Davis82f30042007-02-13 12:45:44 +01001241 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001242
Tobin Davis82f30042007-02-13 12:45:44 +01001243 if (!cxt_eapd_put(kcontrol, ucontrol))
Tobin Davisc9b443d2006-11-14 12:13:39 +01001244 return 0;
1245
Tobin Davis82f30042007-02-13 12:45:44 +01001246 /* toggle internal speakers mute depending of presence of
1247 * the headphone jack
1248 */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001249 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001250 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1251 * pin widgets unlike other codecs. In this case, we need to
1252 * set index 0x01 for the volume from the mixer amp 0x19.
1253 */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001254 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001255 HDA_AMP_MUTE, bits);
1256 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1257 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1258 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001259 return 1;
1260}
1261
Tobin Davisc9b443d2006-11-14 12:13:39 +01001262/* mute internal speaker if HP is plugged */
1263static void cxt5047_hp_automute(struct hda_codec *codec)
1264{
Tobin Davis82f30042007-02-13 12:45:44 +01001265 struct conexant_spec *spec = codec->spec;
Tobin Davisdd87da12007-02-26 16:07:42 +01001266 unsigned int bits;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001267
Takashi Iwaid56757a2009-11-18 08:00:14 +01001268 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
Tobin Davisdd87da12007-02-26 16:07:42 +01001269
Takashi Iwai47fd8302007-08-10 17:11:07 +02001270 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001271 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001272 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001273 HDA_AMP_MUTE, bits);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001274}
1275
1276/* toggle input of built-in and mic jack appropriately */
1277static void cxt5047_hp_automic(struct hda_codec *codec)
1278{
1279 static struct hda_verb mic_jack_on[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001280 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1281 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001282 {}
1283 };
1284 static struct hda_verb mic_jack_off[] = {
Marc Boucher9f113e02008-01-22 15:18:08 +01001285 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1286 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001287 {}
1288 };
1289 unsigned int present;
1290
Takashi Iwaid56757a2009-11-18 08:00:14 +01001291 present = snd_hda_jack_detect(codec, 0x15);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001292 if (present)
1293 snd_hda_sequence_write(codec, mic_jack_on);
1294 else
1295 snd_hda_sequence_write(codec, mic_jack_off);
1296}
1297
1298/* unsolicited event for HP jack sensing */
1299static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1300 unsigned int res)
1301{
Marc Boucher9f113e02008-01-22 15:18:08 +01001302 switch (res >> 26) {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001303 case CONEXANT_HP_EVENT:
1304 cxt5047_hp_automute(codec);
1305 break;
1306 case CONEXANT_MIC_EVENT:
1307 cxt5047_hp_automic(codec);
1308 break;
1309 }
1310}
1311
Takashi Iwaidf481e42009-03-10 15:35:35 +01001312static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1313 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001316 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1318 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1319 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001320 {
1321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1322 .name = "Master Playback Switch",
1323 .info = cxt_eapd_info,
1324 .get = cxt_eapd_get,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001325 .put = cxt5047_hp_master_sw_put,
1326 .private_value = 0x13,
1327 },
1328
1329 {}
1330};
1331
Takashi Iwaidf481e42009-03-10 15:35:35 +01001332static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
Takashi Iwai3b7523f2009-03-12 16:45:01 +01001333 /* See the note in cxt5047_hp_master_sw_put */
Gregorio Guidi5d75bc52009-03-12 16:41:51 +01001334 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
Takashi Iwaidf481e42009-03-10 15:35:35 +01001335 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1336 {}
1337};
1338
1339static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001340 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001341 { } /* end */
1342};
1343
1344static struct hda_verb cxt5047_init_verbs[] = {
1345 /* Line in, Mic, Built-in Mic */
1346 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1347 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1348 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
Tobin Davis7f296732007-03-12 11:39:01 +01001349 /* HP, Speaker */
Tobin Davisb7589ce2007-04-24 17:56:55 +02001350 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
Takashi Iwai5b3a7442009-03-10 15:10:55 +01001351 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1352 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
Tobin Davis7f296732007-03-12 11:39:01 +01001353 /* Record selector: Mic */
1354 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1355 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1356 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1357 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001358 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1359 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1360 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1361 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001362 /* SPDIF route: PCM */
1363 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
Tobin Davis82f30042007-02-13 12:45:44 +01001364 /* Enable unsolicited events */
1365 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1366 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
Tobin Davisc9b443d2006-11-14 12:13:39 +01001367 { } /* end */
1368};
1369
1370/* configuration for Toshiba Laptops */
1371static struct hda_verb cxt5047_toshiba_init_verbs[] = {
Takashi Iwai3b628862009-03-10 14:53:54 +01001372 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001373 {}
1374};
1375
1376/* Test configuration for debugging, modelled after the ALC260 test
1377 * configuration.
1378 */
1379#ifdef CONFIG_SND_DEBUG
1380static struct hda_input_mux cxt5047_test_capture_source = {
Tobin Davis82f30042007-02-13 12:45:44 +01001381 .num_items = 4,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001382 .items = {
Tobin Davis82f30042007-02-13 12:45:44 +01001383 { "LINE1 pin", 0x0 },
1384 { "MIC1 pin", 0x1 },
1385 { "MIC2 pin", 0x2 },
1386 { "CD pin", 0x3 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01001387 },
1388};
1389
1390static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1391
1392 /* Output only controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001393 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1394 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1395 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1396 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001397 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Tobin Davis82f30042007-02-13 12:45:44 +01001401 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1404 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001405
1406 /* Modes for retasking pin widgets */
1407 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1408 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1409
Tobin Davis82f30042007-02-13 12:45:44 +01001410 /* EAPD Switch Control */
1411 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1412
Tobin Davisc9b443d2006-11-14 12:13:39 +01001413 /* Loopback mixer controls */
Tobin Davis82f30042007-02-13 12:45:44 +01001414 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1415 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1416 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1417 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1418 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1419 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1420 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1421 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001422
Tobin Davis82f30042007-02-13 12:45:44 +01001423 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1424 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1426 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1427 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1428 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1429 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1430 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001431 {
1432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1433 .name = "Input Source",
1434 .info = conexant_mux_enum_info,
1435 .get = conexant_mux_enum_get,
1436 .put = conexant_mux_enum_put,
1437 },
Takashi Iwai854206b2009-11-30 18:22:04 +01001438 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
Marc Boucher9f113e02008-01-22 15:18:08 +01001439
Tobin Davisc9b443d2006-11-14 12:13:39 +01001440 { } /* end */
1441};
1442
1443static struct hda_verb cxt5047_test_init_verbs[] = {
Tobin Davisc9b443d2006-11-14 12:13:39 +01001444 /* Enable retasking pins as output, initially without power amp */
1445 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1446 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1448
1449 /* Disable digital (SPDIF) pins initially, but users can enable
1450 * them via a mixer switch. In the case of SPDIF-out, this initverb
1451 * payload also sets the generation to 0, output to be in "consumer"
1452 * PCM format, copyright asserted, no pre-emphasis and no validity
1453 * control.
1454 */
1455 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1456
1457 /* Ensure mic1, mic2, line1 pin widgets take input from the
1458 * OUT1 sum bus when acting as an output.
1459 */
1460 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1461 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1462
1463 /* Start with output sum widgets muted and their output gains at min */
1464 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1466
1467 /* Unmute retasking pin widget output buffers since the default
1468 * state appears to be output. As the pin mode is changed by the
1469 * user the pin mode control will take care of enabling the pin's
1470 * input/output buffers as needed.
1471 */
1472 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1475
1476 /* Mute capture amp left and right */
1477 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1478
1479 /* Set ADC connection select to match default mixer setting (mic1
1480 * pin)
1481 */
1482 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1483
1484 /* Mute all inputs to mixer widget (even unconnected ones) */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1492 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1493
1494 { }
1495};
1496#endif
1497
1498
1499/* initialize jack-sensing, too */
1500static int cxt5047_hp_init(struct hda_codec *codec)
1501{
1502 conexant_init(codec);
1503 cxt5047_hp_automute(codec);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001504 return 0;
1505}
1506
1507
1508enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001509 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1510 CXT5047_LAPTOP_HP, /* Some HP laptops */
1511 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
Tobin Davisc9b443d2006-11-14 12:13:39 +01001512#ifdef CONFIG_SND_DEBUG
1513 CXT5047_TEST,
1514#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001515 CXT5047_MODELS
Tobin Davisc9b443d2006-11-14 12:13:39 +01001516};
1517
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001518static const char *cxt5047_models[CXT5047_MODELS] = {
1519 [CXT5047_LAPTOP] = "laptop",
1520 [CXT5047_LAPTOP_HP] = "laptop-hp",
1521 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001522#ifdef CONFIG_SND_DEBUG
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001523 [CXT5047_TEST] = "test",
Tobin Davisc9b443d2006-11-14 12:13:39 +01001524#endif
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001525};
1526
1527static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001528 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001529 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1530 CXT5047_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001531 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
Tobin Davisc9b443d2006-11-14 12:13:39 +01001532 {}
1533};
1534
1535static int patch_cxt5047(struct hda_codec *codec)
1536{
1537 struct conexant_spec *spec;
1538 int board_config;
1539
1540 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1541 if (!spec)
1542 return -ENOMEM;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001543 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001544 codec->pin_amp_workaround = 1;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001545
1546 spec->multiout.max_channels = 2;
1547 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1548 spec->multiout.dac_nids = cxt5047_dac_nids;
1549 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1550 spec->num_adc_nids = 1;
1551 spec->adc_nids = cxt5047_adc_nids;
1552 spec->capsrc_nids = cxt5047_capsrc_nids;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001553 spec->num_mixers = 1;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001554 spec->mixers[0] = cxt5047_base_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001555 spec->num_init_verbs = 1;
1556 spec->init_verbs[0] = cxt5047_init_verbs;
1557 spec->spdif_route = 0;
Tobin Davis5cd57522006-11-20 17:42:09 +01001558 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1559 spec->channel_mode = cxt5047_modes,
Tobin Davisc9b443d2006-11-14 12:13:39 +01001560
1561 codec->patch_ops = conexant_patch_ops;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001562
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001563 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1564 cxt5047_models,
1565 cxt5047_cfg_tbl);
Tobin Davisc9b443d2006-11-14 12:13:39 +01001566 switch (board_config) {
1567 case CXT5047_LAPTOP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001568 spec->num_mixers = 2;
1569 spec->mixers[1] = cxt5047_hp_spk_mixers;
1570 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001571 break;
1572 case CXT5047_LAPTOP_HP:
Takashi Iwaidf481e42009-03-10 15:35:35 +01001573 spec->num_mixers = 2;
1574 spec->mixers[1] = cxt5047_hp_only_mixers;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001575 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001576 codec->patch_ops.init = cxt5047_hp_init;
1577 break;
1578 case CXT5047_LAPTOP_EAPD:
Tobin Davis82f30042007-02-13 12:45:44 +01001579 spec->input_mux = &cxt5047_toshiba_capture_source;
Takashi Iwaidf481e42009-03-10 15:35:35 +01001580 spec->num_mixers = 2;
1581 spec->mixers[1] = cxt5047_hp_spk_mixers;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001582 spec->num_init_verbs = 2;
1583 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001584 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001585 break;
1586#ifdef CONFIG_SND_DEBUG
1587 case CXT5047_TEST:
1588 spec->input_mux = &cxt5047_test_capture_source;
1589 spec->mixers[0] = cxt5047_test_mixer;
1590 spec->init_verbs[0] = cxt5047_test_init_verbs;
Tobin Davisfb3409e2007-05-17 09:40:47 +02001591 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
Tobin Davisc9b443d2006-11-14 12:13:39 +01001592#endif
1593 }
Takashi Iwaidd5746a2009-03-10 14:30:40 +01001594 spec->vmaster_nid = 0x13;
Daniel T Chen025f2062010-03-21 18:34:43 -04001595
1596 switch (codec->subsystem_id >> 16) {
1597 case 0x103c:
1598 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1599 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1600 * with 0 dB offset 0x17)
1601 */
1602 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1603 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1604 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1605 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1606 (1 << AC_AMPCAP_MUTE_SHIFT));
1607 break;
1608 }
1609
Tobin Davisc9b443d2006-11-14 12:13:39 +01001610 return 0;
1611}
1612
Takashi Iwai461e2c72008-01-25 11:35:17 +01001613/* Conexant 5051 specific */
1614static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1615static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
Takashi Iwai461e2c72008-01-25 11:35:17 +01001616
1617static struct hda_channel_mode cxt5051_modes[1] = {
1618 { 2, NULL },
1619};
1620
1621static void cxt5051_update_speaker(struct hda_codec *codec)
1622{
1623 struct conexant_spec *spec = codec->spec;
1624 unsigned int pinctl;
Takashi Iwai23d2df52010-01-24 11:19:27 +01001625 /* headphone pin */
1626 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1627 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1628 pinctl);
1629 /* speaker pin */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001630 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1631 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1632 pinctl);
1633}
1634
1635/* turn on/off EAPD (+ mute HP) as a master switch */
1636static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1638{
1639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1640
1641 if (!cxt_eapd_put(kcontrol, ucontrol))
1642 return 0;
1643 cxt5051_update_speaker(codec);
1644 return 1;
1645}
1646
1647/* toggle input of built-in and mic jack appropriately */
1648static void cxt5051_portb_automic(struct hda_codec *codec)
1649{
Takashi Iwai79d7d532009-03-04 09:03:50 +01001650 struct conexant_spec *spec = codec->spec;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001651 unsigned int present;
1652
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001653 if (!(spec->auto_mic & AUTO_MIC_PORTB))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001654 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001655 present = snd_hda_jack_detect(codec, 0x17);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001656 snd_hda_codec_write(codec, 0x14, 0,
1657 AC_VERB_SET_CONNECT_SEL,
1658 present ? 0x01 : 0x00);
1659}
1660
1661/* switch the current ADC according to the jack state */
1662static void cxt5051_portc_automic(struct hda_codec *codec)
1663{
1664 struct conexant_spec *spec = codec->spec;
1665 unsigned int present;
1666 hda_nid_t new_adc;
1667
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001668 if (!(spec->auto_mic & AUTO_MIC_PORTC))
Takashi Iwai79d7d532009-03-04 09:03:50 +01001669 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01001670 present = snd_hda_jack_detect(codec, 0x18);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001671 if (present)
1672 spec->cur_adc_idx = 1;
1673 else
1674 spec->cur_adc_idx = 0;
1675 new_adc = spec->adc_nids[spec->cur_adc_idx];
1676 if (spec->cur_adc && spec->cur_adc != new_adc) {
1677 /* stream is running, let's swap the current ADC */
Takashi Iwai888afa12008-03-18 09:57:50 +01001678 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001679 spec->cur_adc = new_adc;
1680 snd_hda_codec_setup_stream(codec, new_adc,
1681 spec->cur_adc_stream_tag, 0,
1682 spec->cur_adc_format);
1683 }
1684}
1685
1686/* mute internal speaker if HP is plugged */
1687static void cxt5051_hp_automute(struct hda_codec *codec)
1688{
1689 struct conexant_spec *spec = codec->spec;
1690
Takashi Iwaid56757a2009-11-18 08:00:14 +01001691 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001692 cxt5051_update_speaker(codec);
1693}
1694
1695/* unsolicited event for HP jack sensing */
1696static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1697 unsigned int res)
1698{
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001699 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001700 switch (res >> 26) {
1701 case CONEXANT_HP_EVENT:
1702 cxt5051_hp_automute(codec);
1703 break;
1704 case CXT5051_PORTB_EVENT:
1705 cxt5051_portb_automic(codec);
1706 break;
1707 case CXT5051_PORTC_EVENT:
1708 cxt5051_portc_automic(codec);
1709 break;
1710 }
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001711 conexant_report_jack(codec, nid);
Takashi Iwai461e2c72008-01-25 11:35:17 +01001712}
1713
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001714static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Takashi Iwai461e2c72008-01-25 11:35:17 +01001715 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1716 {
1717 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1718 .name = "Master Playback Switch",
1719 .info = cxt_eapd_info,
1720 .get = cxt_eapd_get,
1721 .put = cxt5051_hp_master_sw_put,
1722 .private_value = 0x1a,
1723 },
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001724 {}
1725};
Takashi Iwai461e2c72008-01-25 11:35:17 +01001726
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001727static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1728 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1729 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1730 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1731 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1732 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1733 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001734 {}
1735};
1736
1737static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1738 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1739 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1740 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1741 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001742 {}
1743};
1744
Takashi Iwai79d7d532009-03-04 09:03:50 +01001745static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
Takashi Iwai4e4ac602010-01-23 22:29:54 +01001746 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1747 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
Takashi Iwai79d7d532009-03-04 09:03:50 +01001748 {}
1749};
1750
Ken Proxcd9d95a2010-01-08 09:01:47 +01001751static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001752 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1753 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
Ken Proxcd9d95a2010-01-08 09:01:47 +01001754 {}
1755};
1756
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001757static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1758 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1759 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1760 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1761 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001762 {}
1763};
1764
Takashi Iwai461e2c72008-01-25 11:35:17 +01001765static struct hda_verb cxt5051_init_verbs[] = {
1766 /* Line in, Mic */
1767 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1768 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1769 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1770 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1771 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1772 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1773 /* SPK */
1774 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1775 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1776 /* HP, Amp */
1777 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1778 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1779 /* DAC1 */
1780 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1781 /* Record selector: Int mic */
1782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1784 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1785 /* SPDIF route: PCM */
1786 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1787 /* EAPD */
1788 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1789 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai461e2c72008-01-25 11:35:17 +01001790 { } /* end */
1791};
1792
Takashi Iwai79d7d532009-03-04 09:03:50 +01001793static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1794 /* Line in, Mic */
1795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1798 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1799 /* SPK */
1800 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1801 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1802 /* HP, Amp */
1803 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1804 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1805 /* DAC1 */
1806 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1807 /* Record selector: Int mic */
1808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1809 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1810 /* SPDIF route: PCM */
1811 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1812 /* EAPD */
1813 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1814 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Takashi Iwai79d7d532009-03-04 09:03:50 +01001815 { } /* end */
1816};
1817
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001818static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1819 /* Line in, Mic */
1820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1821 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1822 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1823 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1824 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1825 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 /* SPK */
1827 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1828 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1829 /* HP, Amp */
1830 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1831 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1832 /* Docking HP */
1833 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1834 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* DAC1 */
1836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1837 /* Record selector: Int mic */
1838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1839 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1840 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1841 /* SPDIF route: PCM */
1842 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1843 /* EAPD */
1844 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1845 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001846 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1847 { } /* end */
1848};
1849
Ken Proxcd9d95a2010-01-08 09:01:47 +01001850static struct hda_verb cxt5051_f700_init_verbs[] = {
1851 /* Line in, Mic */
Takashi Iwai30ed7ed2010-01-28 17:11:45 +01001852 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001853 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1854 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1855 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1856 /* SPK */
1857 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1858 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1859 /* HP, Amp */
1860 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1861 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1862 /* DAC1 */
1863 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1864 /* Record selector: Int mic */
1865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1866 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1867 /* SPDIF route: PCM */
1868 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1869 /* EAPD */
1870 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1871 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
Ken Proxcd9d95a2010-01-08 09:01:47 +01001872 { } /* end */
1873};
1874
Takashi Iwai6953e552010-01-24 11:00:27 +01001875static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1876 unsigned int event)
1877{
1878 snd_hda_codec_write(codec, nid, 0,
1879 AC_VERB_SET_UNSOLICITED_ENABLE,
1880 AC_USRSP_EN | event);
1881#ifdef CONFIG_SND_HDA_INPUT_JACK
1882 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1883 conexant_report_jack(codec, nid);
1884#endif
1885}
1886
Takashi Iwai461e2c72008-01-25 11:35:17 +01001887/* initialize jack-sensing, too */
1888static int cxt5051_init(struct hda_codec *codec)
1889{
Takashi Iwai6953e552010-01-24 11:00:27 +01001890 struct conexant_spec *spec = codec->spec;
1891
Takashi Iwai461e2c72008-01-25 11:35:17 +01001892 conexant_init(codec);
Ulrich Dangelacf26c02009-01-02 19:30:14 +01001893 conexant_init_jacks(codec);
Takashi Iwai6953e552010-01-24 11:00:27 +01001894
1895 if (spec->auto_mic & AUTO_MIC_PORTB)
1896 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1897 if (spec->auto_mic & AUTO_MIC_PORTC)
1898 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1899
Takashi Iwai461e2c72008-01-25 11:35:17 +01001900 if (codec->patch_ops.unsol_event) {
1901 cxt5051_hp_automute(codec);
1902 cxt5051_portb_automic(codec);
1903 cxt5051_portc_automic(codec);
1904 }
1905 return 0;
1906}
1907
1908
1909enum {
1910 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1911 CXT5051_HP, /* no docking */
Takashi Iwai79d7d532009-03-04 09:03:50 +01001912 CXT5051_HP_DV6736, /* HP without mic switch */
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001913 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
Ken Proxcd9d95a2010-01-08 09:01:47 +01001914 CXT5051_F700, /* HP Compaq Presario F700 */
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001915 CXT5051_TOSHIBA, /* Toshiba M300 & co */
Takashi Iwai461e2c72008-01-25 11:35:17 +01001916 CXT5051_MODELS
1917};
1918
1919static const char *cxt5051_models[CXT5051_MODELS] = {
1920 [CXT5051_LAPTOP] = "laptop",
1921 [CXT5051_HP] = "hp",
Takashi Iwai79d7d532009-03-04 09:03:50 +01001922 [CXT5051_HP_DV6736] = "hp-dv6736",
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001923 [CXT5051_LENOVO_X200] = "lenovo-x200",
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001924 [CXT5051_F700] = "hp-700",
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001925 [CXT5051_TOSHIBA] = "toshiba",
Takashi Iwai461e2c72008-01-25 11:35:17 +01001926};
1927
1928static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
Takashi Iwai79d7d532009-03-04 09:03:50 +01001929 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
Tony Vroon1812e672009-05-27 21:00:41 +01001930 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
Takashi Iwai5f6c3de2010-01-23 22:19:29 +01001931 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001932 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001933 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1934 CXT5051_LAPTOP),
1935 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001936 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
Takashi Iwai461e2c72008-01-25 11:35:17 +01001937 {}
1938};
1939
1940static int patch_cxt5051(struct hda_codec *codec)
1941{
1942 struct conexant_spec *spec;
1943 int board_config;
1944
1945 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1946 if (!spec)
1947 return -ENOMEM;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001948 codec->spec = spec;
Takashi Iwai9421f952009-03-12 17:06:07 +01001949 codec->pin_amp_workaround = 1;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001950
1951 codec->patch_ops = conexant_patch_ops;
1952 codec->patch_ops.init = cxt5051_init;
1953
1954 spec->multiout.max_channels = 2;
1955 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1956 spec->multiout.dac_nids = cxt5051_dac_nids;
1957 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1958 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1959 spec->adc_nids = cxt5051_adc_nids;
Takashi Iwai2c7a3fb2010-01-24 10:47:02 +01001960 spec->num_mixers = 2;
1961 spec->mixers[0] = cxt5051_capture_mixers;
1962 spec->mixers[1] = cxt5051_playback_mixers;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001963 spec->num_init_verbs = 1;
1964 spec->init_verbs[0] = cxt5051_init_verbs;
1965 spec->spdif_route = 0;
1966 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1967 spec->channel_mode = cxt5051_modes;
1968 spec->cur_adc = 0;
1969 spec->cur_adc_idx = 0;
1970
Takashi Iwai79d7d532009-03-04 09:03:50 +01001971 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1972
Takashi Iwai461e2c72008-01-25 11:35:17 +01001973 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1974 cxt5051_models,
1975 cxt5051_cfg_tbl);
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001976 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001977 switch (board_config) {
1978 case CXT5051_HP:
Takashi Iwai461e2c72008-01-25 11:35:17 +01001979 spec->mixers[0] = cxt5051_hp_mixers;
1980 break;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001981 case CXT5051_HP_DV6736:
1982 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1983 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001984 spec->auto_mic = 0;
Takashi Iwai79d7d532009-03-04 09:03:50 +01001985 break;
Aristeu Sergio Rozanski Filho27e08982009-02-12 17:50:37 -05001986 case CXT5051_LENOVO_X200:
1987 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001988 break;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001989 case CXT5051_F700:
1990 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1991 spec->mixers[0] = cxt5051_f700_mixers;
Takashi Iwaifaddaa52010-01-23 22:31:36 +01001992 spec->auto_mic = 0;
1993 break;
1994 case CXT5051_TOSHIBA:
1995 spec->mixers[0] = cxt5051_toshiba_mixers;
1996 spec->auto_mic = AUTO_MIC_PORTB;
Ken Proxcd9d95a2010-01-08 09:01:47 +01001997 break;
Takashi Iwai461e2c72008-01-25 11:35:17 +01001998 }
1999
2000 return 0;
2001}
2002
Daniel Drake0fb67e92009-07-16 14:46:57 +01002003/* Conexant 5066 specific */
2004
2005static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2006static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2007static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2008#define CXT5066_SPDIF_OUT 0x21
2009
Daniel Drakedbaccc02009-11-09 15:17:24 +00002010/* OLPC's microphone port is DC coupled for use with external sensors,
2011 * therefore we use a 50% mic bias in order to center the input signal with
2012 * the DC input range of the codec. */
2013#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2014
Daniel Drake0fb67e92009-07-16 14:46:57 +01002015static struct hda_channel_mode cxt5066_modes[1] = {
2016 { 2, NULL },
2017};
2018
2019static void cxt5066_update_speaker(struct hda_codec *codec)
2020{
2021 struct conexant_spec *spec = codec->spec;
2022 unsigned int pinctl;
2023
2024 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2025 spec->hp_present);
2026
2027 /* Port A (HP) */
2028 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2029 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2030 pinctl);
2031
2032 /* Port D (HP/LO) */
2033 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2034 ? spec->port_d_mode : 0;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002035 /* Mute if Port A is connected on Thinkpad */
2036 if (spec->thinkpad && (spec->hp_present & 1))
2037 pinctl = 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002038 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2039 pinctl);
2040
2041 /* CLASS_D AMP */
2042 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2043 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2044 pinctl);
2045
2046 if (spec->dell_automute) {
2047 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2048 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2049 ? PIN_OUT : 0;
2050 snd_hda_codec_write(codec, 0x1c, 0,
2051 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2052 }
2053}
2054
2055/* turn on/off EAPD (+ mute HP) as a master switch */
2056static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2057 struct snd_ctl_elem_value *ucontrol)
2058{
2059 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2060
2061 if (!cxt_eapd_put(kcontrol, ucontrol))
2062 return 0;
2063
2064 cxt5066_update_speaker(codec);
2065 return 1;
2066}
2067
Daniel Drakec4cfe662010-01-07 13:47:04 +01002068static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2069 .num_items = 3,
2070 .items = {
2071 { "Off", PIN_IN },
2072 { "50%", PIN_VREF50 },
2073 { "80%", PIN_VREF80 },
2074 },
2075};
2076
2077static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2078{
2079 struct conexant_spec *spec = codec->spec;
2080 /* Even though port F is the DC input, the bias is controlled on port B.
2081 * we also leave that port as an active input (but unselected) in DC mode
2082 * just in case that is necessary to make the bias setting take effect. */
2083 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2084 AC_VERB_SET_PIN_WIDGET_CONTROL,
2085 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2086}
2087
Daniel Drake75f89912010-01-07 13:46:25 +01002088/* OLPC defers mic widget control until when capture is started because the
2089 * microphone LED comes on as soon as these settings are put in place. if we
2090 * did this before recording, it would give the false indication that recording
2091 * is happening when it is not. */
2092static void cxt5066_olpc_select_mic(struct hda_codec *codec)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002093{
Daniel Drakedbaccc02009-11-09 15:17:24 +00002094 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002095 if (!spec->recording)
2096 return;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002097
Daniel Drakec4cfe662010-01-07 13:47:04 +01002098 if (spec->dc_enable) {
2099 /* in DC mode we ignore presence detection and just use the jack
2100 * through our special DC port */
2101 const struct hda_verb enable_dc_mode[] = {
2102 /* disble internal mic, port C */
2103 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2104
2105 /* enable DC capture, port F */
2106 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2107 {},
2108 };
2109
2110 snd_hda_sequence_write(codec, enable_dc_mode);
2111 /* port B input disabled (and bias set) through the following call */
2112 cxt5066_set_olpc_dc_bias(codec);
2113 return;
2114 }
2115
2116 /* disable DC (port F) */
2117 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2118
Daniel Drake75f89912010-01-07 13:46:25 +01002119 /* external mic, port B */
2120 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2121 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002122
Daniel Drake75f89912010-01-07 13:46:25 +01002123 /* internal mic, port C */
2124 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2125 spec->ext_mic_present ? 0 : PIN_VREF80);
2126}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002127
Daniel Drake75f89912010-01-07 13:46:25 +01002128/* toggle input of built-in and mic jack appropriately */
2129static void cxt5066_olpc_automic(struct hda_codec *codec)
2130{
2131 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002132 unsigned int present;
2133
Daniel Drakec4cfe662010-01-07 13:47:04 +01002134 if (spec->dc_enable) /* don't do presence detection in DC mode */
2135 return;
2136
Daniel Drake75f89912010-01-07 13:46:25 +01002137 present = snd_hda_codec_read(codec, 0x1a, 0,
2138 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2139 if (present)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002140 snd_printdd("CXT5066: external microphone detected\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002141 else
Daniel Drake0fb67e92009-07-16 14:46:57 +01002142 snd_printdd("CXT5066: external microphone absent\n");
Daniel Drake75f89912010-01-07 13:46:25 +01002143
2144 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2145 present ? 0 : 1);
2146 spec->ext_mic_present = !!present;
2147
2148 cxt5066_olpc_select_mic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002149}
2150
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002151/* toggle input of built-in digital mic and mic jack appropriately */
2152static void cxt5066_vostro_automic(struct hda_codec *codec)
2153{
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002154 unsigned int present;
2155
2156 struct hda_verb ext_mic_present[] = {
2157 /* enable external mic, port B */
Daniel Drake75f89912010-01-07 13:46:25 +01002158 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002159
2160 /* switch to external mic input */
2161 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2162 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2163
2164 /* disable internal digital mic */
2165 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2166 {}
2167 };
2168 static struct hda_verb ext_mic_absent[] = {
2169 /* enable internal mic, port C */
2170 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2171
2172 /* switch to internal mic input */
2173 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2174
2175 /* disable external mic, port B */
2176 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2177 {}
2178 };
2179
2180 present = snd_hda_jack_detect(codec, 0x1a);
2181 if (present) {
2182 snd_printdd("CXT5066: external microphone detected\n");
2183 snd_hda_sequence_write(codec, ext_mic_present);
2184 } else {
2185 snd_printdd("CXT5066: external microphone absent\n");
2186 snd_hda_sequence_write(codec, ext_mic_absent);
2187 }
2188}
2189
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002190/* toggle input of built-in digital mic and mic jack appropriately */
2191static void cxt5066_ideapad_automic(struct hda_codec *codec)
2192{
2193 unsigned int present;
2194
2195 struct hda_verb ext_mic_present[] = {
2196 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2197 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2198 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2199 {}
2200 };
2201 static struct hda_verb ext_mic_absent[] = {
2202 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2203 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2204 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2205 {}
2206 };
2207
2208 present = snd_hda_jack_detect(codec, 0x1b);
2209 if (present) {
2210 snd_printdd("CXT5066: external microphone detected\n");
2211 snd_hda_sequence_write(codec, ext_mic_present);
2212 } else {
2213 snd_printdd("CXT5066: external microphone absent\n");
2214 snd_hda_sequence_write(codec, ext_mic_absent);
2215 }
2216}
2217
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002218/* toggle input of built-in digital mic and mic jack appropriately
2219 order is: external mic -> dock mic -> interal mic */
2220static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2221{
2222 unsigned int ext_present, dock_present;
2223
2224 static struct hda_verb ext_mic_present[] = {
2225 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2226 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2227 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2228 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2229 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2230 {}
2231 };
2232 static struct hda_verb dock_mic_present[] = {
2233 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2234 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2235 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2236 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2237 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {}
2239 };
2240 static struct hda_verb ext_mic_absent[] = {
2241 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2242 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2243 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2244 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2245 {}
2246 };
2247
2248 ext_present = snd_hda_jack_detect(codec, 0x1b);
2249 dock_present = snd_hda_jack_detect(codec, 0x1a);
2250 if (ext_present) {
2251 snd_printdd("CXT5066: external microphone detected\n");
2252 snd_hda_sequence_write(codec, ext_mic_present);
2253 } else if (dock_present) {
2254 snd_printdd("CXT5066: dock microphone detected\n");
2255 snd_hda_sequence_write(codec, dock_mic_present);
2256 } else {
2257 snd_printdd("CXT5066: external microphone absent\n");
2258 snd_hda_sequence_write(codec, ext_mic_absent);
2259 }
2260}
2261
Daniel Drake0fb67e92009-07-16 14:46:57 +01002262/* mute internal speaker if HP is plugged */
2263static void cxt5066_hp_automute(struct hda_codec *codec)
2264{
2265 struct conexant_spec *spec = codec->spec;
2266 unsigned int portA, portD;
2267
2268 /* Port A */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002269 portA = snd_hda_jack_detect(codec, 0x19);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002270
2271 /* Port D */
Takashi Iwaid56757a2009-11-18 08:00:14 +01002272 portD = snd_hda_jack_detect(codec, 0x1c);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002273
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002274 spec->hp_present = !!(portA);
2275 spec->hp_present |= portD ? 2 : 0;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002276 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2277 portA, portD, spec->hp_present);
2278 cxt5066_update_speaker(codec);
2279}
2280
2281/* unsolicited event for jack sensing */
Daniel Drake75f89912010-01-07 13:46:25 +01002282static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
Daniel Drake0fb67e92009-07-16 14:46:57 +01002283{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002284 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002285 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2286 switch (res >> 26) {
2287 case CONEXANT_HP_EVENT:
2288 cxt5066_hp_automute(codec);
2289 break;
2290 case CONEXANT_MIC_EVENT:
Daniel Drakec4cfe662010-01-07 13:47:04 +01002291 /* ignore mic events in DC mode; we're always using the jack */
2292 if (!spec->dc_enable)
2293 cxt5066_olpc_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002294 break;
2295 }
2296}
2297
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002298/* unsolicited event for jack sensing */
2299static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2300{
2301 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2302 switch (res >> 26) {
2303 case CONEXANT_HP_EVENT:
2304 cxt5066_hp_automute(codec);
2305 break;
2306 case CONEXANT_MIC_EVENT:
2307 cxt5066_vostro_automic(codec);
2308 break;
2309 }
2310}
2311
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002312/* unsolicited event for jack sensing */
2313static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2314{
2315 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2316 switch (res >> 26) {
2317 case CONEXANT_HP_EVENT:
2318 cxt5066_hp_automute(codec);
2319 break;
2320 case CONEXANT_MIC_EVENT:
2321 cxt5066_ideapad_automic(codec);
2322 break;
2323 }
2324}
2325
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002326/* unsolicited event for jack sensing */
2327static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
2328{
2329 snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
2330 switch (res >> 26) {
2331 case CONEXANT_HP_EVENT:
2332 cxt5066_hp_automute(codec);
2333 break;
2334 case CONEXANT_MIC_EVENT:
2335 cxt5066_thinkpad_automic(codec);
2336 break;
2337 }
2338}
2339
Daniel Drake0fb67e92009-07-16 14:46:57 +01002340static const struct hda_input_mux cxt5066_analog_mic_boost = {
2341 .num_items = 5,
2342 .items = {
2343 { "0dB", 0 },
2344 { "10dB", 1 },
2345 { "20dB", 2 },
2346 { "30dB", 3 },
2347 { "40dB", 4 },
2348 },
2349};
2350
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002351static void cxt5066_set_mic_boost(struct hda_codec *codec)
Daniel Drakec4cfe662010-01-07 13:47:04 +01002352{
2353 struct conexant_spec *spec = codec->spec;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002354 snd_hda_codec_write_cache(codec, 0x17, 0,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002355 AC_VERB_SET_AMP_GAIN_MUTE,
2356 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2357 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002358 if (spec->ideapad || spec->thinkpad) {
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002359 /* adjust the internal mic as well...it is not through 0x17 */
2360 snd_hda_codec_write_cache(codec, 0x23, 0,
2361 AC_VERB_SET_AMP_GAIN_MUTE,
2362 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2363 cxt5066_analog_mic_boost.
2364 items[spec->mic_boost].index);
2365 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002366}
2367
Daniel Drake0fb67e92009-07-16 14:46:57 +01002368static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2369 struct snd_ctl_elem_info *uinfo)
2370{
2371 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2372}
2373
2374static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2375 struct snd_ctl_elem_value *ucontrol)
2376{
2377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002378 struct conexant_spec *spec = codec->spec;
2379 ucontrol->value.enumerated.item[0] = spec->mic_boost;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002380 return 0;
2381}
2382
2383static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2384 struct snd_ctl_elem_value *ucontrol)
2385{
2386 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002387 struct conexant_spec *spec = codec->spec;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002388 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2389 unsigned int idx;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002390 idx = ucontrol->value.enumerated.item[0];
2391 if (idx >= imux->num_items)
2392 idx = imux->num_items - 1;
2393
Daniel Drakec4cfe662010-01-07 13:47:04 +01002394 spec->mic_boost = idx;
2395 if (!spec->dc_enable)
2396 cxt5066_set_mic_boost(codec);
2397 return 1;
2398}
Daniel Drake0fb67e92009-07-16 14:46:57 +01002399
Daniel Drakec4cfe662010-01-07 13:47:04 +01002400static void cxt5066_enable_dc(struct hda_codec *codec)
2401{
2402 const struct hda_verb enable_dc_mode[] = {
2403 /* disable gain */
2404 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2405
2406 /* switch to DC input */
2407 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2408 {}
2409 };
2410
2411 /* configure as input source */
2412 snd_hda_sequence_write(codec, enable_dc_mode);
2413 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2414}
2415
2416static void cxt5066_disable_dc(struct hda_codec *codec)
2417{
2418 /* reconfigure input source */
2419 cxt5066_set_mic_boost(codec);
2420 /* automic also selects the right mic if we're recording */
2421 cxt5066_olpc_automic(codec);
2422}
2423
2424static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2425 struct snd_ctl_elem_value *ucontrol)
2426{
2427 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2428 struct conexant_spec *spec = codec->spec;
2429 ucontrol->value.integer.value[0] = spec->dc_enable;
2430 return 0;
2431}
2432
2433static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2434 struct snd_ctl_elem_value *ucontrol)
2435{
2436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2437 struct conexant_spec *spec = codec->spec;
2438 int dc_enable = !!ucontrol->value.integer.value[0];
2439
2440 if (dc_enable == spec->dc_enable)
2441 return 0;
2442
2443 spec->dc_enable = dc_enable;
2444 if (dc_enable)
2445 cxt5066_enable_dc(codec);
2446 else
2447 cxt5066_disable_dc(codec);
2448
2449 return 1;
2450}
2451
2452static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2453 struct snd_ctl_elem_info *uinfo)
2454{
2455 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2456}
2457
2458static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2459 struct snd_ctl_elem_value *ucontrol)
2460{
2461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2462 struct conexant_spec *spec = codec->spec;
2463 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2464 return 0;
2465}
2466
2467static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2468 struct snd_ctl_elem_value *ucontrol)
2469{
2470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2471 struct conexant_spec *spec = codec->spec;
2472 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2473 unsigned int idx;
2474
2475 idx = ucontrol->value.enumerated.item[0];
2476 if (idx >= imux->num_items)
2477 idx = imux->num_items - 1;
2478
2479 spec->dc_input_bias = idx;
2480 if (spec->dc_enable)
2481 cxt5066_set_olpc_dc_bias(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002482 return 1;
2483}
2484
Daniel Drake75f89912010-01-07 13:46:25 +01002485static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2486{
2487 struct conexant_spec *spec = codec->spec;
2488 /* mark as recording and configure the microphone widget so that the
2489 * recording LED comes on. */
2490 spec->recording = 1;
2491 cxt5066_olpc_select_mic(codec);
2492}
2493
2494static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2495{
2496 struct conexant_spec *spec = codec->spec;
2497 const struct hda_verb disable_mics[] = {
2498 /* disable external mic, port B */
2499 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2500
2501 /* disble internal mic, port C */
2502 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drakec4cfe662010-01-07 13:47:04 +01002503
2504 /* disable DC capture, port F */
2505 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake75f89912010-01-07 13:46:25 +01002506 {},
2507 };
2508
2509 snd_hda_sequence_write(codec, disable_mics);
2510 spec->recording = 0;
2511}
2512
Daniel Drake0fb67e92009-07-16 14:46:57 +01002513static struct hda_input_mux cxt5066_capture_source = {
2514 .num_items = 4,
2515 .items = {
2516 { "Mic B", 0 },
2517 { "Mic C", 1 },
2518 { "Mic E", 2 },
2519 { "Mic F", 3 },
2520 },
2521};
2522
2523static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2524 .ops = &snd_hda_bind_vol,
2525 .values = {
2526 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2527 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2528 0
2529 },
2530};
2531
2532static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2533 .ops = &snd_hda_bind_sw,
2534 .values = {
2535 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2536 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2537 0
2538 },
2539};
2540
2541static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2542 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2543 {}
2544};
2545
2546static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2547 {
2548 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2549 .name = "Master Playback Volume",
2550 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2551 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2552 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002553 .subdevice = HDA_SUBDEV_AMP_FLAG,
Daniel Drake0fb67e92009-07-16 14:46:57 +01002554 .info = snd_hda_mixer_amp_volume_info,
2555 .get = snd_hda_mixer_amp_volume_get,
2556 .put = snd_hda_mixer_amp_volume_put,
2557 .tlv = { .c = snd_hda_mixer_amp_tlv },
2558 /* offset by 28 volume steps to limit minimum gain to -46dB */
2559 .private_value =
2560 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2561 },
2562 {}
2563};
2564
Daniel Drakec4cfe662010-01-07 13:47:04 +01002565static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2566 {
2567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2568 .name = "DC Mode Enable Switch",
2569 .info = snd_ctl_boolean_mono_info,
2570 .get = cxt5066_olpc_dc_get,
2571 .put = cxt5066_olpc_dc_put,
2572 },
2573 {
2574 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2575 .name = "DC Input Bias Enum",
2576 .info = cxt5066_olpc_dc_bias_enum_info,
2577 .get = cxt5066_olpc_dc_bias_enum_get,
2578 .put = cxt5066_olpc_dc_bias_enum_put,
2579 },
2580 {}
2581};
2582
Daniel Drake0fb67e92009-07-16 14:46:57 +01002583static struct snd_kcontrol_new cxt5066_mixers[] = {
2584 {
2585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2586 .name = "Master Playback Switch",
2587 .info = cxt_eapd_info,
2588 .get = cxt_eapd_get,
2589 .put = cxt5066_hp_master_sw_put,
2590 .private_value = 0x1d,
2591 },
2592
2593 {
2594 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Daniel Drakec4cfe662010-01-07 13:47:04 +01002595 .name = "Analog Mic Boost Capture Enum",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002596 .info = cxt5066_mic_boost_mux_enum_info,
2597 .get = cxt5066_mic_boost_mux_enum_get,
2598 .put = cxt5066_mic_boost_mux_enum_put,
2599 },
2600
2601 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2602 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2603 {}
2604};
2605
Einar Rünkaru254bba62009-12-16 22:16:13 +02002606static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2607 {
2608 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2609 .name = "Int Mic Boost Capture Enum",
2610 .info = cxt5066_mic_boost_mux_enum_info,
2611 .get = cxt5066_mic_boost_mux_enum_get,
2612 .put = cxt5066_mic_boost_mux_enum_put,
2613 .private_value = 0x23 | 0x100,
2614 },
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +02002615 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
Einar Rünkaru254bba62009-12-16 22:16:13 +02002616 {}
2617};
2618
Daniel Drake0fb67e92009-07-16 14:46:57 +01002619static struct hda_verb cxt5066_init_verbs[] = {
2620 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2621 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2622 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2623 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2624
2625 /* Speakers */
2626 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2627 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2628
2629 /* HP, Amp */
2630 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2631 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2632
2633 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2634 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2635
2636 /* DAC1 */
2637 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2638
2639 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2640 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2641 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2642 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2643 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2644 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2645
2646 /* no digital microphone support yet */
2647 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2648
2649 /* Audio input selector */
2650 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2651
2652 /* SPDIF route: PCM */
2653 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2654 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2655
2656 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2657 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2658
2659 /* EAPD */
2660 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2661
2662 /* not handling these yet */
2663 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2664 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2665 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2666 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2667 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2668 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2669 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2670 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2671 { } /* end */
2672};
2673
2674static struct hda_verb cxt5066_init_verbs_olpc[] = {
2675 /* Port A: headphones */
2676 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2677 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2678
2679 /* Port B: external microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002680 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002681
2682 /* Port C: internal microphone */
Daniel Drake75f89912010-01-07 13:46:25 +01002683 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
Daniel Drake0fb67e92009-07-16 14:46:57 +01002684
2685 /* Port D: unused */
2686 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2687
2688 /* Port E: unused, but has primary EAPD */
2689 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2690 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2691
Daniel Drakec4cfe662010-01-07 13:47:04 +01002692 /* Port F: external DC input through microphone port */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002693 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2694
2695 /* Port G: internal speakers */
2696 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2697 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2698
2699 /* DAC1 */
2700 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2701
2702 /* DAC2: unused */
2703 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2704
2705 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2706 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2707 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2708 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2709 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2710 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2711 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2712 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2713 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2714 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2715 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2716 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2717
2718 /* Disable digital microphone port */
2719 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2720
2721 /* Audio input selectors */
2722 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2723 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2724
2725 /* Disable SPDIF */
2726 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2728
2729 /* enable unsolicited events for Port A and B */
2730 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2731 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2732 { } /* end */
2733};
2734
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002735static struct hda_verb cxt5066_init_verbs_vostro[] = {
2736 /* Port A: headphones */
2737 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2738 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2739
2740 /* Port B: external microphone */
2741 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2742
2743 /* Port C: unused */
2744 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2745
2746 /* Port D: unused */
2747 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2748
2749 /* Port E: unused, but has primary EAPD */
2750 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2751 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2752
2753 /* Port F: unused */
2754 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2755
2756 /* Port G: internal speakers */
2757 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2758 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2759
2760 /* DAC1 */
2761 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2762
2763 /* DAC2: unused */
2764 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2765
2766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2767 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2769 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2770 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2771 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2772 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2773 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2774 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2775 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2776 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2777 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2778
2779 /* Digital microphone port */
2780 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2781
2782 /* Audio input selectors */
2783 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2784 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2785
2786 /* Disable SPDIF */
2787 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2788 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2789
2790 /* enable unsolicited events for Port A and B */
2791 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2792 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2793 { } /* end */
2794};
2795
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002796static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2797 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2798 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2799 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2800 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2801
2802 /* Speakers */
2803 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2804 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2805
2806 /* HP, Amp */
2807 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2808 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2809
2810 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2811 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2812
2813 /* DAC1 */
2814 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2815
2816 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2822 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2823
2824 /* Audio input selector */
2825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2826 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2827
2828 /* SPDIF route: PCM */
2829 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2830 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2831
2832 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2834
2835 /* internal microphone */
2836 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2837
2838 /* EAPD */
2839 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2840
2841 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2842 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2843 { } /* end */
2844};
2845
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002846static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2847 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2848 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2849
2850 /* Port G: internal speakers */
2851 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2852 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2853
2854 /* Port A: HP, Amp */
2855 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2856 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2857
2858 /* Port B: Mic Dock */
2859 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2860
2861 /* Port C: Mic */
2862 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863
2864 /* Port D: HP Dock, Amp */
2865 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2867
2868 /* DAC1 */
2869 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2870
2871 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2872 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2873 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2874 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2877 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2878
2879 /* Audio input selector */
2880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2881 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2882
2883 /* SPDIF route: PCM */
2884 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2885 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2886
2887 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2888 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2889
2890 /* internal microphone */
2891 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2892
2893 /* EAPD */
2894 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2895
2896 /* enable unsolicited events for Port A, B, C and D */
2897 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2898 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2899 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2900 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2901 { } /* end */
2902};
2903
Daniel Drake0fb67e92009-07-16 14:46:57 +01002904static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2905 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2906 { } /* end */
2907};
2908
2909/* initialize jack-sensing, too */
2910static int cxt5066_init(struct hda_codec *codec)
2911{
Einar Rünkaru254bba62009-12-16 22:16:13 +02002912 struct conexant_spec *spec = codec->spec;
2913
Daniel Drake0fb67e92009-07-16 14:46:57 +01002914 snd_printdd("CXT5066: init\n");
2915 conexant_init(codec);
2916 if (codec->patch_ops.unsol_event) {
2917 cxt5066_hp_automute(codec);
Einar Rünkaru254bba62009-12-16 22:16:13 +02002918 if (spec->dell_vostro)
2919 cxt5066_vostro_automic(codec);
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002920 else if (spec->ideapad)
2921 cxt5066_ideapad_automic(codec);
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002922 else if (spec->thinkpad)
2923 cxt5066_thinkpad_automic(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002924 }
Daniel Drakec4cfe662010-01-07 13:47:04 +01002925 cxt5066_set_mic_boost(codec);
Daniel Drake0fb67e92009-07-16 14:46:57 +01002926 return 0;
2927}
2928
Daniel Drake75f89912010-01-07 13:46:25 +01002929static int cxt5066_olpc_init(struct hda_codec *codec)
2930{
Daniel Drakec4cfe662010-01-07 13:47:04 +01002931 struct conexant_spec *spec = codec->spec;
Daniel Drake75f89912010-01-07 13:46:25 +01002932 snd_printdd("CXT5066: init\n");
2933 conexant_init(codec);
2934 cxt5066_hp_automute(codec);
Daniel Drakec4cfe662010-01-07 13:47:04 +01002935 if (!spec->dc_enable) {
2936 cxt5066_set_mic_boost(codec);
2937 cxt5066_olpc_automic(codec);
2938 } else {
2939 cxt5066_enable_dc(codec);
2940 }
Daniel Drake75f89912010-01-07 13:46:25 +01002941 return 0;
2942}
2943
Daniel Drake0fb67e92009-07-16 14:46:57 +01002944enum {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002945 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002946 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2947 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002948 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002949 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002950 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
Daniel Drake0fb67e92009-07-16 14:46:57 +01002951 CXT5066_MODELS
2952};
2953
2954static const char *cxt5066_models[CXT5066_MODELS] = {
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002955 [CXT5066_LAPTOP] = "laptop",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002956 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2957 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002958 [CXT5066_DELL_VOSTO] = "dell-vostro",
2959 [CXT5066_IDEAPAD] = "ideapad",
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002960 [CXT5066_THINKPAD] = "thinkpad",
Daniel Drake0fb67e92009-07-16 14:46:57 +01002961};
2962
2963static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2964 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2965 CXT5066_LAPTOP),
2966 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2967 CXT5066_DELL_LAPTOP),
Daniel Drake798a8a12009-11-04 10:11:07 +00002968 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
Einar Rünkaru95a618b2009-11-23 22:23:49 +02002969 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05002970 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02002971 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
Daniel Drake0fb67e92009-07-16 14:46:57 +01002972 {}
2973};
2974
2975static int patch_cxt5066(struct hda_codec *codec)
2976{
2977 struct conexant_spec *spec;
2978 int board_config;
2979
2980 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2981 if (!spec)
2982 return -ENOMEM;
2983 codec->spec = spec;
2984
2985 codec->patch_ops = conexant_patch_ops;
Daniel Drake75f89912010-01-07 13:46:25 +01002986 codec->patch_ops.init = conexant_init;
Daniel Drake0fb67e92009-07-16 14:46:57 +01002987
2988 spec->dell_automute = 0;
2989 spec->multiout.max_channels = 2;
2990 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2991 spec->multiout.dac_nids = cxt5066_dac_nids;
2992 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2993 spec->num_adc_nids = 1;
2994 spec->adc_nids = cxt5066_adc_nids;
2995 spec->capsrc_nids = cxt5066_capsrc_nids;
2996 spec->input_mux = &cxt5066_capture_source;
2997
2998 spec->port_d_mode = PIN_HP;
2999
3000 spec->num_init_verbs = 1;
3001 spec->init_verbs[0] = cxt5066_init_verbs;
3002 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3003 spec->channel_mode = cxt5066_modes;
3004 spec->cur_adc = 0;
3005 spec->cur_adc_idx = 0;
3006
3007 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3008 cxt5066_models, cxt5066_cfg_tbl);
3009 switch (board_config) {
3010 default:
3011 case CXT5066_LAPTOP:
3012 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3013 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3014 break;
3015 case CXT5066_DELL_LAPTOP:
3016 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3017 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3018
3019 spec->port_d_mode = PIN_OUT;
3020 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3021 spec->num_init_verbs++;
3022 spec->dell_automute = 1;
3023 break;
3024 case CXT5066_OLPC_XO_1_5:
Daniel Drake75f89912010-01-07 13:46:25 +01003025 codec->patch_ops.init = cxt5066_olpc_init;
3026 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003027 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3028 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003029 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003030 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3031 spec->port_d_mode = 0;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003032 spec->mic_boost = 3; /* default 30dB gain */
Daniel Drake0fb67e92009-07-16 14:46:57 +01003033
3034 /* no S/PDIF out */
3035 spec->multiout.dig_out_nid = 0;
3036
3037 /* input source automatically selected */
3038 spec->input_mux = NULL;
Daniel Drake75f89912010-01-07 13:46:25 +01003039
3040 /* our capture hooks which allow us to turn on the microphone LED
3041 * at the right time */
3042 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3043 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003044 break;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003045 case CXT5066_DELL_VOSTO:
Daniel Drake75f89912010-01-07 13:46:25 +01003046 codec->patch_ops.init = cxt5066_init;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003047 codec->patch_ops.unsol_event = cxt5066_vostro_event;
3048 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3049 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3050 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003051 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003052 spec->port_d_mode = 0;
Einar Rünkaru254bba62009-12-16 22:16:13 +02003053 spec->dell_vostro = 1;
Daniel Drakec4cfe662010-01-07 13:47:04 +01003054 spec->mic_boost = 3; /* default 30dB gain */
Einar Rünkaruc0f8faf2009-12-16 22:41:36 +02003055 snd_hda_attach_beep_device(codec, 0x13);
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003056
3057 /* no S/PDIF out */
3058 spec->multiout.dig_out_nid = 0;
3059
3060 /* input source automatically selected */
3061 spec->input_mux = NULL;
3062 break;
Greg Alexandercfd3d8d2010-02-13 02:02:25 -05003063 case CXT5066_IDEAPAD:
3064 codec->patch_ops.init = cxt5066_init;
3065 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3066 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3067 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3068 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3069 spec->port_d_mode = 0;
3070 spec->ideapad = 1;
3071 spec->mic_boost = 2; /* default 20dB gain */
3072
3073 /* no S/PDIF out */
3074 spec->multiout.dig_out_nid = 0;
3075
3076 /* input source automatically selected */
3077 spec->input_mux = NULL;
3078 break;
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003079 case CXT5066_THINKPAD:
3080 codec->patch_ops.init = cxt5066_init;
3081 codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
3082 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3083 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3084 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3085 spec->thinkpad = 1;
3086 spec->port_d_mode = PIN_OUT;
3087 spec->mic_boost = 2; /* default 20dB gain */
3088
3089 /* no S/PDIF out */
3090 spec->multiout.dig_out_nid = 0;
3091
3092 /* input source automatically selected */
3093 spec->input_mux = NULL;
3094 break;
Daniel Drake0fb67e92009-07-16 14:46:57 +01003095 }
3096
3097 return 0;
3098}
Takashi Iwai461e2c72008-01-25 11:35:17 +01003099
3100/*
3101 */
3102
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003103static struct hda_codec_preset snd_hda_preset_conexant[] = {
Tobin Davis82f30042007-02-13 12:45:44 +01003104 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3105 .patch = patch_cxt5045 },
3106 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3107 .patch = patch_cxt5047 },
Takashi Iwai461e2c72008-01-25 11:35:17 +01003108 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3109 .patch = patch_cxt5051 },
Daniel Drake0fb67e92009-07-16 14:46:57 +01003110 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3111 .patch = patch_cxt5066 },
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003112 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3113 .patch = patch_cxt5066 },
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003114 { .id = 0x14f15069, .name = "CX20585",
3115 .patch = patch_cxt5066 },
Tobin Davisc9b443d2006-11-14 12:13:39 +01003116 {} /* terminator */
3117};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003118
3119MODULE_ALIAS("snd-hda-codec-id:14f15045");
3120MODULE_ALIAS("snd-hda-codec-id:14f15047");
3121MODULE_ALIAS("snd-hda-codec-id:14f15051");
Daniel Drake0fb67e92009-07-16 14:46:57 +01003122MODULE_ALIAS("snd-hda-codec-id:14f15066");
Einar Rünkaru95a618b2009-11-23 22:23:49 +02003123MODULE_ALIAS("snd-hda-codec-id:14f15067");
Jens Taprogge7b2bfdb2010-04-14 23:42:04 +02003124MODULE_ALIAS("snd-hda-codec-id:14f15069");
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003125
3126MODULE_LICENSE("GPL");
3127MODULE_DESCRIPTION("Conexant HD-audio codec");
3128
3129static struct hda_codec_preset_list conexant_list = {
3130 .preset = snd_hda_preset_conexant,
3131 .owner = THIS_MODULE,
3132};
3133
3134static int __init patch_conexant_init(void)
3135{
3136 return snd_hda_add_codec_preset(&conexant_list);
3137}
3138
3139static void __exit patch_conexant_exit(void)
3140{
3141 snd_hda_delete_codec_preset(&conexant_list);
3142}
3143
3144module_init(patch_conexant_init)
3145module_exit(patch_conexant_exit)